@codexhost/cli-darwin-arm64 0.18.0-beta.1 → 0.18.0-beta.3
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 +1 -1
- package/app/codexhost-distribution.json +1 -1
- package/app/console-server.mjs +103 -93
- package/app/console-web.js +104 -94
- package/app/desktop-controller.mjs +103 -109
- package/app/host-runtime.mjs +10067 -8374
- package/app/plugins/antigravity/plugin.mjs +103 -93
- package/app/plugins/claude-code/plugin.mjs +103 -93
- package/app/plugins/codebuddy/plugin.mjs +103 -93
- package/app/plugins/codex-usage/plugin.mjs +103 -93
- package/app/plugins/copilot/plugin.mjs +103 -93
- package/app/plugins/cursor-cli/plugin.mjs +103 -93
- package/app/plugins/deepseek-harness/plugin.mjs +103 -93
- package/app/plugins/devin/plugin.mjs +103 -93
- package/app/plugins/enabled.json +0 -1
- package/app/plugins/grok/plugin.mjs +103 -93
- package/app/plugins/hermes/plugin.mjs +103 -93
- package/app/plugins/kimi-code/plugin.mjs +103 -93
- package/app/plugins/kiro-cli/plugin.mjs +103 -93
- package/app/plugins/omp/plugin.mjs +103 -93
- package/app/plugins/opencode/plugin.mjs +103 -93
- package/app/plugins/pi/plugin.mjs +103 -93
- package/app/plugins/qoder/plugin.mjs +103 -93
- package/app/plugins/qoder-cn/plugin.mjs +103 -93
- package/app/plugins/qwen-code/plugin.mjs +103 -93
- package/app/plugins/workbuddy/plugin.mjs +103 -93
- package/app/plugins/zcode/plugin.mjs +103 -93
- package/app/renderer-extension.js +122 -149
- package/app/web/assets/index-C3lniEH1.css +1 -0
- package/app/web/assets/index-aKvkfNJN.js +199 -0
- package/app/web/codexhost-settings.js +104 -94
- package/app/web/index.html +2 -2
- package/app/web/plugins/deepseek-ai__dsh-api-gateway/client.js +1 -1
- package/app/web/plugins/deepseek-ai__dsh-api-remotes/client.js +64 -64
- package/app/web/plugins/deepseek-ai__dsh-api-session-controller/client.js +69 -69
- package/app/web/plugins/deepseek-ai__dsh-client-ui-chat/client.js +2 -2
- package/app/web/plugins/deepseek-ai__dsh-client-ui-codexhost/client.js +63 -62
- package/app/web/plugins/deepseek-ai__dsh-client-ui-conversation/client.js +85 -85
- package/app/web/plugins/deepseek-ai__dsh-client-ui-directory-picker-browse/client.js +10 -10
- package/app/web/plugins/deepseek-ai__dsh-client-ui-input-trigger/client.js +1 -1
- package/app/web/plugins/deepseek-ai__dsh-client-ui-layout/client.js +3 -3
- package/app/web/plugins/deepseek-ai__dsh-client-ui-model-selection/client.js +2 -2
- package/app/web/plugins/deepseek-ai__dsh-client-ui-permission-presets/client.js +1 -1
- package/app/web/plugins/deepseek-ai__dsh-client-ui-sidebar/client.js +1 -1
- package/app/web/plugins/deepseek-ai__dsh-client-ui-sidebar-right/client.js +55 -55
- package/app/web/plugins/deepseek-ai__dsh-client-ui-tool/client.js +18 -18
- package/app/web/plugins/deepseek-ai__dsh-client-ui-workspace/client.js +8 -8
- package/app/web/sw.js +55 -24
- package/app/web-modules/server.mjs +1091 -680
- package/bin/codexhost +0 -0
- package/libexec/codexhost-shim +0 -0
- package/libexec/codexhost-updater +0 -0
- package/package.json +1 -1
- package/app/plugins/codex-cli/manifest.json +0 -16
- package/app/plugins/codex-cli/plugin.mjs +0 -20374
- package/app/web/assets/index-CIeTchMu.css +0 -1
- package/app/web/assets/index-DeAPBQbV.js +0 -199
- /package/app/{plugins/codex-cli/assets/icon.png → web/codex.png} +0 -0
|
@@ -7,8 +7,8 @@ default:throw Error(`unreachable context form: ${String(e)}`)}}let Ne=`@deepseek
|
|
|
7
7
|
/* v8 ignore next 2 -- scan() stops stepping once the view is invalid. */
|
|
8
8
|
case`invalid`:return;
|
|
9
9
|
/* v8 ignore next 2 -- Every scanner mode has a handler above. */
|
|
10
|
-
default:Ot(this.#r)}}fail(){this.#d=this.#n,this.#r=`invalid`,this.#c=null}beginKey(e){this.#r=`key`,this.#a=e+1,this.#o=!1,this.#i=!1}stepKey(e,t){if(e<` `){this.fail();return}if(this.#i){this.#i=!1;return}if(e===`\\`){this.#i=!0,this.#o=!0;return}if(e!==`"`)return;let n=this.slice(this.#a,t);if(this.#o)try{this.#s=JSON.parse(`"${n}"`)}catch{this.fail();return}else this.#s=n;this.#r=`colon`}open(e){this.#p.has(this.#s)||this.#m.push(this.#s),this.#p.set(this.#s,e),this.#c=e}beginValue(e,t){Tt(e)||(e===`"`?(this.open({kind:`string`,start:t+1,end:-1,needsDecoding:!1,invalidAt:void 0,length:void 0,text:void 0,prefixes:void 0}),this.#i=!1,this.#r=`string`):e===`}`||e===`,`||e===`:`||e===`]`?this.fail():(this.open({kind:`value`,start:t,end:-1,parsed:void 0,invalid:!1}),e===`{`||e===`[`?(this.#r=`nested`,this.#l=[e===`{`?`}`:`]`],this.#u=!1,this.#i=!1):this.#r=`scalar`))}stepScalar(e,t){(e===`,`||e===`}`||Tt(e))&&(this.closeValue(t),this.#r=e===`,`?`key-only`:e===`}`?`closed`:`comma-or-end`)}stepNested(e,t){if(this.#u)this.#u=!1;else if(e===`"`)this.#u=!0;else if(e===`{`||e===`[`)this.#l.push(e===`{`?`}`:`]`);else if(e===`}`||e===`]`){if(this.#l.pop()!==e){this.fail();return}this.#l.length===0&&(this.closeValue(t+1),this.#r=`comma-or-end`)}}closeValue(e){let t=this.#c;t.end=e,this.#c=null}};function Ot(e,t){let n=JSON.stringify(e)??String(e);throw Error(`unreachable variant${t?` in ${t}`:``}: ${n}`)}function kt(e){switch(e.kind){case`node`:return JSON.stringify([`node`,e.key,e.groupPart??null]);case`group`:return JSON.stringify([`group`,e.key]);default:return Ot(e)}}function At(e,t){let n=e.counts.slice(0,3).map(({kind:e})=>t(`message.stepProcess.done.${e}`)),r=n[0];if(r===void 0)return t(`message.stepProcess.done.thinking`);let i=e=>e.charAt(0).toLowerCase()+e.slice(1),a=n[1];if(a===void 0)return r;if(n.length===2){let e=t(`message.stepProcess.sharedPrefix`);return t(`message.stepProcess.joinTwo`,{first:r,second:i(e!==``&&r.startsWith(e)&&a.startsWith(e)?a.slice(e.length):a)})}let o=[r,...n.slice(1).map(i)].join(t(`message.stepProcess.comma`));return e.counts.length>3?t(`message.stepProcess.more`,{title:o}):o}function jt(e=0){let[t,n]=(0,d.useState)(null);return{expanded:t===e,setExpanded:(0,d.useCallback)(t=>{n(t?e:null)},[e]),toggle:(0,d.useCallback)(()=>{n(t=>t===e?null:e)},[e])}}function Mt(e){let t=t=>e.subscribe(t),n=()=>e.getSnapshot();return function(){return jt((0,d.useSyncExternalStore)(t,n))}}function Nt(e){let t=e.clientHeight;return{top:e.scrollTop,height:t,floor:Math.max(0,e.scrollHeight-t)}}var Pt=class e{following;threshold;static owners=/* @__PURE__ */ new WeakMap;target=null;sampledTop;constructor(e,t){this.following=e,this.threshold=t}static forElement(e){return this.owners.get(e)}bind(t){return e.owners.set(t,this),()=>{e.owners.get(t)===this&&e.owners.delete(t)}}get active(){return this.following}get animating(){return this.target!==null}nearBottom(e){return e.floor-e.top<=this.threshold}setFollowing(e){this.following=e,e||(this.target=null)}reset(){this.setFollowing(!1),this.sampledTop=void 0}sample(e,t=this.sampledTop===void 0||Math.abs(e.top-this.sampledTop)>.5){return this.sampledTop=e.top,!this.animating&&t&&(this.following=this.nearBottom(e)),this.active}settle(e){let t=this.target;return this.target=null,this.sample(e,t===null?void 0:Math.abs(e.top-Math.min(t,e.floor))>this.threshold)}jump(e,t,n){let r=this.animating;this.target=null;let i=Math.max(0,Math.min(t.floor,n));r?e.scrollTo({top:i,behavior:`instant`}):i!==t.top&&(e.scrollTop=i);let a={...t,top:e.scrollTop};return this.sampledTop=a.top,this.following=this.nearBottom(a),a}toBottom(e,t,n){return this.following=!0,n===`instant`||t.top>=t.floor||!this.animating&&this.nearBottom(t)||typeof matchMedia==`function`&&matchMedia(`(prefers-reduced-motion: reduce)`).matches?this.jump(e,t,t.floor):(this.target===null&&(this.target=t.floor,e.scrollTo({top:t.floor,behavior:`smooth`})),t)}interrupt(e,t){this.animating&&(this.target=null,this.sampledTop=t.top,e.scrollTo({top:t.top,behavior:`instant`}))}};function Ft(e,t){let[n]=(0,d.useState)(()=>new Pt(e,t));return n}let It={canScrollUp:!1,canScrollDown:!1},Lt=/* @__PURE__ */ new Set([`ArrowUp`,`ArrowDown`,`PageUp`,`PageDown`,`Home`,`End`,` `]);function Rt(e,t,n,r){let i=Ft(!1,1),a=(0,d.useRef)(null),[o,s]=(0,d.useState)(It),c=(0,d.useCallback)(e=>{a.current=e},[]),l=(0,d.useCallback)(t=>{let n=e.current,r=It;if(n!==null&&n.closest(`[hidden], [data-group-expanded-mode]`)===null){let e=Nt(n),o=t===`resize`?a.current:null;if(o!==null)e=i.jump(n,e,o===`bottom`?e.floor:0),o===`top`&&i.setFollowing(!1),a.current=null;else{let r=i.animating;t===`scrollend`?i.settle(e):i.sample(e),i.active&&(t===`resize`||t===`scrollend`&&r)&&(e=i.toBottom(n,e,`smooth`))}r={canScrollUp:e.top>1,canScrollDown:e.top<e.floor-1}}else i.reset();s(e=>e.canScrollUp===r.canScrollUp&&e.canScrollDown===r.canScrollDown?e:r)},[e,i]),u=(0,d.useCallback)(()=>{let t=e.current;t!==null&&i.animating&&i.interrupt(t,Nt(t))},[e,i]),f=(0,d.useMemo)(()=>({onScroll:()=>{l(`scroll`)},onWheel:u,onTouchStart:u,onPointerDown:u,onKeyDown:e=>{!e.defaultPrevented&&Lt.has(e.key)&&u()}}),[u,l]);return(0,d.useLayoutEffect)(()=>{u(),i.reset(),(!r||!n)&&(a.current=null)},[i,r,u,n]),(0,d.useLayoutEffect)(()=>{let r=e.current;if(r===null||!n||typeof ResizeObserver>`u`)return;let a=i.bind(r),o=new ResizeObserver(()=>{l(`resize`)}),s=e=>{e.target===r&&l(`scrollend`)};return r.addEventListener(`scrollend`,s),o.observe(r),t.current!==null&&o.observe(t.current),()=>{a(),o.disconnect(),r.removeEventListener(`scrollend`,s)}},[e,t,i,n,l]),{edges:o,events:f,initialize:c}}let zt=`@deepseek-ai/dsh-client-ui-chat/ChatGroupSeat.module.css`;if(typeof document<`u`&&document.querySelector(`style[data-plugin-css=`+JSON.stringify(zt)+`]`)===null){let e=document.createElement(`style`);e.dataset.plugin=`@deepseek-ai/dsh-client-ui-chat`,e.dataset.pluginCss=zt,e.textContent=`.yzVGVG_root{min-width:0}.yzVGVG_title{max-width:100%;color:var(--dsw-alias-label-tertiary);font:inherit;font-size:var(--dsh-content-font-size,14px);text-align:left;cursor:pointer;background:0 0;border:0;align-items:center;gap:6px;padding:0;transition:color .1s;display:flex}.yzVGVG_title:hover{color:var(--dsw-alias-label-secondary)}.yzVGVG_leading{width:calc(16px + var(--dsh-content-font-delta,0px));height:calc(16px + var(--dsh-content-font-delta,0px));color:inherit;flex:none;justify-content:center;align-items:center;display:inline-flex;position:relative}.yzVGVG_leading svg{width:calc(14px + var(--dsh-content-font-delta,0px));height:calc(14px + var(--dsh-content-font-delta,0px))}.yzVGVG_leading svg[width="16"]{width:calc(16px + var(--dsh-content-font-delta,0px));height:calc(16px + var(--dsh-content-font-delta,0px))}.yzVGVG_activityIcon,.yzVGVG_chevron{justify-content:center;align-items:center;transition:opacity .1s;display:inline-flex;position:absolute;inset:0}.yzVGVG_activityIcon{opacity:1}.yzVGVG_chevron,.yzVGVG_title:is(:hover,:focus-visible) .yzVGVG_activityIcon{opacity:0}.yzVGVG_title:is(:hover,:focus-visible) .yzVGVG_chevron{opacity:1}.yzVGVG_title[aria-expanded=true] .yzVGVG_activityIcon{opacity:0}.yzVGVG_title[aria-expanded=true] .yzVGVG_chevron{opacity:1}.yzVGVG_title[aria-expanded=true]{padding-bottom:8px}.yzVGVG_body{--dsh-chat-flow-gap:6px;overscroll-behavior-y:auto;scrollbar-gutter:stable;max-height:min(400px,50vh);overflow-y:auto}.yzVGVG_label{text-overflow:ellipsis;white-space:nowrap;min-width:0;overflow:hidden}.yzVGVG_fadeTop{mask-image:linear-gradient(#0000 0,#000 24px 100%)}.yzVGVG_fadeBottom{mask-image:linear-gradient(#000 0 calc(100% - 24px),#0000 100%)}.yzVGVG_fadeTop.yzVGVG_fadeBottom{mask-image:linear-gradient(#0000 0,#000 24px calc(100% - 24px),#0000 100%)}@media (prefers-reduced-motion:reduce){.yzVGVG_title,.yzVGVG_activityIcon,.yzVGVG_chevron{transition:none}}.yzVGVG_content{flex-direction:column;display:flex}.yzVGVG_content>*{flex-shrink:0}.yzVGVG_content>:not([hidden]):not(:empty)~:not([hidden]):not(:empty){margin-top:var(--dsh-chat-flow-gap,6px)}.yzVGVG_expandedBody{scrollbar-gutter:auto;max-height:none;overflow:visible}`,document.head.appendChild(e)}var W={activityIcon:`yzVGVG_activityIcon`,body:`yzVGVG_body`,chevron:`yzVGVG_chevron`,content:`yzVGVG_content`,expandedBody:`yzVGVG_expandedBody`,fadeBottom:`yzVGVG_fadeBottom`,fadeTop:`yzVGVG_fadeTop`,label:`yzVGVG_label`,leading:`yzVGVG_leading`,root:`yzVGVG_root`,title:`yzVGVG_title`};let Bt={thinking:/* @__PURE__ */ (0,f.jsx)(p.IconThinkOutlineRegular,{}),read:/* @__PURE__ */ (0,f.jsx)(p.IconBrowseOutlineRegular,{size:14}),readImage:/* @__PURE__ */ (0,f.jsx)(p.IconBrowseOutlineRegular,{size:14}),search:/* @__PURE__ */ (0,f.jsx)(p.IconSearchOutlineRegular,{size:14}),edit:/* @__PURE__ */ (0,f.jsx)(p.IconEditOutlineRegular,{size:14}),write:/* @__PURE__ */ (0,f.jsx)(p.IconEditOutlineRegular,{size:14}),commands:/* @__PURE__ */ (0,f.jsx)(p.IconApiOutlineRegular,{}),code:/* @__PURE__ */ (0,f.jsx)(p.IconCodeOutlineRegular,{size:14}),webSearch:/* @__PURE__ */ (0,f.jsx)(p.IconGlobeOutlineRegular,{}),webFetch:/* @__PURE__ */ (0,f.jsx)(p.IconBrowseOutlineRegular,{size:14}),subagents:/* @__PURE__ */ (0,f.jsx)(p.IconAgentPresetOutlineRegular,{size:14}),plan:/* @__PURE__ */ (0,f.jsx)(p.IconPlanOutlineRegular,{}),questions:/* @__PURE__ */ (0,f.jsx)(p.IconQuestionOutlineRegular,{}),tools:/* @__PURE__ */ (0,f.jsx)(p.IconSparkleRegular,{size:14})};function Vt(e,t){return e.activity===t.activity&&e.detail===t.detail&&e.preparing===t.preparing}function Ht(e,t){let[n,r]=(0,d.useState)(e),i=(0,d.useRef)(n),a=(0,d.useRef)(e),o=(0,d.useRef)(Date.now());return(0,d.useEffect)(()=>{if(a.current=e,!t||Vt(i.current,e))return;let n=150-(Date.now()-o.current),s=()=>{let e=a.current;i.current=e,o.current=Date.now(),r(e)};if(n<=0){s();return}let c=setTimeout(s,n);return()=>{clearTimeout(c)}},[t,e.activity,e.detail,e.preparing]),t?n:e}let Ut=(0,d.memo)(function({members:e,...t}){return e.map(e=>/* @__PURE__ */ (0,d.createElement)(St,{...t,key:kt(e),nodeKey:e.key,...e.groupPart===void 0?{}:{groupPart:e.groupPart}}))}),Wt=(0,d.memo)(function({groupKey:e,useChatGroup:t,usePresentation:n,t:r,open:i,bodyId:a,toggle:o}){let s=t(e,e=>e?.data),c=n(e=>s?.closed===!1&&e.liveProcessDetail),l=Ht({activity:s?.summary.running??`thinking`,detail:s?.summary.runningDetail??``,preparing:s?.summary.preparing===!0},s!==void 0&&!s.closed);if(s===void 0)return null;let u=s.closed?At(s.summary,r):l.preparing?r(`message.stepProcess.prepare.${l.activity===`thinking`?`tools`:l.activity}`):r(`message.stepProcess.${l.activity}`),d=c&&!s.closed?l.detail:``,m=d===``?u:`${u}${r(`message.turnProcess.separator`)}${d}`,h=s.closed?s.summary.counts[0]?.kind??`thinking`:l.activity;return/* @__PURE__ */ (0,f.jsxs)(`button`,{type:`button`,className:W.title,"aria-expanded":i,"aria-controls":a,"data-process-activity":h,onClick:e=>{e.currentTarget.focus(),o()},children:[/* @__PURE__ */ (0,f.jsxs)(`span`,{className:W.leading,"aria-hidden":`true`,children:[/* @__PURE__ */ (0,f.jsx)(`span`,{className:W.activityIcon,"data-step-process-icon":!0,children:Bt[h]}),/* @__PURE__ */ (0,f.jsx)(`span`,{className:W.chevron,"data-step-process-chevron":!0,children:i?/* @__PURE__ */ (0,f.jsx)(p.IconChevronUpOutlineRegular,{}):/* @__PURE__ */ (0,f.jsx)(p.IconChevronDownOutlineRegular,{})})]}),/* @__PURE__ */ (0,f.jsx)(p.TextShimmer,{active:!s.closed,children:/* @__PURE__ */ (0,f.jsx)(p.TextShimmer,{className:W.label,children:m})})]})}),Gt=(0,d.memo)(function({groupKey:e,useChatGroup:t,...n}){let r=t(e,e=>e?.members),i=t(e,e=>e?.data.turn),a=t(e,e=>e?.data.closed),o=n.usePresentation(e=>e.foldCompletedTurns),{expanded:s,setExpanded:c}=jt(),l=r?.[0]?.key??``,u=n.useChatNodeProcess(l),p=n.useChatNode(l,e=>{let t=e?.location;return t?.kind===`turn`||t?.kind===`step`?t.turn:void 0}),m=n.usePresentation(e=>e.stepGrouping===`collapsed`||e.stepGrouping===`history`&&p?.status!==`open`),h=p?.end?.data.reason.kind,g=u?.turnClosed===!1||u?.hasInterleavedInput===!0||p?.end?.data.finalAssistantStep===null||h===`aborted`||h===`error`,_=u?.spec,v=(0,d.useCallback)(e=>i===void 0?void 0:ht(e,i),[i]),y=n.useStore(v),b=o&&u?.turnClosed===!0&&_!==void 0&&!g&&y?.answerStep!==(_.answerStep??0),x=_t(b,(0,d.useCallback)(()=>{_!==void 0&&!g&&n.actions.setTurnProcessOpen(_.turn,_.answerStep??0,!0)},[n.actions,_,g]));(0,d.useEffect)(()=>{b&&x.current?.hasAttribute(`hidden`)&&c(!1)},[b,x,c]);let S=(0,d.useCallback)(()=>{c(!0)},[c]),C=_t(m&&!s,S),w=(0,d.useRef)(null),T=(0,d.useId)(),{edges:E,events:D,initialize:O}=Rt(C,w,s,m),k=(0,d.useCallback)(()=>{s||O(a===!1?`bottom`:`top`),c(!s)},[a,O,s,c]);if(r===void 0)return null;let A=[W.body,m?``:W.expandedBody,m&&E.canScrollUp?W.fadeTop:``,m&&E.canScrollDown?W.fadeBottom:``];return/* @__PURE__ */ (0,f.jsxs)(`div`,{ref:x,className:W.root,"data-chat-group-key":e,"data-chat-flow-key":e,"data-chat-anchor-key":`group:${e}`,"data-chat-turn":i,"data-chat-paging-anchor":m&&!s||void 0,"data-step-process":!0,"data-group-expanded-mode":!m||void 0,children:[/* @__PURE__ */ (0,f.jsx)(`div`,{hidden:!m,children:/* @__PURE__ */ (0,f.jsx)(Wt,{groupKey:e,useChatGroup:t,usePresentation:n.usePresentation,t:n.t,open:s,bodyId:T,toggle:k})}),/* @__PURE__ */ (0,f.jsx)(`div`,{ref:C,id:T,className:A.join(` `),"data-step-process-body":!0,"data-scroll-up":E.canScrollUp||void 0,"data-scroll-down":E.canScrollDown||void 0,...D,children:/* @__PURE__ */ (0,f.jsx)(`div`,{ref:w,className:W.content,"data-step-process-content":!0,"data-chat-flow":``,children:/* @__PURE__ */ (0,f.jsx)(Ut,{...n,members:r})})})]})});function Kt(e){return typeof e==`object`?e.key:e}function qt(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 Jt(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 Yt(e,t){if(e===void 0)throw Error(`Unexpected undefined${t?`: ${t}`:``}`);return e}let Xt=(e,t)=>Math.abs(e-t)<1.01,Zt=(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)}})},Qt,$t=()=>{if(Qt!==void 0)return Qt;if(typeof navigator>`u`)return Qt=!1;if(/iP(hone|od|ad)/.test(navigator.userAgent))return Qt=!0;let e=navigator.maxTouchPoints;return Qt=navigator.platform===`MacIntel`&&e!==void 0&&e>0},en=e=>{let{offsetWidth:t,offsetHeight:n}=e;return{width:t,height:n}},tn=e=>e,nn=e=>{let t=Math.max(e.startIndex-e.overscan,0),n=Math.min(e.endIndex+e.overscan,e.count-1)-t+1,r=Array(n);for(let e=0;e<n;e++)r[e]=t+e;return r},rn=(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(en(n)),!r.ResizeObserver)return()=>{};let a=new r.ResizeObserver(t=>{let r=()=>{let e=t[0];if(e?.borderBoxSize){let t=e.borderBoxSize[0];if(t){i({width:t.inlineSize,height:t.blockSize});return}}i(en(n))};e.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(r):r()});return a.observe(n,{box:`border-box`}),()=>{a.unobserve(n)}},an={passive:!0},on=typeof window>`u`||`onscrollend`in window,sn=(e,t,n)=>{let r=e.scrollElement;if(!r)return;let i=e.targetWindow;if(!i)return;let a=e.options.useScrollendEvent&&on,o=0,s=a?null:Zt(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,an),a&&r.addEventListener(`scrollend`,u,an),()=>{r.removeEventListener(`scroll`,l),a&&r.removeEventListener(`scrollend`,u),s?.cancel()}},cn=(e,t)=>sn(e,t,t=>{let{horizontal:n,isRtl:r}=e.options;return n?t.scrollLeft*(r&&-1||1):t.scrollTop}),ln=(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`]},un=(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})};function dn(e,t,n,r){if(t===0)return!1;let i=r(0),a=/* @__PURE__ */ 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 fn=class{constructor(e){this.unsubs=[],this.scrollElement=null,this.targetWindow=null,this.isScrolling=!1,this.scrollState=null,this.measurementsCache=[],this._singleLaneMeasurements=null,this.itemSizeCache=/* @__PURE__ */ new Map,this.itemSizeCacheVersion=0,this.laneAssignments=/* @__PURE__ */ 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.scrollAdjustments=0,this._iosDeferredAdjustment=0,this._iosTouching=!1,this._iosJustTouchEnded=!1,this._iosTouchEndTimerId=null,this._intendedScrollOffset=null,this._clampedAdjustment=null,this.elementsCache=/* @__PURE__ */ new Map,this.now=()=>{var e;return((e=this.targetWindow?.performance)?.now)?.call(e)??Date.now()},this.observer=/* @__PURE__ */ (()=>{let e=null,t=()=>e||(!this.targetWindow||!this.targetWindow.ResizeObserver?null:e=new this.targetWindow.ResizeObserver(e=>{e.forEach(e=>{let t=()=>{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}}};this.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(t):t()})}));return{disconnect:()=>{var n;(n=t())==null||n.disconnect(),e=null},observe:e=>t()?.observe(e,{box:`border-box`}),unobserve:e=>t()?.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:tn,rangeExtractor:nn,onChange:()=>{},measureElement:ln,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=>Kt(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||dn(e,o,l,t.getItemKey))&&(i=u)}}this.options=t,a&&(this.pendingMin=0,this.itemSizeCacheVersion++);let o=!1,s=0;if(r&&this.scrollOffset!==null){let[e,t]=r,n=this.getMeasurements(),{count:a,getItemKey:c}=this.options,l=0;for(;l<a&&c(l)!==e;)l++;if(l<a){let e=n[l];if(e){let n=Math.max(0,e.start+t);!i&&n!==this.scrollOffset&&(s=n-this.scrollOffset,this.scrollOffset=n,o=!0)}}}(o||i)&&(this.pendingScrollAnchor=[o?r[0]:null,o?r[1]:0,i,s])},this.notify=e=>{var t,n;(n=(t=this.options).onChange)==null||n.call(t,this,e)},this.maybeNotify=Jt(()=>(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=()=>{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,this.isScrolling=!1,this.scrollDirection=null,this._iosDeferredAdjustment=0,this._iosTouching=!1,this._iosJustTouchEnded=!1,this._clampedAdjustment=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}if(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)=>{if(t&&this._intendedScrollOffset===null&&e===this.scrollOffset)return;this._intendedScrollOffset!==null&&Math.abs(e-this._intendedScrollOffset)<1.5&&(e=this._intendedScrollOffset),this._intendedScrollOffset=null,this._clampedAdjustment!==null&&Math.abs(e-this._clampedAdjustment.maxAtWrite)>=1.5&&(this._clampedAdjustment=null),this.scrollAdjustments=0;let n=this.getScrollOffset();this.scrollDirection=t?n===e?this.scrollDirection:n<e?`forward`:`backward`:null,this.scrollOffset=e,this.isScrolling=t,this._flushIosDeferredIfReady(),this.scrollState&&this.scheduleScrollReconcile(),this.maybeNotify()})),`addEventListener`in this.scrollElement){let e=this.scrollElement,t=()=>{this._iosTouching=!0,this._iosJustTouchEnded=!1,this._iosTouchEndTimerId!==null&&this.targetWindow!=null&&(this.targetWindow.clearTimeout(this._iosTouchEndTimerId),this._iosTouchEndTimerId=null)},n=()=>{this._iosTouching=!1,$t()&&this.targetWindow!=null&&(this._iosJustTouchEnded=!0,this._iosTouchEndTimerId=this.targetWindow.setTimeout(()=>{this._iosJustTouchEnded=!1,this._iosTouchEndTimerId=null,this._flushIosDeferredIfReady()},150))};e.addEventListener(`touchstart`,t,an),e.addEventListener(`touchend`,n,an),this.unsubs.push(()=>{e.removeEventListener(`touchstart`,t),e.removeEventListener(`touchend`,n),this._iosTouchEndTimerId!==null&&this.targetWindow!=null&&(this.targetWindow.clearTimeout(this._iosTouchEndTimerId),this._iosTouchEndTimerId=null)})}this._scrollToOffset(this.getScrollOffset(),{adjustments:void 0,behavior:void 0})}let t=this.pendingScrollAnchor;if(this.pendingScrollAnchor=null,t&&this.scrollElement&&this.options.enabled){let[e,n,r,i]=t;e!==null&&!r&&($t()&&(this.isScrolling||this._iosTouching||this._iosJustTouchEnded)?i!==0&&(this._iosDeferredAdjustment+=i):this.scrollState?.behavior===`smooth`&&!Xt(this.getScrollOffset()-i,this.scrollState.lastTargetOffset)||this._scrollToOffset(this.getScrollOffset(),{adjustments:void 0,behavior:void 0})),r&&this.scrollToEnd({behavior:r})}this._retryClampedAdjustment()},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,{adjustments:void 0,behavior:void 0}))},this._flushIosDeferredIfReady=()=>{if(this._iosDeferredAdjustment===0||this.isScrolling||this._iosTouching||this._iosJustTouchEnded)return;let e=this.getScrollOffset(),t=this.getMaxScrollOffset();if(e<0||e>t)return;if(this._iosDeferredAdjustment<0&&e>=t-1){this._iosDeferredAdjustment=0;return}let n=this._iosDeferredAdjustment;this._iosDeferredAdjustment=0,this._scrollToOffset(e,{adjustments:this.scrollAdjustments+=n,behavior:void 0})},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=Jt(()=>[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=Jt(()=>[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=qt(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=Jt(()=>[this.getMeasurements(),this.getSize(),this.getScrollOffset(),this.options.lanes],(e,t,n,r)=>e.length===0||t===0?(this.range=null,null):(this.range=hn(e,t,n,r,r===1&&this._singleLaneMeasurements!==null?this._singleLaneMeasurements.flat:null),this.range),{key:!1,debug:()=>this.options.debug}),this.getVirtualIndexes=Jt(()=>{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]},(e,t,n,r,i)=>r===null||i===null?[]:e({startIndex:r,endIndex:i,overscan:t,count:n}),{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(!this.scrollState||this.scrollState.behavior!==`smooth`)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)),(!this.isScrolling||this.scrollState)&&this.shouldMeasureDuringScroll(t)&&this.resizeItem(t,this.options.measureElement(e,void 0,this))},this.resizeItem=(e,t)=>{if(!this.isIndexInRange(e))return;let n,r,i,a=this._singleLaneMeasurements?.flat;if(this.options.lanes===1&&a!=null)i=this.options.getItemKey(e),r=a[e*2],n=a[e*2+1];else{let t=this.measurementsCache[e];if(!t)return;i=t.key,r=t.start,n=t.size}let o=this.itemSizeCache.get(i)??n,s=t-o;if(s!==0){let a=this.options.anchorTo===`end`&&this.scrollState?.behavior!==`smooth`&&this.getVirtualDistanceFromEnd()<=this.options.scrollEndThreshold,c=a?this.getTotalSize():0,l=this.getScrollOffset()+this.scrollAdjustments,u=this.itemSizeCache.has(i)?r+o<=l&&this.scrollDirection!==`backward`:r<l,d=this.scrollState?.behavior!==`smooth`&&(this.shouldAdjustScrollPositionOnItemSizeChange===void 0?u:this.shouldAdjustScrollPositionOnItemSizeChange(this.measurementsCache[e]??{index:e,key:i,start:r,size:n,end:r+n,lane:0},s,this));(this.pendingMin===null||e<this.pendingMin)&&(this.pendingMin=e),this.itemSizeCache.set(i,t),this.itemSizeCacheVersion++;let f=!1;a?f=this.applyScrollAdjustment(this.getTotalSize()-c):d&&(f=this.applyScrollAdjustment(s)),this.notify(f),this._retryClampedAdjustment()}},this.getVirtualItems=Jt(()=>[this.getVirtualIndexes(),this.getMeasurements()],(e,t)=>{let n=[];for(let r=0,i=e.length;r<i;r++){let i=t[e[r]];n.push(i)}return n},{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 Yt(t[pn(0,t.length-1,r?e=>n[e*2]:e=>Yt(t[e]).start,e)])},this.getMaxScrollOffset=()=>{if(!this.scrollElement)return 0;if(`scrollHeight`in this.scrollElement)return this.options.horizontal?this.scrollElement.scrollWidth-this.scrollElement.clientWidth:this.scrollElement.scrollHeight-this.scrollElement.clientHeight;{let e=this.scrollElement.document.documentElement;return this.options.horizontal?e.scrollWidth-this.scrollElement.innerWidth:e.scrollHeight-this.scrollElement.innerHeight}},this.getVirtualDistanceFromEnd=()=>Math.max(this.getTotalSize()-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)return[this.getMaxScrollOffset(),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._iosDeferredAdjustment=0;let r=this.getOffsetForAlignment(e,t),i=this.now();this.scrollState={index:null,align:t,behavior:n,startedAt:i,lastTargetOffset:r,stableFrames:0},this._scrollToOffset(r,{adjustments:void 0,behavior:n}),this.scheduleScrollReconcile()},this.scrollToIndex=(e,{align:t=`auto`,behavior:n=`auto`}={})=>{this._iosDeferredAdjustment=0,e=Math.max(0,Math.min(e,this.options.count-1));let r=this.getOffsetForIndex(e,t);if(!r)return;let[i,a]=r,o=this.now();this.scrollState={index:e,align:a,behavior:n,startedAt:o,lastTargetOffset:i,stableFrames:0},this._scrollToOffset(i,{adjustments:void 0,behavior:n}),this.scheduleScrollReconcile()},this.scrollBy=(e,{behavior:t=`auto`}={})=>{let n=this.getScrollOffset()+e,r=this.now();this.scrollState={index:null,align:`start`,behavior:t,startedAt:r,lastTargetOffset:n,stableFrames:0},this._scrollToOffset(n,{adjustments:void 0,behavior:t}),this.scheduleScrollReconcile()},this.scrollToEnd=({behavior:e=`auto`}={})=>{this.options.count>0?this.scrollToIndex(this.options.count-1,{align:`end`,behavior:e}):this.scrollToOffset(Math.max(this.getTotalSize()-this.getSize(),0),{behavior:e})},this.getTotalSize=()=>{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})=>{this._intendedScrollOffset=e+(t??0),this.options.scrollToFn(e,{behavior:n,adjustments:t},this)},this.measure=()=>{this.pendingMin=null,this.itemSizeCache.clear(),this.laneAssignments.clear(),this.itemSizeCacheVersion++,this.notify(!1)},this.setOptions(e)}applyScrollAdjustment(e,t){if(e===0)return!1;if($t()&&(this.isScrolling||this._iosTouching||this._iosJustTouchEnded))return this._iosDeferredAdjustment+=e,!1;{let n=this.getScrollOffset()+this.scrollAdjustments+e,r=this.scrollElement,i=r!==null&&(`scrollHeight`in r||`document`in r)?this.getMaxScrollOffset():null;return this._clampedAdjustment=i!==null&&n>i+.5?{target:n,maxAtWrite:i}:null,this._scrollToOffset(this.getScrollOffset(),{adjustments:this.scrollAdjustments+=e,behavior:t}),this.scrollOffset!==null&&(this.scrollOffset+=this.scrollAdjustments,this.scrollOffset<0&&(this.scrollOffset=0),this.scrollAdjustments=0),!0}}scheduleScrollReconcile(){this.targetWindow?this.rafId??=this.targetWindow.requestAnimationFrame(()=>{this.rafId=null,this.reconcileScroll()}):this.scrollState=null}reconcileScroll(){if(!this.scrollState||!this.scrollElement)return;if(this.now()-this.scrollState.startedAt>5e3){this.scrollState=null;return}let e=this.scrollState.index==null?void 0:this.getOffsetForIndex(this.scrollState.index,this.scrollState.align),t=e?e[0]:this.scrollState.lastTargetOffset,n=t!==this.scrollState.lastTargetOffset;if(!n&&Xt(t,this.getScrollOffset())){if(this.scrollState.stableFrames++,this.scrollState.stableFrames>=1){this.getScrollOffset()!==t&&this._scrollToOffset(t,{adjustments:void 0,behavior:`auto`}),this.scrollState=null;return}}else if(this.scrollState.stableFrames=0,n){let e=this.getSize()||600,n=Math.abs(t-this.getScrollOffset()),r=this.scrollState.behavior===`smooth`&&n>e;this.scrollState.lastTargetOffset=t,r||(this.scrollState.behavior=`auto`),this._scrollToOffset(t,{adjustments:void 0,behavior:r?`smooth`:`auto`})}this.scheduleScrollReconcile()}};let pn=(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 mn(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 hn(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=mn(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=pn(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}}let gn=typeof document<`u`?d.useLayoutEffect:d.useEffect;function _n({useFlushSync:e=!0,directDomUpdates:t=!1,directDomUpdatesMode:n=`transform`,...r}){let i=d.useReducer(e=>e+1,0)[1],a=d.useRef({enabled:t,mode:n,container:null,lastSize:null,lastPositions:/* @__PURE__ */ new WeakMap,prevRange:null});a.current.enabled=t,a.current.mode=n;let o=d.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=>{let t=a.current;if(!t.enabled||!t.container)return;s(e);let n=!!e.options.horizontal,r=t.mode===`transform`,i=n?`left`:`top`,o=e.options.scrollMargin,c=e.getVirtualItems();for(let a of c){let s=a.start-o,c=e.elementsCache.get(a.key);c&&t.lastPositions.get(c)!==s&&(t.lastPositions.set(c,s),r?c.style.transform=n?`translate3d(${s}px, 0, 0)`:`translate3d(0, ${s}px, 0)`:c.style[i]=`${s}px`)}},l={...r,onChange:(t,n)=>{var s;let l=a.current,u=!0;if(l.enabled){c(t);let e=t.range,n=l.prevRange;u=!n||n.isScrolling!==t.isScrolling||n.startIndex!==e?.startIndex||n.endIndex!==e?.endIndex,u&&(l.prevRange=e?{startIndex:e.startIndex,endIndex:e.endIndex,isScrolling:t.isScrolling}:null)}u&&(e&&n&&!o.current?(0,h.flushSync)(i):i()),(s=r.onChange)==null||s.call(r,t,n)}},[u]=d.useState(()=>{let e=new fn(l),t=e.measureElement;return e.measureElement=e=>{o.current=!0;try{t(e)}finally{o.current=!1}},Object.assign(e,{containerRef:t=>{let n=a.current;if(n.container=t,n.lastSize=null,t&&n.enabled){let r=e.getTotalSize();n.lastSize=r;let i=e.options.horizontal?`width`:`height`;t.style[i]=`${r}px`}}})});return u.setOptions(l),gn(()=>u._didMount(),[]),gn(()=>(s(u),u._willUpdate())),gn(()=>{c(u)}),u}function vn(e){return _n({observeElementRect:rn,observeElementOffset:cn,scrollToFn:un,...e})}let yn=`@deepseek-ai/dsh-client-ui-chat/TurnNavigator.module.css`;if(typeof document<`u`&&document.querySelector(`style[data-plugin-css=`+JSON.stringify(yn)+`]`)===null){let e=document.createElement(`style`);e.dataset.plugin=`@deepseek-ai/dsh-client-ui-chat`,e.dataset.pluginCss=yn,e.textContent=`.FJ_OyG_slot{z-index:7;height:0;padding-inline:calc(var(--dsh-composer-side-clearance) + 16px);pointer-events:none;position:absolute;top:0;left:0;right:0;container-type:inline-size}[data-conversation-scroll] .FJ_OyG_slot{position:sticky}.FJ_OyG_frame{--turn-rail-band:calc(var(--dsh-conversation-viewport-height,100dvh) - var(--dsh-composer-height,152px));--turn-preview-height:104px;top:calc(var(--turn-rail-band) / 2);width:36px;max-height:min(max(0px, calc(var(--turn-rail-band) - 64px)), 70vh, 640px);contain:layout;cursor:pointer;pointer-events:auto;position:absolute;left:12px;transform:translateY(-50%)}.FJ_OyG_frame[hidden]{display:none}.FJ_OyG_scroller{max-height:inherit;overscroll-behavior:contain;scrollbar-width:none;position:relative;overflow-y:auto}.FJ_OyG_scroller::-webkit-scrollbar{display:none}.FJ_OyG_fadeTop{mask-image:linear-gradient(#0000 0,#000 40px 100%)}.FJ_OyG_fadeBottom{mask-image:linear-gradient(#000 0 calc(100% - 40px),#0000 100%)}.FJ_OyG_fadeTop.FJ_OyG_fadeBottom{mask-image:linear-gradient(#0000 0,#000 40px calc(100% - 40px),#0000 100%)}.FJ_OyG_marks{position:relative}.FJ_OyG_mark{cursor:pointer;background:0 0;border:0;border-radius:8px;height:10px;padding:0;position:absolute;top:0;left:0;right:0}.FJ_OyG_mark:before{background:var(--dsw-alias-label-tertiary);opacity:.4;content:"";transform-origin:0;width:26px;height:2px;transition:transform .16s cubic-bezier(.2,.8,.2,1),background-color .16s,opacity .16s;position:absolute;top:50%;left:0;transform:translateY(-50%)scaleX(.230769)}.FJ_OyG_markUnloaded:before{opacity:.25}.FJ_OyG_mark[data-neighbor-distance="3"]:before{transform:translateY(-50%)scaleX(.384615)}.FJ_OyG_mark[data-neighbor-distance="2"]:before{transform:translateY(-50%)scaleX(.538462)}.FJ_OyG_mark[data-neighbor-distance="1"]:before{transform:translateY(-50%)scaleX(.769231)}.FJ_OyG_markBusy:before{animation:1s ease-in-out infinite FJ_OyG_dsh-turn-mark-busy}.FJ_OyG_markActive:before{background:var(--dsw-alias-label-primary);opacity:.6}.FJ_OyG_frame[data-previewing] .FJ_OyG_markActive:not(.FJ_OyG_markPreview):not(:focus-visible):before{background:var(--dsw-alias-label-tertiary);opacity:.4}.FJ_OyG_markPreview:before{background:var(--dsw-alias-label-primary);opacity:1;transform:translateY(-50%)scaleX(1)}.FJ_OyG_frame[data-scrubbing] .FJ_OyG_mark:before{transition:none}.FJ_OyG_mark:focus-visible:before{background:var(--dsw-focus-ring-color,var(--dsw-alias-state-business-primary));opacity:1;transform:translateY(-50%)scaleX(1)}.FJ_OyG_mark:focus-visible{outline:none}.FJ_OyG_mark:focus-visible:after{border-radius:inherit;outline:1px solid var(--dsw-focus-ring-color,var(--dsw-alias-state-business-primary));outline-offset:-1px;content:"";width:28px;position:absolute;inset:0 auto 0 0}.FJ_OyG_preview{top:clamp(0px, calc(var(--turn-preview-center) - var(--turn-preview-height) / 2), calc(100% - var(--turn-preview-height)));box-sizing:border-box;width:min(320px,100cqw - 48px);max-height:var(--turn-preview-height);border:.5px solid var(--dsw-alias-border-l4);color:var(--dsw-alias-label-primary);background:var(--dsw-alias-bg-layer-1);box-shadow:var(--dsw-elevation-panel);pointer-events:none;border-radius:12px;padding:8px;transition:top .14s cubic-bezier(.2,.8,.2,1);animation:.12s ease-out FJ_OyG_dsh-turn-preview-enter;position:absolute;left:100%;overflow:hidden}.FJ_OyG_previewPrompt,.FJ_OyG_previewResponse{-webkit-box-orient:vertical;display:-webkit-box;overflow:hidden}.FJ_OyG_previewPrompt{-webkit-line-clamp:1;font-size:14px;font-weight:500;line-height:20px}.FJ_OyG_previewResponse{color:var(--dsw-alias-label-caption);-webkit-line-clamp:3;margin-top:4px;font-size:14px;line-height:20px}@keyframes FJ_OyG_dsh-turn-preview-enter{0%{opacity:0;transform:translate(-4px)}to{opacity:1;transform:translate(0)}}@keyframes FJ_OyG_dsh-turn-mark-busy{0%,to{opacity:1}50%{opacity:.35}}@media (prefers-reduced-motion:reduce){.FJ_OyG_frame,.FJ_OyG_scroller,.FJ_OyG_mark:before,.FJ_OyG_markBusy:before,.FJ_OyG_preview{scroll-behavior:auto;transition:none;animation:none}}`,document.head.appendChild(e)}var G={"dsh-turn-mark-busy":`FJ_OyG_dsh-turn-mark-busy`,"dsh-turn-preview-enter":`FJ_OyG_dsh-turn-preview-enter`,fadeBottom:`FJ_OyG_fadeBottom`,fadeTop:`FJ_OyG_fadeTop`,frame:`FJ_OyG_frame`,mark:`FJ_OyG_mark`,markActive:`FJ_OyG_markActive`,markBusy:`FJ_OyG_markBusy`,markPreview:`FJ_OyG_markPreview`,markUnloaded:`FJ_OyG_markUnloaded`,marks:`FJ_OyG_marks`,preview:`FJ_OyG_preview`,previewPrompt:`FJ_OyG_previewPrompt`,previewResponse:`FJ_OyG_previewResponse`,scroller:`FJ_OyG_scroller`,slot:`FJ_OyG_slot`};function bn(){return typeof matchMedia==`function`&&matchMedia(`(prefers-reduced-motion: reduce)`).matches?`auto`:`smooth`}let xn=(0,d.memo)(function({item:e,index:t,active:n,busy:r,previewId:i,neighborDistance:a,registerElement:o,onNavigate:s,onPreview:c,onFocusChange:l,t:u}){let d=[G.mark];return e.anchor.kind===`unloaded`&&d.push(G.markUnloaded),n&&d.push(G.markActive),a===0&&d.push(G.markPreview),r&&d.push(G.markBusy),/* @__PURE__ */ (0,f.jsx)(`button`,{ref:o,"data-index":t,"data-neighbor-distance":a,type:`button`,className:d.join(` `),"aria-label":u(e.anchor.kind===`loaded`?`chat.turnNavigation.jump`:`chat.turnNavigation.jumpLoad`,{turn:t+1}),"aria-current":n?`true`:void 0,"aria-busy":r?`true`:void 0,"aria-describedby":i,onPointerMove:t=>{t.buttons===0&&c(e.turn)},onClick:()=>{s(e)},onFocus:()=>{l(e.turn)},onBlur:()=>{l(null)}})});function Sn({items:e,activeTurn:t,busyTurn:n,onNavigate:r,t:i},a){let[o,s]=(0,d.useState)(null),[c,l]=(0,d.useState)(null),[u,p]=(0,d.useState)(!1),[m,h]=(0,d.useState)(!1),[g,_]=(0,d.useState)(!1),v=(0,d.useRef)(null),y=(0,d.useRef)(null),b=(0,d.useRef)(!1),x=(0,d.useRef)(void 0),S=(0,d.useRef)(null),C=(0,d.useRef)({placed:!1,index:0,follow:null,publishOffset:null}),w=(0,d.useRef)(!1),T=(0,d.useId)(),E=e.length>=2;(0,d.useLayoutEffect)(()=>{let e=v.current,t=e?.parentElement?.querySelector(`[data-chat-flow]`),n=e?.closest(`[data-conversation-scroll]`)??e?.parentElement;if(!t||!n)return;let r=()=>{let e=n.getBoundingClientRect(),r=n.offsetWidth>0?e.width/n.offsetWidth:1;h((t.getBoundingClientRect().left-e.left)/(r||1)>=48)},i=new ResizeObserver(r);return i.observe(t),i.observe(n),r(),()=>i.disconnect()},[E]),(0,d.useEffect)(()=>{if(o===null){p(!1);return}if(u)return;let e=setTimeout(()=>p(!0),150);return()=>clearTimeout(e)},[o,u]),(0,d.useEffect)(()=>()=>{clearTimeout(x.current);let e=y.current;y.current=null,e?.button.hasPointerCapture(e.pointerId)&&e.button.releasePointerCapture(e.pointerId)},[]);let D=(0,d.useMemo)(()=>{let t=/* @__PURE__ */ new Map;return e.forEach((e,n)=>{t.set(e.turn,n)}),t},[e]),O=t===null?void 0:D.get(t);(0,d.useLayoutEffect)(()=>{C.current.index=O??0},[O]);let k=c===null?void 0:D.get(c),A=o===null?void 0:D.get(o),j=(0,d.useCallback)(e=>{l(e),s(e),p(e!==null)},[]),M=vn({count:e.length,enabled:E,directDomUpdates:!0,directDomUpdatesMode:`transform`,useScrollendEvent:!0,getScrollElement:(0,d.useCallback)(()=>S.current,[]),getItemKey:(0,d.useCallback)(t=>e[t]?.turn??t,[e]),estimateSize:()=>10,measureElement:()=>10,initialRect:{width:0,height:0},initialOffset:0,scrollToFn:(e,t,n)=>{C.current.placed&&un(e,t,n)},observeElementOffset:(e,t)=>{C.current.publishOffset=t;let n=cn(e,t);return()=>{n?.(),C.current.placed=!1,C.current.follow=null,C.current.publishOffset=null}},observeElementRect:(e,t)=>{let n=e.scrollElement,r=e.targetWindow?.ResizeObserver;if(n===null||r===void 0)return;let i=new r(([r])=>{if(r===void 0)return;let i=r.borderBoxSize[0],a={width:Math.round(i?.inlineSize??r.contentRect.width),height:Math.round(i?.blockSize??r.contentRect.height)},o=C.current;if(!o.placed&&a.height>0){let t=Math.max(0,e.getTotalSize()-a.height),r=o.index*10+6,i=Math.max(0,Math.min(t,r-a.height/2));o.placed=!0,o.follow={index:o.index,count:e.options.count,height:a.height},n.scrollTop=i,o.publishOffset?.(i,!1)}t(a)});return i.observe(n,{box:`border-box`}),()=>{i.disconnect()}},paddingStart:1,paddingEnd:1,scrollPaddingStart:40,scrollPaddingEnd:40,overscan:3,rangeExtractor:(0,d.useCallback)(e=>{let t=nn(e);if(k!==void 0){let n=Math.min(e.count-1,k+1);for(let e=Math.max(0,k-1);e<=n;e++)t.includes(e)||t.push(e);t.sort((e,t)=>e-t)}return t},[k])}),ee=M.scrollOffset??0,N=M.scrollRect?.height??0,te=M.getVirtualItems(),P=(0,d.useCallback)((e,t,n=bn())=>{let r=M.measurementsCache[e],i=M.scrollRect?.height??0;if(r===void 0||i<=0)return;let a=M.scrollOffset??0,o=r.start+r.size/2;if(t===`if-needed`){let{scrollPaddingStart:e,scrollPaddingEnd:t}=M.options;if(o>=a+e&&o<=a+i-t)return}let s=o-i/2,c=Math.max(0,M.getTotalSize()-i),l=Math.max(0,Math.min(c,s))-a;l!==0&&M.scrollBy(l,{behavior:n})},[M]);(0,d.useImperativeHandle)(a,()=>({activateTurn(t){let n=D.get(t),i=n===void 0?void 0:e[n];i!==void 0&&r(i)},scrollToTurn(e){let t=D.get(e);t!==void 0&&P(t,`always`)}}),[e,D,r,P]),(0,d.useEffect)(()=>{if(N<=0){C.current.follow=null;return}if(O===void 0||w.current)return;let t=C.current.follow;if(t?.index===O&&t.count===e.length&&t.height===N)return;C.current.follow={index:O,count:e.length,height:N};let n=t?.count===e.length&&t.height===N?bn():`instant`;P(O,`if-needed`,n)},[O,e.length,N,P]);let ne=(0,d.useCallback)(e=>{b.current?b.current=!1:r(e)},[r]),F=t=>{if(t.button!==0||!(t.target instanceof Element))return;let n=t.target.closest(`button[data-index]`);if(!n||!S.current?.contains(n))return;let r=e[Number(n.dataset.index)];r&&(clearTimeout(x.current),b.current=!1,y.current={pointerId:t.pointerId,button:n,turn:r.turn,moved:!1},n.setPointerCapture(t.pointerId),_(!0),s(r.turn),p(!0))},re=t=>{let n=y.current,i=S.current;if(!n||!i||t.pointerId!==n.pointerId||!(t.buttons&1))return;let a=i.getBoundingClientRect(),o=Math.max(a.top,Math.min(t.clientY,a.bottom-1)),c=e[Math.max(0,Math.min(e.length-1,Math.round((o-a.top+i.scrollTop-6)/10)))];c&&c.turn!==n.turn&&(n.turn=c.turn,n.moved=!0,s(c.turn),c.anchor.kind===`loaded`&&r(c))},I=e=>{let t=y.current;t&&e.pointerId===t.pointerId&&(y.current=null,_(!1),b.current=t.moved,t.button.hasPointerCapture(e.pointerId)&&t.button.releasePointerCapture(e.pointerId),x.current=setTimeout(()=>{b.current=!1},0),w.current||s(null))};if(!E)return null;let ie=!u||A===void 0?void 0:e[A],ae=te.find(e=>e.index===A),oe=[G.scroller];return ee>1&&oe.push(G.fadeTop),ee<M.getTotalSize()-N-1&&oe.push(G.fadeBottom),/* @__PURE__ */ (0,f.jsx)(`div`,{ref:v,className:G.slot,children:/* @__PURE__ */ (0,f.jsxs)(`nav`,{className:G.frame,hidden:!m,"data-turn-navigation":``,"data-previewing":A!==void 0||void 0,"data-scrubbing":g||void 0,onPointerDownCapture:F,onPointerMove:re,onPointerUpCapture:I,onPointerCancelCapture:I,onLostPointerCapture:I,"aria-label":i(`chat.turnNavigation.label`),onPointerEnter:()=>{w.current=!0},onPointerLeave:()=>{w.current=!1,y.current||s(null)},children:[/* @__PURE__ */ (0,f.jsx)(`div`,{ref:S,className:oe.join(` `),children:/* @__PURE__ */ (0,f.jsx)(`div`,{ref:M.containerRef,className:G.marks,children:te.map(({index:r,key:a})=>{let c=e[r];return c===void 0?null:/* @__PURE__ */ (0,f.jsx)(xn,{item:c,index:r,active:c.turn===t,busy:c.turn===n,previewId:u&&c.turn===o?T:void 0,neighborDistance:A!==void 0&&Math.abs(r-A)<=3?Math.abs(r-A):void 0,registerElement:M.measureElement,onNavigate:ne,onPreview:s,onFocusChange:j,t:i},a)})})}),ie!==void 0&&ae!==void 0&&/* @__PURE__ */ (0,f.jsxs)(`div`,{id:T,role:`tooltip`,className:G.preview,style:{"--turn-preview-center":`${String(ae.start+ae.size/2-ee)}px`},children:[/* @__PURE__ */ (0,f.jsx)(`div`,{className:G.previewPrompt,children:ie.prompt||i(`chat.turnNavigation.turn`,{turn:(A??0)+1})}),ie.response!==``&&/* @__PURE__ */ (0,f.jsx)(`div`,{className:G.previewResponse,children:ie.response})]})]})})}let Cn=(0,d.memo)((0,d.forwardRef)(Sn));function wn(){return/* @__PURE__ */ (0,f.jsx)(`span`,{className:U.runningIcon,"aria-hidden":`true`,children:/* @__PURE__ */ (0,f.jsx)(`span`,{className:U.runningIconMotion,children:/* @__PURE__ */ (0,f.jsxs)(`svg`,{width:`100%`,height:`100%`,viewBox:`2 2 20 20`,fill:`none`,stroke:`currentColor`,strokeWidth:1.2,strokeLinecap:`round`,strokeLinejoin:`round`,children:[/* @__PURE__ */ (0,f.jsx)(`path`,{d:`M16.1 5.3C11.8 2.9 6.6 5 5.1 9.4c-1.8 5.4 1.7 10.2 6.9 10.3 4.8.2 8-3.8 7.2-8.3-.4 3.2-2 5.1-4.2 5.8`}),/* @__PURE__ */ (0,f.jsx)(`rect`,{x:`9.5`,y:`9.1`,width:`4.6`,height:`4.6`,rx:`1`,transform:`rotate(-10 11.8 11.4)`})]})})})}let Tn=`@deepseek-ai/dsh-client-ui-chat/accessibility.module.css`;if(typeof document<`u`&&document.querySelector(`style[data-plugin-css=`+JSON.stringify(Tn)+`]`)===null){let e=document.createElement(`style`);e.dataset.plugin=`@deepseek-ai/dsh-client-ui-chat`,e.dataset.pluginCss=Tn,e.textContent=`.lM_Y6G_visuallyHidden{clip:rect(0 0 0 0);white-space:nowrap;width:1px;height:1px;position:absolute;overflow:hidden}`,document.head.appendChild(e)}var En={visuallyHidden:`lM_Y6G_visuallyHidden`};let Dn=(0,d.memo)(function({startTime:e,compacting:t,stale:n,t:r}){let[i,a]=(0,d.useState)(Date.now);(0,d.useEffect)(()=>{if(e===void 0||t||n)return;a(Date.now());let r=setInterval(()=>{a(Date.now())},1e3);return()=>{clearInterval(r)}},[e,t,n]);let o=n?r(`chat.statusUnconfirmed`):t?r(`message.compaction.running`):e===void 0?r(`chat.deepDiving`):r(`chat.deepDivingFor`,{duration:Le(Math.max(1e3,i-e),r).map(e=>e.text).join(``)});return/* @__PURE__ */ (0,f.jsxs)(`div`,{className:U.running,"data-chat-running":!0,children:[/* @__PURE__ */ (0,f.jsx)(`span`,{className:En.visuallyHidden,role:`status`,"aria-live":`polite`,"aria-atomic":`true`,children:r(n?`chat.statusUnconfirmed`:t?`message.compaction.running`:`chat.deepDiving`)}),/* @__PURE__ */ (0,f.jsx)(`span`,{className:U.runningDivider,"aria-hidden":`true`}),/* @__PURE__ */ (0,f.jsxs)(`span`,{className:U.runningContent,children:[n?null:/* @__PURE__ */ (0,f.jsx)(wn,{}),/* @__PURE__ */ (0,f.jsx)(p.TextShimmer,{active:!n,className:U.runningText,children:o})]})]})});function On(e){return e}function kn(e){return e}function An(e){if(!Number.isSafeInteger(e)||e<0||Object.is(e,-0))throw TypeError(`SessionSeq must be a non-negative safe integer, got ${String(e)}`);return kn(e)}let jn=[];function Mn(e){if(typeof e!=`object`||!e)return;let t=e;if(!(typeof t.turn!=`number`||!Number.isSafeInteger(t.turn)||t.turn<0)&&!(typeof t.seq!=`number`||!Number.isSafeInteger(t.seq)||t.seq<0||Object.is(t.seq,-0)))return{turn:t.turn,seq:An(t.seq),prompt:typeof t.prompt==`string`?t.prompt:``,response:typeof t.response==`string`?t.response:``}}function Nn(e){return Array.isArray(e)?e:jn}function Pn(e,t){let n=/* @__PURE__ */ new Map;for(let e of Nn(t)){let t=Mn(e);t!==void 0&&n.set(t.turn,{turn:t.turn,prompt:t.prompt,response:t.response,anchor:{kind:`unloaded`,seq:t.seq}})}for(let t of e){let e=n.get(t.turn);n.set(t.turn,{turn:t.turn,prompt:t.prompt===``?e?.prompt??``:t.prompt,response:t.response===``?e?.response??``:t.response,anchor:{kind:`loaded`,key:t.anchorKey}})}return n.size===0?jn:[...n.values()].sort((e,t)=>e.turn-t.turn)}var Fn=class{viewport;reading;input;onBusyTurn;jump=null;settleFrame=null;requestedHead;constructor(e,t,n,r){this.viewport=e,this.reading=t,this.input=n,this.onBusyTurn=r}setInput(e){this.input=e}reset(){this.requestedHead=void 0,this.cancel()}dispose(){this.clearTask()}cancel(){this.clearTask(),this.onBusyTurn(null)}clearTask(){this.cancelFrame(),this.jump=null,this.viewport.stopPreserving()}navigateToTurn=e=>{if(e.anchor.kind===`loaded`){this.cancel();let t=this.viewport.scrollToTurn(e.turn);if(t===null)return;this.reading.acceptNavigation(t),this.input.loadingOlder&&this.viewport.beginPreserving(t.position);return}if(!this.input.historyReady)return;this.cancel(),this.viewport.beginPreserving(),this.reading.pauseFollowing();let t={turn:e.turn,seq:e.anchor.seq,phase:`loading`,landing:`pending`,repageHead:null};this.jump=t,this.onBusyTurn(t.turn),this.request(t)};autoLoadEarlier=()=>{if(this.jump!==null||this.input.olderFailed||this.requestedHead===this.input.firstSeq)return;let e=this.viewport.readScroll();e===null||e.metrics.top>240||this.loadEarlier()};loadEarlier=()=>{this.input.historyReady&&this.input.hasMore&&!this.input.loadingOlder&&(this.requestedHead=this.input.firstSeq,this.cancel(),this.viewport.beginPaging(),this.reading.pauseFollowing(),this.input.loadOlder())};readerSampled(e){e.movedByReader&&this.jump?.landing===`landed`&&(this.jump.landing=`interrupted`),(e.followingTail||e.movedByReader)&&this.viewport.stopPreserving()}contentCommitted(){if(!this.viewport.preserving||this.reading.pending)return!1;if(this.landJump(!1))return!0;let e=this.viewport.preserve();return e!==null&&(this.reading.preservePosition(e),!0)}readerSettled(){this.input.loadingOlder&&this.jump===null&&!this.viewport.preserving&&!this.reading.followingTail&&this.viewport.beginPreserving()}reconcile(){let e=this.jump;if(!this.input.historyReady||e===null||this.reading.pending)return;if(e.phase===`loading`){e.landing===`pending`&&this.landJump(!1);return}if(this.input.loadingOlder||this.landJump(!0))return;if((this.input.firstSeq===null||this.input.firstSeq>e.seq)&&this.input.hasMore&&e.repageHead!==this.input.firstSeq){e.repageHead=this.input.firstSeq,this.viewport.beginPreserving(),this.request(e);return}let t=this.viewport.scrollToTurnAtOrAfter(e.turn);this.cancel(),t!==null&&this.reading.acceptNavigation(t)}landJump(e){let t=this.jump;if(t===null)return!1;if(t.landing===`interrupted`)return e?(this.cancel(),!0):!1;let n=this.viewport.scrollToTurn(t.turn);return n!==null&&(this.reading.acceptNavigation(n),e?this.cancel():(this.viewport.beginPreserving(n.position),t.landing=`landed`),!0)}request(e){e.phase=`loading`;let t=()=>{this.jump===e&&(e.phase=`settled`,this.cancelFrame(),typeof requestAnimationFrame==`function`?this.settleFrame=requestAnimationFrame(()=>{this.settleFrame=null,this.jump===e&&this.reconcile()}):this.reconcile())};this.input.loadThrough(e.seq).then(t,t)}cancelFrame(){this.settleFrame!==null&&typeof cancelAnimationFrame==`function`&&cancelAnimationFrame(this.settleFrame),this.settleFrame=null}};function In(e,t,n){let[r,i]=(0,d.useState)(null),[a]=(0,d.useState)(()=>new Fn(e,t,n,i));return(0,d.useLayoutEffect)(()=>{a.setInput(n)},[a,n]),(0,d.useLayoutEffect)(()=>()=>{a.dispose()},[a]),{navigation:a,busyTurn:r}}var Ln=class{viewport;store;state;onChange;follow;sampleTimer=null;probeFrame=null;sampled=null;constructor(e,t,n,r,i){this.viewport=e,this.store=t,this.state=n,this.onChange=r,this.follow=i}get pending(){return this.sampleTimer!==null}get followingTail(){return this.state.followingTail}setStore(e){this.store=e}connect(e){return this.sampled=e,()=>{this.sampled===e&&(this.sampled=null)}}dispose(){this.cancelPending(),this.sampled=null}pauseFollowing(){this.cancelPending(),this.publish({...this.state,followingTail:!1})}followTail(){let e=this.viewport.scrollToBottom(this.follow);e!==null&&(this.cancelPending(),this.commit(e,!0,this.viewport.latestTurn))}restore(){let e=this.store.read();if(e===null){this.followTail();return}let t=this.viewport.restore(e);if(t===null)return;this.cancelPending();let n=this.follow.nearBottom(t.metrics);if(this.commit(t,n,n?this.viewport.latestTurn:this.state.activeTurn,n),!this.state.followingTail&&t.position===null){let e=this.viewport.capturePosition();e!==null&&this.store.save(e)}this.refreshActiveTurn()}acceptNavigation(e){this.cancelPending();let t=this.follow.nearBottom(e.metrics);this.commit(e,t,e.turn??(t?this.viewport.latestTurn:this.state.activeTurn))}preservePosition(e){this.cancelPending(),this.commit(e,this.state.followingTail,this.state.activeTurn)}onScroll=e=>{!e.movedByReader&&this.state.followingTail||e.movedByReader&&e.metrics.top>=e.metrics.floor?(this.followTail(),this.sampled?.({position:null,movedByReader:e.movedByReader,followingTail:!0})):this.sampleTimer??=window.setTimeout(this.flushSample,500)};onScrollEnd=()=>{this.flushSample()};onResize(){this.pending||(this.state.followingTail?this.followTail():this.refreshActiveTurn())}refreshActiveTurn(){this.pending||(this.state.followingTail?this.publish({...this.state,initialized:!0,activeTurn:this.viewport.latestTurn}):this.probeFrame===null&&(typeof requestAnimationFrame==`function`?this.probeFrame=requestAnimationFrame(this.probe):this.probe()))}commit(e,t,n,r=!0){t?this.store.save(null):e.position!==null&&this.store.save(e.position),this.publish({initialized:r,followingTail:t,activeTurn:n})}publish(e){this.follow.setFollowing(e.followingTail),(e.initialized!==this.state.initialized||e.followingTail!==this.state.followingTail||e.activeTurn!==this.state.activeTurn)&&(this.state=e,this.onChange(e))}cancelPending(){this.sampleTimer!==null&&window.clearTimeout(this.sampleTimer),this.probeFrame!==null&&typeof cancelAnimationFrame==`function`&&cancelAnimationFrame(this.probeFrame),this.sampleTimer=null,this.probeFrame=null}probe=()=>{if(this.probeFrame=null,this.pending)return;let e=this.viewport.readScroll();if(e===null)return;let t=this.follow.nearBottom(e.metrics)?this.viewport.latestTurn:this.viewport.readVisibleTurn(e.metrics);this.publish({...this.state,initialized:!0,activeTurn:t})};flushSample=()=>{if(!this.pending)return;this.cancelPending();let e=this.viewport.readScroll();if(e===null)return;let t=this.follow.sample(e.metrics,e.movedByReader),n=null;if(!e.movedByReader&&t)this.followTail();else{n=t?null:this.viewport.capturePosition(),this.viewport.acknowledge(e.metrics),(t||n!==null)&&this.store.save(n);let r=this.follow.nearBottom(e.metrics)?this.viewport.latestTurn:this.viewport.readVisibleTurn(e.metrics);this.publish({initialized:!0,followingTail:t,activeTurn:r})}this.sampled?.({position:n,movedByReader:e.movedByReader,followingTail:t})}};function Rn(e,t,n){let[r,i]=(0,d.useState)(()=>({initialized:!1,followingTail:t.read()===null,activeTurn:n})),a=Ft(r.followingTail,25),[o]=(0,d.useState)(()=>new Ln(e,t,r,i,a));return(0,d.useLayoutEffect)(()=>{o.setStore(t)},[o,t]),(0,d.useLayoutEffect)(()=>()=>{o.dispose()},[o]),{reading:o,state:r}}let zn=[`wheel`,`touchstart`,`touchmove`,`touchend`,`touchcancel`,`pointerdown`,`keydown`,`beforematch`],Bn=/* @__PURE__ */ new Set([`ArrowUp`,`ArrowDown`,`PageUp`,`PageDown`,`Home`,`End`,` `]);var Vn=class{elements=null;observer=null;events=null;turns=[];observation={top:0,landing:null};paging=null;touchY=null;attach(e,t){this.detach();let n=e.closest(`[data-conversation-scroll]`)??e,r=n.querySelector(`[data-composer-seat]`),i={list:e,column:t,scroller:n,composer:r};this.elements=i,n.addEventListener(`scroll`,this.onScroll,{passive:!0}),n.addEventListener(`scrollend`,this.onScrollEnd,{passive:!0,capture:!0});for(let e of zn)n.addEventListener(e,this.onIntent,{passive:!0,capture:!0});typeof ResizeObserver<`u`&&(this.observer=new ResizeObserver(()=>{this.elements===i&&(this.invalidate(),this.events?.resize())}),this.observer.observe(t),this.observer.observe(n),r!==null&&this.observer.observe(r))}detach(){this.stopPreserving(),this.elements?.scroller.removeEventListener(`scroll`,this.onScroll),this.elements?.scroller.removeEventListener(`scrollend`,this.onScrollEnd,!0);for(let e of zn)this.elements?.scroller.removeEventListener(e,this.onIntent,!0);this.observer?.disconnect(),this.observer=null,this.elements=null,this.events=null,this.turns=[],this.touchY=null,this.observation={top:0,landing:null}}connect(e){return this.events=e,()=>{this.events===e&&(this.events=null)}}updateTurns(e){this.turns=e}get latestTurn(){return this.turns.at(-1)?.turn??null}invalidate(){this.observation.landing=null}acknowledge(e){this.observation={top:e.top,landing:null}}readScroll(){let e=this.metrics();return e===null?null:{metrics:e,movedByReader:Math.abs(e.top-Math.min(this.observation.top,e.floor))>.5,towardStart:e.top<Math.min(this.observation.top,e.floor)-.5}}metrics(){let e=this.elements?.scroller;return e===void 0?null:Nt(e)}anchor(e,t=`position`){if(this.elements===null)return null;let n=null;for(let r of this.elements.list.querySelectorAll(`[data-chat-anchor-key]:not([hidden]):not([hidden] *)`)){if(r.dataset.chatAnchorKey===e||t===`node`&&r.dataset.chatNodeKey===e)return r;n===null&&r.dataset.chatNodeKey===e&&(n=r)}return n}capturePosition(){let e=this.elements;if(e===null)return null;let{list:t,scroller:n,composer:r}=e,i=n.getBoundingClientRect(),a=r?.getBoundingClientRect().top??i.bottom,o=null;if(typeof document.elementsFromPoint==`function`&&a>i.top){let e=t.getBoundingClientRect(),n=Math.max(i.left,e.left),r=Math.min(i.right,e.right);for(let e of document.elementsFromPoint(n+Math.max(0,r-n)/2,i.top+1)){let n=e instanceof HTMLElement?e.closest(`[data-chat-anchor-key]`):null;if(n!==null&&n.dataset.chatFlowKind!==`turn-process`&&t.contains(n)){o=n.dataset.chatGroupKey===void 0?n:n.querySelector(`[data-step-process-content] > [data-chat-anchor-key]:not(:empty):not([hidden]):not([hidden] *)`)??n;break}}}if(o===null){let e=t.querySelectorAll(`[data-chat-flow-key]:not([data-chat-group-key]):not([data-chat-flow-kind="turn-process"]):not(:empty):not([hidden]):not([hidden] *)`),n=0,r=e.length;for(;n<r;){let t=n+r>>>1;e.item(t).getBoundingClientRect().bottom>i.top?r=t:n=t+1}let s=e[n];o=s!==void 0&&s.getBoundingClientRect().top<a?s:e[0]??null}let s=o?.dataset.chatAnchorKey;return o===null||s===void 0?null:{anchorKey:s,anchorTop:o.getBoundingClientRect().top-i.top,scrollTop:n.scrollTop}}readVisibleTurn(e=this.metrics()){let t=this.observation.landing?.turn;if(t!=null&&e?.top===this.observation.top)return t;let n=this.elements,r=this.turns[0];if(n===null||e===null||r===void 0)return null;let i=n.scroller.getBoundingClientRect().top+Math.min(96,e.height*.2),a=n.column.children,o=0,s=a.length,c=r.turn;for(;o<s;){let e=o+s>>>1,t=a[e];if(t.getBoundingClientRect().top>i)s=e;else{let n=t.getAttribute(`data-chat-turn`),r=n===null?NaN:Number(n);Number.isSafeInteger(r)&&(c=r),o=e+1}}return c}scrollToTurn(e){let t=this.turns.find(t=>t.turn===e);if(t===void 0)return null;let n=this.anchor(t.anchorKey,`node`);return n===null?null:this.align(n,24,e)}scrollToTurnAtOrAfter(e){if(this.elements===null)return null;for(let t of this.elements.list.querySelectorAll(`[data-chat-turn]:not([hidden]):not([hidden] *)`)){let n=Number(t.dataset.chatTurn);if(Number.isSafeInteger(n)&&n>=e)return this.align(t,24,n)}return null}restore(e){let t=this.anchor(e.anchorKey);if(t!==null)return this.align(t,e.anchorTop,null);let n=this.metrics();return n===null?null:this.write(e.scrollTop,n,null)}beginPaging(){this.stopPreserving();let e=this.elements?.list.querySelector(`[data-chat-paging-anchor]:not(:empty):not([hidden]):not([hidden] *)`);e!=null&&this.retain(e)}beginPreserving(e=this.capturePosition()){if(this.stopPreserving(),e===null)return;let t=this.anchor(e.anchorKey);t!==null&&this.retain(t,e)}retain(e,t,n){let r=this.elements,i=e.dataset.chatAnchorKey;if(r===null||i===void 0)return null;let a=this.paging?.group;a!=null&&this.observer?.unobserve(a.content);let o=e.getBoundingClientRect().top,s=e.closest(`[data-step-process-body]`),c=s?.querySelector(`[data-step-process-content]`),l=s===null||c==null?null:{body:s,content:c,top:n??o-s.getBoundingClientRect().top};return this.paging={row:e,group:l,position:t??{anchorKey:i,anchorTop:o-r.scroller.getBoundingClientRect().top,scrollTop:r.scroller.scrollTop}},l!==null&&this.observer?.observe(l.content),this.paging}stopPreserving(){let e=this.paging?.group;e!=null&&this.observer?.unobserve(e.content),this.paging=null}get preserving(){return this.paging!==null}preserve(){let e=this.paging,t=this.elements;if(e===null||t===null)return null;if(!t.list.contains(e.row)){let t=this.anchor(e.position.anchorKey);if(t===null)return this.stopPreserving(),null;if(e=this.retain(t,e.position,e.group?.top),e===null)return null}let{row:n,group:r,position:i}=e;if(n.closest(`[hidden]`)!==null||n.matches(`:empty`))return this.stopPreserving(),null;if(r!==null&&r.body.contains(n)){let e=n.getBoundingClientRect().top-r.body.getBoundingClientRect().top,t=Nt(r.body),i=Math.max(0,Math.min(t.floor,t.top+e-r.top));if(t.top!==i){let e=Pt.forElement(r.body);e===void 0?r.body.scrollTop=i:(e.jump(r.body,t,i),e.setFollowing(!1))}}let a=this.metrics();if(a===null)return null;let o=n.getBoundingClientRect().top-t.scroller.getBoundingClientRect().top,s=a.top+o-i.anchorTop;return this.write(s,a,null,{key:i.anchorKey,top:o})}scrollToBottom(e){let t=this.metrics();if(t===null||this.elements===null)return null;let n={metrics:e.toBottom(this.elements.scroller,t,`instant`),position:null,turn:this.latestTurn};return this.observation={top:n.metrics.top,landing:n},n}align(e,t,n){let r=this.metrics();if(r===null||this.elements===null)return null;let i=e.getBoundingClientRect().top-this.elements.scroller.getBoundingClientRect().top;return this.write(r.top+i-t,r,n,{key:e.dataset.chatAnchorKey,top:i})}write(e,t,n,r){if(this.elements===null)return null;let i=Math.max(0,Math.min(t.floor,e));i!==t.top&&(this.elements.scroller.scrollTop=i);let a=this.elements.scroller.scrollTop,o={metrics:{...t,top:a},turn:n,position:r?.key===void 0?null:{anchorKey:r.key,anchorTop:r.top-(a-t.top),scrollTop:a}};return this.observation={top:a,landing:o},o}onScroll=e=>{if(this.elements===null||e.target!==this.elements.scroller||this.observation.landing!==null&&this.elements.scroller.scrollTop===this.observation.top)return;if(this.invalidate(),this.paging!==null){this.events?.resize();return}let t=this.readScroll();t!==null&&this.events?.scroll(t)};onScrollEnd=e=>{(e.target===this.elements?.scroller||e.target instanceof HTMLElement&&e.target.hasAttribute(`data-step-process-body`))&&this.events?.scrollEnd()};onIntent=e=>{if(e.type===`touchend`||e.type===`touchcancel`){this.touchY=null;return}if(e.target instanceof Element&&e.target.closest(`[data-composer-seat], [data-turn-navigation], input, textarea, [contenteditable="true"]`)||e.type===`keydown`&&(!(e instanceof KeyboardEvent)||!Bn.has(e.key)))return;let t=e instanceof WheelEvent?e.deltaY<0:e instanceof KeyboardEvent&&([`ArrowUp`,`PageUp`,`Home`].includes(e.key)||e.key===` `&&e.shiftKey);if(typeof TouchEvent<`u`&&e instanceof TouchEvent){let n=e.touches[0]?.clientY;if(t=e.type===`touchmove`&&n!==void 0&&this.touchY!==null&&n>this.touchY,this.touchY=n??null,e.type===`touchstart`)return}if(!(e instanceof PointerEvent&&e.pointerType===`touch`)){if(t&&e.target instanceof Element){for(let n=e.target;n&&n!==this.elements?.scroller;n=n.parentElement)if(n instanceof HTMLElement&&n.scrollTop>0&&n.scrollHeight>n.clientHeight&&/auto|scroll/.test(getComputedStyle(n).overflowY)){t=!1;break}}this.paging!==null&&!(t&&this.observation.top<=0&&(this.elements?.scroller.scrollTop??0)<=0)&&(this.stopPreserving(),this.events?.interact()),t&&this.events?.olderIntent()}}};function Hn(){let e=(0,d.useRef)(null),t=(0,d.useRef)(null),[n]=(0,d.useState)(()=>new Vn);return(0,d.useLayoutEffect)(()=>{if(e.current!==null&&t.current!==null)return n.attach(e.current,t.current),()=>{n.detach()}},[n]),{viewport:n,listRef:e,columnRef:t}}function Un(e){let{displayReady:t,historyReady:n,order:r,firstSeq:i,lastKey:a,lastIsUser:o,steeringId:s,submissionId:c,running:l,loadedTurns:u,chatScroll:f,hasMore:p,loadingOlder:m,olderFailed:h,loadOlder:g,loadThrough:_}=e,{viewport:v,listRef:y,columnRef:b}=Hn(),{reading:x,state:S}=Rn(v,f,u.at(-1)?.turn??null),C=(0,d.useMemo)(()=>({historyReady:n,firstSeq:i,loadingOlder:m,olderFailed:h,hasMore:p,loadOlder:g,loadThrough:_}),[n,i,m,h,p,g,_]),{navigation:w,busyTurn:T}=In(v,x,C),E=(0,d.useRef)({input:e,applied:null,opened:!1}),D=(0,d.useCallback)(()=>{let e=E.current.input,t=E.current.applied,n=e.lastIsUser&&e.lastKey!==t?.lastKey||e.steeringId!==null&&e.steeringId!==t?.steeringId&&e.steeringId!==t?.submissionId||e.submissionId!==null&&e.submissionId!==t?.submissionId&&e.submissionId!==t?.steeringId;(!x.pending||n)&&(E.current.applied=e,e.displayReady&&!E.current.opened?(E.current.opened=!0,w.reset(),x.restore()):n?(w.cancel(),x.followTail()):w.contentCommitted()?w.reconcile():(t===null||e.displayReady!==t.displayReady||e.firstSeq!==t.firstSeq||e.lastKey!==t.lastKey||e.order.length!==t.order.length||e.running!==t.running||e.steeringId!==t.steeringId||e.submissionId!==t.submissionId)&&x.followingTail?(w.cancel(),x.followTail()):w.reconcile())},[x,w]);(0,d.useLayoutEffect)(()=>{let e=null,t=()=>{e===null&&E.current.opened&&E.current.input.historyReady&&(e=requestAnimationFrame(()=>{e=null,E.current.opened&&E.current.input.historyReady&&w.autoLoadEarlier()}))},n=v.connect({scroll:e=>{x.onScroll(e),e.movedByReader&&e.towardStart&&t()},olderIntent:t,scrollEnd:()=>{x.onScrollEnd(),w.readerSettled()},interact:()=>{w.cancel()},resize:()=>{w.contentCommitted()||x.onResize(),w.reconcile()}}),r=x.connect(e=>{w.readerSampled(e),D()});return()=>{e!==null&&cancelAnimationFrame(e),n(),r(),E.current.opened=!1,E.current.applied=null}},[v,x,w,D]),(0,d.useLayoutEffect)(()=>{let e=E.current.input;E.current.input={displayReady:t,order:r,lastKey:a,lastIsUser:o,steeringId:s,submissionId:c,running:l,loadedTurns:u,chatScroll:f,...C},v.updateTurns(u);let n=e.order!==r||e.displayReady!==t;n&&v.invalidate(),D(),n&&x.refreshActiveTurn()},[v,x,D,C,t,r,a,o,s,c,l,u,f]);let O=(0,d.useCallback)(()=>{w.cancel(),x.followTail()},[w,x]);return{listRef:y,columnRef:b,...S,busyTurn:T,navigateToTurn:w.navigateToTurn,loadEarlier:w.loadEarlier,returnToBottom:O}}function Wn(e,t){let n=e instanceof Error?e.message:String(e);return n===``?t:n}function Gn(e,t){let n=/* @__PURE__ */ new Set,r;for(let i of e){let e=t.get(i);if(e===void 0||e.kind!==`user`&&e.kind!==`steering`&&e.kind!==`turn-trigger`||((e.location.kind===`turn`||e.location.kind===`step`)&&(r=e.location.turn.turn),e.kind===`turn-trigger`))continue;let a=e.data.source;a?.kind===`user`&&typeof a.rpcId==`string`&&n.add(a.rpcId)}return{rpcIds:n,lastInputTurn:r}}let Kn=(0,d.memo)(function({entries:e,useChatGroup:t,pendingInputs:n,lastInputTurn:r,...i}){let a=e.map(e=>{switch(e.kind){case`node`:return/* @__PURE__ */ (0,d.createElement)(St,{...i,key:kt(e),nodeKey:e.key,...e.groupPart===void 0?{}:{groupPart:e.groupPart}});case`group`:return/* @__PURE__ */ (0,d.createElement)(Gt,{...i,key:kt(e),groupKey:e.key,useChatGroup:t});default:return Ot(e)}}),o=n.map(e=>`requestId`in e?/* @__PURE__ */ (0,f.jsx)(tt,{submission:e,renderMessageImages:i.renderMessageImages,t:i.t},e.requestId):/* @__PURE__ */ (0,f.jsx)(et,{content:e.content,renderMessageImages:i.renderMessageImages,t:i.t},e.id)),s=e.at(-1),c=s?.kind===`node`?i.nodeStore.get(s.key):void 0;if(c?.kind===`turn-process`&&c.location.kind===`turn`&&c.location.turn.status===`open`&&c.location.turn.turn!==r){let e=n.findIndex(e=>`requestId`in e&&e.placement===`transcript`);e!==-1&&a.splice(a.length-1,0,...o.splice(e,1))}return[...a,...o]});function qn({connection:e,useSession:t,useChat:n,useChatNode:r,useChatNodeProcess:i,useChatGroup:a,useConversation:o,useSessions:s,useStore:c,actions:l,renderSlot:u,sessionId:m,openFile:h,openSkill:g,openExternalLink:_,resolveLink:v,loadOlder:y,loadThrough:b,loadImage:x,inspectCall:S,chatScroll:C,forkAt:w,loadTurnDiffs:T,editMessage:E,fileMentions:D,usePresentation:O,useProjection:k,t:A}){let j=n(e=>e.order),M=o(e=>e.views.grouped(`chat`)?.entries),N=(0,d.useMemo)(()=>M??j.map(e=>({kind:`node`,key:e})),[M,j]),P=n(e=>e.nodes),ne=n(e=>e.navigation.items()),F=ne.at(-1)?.anchorKey,re=r(F??``,e=>{let t=e?.location;return(t?.kind===`turn`||t?.kind===`step`)&&t.turn.status===`open`?t.turn.start?.time:void 0}),I=k(`turnOutline`),ie=(0,d.useMemo)(()=>Pn(ne,I),[ne,I]),ae=k(`inbox`),oe=s(e=>e.byId[m]?.cwd),se=(0,d.useMemo)(()=>({resolve:e=>te(document.baseURI,ee(oe,e)),labels:{open:A(`image.open`),loading:A(`image.loading`),failed:A(`image.failed`),dialog:A(`image.dialog`),close:A(`image.close`)}}),[oe,A]),ce=t(e=>e.running),L=(0,d.useSyncExternalStore)(e.state.subscribe,e.state.getSnapshot),le=(0,p.useSustainedRecovery)(L!==`connected`),ue=k(`compacting`),R=t(e=>e.openState),de=L===`disconnected`||le||R===`error`,z=t(e=>e.openError),fe=t(e=>e.hasMore),pe=t(e=>e.loadingOlder),me=t(e=>e.olderError),[he,ge]=(0,d.useState)(null),[_e,ve]=(0,d.useState)(!1),B=(0,d.useRef)(0),ye=(0,d.useCallback)((e,t)=>{let n=++B.current;ve(!0),(t===void 0?h(e):h(e,t)).then(()=>{n===B.current&&(ge(null),ve(!1))},t=>{n===B.current&&(ge({path:e,message:Wn(t,A(`fileOpen.unknown`))}),ve(!1))})},[h,A]),be=(0,d.useCallback)(()=>{B.current+=1,ge(null),ve(!1)},[]),xe=(0,d.useMemo)(()=>ae?.[`next-step`].filter(e=>e.source.kind===`user`)??[],[ae]),Se=t(e=>e.pendingSubmissions),Ce=We(E,k(`sentMessageEdit`)?.seq??null,R!==`open`||ce||Se.length>0||(ae?.[`next-turn`].length??0)>0),we=Ce.draft&&j.some(e=>{let t=P.get(e);return t?.kind===`user`&&t.data.seq===Ce.draft?.seq}),Te=ce||Se.some(e=>e.placement!==`queued`),[Ee,De]=(0,d.useMemo)(()=>{if(Se.length===0)return[Se,void 0];let e=Gn(j,P);return[Se.filter(t=>t.placement!==`queued`&&!e.rpcIds.has(t.requestId)),e.lastInputTurn]},[Se,j,P]),Oe=(0,d.useMemo)(()=>{let e=new Map(Ee.map(e=>[e.requestId,e])),t=new Set(Se.filter(e=>e.placement!==`queued`).map(e=>e.requestId));return[...xe.flatMap(n=>{let r=n.source;if(r.kind!==`user`||!(`rpcId`in r))return[n];let i=e.get(r.rpcId);return i===void 0?t.has(r.rpcId)?[]:[n]:(e.delete(r.rpcId),[i])}),...e.values()]},[xe,Se,Ee]),ke=(0,d.useCallback)(e=>u(`conversation.message.images`,{...e,loadImage:x}),[x,u]),Ae=j[0],je=Ae===void 0?null:P.get(Ae)?.anchorSeq??null,Me=j.at(-1)??null,Ne=Oe.findLast(e=>`source`in e),V=Ne?.source.kind===`user`&&`rpcId`in Ne.source?Ne.source.rpcId:Ne?.id??null,H=Un({displayReady:R===`open`||j.length>0,historyReady:R===`open`,order:j,firstSeq:je,lastKey:Me,running:ce,loadingOlder:pe,olderFailed:me!=null,hasMore:fe,chatScroll:C,loadOlder:y,loadThrough:b,lastIsUser:Me!==null&&P.get(Me)?.kind===`user`,steeringId:V,submissionId:Ee.at(-1)?.requestId??null,loadedTurns:ne});return/* @__PURE__ */ (0,f.jsxs)(`div`,{className:U.frame,children:[H.initialized&&/* @__PURE__ */ (0,f.jsx)(Cn,{items:ie,activeTurn:H.activeTurn,busyTurn:H.busyTurn,onNavigate:H.navigateToTurn,t:A}),/* @__PURE__ */ (0,f.jsx)(`div`,{className:U.root,"data-chat-following-tail":H.followingTail?``:void 0,children:/* @__PURE__ */ (0,f.jsx)(`div`,{ref:H.listRef,className:U.scroll,children:/* @__PURE__ */ (0,f.jsxs)(`div`,{ref:H.columnRef,className:U.column,"data-chat-flow":``,children:[R===`loading`&&j.length===0&&/* @__PURE__ */ (0,f.jsx)(`div`,{className:U.hint,children:A(`chat.loadingHistory`)}),R===`error`&&z!==null&&/* @__PURE__ */ (0,f.jsx)(`div`,{className:U.openError,children:A(`chat.loadError`,{message:z.message,code:z.code})}),fe&&/* @__PURE__ */ (0,f.jsx)(`div`,{className:U.older,children:me==null?/* @__PURE__ */ (0,f.jsx)(`span`,{role:pe?`status`:void 0,children:A(pe?`chat.loadingOlder`:`chat.scrollOlder`)}):/* @__PURE__ */ (0,f.jsxs)(f.Fragment,{children:[/* @__PURE__ */ (0,f.jsx)(`span`,{role:`alert`,children:A(`chat.loadOlderError`,{message:me.message})}),/* @__PURE__ */ (0,f.jsx)(`button`,{type:`button`,disabled:pe,onClick:H.loadEarlier,children:A(`chat.retryOlder`)})]})}),/* @__PURE__ */ (0,f.jsx)(p.MarkdownDelegateProvider,{openExternalLink:_,resolveLink:v,openFile:ye,fileImages:se,children:/* @__PURE__ */ (0,f.jsx)(Kn,{entries:N,pendingInputs:Oe,lastInputTurn:De,nodeStore:P,useChatGroup:a,useChatNode:r,useChatNodeProcess:i,usePresentation:O,useStore:c,actions:l,cwd:oe,openFile:ye,openSkill:g,inspectCall:S,forkAt:w,loadTurnDiffs:T,messageEditing:Ce,loadImage:x,renderMessageImages:ke,fileMentions:D,renderSlot:u,t:A})}),Ce.draft&&!we&&/* @__PURE__ */ (0,f.jsx)(rt,{editing:Ce,renderMessageImages:ke,t:A}),Te&&/* @__PURE__ */ (0,f.jsx)(Dn,{startTime:re,compacting:ue,stale:de,t:A}),R===`loading`&&j.length>0&&/* @__PURE__ */ (0,f.jsxs)(`div`,{className:U.syncing,role:`status`,"data-history-syncing":!0,children:[/* @__PURE__ */ (0,f.jsx)(p.StateDot,{state:`ongoing`,className:U.syncingIcon}),/* @__PURE__ */ (0,f.jsx)(`span`,{children:A(`chat.syncing`)})]})]})})}),!H.followingTail&&/* @__PURE__ */ (0,f.jsx)(`div`,{className:U.toBottomSlot,children:/* @__PURE__ */ (0,f.jsx)(`button`,{type:`button`,className:U.toBottom,"aria-label":A(`chat.toBottom`),onClick:H.returnToBottom,children:/* @__PURE__ */ (0,f.jsx)(p.IconChevronDownOutlineRegular,{})})}),he!==null&&/* @__PURE__ */ (0,f.jsx)(Jn,{message:he.message,busy:_e,onClose:be,onRetry:()=>{ye(he.path)},t:A})]})}function Jn({message:e,busy:t,onClose:n,onRetry:r,t:i}){return/* @__PURE__ */ (0,f.jsx)(p.Modal,{open:!0,onClose:n,closeLabel:i(`close`),title:i(`fileOpen.title`),description:e,footer:/* @__PURE__ */ (0,f.jsxs)(f.Fragment,{children:[/* @__PURE__ */ (0,f.jsx)(p.Button,{variant:`outline`,className:U.modalAction,onClick:n,children:i(`cancel`)}),/* @__PURE__ */ (0,f.jsx)(p.Button,{variant:`primary`,className:U.modalAction,disabled:t,onClick:r,children:i(`retry`)})]})})}let K=`chat`,Yn={"message.stepProcess.thinking":`正在分析请求`,"message.stepProcess.read":`正在读取文件`,"message.stepProcess.readImage":`正在读取图片`,"message.stepProcess.write":`正在写入文件`,"message.stepProcess.search":`正在搜索代码`,"message.stepProcess.edit":`正在编辑文件`,"message.stepProcess.commands":`正在运行命令`,"message.stepProcess.code":`正在运行代码`,"message.stepProcess.webSearch":`正在搜索网页`,"message.stepProcess.webFetch":`正在访问网页`,"message.stepProcess.subagents":`正在协调子智能体`,"message.stepProcess.plan":`正在更新计划`,"message.stepProcess.questions":`等待你的操作`,"message.stepProcess.tools":`正在调用工具`,"message.stepProcess.prepare.read":`准备读取文件`,"message.stepProcess.prepare.readImage":`准备读取图片`,"message.stepProcess.prepare.write":`准备写入文件`,"message.stepProcess.prepare.search":`准备搜索代码`,"message.stepProcess.prepare.edit":`准备编辑文件`,"message.stepProcess.prepare.commands":`准备运行命令`,"message.stepProcess.prepare.code":`准备运行代码`,"message.stepProcess.prepare.webSearch":`准备搜索网页`,"message.stepProcess.prepare.webFetch":`准备访问网页`,"message.stepProcess.prepare.subagents":`准备协调子智能体`,"message.stepProcess.prepare.plan":`准备更新计划`,"message.stepProcess.prepare.questions":`准备提问`,"message.stepProcess.prepare.tools":`准备调用工具`,"message.stepProcess.done.thinking":`已完成分析`,"message.stepProcess.done.read":`已读取文件`,"message.stepProcess.done.readImage":`已读取图片`,"message.stepProcess.done.write":`已写入文件`,"message.stepProcess.done.search":`已搜索代码`,"message.stepProcess.done.edit":`修改了文件`,"message.stepProcess.done.commands":`执行了命令`,"message.stepProcess.done.code":`运行了代码`,"message.stepProcess.done.webSearch":`已搜索网页`,"message.stepProcess.done.webFetch":`已访问网页`,"message.stepProcess.done.subagents":`已协调子智能体`,"message.stepProcess.done.plan":`更新了计划`,"message.stepProcess.done.questions":`向用户提出了问题`,"message.stepProcess.done.tools":`已调用工具`,"message.stepProcess.joinTwo":`{first}并{second}`,"message.stepProcess.comma":`,`,"message.stepProcess.sharedPrefix":`已`,"message.stepProcess.more":`{title}等`,"message.trigger.request":`收到执行请求`,"message.trigger.goal":`继续执行目标`,"message.trigger.agent":`收到任务消息`,"message.trigger.team":`收到团队消息`,"message.trigger.subagent":`子任务状态更新`,"message.trigger.github":`收到 GitHub 事件`,"message.trigger.webhook":`收到外部事件`,"message.trigger.schedule":`自动化任务`,"message.trigger.job":`后台任务状态更新`,"message.trigger.plugin":`插件状态更新`,"message.trigger.explanation":`这条通知触发了本轮回复。`,"message.turnProcess.worked":`已完成`,"message.turnProcess.took":`已完成,用时 `,"message.turnProcess.failed":`处理失败`,"view.chat":`对话`,"image.open":`查看大图`,"image.loading":`加载图片…`,"image.failed":`图片无法预览`,"image.dialog":`图片预览`,"image.close":`关闭图片预览`,"duration.milliseconds":`{milliseconds}毫秒`,"chat.loadingHistory":`载入历史…`,"chat.syncing":`正在获取最新消息…`,"chat.loadingDiff":`载入差异…`,"chat.retryDiff":`重试`,"chat.loadError":`历史加载失败:{message}({code})`,"chat.loadOlder":`加载更早`,"chat.scrollOlder":`向上滚动查看更早消息`,"chat.loadingOlder":`正在加载更早消息…`,"chat.loadOlderError":`更早消息加载失败:{message}`,"chat.retryOlder":`重试加载`,"chat.toBottom":`回到底部`,"chat.filesChanged":`{count} 个文件已更改`,"chat.fileEdited":`已编辑 {name}`,"chat.filesEdited":`已编辑 {count} 个文件`,"chat.viewChanges":`查看变更`,"chat.hideChanges":`收起变更`,"chat.showMoreFiles":`再显示 {count} 个文件`,"chat.collapseFiles":`收起文件`,"diff.code":`代码`,"diff.wrap":`自动换行`,"diff.unwrap":`取消换行`,"diff.copy":`复制`,"diff.copied":`已复制`,"diff.collapseAria":`折叠差异`,"diff.expandAria":`展开 {count} 行隐藏内容`,"diff.collapse":`折叠`,"diff.expand":`展开 {count} 行`,"chat.deepDiving":`正在处理`,"chat.statusUnconfirmed":`连接中断,任务状态待确认`,"chat.deepDivingFor":`正在处理 · {duration}`,"chat.turnNavigation.label":`轮次导航`,"chat.turnNavigation.jump":`跳转到用户消息 {turn}`,"chat.turnNavigation.jumpLoad":`加载并跳转到用户消息 {turn}`,"chat.turnNavigation.turn":`用户消息 {turn}`,"settings.links.title":`网页链接默认打开方式`,"settings.links.description":`对话中网页链接的打开位置`,"settings.links.sidebar":`应用内侧边栏`,"settings.links.newTab":`默认浏览器`,"settings.transcript.title":`工作步骤展示`,"settings.transcript.description":`选择希望看到多少工具调用细节`,"settings.transcript.compact":`简洁`,"settings.transcript.standard":`标准`,"settings.transcript.detailed":`详细`,"settings.transcript.verbose":`完全展开`,"fileOpen.title":`无法打开文件`,"fileOpen.unknown":`无法打开此文件`,"message.extraBlock":`附加内容块`,"message.systemPrompt":`系统提示词`,"message.systemPromptUpdate":`系统提示词更新`,"message.toolAdded":`已添加工具:{name}`,"message.toolRemoved":`已移除工具:{name}`,"message.toolsAdded":`新增:{names}`,"message.toolsAddedCount":`新增 {count} 个`,"message.toolsChanged":`新增 {added} 个,移除 {removed} 个`,"message.toolsRemoved":`移除:{names}`,"message.toolsRemovedCount":`移除 {count} 个`,"message.toolsUpdated":`工具已更新`,"message.contextInjection":`上下文注入`,"message.contextRecall":`跨会话召回`,"message.referenceSummary":`引用会话 · {labels}`,"message.referenceSeparator":`、`,"message.context.instructions.loaded":`已载入`,"message.context.instructions.added":`已新增`,"message.context.instructions.updated":`已更新`,"message.context.instructions.removed":`已移除`,"message.context.catalog.replaced":`替换目录`,"message.context.catalog.more":`…还有 {count} 条`,"message.context.snapshot.supersedes":`取代先前的快照`,"message.context.relay.from":`来自会话 {session}`,"message.context.recall.counts":`保留 {retained} 条 · 省略 {omitted} 条`,"message.context.recall.truncated":`已截断`,"message.compaction":`上下文已压缩`,"message.compaction.running":`正在压缩…`,"message.compaction.completed":`已压缩 {items} 条历史记录(约 {tokens} tokens)`,"message.compaction.expand":`点击查看压缩摘要`,"message.compaction.unavailable":`压缩摘要不可用`,"message.compaction.commandTitle":`compact`,"message.think":`思考`,"message.unknownSurface":`未知 surface 事件:{type}`,"message.unknownBlock":`未知内容块`,"message.turnProcess.toolCalls.one":`{count} 次工具调用`,"message.turnProcess.toolCalls.other":`{count} 次工具调用`,"message.turnProcess.messages.one":`{count} 条消息`,"message.turnProcess.messages.other":`{count} 条消息`,"message.turnProcess.subagents.one":`{count} 个 subagent`,"message.turnProcess.subagents.other":`{count} 个 subagent`,"message.turnProcess.thoughtForAWhile":`已思考`,"message.turnProcess.separator":` · `,"message.stopped":`已停止`,"message.edit":`编辑消息`,"message.edit.changed":`会话状态已变化,请核对当前历史后继续。`,"message.edit.cancel":`取消`,"message.edit.send":`发送`,"message.edit.sending":`正在回退并重跑…`,"message.edit.checkHistory":`请核对当前历史后再继续;编辑文本已保留,不会自动重发。`,"message.branch":`在新对话中分支`,"message.branchFailed":`分叉未完成:{message}`,"message.branchUnavailable":`仅可从已完成轮次的最后一条消息分支`,"message.retry.active":`正在重试模型请求`,"message.retry.cancelled":`模型请求重试已取消`,"message.retry.started":`已重试模型请求`,"message.retry.scheduled":`等待重试模型请求`,"message.retry.status":`{label}({retry}/{maximum}) · {seconds}s`,"message.retry.delay":`重试延迟:`,"message.retry.failure":`失败原因:`,"message.failure.auth":`API 密钥无效`,"message.accountStopped":`任务已停止`,"message.failure.accountSignedOut":`任务已因退出 DeepSeek 登录而停止。`,"message.failure.accountSignInRequired":`请先登录 DeepSeek,并确认请求地址支持账号认证。`,"message.failure.quota":`当前请求的额度已用尽`,"message.turnError":`本轮运行失败`,"message.maxTokens":`已达到输出 token 上限`,"message.maxTokens.hint":`回答被截断,已有输出保留在对话中。发送“继续”可让模型接着输出。`,"duration.secondUnit":`秒`,"duration.minuteUnit":`分`,"duration.hourUnit":`小时`,"command.running":`执行中…`,"command.failed":`指令失败`,"command.done":`已完成`,"command.title":`指令`,"row.running":`运行中`,"row.failed":`失败`,"json.truncated":`… 已截断,共 {total} 字符`,"clock.md":`{m}月{d}日`,"clock.ymd":`{y}年{m}月{d}日`},Xn={"message.stepProcess.thinking":`Analyzing the request`,"message.stepProcess.read":`Reading files`,"message.stepProcess.readImage":`Reading images`,"message.stepProcess.write":`Writing files`,"message.stepProcess.search":`Searching code`,"message.stepProcess.edit":`Editing files`,"message.stepProcess.commands":`Running commands`,"message.stepProcess.code":`Running code`,"message.stepProcess.webSearch":`Searching the web`,"message.stepProcess.webFetch":`Visiting web pages`,"message.stepProcess.subagents":`Coordinating subagents`,"message.stepProcess.plan":`Updating the plan`,"message.stepProcess.questions":`Waiting for your action`,"message.stepProcess.tools":`Calling tools`,"message.stepProcess.prepare.read":`Preparing to read files`,"message.stepProcess.prepare.readImage":`Preparing to read images`,"message.stepProcess.prepare.write":`Preparing to write files`,"message.stepProcess.prepare.search":`Preparing to search code`,"message.stepProcess.prepare.edit":`Preparing to edit files`,"message.stepProcess.prepare.commands":`Preparing to run commands`,"message.stepProcess.prepare.code":`Preparing to run code`,"message.stepProcess.prepare.webSearch":`Preparing to search the web`,"message.stepProcess.prepare.webFetch":`Preparing to visit web pages`,"message.stepProcess.prepare.subagents":`Preparing to coordinate subagents`,"message.stepProcess.prepare.plan":`Preparing to update the plan`,"message.stepProcess.prepare.questions":`Preparing questions`,"message.stepProcess.prepare.tools":`Preparing tool calls`,"message.stepProcess.done.thinking":`Analysis completed`,"message.stepProcess.done.read":`Read files`,"message.stepProcess.done.readImage":`Read images`,"message.stepProcess.done.write":`Wrote files`,"message.stepProcess.done.search":`Searched code`,"message.stepProcess.done.edit":`Edited files`,"message.stepProcess.done.commands":`Ran commands`,"message.stepProcess.done.code":`Ran code`,"message.stepProcess.done.webSearch":`Searched the web`,"message.stepProcess.done.webFetch":`Visited web pages`,"message.stepProcess.done.subagents":`Coordinated subagents`,"message.stepProcess.done.plan":`Updated the plan`,"message.stepProcess.done.questions":`Asked questions`,"message.stepProcess.done.tools":`Called tools`,"message.stepProcess.joinTwo":`{first} and {second}`,"message.stepProcess.comma":`, `,"message.stepProcess.sharedPrefix":``,"message.stepProcess.more":`{title}, etc.`,"message.trigger.request":`Execution requested`,"message.trigger.goal":`Continuing goal`,"message.trigger.agent":`Task message received`,"message.trigger.team":`Team message received`,"message.trigger.subagent":`Subtask status updated`,"message.trigger.github":`GitHub event received`,"message.trigger.webhook":`External event received`,"message.trigger.schedule":`Automation task`,"message.trigger.job":`Background task updated`,"message.trigger.plugin":`Plugin status updated`,"message.trigger.explanation":`This notification triggered this response.`,"message.turnProcess.worked":`Completed`,"message.turnProcess.took":`Completed in `,"message.turnProcess.failed":`Failed`,"view.chat":`Chat`,"image.open":`View full image`,"image.loading":`Loading image…`,"image.failed":`Image preview unavailable`,"image.dialog":`Image preview`,"image.close":`Close image preview`,"duration.milliseconds":`{milliseconds}ms`,"chat.loadingHistory":`Loading history…`,"chat.syncing":`Fetching latest messages…`,"chat.loadingDiff":`Loading diff…`,"chat.retryDiff":`Retry`,"chat.loadError":`Failed to load history: {message} ({code})`,"chat.loadOlder":`Load earlier`,"chat.scrollOlder":`Scroll up for earlier messages`,"chat.loadingOlder":`Loading earlier messages…`,"chat.loadOlderError":`Could not load earlier messages: {message}`,"chat.retryOlder":`Retry loading`,"chat.toBottom":`Back to bottom`,"chat.filesChanged":`{count} files changed`,"chat.fileEdited":`Edited {name}`,"chat.filesEdited":`Edited {count} files`,"chat.viewChanges":`View changes`,"chat.hideChanges":`Hide changes`,"chat.showMoreFiles":`Show {count} more`,"chat.collapseFiles":`Collapse files`,"diff.code":`Code`,"diff.wrap":`Wrap lines`,"diff.unwrap":`Unwrap lines`,"diff.copy":`Copy`,"diff.copied":`Copied`,"diff.collapseAria":`Collapse diff`,"diff.expandAria":`Expand {count} hidden lines`,"diff.collapse":`Collapse`,"diff.expand":`Expand {count} lines`,"chat.deepDiving":`Working`,"chat.statusUnconfirmed":`Connection interrupted; task status unconfirmed`,"chat.deepDivingFor":`Working · {duration}`,"chat.turnNavigation.label":`Turn navigation`,"chat.turnNavigation.jump":`Jump to user message {turn}`,"chat.turnNavigation.jumpLoad":`Load and jump to user message {turn}`,"chat.turnNavigation.turn":`User message {turn}`,"settings.links.title":`Open chat links in`,"settings.links.description":`Choose where to open web links`,"settings.links.sidebar":`In-App Sidebar`,"settings.links.newTab":`Default Browser`,"settings.transcript.title":`Work details`,"settings.transcript.description":`Choose how much detail to show for tool calls`,"settings.transcript.compact":`Compact`,"settings.transcript.standard":`Standard`,"settings.transcript.detailed":`Detailed`,"settings.transcript.verbose":`Verbose`,"fileOpen.title":`Couldn’t open file`,"fileOpen.unknown":`Couldn’t open this file`,"message.extraBlock":`Extra content block`,"message.systemPrompt":`System prompt`,"message.systemPromptUpdate":`System prompt update`,"message.toolAdded":`Tool added: {name}`,"message.toolRemoved":`Tool removed: {name}`,"message.toolsAdded":`Added: {names}`,"message.toolsAddedCount":`{count} added`,"message.toolsChanged":`{added} added, {removed} removed`,"message.toolsRemoved":`Removed: {names}`,"message.toolsRemovedCount":`{count} removed`,"message.toolsUpdated":`Tools updated`,"message.contextInjection":`Context injection`,"message.contextRecall":`Session recall`,"message.referenceSummary":`Referenced session · {labels}`,"message.referenceSeparator":`, `,"message.context.instructions.loaded":`loaded`,"message.context.instructions.added":`added`,"message.context.instructions.updated":`updated`,"message.context.instructions.removed":`removed`,"message.context.catalog.replaced":`Replacement catalog`,"message.context.catalog.more":`… {count} more`,"message.context.snapshot.supersedes":`Supersedes earlier snapshots`,"message.context.relay.from":`From session {session}`,"message.context.recall.counts":`{retained} kept · {omitted} omitted`,"message.context.recall.truncated":`truncated`,"message.compaction":`Context compacted`,"message.compaction.running":`Compacting context…`,"message.compaction.completed":`Compacted {items} history items (~{tokens} tokens)`,"message.compaction.expand":`View compaction summary`,"message.compaction.unavailable":`Compaction summary unavailable`,"message.compaction.commandTitle":`compact`,"message.think":`Think`,"message.unknownSurface":`Unknown surface event: {type}`,"message.unknownBlock":`Unknown content block`,"message.turnProcess.toolCalls.one":`{count} tool call`,"message.turnProcess.toolCalls.other":`{count} tool calls`,"message.turnProcess.messages.one":`{count} message`,"message.turnProcess.messages.other":`{count} messages`,"message.turnProcess.subagents.one":`{count} subagent`,"message.turnProcess.subagents.other":`{count} subagents`,"message.turnProcess.thoughtForAWhile":`Thought for a while`,"message.turnProcess.separator":` · `,"message.stopped":`Stopped`,"message.edit":`Edit message`,"message.edit.changed":`Conversation state changed. Check current history before continuing.`,"message.edit.cancel":`Cancel`,"message.edit.send":`Send`,"message.edit.sending":`Reverting and rerunning…`,"message.edit.checkHistory":`Check current history before continuing. Your edit is retained and will not be resent automatically.`,"message.branch":`Branch into a new conversation`,"message.branchFailed":`Fork did not complete: {message}`,"message.branchUnavailable":`Available only on the last message of a completed turn`,"message.retry.active":`Retrying model request`,"message.retry.cancelled":`Model request retry cancelled`,"message.retry.started":`Retried model request`,"message.retry.scheduled":`Waiting to retry model request`,"message.retry.status":`{label} ({retry}/{maximum}) · {seconds}s`,"message.retry.delay":`Retry delay: `,"message.retry.failure":`Failure reason: `,"message.failure.auth":`API key is invalid`,"message.accountStopped":`Task stopped`,"message.failure.accountSignedOut":`Stopped because you signed out of DeepSeek.`,"message.failure.accountSignInRequired":`Sign in to DeepSeek and ensure the request destination supports account authentication.`,"message.failure.quota":`Request quota exhausted.`,"message.turnError":`This turn failed`,"message.maxTokens":`Output token limit reached`,"message.maxTokens.hint":`The reply was cut off; earlier output is preserved in the conversation. Send "continue" to let the model resume.`,"duration.secondUnit":`s`,"duration.minuteUnit":`m `,"duration.hourUnit":`h `,"command.running":`Running…`,"command.failed":`Command failed`,"command.done":`Completed`,"command.title":`Command`,"row.running":`Running`,"row.failed":`Failed`,"json.truncated":`… truncated, {total} characters total`,"clock.md":`{m}/{d}`,"clock.ymd":`{y}-{m}-{d}`},Zn=`@deepseek-ai/dsh-client-ui-chat/ReasoningRow.module.css`;if(typeof document<`u`&&document.querySelector(`style[data-plugin-css=`+JSON.stringify(Zn)+`]`)===null){let e=document.createElement(`style`);e.dataset.plugin=`@deepseek-ai/dsh-client-ui-chat`,e.dataset.pluginCss=Zn,e.textContent=`.nAJelq_root{flex-direction:column;display:flex}.nAJelq_root:not([data-expanded]){contain:size layout;height:calc(24px + var(--dsh-content-font-delta,0px))}.nAJelq_row{overflow:hidden}.nAJelq_root[data-expanded] [data-open] [data-disclosure-row]{z-index:1;background:var(--dsw-alias-bg-base);position:sticky;top:0}.nAJelq_leading{flex-shrink:0}.nAJelq_title{font-weight:400}.nAJelq_separator{background:var(--dsw-alias-label-caption);border-radius:1px;flex:none;width:2px;height:2px;margin:0 8px}.nAJelq_summary{min-width:0;font-size:var(--dsh-content-font-size-secondary,13px);line-height:calc(20px + var(--dsh-content-font-delta-secondary,0px));white-space:nowrap;flex:auto;overflow:hidden}.nAJelq_summaryText{text-overflow:ellipsis;display:block;overflow:hidden}.nAJelq_summary[data-streaming]{mask-image:linear-gradient(90deg,#000 calc(100% - 48px),#0000)}.nAJelq_summary[data-streaming] .nAJelq_summaryText{text-overflow:clip;overflow:visible}.nAJelq_root:not([data-preview]) .nAJelq_separator,.nAJelq_root:not([data-preview]) .nAJelq_summary{display:none}.nAJelq_thinkBody{padding:4px 0 4px calc(22px + var(--dsh-content-font-delta,0px));min-width:0}`,document.head.appendChild(e)}var Qn={leading:`nAJelq_leading`,root:`nAJelq_root`,row:`nAJelq_row`,separator:`nAJelq_separator`,summary:`nAJelq_summary`,summaryText:`nAJelq_summaryText`,thinkBody:`nAJelq_thinkBody`,title:`nAJelq_title`};let $n=/* @__PURE__ */ (0,f.jsx)(p.IconThinkOutlineRegular,{size:14});function er(e){let t=e.indexOf(`
|
|
10
|
+
default:Ot(this.#r)}}fail(){this.#d=this.#n,this.#r=`invalid`,this.#c=null}beginKey(e){this.#r=`key`,this.#a=e+1,this.#o=!1,this.#i=!1}stepKey(e,t){if(e<` `){this.fail();return}if(this.#i){this.#i=!1;return}if(e===`\\`){this.#i=!0,this.#o=!0;return}if(e!==`"`)return;let n=this.slice(this.#a,t);if(this.#o)try{this.#s=JSON.parse(`"${n}"`)}catch{this.fail();return}else this.#s=n;this.#r=`colon`}open(e){this.#p.has(this.#s)||this.#m.push(this.#s),this.#p.set(this.#s,e),this.#c=e}beginValue(e,t){Tt(e)||(e===`"`?(this.open({kind:`string`,start:t+1,end:-1,needsDecoding:!1,invalidAt:void 0,length:void 0,text:void 0,prefixes:void 0}),this.#i=!1,this.#r=`string`):e===`}`||e===`,`||e===`:`||e===`]`?this.fail():(this.open({kind:`value`,start:t,end:-1,parsed:void 0,invalid:!1}),e===`{`||e===`[`?(this.#r=`nested`,this.#l=[e===`{`?`}`:`]`],this.#u=!1,this.#i=!1):this.#r=`scalar`))}stepScalar(e,t){(e===`,`||e===`}`||Tt(e))&&(this.closeValue(t),this.#r=e===`,`?`key-only`:e===`}`?`closed`:`comma-or-end`)}stepNested(e,t){if(this.#u)this.#u=!1;else if(e===`"`)this.#u=!0;else if(e===`{`||e===`[`)this.#l.push(e===`{`?`}`:`]`);else if(e===`}`||e===`]`){if(this.#l.pop()!==e){this.fail();return}this.#l.length===0&&(this.closeValue(t+1),this.#r=`comma-or-end`)}}closeValue(e){let t=this.#c;t.end=e,this.#c=null}};function Ot(e,t){let n=JSON.stringify(e)??String(e);throw Error(`unreachable variant${t?` in ${t}`:``}: ${n}`)}function kt(e){switch(e.kind){case`node`:return JSON.stringify([`node`,e.key,e.groupPart??null]);case`group`:return JSON.stringify([`group`,e.key]);default:return Ot(e)}}function At(e,t){let n=e.counts.slice(0,3).map(({kind:e})=>t(`message.stepProcess.done.${e}`)),r=n[0];if(r===void 0)return t(`message.stepProcess.done.thinking`);let i=e=>e.charAt(0).toLowerCase()+e.slice(1),a=n[1];if(a===void 0)return r;if(n.length===2){let e=t(`message.stepProcess.sharedPrefix`);return t(`message.stepProcess.joinTwo`,{first:r,second:i(e!==``&&r.startsWith(e)&&a.startsWith(e)?a.slice(e.length):a)})}let o=[r,...n.slice(1).map(i)].join(t(`message.stepProcess.comma`));return e.counts.length>3?t(`message.stepProcess.more`,{title:o}):o}function jt(e=0){let[t,n]=(0,d.useState)(null);return{expanded:t===e,setExpanded:(0,d.useCallback)(t=>{n(t?e:null)},[e]),toggle:(0,d.useCallback)(()=>{n(t=>t===e?null:e)},[e])}}function Mt(e){let t=t=>e.subscribe(t),n=()=>e.getSnapshot();return function(){return jt((0,d.useSyncExternalStore)(t,n))}}function Nt(e){let t=e.clientHeight;return{top:e.scrollTop,height:t,floor:Math.max(0,e.scrollHeight-t)}}var Pt=class e{following;threshold;static owners=/* @__PURE__ */ new WeakMap;target=null;sampledTop;constructor(e,t){this.following=e,this.threshold=t}static forElement(e){return this.owners.get(e)}bind(t){return e.owners.set(t,this),()=>{e.owners.get(t)===this&&e.owners.delete(t)}}get active(){return this.following}get animating(){return this.target!==null}nearBottom(e){return e.floor-e.top<=this.threshold}setFollowing(e){this.following=e,e||(this.target=null)}reset(){this.setFollowing(!1),this.sampledTop=void 0}sample(e,t=this.sampledTop===void 0||Math.abs(e.top-this.sampledTop)>.5){return this.sampledTop=e.top,!this.animating&&t&&(this.following=this.nearBottom(e)),this.active}settle(e){let t=this.target;return this.target=null,this.sample(e,t===null?void 0:Math.abs(e.top-Math.min(t,e.floor))>this.threshold)}jump(e,t,n){let r=this.animating;this.target=null;let i=Math.max(0,Math.min(t.floor,n));r?e.scrollTo({top:i,behavior:`instant`}):i!==t.top&&(e.scrollTop=i);let a={...t,top:e.scrollTop};return this.sampledTop=a.top,this.following=this.nearBottom(a),a}toBottom(e,t,n){return this.following=!0,n===`instant`||t.top>=t.floor||!this.animating&&this.nearBottom(t)||typeof matchMedia==`function`&&matchMedia(`(prefers-reduced-motion: reduce)`).matches?this.jump(e,t,t.floor):(this.target===null&&(this.target=t.floor,e.scrollTo({top:t.floor,behavior:`smooth`})),t)}interrupt(e,t){this.animating&&(this.target=null,this.sampledTop=t.top,e.scrollTo({top:t.top,behavior:`instant`}))}};function Ft(e,t){let[n]=(0,d.useState)(()=>new Pt(e,t));return n}let It={canScrollUp:!1,canScrollDown:!1},Lt=/* @__PURE__ */ new Set([`ArrowUp`,`ArrowDown`,`PageUp`,`PageDown`,`Home`,`End`,` `]);function Rt(e,t,n,r){let i=Ft(!1,1),a=(0,d.useRef)(null),[o,s]=(0,d.useState)(It),c=(0,d.useCallback)(e=>{a.current=e},[]),l=(0,d.useCallback)(t=>{let n=e.current,r=It;if(n!==null&&n.closest(`[hidden], [data-group-expanded-mode]`)===null){let e=Nt(n),o=t===`resize`?a.current:null;if(o!==null)e=i.jump(n,e,o===`bottom`?e.floor:0),o===`top`&&i.setFollowing(!1),a.current=null;else{let r=i.animating;t===`scrollend`?i.settle(e):i.sample(e),i.active&&(t===`resize`||t===`scrollend`&&r)&&(e=i.toBottom(n,e,`smooth`))}r={canScrollUp:e.top>1,canScrollDown:e.top<e.floor-1}}else i.reset();s(e=>e.canScrollUp===r.canScrollUp&&e.canScrollDown===r.canScrollDown?e:r)},[e,i]),u=(0,d.useCallback)(()=>{let t=e.current;t!==null&&i.animating&&i.interrupt(t,Nt(t))},[e,i]),f=(0,d.useMemo)(()=>({onScroll:()=>{l(`scroll`)},onWheel:u,onTouchStart:u,onPointerDown:u,onKeyDown:e=>{!e.defaultPrevented&&Lt.has(e.key)&&u()}}),[u,l]);return(0,d.useLayoutEffect)(()=>{u(),i.reset(),(!r||!n)&&(a.current=null)},[i,r,u,n]),(0,d.useLayoutEffect)(()=>{let r=e.current;if(r===null||!n||typeof ResizeObserver>`u`)return;let a=i.bind(r),o=new ResizeObserver(()=>{l(`resize`)}),s=e=>{e.target===r&&l(`scrollend`)};return r.addEventListener(`scrollend`,s),o.observe(r),t.current!==null&&o.observe(t.current),()=>{a(),o.disconnect(),r.removeEventListener(`scrollend`,s)}},[e,t,i,n,l]),{edges:o,events:f,initialize:c}}let zt=`@deepseek-ai/dsh-client-ui-chat/ChatGroupSeat.module.css`;if(typeof document<`u`&&document.querySelector(`style[data-plugin-css=`+JSON.stringify(zt)+`]`)===null){let e=document.createElement(`style`);e.dataset.plugin=`@deepseek-ai/dsh-client-ui-chat`,e.dataset.pluginCss=zt,e.textContent=`.yzVGVG_root{min-width:0}.yzVGVG_title{max-width:100%;color:var(--dsw-alias-label-tertiary);font:inherit;font-size:var(--dsh-content-font-size,14px);text-align:left;cursor:pointer;background:0 0;border:0;align-items:center;gap:6px;padding:0;transition:color .1s;display:flex}.yzVGVG_title:hover{color:var(--dsw-alias-label-secondary)}.yzVGVG_leading{width:calc(16px + var(--dsh-content-font-delta,0px));height:calc(16px + var(--dsh-content-font-delta,0px));color:inherit;flex:none;justify-content:center;align-items:center;display:inline-flex;position:relative}.yzVGVG_leading svg{width:calc(14px + var(--dsh-content-font-delta,0px));height:calc(14px + var(--dsh-content-font-delta,0px))}.yzVGVG_leading svg[width="16"]{width:calc(16px + var(--dsh-content-font-delta,0px));height:calc(16px + var(--dsh-content-font-delta,0px))}.yzVGVG_activityIcon,.yzVGVG_chevron{justify-content:center;align-items:center;transition:opacity .1s;display:inline-flex;position:absolute;inset:0}.yzVGVG_activityIcon{opacity:1}.yzVGVG_chevron,.yzVGVG_title:is(:hover,:focus-visible) .yzVGVG_activityIcon{opacity:0}.yzVGVG_title:is(:hover,:focus-visible) .yzVGVG_chevron{opacity:1}.yzVGVG_title[aria-expanded=true] .yzVGVG_activityIcon{opacity:0}.yzVGVG_title[aria-expanded=true] .yzVGVG_chevron{opacity:1}.yzVGVG_title[aria-expanded=true]{padding-bottom:8px}.yzVGVG_body{--dsh-chat-flow-gap:6px;overscroll-behavior-y:auto;scrollbar-gutter:stable;max-height:min(400px,50vh);overflow-y:auto}.yzVGVG_label{text-overflow:ellipsis;white-space:nowrap;min-width:0;overflow:hidden}.yzVGVG_fadeTop{mask-image:linear-gradient(#0000 0,#000 24px 100%)}.yzVGVG_fadeBottom{mask-image:linear-gradient(#000 0 calc(100% - 24px),#0000 100%)}.yzVGVG_fadeTop.yzVGVG_fadeBottom{mask-image:linear-gradient(#0000 0,#000 24px calc(100% - 24px),#0000 100%)}@media (prefers-reduced-motion:reduce){.yzVGVG_title,.yzVGVG_activityIcon,.yzVGVG_chevron{transition:none}}.yzVGVG_content{flex-direction:column;display:flex}.yzVGVG_content>*{flex-shrink:0}.yzVGVG_content>:not([hidden]):not(:empty)~:not([hidden]):not(:empty){margin-top:var(--dsh-chat-flow-gap,6px)}.yzVGVG_expandedBody{scrollbar-gutter:auto;max-height:none;overflow:visible}`,document.head.appendChild(e)}var W={activityIcon:`yzVGVG_activityIcon`,body:`yzVGVG_body`,chevron:`yzVGVG_chevron`,content:`yzVGVG_content`,expandedBody:`yzVGVG_expandedBody`,fadeBottom:`yzVGVG_fadeBottom`,fadeTop:`yzVGVG_fadeTop`,label:`yzVGVG_label`,leading:`yzVGVG_leading`,root:`yzVGVG_root`,title:`yzVGVG_title`};let Bt={thinking:/* @__PURE__ */ (0,f.jsx)(p.IconThinkOutlineRegular,{}),read:/* @__PURE__ */ (0,f.jsx)(p.IconBrowseOutlineRegular,{size:14}),readImage:/* @__PURE__ */ (0,f.jsx)(p.IconBrowseOutlineRegular,{size:14}),search:/* @__PURE__ */ (0,f.jsx)(p.IconSearchOutlineRegular,{size:14}),edit:/* @__PURE__ */ (0,f.jsx)(p.IconEditOutlineRegular,{size:14}),write:/* @__PURE__ */ (0,f.jsx)(p.IconEditOutlineRegular,{size:14}),commands:/* @__PURE__ */ (0,f.jsx)(p.IconApiOutlineRegular,{}),code:/* @__PURE__ */ (0,f.jsx)(p.IconCodeOutlineRegular,{size:14}),webSearch:/* @__PURE__ */ (0,f.jsx)(p.IconGlobeOutlineRegular,{}),webFetch:/* @__PURE__ */ (0,f.jsx)(p.IconBrowseOutlineRegular,{size:14}),subagents:/* @__PURE__ */ (0,f.jsx)(p.IconAgentPresetOutlineRegular,{size:14}),plan:/* @__PURE__ */ (0,f.jsx)(p.IconPlanOutlineRegular,{}),questions:/* @__PURE__ */ (0,f.jsx)(p.IconQuestionOutlineRegular,{}),tools:/* @__PURE__ */ (0,f.jsx)(p.IconSparkleRegular,{size:14})};function Vt(e,t){return e.activity===t.activity&&e.detail===t.detail&&e.preparing===t.preparing}function Ht(e,t){let[n,r]=(0,d.useState)(e),i=(0,d.useRef)(n),a=(0,d.useRef)(e),o=(0,d.useRef)(Date.now());return(0,d.useEffect)(()=>{if(a.current=e,!t||Vt(i.current,e))return;let n=150-(Date.now()-o.current),s=()=>{let e=a.current;i.current=e,o.current=Date.now(),r(e)};if(n<=0){s();return}let c=setTimeout(s,n);return()=>{clearTimeout(c)}},[t,e.activity,e.detail,e.preparing]),t?n:e}let Ut=(0,d.memo)(function({members:e,...t}){return e.map(e=>/* @__PURE__ */ (0,d.createElement)(St,{...t,key:kt(e),nodeKey:e.key,...e.groupPart===void 0?{}:{groupPart:e.groupPart}}))}),Wt=(0,d.memo)(function({groupKey:e,useChatGroup:t,usePresentation:n,t:r,open:i,bodyId:a,toggle:o}){let s=t(e,e=>e?.data),c=n(e=>s?.closed===!1&&e.liveProcessDetail),l=Ht({activity:s?.summary.running??`thinking`,detail:s?.summary.runningDetail??``,preparing:s?.summary.preparing===!0},s!==void 0&&!s.closed);if(s===void 0)return null;let u=s.closed?At(s.summary,r):l.preparing?r(`message.stepProcess.prepare.${l.activity===`thinking`?`tools`:l.activity}`):r(`message.stepProcess.${l.activity}`),d=c&&!s.closed?l.detail:``,m=d===``?u:`${u}${r(`message.turnProcess.separator`)}${d}`,h=s.closed?s.summary.counts[0]?.kind??`thinking`:l.activity;return/* @__PURE__ */ (0,f.jsxs)(`button`,{type:`button`,className:W.title,"aria-expanded":i,"aria-controls":a,"data-process-activity":h,onClick:e=>{e.currentTarget.focus(),o()},children:[/* @__PURE__ */ (0,f.jsxs)(`span`,{className:W.leading,"aria-hidden":`true`,children:[/* @__PURE__ */ (0,f.jsx)(`span`,{className:W.activityIcon,"data-step-process-icon":!0,children:Bt[h]}),/* @__PURE__ */ (0,f.jsx)(`span`,{className:W.chevron,"data-step-process-chevron":!0,children:i?/* @__PURE__ */ (0,f.jsx)(p.IconChevronUpOutlineRegular,{}):/* @__PURE__ */ (0,f.jsx)(p.IconChevronDownOutlineRegular,{})})]}),/* @__PURE__ */ (0,f.jsx)(p.TextShimmer,{active:!s.closed,children:/* @__PURE__ */ (0,f.jsx)(p.TextShimmer,{className:W.label,children:m})})]})}),Gt=(0,d.memo)(function({groupKey:e,useChatGroup:t,...n}){let r=t(e,e=>e?.members),i=t(e,e=>e?.data.turn),a=t(e,e=>e?.data.closed),o=n.usePresentation(e=>e.foldCompletedTurns),{expanded:s,setExpanded:c}=jt(),l=r?.[0]?.key??``,u=n.useChatNodeProcess(l),p=n.useChatNode(l,e=>{let t=e?.location;return t?.kind===`turn`||t?.kind===`step`?t.turn:void 0}),m=n.usePresentation(e=>e.stepGrouping===`collapsed`||e.stepGrouping===`history`&&p?.status!==`open`),h=p?.end?.data.reason.kind,g=u?.turnClosed===!1||u?.hasInterleavedInput===!0||p?.end?.data.finalAssistantStep===null||h===`aborted`||h===`error`,_=u?.spec,v=(0,d.useCallback)(e=>i===void 0?void 0:ht(e,i),[i]),y=n.useStore(v),b=o&&u?.turnClosed===!0&&_!==void 0&&!g&&y?.answerStep!==(_.answerStep??0),x=_t(b,(0,d.useCallback)(()=>{_!==void 0&&!g&&n.actions.setTurnProcessOpen(_.turn,_.answerStep??0,!0)},[n.actions,_,g]));(0,d.useEffect)(()=>{b&&x.current?.hasAttribute(`hidden`)&&c(!1)},[b,x,c]);let S=(0,d.useCallback)(()=>{c(!0)},[c]),C=_t(m&&!s,S),w=(0,d.useRef)(null),T=(0,d.useId)(),{edges:E,events:D,initialize:O}=Rt(C,w,s,m),k=(0,d.useCallback)(()=>{s||O(a===!1?`bottom`:`top`),c(!s)},[a,O,s,c]);if(r===void 0)return null;let A=[W.body,m?``:W.expandedBody,m&&E.canScrollUp?W.fadeTop:``,m&&E.canScrollDown?W.fadeBottom:``];return/* @__PURE__ */ (0,f.jsxs)(`div`,{ref:x,className:W.root,"data-chat-group-key":e,"data-chat-flow-key":e,"data-chat-anchor-key":`group:${e}`,"data-chat-turn":i,"data-chat-paging-anchor":m&&!s||void 0,"data-step-process":!0,"data-group-expanded-mode":!m||void 0,children:[/* @__PURE__ */ (0,f.jsx)(`div`,{hidden:!m,children:/* @__PURE__ */ (0,f.jsx)(Wt,{groupKey:e,useChatGroup:t,usePresentation:n.usePresentation,t:n.t,open:s,bodyId:T,toggle:k})}),/* @__PURE__ */ (0,f.jsx)(`div`,{ref:C,id:T,className:A.join(` `),"data-step-process-body":!0,"data-scroll-up":E.canScrollUp||void 0,"data-scroll-down":E.canScrollDown||void 0,...D,children:/* @__PURE__ */ (0,f.jsx)(`div`,{ref:w,className:W.content,"data-step-process-content":!0,"data-chat-flow":``,children:/* @__PURE__ */ (0,f.jsx)(Ut,{...n,members:r})})})]})});function Kt(e){return typeof e==`object`?e.key:e}function qt(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 Jt(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 Yt(e,t){if(e===void 0)throw Error(`Unexpected undefined${t?`: ${t}`:``}`);return e}let Xt=(e,t)=>Math.abs(e-t)<1.01,Zt=(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)}})},Qt,$t=()=>{if(Qt!==void 0)return Qt;if(typeof navigator>`u`)return Qt=!1;if(/iP(hone|od|ad)/.test(navigator.userAgent))return Qt=!0;let e=navigator.maxTouchPoints;return Qt=navigator.platform===`MacIntel`&&e!==void 0&&e>0},en=e=>{let{offsetWidth:t,offsetHeight:n}=e;return{width:t,height:n}},tn=e=>e,nn=e=>{let t=Math.max(e.startIndex-e.overscan,0),n=Math.min(e.endIndex+e.overscan,e.count-1)-t+1,r=Array(n);for(let e=0;e<n;e++)r[e]=t+e;return r},rn=(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(en(n)),!r.ResizeObserver)return()=>{};let a=new r.ResizeObserver(t=>{let r=()=>{let e=t[0];if(e?.borderBoxSize){let t=e.borderBoxSize[0];if(t){i({width:t.inlineSize,height:t.blockSize});return}}i(en(n))};e.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(r):r()});return a.observe(n,{box:`border-box`}),()=>{a.unobserve(n)}},an={passive:!0},on=typeof window>`u`||`onscrollend`in window,sn=(e,t,n)=>{let r=e.scrollElement;if(!r)return;let i=e.targetWindow;if(!i)return;let a=e.options.useScrollendEvent&&on,o=0,s=a?null:Zt(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,an),a&&r.addEventListener(`scrollend`,u,an),()=>{r.removeEventListener(`scroll`,l),a&&r.removeEventListener(`scrollend`,u),s?.cancel()}},cn=(e,t)=>sn(e,t,t=>{let{horizontal:n,isRtl:r}=e.options;return n?t.scrollLeft*(r&&-1||1):t.scrollTop}),ln=(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`]},un=(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})};function dn(e,t,n,r){if(t===0)return!1;let i=r(0),a=/* @__PURE__ */ 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 fn=class{constructor(e){this.unsubs=[],this.scrollElement=null,this.targetWindow=null,this.isScrolling=!1,this.scrollState=null,this.measurementsCache=[],this._singleLaneMeasurements=null,this.itemSizeCache=/* @__PURE__ */ new Map,this.itemSizeCacheVersion=0,this.laneAssignments=/* @__PURE__ */ 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.scrollAdjustments=0,this._iosDeferredAdjustment=0,this._iosTouching=!1,this._iosJustTouchEnded=!1,this._iosTouchEndTimerId=null,this._intendedScrollOffset=null,this._clampedAdjustment=null,this.elementsCache=/* @__PURE__ */ new Map,this.now=()=>{var e;return((e=this.targetWindow?.performance)?.now)?.call(e)??Date.now()},this.observer=/* @__PURE__ */ (()=>{let e=null,t=()=>e||(!this.targetWindow||!this.targetWindow.ResizeObserver?null:e=new this.targetWindow.ResizeObserver(e=>{e.forEach(e=>{let t=()=>{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}}};this.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(t):t()})}));return{disconnect:()=>{var n;(n=t())==null||n.disconnect(),e=null},observe:e=>t()?.observe(e,{box:`border-box`}),unobserve:e=>t()?.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:tn,rangeExtractor:nn,onChange:()=>{},measureElement:ln,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=>Kt(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||dn(e,o,l,t.getItemKey))&&(i=u)}}this.options=t,a&&(this.pendingMin=0,this.itemSizeCacheVersion++);let o=!1,s=0;if(r&&this.scrollOffset!==null){let[e,t]=r,n=this.getMeasurements(),{count:a,getItemKey:c}=this.options,l=0;for(;l<a&&c(l)!==e;)l++;if(l<a){let e=n[l];if(e){let n=Math.max(0,e.start+t);!i&&n!==this.scrollOffset&&(s=n-this.scrollOffset,this.scrollOffset=n,o=!0)}}}(o||i)&&(this.pendingScrollAnchor=[o?r[0]:null,o?r[1]:0,i,s])},this.notify=e=>{var t,n;(n=(t=this.options).onChange)==null||n.call(t,this,e)},this.maybeNotify=Jt(()=>(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=()=>{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,this.isScrolling=!1,this.scrollDirection=null,this._iosDeferredAdjustment=0,this._iosTouching=!1,this._iosJustTouchEnded=!1,this._clampedAdjustment=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}if(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)=>{if(t&&this._intendedScrollOffset===null&&e===this.scrollOffset)return;this._intendedScrollOffset!==null&&Math.abs(e-this._intendedScrollOffset)<1.5&&(e=this._intendedScrollOffset),this._intendedScrollOffset=null,this._clampedAdjustment!==null&&Math.abs(e-this._clampedAdjustment.maxAtWrite)>=1.5&&(this._clampedAdjustment=null),this.scrollAdjustments=0;let n=this.getScrollOffset();this.scrollDirection=t?n===e?this.scrollDirection:n<e?`forward`:`backward`:null,this.scrollOffset=e,this.isScrolling=t,this._flushIosDeferredIfReady(),this.scrollState&&this.scheduleScrollReconcile(),this.maybeNotify()})),`addEventListener`in this.scrollElement){let e=this.scrollElement,t=()=>{this._iosTouching=!0,this._iosJustTouchEnded=!1,this._iosTouchEndTimerId!==null&&this.targetWindow!=null&&(this.targetWindow.clearTimeout(this._iosTouchEndTimerId),this._iosTouchEndTimerId=null)},n=()=>{this._iosTouching=!1,$t()&&this.targetWindow!=null&&(this._iosJustTouchEnded=!0,this._iosTouchEndTimerId=this.targetWindow.setTimeout(()=>{this._iosJustTouchEnded=!1,this._iosTouchEndTimerId=null,this._flushIosDeferredIfReady()},150))};e.addEventListener(`touchstart`,t,an),e.addEventListener(`touchend`,n,an),this.unsubs.push(()=>{e.removeEventListener(`touchstart`,t),e.removeEventListener(`touchend`,n),this._iosTouchEndTimerId!==null&&this.targetWindow!=null&&(this.targetWindow.clearTimeout(this._iosTouchEndTimerId),this._iosTouchEndTimerId=null)})}this._scrollToOffset(this.getScrollOffset(),{adjustments:void 0,behavior:void 0})}let t=this.pendingScrollAnchor;if(this.pendingScrollAnchor=null,t&&this.scrollElement&&this.options.enabled){let[e,n,r,i]=t;e!==null&&!r&&($t()&&(this.isScrolling||this._iosTouching||this._iosJustTouchEnded)?i!==0&&(this._iosDeferredAdjustment+=i):this.scrollState?.behavior===`smooth`&&!Xt(this.getScrollOffset()-i,this.scrollState.lastTargetOffset)||this._scrollToOffset(this.getScrollOffset(),{adjustments:void 0,behavior:void 0})),r&&this.scrollToEnd({behavior:r})}this._retryClampedAdjustment()},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,{adjustments:void 0,behavior:void 0}))},this._flushIosDeferredIfReady=()=>{if(this._iosDeferredAdjustment===0||this.isScrolling||this._iosTouching||this._iosJustTouchEnded)return;let e=this.getScrollOffset(),t=this.getMaxScrollOffset();if(e<0||e>t)return;if(this._iosDeferredAdjustment<0&&e>=t-1){this._iosDeferredAdjustment=0;return}let n=this._iosDeferredAdjustment;this._iosDeferredAdjustment=0,this._scrollToOffset(e,{adjustments:this.scrollAdjustments+=n,behavior:void 0})},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=Jt(()=>[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=Jt(()=>[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=qt(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=Jt(()=>[this.getMeasurements(),this.getSize(),this.getScrollOffset(),this.options.lanes],(e,t,n,r)=>e.length===0||t===0?(this.range=null,null):(this.range=hn(e,t,n,r,r===1&&this._singleLaneMeasurements!==null?this._singleLaneMeasurements.flat:null),this.range),{key:!1,debug:()=>this.options.debug}),this.getVirtualIndexes=Jt(()=>{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]},(e,t,n,r,i)=>r===null||i===null?[]:e({startIndex:r,endIndex:i,overscan:t,count:n}),{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(!this.scrollState||this.scrollState.behavior!==`smooth`)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)),(!this.isScrolling||this.scrollState)&&this.shouldMeasureDuringScroll(t)&&this.resizeItem(t,this.options.measureElement(e,void 0,this))},this.resizeItem=(e,t)=>{if(!this.isIndexInRange(e))return;let n,r,i,a=this._singleLaneMeasurements?.flat;if(this.options.lanes===1&&a!=null)i=this.options.getItemKey(e),r=a[e*2],n=a[e*2+1];else{let t=this.measurementsCache[e];if(!t)return;i=t.key,r=t.start,n=t.size}let o=this.itemSizeCache.get(i)??n,s=t-o;if(s!==0){let a=this.options.anchorTo===`end`&&this.scrollState?.behavior!==`smooth`&&this.getVirtualDistanceFromEnd()<=this.options.scrollEndThreshold,c=a?this.getTotalSize():0,l=this.getScrollOffset()+this.scrollAdjustments,u=this.itemSizeCache.has(i)?r+o<=l&&this.scrollDirection!==`backward`:r<l,d=this.scrollState?.behavior!==`smooth`&&(this.shouldAdjustScrollPositionOnItemSizeChange===void 0?u:this.shouldAdjustScrollPositionOnItemSizeChange(this.measurementsCache[e]??{index:e,key:i,start:r,size:n,end:r+n,lane:0},s,this));(this.pendingMin===null||e<this.pendingMin)&&(this.pendingMin=e),this.itemSizeCache.set(i,t),this.itemSizeCacheVersion++;let f=!1;a?f=this.applyScrollAdjustment(this.getTotalSize()-c):d&&(f=this.applyScrollAdjustment(s)),this.notify(f),this._retryClampedAdjustment()}},this.getVirtualItems=Jt(()=>[this.getVirtualIndexes(),this.getMeasurements()],(e,t)=>{let n=[];for(let r=0,i=e.length;r<i;r++){let i=t[e[r]];n.push(i)}return n},{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 Yt(t[pn(0,t.length-1,r?e=>n[e*2]:e=>Yt(t[e]).start,e)])},this.getMaxScrollOffset=()=>{if(!this.scrollElement)return 0;if(`scrollHeight`in this.scrollElement)return this.options.horizontal?this.scrollElement.scrollWidth-this.scrollElement.clientWidth:this.scrollElement.scrollHeight-this.scrollElement.clientHeight;{let e=this.scrollElement.document.documentElement;return this.options.horizontal?e.scrollWidth-this.scrollElement.innerWidth:e.scrollHeight-this.scrollElement.innerHeight}},this.getVirtualDistanceFromEnd=()=>Math.max(this.getTotalSize()-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)return[this.getMaxScrollOffset(),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._iosDeferredAdjustment=0;let r=this.getOffsetForAlignment(e,t),i=this.now();this.scrollState={index:null,align:t,behavior:n,startedAt:i,lastTargetOffset:r,stableFrames:0},this._scrollToOffset(r,{adjustments:void 0,behavior:n}),this.scheduleScrollReconcile()},this.scrollToIndex=(e,{align:t=`auto`,behavior:n=`auto`}={})=>{this._iosDeferredAdjustment=0,e=Math.max(0,Math.min(e,this.options.count-1));let r=this.getOffsetForIndex(e,t);if(!r)return;let[i,a]=r,o=this.now();this.scrollState={index:e,align:a,behavior:n,startedAt:o,lastTargetOffset:i,stableFrames:0},this._scrollToOffset(i,{adjustments:void 0,behavior:n}),this.scheduleScrollReconcile()},this.scrollBy=(e,{behavior:t=`auto`}={})=>{let n=this.getScrollOffset()+e,r=this.now();this.scrollState={index:null,align:`start`,behavior:t,startedAt:r,lastTargetOffset:n,stableFrames:0},this._scrollToOffset(n,{adjustments:void 0,behavior:t}),this.scheduleScrollReconcile()},this.scrollToEnd=({behavior:e=`auto`}={})=>{this.options.count>0?this.scrollToIndex(this.options.count-1,{align:`end`,behavior:e}):this.scrollToOffset(Math.max(this.getTotalSize()-this.getSize(),0),{behavior:e})},this.getTotalSize=()=>{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})=>{this._intendedScrollOffset=e+(t??0),this.options.scrollToFn(e,{behavior:n,adjustments:t},this)},this.measure=()=>{this.pendingMin=null,this.itemSizeCache.clear(),this.laneAssignments.clear(),this.itemSizeCacheVersion++,this.notify(!1)},this.setOptions(e)}applyScrollAdjustment(e,t){if(e===0)return!1;if($t()&&(this.isScrolling||this._iosTouching||this._iosJustTouchEnded))return this._iosDeferredAdjustment+=e,!1;{let n=this.getScrollOffset()+this.scrollAdjustments+e,r=this.scrollElement,i=r!==null&&(`scrollHeight`in r||`document`in r)?this.getMaxScrollOffset():null;return this._clampedAdjustment=i!==null&&n>i+.5?{target:n,maxAtWrite:i}:null,this._scrollToOffset(this.getScrollOffset(),{adjustments:this.scrollAdjustments+=e,behavior:t}),this.scrollOffset!==null&&(this.scrollOffset+=this.scrollAdjustments,this.scrollOffset<0&&(this.scrollOffset=0),this.scrollAdjustments=0),!0}}scheduleScrollReconcile(){this.targetWindow?this.rafId??=this.targetWindow.requestAnimationFrame(()=>{this.rafId=null,this.reconcileScroll()}):this.scrollState=null}reconcileScroll(){if(!this.scrollState||!this.scrollElement)return;if(this.now()-this.scrollState.startedAt>5e3){this.scrollState=null;return}let e=this.scrollState.index==null?void 0:this.getOffsetForIndex(this.scrollState.index,this.scrollState.align),t=e?e[0]:this.scrollState.lastTargetOffset,n=t!==this.scrollState.lastTargetOffset;if(!n&&Xt(t,this.getScrollOffset())){if(this.scrollState.stableFrames++,this.scrollState.stableFrames>=1){this.getScrollOffset()!==t&&this._scrollToOffset(t,{adjustments:void 0,behavior:`auto`}),this.scrollState=null;return}}else if(this.scrollState.stableFrames=0,n){let e=this.getSize()||600,n=Math.abs(t-this.getScrollOffset()),r=this.scrollState.behavior===`smooth`&&n>e;this.scrollState.lastTargetOffset=t,r||(this.scrollState.behavior=`auto`),this._scrollToOffset(t,{adjustments:void 0,behavior:r?`smooth`:`auto`})}this.scheduleScrollReconcile()}};let pn=(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 mn(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 hn(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=mn(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=pn(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}}let gn=typeof document<`u`?d.useLayoutEffect:d.useEffect;function _n({useFlushSync:e=!0,directDomUpdates:t=!1,directDomUpdatesMode:n=`transform`,...r}){let i=d.useReducer(e=>e+1,0)[1],a=d.useRef({enabled:t,mode:n,container:null,lastSize:null,lastPositions:/* @__PURE__ */ new WeakMap,prevRange:null});a.current.enabled=t,a.current.mode=n;let o=d.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=>{let t=a.current;if(!t.enabled||!t.container)return;s(e);let n=!!e.options.horizontal,r=t.mode===`transform`,i=n?`left`:`top`,o=e.options.scrollMargin,c=e.getVirtualItems();for(let a of c){let s=a.start-o,c=e.elementsCache.get(a.key);c&&t.lastPositions.get(c)!==s&&(t.lastPositions.set(c,s),r?c.style.transform=n?`translate3d(${s}px, 0, 0)`:`translate3d(0, ${s}px, 0)`:c.style[i]=`${s}px`)}},l={...r,onChange:(t,n)=>{var s;let l=a.current,u=!0;if(l.enabled){c(t);let e=t.range,n=l.prevRange;u=!n||n.isScrolling!==t.isScrolling||n.startIndex!==e?.startIndex||n.endIndex!==e?.endIndex,u&&(l.prevRange=e?{startIndex:e.startIndex,endIndex:e.endIndex,isScrolling:t.isScrolling}:null)}u&&(e&&n&&!o.current?(0,h.flushSync)(i):i()),(s=r.onChange)==null||s.call(r,t,n)}},[u]=d.useState(()=>{let e=new fn(l),t=e.measureElement;return e.measureElement=e=>{o.current=!0;try{t(e)}finally{o.current=!1}},Object.assign(e,{containerRef:t=>{let n=a.current;if(n.container=t,n.lastSize=null,t&&n.enabled){let r=e.getTotalSize();n.lastSize=r;let i=e.options.horizontal?`width`:`height`;t.style[i]=`${r}px`}}})});return u.setOptions(l),gn(()=>u._didMount(),[]),gn(()=>(s(u),u._willUpdate())),gn(()=>{c(u)}),u}function vn(e){return _n({observeElementRect:rn,observeElementOffset:cn,scrollToFn:un,...e})}let yn=`@deepseek-ai/dsh-client-ui-chat/TurnNavigator.module.css`;if(typeof document<`u`&&document.querySelector(`style[data-plugin-css=`+JSON.stringify(yn)+`]`)===null){let e=document.createElement(`style`);e.dataset.plugin=`@deepseek-ai/dsh-client-ui-chat`,e.dataset.pluginCss=yn,e.textContent=`.FJ_OyG_slot{z-index:7;height:0;padding-inline:calc(var(--dsh-composer-side-clearance) + 16px);pointer-events:none;position:absolute;top:0;left:0;right:0;container-type:inline-size}[data-conversation-scroll] .FJ_OyG_slot{position:sticky}.FJ_OyG_frame{--turn-rail-band:calc(var(--dsh-conversation-viewport-height,100dvh) - var(--dsh-composer-height,152px));--turn-preview-height:104px;top:calc(var(--turn-rail-band) / 2);width:36px;max-height:min(max(0px, calc(var(--turn-rail-band) - 64px)), 70vh, 640px);contain:layout;cursor:pointer;pointer-events:auto;position:absolute;left:12px;transform:translateY(-50%)}.FJ_OyG_frame[hidden]{display:none}.FJ_OyG_scroller{max-height:inherit;overscroll-behavior:contain;scrollbar-width:none;position:relative;overflow-y:auto}.FJ_OyG_scroller::-webkit-scrollbar{display:none}.FJ_OyG_fadeTop{mask-image:linear-gradient(#0000 0,#000 40px 100%)}.FJ_OyG_fadeBottom{mask-image:linear-gradient(#000 0 calc(100% - 40px),#0000 100%)}.FJ_OyG_fadeTop.FJ_OyG_fadeBottom{mask-image:linear-gradient(#0000 0,#000 40px calc(100% - 40px),#0000 100%)}.FJ_OyG_marks{position:relative}.FJ_OyG_mark{cursor:pointer;background:0 0;border:0;border-radius:8px;height:10px;padding:0;position:absolute;top:0;left:0;right:0}.FJ_OyG_mark:before{background:var(--dsw-alias-label-tertiary);opacity:.4;content:"";transform-origin:0;width:26px;height:2px;transition:transform .16s cubic-bezier(.2,.8,.2,1),background-color .16s,opacity .16s;position:absolute;top:50%;left:0;transform:translateY(-50%)scaleX(.230769)}.FJ_OyG_markUnloaded:before{opacity:.25}.FJ_OyG_mark[data-neighbor-distance="3"]:before{transform:translateY(-50%)scaleX(.384615)}.FJ_OyG_mark[data-neighbor-distance="2"]:before{transform:translateY(-50%)scaleX(.538462)}.FJ_OyG_mark[data-neighbor-distance="1"]:before{transform:translateY(-50%)scaleX(.769231)}.FJ_OyG_markBusy:before{animation:1s ease-in-out infinite FJ_OyG_dsh-turn-mark-busy}.FJ_OyG_markActive:before{background:var(--dsw-alias-label-primary);opacity:.6}.FJ_OyG_frame[data-previewing] .FJ_OyG_markActive:not(.FJ_OyG_markPreview):not(:focus-visible):before{background:var(--dsw-alias-label-tertiary);opacity:.4}.FJ_OyG_markPreview:before{background:var(--dsw-alias-label-primary);opacity:1;transform:translateY(-50%)scaleX(1)}.FJ_OyG_frame[data-scrubbing] .FJ_OyG_mark:before{transition:none}.FJ_OyG_mark:focus-visible:before{background:var(--dsw-focus-ring-color,var(--dsw-alias-state-business-primary));opacity:1;transform:translateY(-50%)scaleX(1)}.FJ_OyG_mark:focus-visible{outline:none}.FJ_OyG_mark:focus-visible:after{border-radius:inherit;outline:1px solid var(--dsw-focus-ring-color,var(--dsw-alias-state-business-primary));outline-offset:-1px;content:"";width:28px;position:absolute;inset:0 auto 0 0}.FJ_OyG_preview{top:clamp(0px, calc(var(--turn-preview-center) - var(--turn-preview-height) / 2), calc(100% - var(--turn-preview-height)));box-sizing:border-box;width:min(320px,100cqw - 48px);max-height:var(--turn-preview-height);border:.5px solid var(--dsw-alias-border-l4);color:var(--dsw-alias-label-primary);background:var(--dsw-alias-bg-layer-1);box-shadow:var(--dsw-elevation-panel);pointer-events:none;border-radius:12px;padding:8px;transition:top .14s cubic-bezier(.2,.8,.2,1);animation:.12s ease-out FJ_OyG_dsh-turn-preview-enter;position:absolute;left:100%;overflow:hidden}.FJ_OyG_previewPrompt,.FJ_OyG_previewResponse{-webkit-box-orient:vertical;display:-webkit-box;overflow:hidden}.FJ_OyG_previewPrompt{-webkit-line-clamp:1;font-size:14px;font-weight:500;line-height:20px}.FJ_OyG_previewResponse{color:var(--dsw-alias-label-caption);-webkit-line-clamp:3;margin-top:4px;font-size:14px;line-height:20px}@keyframes FJ_OyG_dsh-turn-preview-enter{0%{opacity:0;transform:translate(-4px)}to{opacity:1;transform:translate(0)}}@keyframes FJ_OyG_dsh-turn-mark-busy{0%,to{opacity:1}50%{opacity:.35}}@media (prefers-reduced-motion:reduce){.FJ_OyG_frame,.FJ_OyG_scroller,.FJ_OyG_mark:before,.FJ_OyG_markBusy:before,.FJ_OyG_preview{scroll-behavior:auto;transition:none;animation:none}}`,document.head.appendChild(e)}var G={"dsh-turn-mark-busy":`FJ_OyG_dsh-turn-mark-busy`,"dsh-turn-preview-enter":`FJ_OyG_dsh-turn-preview-enter`,fadeBottom:`FJ_OyG_fadeBottom`,fadeTop:`FJ_OyG_fadeTop`,frame:`FJ_OyG_frame`,mark:`FJ_OyG_mark`,markActive:`FJ_OyG_markActive`,markBusy:`FJ_OyG_markBusy`,markPreview:`FJ_OyG_markPreview`,markUnloaded:`FJ_OyG_markUnloaded`,marks:`FJ_OyG_marks`,preview:`FJ_OyG_preview`,previewPrompt:`FJ_OyG_previewPrompt`,previewResponse:`FJ_OyG_previewResponse`,scroller:`FJ_OyG_scroller`,slot:`FJ_OyG_slot`};function bn(){return typeof matchMedia==`function`&&matchMedia(`(prefers-reduced-motion: reduce)`).matches?`auto`:`smooth`}let xn=(0,d.memo)(function({item:e,index:t,active:n,busy:r,previewId:i,neighborDistance:a,registerElement:o,onNavigate:s,onPreview:c,onFocusChange:l,t:u}){let d=[G.mark];return e.anchor.kind===`unloaded`&&d.push(G.markUnloaded),n&&d.push(G.markActive),a===0&&d.push(G.markPreview),r&&d.push(G.markBusy),/* @__PURE__ */ (0,f.jsx)(`button`,{ref:o,"data-index":t,"data-neighbor-distance":a,type:`button`,className:d.join(` `),"aria-label":u(e.anchor.kind===`loaded`?`chat.turnNavigation.jump`:`chat.turnNavigation.jumpLoad`,{turn:t+1}),"aria-current":n?`true`:void 0,"aria-busy":r?`true`:void 0,"aria-describedby":i,onPointerMove:t=>{t.buttons===0&&c(e.turn)},onClick:()=>{s(e)},onFocus:()=>{l(e.turn)},onBlur:()=>{l(null)}})});function Sn({items:e,activeTurn:t,busyTurn:n,onNavigate:r,t:i},a){let[o,s]=(0,d.useState)(null),[c,l]=(0,d.useState)(null),[u,p]=(0,d.useState)(!1),[m,h]=(0,d.useState)(!1),[g,_]=(0,d.useState)(!1),v=(0,d.useRef)(null),y=(0,d.useRef)(null),b=(0,d.useRef)(!1),x=(0,d.useRef)(void 0),S=(0,d.useRef)(null),C=(0,d.useRef)({placed:!1,index:0,follow:null,publishOffset:null}),w=(0,d.useRef)(!1),T=(0,d.useId)(),E=e.length>=2;(0,d.useLayoutEffect)(()=>{let e=v.current,t=e?.parentElement?.querySelector(`[data-chat-flow]`),n=e?.closest(`[data-conversation-scroll]`)??e?.parentElement;if(!t||!n)return;let r=()=>{let e=n.getBoundingClientRect(),r=n.offsetWidth>0?e.width/n.offsetWidth:1;h((t.getBoundingClientRect().left-e.left)/(r||1)>=48)},i=new ResizeObserver(r);return i.observe(t),i.observe(n),r(),()=>i.disconnect()},[E]),(0,d.useEffect)(()=>{if(o===null){p(!1);return}if(u)return;let e=setTimeout(()=>p(!0),150);return()=>clearTimeout(e)},[o,u]),(0,d.useEffect)(()=>()=>{clearTimeout(x.current);let e=y.current;y.current=null,e?.button.hasPointerCapture(e.pointerId)&&e.button.releasePointerCapture(e.pointerId)},[]);let D=(0,d.useMemo)(()=>{let t=/* @__PURE__ */ new Map;return e.forEach((e,n)=>{t.set(e.turn,n)}),t},[e]),O=t===null?void 0:D.get(t);(0,d.useLayoutEffect)(()=>{C.current.index=O??0},[O]);let k=c===null?void 0:D.get(c),A=o===null?void 0:D.get(o),j=(0,d.useCallback)(e=>{l(e),s(e),p(e!==null)},[]),M=vn({count:e.length,enabled:E,directDomUpdates:!0,directDomUpdatesMode:`transform`,useScrollendEvent:!0,getScrollElement:(0,d.useCallback)(()=>S.current,[]),getItemKey:(0,d.useCallback)(t=>e[t]?.turn??t,[e]),estimateSize:()=>10,measureElement:()=>10,initialRect:{width:0,height:0},initialOffset:0,scrollToFn:(e,t,n)=>{C.current.placed&&un(e,t,n)},observeElementOffset:(e,t)=>{C.current.publishOffset=t;let n=cn(e,t);return()=>{n?.(),C.current.placed=!1,C.current.follow=null,C.current.publishOffset=null}},observeElementRect:(e,t)=>{let n=e.scrollElement,r=e.targetWindow?.ResizeObserver;if(n===null||r===void 0)return;let i=new r(([r])=>{if(r===void 0)return;let i=r.borderBoxSize[0],a={width:Math.round(i?.inlineSize??r.contentRect.width),height:Math.round(i?.blockSize??r.contentRect.height)},o=C.current;if(!o.placed&&a.height>0){let t=Math.max(0,e.getTotalSize()-a.height),r=o.index*10+6,i=Math.max(0,Math.min(t,r-a.height/2));o.placed=!0,o.follow={index:o.index,count:e.options.count,height:a.height},n.scrollTop=i,o.publishOffset?.(i,!1)}t(a)});return i.observe(n,{box:`border-box`}),()=>{i.disconnect()}},paddingStart:1,paddingEnd:1,scrollPaddingStart:40,scrollPaddingEnd:40,overscan:3,rangeExtractor:(0,d.useCallback)(e=>{let t=nn(e);if(k!==void 0){let n=Math.min(e.count-1,k+1);for(let e=Math.max(0,k-1);e<=n;e++)t.includes(e)||t.push(e);t.sort((e,t)=>e-t)}return t},[k])}),ee=M.scrollOffset??0,N=M.scrollRect?.height??0,te=M.getVirtualItems(),P=(0,d.useCallback)((e,t,n=bn())=>{let r=M.measurementsCache[e],i=M.scrollRect?.height??0;if(r===void 0||i<=0)return;let a=M.scrollOffset??0,o=r.start+r.size/2;if(t===`if-needed`){let{scrollPaddingStart:e,scrollPaddingEnd:t}=M.options;if(o>=a+e&&o<=a+i-t)return}let s=o-i/2,c=Math.max(0,M.getTotalSize()-i),l=Math.max(0,Math.min(c,s))-a;l!==0&&M.scrollBy(l,{behavior:n})},[M]);(0,d.useImperativeHandle)(a,()=>({activateTurn(t){let n=D.get(t),i=n===void 0?void 0:e[n];i!==void 0&&r(i)},scrollToTurn(e){let t=D.get(e);t!==void 0&&P(t,`always`)}}),[e,D,r,P]),(0,d.useEffect)(()=>{if(N<=0){C.current.follow=null;return}if(O===void 0||w.current)return;let t=C.current.follow;if(t?.index===O&&t.count===e.length&&t.height===N)return;C.current.follow={index:O,count:e.length,height:N};let n=t?.count===e.length&&t.height===N?bn():`instant`;P(O,`if-needed`,n)},[O,e.length,N,P]);let ne=(0,d.useCallback)(e=>{b.current?b.current=!1:r(e)},[r]),F=t=>{if(t.button!==0||!(t.target instanceof Element))return;let n=t.target.closest(`button[data-index]`);if(!n||!S.current?.contains(n))return;let r=e[Number(n.dataset.index)];r&&(clearTimeout(x.current),b.current=!1,y.current={pointerId:t.pointerId,button:n,turn:r.turn,moved:!1},n.setPointerCapture(t.pointerId),_(!0),s(r.turn),p(!0))},re=t=>{let n=y.current,i=S.current;if(!n||!i||t.pointerId!==n.pointerId||!(t.buttons&1))return;let a=i.getBoundingClientRect(),o=Math.max(a.top,Math.min(t.clientY,a.bottom-1)),c=e[Math.max(0,Math.min(e.length-1,Math.round((o-a.top+i.scrollTop-6)/10)))];c&&c.turn!==n.turn&&(n.turn=c.turn,n.moved=!0,s(c.turn),c.anchor.kind===`loaded`&&r(c))},I=e=>{let t=y.current;t&&e.pointerId===t.pointerId&&(y.current=null,_(!1),b.current=t.moved,t.button.hasPointerCapture(e.pointerId)&&t.button.releasePointerCapture(e.pointerId),x.current=setTimeout(()=>{b.current=!1},0),w.current||s(null))};if(!E)return null;let ie=!u||A===void 0?void 0:e[A],ae=te.find(e=>e.index===A),oe=[G.scroller];return ee>1&&oe.push(G.fadeTop),ee<M.getTotalSize()-N-1&&oe.push(G.fadeBottom),/* @__PURE__ */ (0,f.jsx)(`div`,{ref:v,className:G.slot,children:/* @__PURE__ */ (0,f.jsxs)(`nav`,{className:G.frame,hidden:!m,"data-turn-navigation":``,"data-previewing":A!==void 0||void 0,"data-scrubbing":g||void 0,onPointerDownCapture:F,onPointerMove:re,onPointerUpCapture:I,onPointerCancelCapture:I,onLostPointerCapture:I,"aria-label":i(`chat.turnNavigation.label`),onPointerEnter:()=>{w.current=!0},onPointerLeave:()=>{w.current=!1,y.current||s(null)},children:[/* @__PURE__ */ (0,f.jsx)(`div`,{ref:S,className:oe.join(` `),children:/* @__PURE__ */ (0,f.jsx)(`div`,{ref:M.containerRef,className:G.marks,children:te.map(({index:r,key:a})=>{let c=e[r];return c===void 0?null:/* @__PURE__ */ (0,f.jsx)(xn,{item:c,index:r,active:c.turn===t,busy:c.turn===n,previewId:u&&c.turn===o?T:void 0,neighborDistance:A!==void 0&&Math.abs(r-A)<=3?Math.abs(r-A):void 0,registerElement:M.measureElement,onNavigate:ne,onPreview:s,onFocusChange:j,t:i},a)})})}),ie!==void 0&&ae!==void 0&&/* @__PURE__ */ (0,f.jsxs)(`div`,{id:T,role:`tooltip`,className:G.preview,style:{"--turn-preview-center":`${String(ae.start+ae.size/2-ee)}px`},children:[/* @__PURE__ */ (0,f.jsx)(`div`,{className:G.previewPrompt,children:ie.prompt||i(`chat.turnNavigation.turn`,{turn:(A??0)+1})}),ie.response!==``&&/* @__PURE__ */ (0,f.jsx)(`div`,{className:G.previewResponse,children:ie.response})]})]})})}let Cn=(0,d.memo)((0,d.forwardRef)(Sn));function wn(){return/* @__PURE__ */ (0,f.jsx)(`span`,{className:U.runningIcon,"aria-hidden":`true`,children:/* @__PURE__ */ (0,f.jsx)(`span`,{className:U.runningIconMotion,children:/* @__PURE__ */ (0,f.jsxs)(`svg`,{width:`100%`,height:`100%`,viewBox:`2 2 20 20`,fill:`none`,stroke:`currentColor`,strokeWidth:1.2,strokeLinecap:`round`,strokeLinejoin:`round`,children:[/* @__PURE__ */ (0,f.jsx)(`path`,{d:`M16.1 5.3C11.8 2.9 6.6 5 5.1 9.4c-1.8 5.4 1.7 10.2 6.9 10.3 4.8.2 8-3.8 7.2-8.3-.4 3.2-2 5.1-4.2 5.8`}),/* @__PURE__ */ (0,f.jsx)(`rect`,{x:`9.5`,y:`9.1`,width:`4.6`,height:`4.6`,rx:`1`,transform:`rotate(-10 11.8 11.4)`})]})})})}let Tn=`@deepseek-ai/dsh-client-ui-chat/accessibility.module.css`;if(typeof document<`u`&&document.querySelector(`style[data-plugin-css=`+JSON.stringify(Tn)+`]`)===null){let e=document.createElement(`style`);e.dataset.plugin=`@deepseek-ai/dsh-client-ui-chat`,e.dataset.pluginCss=Tn,e.textContent=`.lM_Y6G_visuallyHidden{clip:rect(0 0 0 0);white-space:nowrap;width:1px;height:1px;position:absolute;overflow:hidden}`,document.head.appendChild(e)}var En={visuallyHidden:`lM_Y6G_visuallyHidden`};let Dn=(0,d.memo)(function({startTime:e,compacting:t,stale:n,t:r}){let[i,a]=(0,d.useState)(Date.now);(0,d.useEffect)(()=>{if(e===void 0||t||n)return;a(Date.now());let r=setInterval(()=>{a(Date.now())},1e3);return()=>{clearInterval(r)}},[e,t,n]);let o=n?r(`chat.statusUnconfirmed`):t?r(`message.compaction.running`):e===void 0?r(`chat.deepDiving`):r(`chat.deepDivingFor`,{duration:Le(Math.max(1e3,i-e),r).map(e=>e.text).join(``)});return/* @__PURE__ */ (0,f.jsxs)(`div`,{className:U.running,"data-chat-running":!0,children:[/* @__PURE__ */ (0,f.jsx)(`span`,{className:En.visuallyHidden,role:`status`,"aria-live":`polite`,"aria-atomic":`true`,children:r(n?`chat.statusUnconfirmed`:t?`message.compaction.running`:`chat.deepDiving`)}),/* @__PURE__ */ (0,f.jsx)(`span`,{className:U.runningDivider,"aria-hidden":`true`}),/* @__PURE__ */ (0,f.jsxs)(`span`,{className:U.runningContent,children:[n?null:/* @__PURE__ */ (0,f.jsx)(wn,{}),/* @__PURE__ */ (0,f.jsx)(p.TextShimmer,{active:!n,className:U.runningText,children:o})]})]})});function On(e){return e}function kn(e){return e}function An(e){if(!Number.isSafeInteger(e)||e<0||Object.is(e,-0))throw TypeError(`SessionSeq must be a non-negative safe integer, got ${String(e)}`);return kn(e)}let jn=[];function Mn(e){if(typeof e!=`object`||!e)return;let t=e;if(!(typeof t.turn!=`number`||!Number.isSafeInteger(t.turn)||t.turn<0)&&!(typeof t.seq!=`number`||!Number.isSafeInteger(t.seq)||t.seq<0||Object.is(t.seq,-0)))return{turn:t.turn,seq:An(t.seq),prompt:typeof t.prompt==`string`?t.prompt:``,response:typeof t.response==`string`?t.response:``}}function Nn(e){return Array.isArray(e)?e:jn}function Pn(e,t){let n=/* @__PURE__ */ new Map;for(let e of Nn(t)){let t=Mn(e);t!==void 0&&n.set(t.turn,{turn:t.turn,prompt:t.prompt,response:t.response,anchor:{kind:`unloaded`,seq:t.seq}})}for(let t of e){let e=n.get(t.turn);n.set(t.turn,{turn:t.turn,prompt:t.prompt===``?e?.prompt??``:t.prompt,response:t.response===``?e?.response??``:t.response,anchor:{kind:`loaded`,key:t.anchorKey}})}return n.size===0?jn:[...n.values()].sort((e,t)=>e.turn-t.turn)}var Fn=class{viewport;reading;input;onBusyTurn;jump=null;settleFrame=null;requestedHead;constructor(e,t,n,r){this.viewport=e,this.reading=t,this.input=n,this.onBusyTurn=r}setInput(e){this.input=e}reset(){this.requestedHead=void 0,this.cancel()}dispose(){this.clearTask()}cancel(){this.clearTask(),this.onBusyTurn(null)}clearTask(){this.cancelFrame(),this.jump=null,this.viewport.stopPreserving()}navigateToTurn=e=>{if(e.anchor.kind===`loaded`){this.cancel();let t=this.viewport.scrollToTurn(e.turn);if(t===null)return;this.reading.acceptNavigation(t),this.input.loadingOlder&&this.viewport.beginPreserving(t.position);return}if(!this.input.historyReady)return;this.cancel(),this.viewport.beginPreserving(),this.reading.pauseFollowing();let t={turn:e.turn,seq:e.anchor.seq,phase:`loading`,landing:`pending`,repageHead:null};this.jump=t,this.onBusyTurn(t.turn),this.request(t)};autoLoadEarlier=()=>{if(this.jump!==null||this.input.olderFailed||this.requestedHead===this.input.firstSeq)return;let e=this.viewport.readScroll();e===null||e.metrics.top>240||this.loadEarlier()};loadEarlier=()=>{this.input.historyReady&&this.input.hasMore&&!this.input.loadingOlder&&(this.requestedHead=this.input.firstSeq,this.cancel(),this.viewport.beginPaging(),this.reading.pauseFollowing(),this.input.loadOlder())};readerSampled(e){e.movedByReader&&this.jump?.landing===`landed`&&(this.jump.landing=`interrupted`),(e.followingTail||e.movedByReader)&&this.viewport.stopPreserving()}contentCommitted(){if(!this.viewport.preserving||this.reading.pending)return!1;if(this.landJump(!1))return!0;let e=this.viewport.preserve();return e!==null&&(this.reading.preservePosition(e),!0)}readerSettled(){this.input.loadingOlder&&this.jump===null&&!this.viewport.preserving&&!this.reading.followingTail&&this.viewport.beginPreserving()}reconcile(){let e=this.jump;if(!this.input.historyReady||e===null||this.reading.pending)return;if(e.phase===`loading`){e.landing===`pending`&&this.landJump(!1);return}if(this.input.loadingOlder||this.landJump(!0))return;if((this.input.firstSeq===null||this.input.firstSeq>e.seq)&&this.input.hasMore&&e.repageHead!==this.input.firstSeq){e.repageHead=this.input.firstSeq,this.viewport.beginPreserving(),this.request(e);return}let t=this.viewport.scrollToTurnAtOrAfter(e.turn);this.cancel(),t!==null&&this.reading.acceptNavigation(t)}landJump(e){let t=this.jump;if(t===null)return!1;if(t.landing===`interrupted`)return e?(this.cancel(),!0):!1;let n=this.viewport.scrollToTurn(t.turn);return n!==null&&(this.reading.acceptNavigation(n),e?this.cancel():(this.viewport.beginPreserving(n.position),t.landing=`landed`),!0)}request(e){e.phase=`loading`;let t=()=>{this.jump===e&&(e.phase=`settled`,this.cancelFrame(),typeof requestAnimationFrame==`function`?this.settleFrame=requestAnimationFrame(()=>{this.settleFrame=null,this.jump===e&&this.reconcile()}):this.reconcile())};this.input.loadThrough(e.seq).then(t,t)}cancelFrame(){this.settleFrame!==null&&typeof cancelAnimationFrame==`function`&&cancelAnimationFrame(this.settleFrame),this.settleFrame=null}};function In(e,t,n){let[r,i]=(0,d.useState)(null),[a]=(0,d.useState)(()=>new Fn(e,t,n,i));return(0,d.useLayoutEffect)(()=>{a.setInput(n)},[a,n]),(0,d.useLayoutEffect)(()=>()=>{a.dispose()},[a]),{navigation:a,busyTurn:r}}var Ln=class{viewport;store;state;onChange;follow;sampleTimer=null;probeFrame=null;sampled=null;constructor(e,t,n,r,i){this.viewport=e,this.store=t,this.state=n,this.onChange=r,this.follow=i}get pending(){return this.sampleTimer!==null}get followingTail(){return this.state.followingTail}setStore(e){this.store=e}connect(e){return this.sampled=e,()=>{this.sampled===e&&(this.sampled=null)}}dispose(){this.cancelPending(),this.sampled=null}pauseFollowing(){this.cancelPending(),this.publish({...this.state,followingTail:!1})}followTail(){let e=this.viewport.scrollToBottom(this.follow);e!==null&&(this.cancelPending(),this.commit(e,!0,this.viewport.latestTurn))}restore(){let e=this.store.read();if(e===null){this.followTail();return}let t=this.viewport.restore(e);if(t===null)return;this.cancelPending();let n=this.follow.nearBottom(t.metrics);if(this.commit(t,n,n?this.viewport.latestTurn:this.state.activeTurn,n),!this.state.followingTail&&t.position===null){let e=this.viewport.capturePosition();e!==null&&this.store.save(e)}this.refreshActiveTurn()}acceptNavigation(e){this.cancelPending();let t=this.follow.nearBottom(e.metrics);this.commit(e,t,e.turn??(t?this.viewport.latestTurn:this.state.activeTurn))}preservePosition(e){this.cancelPending(),this.commit(e,this.state.followingTail,this.state.activeTurn)}onScroll=e=>{!e.movedByReader&&this.state.followingTail||e.movedByReader&&e.metrics.top>=e.metrics.floor?(this.followTail(),this.sampled?.({position:null,movedByReader:e.movedByReader,followingTail:!0})):this.sampleTimer??=window.setTimeout(this.flushSample,500)};onScrollEnd=()=>{this.flushSample()};onResize(){this.pending||(this.state.followingTail?this.followTail():this.refreshActiveTurn())}refreshActiveTurn(){this.pending||(this.state.followingTail?this.publish({...this.state,initialized:!0,activeTurn:this.viewport.latestTurn}):this.probeFrame===null&&(typeof requestAnimationFrame==`function`?this.probeFrame=requestAnimationFrame(this.probe):this.probe()))}commit(e,t,n,r=!0){t?this.store.save(null):e.position!==null&&this.store.save(e.position),this.publish({initialized:r,followingTail:t,activeTurn:n})}publish(e){this.follow.setFollowing(e.followingTail),(e.initialized!==this.state.initialized||e.followingTail!==this.state.followingTail||e.activeTurn!==this.state.activeTurn)&&(this.state=e,this.onChange(e))}cancelPending(){this.sampleTimer!==null&&window.clearTimeout(this.sampleTimer),this.probeFrame!==null&&typeof cancelAnimationFrame==`function`&&cancelAnimationFrame(this.probeFrame),this.sampleTimer=null,this.probeFrame=null}probe=()=>{if(this.probeFrame=null,this.pending)return;let e=this.viewport.readScroll();if(e===null)return;let t=this.follow.nearBottom(e.metrics)?this.viewport.latestTurn:this.viewport.readVisibleTurn(e.metrics);this.publish({...this.state,initialized:!0,activeTurn:t})};flushSample=()=>{if(!this.pending)return;this.cancelPending();let e=this.viewport.readScroll();if(e===null)return;let t=this.follow.sample(e.metrics,e.movedByReader),n=null;if(!e.movedByReader&&t)this.followTail();else{n=t?null:this.viewport.capturePosition(),this.viewport.acknowledge(e.metrics),(t||n!==null)&&this.store.save(n);let r=this.follow.nearBottom(e.metrics)?this.viewport.latestTurn:this.viewport.readVisibleTurn(e.metrics);this.publish({initialized:!0,followingTail:t,activeTurn:r})}this.sampled?.({position:n,movedByReader:e.movedByReader,followingTail:t})}};function Rn(e,t,n){let[r,i]=(0,d.useState)(()=>({initialized:!1,followingTail:t.read()===null,activeTurn:n})),a=Ft(r.followingTail,25),[o]=(0,d.useState)(()=>new Ln(e,t,r,i,a));return(0,d.useLayoutEffect)(()=>{o.setStore(t)},[o,t]),(0,d.useLayoutEffect)(()=>()=>{o.dispose()},[o]),{reading:o,state:r}}let zn=[`wheel`,`touchstart`,`touchmove`,`touchend`,`touchcancel`,`pointerdown`,`keydown`,`beforematch`],Bn=/* @__PURE__ */ new Set([`ArrowUp`,`ArrowDown`,`PageUp`,`PageDown`,`Home`,`End`,` `]);var Vn=class{elements=null;observer=null;events=null;turns=[];observation={top:0,landing:null};paging=null;touchY=null;attach(e,t){this.detach();let n=e.closest(`[data-conversation-scroll]`)??e,r=n.querySelector(`[data-composer-seat]`),i={list:e,column:t,scroller:n,composer:r};this.elements=i,n.addEventListener(`scroll`,this.onScroll,{passive:!0}),n.addEventListener(`scrollend`,this.onScrollEnd,{passive:!0,capture:!0});for(let e of zn)n.addEventListener(e,this.onIntent,{passive:!0,capture:!0});typeof ResizeObserver<`u`&&(this.observer=new ResizeObserver(()=>{this.elements===i&&(this.invalidate(),this.events?.resize())}),this.observer.observe(t),this.observer.observe(n),r!==null&&this.observer.observe(r))}detach(){this.stopPreserving(),this.elements?.scroller.removeEventListener(`scroll`,this.onScroll),this.elements?.scroller.removeEventListener(`scrollend`,this.onScrollEnd,!0);for(let e of zn)this.elements?.scroller.removeEventListener(e,this.onIntent,!0);this.observer?.disconnect(),this.observer=null,this.elements=null,this.events=null,this.turns=[],this.touchY=null,this.observation={top:0,landing:null}}connect(e){return this.events=e,()=>{this.events===e&&(this.events=null)}}updateTurns(e){this.turns=e}get latestTurn(){return this.turns.at(-1)?.turn??null}invalidate(){this.observation.landing=null}acknowledge(e){this.observation={top:e.top,landing:null}}readScroll(){let e=this.metrics();return e===null?null:{metrics:e,movedByReader:Math.abs(e.top-Math.min(this.observation.top,e.floor))>.5,towardStart:e.top<Math.min(this.observation.top,e.floor)-.5}}metrics(){let e=this.elements?.scroller;return e===void 0?null:Nt(e)}anchor(e,t=`position`){if(this.elements===null)return null;let n=null;for(let r of this.elements.list.querySelectorAll(`[data-chat-anchor-key]:not([hidden]):not([hidden] *)`)){if(r.dataset.chatAnchorKey===e||t===`node`&&r.dataset.chatNodeKey===e)return r;n===null&&r.dataset.chatNodeKey===e&&(n=r)}return n}capturePosition(){let e=this.elements;if(e===null)return null;let{list:t,scroller:n,composer:r}=e,i=n.getBoundingClientRect(),a=r?.getBoundingClientRect().top??i.bottom,o=null;if(typeof document.elementsFromPoint==`function`&&a>i.top){let e=t.getBoundingClientRect(),n=Math.max(i.left,e.left),r=Math.min(i.right,e.right);for(let e of document.elementsFromPoint(n+Math.max(0,r-n)/2,i.top+1)){let n=e instanceof HTMLElement?e.closest(`[data-chat-anchor-key]`):null;if(n!==null&&n.dataset.chatFlowKind!==`turn-process`&&t.contains(n)){o=n.dataset.chatGroupKey===void 0?n:n.querySelector(`[data-step-process-content] > [data-chat-anchor-key]:not(:empty):not([hidden]):not([hidden] *)`)??n;break}}}if(o===null){let e=t.querySelectorAll(`[data-chat-flow-key]:not([data-chat-group-key]):not([data-chat-flow-kind="turn-process"]):not(:empty):not([hidden]):not([hidden] *)`),n=0,r=e.length;for(;n<r;){let t=n+r>>>1;e.item(t).getBoundingClientRect().bottom>i.top?r=t:n=t+1}let s=e[n];o=s!==void 0&&s.getBoundingClientRect().top<a?s:e[0]??null}let s=o?.dataset.chatAnchorKey;return o===null||s===void 0?null:{anchorKey:s,anchorTop:o.getBoundingClientRect().top-i.top,scrollTop:n.scrollTop}}readVisibleTurn(e=this.metrics()){let t=this.observation.landing?.turn;if(t!=null&&e?.top===this.observation.top)return t;let n=this.elements,r=this.turns[0];if(n===null||e===null||r===void 0)return null;let i=n.scroller.getBoundingClientRect().top+Math.min(96,e.height*.2),a=n.column.children,o=0,s=a.length,c=r.turn;for(;o<s;){let e=o+s>>>1,t=a[e];if(t.getBoundingClientRect().top>i)s=e;else{let n=t.getAttribute(`data-chat-turn`),r=n===null?NaN:Number(n);Number.isSafeInteger(r)&&(c=r),o=e+1}}return c}scrollToTurn(e){let t=this.turns.find(t=>t.turn===e);if(t===void 0)return null;let n=this.anchor(t.anchorKey,`node`);return n===null?null:this.align(n,24,e)}scrollToTurnAtOrAfter(e){if(this.elements===null)return null;for(let t of this.elements.list.querySelectorAll(`[data-chat-turn]:not([hidden]):not([hidden] *)`)){let n=Number(t.dataset.chatTurn);if(Number.isSafeInteger(n)&&n>=e)return this.align(t,24,n)}return null}restore(e){let t=this.anchor(e.anchorKey);if(t!==null)return this.align(t,e.anchorTop,null);let n=this.metrics();return n===null?null:this.write(e.scrollTop,n,null)}beginPaging(){this.stopPreserving();let e=this.elements?.list.querySelector(`[data-chat-paging-anchor]:not(:empty):not([hidden]):not([hidden] *)`);e!=null&&this.retain(e)}beginPreserving(e=this.capturePosition()){if(this.stopPreserving(),e===null)return;let t=this.anchor(e.anchorKey);t!==null&&this.retain(t,e)}retain(e,t,n){let r=this.elements,i=e.dataset.chatAnchorKey;if(r===null||i===void 0)return null;let a=this.paging?.group;a!=null&&this.observer?.unobserve(a.content);let o=e.getBoundingClientRect().top,s=e.closest(`[data-step-process-body]`),c=s?.querySelector(`[data-step-process-content]`),l=s===null||c==null?null:{body:s,content:c,top:n??o-s.getBoundingClientRect().top};return this.paging={row:e,group:l,position:t??{anchorKey:i,anchorTop:o-r.scroller.getBoundingClientRect().top,scrollTop:r.scroller.scrollTop}},l!==null&&this.observer?.observe(l.content),this.paging}stopPreserving(){let e=this.paging?.group;e!=null&&this.observer?.unobserve(e.content),this.paging=null}get preserving(){return this.paging!==null}preserve(){let e=this.paging,t=this.elements;if(e===null||t===null)return null;if(!t.list.contains(e.row)){let t=this.anchor(e.position.anchorKey);if(t===null)return this.stopPreserving(),null;if(e=this.retain(t,e.position,e.group?.top),e===null)return null}let{row:n,group:r,position:i}=e;if(n.closest(`[hidden]`)!==null||n.matches(`:empty`))return this.stopPreserving(),null;if(r!==null&&r.body.contains(n)){let e=n.getBoundingClientRect().top-r.body.getBoundingClientRect().top,t=Nt(r.body),i=Math.max(0,Math.min(t.floor,t.top+e-r.top));if(t.top!==i){let e=Pt.forElement(r.body);e===void 0?r.body.scrollTop=i:(e.jump(r.body,t,i),e.setFollowing(!1))}}let a=this.metrics();if(a===null)return null;let o=n.getBoundingClientRect().top-t.scroller.getBoundingClientRect().top,s=a.top+o-i.anchorTop;return this.write(s,a,null,{key:i.anchorKey,top:o})}scrollToBottom(e){let t=this.metrics();if(t===null||this.elements===null)return null;let n={metrics:t.top>t.floor?t:e.toBottom(this.elements.scroller,t,`instant`),position:null,turn:this.latestTurn};return this.observation={top:n.metrics.top,landing:n},n}align(e,t,n){let r=this.metrics();if(r===null||this.elements===null)return null;let i=e.getBoundingClientRect().top-this.elements.scroller.getBoundingClientRect().top;return this.write(r.top+i-t,r,n,{key:e.dataset.chatAnchorKey,top:i})}write(e,t,n,r){if(this.elements===null)return null;let i=Math.max(0,Math.min(t.floor,e));i!==t.top&&(this.elements.scroller.scrollTop=i);let a=this.elements.scroller.scrollTop,o={metrics:{...t,top:a},turn:n,position:r?.key===void 0?null:{anchorKey:r.key,anchorTop:r.top-(a-t.top),scrollTop:a}};return this.observation={top:a,landing:o},o}onScroll=e=>{if(this.elements===null||e.target!==this.elements.scroller||this.observation.landing!==null&&this.elements.scroller.scrollTop===this.observation.top)return;this.invalidate();let t=this.readScroll();t!==null&&this.events?.scroll(t)};onScrollEnd=e=>{(e.target===this.elements?.scroller||e.target instanceof HTMLElement&&e.target.hasAttribute(`data-step-process-body`))&&this.events?.scrollEnd()};onIntent=e=>{if(e.type===`touchend`||e.type===`touchcancel`){this.touchY=null;return}if(e.target instanceof Element&&e.target.closest(`[data-composer-seat], [data-turn-navigation], input, textarea, [contenteditable="true"]`)||e.type===`keydown`&&(!(e instanceof KeyboardEvent)||!Bn.has(e.key)))return;let t=e instanceof WheelEvent?e.deltaY<0:e instanceof KeyboardEvent&&([`ArrowUp`,`PageUp`,`Home`].includes(e.key)||e.key===` `&&e.shiftKey);if(typeof TouchEvent<`u`&&e instanceof TouchEvent){let n=e.touches[0]?.clientY;if(t=e.type===`touchmove`&&n!==void 0&&this.touchY!==null&&n>this.touchY,this.touchY=n??null,e.type===`touchstart`)return}if(!(e instanceof PointerEvent&&e.pointerType===`touch`)){if(t&&e.target instanceof Element){for(let n=e.target;n&&n!==this.elements?.scroller;n=n.parentElement)if(n instanceof HTMLElement&&n.scrollTop>0&&n.scrollHeight>n.clientHeight&&/auto|scroll/.test(getComputedStyle(n).overflowY)){t=!1;break}}this.paging!==null&&!(t&&this.observation.top<=0&&(this.elements?.scroller.scrollTop??0)<=0)&&(this.stopPreserving(),this.events?.interact()),t&&this.events?.olderIntent()}}};function Hn(){let e=(0,d.useRef)(null),t=(0,d.useRef)(null),[n]=(0,d.useState)(()=>new Vn);return(0,d.useLayoutEffect)(()=>{if(e.current!==null&&t.current!==null)return n.attach(e.current,t.current),()=>{n.detach()}},[n]),{viewport:n,listRef:e,columnRef:t}}function Un(e){let{displayReady:t,historyReady:n,order:r,firstSeq:i,lastKey:a,lastIsUser:o,steeringId:s,submissionId:c,running:l,loadedTurns:u,chatScroll:f,hasMore:p,loadingOlder:m,olderFailed:h,loadOlder:g,loadThrough:_}=e,{viewport:v,listRef:y,columnRef:b}=Hn(),{reading:x,state:S}=Rn(v,f,u.at(-1)?.turn??null),C=(0,d.useMemo)(()=>({historyReady:n,firstSeq:i,loadingOlder:m,olderFailed:h,hasMore:p,loadOlder:g,loadThrough:_}),[n,i,m,h,p,g,_]),{navigation:w,busyTurn:T}=In(v,x,C),E=(0,d.useRef)({input:e,applied:null,opened:!1}),D=(0,d.useCallback)(()=>{let e=E.current.input,t=E.current.applied,n=e.lastIsUser&&e.lastKey!==t?.lastKey||e.steeringId!==null&&e.steeringId!==t?.steeringId&&e.steeringId!==t?.submissionId||e.submissionId!==null&&e.submissionId!==t?.submissionId&&e.submissionId!==t?.steeringId;(!x.pending||n)&&(E.current.applied=e,e.displayReady&&!E.current.opened?(E.current.opened=!0,w.reset(),x.restore()):n?(w.cancel(),x.followTail()):w.contentCommitted()?w.reconcile():(t===null||e.displayReady!==t.displayReady||e.firstSeq!==t.firstSeq||e.lastKey!==t.lastKey||e.order.length!==t.order.length||e.running!==t.running||e.steeringId!==t.steeringId||e.submissionId!==t.submissionId)&&x.followingTail?(w.cancel(),x.followTail()):w.reconcile())},[x,w]);(0,d.useLayoutEffect)(()=>{let e=null,t=()=>{e===null&&E.current.opened&&E.current.input.historyReady&&(e=requestAnimationFrame(()=>{e=null,E.current.opened&&E.current.input.historyReady&&w.autoLoadEarlier()}))},n=v.connect({scroll:e=>{x.onScroll(e),e.movedByReader&&e.towardStart&&t()},olderIntent:t,scrollEnd:()=>{x.onScrollEnd(),w.readerSettled()},interact:()=>{w.cancel()},resize:()=>{w.contentCommitted()||x.onResize(),w.reconcile()}}),r=x.connect(e=>{w.readerSampled(e),D()});return()=>{e!==null&&cancelAnimationFrame(e),n(),r(),E.current.opened=!1,E.current.applied=null}},[v,x,w,D]),(0,d.useLayoutEffect)(()=>{let e=E.current.input;E.current.input={displayReady:t,order:r,lastKey:a,lastIsUser:o,steeringId:s,submissionId:c,running:l,loadedTurns:u,chatScroll:f,...C},v.updateTurns(u);let n=e.order!==r||e.displayReady!==t;n&&v.invalidate(),D(),n&&x.refreshActiveTurn()},[v,x,D,C,t,r,a,o,s,c,l,u,f]);let O=(0,d.useCallback)(()=>{w.cancel(),x.followTail()},[w,x]);return{listRef:y,columnRef:b,...S,busyTurn:T,navigateToTurn:w.navigateToTurn,loadEarlier:w.loadEarlier,returnToBottom:O}}function Wn(e,t){let n=e instanceof Error?e.message:String(e);return n===``?t:n}function Gn(e,t){let n=/* @__PURE__ */ new Set,r;for(let i of e){let e=t.get(i);if(e===void 0||e.kind!==`user`&&e.kind!==`steering`&&e.kind!==`turn-trigger`||((e.location.kind===`turn`||e.location.kind===`step`)&&(r=e.location.turn.turn),e.kind===`turn-trigger`))continue;let a=e.data.source;a?.kind===`user`&&typeof a.rpcId==`string`&&n.add(a.rpcId)}return{rpcIds:n,lastInputTurn:r}}let Kn=(0,d.memo)(function({entries:e,useChatGroup:t,pendingInputs:n,lastInputTurn:r,...i}){let a=e.map(e=>{switch(e.kind){case`node`:return/* @__PURE__ */ (0,d.createElement)(St,{...i,key:kt(e),nodeKey:e.key,...e.groupPart===void 0?{}:{groupPart:e.groupPart}});case`group`:return/* @__PURE__ */ (0,d.createElement)(Gt,{...i,key:kt(e),groupKey:e.key,useChatGroup:t});default:return Ot(e)}}),o=n.map(e=>`requestId`in e?/* @__PURE__ */ (0,f.jsx)(tt,{submission:e,renderMessageImages:i.renderMessageImages,t:i.t},e.requestId):/* @__PURE__ */ (0,f.jsx)(et,{content:e.content,renderMessageImages:i.renderMessageImages,t:i.t},e.id)),s=e.at(-1),c=s?.kind===`node`?i.nodeStore.get(s.key):void 0;if(c?.kind===`turn-process`&&c.location.kind===`turn`&&c.location.turn.status===`open`&&c.location.turn.turn!==r){let e=n.findIndex(e=>`requestId`in e&&e.placement===`transcript`);e!==-1&&a.splice(a.length-1,0,...o.splice(e,1))}return[...a,...o]});function qn({connection:e,useSession:t,useChat:n,useChatNode:r,useChatNodeProcess:i,useChatGroup:a,useConversation:o,useSessions:s,useStore:c,actions:l,renderSlot:u,sessionId:m,openFile:h,openSkill:g,openExternalLink:_,resolveLink:v,loadOlder:y,loadThrough:b,loadImage:x,inspectCall:S,chatScroll:C,forkAt:w,loadTurnDiffs:T,editMessage:E,fileMentions:D,usePresentation:O,useProjection:k,t:A}){let j=n(e=>e.order),M=o(e=>e.views.grouped(`chat`)?.entries),N=(0,d.useMemo)(()=>M??j.map(e=>({kind:`node`,key:e})),[M,j]),P=n(e=>e.nodes),ne=n(e=>e.navigation.items()),F=ne.at(-1)?.anchorKey,re=r(F??``,e=>{let t=e?.location;return(t?.kind===`turn`||t?.kind===`step`)&&t.turn.status===`open`?t.turn.start?.time:void 0}),I=k(`turnOutline`),ie=(0,d.useMemo)(()=>Pn(ne,I),[ne,I]),ae=k(`inbox`),oe=s(e=>e.byId[m]?.cwd),se=(0,d.useMemo)(()=>({resolve:e=>te(document.baseURI,ee(oe,e)),labels:{open:A(`image.open`),loading:A(`image.loading`),failed:A(`image.failed`),dialog:A(`image.dialog`),close:A(`image.close`)}}),[oe,A]),ce=t(e=>e.running),L=(0,d.useSyncExternalStore)(e.state.subscribe,e.state.getSnapshot),le=(0,p.useSustainedRecovery)(L!==`connected`),ue=k(`compacting`),R=t(e=>e.openState),de=L===`disconnected`||le||R===`error`,z=t(e=>e.openError),fe=t(e=>e.hasMore),pe=t(e=>e.loadingOlder),me=t(e=>e.olderError),[he,ge]=(0,d.useState)(null),[_e,ve]=(0,d.useState)(!1),B=(0,d.useRef)(0),ye=(0,d.useCallback)((e,t)=>{let n=++B.current;ve(!0),(t===void 0?h(e):h(e,t)).then(()=>{n===B.current&&(ge(null),ve(!1))},t=>{n===B.current&&(ge({path:e,message:Wn(t,A(`fileOpen.unknown`))}),ve(!1))})},[h,A]),be=(0,d.useCallback)(()=>{B.current+=1,ge(null),ve(!1)},[]),xe=(0,d.useMemo)(()=>ae?.[`next-step`].filter(e=>e.source.kind===`user`)??[],[ae]),Se=t(e=>e.pendingSubmissions),Ce=We(E,k(`sentMessageEdit`)?.seq??null,R!==`open`||ce||Se.length>0||(ae?.[`next-turn`].length??0)>0),we=Ce.draft&&j.some(e=>{let t=P.get(e);return t?.kind===`user`&&t.data.seq===Ce.draft?.seq}),Te=ce||Se.some(e=>e.placement!==`queued`),[Ee,De]=(0,d.useMemo)(()=>{if(Se.length===0)return[Se,void 0];let e=Gn(j,P);return[Se.filter(t=>t.placement!==`queued`&&!e.rpcIds.has(t.requestId)),e.lastInputTurn]},[Se,j,P]),Oe=(0,d.useMemo)(()=>{let e=new Map(Ee.map(e=>[e.requestId,e])),t=new Set(Se.filter(e=>e.placement!==`queued`).map(e=>e.requestId));return[...xe.flatMap(n=>{let r=n.source;if(r.kind!==`user`||!(`rpcId`in r))return[n];let i=e.get(r.rpcId);return i===void 0?t.has(r.rpcId)?[]:[n]:(e.delete(r.rpcId),[i])}),...e.values()]},[xe,Se,Ee]),ke=(0,d.useCallback)(e=>u(`conversation.message.images`,{...e,loadImage:x}),[x,u]),Ae=j[0],je=Ae===void 0?null:P.get(Ae)?.anchorSeq??null,Me=j.at(-1)??null,Ne=Oe.findLast(e=>`source`in e),V=Ne?.source.kind===`user`&&`rpcId`in Ne.source?Ne.source.rpcId:Ne?.id??null,H=Un({displayReady:R===`open`||j.length>0,historyReady:R===`open`,order:j,firstSeq:je,lastKey:Me,running:ce,loadingOlder:pe,olderFailed:me!=null,hasMore:fe,chatScroll:C,loadOlder:y,loadThrough:b,lastIsUser:Me!==null&&P.get(Me)?.kind===`user`,steeringId:V,submissionId:Ee.at(-1)?.requestId??null,loadedTurns:ne});return/* @__PURE__ */ (0,f.jsxs)(`div`,{className:U.frame,children:[H.initialized&&/* @__PURE__ */ (0,f.jsx)(Cn,{items:ie,activeTurn:H.activeTurn,busyTurn:H.busyTurn,onNavigate:H.navigateToTurn,t:A}),/* @__PURE__ */ (0,f.jsx)(`div`,{className:U.root,"data-chat-following-tail":H.followingTail?``:void 0,children:/* @__PURE__ */ (0,f.jsx)(`div`,{ref:H.listRef,className:U.scroll,children:/* @__PURE__ */ (0,f.jsxs)(`div`,{ref:H.columnRef,className:U.column,"data-chat-flow":``,children:[R===`loading`&&j.length===0&&/* @__PURE__ */ (0,f.jsx)(`div`,{className:U.hint,children:A(`chat.loadingHistory`)}),R===`error`&&z!==null&&/* @__PURE__ */ (0,f.jsx)(`div`,{className:U.openError,children:A(`chat.loadError`,{message:z.message,code:z.code})}),fe&&/* @__PURE__ */ (0,f.jsx)(`div`,{className:U.older,children:me==null?/* @__PURE__ */ (0,f.jsx)(`span`,{role:pe?`status`:void 0,children:A(pe?`chat.loadingOlder`:`chat.scrollOlder`)}):/* @__PURE__ */ (0,f.jsxs)(f.Fragment,{children:[/* @__PURE__ */ (0,f.jsx)(`span`,{role:`alert`,children:A(`chat.loadOlderError`,{message:me.message})}),/* @__PURE__ */ (0,f.jsx)(`button`,{type:`button`,disabled:pe,onClick:H.loadEarlier,children:A(`chat.retryOlder`)})]})}),/* @__PURE__ */ (0,f.jsx)(p.MarkdownDelegateProvider,{openExternalLink:_,resolveLink:v,openFile:ye,fileImages:se,children:/* @__PURE__ */ (0,f.jsx)(Kn,{entries:N,pendingInputs:Oe,lastInputTurn:De,nodeStore:P,useChatGroup:a,useChatNode:r,useChatNodeProcess:i,usePresentation:O,useStore:c,actions:l,cwd:oe,openFile:ye,openSkill:g,inspectCall:S,forkAt:w,loadTurnDiffs:T,messageEditing:Ce,loadImage:x,renderMessageImages:ke,fileMentions:D,renderSlot:u,t:A})}),Ce.draft&&!we&&/* @__PURE__ */ (0,f.jsx)(rt,{editing:Ce,renderMessageImages:ke,t:A}),Te&&/* @__PURE__ */ (0,f.jsx)(Dn,{startTime:re,compacting:ue,stale:de,t:A}),R===`loading`&&j.length>0&&/* @__PURE__ */ (0,f.jsxs)(`div`,{className:U.syncing,role:`status`,"data-history-syncing":!0,children:[/* @__PURE__ */ (0,f.jsx)(p.StateDot,{state:`ongoing`,className:U.syncingIcon}),/* @__PURE__ */ (0,f.jsx)(`span`,{children:A(`chat.syncing`)})]})]})})}),!H.followingTail&&/* @__PURE__ */ (0,f.jsx)(`div`,{className:U.toBottomSlot,children:/* @__PURE__ */ (0,f.jsx)(`button`,{type:`button`,className:U.toBottom,"aria-label":A(`chat.toBottom`),onClick:H.returnToBottom,children:/* @__PURE__ */ (0,f.jsx)(p.IconChevronDownOutlineRegular,{})})}),he!==null&&/* @__PURE__ */ (0,f.jsx)(Jn,{message:he.message,busy:_e,onClose:be,onRetry:()=>{ye(he.path)},t:A})]})}function Jn({message:e,busy:t,onClose:n,onRetry:r,t:i}){return/* @__PURE__ */ (0,f.jsx)(p.Modal,{open:!0,onClose:n,closeLabel:i(`close`),title:i(`fileOpen.title`),description:e,footer:/* @__PURE__ */ (0,f.jsxs)(f.Fragment,{children:[/* @__PURE__ */ (0,f.jsx)(p.Button,{variant:`outline`,className:U.modalAction,onClick:n,children:i(`cancel`)}),/* @__PURE__ */ (0,f.jsx)(p.Button,{variant:`primary`,className:U.modalAction,disabled:t,onClick:r,children:i(`retry`)})]})})}let K=`chat`,Yn={"message.stepProcess.thinking":`正在分析请求`,"message.stepProcess.read":`正在读取文件`,"message.stepProcess.readImage":`正在读取图片`,"message.stepProcess.write":`正在写入文件`,"message.stepProcess.search":`正在搜索代码`,"message.stepProcess.edit":`正在编辑文件`,"message.stepProcess.commands":`正在运行命令`,"message.stepProcess.code":`正在运行代码`,"message.stepProcess.webSearch":`正在搜索网页`,"message.stepProcess.webFetch":`正在访问网页`,"message.stepProcess.subagents":`正在协调子智能体`,"message.stepProcess.plan":`正在更新计划`,"message.stepProcess.questions":`等待你的操作`,"message.stepProcess.tools":`正在调用工具`,"message.stepProcess.prepare.read":`准备读取文件`,"message.stepProcess.prepare.readImage":`准备读取图片`,"message.stepProcess.prepare.write":`准备写入文件`,"message.stepProcess.prepare.search":`准备搜索代码`,"message.stepProcess.prepare.edit":`准备编辑文件`,"message.stepProcess.prepare.commands":`准备运行命令`,"message.stepProcess.prepare.code":`准备运行代码`,"message.stepProcess.prepare.webSearch":`准备搜索网页`,"message.stepProcess.prepare.webFetch":`准备访问网页`,"message.stepProcess.prepare.subagents":`准备协调子智能体`,"message.stepProcess.prepare.plan":`准备更新计划`,"message.stepProcess.prepare.questions":`准备提问`,"message.stepProcess.prepare.tools":`准备调用工具`,"message.stepProcess.done.thinking":`已完成分析`,"message.stepProcess.done.read":`已读取文件`,"message.stepProcess.done.readImage":`已读取图片`,"message.stepProcess.done.write":`已写入文件`,"message.stepProcess.done.search":`已搜索代码`,"message.stepProcess.done.edit":`修改了文件`,"message.stepProcess.done.commands":`执行了命令`,"message.stepProcess.done.code":`运行了代码`,"message.stepProcess.done.webSearch":`已搜索网页`,"message.stepProcess.done.webFetch":`已访问网页`,"message.stepProcess.done.subagents":`已协调子智能体`,"message.stepProcess.done.plan":`更新了计划`,"message.stepProcess.done.questions":`向用户提出了问题`,"message.stepProcess.done.tools":`已调用工具`,"message.stepProcess.joinTwo":`{first}并{second}`,"message.stepProcess.comma":`,`,"message.stepProcess.sharedPrefix":`已`,"message.stepProcess.more":`{title}等`,"message.trigger.request":`收到执行请求`,"message.trigger.goal":`继续执行目标`,"message.trigger.agent":`收到任务消息`,"message.trigger.team":`收到团队消息`,"message.trigger.subagent":`子任务状态更新`,"message.trigger.github":`收到 GitHub 事件`,"message.trigger.webhook":`收到外部事件`,"message.trigger.schedule":`自动化任务`,"message.trigger.job":`后台任务状态更新`,"message.trigger.plugin":`插件状态更新`,"message.trigger.explanation":`这条通知触发了本轮回复。`,"message.turnProcess.worked":`已完成`,"message.turnProcess.took":`已完成,用时 `,"message.turnProcess.failed":`处理失败`,"view.chat":`对话`,"image.open":`查看大图`,"image.loading":`加载图片…`,"image.failed":`图片无法预览`,"image.dialog":`图片预览`,"image.close":`关闭图片预览`,"duration.milliseconds":`{milliseconds}毫秒`,"chat.loadingHistory":`载入历史…`,"chat.syncing":`正在获取最新消息…`,"chat.loadingDiff":`载入差异…`,"chat.retryDiff":`重试`,"chat.loadError":`历史加载失败:{message}({code})`,"chat.loadOlder":`加载更早`,"chat.scrollOlder":`向上滚动查看更早消息`,"chat.loadingOlder":`正在加载更早消息…`,"chat.loadOlderError":`更早消息加载失败:{message}`,"chat.retryOlder":`重试加载`,"chat.toBottom":`回到底部`,"chat.filesChanged":`{count} 个文件已更改`,"chat.fileEdited":`已编辑 {name}`,"chat.filesEdited":`已编辑 {count} 个文件`,"chat.viewChanges":`查看变更`,"chat.hideChanges":`收起变更`,"chat.showMoreFiles":`再显示 {count} 个文件`,"chat.collapseFiles":`收起文件`,"diff.code":`代码`,"diff.wrap":`自动换行`,"diff.unwrap":`取消换行`,"diff.copy":`复制`,"diff.copied":`已复制`,"diff.collapseAria":`折叠差异`,"diff.expandAria":`展开 {count} 行隐藏内容`,"diff.collapse":`折叠`,"diff.expand":`展开 {count} 行`,"chat.deepDiving":`正在处理`,"chat.statusUnconfirmed":`连接中断,任务状态待确认`,"chat.deepDivingFor":`正在处理 · {duration}`,"chat.turnNavigation.label":`轮次导航`,"chat.turnNavigation.jump":`跳转到用户消息 {turn}`,"chat.turnNavigation.jumpLoad":`加载并跳转到用户消息 {turn}`,"chat.turnNavigation.turn":`用户消息 {turn}`,"settings.links.title":`网页链接默认打开方式`,"settings.links.description":`对话中网页链接的打开位置`,"settings.links.sidebar":`应用内侧边栏`,"settings.links.newTab":`默认浏览器`,"settings.transcript.title":`工作步骤展示`,"settings.transcript.description":`选择希望看到多少工具调用细节`,"settings.transcript.compact":`简洁`,"settings.transcript.standard":`标准`,"settings.transcript.detailed":`详细`,"settings.transcript.verbose":`完全展开`,"fileOpen.title":`无法打开文件`,"fileOpen.unknown":`无法打开此文件`,"message.extraBlock":`附加内容块`,"message.systemPrompt":`系统提示词`,"message.systemPromptUpdate":`系统提示词更新`,"message.toolAdded":`已添加工具:{name}`,"message.toolRemoved":`已移除工具:{name}`,"message.toolsAdded":`新增:{names}`,"message.toolsAddedCount":`新增 {count} 个`,"message.toolsChanged":`新增 {added} 个,移除 {removed} 个`,"message.toolsRemoved":`移除:{names}`,"message.toolsRemovedCount":`移除 {count} 个`,"message.toolsUpdated":`工具已更新`,"message.contextInjection":`上下文注入`,"message.contextRecall":`跨会话召回`,"message.referenceSummary":`引用会话 · {labels}`,"message.referenceSeparator":`、`,"message.context.instructions.loaded":`已载入`,"message.context.instructions.added":`已新增`,"message.context.instructions.updated":`已更新`,"message.context.instructions.removed":`已移除`,"message.context.catalog.replaced":`替换目录`,"message.context.catalog.more":`…还有 {count} 条`,"message.context.snapshot.supersedes":`取代先前的快照`,"message.context.relay.from":`来自会话 {session}`,"message.context.recall.counts":`保留 {retained} 条 · 省略 {omitted} 条`,"message.context.recall.truncated":`已截断`,"message.compaction":`上下文已压缩`,"message.compaction.running":`正在压缩…`,"message.compaction.completed":`已压缩 {items} 条历史记录(约 {tokens} tokens)`,"message.compaction.expand":`点击查看压缩摘要`,"message.compaction.unavailable":`压缩摘要不可用`,"message.compaction.commandTitle":`compact`,"message.think":`思考`,"message.unknownSurface":`未知 surface 事件:{type}`,"message.unknownBlock":`未知内容块`,"message.turnProcess.toolCalls.one":`{count} 次工具调用`,"message.turnProcess.toolCalls.other":`{count} 次工具调用`,"message.turnProcess.messages.one":`{count} 条消息`,"message.turnProcess.messages.other":`{count} 条消息`,"message.turnProcess.subagents.one":`{count} 个 subagent`,"message.turnProcess.subagents.other":`{count} 个 subagent`,"message.turnProcess.thoughtForAWhile":`已思考`,"message.turnProcess.separator":` · `,"message.stopped":`已停止`,"message.edit":`编辑消息`,"message.edit.changed":`会话状态已变化,请核对当前历史后继续。`,"message.edit.cancel":`取消`,"message.edit.send":`发送`,"message.edit.sending":`正在回退并重跑…`,"message.edit.checkHistory":`请核对当前历史后再继续;编辑文本已保留,不会自动重发。`,"message.branch":`在新对话中分支`,"message.branchFailed":`分叉未完成:{message}`,"message.branchUnavailable":`仅可从已完成轮次的最后一条消息分支`,"message.retry.active":`正在重试模型请求`,"message.retry.cancelled":`模型请求重试已取消`,"message.retry.started":`已重试模型请求`,"message.retry.scheduled":`等待重试模型请求`,"message.retry.status":`{label}({retry}/{maximum}) · {seconds}s`,"message.retry.delay":`重试延迟:`,"message.retry.failure":`失败原因:`,"message.failure.auth":`API 密钥无效`,"message.accountStopped":`任务已停止`,"message.failure.accountSignedOut":`任务已因退出 DeepSeek 登录而停止。`,"message.failure.accountSignInRequired":`请先登录 DeepSeek,并确认请求地址支持账号认证。`,"message.failure.quota":`当前请求的额度已用尽`,"message.turnError":`本轮运行失败`,"message.maxTokens":`已达到输出 token 上限`,"message.maxTokens.hint":`回答被截断,已有输出保留在对话中。发送“继续”可让模型接着输出。`,"duration.secondUnit":`秒`,"duration.minuteUnit":`分`,"duration.hourUnit":`小时`,"command.running":`执行中…`,"command.failed":`指令失败`,"command.done":`已完成`,"command.title":`指令`,"row.running":`运行中`,"row.failed":`失败`,"json.truncated":`… 已截断,共 {total} 字符`,"clock.md":`{m}月{d}日`,"clock.ymd":`{y}年{m}月{d}日`},Xn={"message.stepProcess.thinking":`Analyzing the request`,"message.stepProcess.read":`Reading files`,"message.stepProcess.readImage":`Reading images`,"message.stepProcess.write":`Writing files`,"message.stepProcess.search":`Searching code`,"message.stepProcess.edit":`Editing files`,"message.stepProcess.commands":`Running commands`,"message.stepProcess.code":`Running code`,"message.stepProcess.webSearch":`Searching the web`,"message.stepProcess.webFetch":`Visiting web pages`,"message.stepProcess.subagents":`Coordinating subagents`,"message.stepProcess.plan":`Updating the plan`,"message.stepProcess.questions":`Waiting for your action`,"message.stepProcess.tools":`Calling tools`,"message.stepProcess.prepare.read":`Preparing to read files`,"message.stepProcess.prepare.readImage":`Preparing to read images`,"message.stepProcess.prepare.write":`Preparing to write files`,"message.stepProcess.prepare.search":`Preparing to search code`,"message.stepProcess.prepare.edit":`Preparing to edit files`,"message.stepProcess.prepare.commands":`Preparing to run commands`,"message.stepProcess.prepare.code":`Preparing to run code`,"message.stepProcess.prepare.webSearch":`Preparing to search the web`,"message.stepProcess.prepare.webFetch":`Preparing to visit web pages`,"message.stepProcess.prepare.subagents":`Preparing to coordinate subagents`,"message.stepProcess.prepare.plan":`Preparing to update the plan`,"message.stepProcess.prepare.questions":`Preparing questions`,"message.stepProcess.prepare.tools":`Preparing tool calls`,"message.stepProcess.done.thinking":`Analysis completed`,"message.stepProcess.done.read":`Read files`,"message.stepProcess.done.readImage":`Read images`,"message.stepProcess.done.write":`Wrote files`,"message.stepProcess.done.search":`Searched code`,"message.stepProcess.done.edit":`Edited files`,"message.stepProcess.done.commands":`Ran commands`,"message.stepProcess.done.code":`Ran code`,"message.stepProcess.done.webSearch":`Searched the web`,"message.stepProcess.done.webFetch":`Visited web pages`,"message.stepProcess.done.subagents":`Coordinated subagents`,"message.stepProcess.done.plan":`Updated the plan`,"message.stepProcess.done.questions":`Asked questions`,"message.stepProcess.done.tools":`Called tools`,"message.stepProcess.joinTwo":`{first} and {second}`,"message.stepProcess.comma":`, `,"message.stepProcess.sharedPrefix":``,"message.stepProcess.more":`{title}, etc.`,"message.trigger.request":`Execution requested`,"message.trigger.goal":`Continuing goal`,"message.trigger.agent":`Task message received`,"message.trigger.team":`Team message received`,"message.trigger.subagent":`Subtask status updated`,"message.trigger.github":`GitHub event received`,"message.trigger.webhook":`External event received`,"message.trigger.schedule":`Automation task`,"message.trigger.job":`Background task updated`,"message.trigger.plugin":`Plugin status updated`,"message.trigger.explanation":`This notification triggered this response.`,"message.turnProcess.worked":`Completed`,"message.turnProcess.took":`Completed in `,"message.turnProcess.failed":`Failed`,"view.chat":`Chat`,"image.open":`View full image`,"image.loading":`Loading image…`,"image.failed":`Image preview unavailable`,"image.dialog":`Image preview`,"image.close":`Close image preview`,"duration.milliseconds":`{milliseconds}ms`,"chat.loadingHistory":`Loading history…`,"chat.syncing":`Fetching latest messages…`,"chat.loadingDiff":`Loading diff…`,"chat.retryDiff":`Retry`,"chat.loadError":`Failed to load history: {message} ({code})`,"chat.loadOlder":`Load earlier`,"chat.scrollOlder":`Scroll up for earlier messages`,"chat.loadingOlder":`Loading earlier messages…`,"chat.loadOlderError":`Could not load earlier messages: {message}`,"chat.retryOlder":`Retry loading`,"chat.toBottom":`Back to bottom`,"chat.filesChanged":`{count} files changed`,"chat.fileEdited":`Edited {name}`,"chat.filesEdited":`Edited {count} files`,"chat.viewChanges":`View changes`,"chat.hideChanges":`Hide changes`,"chat.showMoreFiles":`Show {count} more`,"chat.collapseFiles":`Collapse files`,"diff.code":`Code`,"diff.wrap":`Wrap lines`,"diff.unwrap":`Unwrap lines`,"diff.copy":`Copy`,"diff.copied":`Copied`,"diff.collapseAria":`Collapse diff`,"diff.expandAria":`Expand {count} hidden lines`,"diff.collapse":`Collapse`,"diff.expand":`Expand {count} lines`,"chat.deepDiving":`Working`,"chat.statusUnconfirmed":`Connection interrupted; task status unconfirmed`,"chat.deepDivingFor":`Working · {duration}`,"chat.turnNavigation.label":`Turn navigation`,"chat.turnNavigation.jump":`Jump to user message {turn}`,"chat.turnNavigation.jumpLoad":`Load and jump to user message {turn}`,"chat.turnNavigation.turn":`User message {turn}`,"settings.links.title":`Open chat links in`,"settings.links.description":`Choose where to open web links`,"settings.links.sidebar":`In-App Sidebar`,"settings.links.newTab":`Default Browser`,"settings.transcript.title":`Work details`,"settings.transcript.description":`Choose how much detail to show for tool calls`,"settings.transcript.compact":`Compact`,"settings.transcript.standard":`Standard`,"settings.transcript.detailed":`Detailed`,"settings.transcript.verbose":`Verbose`,"fileOpen.title":`Couldn’t open file`,"fileOpen.unknown":`Couldn’t open this file`,"message.extraBlock":`Extra content block`,"message.systemPrompt":`System prompt`,"message.systemPromptUpdate":`System prompt update`,"message.toolAdded":`Tool added: {name}`,"message.toolRemoved":`Tool removed: {name}`,"message.toolsAdded":`Added: {names}`,"message.toolsAddedCount":`{count} added`,"message.toolsChanged":`{added} added, {removed} removed`,"message.toolsRemoved":`Removed: {names}`,"message.toolsRemovedCount":`{count} removed`,"message.toolsUpdated":`Tools updated`,"message.contextInjection":`Context injection`,"message.contextRecall":`Session recall`,"message.referenceSummary":`Referenced session · {labels}`,"message.referenceSeparator":`, `,"message.context.instructions.loaded":`loaded`,"message.context.instructions.added":`added`,"message.context.instructions.updated":`updated`,"message.context.instructions.removed":`removed`,"message.context.catalog.replaced":`Replacement catalog`,"message.context.catalog.more":`… {count} more`,"message.context.snapshot.supersedes":`Supersedes earlier snapshots`,"message.context.relay.from":`From session {session}`,"message.context.recall.counts":`{retained} kept · {omitted} omitted`,"message.context.recall.truncated":`truncated`,"message.compaction":`Context compacted`,"message.compaction.running":`Compacting context…`,"message.compaction.completed":`Compacted {items} history items (~{tokens} tokens)`,"message.compaction.expand":`View compaction summary`,"message.compaction.unavailable":`Compaction summary unavailable`,"message.compaction.commandTitle":`compact`,"message.think":`Think`,"message.unknownSurface":`Unknown surface event: {type}`,"message.unknownBlock":`Unknown content block`,"message.turnProcess.toolCalls.one":`{count} tool call`,"message.turnProcess.toolCalls.other":`{count} tool calls`,"message.turnProcess.messages.one":`{count} message`,"message.turnProcess.messages.other":`{count} messages`,"message.turnProcess.subagents.one":`{count} subagent`,"message.turnProcess.subagents.other":`{count} subagents`,"message.turnProcess.thoughtForAWhile":`Thought for a while`,"message.turnProcess.separator":` · `,"message.stopped":`Stopped`,"message.edit":`Edit message`,"message.edit.changed":`Conversation state changed. Check current history before continuing.`,"message.edit.cancel":`Cancel`,"message.edit.send":`Send`,"message.edit.sending":`Reverting and rerunning…`,"message.edit.checkHistory":`Check current history before continuing. Your edit is retained and will not be resent automatically.`,"message.branch":`Branch into a new conversation`,"message.branchFailed":`Fork did not complete: {message}`,"message.branchUnavailable":`Available only on the last message of a completed turn`,"message.retry.active":`Retrying model request`,"message.retry.cancelled":`Model request retry cancelled`,"message.retry.started":`Retried model request`,"message.retry.scheduled":`Waiting to retry model request`,"message.retry.status":`{label} ({retry}/{maximum}) · {seconds}s`,"message.retry.delay":`Retry delay: `,"message.retry.failure":`Failure reason: `,"message.failure.auth":`API key is invalid`,"message.accountStopped":`Task stopped`,"message.failure.accountSignedOut":`Stopped because you signed out of DeepSeek.`,"message.failure.accountSignInRequired":`Sign in to DeepSeek and ensure the request destination supports account authentication.`,"message.failure.quota":`Request quota exhausted.`,"message.turnError":`This turn failed`,"message.maxTokens":`Output token limit reached`,"message.maxTokens.hint":`The reply was cut off; earlier output is preserved in the conversation. Send "continue" to let the model resume.`,"duration.secondUnit":`s`,"duration.minuteUnit":`m `,"duration.hourUnit":`h `,"command.running":`Running…`,"command.failed":`Command failed`,"command.done":`Completed`,"command.title":`Command`,"row.running":`Running`,"row.failed":`Failed`,"json.truncated":`… truncated, {total} characters total`,"clock.md":`{m}/{d}`,"clock.ymd":`{y}-{m}-{d}`},Zn=`@deepseek-ai/dsh-client-ui-chat/ReasoningRow.module.css`;if(typeof document<`u`&&document.querySelector(`style[data-plugin-css=`+JSON.stringify(Zn)+`]`)===null){let e=document.createElement(`style`);e.dataset.plugin=`@deepseek-ai/dsh-client-ui-chat`,e.dataset.pluginCss=Zn,e.textContent=`.nAJelq_root{flex-direction:column;display:flex}.nAJelq_root:not([data-expanded]){contain:size layout;height:calc(24px + var(--dsh-content-font-delta,0px))}.nAJelq_row{overflow:hidden}.nAJelq_root[data-expanded] [data-open] [data-disclosure-row]{z-index:1;background:var(--dsw-alias-bg-base);position:sticky;top:0}.nAJelq_leading{flex-shrink:0}.nAJelq_title{font-weight:400}.nAJelq_separator{background:var(--dsw-alias-label-caption);border-radius:1px;flex:none;width:2px;height:2px;margin:0 8px}.nAJelq_summary{min-width:0;font-size:var(--dsh-content-font-size-secondary,13px);line-height:calc(20px + var(--dsh-content-font-delta-secondary,0px));white-space:nowrap;flex:auto;overflow:hidden}.nAJelq_summaryText{text-overflow:ellipsis;display:block;overflow:hidden}.nAJelq_summary[data-streaming]{mask-image:linear-gradient(90deg,#000 calc(100% - 48px),#0000)}.nAJelq_summary[data-streaming] .nAJelq_summaryText{text-overflow:clip;overflow:visible}.nAJelq_root:not([data-preview]) .nAJelq_separator,.nAJelq_root:not([data-preview]) .nAJelq_summary{display:none}.nAJelq_thinkBody{padding:4px 0 4px calc(22px + var(--dsh-content-font-delta,0px));min-width:0}`,document.head.appendChild(e)}var Qn={leading:`nAJelq_leading`,root:`nAJelq_root`,row:`nAJelq_row`,separator:`nAJelq_separator`,summary:`nAJelq_summary`,summaryText:`nAJelq_summaryText`,thinkBody:`nAJelq_thinkBody`,title:`nAJelq_title`};let $n=/* @__PURE__ */ (0,f.jsx)(p.IconThinkOutlineRegular,{size:14});function er(e){let t=e.indexOf(`
|
|
11
11
|
`);return t===-1?e:e.slice(0,t)}function tr(e){let t=``,n=0,r=/\r?\n(?:[\t ]*\r?\n)+/g;for(;;){let i=r.exec(e),a=i===null?e.length:i.index+i[0].indexOf(`
|
|
12
12
|
`),o=e.indexOf(`
|
|
13
13
|
`,n);if(o!==-1&&o<=a){let r=e.slice(n,o).trim();r!==``&&(t=r)}if(i===null)return t;n=i.index+i[0].length}}let nr=(0,d.memo)(function({text:e,running:t,usePresentation:n,useDisclosure:r,t:i}){let{expanded:a,toggle:o}=r(),s=(0,d.useMemo)(()=>se(i),[i]),c=t?tr(e):er(e),l=(0,d.useMemo)(()=>c.replaceAll(`**`,``),[c]),u=n(e=>!a&&l!==``&&(t||e.settledReasoningPreview)),m=(0,d.useMemo)(()=>/* @__PURE__ */ (0,f.jsxs)(f.Fragment,{children:[/* @__PURE__ */ (0,f.jsx)(`span`,{className:Qn.separator,"data-shimmer-decoration":!0,"aria-hidden":!0}),/* @__PURE__ */ (0,f.jsx)(`span`,{className:Qn.summary,"data-streaming":t||void 0,children:/* @__PURE__ */ (0,f.jsx)(`span`,{className:Qn.summaryText,children:/* @__PURE__ */ (0,f.jsx)(p.TextShimmer,{children:l})})})]}),[t,l]),h=(0,d.useMemo)(()=>a?/* @__PURE__ */ (0,f.jsx)(`div`,{className:Qn.thinkBody,children:/* @__PURE__ */ (0,f.jsx)(p.MarkdownText,{text:e,streaming:t,labels:s,variant:`compact`})}):void 0,[a,s,t,e]);return/* @__PURE__ */ (0,f.jsxs)(`div`,{className:Qn.root,"data-variant":`think`,"data-state":t?`running`:`ok`,"data-expanded":a||void 0,"data-preview":u||void 0,children:[t&&/* @__PURE__ */ (0,f.jsx)(`span`,{className:En.visuallyHidden,children:i(`row.running`)}),/* @__PURE__ */ (0,f.jsx)(p.DisclosureRow,{rowClassName:Qn.row,leadingClassName:Qn.leading,titleClassName:Qn.title,icon:$n,title:i(`message.think`),running:t,open:a,expandable:!0,expandOnRowClick:!0,onToggle:o,collapsedContent:m,children:h})]})}),rr=`@deepseek-ai/dsh-client-ui-chat/AssistantMarkdown.module.css`;if(typeof document<`u`&&document.querySelector(`style[data-plugin-css=`+JSON.stringify(rr)+`]`)===null){let e=document.createElement(`style`);e.dataset.plugin=`@deepseek-ai/dsh-client-ui-chat`,e.dataset.pluginCss=rr,e.textContent=`.UoIYma_root{font-size:var(--dsh-content-font-size,14px);line-height:calc(24px + var(--dsh-content-font-delta,0px));color:var(--dsw-alias-label-primary);flex-direction:column;display:flex}.UoIYma_body{flex-direction:column;gap:16px;display:flex}.UoIYma_body .md-table-wide{--dsh-table-spare:max(0px, calc((100cqw - var(--dsh-chat-content-width)) / 2));--dsh-table-lead:calc(var(--dsh-table-spare) + min(var(--dsh-chat-content-width), 100cqw) - 100%);box-sizing:border-box;width:calc(100% + var(--dsh-table-lead) + var(--dsh-table-spare));max-width:none;margin-left:calc(-1 * var(--dsh-table-lead));padding-left:var(--dsh-table-lead)}.UoIYma_body .md-table-wide>table{z-index:1;position:relative}.UoIYma_body>[data-turn-process-inline][hidden]{margin-bottom:-16px}.UoIYma_stopped{border-radius:var(--dsw-radius-sm);background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-tertiary);align-self:flex-start;padding:0 6px;font-size:11px;line-height:18px}.UoIYma_actions{margin-top:16px;margin-left:-6px}`,document.head.appendChild(e)}var ir={actions:`UoIYma_actions`,body:`UoIYma_body`,root:`UoIYma_root`,stopped:`UoIYma_stopped`};function ar(e,t){let n;try{n=decodeURIComponent(t.split(/[?#]/u)[0]??``)}catch{return}return te(e,n)}let or=(0,d.memo)(function({blocks:e,streaming:t,interrupted:n,renderMessageImages:r,groupPart:i,useDisclosure:a,reasoningHidden:o=!1,usePresentation:s,revealProcess:c,mentions:l,t:u}){let m=(0,d.useMemo)(()=>se(u),[u]),h=(0,d.useMemo)(()=>({resolve:e=>ar(document.baseURI,e)}),[]),g=e.length-1;if(!(t||n===!0||e.some(e=>e.kind!==`tool-call`)))return null;let _=[];for(let n=0;n<e.length;n++){let v=e[n];if(v!==void 0&&(i!==`reasoning`||v.kind===`reasoning`)&&(i!==`response`||v.kind!==`reasoning`))switch(v.kind){case`text`:_.push(/* @__PURE__ */ (0,f.jsx)(p.MarkdownText,{text:v.text,streaming:t,labels:m,fileMentions:l,pathImages:h},n));break;case`reasoning`:_.push(/* @__PURE__ */ (0,f.jsx)(sr,{hidden:o,reveal:c,children:/* @__PURE__ */ (0,f.jsx)(nr,{text:v.text,running:t&&n===g,usePresentation:s,useDisclosure:a,t:u})},n));break;case`image`:{let t=n,i=[v];for(;n+1<e.length;){let t=e[n+1];if(t===void 0||t.kind!==`image`)break;i.push(t),n+=1}_.push(/* @__PURE__ */ (0,f.jsx)(d.Fragment,{children:r({images:i.map(({attachment:e})=>({attachment:e})),align:`start`})},t));break}case`tool-call`:break;default:_.push(/* @__PURE__ */ (0,f.jsx)(p.JsonBlock,{label:u(`message.unknownBlock`),payload:v.block,truncatedLabel:e=>u(`json.truncated`,{total:e})},n))}}return/* @__PURE__ */ (0,f.jsx)(`div`,{className:ir.root,"data-streaming":t||void 0,children:/* @__PURE__ */ (0,f.jsxs)(`div`,{className:ir.body,children:[_,n&&(i===void 0||i===`response`||!e.some(e=>e.kind!==`reasoning`&&e.kind!==`tool-call`))&&/* @__PURE__ */ (0,f.jsx)(`span`,{className:ir.stopped,children:u(`message.stopped`)})]})})});function sr({hidden:e,reveal:t,children:n}){let r=_t(e,t??cr);return/* @__PURE__ */ (0,f.jsx)(`div`,{ref:r,"data-turn-process-inline":e||void 0,children:n})}let cr=()=>{},lr=(0,d.memo)(function({node:e,groupPart:t,useDisclosure:n,useTurnData:r,turnProcess:i,openFile:a,renderMessageImages:o,fileMentions:s,usePresentation:c,t:l}){let u=e.data,p=e.location.kind===`turn`||e.location.kind===`step`?e.location.turn:void 0,m=r(`turn-tail`),h=(0,d.useMemo)(()=>{if(p?.status===`closed`&&u.finalNode!==void 0&&m?.closing?.finalNode.seq===u.finalNode.seq)return{turn:p,seq:u.finalNode.seq,openFile:a}},[u.finalNode,a,m,p]),g=(0,d.useMemo)(()=>h===void 0?void 0:s(h),[s,h]),_=i!==void 0&&i.foldable&&i.spec.answerStep===u.step&&i.spec.inlineReasoning&&!i.open,v=(0,d.useCallback)(()=>{i?.setOpen(!0)},[i]);return/* @__PURE__ */ (0,f.jsx)(or,{blocks:u.blocks,groupPart:t,useDisclosure:n,streaming:u.status===`running`,interrupted:u.status===`interrupted`,renderMessageImages:o,reasoningHidden:_,usePresentation:c,revealProcess:v,mentions:g,t:l})}),ur=`@deepseek-ai/dsh-client-ui-chat/GenericCommandCard.module.css`;if(typeof document<`u`&&document.querySelector(`style[data-plugin-css=`+JSON.stringify(ur)+`]`)===null){let e=document.createElement(`style`);e.dataset.plugin=`@deepseek-ai/dsh-client-ui-chat`,e.dataset.pluginCss=ur,e.textContent=`.hIxFiG_root{flex-direction:column;display:flex}.hIxFiG_leading{flex-shrink:0}.hIxFiG_title{font-weight:400}.hIxFiG_separator{background:var(--dsw-alias-label-caption);border-radius:1px;flex:none;width:2px;height:2px;margin:0 8px}.hIxFiG_summary{min-width:0;font-size:var(--dsh-content-font-size-secondary,13px);line-height:calc(24px + var(--dsh-content-font-delta,0px));text-overflow:ellipsis;white-space:nowrap;flex:auto;overflow:hidden}.hIxFiG_summary[data-error],.hIxFiG_body[data-error]{color:var(--dsw-alias-state-error-primary)}.hIxFiG_body{border:.5px solid var(--dsw-alias-border-l1);border-radius:var(--dsw-radius-lg);background:var(--dsw-alias-markdown-code-block);max-height:260px;color:var(--dsw-alias-label-primary);font:var(--dsw-font-markdown-code-block-small);white-space:pre-wrap;margin:4px 0 4px 4px;padding:12px 16px;overflow:auto}`,document.head.appendChild(e)}var dr={body:`hIxFiG_body`,leading:`hIxFiG_leading`,root:`hIxFiG_root`,separator:`hIxFiG_separator`,summary:`hIxFiG_summary`,title:`hIxFiG_title`};let fr=/* @__PURE__ */ (0,f.jsx)(p.IconApiOutlineRegular,{size:14});function pr(e){return e===null?`running`:e.kind===`error`?`error`:`ok`}let mr=(0,d.memo)(function({node:e,t,runningSummary:n,successSummary:r}){let[i,a]=(0,d.useState)(!1),o=e.outcome?.text,s=e.outcome===null?n??t(`command.running`):o??(e.outcome.kind===`error`?t(`command.failed`):r??t(`command.done`)),c=e.name??t(`command.title`),l=pr(e.outcome),u=l===`running`,m=o!==void 0&&o.includes(`
|
|
14
|
-
`)?o:null,h=i&&m!==null,g=(0,d.useCallback)(()=>{a(e=>!e)},[]),_=(0,d.useMemo)(()=>/* @__PURE__ */ (0,f.jsxs)(f.Fragment,{children:[/* @__PURE__ */ (0,f.jsx)(`span`,{className:dr.separator,"data-shimmer-decoration":!0,"aria-hidden":!0}),/* @__PURE__ */ (0,f.jsx)(`span`,{className:dr.summary,"data-error":l===`error`||void 0,children:/* @__PURE__ */ (0,f.jsx)(p.TextShimmer,{children:s})})]}),[u,l,s]),v=(0,d.useMemo)(()=>h?/* @__PURE__ */ (0,f.jsx)(`pre`,{className:dr.body,"data-error":l===`error`||void 0,children:m}):void 0,[m,h,l]);return/* @__PURE__ */ (0,f.jsxs)(`div`,{className:dr.root,"data-variant":`others`,"data-command":e.name??void 0,"data-state":l,children:[l===`running`&&/* @__PURE__ */ (0,f.jsx)(`span`,{className:En.visuallyHidden,children:t(`row.running`)}),l===`error`&&/* @__PURE__ */ (0,f.jsx)(`span`,{className:En.visuallyHidden,children:t(`row.failed`)}),/* @__PURE__ */ (0,f.jsx)(p.DisclosureRow,{leadingClassName:dr.leading,titleClassName:dr.title,icon:fr,title:c,running:u,open:h,expandable:m!==null,expandOnRowClick:!0,keepContentWhenOpen:!0,onToggle:g,collapsedContent:_,children:v})]})});function hr({node:e,compaction:t,t:n}){return t===void 0?/* @__PURE__ */ (0,f.jsx)(mr,{node:e,t:n,runningSummary:n(`message.compaction.running`),successSummary:n(`message.compaction`)}):/* @__PURE__ */ (0,f.jsx)(le,{node:t,title:n(`message.compaction.commandTitle`),fallbackSummary:e.outcome?.text??null,t:n})}let gr=(0,d.memo)(function({node:e,renderSlot:t,t:n}){let r=e.data,i=(0,d.useMemo)(()=>({node:r}),[r]);return/* @__PURE__ */ (0,f.jsx)(`div`,{className:U.callRow,children:t(`conversation.chat.commandview`,i,{entryKey:r.name??``,fallback:/* @__PURE__ */ (0,f.jsx)(mr,{...i,t:n})})})}),_r=(0,d.memo)(function({node:e,t}){let n=e.data;return/* @__PURE__ */ (0,f.jsx)(`div`,{className:U.callRow,children:/* @__PURE__ */ (0,f.jsx)(hr,{node:n.command,...n.compaction===null?{}:{compaction:n.compaction},t})})});function vr({text:e,update:t=!1,t:n}){let[r,i]=(0,d.useState)(!1);return/* @__PURE__ */ (0,f.jsx)(p.DisclosureRow,{className:V.root,icon:/* @__PURE__ */ (0,f.jsx)(p.IconBrowseOutlineRegular,{size:14}),chevronClassName:V.chevron,title:n(t?`message.systemPromptUpdate`:`message.systemPrompt`),open:r,expandable:!0,expandOnRowClick:!0,onToggle:()=>{i(e=>!e)},children:/* @__PURE__ */ (0,f.jsx)(`div`,{className:V.body,"data-system-prompt-body":!0,children:/* @__PURE__ */ (0,f.jsx)(B,{content:[{type:`text`,text:e}],source:null,t:n})})})}let yr=(0,d.memo)(function({node:e,t}){return/* @__PURE__ */ (0,f.jsx)(vr,{text:e.data.text,update:e.data.update===!0,t})}),br=`@deepseek-ai/dsh-client-ui-chat/TurnProcessNodeView.module.css`;if(typeof document<`u`&&document.querySelector(`style[data-plugin-css=`+JSON.stringify(br)+`]`)===null){let e=document.createElement(`style`);e.dataset.plugin=`@deepseek-ai/dsh-client-ui-chat`,e.dataset.pluginCss=br,e.textContent=`.ty-UXa_root{box-sizing:border-box;width:100%;min-width:0;height:calc(33px + var(--dsh-content-font-delta,0px));border:none;border-bottom:.5px solid var(--dsw-alias-border-l2);color:var(--dsw-alias-label-tertiary);font:inherit;font-size:var(--dsh-content-font-size,14px);cursor:pointer;text-align:left;background:0 0;align-items:center;padding:0 0 8px;transition:color .1s;display:flex}.ty-UXa_root:disabled{cursor:default}.ty-UXa_root:hover:not(:disabled){color:var(--dsw-alias-label-secondary)}.ty-UXa_chevron{width:14px;height:14px;color:inherit;flex:none;margin-left:4px;transition:transform .1s}.ty-UXa_root[data-open] .ty-UXa_chevron{transform:rotate(180deg)}.ty-UXa_label{min-width:0;font-size:inherit;line-height:calc(24px + var(--dsh-content-font-delta,0px));text-overflow:ellipsis;white-space:nowrap;overflow:hidden}.ty-UXa_durationNumber{font-family:var(--ds-font-family-code);font-variant-numeric:tabular-nums}@media (prefers-reduced-motion:reduce){.ty-UXa_root,.ty-UXa_chevron{transition:none}}`,document.head.appendChild(e)}var xr={chevron:`ty-UXa_chevron`,durationNumber:`ty-UXa_durationNumber`,label:`ty-UXa_label`,root:`ty-UXa_root`};let Sr=(0,d.memo)(function({node:e,turnProcess:t,t:n}){if(t===void 0)throw Error(`turn-process node requires Turn process owner state`);let r=!t.foldable||t.open,i=e.location.kind===`turn`||e.location.kind===`step`?e.location.turn:void 0;if(i?.status!==`closed`)return null;let a=t.foldable&&t.hasContent&&!mt(e),o=i.end?.data.reason.kind,s=i.start===void 0||i.end===void 0||i.end.time<=i.start.time?void 0:Math.max(1e3,i.end.time-i.start.time),c=s===void 0||o===`aborted`||o===`error`?void 0:Le(s,n),l=n(o===`aborted`?`message.stopped`:o===`error`?`message.turnProcess.failed`:c===void 0?`message.turnProcess.worked`:`message.turnProcess.took`),u=n(o===`aborted`?`message.stopped`:o===`error`?`message.turnProcess.failed`:`message.turnProcess.worked`);return/* @__PURE__ */ (0,f.jsxs)(f.Fragment,{children:[/* @__PURE__ */ (0,f.jsx)(`span`,{className:En.visuallyHidden,role:`status`,"aria-live":`polite`,"aria-atomic":`true`,children:u}),/* @__PURE__ */ (0,f.jsxs)(`button`,{type:`button`,className:xr.root,"data-open":r||void 0,"data-turn-process":e.data.turn,"data-turn-process-messages":e.data.messageCount,"data-turn-process-tool-calls":e.data.toolCallCount,"data-turn-process-subagents":e.data.subagentCount,disabled:!a,"aria-expanded":t.hasContent?r:void 0,onClick:e=>{e.currentTarget.focus(),t.setOpen(!r)},children:[/* @__PURE__ */ (0,f.jsxs)(`span`,{className:xr.label,children:[l,c?.map((e,t)=>/* @__PURE__ */ (0,f.jsx)(`span`,{className:e.numeric?xr.durationNumber:void 0,children:e.text},t))]}),a&&/* @__PURE__ */ (0,f.jsx)(p.IconChevronDownOutlineRegular,{className:xr.chevron})]})]})});function Cr(e,t,n,r){let[i,a]=(0,d.useState)({}),[o,s]=(0,d.useState)(),[c,l]=(0,d.useState)(0),u=JSON.stringify(t.filter(e=>n.has(e.path)&&e.hunks===void 0).map(e=>[e.path,e.revision]));return(0,d.useEffect)(()=>{let t=JSON.parse(u).filter(([e,t])=>i[e]?.revision!==t);if(!r||t.length===0)return;let n=!0;return s(void 0),Promise.all(t.map(async([t,n])=>[t,{revision:n,diffs:(await r(e,t)).filter(e=>e.path===t)}])).then(e=>{n&&a(t=>({...t,...Object.fromEntries(e)}))},e=>{n&&s(e instanceof Error?e.message:String(e))}),()=>{n=!1}},[e,u,r,i,c]),{diffs:e=>e.hunks??(i[e.path]?.revision===e.revision?i[e.path]?.diffs:void 0),error:o,retry:()=>l(e=>e+1)}}let wr=`@deepseek-ai/dsh-client-ui-chat/TurnChangesCard.module.css`;if(typeof document<`u`&&document.querySelector(`style[data-plugin-css=`+JSON.stringify(wr)+`]`)===null){let e=document.createElement(`style`);e.dataset.plugin=`@deepseek-ai/dsh-client-ui-chat`,e.dataset.pluginCss=wr,e.textContent=`.IG8hNq_card{border:1px solid var(--dsw-alias-border-l2);corner-shape:round;color:var(--dsw-alias-label-primary);font-size:calc(var(--dsh-content-font-size-secondary,13px) + 2px);--dsh-change-stat-font-size:calc(var(--dsh-content-font-size-secondary,13px) + 1px);--dsw-alias-state-success-primary:var(--dsw-alias-file-diff-added-marker);--dsw-alias-state-error-primary:var(--dsw-alias-file-diff-deleted-marker);border-radius:12px;margin:8px 0;line-height:20px;overflow:hidden}.IG8hNq_header{align-items:center;gap:12px;padding:12px;display:flex}.IG8hNq_icon{corner-shape:round;background:color-mix(in srgb, var(--dsw-alias-label-primary) 4%, transparent);width:44px;height:44px;color:var(--dsw-alias-label-secondary);border-radius:12px;flex:none;place-items:center;display:grid}.IG8hNq_text{flex-direction:column;flex:auto;gap:2px;min-width:0;display:flex}.IG8hNq_title{text-overflow:ellipsis;white-space:nowrap;font-weight:600;overflow:hidden}.IG8hNq_review,.IG8hNq_fileHead,.IG8hNq_more{color:inherit;font:inherit;text-align:left;cursor:pointer;background:0 0;border:0}.IG8hNq_review{border:1px solid var(--dsw-alias-border-l2);corner-shape:round;font-size:var(--dsh-content-font-size,14px);white-space:nowrap;border-radius:12px;flex:none;padding:4px 8px;font-weight:500}.IG8hNq_review:hover,.IG8hNq_fileHead:hover,.IG8hNq_more:hover{background:var(--dsw-alias-interactive-bg-hover)}.IG8hNq_review:focus-visible,.IG8hNq_fileHead:focus-visible,.IG8hNq_more:focus-visible{outline:2px solid var(--dsw-alias-label-tertiary);outline-offset:-2px}.IG8hNq_files{border-top:1px solid var(--dsw-alias-border-l2);margin:0;padding:0;list-style:none}.IG8hNq_fileHead{justify-content:space-between;align-items:center;gap:12px;width:100%;min-height:40px;padding:8px 12px;display:flex}.IG8hNq_fileHead .IG8hNq_path{min-width:0;font-size:inherit;--dsw-alias-label-tertiary:var(--dsw-alias-label-secondary);flex:1}.IG8hNq_diff{padding:0 12px 12px}.IG8hNq_file:first-child .IG8hNq_diff:first-child{padding-top:12px}.IG8hNq_more{align-items:center;gap:8px;width:100%;min-height:40px;padding:8px 12px;font-weight:500;display:flex}.IG8hNq_chevron{flex:none;transition:transform .15s}.IG8hNq_chevron[data-open=true]{transform:rotate(180deg)}@media (width<=480px){.IG8hNq_header{grid-template-columns:36px minmax(0,1fr);gap:8px;display:grid}.IG8hNq_icon{width:36px;height:36px}.IG8hNq_review{grid-column:2;justify-self:start}}`,document.head.appendChild(e)}var q={card:`IG8hNq_card`,chevron:`IG8hNq_chevron`,diff:`IG8hNq_diff`,file:`IG8hNq_file`,fileHead:`IG8hNq_fileHead`,files:`IG8hNq_files`,header:`IG8hNq_header`,icon:`IG8hNq_icon`,more:`IG8hNq_more`,path:`IG8hNq_path`,review:`IG8hNq_review`,text:`IG8hNq_text`,title:`IG8hNq_title`};let Tr=(0,d.memo)(function({nodeStore:e,turn:t,t:n,useProjection:r,loadTurnDiffs:i}){let a=S(e,t,r),[o,s]=(0,d.useState)(()=>/* @__PURE__ */ new Set),[c,l]=(0,d.useState)(!1),u=Cr(t,a,o,i),m=(0,d.useMemo)(()=>({codeLabel:n(`diff.code`),wrapLabel:n(`diff.wrap`),unwrapLabel:n(`diff.unwrap`),copy:n(`diff.copy`),copied:n(`diff.copied`),collapseAria:n(`diff.collapseAria`),expandAria:e=>n(`diff.expandAria`,{count:e}),collapse:n(`diff.collapse`),expand:e=>n(`diff.expand`,{count:e})}),[n]);if(a.length===0)return null;let{added:h,removed:g}=C(a),[_]=a,y=a.length===1&&_!==void 0?n(`chat.fileEdited`,{name:w(_.path)}):n(`chat.filesEdited`,{count:a.length}),b=a.some(e=>o.has(e.path)),x=c?a:a.slice(0,3),T=a.length-x.length;return/* @__PURE__ */ (0,f.jsxs)(`section`,{className:q.card,"data-turn-changes":t,children:[/* @__PURE__ */ (0,f.jsxs)(`div`,{className:q.header,children:[/* @__PURE__ */ (0,f.jsx)(`span`,{className:q.icon,"aria-hidden":`true`,children:/* @__PURE__ */ (0,f.jsx)(p.IconFileDiffOutlineRegular,{size:24})}),/* @__PURE__ */ (0,f.jsxs)(`span`,{className:q.text,children:[/* @__PURE__ */ (0,f.jsx)(`span`,{className:q.title,title:y,children:y}),/* @__PURE__ */ (0,f.jsx)(v,{added:h,removed:g})]}),/* @__PURE__ */ (0,f.jsx)(`button`,{type:`button`,className:q.review,"aria-expanded":b,onClick:()=>{s(new Set(b?[]:a.map(e=>e.path))),b||l(!0)},children:n(b?`chat.hideChanges`:`chat.viewChanges`)})]}),(a.length>1||b)&&/* @__PURE__ */ (0,f.jsxs)(`ul`,{className:q.files,children:[x.map(e=>{let t=u.diffs(e);return/* @__PURE__ */ (0,f.jsxs)(`li`,{className:q.file,children:[a.length>1&&/* @__PURE__ */ (0,f.jsxs)(`button`,{type:`button`,className:q.fileHead,"aria-expanded":o.has(e.path),onClick:()=>{s(t=>{let n=new Set(t);return n.has(e.path)?n.delete(e.path):n.add(e.path),n})},children:[/* @__PURE__ */ (0,f.jsx)(p.PathLabel,{path:e.path,className:q.path}),/* @__PURE__ */ (0,f.jsx)(v,{added:e.added,removed:e.removed})]}),o.has(e.path)&&/* @__PURE__ */ (0,f.jsx)(`div`,{className:q.diff,children:t===void 0?u.error?/* @__PURE__ */ (0,f.jsxs)(`div`,{role:`alert`,children:[u.error,` `,/* @__PURE__ */ (0,f.jsx)(`button`,{type:`button`,onClick:u.retry,children:n(`chat.retryDiff`)})]}):/* @__PURE__ */ (0,f.jsx)(`span`,{role:`status`,children:n(`chat.loadingDiff`)}):/* @__PURE__ */ (0,f.jsx)(p.DiffBlock,{diffs:[...t],labels:m,maxLines:1/0})})]},e.path)}),a.length>3&&/* @__PURE__ */ (0,f.jsx)(`li`,{children:/* @__PURE__ */ (0,f.jsxs)(`button`,{type:`button`,className:q.more,"aria-expanded":c,onClick:()=>l(e=>!e),children:[T>0?n(`chat.showMoreFiles`,{count:T}):n(`chat.collapseFiles`),/* @__PURE__ */ (0,f.jsx)(p.IconChevronDownOutlineRegular,{size:16,className:q.chevron,"data-open":c})]})})]})]})});function Er(e){return e.flatMap(e=>e.kind===`text`?[e.text]:[]).join(``)}function Dr(e){return e.some(e=>e.kind===`reasoning`||e.kind===`tool-call`?!1:e.kind!==`text`||e.text.trim()!==``)}let Or=`@deepseek-ai/dsh-client-ui-chat/TurnTailNodeView.module.css`;if(typeof document<`u`&&document.querySelector(`style[data-plugin-css=`+JSON.stringify(Or)+`]`)===null){let e=document.createElement(`style`);e.dataset.plugin=`@deepseek-ai/dsh-client-ui-chat`,e.dataset.pluginCss=Or,e.textContent=`.ONXMya_root{flex-direction:column;gap:16px;display:flex}.ONXMya_actions{margin-top:4px;margin-left:-6px}`,document.head.appendChild(e)}var kr={actions:`ONXMya_actions`,root:`ONXMya_root`};function Ar(e,t,n){let r=e.locations.getTurn(t);for(let t=r.length-1;t>=0;t--){let i=e.nodes.get(r[t]);if(!(i===void 0||i.kind===`turn-tail`||i.kind===`turn-process`||n&&i.kind===`turn-max-tokens`))return i}}let jr=(0,d.memo)(function({node:e,openFile:t,forkAt:n,loadTurnDiffs:r,renderSlot:i,t:a,useChat:o,useSession:s,useProjection:c}){let l=s(e=>e.openState===`open`),u=(0,d.useRef)(!1),[p,m]=(0,d.useState)(!1),[h,g]=(0,d.useState)(),_=e.data,v=o(e=>e.nodes),y=o(e=>(Ar(e,_.turn,!0)?.anchorSeq??-1)>(_.closing?.finalNode.seq??_.seq)),b=o(e=>{if(e.timeline.turnOrder.at(-1)!==_.turn)return!1;let t=Ar(e,_.turn,!1),n=t?.kind===`assistant-step`?t.data.blocks.findLast(e=>e.kind!==`text`&&e.kind!==`reasoning`||e.text.trim()!==``):void 0;return n!==void 0&&Dr([n])}),x=e.location.kind===`turn`||e.location.kind===`step`?e.location.turn:void 0,S=Ue(c,x?.turn,`end`);if(x===void 0)return null;let C=_.closing,w=i(`conversation.chat.turnTail`,{turn:x,seq:C?.finalNode.seq??_.seq,openFile:t});if(C===null)return w===null?null:/* @__PURE__ */ (0,f.jsx)(`div`,{className:kr.root,"data-turn-tail":_.turn,children:w});let T=C.finalNode.messageId,E=T===void 0?null:i(`conversation.chat.assistant-actions`,{messageId:T});return/* @__PURE__ */ (0,f.jsxs)(`div`,{className:kr.root,"data-turn-tail":_.turn,"data-actions-reveal":b?`always`:`hover`,children:[/* @__PURE__ */ (0,f.jsx)(Tr,{nodeStore:v,turn:_.turn,t:a,useProjection:c,loadTurnDiffs:r}),w,/* @__PURE__ */ (0,f.jsx)(He,{text:Er(C.blocks),time:S,clock:`end`,onBranch:()=>{!u.current&&l&&(u.current=!0,m(!0),g(void 0),n(_.seq).catch(e=>{g(e instanceof Error?e.message:String(e))}).finally(()=>{u.current=!1,m(!1)}))},branchUnavailable:!l||p||_.branchUnavailable||y,className:kr.actions,extraActions:E,t:a}),h!==void 0&&/* @__PURE__ */ (0,f.jsx)(`p`,{role:`alert`,children:a(`message.branchFailed`,{message:h})})]})});function Mr(e){return typeof e==`object`&&e&&!Array.isArray(e)?e:{}}function Nr(e,t){return typeof e[t]==`string`?e[t]:``}function Pr(e){let t=Mr(e.source),n=Nr(t,`kind`),r=`message.trigger.request`,i=`request`;switch(n){case`goal`:r=`message.trigger.goal`,i=`goal`;break;case`agent-message`:r=`message.trigger.agent`,i=`agent`;break;case`team-message`:r=`message.trigger.team`,i=`team`;break;case`subagent-settled`:r=`message.trigger.subagent`,i=`subagent`;break;case`webhook`:{let e=Nr(t,`provider`)===`github`;r=e?`message.trigger.github`:`message.trigger.webhook`,i=e?`github`:`webhook`;break}case`schedule`:r=`message.trigger.schedule`,i=`schedule`;break;case`tool-jobs`:r=`message.trigger.job`,i=`job`;break;case`cordis-host-runner`:r=`message.trigger.plugin`,i=`plugin`}return{title:r,icon:i}}let Fr=`@deepseek-ai/dsh-client-ui-chat/TurnTriggerNodeView.module.css`;if(typeof document<`u`&&document.querySelector(`style[data-plugin-css=`+JSON.stringify(Fr)+`]`)===null){let e=document.createElement(`style`);e.dataset.plugin=`@deepseek-ai/dsh-client-ui-chat`,e.dataset.pluginCss=Fr,e.textContent=`.u7aAgG_root{border:.5px solid var(--dsw-alias-border-l1);border-radius:var(--dsw-radius-xl);background:var(--dsw-alias-turn-trigger-bg,var(--dsw-alias-markdown-code-block));min-width:0;transition:background-color .1s}.u7aAgG_root:hover{background:var(--dsw-alias-turn-trigger-bg-hover,var(--dsw-alias-interactive-bg-hover))}.u7aAgG_header{width:100%;color:var(--dsw-alias-label-tertiary);font:inherit;text-align:left;cursor:pointer;background:0 0;border:0;align-items:center;gap:10px;padding:12px 16px;transition:color .1s;display:flex}.u7aAgG_header:hover{color:var(--dsw-alias-label-secondary)}.u7aAgG_icon{color:inherit;flex:none;display:inline-flex}.u7aAgG_title{font-size:var(--dsh-content-font-size,14px);flex:none}.u7aAgG_time{color:inherit;font:var(--dsw-font-xxs-12);flex:none;margin-left:auto}.u7aAgG_chevron,.u7aAgG_openChevron{color:inherit;flex:none}.u7aAgG_openChevron{transform:rotate(180deg)}.u7aAgG_body{padding:0 16px 12px 40px}.u7aAgG_explanation{color:var(--dsw-alias-label-secondary);font:var(--dsw-font-xxs-12);margin:8px 0}.u7aAgG_content{white-space:pre-wrap;overflow-wrap:anywhere;max-height:240px;font:var(--dsw-font-xxs-12);overflow:auto}@media (prefers-reduced-motion:reduce){.u7aAgG_root,.u7aAgG_header{transition:none}}`,document.head.appendChild(e)}var Ir={body:`u7aAgG_body`,chevron:`u7aAgG_chevron`,content:`u7aAgG_content`,explanation:`u7aAgG_explanation`,header:`u7aAgG_header`,icon:`u7aAgG_icon`,openChevron:`u7aAgG_openChevron`,root:`u7aAgG_root`,time:`u7aAgG_time`,title:`u7aAgG_title`};let Lr={request:p.IconContextInjectionOutlineRegular,goal:p.IconGoalOutlineRegular,agent:p.IconPaperPlaneOutlineRegular,team:p.IconAgentPresetOutlineRegular,subagent:p.IconAgentPresetOutlineRegular,github:p.IconBranchOutlineRegular,webhook:p.IconGlobeOutlineRegular,schedule:p.IconClockOutlineRegular,job:p.IconQueueOutlineRegular,plugin:p.IconCordisPluginOutlineRegular};function Rr({node:e,t}){let[n,r]=(0,d.useState)(!1),i=(0,d.useId)(),a=Pr(e.data),o=Lr[a.icon],s=new Date(e.data.time),c=Re(e.data.time,t);return/* @__PURE__ */ (0,f.jsxs)(`section`,{className:Ir.root,"data-turn-trigger":!0,children:[/* @__PURE__ */ (0,f.jsxs)(`button`,{className:Ir.header,type:`button`,"aria-expanded":n,"aria-controls":i,onClick:()=>{r(!n)},children:[/* @__PURE__ */ (0,f.jsx)(`span`,{className:Ir.icon,"aria-hidden":!0,children:/* @__PURE__ */ (0,f.jsx)(o,{size:14})}),/* @__PURE__ */ (0,f.jsx)(`span`,{className:Ir.title,children:t(a.title)}),/* @__PURE__ */ (0,f.jsx)(`time`,{className:Ir.time,dateTime:s.toISOString(),children:c}),/* @__PURE__ */ (0,f.jsx)(p.IconChevronDownOutlineRegular,{size:12,className:n?Ir.openChevron:Ir.chevron})]}),n&&/* @__PURE__ */ (0,f.jsxs)(`div`,{id:i,className:Ir.body,children:[/* @__PURE__ */ (0,f.jsx)(`p`,{className:Ir.explanation,children:t(`message.trigger.explanation`)}),/* @__PURE__ */ (0,f.jsx)(`div`,{className:Ir.content,children:/* @__PURE__ */ (0,f.jsx)(Ee,{content:e.data.content,source:e.data.source,t})})]})]})}function zr(e,t){e.slots.inject(`conversation.chat.node`,()=>e.slots.register({name:`conversation.chat.node`,key:`user`,locale:K},nt)),e.slots.inject(`conversation.chat.node`,()=>e.slots.register({name:`conversation.chat.node`,key:`steering`,locale:K},nt)),e.slots.inject(`conversation.chat.node`,()=>e.slots.register({name:`conversation.chat.node`,key:`context`,locale:K},it)),e.slots.inject(`conversation.chat.node`,()=>e.slots.register({name:`conversation.chat.node`,key:`turn-trigger`,locale:K},Rr)),e.slots.inject(`conversation.chat.node`,()=>e.slots.register({name:`conversation.chat.node`,key:`system-prompt`,locale:K},yr)),e.slots.inject(`conversation.chat.node`,()=>e.slots.register({name:`conversation.chat.node`,key:`assistant-step`,locale:K,inject:()=>({hooks:{presentation:t}})},lr)),e.slots.inject(`conversation.chat.node`,()=>e.slots.register({name:`conversation.chat.node`,key:`command`,locale:K,children:{"conversation.chat.commandview":{kind:`keyed`,scope:`session`}}},gr)),e.slots.inject(`conversation.chat.node`,()=>e.slots.register({name:`conversation.chat.node`,key:`manual-compaction`,locale:K},_r)),e.slots.inject(`conversation.chat.node`,()=>e.slots.register({name:`conversation.chat.node`,key:`compaction`,locale:K},at)),e.slots.inject(`conversation.chat.node`,()=>e.slots.register({name:`conversation.chat.node`,key:`model-retry`,locale:K},ot)),e.slots.inject(`conversation.chat.node`,()=>e.slots.register({name:`conversation.chat.node`,key:`turn-error`,locale:K},st)),e.slots.inject(`conversation.chat.node`,()=>e.slots.register({name:`conversation.chat.node`,key:`turn-max-tokens`,locale:K},ct)),e.slots.inject(`conversation.chat.node`,()=>e.slots.register({name:`conversation.chat.node`,key:`turn-process`,locale:K},Sr)),e.slots.inject(`conversation.chat.node`,()=>e.slots.register({name:`conversation.chat.node`,key:`turn-tail`,locale:K,children:{"conversation.chat.turnTail":{kind:`list`,scope:`session`},"conversation.chat.assistant-actions":{kind:`list`,scope:`session`}}},jr)),e.slots.inject(`conversation.chat.node`,()=>e.slots.register({name:`conversation.chat.node`,key:`unknown`,locale:K},lt))}let Br={interruptedAssistant:-.9,interruptedFollowup:-.8,processControl:-.1,maxTokensNotice:.05,finalizedFollowup:.1};function Vr(e){return e.start?.location??e.matches[0]?.location??{kind:`unresolved`}}function J(e,t,n,r,i={}){return{key:e.key,kind:t,id:e.id,target:`chat`,anchorSeq:n,location:i.location??Vr(e),visibility:i.visibility??`visible`,data:r}}function Hr(e){return typeof e==`object`&&e&&!Array.isArray(e)?e:null}function Ur(e,t){let n=e[t];return typeof n==`string`&&n.length>0?n:null}function Wr(e,t,n){let r=e[t];if(!Array.isArray(r))return[];let i=[];for(let e of r){let t=Hr(e),r=t===null?null:Ur(t,n);r!==null&&!i.includes(r)&&i.push(r)}return i}function Gr(e){return e.length>0?e.join(`, `):null}let Kr=[`instructions`,`catalog`,`snapshot`,`notice`,`relay`,`recall`];function qr(e){let t=Hr(e),n=t===null?null:Ur(t,`form`);return n!==null&&Kr.includes(n)?n:null}function Jr(e){let t=Hr(e),n=t===null?null:Ur(t,`kind`);if(t===null||n===null)return{role:`inject`,label:null};switch(n){case`session-reference`:return{role:`recall`,label:Gr(Wr(t,`references`,`label`))??n};case`agent-instructions`:return{role:`inject`,label:Gr(Wr(t,`changes`,`path`))??n};case`skill-invocation`:return{role:`inject`,label:Ur(t,`name`)??n};default:return{role:`inject`,label:n}}}function Yr(e){let t=Hr(e);return t===null||Ur(t,`kind`)!==`session-reference`?[]:Wr(t,`references`,`label`)}function Xr(e){let t=Hr(e);return t===null||Ur(t,`kind`)!==`skill-invocation`?null:Ur(t,`name`)}function Zr(e){return e.map(Qr)}function Qr(e){switch(e.type){case`text`:return{kind:`text`,text:e.text};case`reasoning`:return{kind:`reasoning`,text:e.text};case`image`:return{kind:`image`,attachment:e.attachment};case`tool-call`:return{kind:`tool-call`,callId:String(e.id),name:e.name,argsRaw:e.arguments};default:return{kind:`other`,block:e}}}function $r(e){switch(e){case`text`:return{kind:`text`,text:``};case`reasoning`:return{kind:`reasoning`,text:``};case`tool-call`:return{kind:`tool-call`,callId:``,name:``,argsRaw:``};default:return{kind:`other`,block:null}}}function ei(e){if(typeof e!=`object`||!e)return{message:String(e)};let t=e,n=typeof t.code==`string`?t.code:void 0;return n===`AUTH`?{code:n,message:``}:{...n===void 0?{}:{code:n},message:typeof t.message==`string`?t.message:JSON.stringify(e)}}function ti(e){switch(e.type){case`text-delta`:case`reasoning-delta`:return e.text!==``;case`tool-call-delta`:return e.argumentsDelta!==``||e.name!==void 0;default:return!1}}function ni(e,t){return{turn:e,step:t,blocks:[],visibleByIndex:[],visibleBlocks:0,firstVisibleSeq:void 0,firstVisibleTime:void 0,firstTokenTime:void 0,final:void 0,usage:void 0}}function ri(e){return e.filter(e=>e!==void 0)}function ii(e){return e===void 0||e.kind===`tool-call`?!1:e.kind===`text`||e.kind===`reasoning`?e.text.trim()!==``:!0}function ai(e){return e.some(ii)}function oi(e){return e.some(e=>e.kind===`text`||e.kind===`reasoning`?e.text.trim()!==``:!0)}function si(e){return{...ni(e.turn,e.step),firstTokenTime:e.firstTokenTime}}function ci(e,t,n,r){if(t.type===`tool-call-delta`){let n=e.blocks[t.index];if(n?.kind===`tool-call`&&n.callId!==``&&(t.name===void 0||t.name===n.name)&&(e.firstTokenTime!==void 0||!ti(t)))return e}let i=[...e.blocks],a=-1,o=!1,s=!1;switch(t.type){case`block-start`:a=t.index,o=e.visibleByIndex[t.index]===!0,i[t.index]=$r(t.blockType),s=ii(i[t.index]);break;case`text-delta`:{let n=i[t.index];a=t.index,o=e.visibleByIndex[t.index]===!0,i[t.index]={kind:`text`,text:(n?.kind===`text`?n.text:``)+t.text},s=n?.kind===`text`&&o||t.text.trim()!==``;break}case`reasoning-delta`:{let n=i[t.index];a=t.index,o=e.visibleByIndex[t.index]===!0,i[t.index]={kind:`reasoning`,text:(n?.kind===`reasoning`?n.text:``)+t.text},s=n?.kind===`reasoning`&&o||t.text.trim()!==``;break}case`tool-call-delta`:{let n=i[t.index];a=t.index,o=e.visibleByIndex[t.index]===!0,i[t.index]={kind:`tool-call`,callId:(n?.kind===`tool-call`?n.callId:``)||String(t.id),name:t.name??(n?.kind===`tool-call`?n.name:``),argsRaw:n?.kind===`tool-call`?n.argsRaw:``};break}case`block-end`:a=t.index,o=e.visibleByIndex[t.index]===!0,i[t.index]=Qr(t.block),s=ii(i[t.index]);break;case`usage`:return{...e,usage:t.usage};default:return e}let c=e.visibleBlocks-Number(o)+Number(s),l=e.visibleByIndex;if(o!==s){let e=[...l];e[a]=s,l=e}let u=ti(t);return{...e,blocks:i,visibleByIndex:l,visibleBlocks:c,...c>0&&e.firstVisibleSeq===void 0?{firstVisibleSeq:n,firstVisibleTime:r}:{},...u&&e.firstTokenTime===void 0?{firstTokenTime:r}:{}}}function li(e,t,n){let r=Zr(n.data.message.content),i=r.map(ii);return{...e,blocks:r,visibleByIndex:i,visibleBlocks:i.reduce((e,t)=>e+Number(t),0),final:t,usage:n.data.usage}}function ui(e){if(e.kind===`step`&&e.step.status===`closed`&&e.step.end!==void 0)return e.step.end;if((e.kind===`step`||e.kind===`turn`)&&e.turn.status===`closed`&&e.turn.end!==void 0)return e.turn.end}function di(e,t){let n=e.final;if(n?.event.type===`assistant/message`){let r=n.event;return{kind:`assistant`,seq:r.seq,messageId:r.data.message.id,time:r.time,turn:e.turn,step:e.step,blocks:Zr(r.data.message.content),usage:r.data.usage,timing:{stepStartTime:t.start?.event.time??null,firstTokenTime:e.firstTokenTime??null,completedTime:r.time},...r.data.interrupted===!0?{interrupted:!0}:{}}}let r=t.start?.location??t.matches.at(-1)?.location,i=r===void 0?void 0:ui(r);if(i===void 0)return;let a=ri(e.blocks);if(oi(a))return{kind:`assistant`,seq:i.seq+Br.interruptedAssistant,time:i.time,turn:e.turn,step:e.step,blocks:a,interrupted:!0}}function fi(e){let t;for(let n of e.matches)n.event.type===`assistant/live-chunk`?(t??=ni(n.event.data.turn,n.event.data.step),t=ci(t,n.event.data.chunk,n.event.seq,n.event.time)):n.event.type===`assistant/message`?(t??=ni(n.event.data.turn,n.event.data.step),t=li(t,n,n.event)):n.event.type===`llm/retry`&&t!==void 0&&(t=si(t));return t}function pi(e){let t=e.state??fi(e);if(t===void 0)return;let n=di(t,e),r=n?.blocks??ri(t.blocks),i=n===void 0?t.visibleBlocks>0:ai(r),a=n?.interrupted===!0?`interrupted`:n===void 0?`running`:`settled`,o=(n?.interrupted===!0?n.seq:t.firstVisibleSeq??n?.seq)??e.matches[0]?.event.seq??0,s=n?.time??t.firstVisibleTime??e.matches[0]?.event.time??0;return{anchorSeq:o,visible:i,settled:n,data:{status:a,turn:t.turn,step:t.step,blocks:r,time:s,...t.usage===void 0?{}:{usage:t.usage},...n===void 0?{}:{finalNode:n}}}}function mi(e){let t=e.start?.location??e.matches.at(-1)?.location;return t?.kind===`step`?t.step.data.get(`assistant-step`):void 0}let hi={kind:`assistant-step`,target:`chat`,match:e=>e.type===`step/start`?{id:`${e.data.turn}:${e.data.step}`,role:`start`}:e.type===`assistant/live-chunk`||e.type===`assistant/message`&&e.surfaceOp===`append`||e.type===`llm/retry`?{id:`${e.data.turn}:${e.data.step}`,role:`update`}:null,start:(e,t)=>{if(t.event.type!==`step/start`)throw Error(`assistant-step start requires step/start`);return ni(t.event.data.turn,t.event.data.step)},update:(e,t)=>t.event.type===`assistant/live-chunk`?ci(e.state,t.event.data.chunk,t.event.seq,t.event.time):t.event.type===`assistant/message`?li(e.state,t,t.event):t.event.type===`llm/retry`?si(e.state):e.state,publication:e=>{if(e.event.type===`step/start`)return`none`;if(e.event.type!==`assistant/live-chunk`)return`immediate`;let t=e.event.data.chunk.type;return t===`usage`||t===`finish`?`none`:`animation-frame`},buildLocationData:(e,t)=>{if(t!==`step`)return null;let n=pi(e);return n===void 0?null:{kind:`step`,turn:n.data.turn,step:n.data.step,key:`assistant-step`,value:n.data}},buildViewNode:e=>{let t=e.current.get(`chat`),n=e.state??fi(e),r=mi(e);if(n===void 0||r===void 0)return t==null?null:{...t,visibility:`hidden`};let i=r.finalNode,a=i===void 0?n.visibleBlocks>0:ai(r.blocks);return i===void 0&&!a&&t==null?null:J(e,`assistant-step`,(i?.interrupted===!0?i.seq:n.firstVisibleSeq??i?.seq)??e.matches[0]?.event.seq??0,r,{visibility:i?.interrupted===!0||a?`visible`:`hidden`})}};function gi(e){let t=hi.match.bind(hi);e.uiConversation.events.register({...hi,match:{"step/start":t,"assistant/live-chunk":t,"assistant/message":t,"llm/retry":t}})}function _i(e){return`kind`in e}function vi(e){return!_i(e)}function yi(e){return e.visibility===`visible`&&e.kind!==`system-prompt`&&(e.kind!==`context`||e.data.content.some(e=>e.type===`tool-addition`||e.type===`tool-removal`))&&(e.kind!==`command`||e.data.name!==`permission`)}function bi(e,t){let n=``,r=!1;for(let i of e){if(n.length>=t*2){r=!0;break}let e=i.length>t*2,a=e?i.slice(0,t*2):i;if(n+=n===``?a:` ${a}`,e){r=!0;break}}let i=n.replace(/\s+/g,` `).trim();return i.length>t-1?`${i.slice(0,t-1).trimEnd()}…`:r?`${i}…`:i}function xi(e){return e.kind===`user`?bi(e.data.content.flatMap(e=>e.type===`text`?[e.text]:[]),50):``}function Si(e){return e.kind===`assistant-step`?bi(e.data.blocks.flatMap(e=>e.kind===`text`?[e.text]:[]),120):``}function Ci(e,t){return e===void 0||t===void 0?e===t:e.turn===t.turn&&e.anchorKey===t.anchorKey&&e.prompt===t.prompt&&e.response===t.response}function wi(e,t,n){let r=t.getTurn(e).map(e=>n.get(e)).filter(e=>e!==void 0&&yi(e)),i=r.find(e=>e.kind===`user`),a=i??r[0];if(a===void 0)return;let o=r.findLast(e=>Si(e)!==``);return{turn:e,anchorKey:a.key,prompt:i===void 0?``:xi(i),response:o===void 0?``:Si(o)}}function Ti(e){let t=e?.location;return t?.kind===`turn`||t?.kind===`step`?t.turn.turn:void 0}function Ei(e,t){return e===t||e!==void 0&&t!==void 0&&e.spec===t.spec&&e.turn===t.turn&&e.turnStarted===t.turnStarted&&e.turnClosed===t.turnClosed&&e.hasExternalProcess===t.hasExternalProcess&&e.hasInterleavedInput===t.hasInterleavedInput&&e.compactAnswer===t.compactAnswer}function Di(e,t,n){let r=t.getTurn(e),i=r.map(e=>n.get(e)).find(e=>e?.kind===`turn-process`);if(i===void 0)return;let a=i.data,o=i.location;if(o.kind!==`turn`&&o.kind!==`step`)return;let s;for(let e of r){let t=n.get(e);(t?.kind===`user`||t?.kind===`steering`||t?.kind===`turn-trigger`)&&(a.controlAnchorSeq===o.turn.start?.seq||t.anchorSeq<a.controlAnchorSeq)&&(s=Math.max(s??t.anchorSeq,t.anchorSeq))}let c=!1,l=!1,u=!0;for(let e of r){let t=n.get(e);t!==void 0&&yi(t)&&t.kind!==`turn-process`&&((t.kind===`user`||t.kind===`steering`||t.kind===`turn-trigger`)&&(s===void 0||t.anchorSeq>s)&&(l=!0,(a.answerAnchorSeq===null||t.anchorSeq<a.answerAnchorSeq)&&(u=!1)),!(ut.has(t.kind)||t.anchorSeq<a.processStartSeq)&&(t.kind!==`assistant-step`||a.answerStep===null||t.data.step!==a.answerStep)&&(c=!0))}return{turn:e,spec:a,turnStarted:o.turn.start!==void 0,turnClosed:o.turn.status===`closed`,hasExternalProcess:c,hasInterleavedInput:l,compactAnswer:u}}var Oi=class{presentations=/* @__PURE__ */ new Map;get(e){let t=Ti(e);return t===void 0?void 0:this.presentations.get(t)}replace(e,t,n){let r=/* @__PURE__ */ new Set;for(let t of e){let e=Ti(n.get(t));e!==void 0&&r.add(e)}let i=/* @__PURE__ */ new Set;for(let e of/* @__PURE__ */ new Set([...this.presentations.keys(),...r]))this.set(e,r.has(e)?Di(e,t,n):void 0)&&i.add(e);return i}update(e,t,n){let r=/* @__PURE__ */ new Set;for(let i of e)this.set(i,Di(i,t,n))&&r.add(i);return r}set(e,t){return!Ei(this.presentations.get(e),t)&&(t===void 0?this.presentations.delete(e):this.presentations.set(e,t),!0)}};let ki=[],Ai=[],ji=[],Mi=[];function Ni(e,t){return e.length===t.length&&e.every((e,n)=>e===t[n])}function Pi(e,t,n){let r=e.get(t);return r===void 0&&(r=n(),e.set(t,r)),r}var Fi=class{read;label;listeners=/* @__PURE__ */ new Set;published;constructor(e,t){this.read=e,this.label=t,this.published=e()}getSnapshot=()=>this.read();subscribe=e=>(this.listeners.add(e),()=>{this.listeners.delete(e)});publish(){let e=this.getSnapshot();this.published!==e&&(this.published=e,(0,m.notifySubscribers)(this.listeners,this.label))}},Ii=class{nodes=/* @__PURE__ */ new Map;current=Mi;dirty=!1;observable;source(){return this.observable??=new Fi(()=>this.read(),`[ui-chat] turn kind nodes`)}set(e){let t=this.nodes.get(e.key);this.nodes.set(e.key,e),(t===void 0||t.data!==e.data||t.anchorSeq!==e.anchorSeq)&&(this.dirty=!0)}delete(e){this.nodes.delete(e),this.dirty=!0}publish(){this.observable?.publish()}read(){return this.dirty&&=(this.current=[...this.nodes.values()].sort((e,t)=>e.anchorSeq-t.anchorSeq).map(e=>e.data),!1),this.current}},Li=class{byKey=/* @__PURE__ */ new Map;turnProcesses=new Oi;sources=/* @__PURE__ */ new Map;processSources=/* @__PURE__ */ new Map;dirtyKeys=/* @__PURE__ */ new Set;dirtyProcessKeys=/* @__PURE__ */ new Set;turnKinds=/* @__PURE__ */ new Map;dirtyTurnKinds=/* @__PURE__ */ new Set;valuesCache=Mi;valuesDirty=!1;get(e){return this.byKey.get(e)}source(e){return Pi(this.sources,e,()=>new Fi(()=>this.get(e),`[ui-chat] node source ${e}`))}turnDataSource(e,t){return this.turnKind(e,t).source()}turnKind(e,t){return Pi(Pi(this.turnKinds,e,()=>/* @__PURE__ */ new Map),t,()=>new Ii)}updateTurnKind(e,t){let n=e===void 0?void 0:Hi(e.location).turn,r=t===void 0?void 0:Hi(t.location).turn;if(e!==void 0&&n!==void 0&&(n!==r||e.kind!==t?.kind)){let t=this.turnKind(n,e.kind);t.delete(e.key),this.dirtyTurnKinds.add(t)}if(t!==void 0&&r!==void 0){let e=this.turnKind(r,t.kind);e.set(t),this.dirtyTurnKinds.add(e)}}processSource(e){return Pi(this.processSources,e,()=>new Fi(()=>this.process(e),`[ui-chat] node process source ${e}`))}process(e){return this.turnProcesses.get(this.get(e))}values(){return this.valuesDirty&&=(this.valuesCache=[...this.byKey.values()],!1),this.valuesCache}replace(e){let t=new Map(this.byKey);this.byKey.clear();for(let n of e)this.byKey.set(n.key,n),t.get(n.key)!==n&&(this.updateTurnKind(t.get(n.key),n),this.dirtyKeys.add(n.key),this.dirtyProcessKeys.add(n.key)),t.delete(n.key);for(let e of t.keys())this.updateTurnKind(t.get(e),void 0),this.dirtyKeys.add(e),this.dirtyProcessKeys.add(e);this.valuesCache=[...this.byKey.values()],this.valuesDirty=!1}upsert(e){let t=!1;for(let n of e)this.byKey.get(n.key)!==n&&(this.updateTurnKind(this.byKey.get(n.key),n),this.byKey.set(n.key,n),this.dirtyKeys.add(n.key),this.dirtyProcessKeys.add(n.key),t=!0);t&&(this.valuesDirty=!0)}touchProcesses(e,t){for(let n of e)for(let e of t.getTurn(n))this.dirtyProcessKeys.add(e)}replaceProcesses(e,t){this.touchProcesses(this.turnProcesses.replace(e,t,this),t)}updateProcesses(e,t){this.touchProcesses(this.turnProcesses.update(e,t,this),t)}publish(){let e=[...this.dirtyKeys],t=[...this.dirtyProcessKeys],n=[...this.dirtyTurnKinds];this.dirtyKeys.clear(),this.dirtyProcessKeys.clear(),this.dirtyTurnKinds.clear();for(let t of e)this.sources.get(t)?.publish();for(let e of t)this.processSources.get(e)?.publish();for(let e of n)e.publish()}},Ri=class{turns=/* @__PURE__ */ new Map;steps=/* @__PURE__ */ new Map;positions=/* @__PURE__ */ new Map;getTurn(e){return this.turns.get(e)??ki}getStep(e,t){return this.steps.get(Vi(e,t))??ki}getPosition(e){return this.positions.get(e)}rebuild(e,t){let n=/* @__PURE__ */ new Map,r=/* @__PURE__ */ new Map,i=/* @__PURE__ */ new Map,a=/* @__PURE__ */ new Set;for(let[o,s]of e.entries()){let c=t.get(s)?.location;if(c===void 0)continue;let l=Hi(c),u=this.positions.get(s),d={turn:l.turn,previous:e[o-1],next:e[o+1]},f=u!==void 0&&u.turn===d.turn&&u.previous===d.previous&&u.next===d.next;if(i.set(s,f?u:d),f||(u?.turn!==void 0&&a.add(u.turn),d.turn!==void 0&&a.add(d.turn)),l.turn===void 0)continue;let p=n.get(l.turn)??[];if(p.push(s),n.set(l.turn,p),l.step===void 0)continue;let m=Vi(l.turn,l.step),h=r.get(m)??[];h.push(s),r.set(m,h)}for(let[e,t]of this.positions)!i.has(e)&&t.turn!==void 0&&a.add(t.turn);return this.positions=i,this.turns=zi(this.turns,n),this.steps=zi(this.steps,r),[...a]}touch(e){let t=/* @__PURE__ */ new Set,n=/* @__PURE__ */ new Set;for(let r of e){let e=Hi(r.location);e.turn!==void 0&&this.turns.get(e.turn)?.includes(r.key)&&(t.add(e.turn),e.step!==void 0&&n.add(Vi(e.turn,e.step)))}for(let e of t){let t=this.turns.get(e);t!==void 0&&this.turns.set(e,[...t])}for(let e of n){let t=this.steps.get(e);t!==void 0&&this.steps.set(e,[...t])}}};function zi(e,t){let n=/* @__PURE__ */ new Map,r=/* @__PURE__ */ new Set([...e.keys(),...t.keys()]);for(let i of r){let r=e.get(i)??ki,a=t.get(i)??ki,o=Ni(r,a)?r:a;a.length>0&&n.set(i,o)}return n}var Bi=class{current=ji;byTurn=/* @__PURE__ */ new Map;items(){return this.current}rebuild(e,t,n){let r=[],i=/* @__PURE__ */ new Map;for(let a of e.turnOrder){let e=wi(a,t,n);if(e===void 0)continue;let o=this.byTurn.get(a),s=o!==void 0&&Ci(o,e)?o:e;r.push(s),i.set(a,s)}this.byTurn=i,r.length===this.current.length&&r.every((e,t)=>e===this.current[t])||(this.current=r)}touch(e,t,n){if(e.size===0)return;let r=this.current.map(r=>{if(!e.has(r.turn))return r;let i=wi(r.turn,t,n);return i===void 0||Ci(r,i)?r:(this.byTurn.set(r.turn,i),i)});r.some((e,t)=>e!==this.current[t])&&(this.current=r)}};function Vi(e,t){return`${e}:${t}`}function Hi(e){return e.kind===`step`?{turn:e.turn.turn,step:e.step.step}:e.kind===`turn`?{turn:e.turn.turn}:{}}function Ui(e){return e.kind===`turn`||e.kind===`step`?e.turn.status:void 0}function Wi(e,t,n){return n||e===void 0||Ui(e.location)!==Ui(t.location)?!0:e.kind===`turn-process`&&t.kind===`turn-process`?e.data!==t.data:e.kind===`assistant-step`&&t.kind===`assistant-step`&&e.data.step!==t.data.step}function Gi(e){let t=/* @__PURE__ */ new Map;for(let n of e){let e=n;e.kind===`turn-process`&&t.set(e.data.turn,{...t.get(e.data.turn),control:e})}for(let n of e){let e=n,r=e.location;if(r.kind!==`turn`&&r.kind!==`step`)continue;let i=t.get(r.turn.turn)??{},a=i.control?.data.controlAnchorSeq;(e.kind===`user`||e.kind===`turn-trigger`||e.kind===`steering`)&&a!==void 0&&(a===r.turn.start?.seq||e.anchorSeq<a)?t.set(r.turn.turn,{...i,openingInputAnchor:Math.max(i.openingInputAnchor??e.anchorSeq,e.anchorSeq)}):ut.has(e.kind)||t.set(r.turn.turn,{...i,earliestProcessAnchor:Math.min(i.earliestProcessAnchor??e.anchorSeq,e.anchorSeq)})}return t}function Ki(e,t){let n=e,r=n.location;if(r.kind!==`turn`&&r.kind!==`step`)return{anchor:n.anchorSeq,rank:0,originalAnchor:n.anchorSeq};let i=t.get(r.turn.turn);if(i===void 0)return{anchor:n.anchorSeq,rank:0,originalAnchor:n.anchorSeq};let a=i.openingInputAnchor;return a!==void 0&&n.anchorSeq<a&&!ut.has(n.kind)?{anchor:a,rank:2,originalAnchor:n.anchorSeq}:i.control!==void 0&&n.key===i.control.key?a===void 0?{anchor:i.earliestProcessAnchor??n.anchorSeq,rank:-1,originalAnchor:n.anchorSeq}:{anchor:a,rank:1,originalAnchor:n.anchorSeq}:{anchor:n.anchorSeq,rank:0,originalAnchor:n.anchorSeq}}function qi(e){let t=e.filter(e=>yi(e)),n=Gi(t);return t.sort((e,t)=>{let r=Ki(e,n),i=Ki(t,n);return r.anchor-i.anchor||r.rank-i.rank||r.originalAnchor-i.originalAnchor||e.key.localeCompare(t.key)})}function Ji(e){let t=e;return t.kind===`user`||t.kind===`steering`?t.data.seq:void 0}function Yi(e){let t=e;if(t.kind===`context`)return{messageSeq:t.data.seq-1,labels:Yr(t.data.source)}}function Xi(e,t){let n=e;if(n.kind!==`user`&&n.kind!==`steering`)return e;let r=n.data.referenceLabels??ki,i=Object.hasOwn(n.data,`referenceLabels`);if(Ni(r,t)&&i===t.length>0)return e;let a={...n.data};return t.length===0?delete a.referenceLabels:a.referenceLabels=t,{...n,data:a}}var Zi=class{messagesBySeq=/* @__PURE__ */ new Map;labelsByMessageSeq=/* @__PURE__ */ new Map;replace(e){this.messagesBySeq.clear(),this.labelsByMessageSeq.clear();for(let t of e){let e=Ji(t);e!==void 0&&this.messagesBySeq.set(e,t.key);let n=Yi(t);n!==void 0&&n.labels.length>0&&this.labelsByMessageSeq.set(n.messageSeq,n.labels)}return e.map(e=>{let t=Ji(e);return t===void 0?e:Xi(e,this.labelsByMessageSeq.get(t)??ki)})}apply(e,t){let n=new Map(e.map(e=>[e.key,e])),r=/* @__PURE__ */ new Set;for(let t of e){let e=Ji(t);e!==void 0&&(this.messagesBySeq.set(e,t.key),r.add(e));let n=Yi(t);if(n===void 0)continue;let i=this.labelsByMessageSeq.get(n.messageSeq);n.labels.length===0?this.labelsByMessageSeq.delete(n.messageSeq):this.labelsByMessageSeq.set(n.messageSeq,i!==void 0&&Ni(i,n.labels)?i:n.labels),r.add(n.messageSeq)}for(let e of r){let r=this.messagesBySeq.get(e);if(r===void 0)continue;let i=n.get(r)??t.get(r);i!==void 0&&n.set(r,Xi(i,this.labelsByMessageSeq.get(e)??ki))}return[...n.values()]}};function Qi(e,t){let n=e;if(n.kind!==`user`&&n.kind!==`steering`)return e;let r=n.data.skillNames??ki,i=Object.hasOwn(n.data,`skillNames`);if(Ni(r,t)&&i===t.length>0)return e;let a={...n.data};return t.length===0?delete a.skillNames:a.skillNames=t,{...n,data:a}}function $i(e){let t=e;if(t.kind===`user`||t.kind===`steering`)return{key:e.key,seq:e.anchorSeq,kind:`message`,name:null};if(t.kind===`context`){let n=Xr(t.data.source);return n===null?null:{key:e.key,seq:e.anchorSeq,kind:`skill`,name:n}}return{key:e.key,seq:e.anchorSeq,kind:`boundary`,name:null}}function ea(e,t){return e.seq===t.seq&&e.kind===t.kind&&e.name===t.name}var ta=class{entries=/* @__PURE__ */ new Map;sorted=[];replace(e){this.entries.clear(),this.sorted=[];for(let t of e){let e=$i(t);e!==null&&(this.entries.set(e.key,e),this.sorted.push(e))}this.sorted.sort((e,t)=>e.seq-t.seq);let t=/* @__PURE__ */ new Map;for(let e=0;e<this.sorted.length;e++){if(this.sorted[e]?.kind===`boundary`)continue;let n=this.runEnd(e);this.assignRun(e,n,t),e=n}return e.map(e=>Qi(e,t.get(e.key)??ki))}apply(e,t){let n=[];for(let t of e){let e=$i(t),r=this.entries.get(t.key);if(r!==void 0){if(e!==null&&ea(r,e)){e.kind===`message`&&n.push(e.seq);continue}this.remove(r),n.push(r.seq)}e!==null&&(this.insert(e),n.push(e.seq))}if(n.length===0)return e;let r=/* @__PURE__ */ new Map;for(let e of n)this.collectAround(e,r);let i=new Map(e.map(e=>[e.key,e]));for(let[e,n]of r){let r=i.get(e)??t.get(e);if(r===void 0)continue;let a=Qi(r,n);(a!==r||i.has(e))&&i.set(e,a)}return[...i.values()]}insert(e){this.sorted.splice(this.lowerBound(e.seq),0,e),this.entries.set(e.key,e)}remove(e){this.sorted.splice(this.sorted.indexOf(e),1),this.entries.delete(e.key)}lowerBound(e){let t=0,n=this.sorted.length;for(;t<n;){let r=t+n>>>1;(this.sorted[r]?.seq??1/0)<e?t=r+1:n=r}return t}runEnd(e){let t=e;for(;t+1<this.sorted.length&&this.sorted[t+1]?.kind!==`boundary`;)t++;return t}runStart(e){let t=e;for(;t-1>=0&&this.sorted[t-1]?.kind!==`boundary`;)t--;return t}assignRun(e,t,n){let r=[];for(let n=e;n<=t;n++){let e=this.sorted[n];e?.kind===`skill`&&e.name!==null&&!r.includes(e.name)&&r.push(e.name)}for(let i=e;i<=t;i++){let e=this.sorted[i];e?.kind===`message`&&n.set(e.key,r)}}collectAround(e,t){let n=this.lowerBound(e),r=this.sorted[n];if(r!==void 0&&r.seq===e&&r.kind!==`boundary`){this.assignRun(this.runStart(n),this.runEnd(n),t);return}n-1>=0&&this.sorted[n-1]?.kind!==`boundary`&&this.assignRun(this.runStart(n-1),n-1,t);let i=r!==void 0&&r.seq===e?n+1:n;i<this.sorted.length&&this.sorted[i]?.kind!==`boundary`&&this.assignRun(i,this.runEnd(i),t)}};let na={anchorSeq:0,nodes:Mi,partial:null,running:null};function ra(e){let t=e;if(e.visibility!==`visible`&&t.kind!==`assistant-step`)return na;switch(t.kind){case`user`:case`steering`:case`context`:case`command`:case`compaction`:case`turn-error`:case`turn-max-tokens`:case`unknown`:return{anchorSeq:t.anchorSeq,nodes:[t.data],partial:null,running:null};case`assistant-step`:{let n=t.data;return n.status===`running`?e.visibility===`visible`?{anchorSeq:t.anchorSeq,nodes:Mi,partial:{turn:n.turn,step:n.step,blocks:n.blocks},running:null}:na:{anchorSeq:t.anchorSeq,nodes:n.finalNode===void 0?Mi:[n.finalNode],partial:null,running:null}}case`tool-call`:{let e=t.data.root;return vi(e)?{anchorSeq:t.anchorSeq,nodes:Mi,partial:null,running:e}:{anchorSeq:t.anchorSeq,nodes:[e],partial:null,running:null}}case`manual-compaction`:{let e=t.data;return{anchorSeq:t.anchorSeq,nodes:e.compaction===null?[e.command]:[e.command,e.compaction],partial:null,running:null}}case`model-retry`:return{anchorSeq:t.anchorSeq,nodes:t.data.attempts,partial:null,running:null};case`turn-tail`:case`system-prompt`:return na;default:return na}}function ia(e,t){return e!==void 0&&e.anchorSeq===t.anchorSeq&&e.partial?.blocks===t.partial?.blocks&&e.partial?.turn===t.partial?.turn&&e.partial?.step===t.partial?.step&&e.running===t.running&&Ni(e.nodes,t.nodes)}var aa=class{contributions=/* @__PURE__ */ new Map;finalizedContributions=/* @__PURE__ */ new Map;runningContributions=/* @__PURE__ */ new Map;partialContributions=/* @__PURE__ */ new Map;finalized=Mi;runningCalls=Mi;partial=null;timeline;turnTimings=/* @__PURE__ */ new Map;turnEnds=/* @__PURE__ */ new Map;replace(e,t){this.contributions.clear(),this.finalizedContributions.clear(),this.runningContributions.clear(),this.partialContributions.clear();for(let t of e){let e=ra(t);this.contributions.set(t.key,e),this.indexContribution(t.key,e)}return this.rebuildFinalized(),this.rebuildRunning(),this.rebuildPartial(),this.updateTimeline(t),this.snapshot()}apply(e,t){let n=!1,r=!1,i=!1;for(let t of e){let e=ra(t),a=this.contributions.get(t.key);ia(a,e)||(n||=sa(a,e),r||=ca(a,e),i||=la(a,e),this.contributions.set(t.key,e),this.indexContribution(t.key,e))}return n&&this.rebuildFinalized(),r&&this.rebuildRunning(),i&&this.rebuildPartial(),this.updateTimeline(t),this.snapshot()}indexContribution(e,t){oa(this.finalizedContributions,e,t,t.nodes.length>0),oa(this.runningContributions,e,t,t.running!==null),oa(this.partialContributions,e,t,t.partial!==null)}rebuildFinalized(){let e=[...this.finalizedContributions.values()].flatMap(e=>e.nodes).sort((e,t)=>e.seq-t.seq);Ni(this.finalized,e)||(this.finalized=e)}rebuildRunning(){let e=[...this.runningContributions.values()].sort((e,t)=>e.anchorSeq-t.anchorSeq).flatMap(e=>e.running===null?[]:[e.running]);Ni(this.runningCalls,e)||(this.runningCalls=e)}rebuildPartial(){let e=[...this.partialContributions.values()].sort((e,t)=>e.anchorSeq-t.anchorSeq).findLast(e=>e.partial!==null)?.partial??null;(this.partial?.blocks!==e?.blocks||this.partial?.turn!==e?.turn||this.partial?.step!==e?.step)&&(this.partial=e)}updateTimeline(e){if(this.timeline===e)return;this.timeline=e;let t=/* @__PURE__ */ new Map,n=/* @__PURE__ */ new Map;for(let r of e.turns.values())r.start!==void 0&&t.set(r.turn,{startTime:r.start.time,...r.end===void 0?{}:{endTime:r.end.time}}),r.end!==void 0&&n.set(r.turn,r.end.seq);this.turnTimings=t,this.turnEnds=n}snapshot(){return{nodes:this.finalized,turnTimings:this.turnTimings,turnEnds:this.turnEnds,partial:this.partial,runningCalls:this.runningCalls}}};function oa(e,t,n,r){r?e.set(t,n):e.delete(t)}function sa(e,t){let n=e?.nodes??Mi;return!Ni(n,t.nodes)||(n.length>0||t.nodes.length>0)&&e?.anchorSeq!==t.anchorSeq}function ca(e,t){return e?.running!==t.running||(e.running!==null||t.running!==null)&&e.anchorSeq!==t.anchorSeq}function la(e,t){return e?.partial?.blocks!==t.partial?.blocks||e?.partial?.turn!==t.partial?.turn||e?.partial?.step!==t.partial?.step||((e?.partial??null)!==null||t.partial!==null)&&e?.anchorSeq!==t.anchorSeq}var ua=class{store=new Li;locations=new Ri;navigation=new Bi;legacy=new aa;referenceLabels=new Zi;skillNames=new ta;order=ki;latestGroupInput;readGroupNode=e=>this.store.get(e);readGroupTurn=e=>this.locations.getTurn(e);readGroupPosition=e=>this.locations.getPosition(e);timeline=null;empty;constructor(){this.empty=this.snapshot({turnOrder:Ai,turns:/* @__PURE__ */ new Map}),this.latestGroupInput={kind:`replace`,order:this.order,readNode:this.readGroupNode,readTurn:this.readGroupTurn,readPosition:this.readGroupPosition,timeline:this.empty.timeline}}replace(e){let t=this.skillNames.replace(this.referenceLabels.replace(e.nodes));return this.store.replace(t),this.order=qi(t).map(e=>e.key),this.locations.rebuild(this.order,this.store),this.store.replaceProcesses(this.order,this.locations),this.navigation.rebuild(e.timeline,this.locations,this.store),this.timeline=e.timeline,this.latestGroupInput={kind:`replace`,order:this.order,readNode:this.readGroupNode,readTurn:this.readGroupTurn,readPosition:this.readGroupPosition,timeline:e.timeline},this.snapshot(e.timeline,this.legacy.replace(t,e.timeline))}apply(e){let t=this.skillNames.apply(this.referenceLabels.apply(e.upserts,this.store),this.store),n=/* @__PURE__ */ new Set,r=!1,i=[],a=[];for(let e of t){let t=this.store.get(e.key);t!==e&&a.push({previous:t,current:e});let o=t===void 0||t.kind!==e.kind||t.anchorSeq!==e.anchorSeq||t.visibility!==e.visibility||fa(t.location)!==fa(e.location);if(r||=o,o||i.push(e),Wi(t,e,o)){let r=t===void 0?void 0:Hi(t.location).turn,i=Hi(e.location).turn;r!==void 0&&n.add(r),i!==void 0&&n.add(i)}}this.store.upsert(t);let o=Ai;if(r){let e=qi(this.store.values()).map(e=>e.key);this.order=Ni(this.order,e)?this.order:e,o=this.locations.rebuild(this.order,this.store)}return this.locations.touch(i),this.store.updateProcesses(n,this.locations),r||e.timeline!==this.timeline?this.navigation.rebuild(e.timeline,this.locations,this.store):this.navigation.touch(da(i),this.locations,this.store),this.timeline=e.timeline,this.latestGroupInput={kind:`apply`,changes:a,order:this.order,readNode:this.readGroupNode,readTurn:this.readGroupTurn,readPosition:this.readGroupPosition,timeline:e.timeline,changedTurns:e.changedTurns??Ai,changedTurnOrders:o},this.snapshot(e.timeline,this.legacy.apply(t,e.timeline))}groupInput(){return this.latestGroupInput}publish(){this.store.publish()}snapshot(e,t=this.legacy.replace(Mi,e)){return{order:this.order,nodes:this.store,locations:this.locations,navigation:this.navigation,timeline:e,legacy:t}}};function da(e){let t=/* @__PURE__ */ new Set;for(let n of e){let e=Hi(n.location).turn;e!==void 0&&t.add(e)}return t}function fa(e){let t=Hi(e);return`${e.kind}:${t.turn??``}:${t.step??``}`}let pa={target:`chat`,create:()=>new ua,isActive:e=>e.order.some(t=>e.nodes.get(t)?.kind!==`command`)};function ma(e){e.uiConversation.views.register(pa)}let ha=/* @__PURE__ */ new Set([`system/message`,`developer/message`,`user/message`,`assistant/message`,`tool/result`]);function ga(e){return ha.has(e.type)?e.surfaceOp!==void 0:!1}function _a(e){return ga(e)&&e.surfaceOp===`append`}function va(e){return ga(e)&&e.surfaceOp!==`append`}function ya(e){if(e.event.type!==`command/run`)throw Error(`command start requires command/run`);let t=e.event.data;return{kind:`command`,seq:e.event.seq,time:e.event.time,commandId:t.commandId,name:t.name,args:t.args??null,outcome:null}}function ba(e,t){if(e.event.type!==`command/done`)throw Error(`command update requires command/done`);let n=e.event.data,r=n.kind===`success`&&n.sourceEventSeq!==void 0&&Number.isSafeInteger(n.sourceEventSeq)&&n.sourceEventSeq>=0?n.sourceEventSeq:void 0;return{kind:`command`,seq:t?.seq??e.event.seq,time:t?.time??e.event.time,commandId:n.commandId,name:t?.name??null,args:t?.args??null,outcome:{kind:n.kind,...n.text===void 0?{}:{text:n.text},...r===void 0?{}:{sourceEventSeq:r}}}}function xa(e){if(e.type!==`user/message`||!va(e))return;let t=e.data.source;if(t.kind===`compact-checkpoint`&&typeof t.compactionId==`string`)return{compactionId:t.compactionId,...t.sourceCommandId===void 0?{}:{sourceCommandId:t.sourceCommandId}}}function Sa(e,t){let n=null,r=null,i=null;if(e?.event.type===`compaction/summary`){let t=e.event.data;if(Array.isArray(t.summary)){let e=t.summary.map(e=>e.type===`text`?e.text:``).join(``);n=e.trim()===``?null:e}r=Array.isArray(t.shadowedSeqs)&&t.shadowedSeqs.every(e=>Number.isSafeInteger(e)&&e>=0)?t.shadowedSeqs.length:null,i=Number.isSafeInteger(t.shadowedTokenCount)&&t.shadowedTokenCount>=0?t.shadowedTokenCount:null}return{kind:`compaction`,seq:t.event.seq,time:t.event.time,summary:n,summaryEventSeq:e?.event.seq??null,shadowedItemCount:r,shadowedTokenCount:i}}function Ca(e){let t=e.matches.find(e=>e.event.type===`command/done`),n=e.matches.find(e=>xa(e.event)!==void 0),r=e.matches.find(e=>e.event.type===`compaction/summary`);if(n===void 0)return t===void 0?void 0:{command:ba(t)};let i=xa(n.event);return i?.sourceCommandId===void 0?t===void 0?void 0:{command:ba(t)}:{command:t===void 0?{kind:`command`,seq:n.event.seq,time:n.event.time,commandId:i.sourceCommandId,name:`compact`,args:null,outcome:null}:{...ba(t),name:`compact`},checkpoint:n,...r===void 0?{}:{summary:r}}}function wa(e,t){return t.event.type===`compaction/summary`?{...e,summary:t}:xa(t.event)===void 0?e:{...e,checkpoint:t}}let Ta={kind:`command`,target:`chat`,match:e=>{if(e.type===`command/run`)return{id:String(e.data.commandId),role:`start`};if(e.type===`command/done`)return{id:String(e.data.commandId),role:`update`};let t=xa(e);return t?.sourceCommandId===void 0?(e.type===`compaction/start`||e.type===`compaction/summary`||e.type===`compaction/end`)&&e.data.sourceCommandId!==void 0?{id:String(e.data.sourceCommandId),role:`update`}:null:{id:String(t.sourceCommandId),role:`update`}},start:(e,t)=>({command:ya(t)}),update:(e,t)=>t.event.type===`command/done`?{...e.state,command:ba(t,e.state.command)}:wa(e.state,t),buildViewNode:e=>{let t=e.state??Ca(e);if(t===void 0)return null;if(t.command.name!==`compact`)return J(e,`command`,t.command.seq,t.command);let n=t.checkpoint===void 0?null:Sa(t.summary,t.checkpoint),r={command:t.command,compaction:n};return J(e,`manual-compaction`,n?.seq??t.command.seq,r)}};function Ea(e){e.uiConversation.events.register(Ta)}function Da(e){let t=e.matches.find(e=>e.event.type===`compaction/summary`),n=e.matches.find(e=>xa(e.event)!==void 0);return{...t===void 0?{}:{summary:t},...n===void 0?{}:{checkpoint:n}}}let Oa={kind:`compaction`,target:`chat`,match:e=>{let t=xa(e);if(t!==void 0&&t.sourceCommandId===void 0)return{id:t.compactionId,role:`update`};if(e.type===`compaction/start`||e.type===`compaction/summary`||e.type===`compaction/end`){if(e.data.sourceCommandId!==void 0)return null;let t=e.data.compactionId;return typeof t!=`string`||t===``?null:{id:t,role:e.type===`compaction/start`?`start`:`update`}}return null},start:()=>({}),update:(e,t)=>wa(e.state,t),buildViewNode:e=>{let t=e.state??Da(e);if(t.checkpoint===void 0)return null;let n=Sa(t.summary,t.checkpoint);return J(e,`compaction`,n.seq,n)}};function ka(e){e.uiConversation.events.register(Oa)}let Aa={kind:`unknown-surface`,target:`chat`,match:e=>e.type!==`assistant/live-chunk`&&_a(e)?{id:String(e.seq),role:`start`}:null,start:(e,t)=>({kind:`unknown`,seq:t.event.seq,time:t.event.time,type:t.event.type,data:t.event.data}),update:e=>e.state,buildViewNode:e=>e.state===void 0?null:J(e,`unknown`,e.state.seq,e.state)};function ja(e){e.uiConversation.events.registerFallback(Aa)}let Ma={kind:`snapshot`,ids:[]},Na=/* @__PURE__ */ new Set;function Pa(e){let t=[],n=e;for(;n.kind===`splice`;)t.push(n),n=n.previous;let r=[...n.ids];for(let e of t.reverse())r.splice(e.start,e.removedCount,...e.inserted);return r}function Fa(e,t){let n;for(let{id:r}of t)e.has(r)&&(n??=new Set(e),n.delete(r));return n??e}function Ia(e,t,n){let r=e?.state.pending??Ma,i=t.inserted,a=t.removedCount??0;if(a>0&&t.outcome!==`canceled`){let e=Pa(r),o=e.splice(t.start,a,...i);return{pending:{kind:`snapshot`,ids:e},currentClaimed:new Set(o.map(e=>e.id)),claimSeq:n,claimedHuman:o.some(e=>e.source.kind===`user`)}}let o=Fa(e?.state.currentClaimed??Na,i);return{pending:{kind:`splice`,previous:r,start:t.start,removedCount:a,inserted:i},currentClaimed:o,claimSeq:e?.state.claimSeq??-1,claimedHuman:e?.state.claimedHuman??!1}}function La(e){let t=`inbox-${e}`;return{kind:t,match:t=>t.type===`agent/inbox/spliced`&&t.data.target===e?{id:String(t.seq),role:`start`}:null,start:(e,n,r)=>{if(n.event.type!==`agent/inbox/spliced`)throw Error(`inbox start requires agent/inbox/spliced`);return Ia(r.previous(t),n.event.data,n.event.seq)},update:e=>e.state,publication:()=>`none`}}let Ra=La(`next-step`),za=La(`next-turn`);function Ba(e){e.uiConversation.events.register(Ra),e.uiConversation.events.register(za)}function Va(e){return e.type!==`user/message`||!va(e)?!1:e.data.source.kind===`compact-checkpoint`}function Ha(e,t){return{kind:`context`,seq:e.seq,time:e.time,content:t.content,source:t.source,producer:Jr(t.source),form:qr(t.source)}}let Ua={kind:`input-message`,target:`chat`,match:e=>e.type===`user/message`&&_a(e)&&!Va(e)?{id:String(e.data.id),role:`start`}:null,start:(e,t,n)=>{let r=t.event;if(r.type!==`user/message`)throw Error(`input-message start requires user/message`);if(r.data.source.kind!==`user`){let e=n.previous(`inbox-next-turn`)?.state,i=n.previous(`inbox-next-step`)?.state,a=t.location,o=a.kind===`step`?a.turn.start?.seq:void 0,s=a.kind===`step`&&a.step.step===1&&o!==void 0&&(i?.claimSeq??-1)>o&&(e?.claimSeq??-1)<o&&i?.claimedHuman===!1&&i.currentClaimed.has(String(r.data.id));return{...Ha(r,r.data),waking:e?.currentClaimed.has(String(r.data.id))===!0||s}}return n.previous(`inbox-next-step`)?.state.currentClaimed.has(String(r.data.id))===!0?{kind:`steering`,messageId:r.data.id,seq:r.seq,time:r.time,content:r.data.content,source:r.data.source}:{kind:`user`,seq:r.seq,time:r.time,content:r.data.content,source:r.data.source}},update:e=>e.state,buildViewNode:e=>e.state===void 0?null:J(e,e.state.kind===`context`&&e.start?.event.type===`user/message`&&e.state.waking===!0?`turn-trigger`:e.state.kind,e.state.seq,e.state)},Wa={...Ua,kind:`developer-message`,match:e=>e.type===`developer/message`?{id:String(e.data.message.id),role:`start`}:null,start:(e,t)=>{let n=t.event;if(n.type!==`developer/message`)throw Error(`developer-message start requires developer/message`);return Ha(n,n.data.message)}};function Ga(e){e.uiConversation.events.register(Ua),e.uiConversation.events.register(Wa)}function Ka(e,t,n){return e.location.kind!==`step`||t===void 0&&!n||t?.turn===e.location.turn.turn&&t.step===e.location.step.step?e.event.seq:e.location.step.step===1?e.location.turn.start?.seq??e.location.step.start?.seq??e.event.seq:e.location.step.start?.seq??e.event.seq}function qa(e,t,n,r){let i=e.current.get(`chat`);return i?.kind===`system-prompt`?i.anchorSeq:Ka(t,n,r)}function Ja(e){return{kind:`system-message`,target:`chat`,match:e=>e.type===`system/message`||`surfaceOp`in e&&e.surfaceOp!==`append`?{id:String(e.seq),role:`start`}:null,start:(t,n,r)=>{if(n.event.type===`assistant/live-chunk`)throw Error(`system-message requires a durable event`);return e(r.previous(`system-message`)?.state,n.event)},update:e=>e.state,buildViewNode:e=>{let t=e.state?.introduced;return t===void 0||t.text===``||e.start?.event.type!==`system/message`||e.start.event.surfaceOp!==`append`?null:J(e,`system-prompt`,t.update?t.seq:Ka(e.start,void 0,!0),{text:t.text,...t.update?{update:!0}:{}})}}}function Ya(e){return{kind:`request-prompt`,target:`chat`,match:e=>e.type===`request/header`?{id:String(e.seq),role:`start`}:null,start:(t,n,r)=>{if(n.event.type!==`request/header`)throw Error(`request-prompt start requires request/header`);let i=r.previous(`request-prompt`)?.state,a=r.previous(`system-message`),o=a?.state.effective,s=n.location.kind===`step`?{turn:n.location.turn.turn,step:n.location.step.step}:{},c=e(i?.prompt,n.event,o),l=c.change?.kind,u=a?.matches[0]?.event,d=o!==void 0&&u?.type===`system/message`&&u.surfaceOp===`append`&&(o.update||i===void 0)&&o.turn===s.turn&&o.step===s.step;return{anchorSeq:qa(t,n,i,n.event.data.reason===`initial`),showsPrompt:!d&&(i===void 0||n.event.data.reason!==`change`||n.event.data.startsSeries===!0||l===`system`||l===`system-and-tools`),...s,...c}},update:e=>e.state,buildViewNode:e=>{let t=e.state;if(t===void 0)return null;let n=e.current.get(`chat`),r=t.showsPrompt&&t.prompt.system!==``;return!r&&n?.kind!==`system-prompt`?null:J(e,`system-prompt`,t.anchorSeq,{text:t.prompt.system},{visibility:r?`visible`:`hidden`})}}}function Xa(e){e.uiConversation.events.register(Ja((t,n)=>e.uiConversation.inspectSystemPrompt(t,n))),e.uiConversation.events.register(Ya((t,n,r)=>e.uiConversation.inspectRequestPrompt(t,n,r)))}function Za(e){if(e.event.type===`llm/retry`)return{kind:`model-retry`,seq:e.event.seq,time:e.event.time,retryState:`scheduled`,...e.event.data}}function Qa(e){return e.kind===`step`&&e.step.status===`closed`||(e.kind===`step`||e.kind===`turn`)&&e.turn.status===`closed`}let $a={kind:`model-retry`,target:`chat`,match:e=>{if(e.type===`llm/retry`){let t=e.data.retryId;return typeof t!=`string`||t===``?null:{id:t,role:e.data.retry===1?`start`:`update`}}if(e.type===`llm/retry-started`){let t=e.data.retryId;return typeof t==`string`&&t!==``?{id:t,role:`update`}:null}return null},start:(e,t)=>{let n=Za(t);if(n===void 0)throw Error(`model-retry start requires a valid llm/retry event`);return{turn:n.turn,step:n.step,attempts:[n]}},update:(e,t)=>{if(t.event.type===`llm/retry`){let n=Za(t);return n===void 0?e.state:{...e.state,attempts:[...e.state.attempts,n]}}if(t.event.type!==`llm/retry-started`)return e.state;let n=t.event.data.retry;return{...e.state,attempts:e.state.attempts.map(e=>e.retry===n?{...e,retryState:`started`}:e)}},buildViewNode:e=>{if(e.state===void 0||e.state.attempts.length===0)return null;let t=e.start?.location??e.matches[0]?.location??{kind:`unresolved`},n=e.state.attempts,r=n.map((e,r)=>r===n.length-1&&e.retryState===`scheduled`&&Qa(t)?{...e,retryState:`cancelled`}:e),i=r.at(-1);if(i===void 0)return null;let a={attempts:r,current:i};return J(e,`model-retry`,r[0]?.seq??i.seq,a)}};function eo(e){e.uiConversation.events.register($a)}let to=/* @__PURE__ */ new WeakMap;function no(e){return JSON.stringify(e)}function ro(e,t){if(e.event.type!==`tool/call`)throw Error(`tool-call start requires tool/call`);return{phase:`start`,callId:String(e.event.data.callId),name:e.event.data.name,argsRaw:e.event.data.arguments,args:t===void 0?Dt.fromText(e.event.data.arguments):t.args.settle(e.event.data.arguments),turn:e.event.data.turn,step:e.event.data.step,time:e.event.time,subCalls:[]}}function io(e,t){let n=t.event;if(n.type!==`assistant/live-chunk`)return e;let r=n.data.chunk,i=e.root;if(r.type===`block-end`&&r.block.type===`tool-call`)return i===void 0||`kind`in i||i.phase!==`preparing`?e:{...e,root:{...i,name:r.block.name,args:i.args.settle(r.block.arguments)}};if(r.type!==`tool-call-delta`)return e;if(i===void 0){if(!r.name)return e;let t=new Dt;return t.append(r.argumentsDelta),{...e,root:{phase:`preparing`,callId:String(r.id),name:r.name,turn:n.data.turn,step:n.data.step,time:n.time,subCalls:[],args:t}}}return`kind`in i||i.phase!==`preparing`||i.args.isSealed||i.args.append(r.argumentsDelta),e}function ao(e,t){let n=e.args.refresh();return!n&&t!==void 0&&!(`kind`in t)&&t.phase===`preparing`&&t.name===e.name&&t.args===e.args?t:n?{...e}:e}function oo(e,t){if(e.event.type!==`tool/result`)return;let n=e.event.data.message;return{kind:`tool-result`,seq:e.event.seq,time:e.event.time,callId:String(n.source.callId),name:t?.name??``,args:t?.args??Dt.EMPTY,call:t===void 0?null:{name:t.name,argsRaw:t.argsRaw},callTime:t?.time??null,content:n.content,isError:n.isError===!0,...e.event.data.error===void 0?{}:{error:e.event.data.error},meta:e.event.data.meta,subCalls:[]}}function so(e,t){return{phase:`start`,callId:t.subCallId,parentCallId:t.parentCallId,name:t.name,argsRaw:no(t.arguments),args:Dt.fromObject(t.arguments),turn:lo(e),step:uo(e),time:e.event.time,subCalls:[]}}function co(e,t,n){return{kind:`tool-result`,seq:e.event.seq,time:e.event.time,callId:t.subCallId,parentCallId:t.parentCallId,name:t.name,args:n!==void 0&&!(`kind`in n)?n.args:Dt.fromObject(t.arguments),call:{name:t.name,argsRaw:no(t.arguments)},callTime:n?.time??null,content:t.content??[],isError:t.isError===!0,...t.error===void 0?{}:{error:t.error},subCalls:[]}}function lo(e){return e.location.kind===`step`||e.location.kind===`turn`?e.location.turn.turn:0}function uo(e){return e.location.kind===`step`?e.location.step.step:0}function fo(e,t,n){if(t===n||e.parents.has(n))return!1;let r=t,i=0,a=/* @__PURE__ */ new Set;for(;r!==void 0;){if(r===n||a.has(r))return!1;a.add(r),i++,r=e.parents.get(r)}let o=[{callId:n,depth:1}],s=/* @__PURE__ */ new Set,c=0;for(let t of o){if(s.has(t.callId))return!1;s.add(t.callId),c=Math.max(c,t.depth);for(let n of e.children.get(t.callId)??[])o.push({callId:n.callId,depth:t.depth+1})}return i+c<=256}function po(e,t){let n=t.event;if(n.type!==`tool/ptc-dispatch-start`&&n.type!==`tool/ptc-dispatch`)return e;let r=n.data,i=String(r.parentCallId),a=String(r.subCallId),o=e.children.get(i)??[],s=o.findIndex(e=>e.callId===a);if(n.type===`tool/ptc-dispatch-start`){if(s>=0||!fo(e,i,a))return e;let n=new Map(e.children);n.set(i,[...o,so(t,r)]);let c=new Map(e.parents);return c.set(a,i),{...e,children:n,parents:c}}if(s<0&&!fo(e,i,a))return e;let c=co(t,r,s<0?void 0:o[s]),l=new Map(e.children);l.set(i,s<0?[...o,c]:o.map((e,t)=>t===s?c:e));let u=new Map(e.parents);return s<0&&u.set(a,i),{...e,children:l,parents:u}}function mo(e,t,n,r=/* @__PURE__ */ new Set,i=1){if(!(`kind`in e)&&e.phase===`preparing`)return e;if(r.has(e.callId)||i>256)return{...e,subCalls:[]};let a=new Set(r);a.add(e.callId);let o=(t.children.get(e.callId)??e.subCalls).map(e=>mo(e,t,n,a,i+1)),s=`kind`in e?void 0:n?.seq,c=`kind`in e?void 0:n?.time,l=to.get(e);if(l!==void 0&&l.interruptionSeq===s&&l.interruptionTime===c&&ho(l.children,o))return l.value;let u=`kind`in e||n===void 0?ho(e.subCalls,o)?e:{...e,subCalls:o}:{kind:`tool-result`,seq:n.seq+Br.interruptedFollowup,time:n.time,callId:e.callId,...e.parentCallId===void 0?{}:{parentCallId:e.parentCallId},name:e.name,args:e.args,call:{name:e.name,argsRaw:e.argsRaw},callTime:e.time,content:[],isError:!0,error:{name:`Interrupted`,code:`interrupted`},subCalls:o};return to.set(e,{children:o,interruptionSeq:s,interruptionTime:c,value:u}),u}function ho(e,t){return e.length===t.length&&e.every((e,n)=>e===t[n])}function go(e){let t=e.start?.location;if(t?.kind===`step`&&t.step.status===`closed`)return t.step.end;if((t?.kind===`step`||t?.kind===`turn`)&&t.turn.status===`closed`)return t.turn.end}function _o(e){let t=e.matches.find(e=>e.event.type===`tool/result`),n=t===void 0?void 0:oo(t);if(n===void 0)return;let r={root:n,children:/* @__PURE__ */ new Map,parents:/* @__PURE__ */ new Map};for(let t of e.matches)r=po(r,t);return r}let vo={kind:`tool-call`,target:`chat`,match:e=>{if(e.type===`assistant/live-chunk`){let t=e.data.chunk;return t.type===`block-end`&&t.block.type===`tool-call`?{id:String(t.block.id),role:`start`}:t.type===`tool-call-delta`?{id:String(t.id),role:`start`}:null}if(e.type===`tool/call`)return{id:String(e.data.callId),role:`start`};if(e.type===`tool/result`&&_a(e))return{id:String(e.data.message.source.callId),role:`update`};if(e.type===`tool/ptc-dispatch-start`||e.type===`tool/ptc-dispatch`){let t=e.data.rootCallId;return typeof t==`string`&&t!==``?{id:t,role:`update`}:null}return null},start:(e,t)=>{let n={root:void 0,children:/* @__PURE__ */ new Map,parents:/* @__PURE__ */ new Map};return t.event.type===`tool/call`?{...n,root:ro(t)}:io(n,t)},update:(e,t)=>{if(t.event.type===`assistant/live-chunk`)return io(e.state,t);if(t.event.type===`tool/call`)return{...e.state,root:ro(t,e.state.root)};if(t.event.type===`tool/result`){let n=e.state.root,r=oo(t,n!==void 0&&!(`kind`in n)&&n.phase===`start`?n:void 0);return r===void 0?e.state:{...e.state,root:r}}return po(e.state,t)},publication:e=>e.event.type===`assistant/live-chunk`?`animation-frame`:`immediate`,buildViewNode:e=>{let t=e.current.get(`chat`),n=e.state??_o(e);if(n?.root===void 0)return t==null?null:t.visibility===`hidden`?t:{...t,visibility:`hidden`};let r=go(e),i=mo(!(`kind`in n.root)&&n.root.phase===`preparing`?ao(n.root,t?.data.root):n.root,n,r),a=e.start?.event.seq??(`kind`in n.root?n.root.seq:e.matches[0]?.event.seq??0),o=!(`kind`in i)&&i.phase===`preparing`&&r!==void 0?`hidden`:`visible`,s=Vr(e),c=pt(i.name)&&s.kind===`step`?{kind:`turn`,turn:s.turn}:s,l=t?.data.root===i?t.data:{root:i};return t?.data===l&&t.anchorSeq===a&&t.visibility===o&&t.location===c?t:J(e,`tool-call`,a,l,{visibility:o,location:c})}};function yo(e){let t=vo.match.bind(vo);e.uiConversation.events.register({...vo,match:{"assistant/live-chunk":t,"tool/call":t,"tool/result":t,"tool/ptc-dispatch-start":t,"tool/ptc-dispatch":t}})}function bo(e){let t=e.start?.location??e.matches[0]?.location;return t?.kind!==`turn`&&t?.kind!==`step`?0:t.turn.steps.at(-1)?.step??0}function xo(e){if(e.event.type!==`turn/end`)return;let t=e.event.data.reason,n=t.kind===`error`?t.error:t.kind===`aborted`&&t.reason.kind===`hook`&&t.reason.reason===`deepseek-account/signed-out`?{message:`Stopped because you signed out of DeepSeek.`,code:`ACCOUNT_SIGNED_OUT`}:void 0;if(n===void 0)return;let r=ei(n);return{seq:e.event.seq,time:e.event.time,message:r.message,...r.code===void 0?{}:{code:r.code}}}function So(e){let t=e.matches.find(e=>xo(e)!==void 0);if(t?.event.type!==`turn/end`)return;let n=xo(t);if(n!==void 0)return{turn:t.event.data.turn,failure:n}}let Co={kind:`turn-error`,target:`chat`,match:e=>e.type===`turn/start`?{id:String(e.data.turn),role:`start`}:e.type===`turn/end`&&(e.data.reason.kind===`error`||e.data.reason.kind===`aborted`&&e.data.reason.reason.kind===`hook`&&e.data.reason.reason.reason===`deepseek-account/signed-out`)?{id:String(e.data.turn),role:`update`}:null,start:(e,t)=>{if(t.event.type!==`turn/start`)throw Error(`turn-error start requires turn/start`);return{turn:t.event.data.turn}},update:(e,t)=>{let n=xo(t);return n===void 0?e.state:{...e.state,failure:n}},buildViewNode:e=>{let t=e.state??So(e);if(t?.failure===void 0)return null;let n=t.failure,r={kind:`turn-error`,seq:n.seq,time:n.time,turn:t.turn,step:bo(e),message:n.message,...n.code===void 0?{}:{code:n.code}};return J(e,`turn-error`,r.seq,r)}};function wo(e){e.uiConversation.events.register(Co)}function To(e){let t=e.start?.location??e.matches[0]?.location;return t?.kind!==`turn`&&t?.kind!==`step`?0:t.turn.steps.at(-1)?.step??0}function Eo(e,t){let n=e.start?.location??e.matches[0]?.location;if(n?.kind!==`turn`&&n?.kind!==`step`)return t;let r=n.turn.data.get(`turn-tail`)?.closing;return r==null?t:r.finalNode.seq+Br.maxTokensNotice}function Do(e){if(e.event.type===`turn/end`&&e.event.data.reason.kind===`max-tokens`)return{turn:e.event.data.turn,seq:e.event.seq,time:e.event.time}}let Oo={kind:`turn-max-tokens`,target:`chat`,match:e=>e.type===`turn/end`&&e.data.reason.kind===`max-tokens`?{id:String(e.data.turn),role:`start`}:null,start:(e,t)=>{let n=Do(t);if(n===void 0)throw Error(`turn-max-tokens start requires a max-tokens turn/end`);return n},update:e=>e.state,buildViewNode:e=>{let t=e.state;if(t===void 0)return null;let n={kind:`turn-max-tokens`,seq:t.seq,time:t.time,turn:t.turn,step:To(e)};return J(e,`turn-max-tokens`,Eo(e,t.seq),n)}};function ko(e){e.uiConversation.events.register(Oo)}function Ao(e){let t=e.data;return typeof t.turn==`number`?t.turn:void 0}function jo(e){if(e.type===`text-delta`||e.type===`reasoning-delta`)return e.text.trim()!==``;if(e.type===`block-start`)return e.blockType!==`text`&&e.blockType!==`reasoning`&&e.blockType!==`tool-call`;if(e.type!==`block-end`)return!1;let t=e.block;return t.type===`tool-call`?!1:t.type===`text`||t.type===`reasoning`?t.text.trim()!==``:!0}function Mo(e){return e.type===`assistant/live-chunk`?jo(e.data.chunk):e.type!==`assistant/attempt`&&e.type===`assistant/message`&&e.surfaceOp===`append`&&Zr(e.data.message.content).some(e=>e.kind===`tool-call`?!1:e.kind===`text`||e.kind===`reasoning`?e.text.trim()!==``:!0)}function No(e,t){return e.type===`tool/call`?pt(e.data.name):e.type===`tool/result`&&t.has(String(e.data.message.source.callId))}function Po(e,t){if(Mo(e))return e.type!==`assistant/live-chunk`&&e.type!==`assistant/message`&&e.type!==`assistant/attempt`?void 0:{kind:`assistant`,seq:e.seq,step:e.data.step};if(!No(e,t)&&(e.type===`tool/call`||e.type===`tool/result`&&e.surfaceOp===`append`||e.type===`llm/retry`))return{kind:`other`,seq:e.seq}}function Fo(e){let t=e.start?.location??e.matches.at(-1)?.location;return t?.kind===`turn`||t?.kind===`step`?t.turn:void 0}function Io(e){let t=e.matches.map(e=>Ao(e.event)).find(e=>e!==void 0);if(t===void 0)return;let n={turn:t,assistantStartByStep:/* @__PURE__ */ new Map,messageCountByStep:/* @__PURE__ */ new Map,messageCount:0,toolCallCount:0,subagentCount:0,contextCompactionCalls:/* @__PURE__ */ new Set};for(let t of e.matches)n=Bo(n,t.event);return n}function Lo(e){return e?.finalNode!==void 0}function Ro(e){let t=e.end?.data.finalAssistantStep;if(t===null)return null;let n=(t===void 0?e.steps.at(-1):e.steps.find(e=>e.step===t))?.data.get(`assistant-step`);return!Lo(n)||n.finalNode.interrupted===!0||!Dr(n.blocks)||t===void 0&&n.blocks.some(e=>e.kind===`tool-call`)?null:n}function zo(e,t){let n=e.controlAnchorSeq??t.start?.seq;if(n===void 0)return null;let r=Ro(t),i={messageCount:r===null?e.messageCount:[...e.messageCountByStep].filter(([e])=>e!==r.step).reduce((e,[,t])=>e+t,0),toolCallCount:e.toolCallCount,subagentCount:e.subagentCount};if(r===null)return{turn:t.turn,controlAnchorSeq:n,processStartSeq:n,answerAnchorSeq:null,answerStep:null,inlineReasoning:!1,...i};let a=r.blocks.some(e=>e.kind===`reasoning`&&e.text.trim()!==``),o=Math.min(...[...e.assistantStartByStep].filter(([e])=>e<r.step).map(([,e])=>e)),s=Math.min(e.otherStartSeq??1/0,o);return{turn:t.turn,controlAnchorSeq:n,processStartSeq:t.start?.seq??(Number.isFinite(s)?s:r.finalNode.seq),answerAnchorSeq:r.finalNode.seq,answerStep:r.step,inlineReasoning:a,...i}}function Bo(e,t){let n=e;if(t.type===`assistant/message`&&t.surfaceOp===`append`&&Dr(Zr(t.data.message.content))){let e=new Map(n.messageCountByStep);e.set(t.data.step,(e.get(t.data.step)??0)+1),n={...n,messageCountByStep:e,messageCount:n.messageCount+1}}if(t.type===`tool/call`){if(pt(t.data.name)){let e=new Set(n.contextCompactionCalls);e.add(String(t.data.callId)),n={...n,contextCompactionCalls:e}}else{let e=ft(t.data.name);n={...n,toolCallCount:n.toolCallCount+ +!e,subagentCount:n.subagentCount+ +!!e}}}let r=Po(t,n.contextCompactionCalls);if(r===void 0)return n;if(r.kind===`other`)return n.otherStartSeq===void 0?{...n,otherStartSeq:r.seq,controlAnchorSeq:Math.min(n.controlAnchorSeq??1/0,r.seq)}:n;if(n.assistantStartByStep.has(r.step))return n;let i=new Map(n.assistantStartByStep);return i.set(r.step,r.seq),{...n,assistantStartByStep:i,controlAnchorSeq:Math.min(n.controlAnchorSeq??1/0,r.seq)}}let Vo={kind:`turn-process`,target:`chat`,match:e=>{if(e.type===`turn/start`)return{id:String(e.data.turn),role:`start`};let t=Ao(e);return t===void 0?null:e.type===`assistant/live-chunk`||e.type===`assistant/message`||e.type===`tool/call`||e.type===`tool/result`||e.type===`llm/retry`||e.type===`step/start`||e.type===`step/end`||e.type===`turn/end`?{id:String(t),role:`update`}:null},start:(e,t)=>{if(t.event.type!==`turn/start`)throw Error(`turn-process start requires turn/start`);return{turn:t.event.data.turn,assistantStartByStep:/* @__PURE__ */ new Map,messageCountByStep:/* @__PURE__ */ new Map,messageCount:0,toolCallCount:0,subagentCount:0,contextCompactionCalls:/* @__PURE__ */ new Set}},update:(e,t)=>Bo(e.state,t.event),publication:e=>{if(e.event.type===`assistant/live-chunk`){let t=e.event.data.chunk.type;return t===`usage`||t===`finish`?`none`:`animation-frame`}return`immediate`},buildLocationData:(e,t,n)=>{if(t!==`turn`)return null;let r=e.state??Io(e);if(r===void 0)return null;let i=Fo(e);if(i===void 0)return null;let a=e.current.get(`chat`),o=i.steps.at(-1);if(n?.kind===`turn`&&n.key===`turn-process`&&a?.kind===`turn-process`&&a.data.answerAnchorSeq===null&&a.data.controlAnchorSeq===r.controlAnchorSeq&&a.data.messageCount===r.messageCount&&a.data.toolCallCount===r.toolCallCount&&a.data.subagentCount===r.subagentCount&&i.status!==`closed`&&o?.status!==`closed`)return n;let s=zo(r,i);return s===null?null:n?.kind===`turn`&&n.turn===s.turn&&n.key===`turn-process`&&dt(n.value,s)?n:{kind:`turn`,turn:i.turn,key:`turn-process`,value:s}},buildViewNode:e=>{let t=Fo(e),n=t?.data.get(`turn-process`);if(t===void 0||n===void 0)return null;let r=e.current.get(`chat`),i=e.state;return r?.kind===`turn-process`&&i!==void 0&&r.data.answerAnchorSeq===null&&r.data.controlAnchorSeq===i.controlAnchorSeq&&r.data.messageCount===i.messageCount&&r.data.toolCallCount===i.toolCallCount&&r.data.subagentCount===i.subagentCount&&t.status!==`closed`&&t.steps.at(-1)?.status!==`closed`&&r.location===(e.start?.location??e.matches[0]?.location)?r:J(e,`turn-process`,n.controlAnchorSeq+Br.processControl,n)}};function Ho(e){let t=Vo.match.bind(Vo);e.uiConversation.events.register({...Vo,match:{"turn/start":t,"assistant/live-chunk":t,"assistant/message":t,"tool/call":t,"tool/result":t,"llm/retry":t,"step/start":t,"step/end":t,"turn/end":t}})}function Uo(e,t){for(let n=e.length-1;n>=0;--n){let r=e[n];if(r.type===`chunk`&&r.chunk.type===t)return r.chunk}}function Y(e){return typeof e==`number`&&Number.isSafeInteger(e)&&e>=0}function Wo(e){let t=0;for(let n of e)if(t+=n,!Number.isSafeInteger(t))return;return t}function Go(e){let{provider:t,model:n}=e.source;return t.length>0&&n.length>0?{provider:t,model:n}:void 0}function Ko(e){return Uo(e,`usage`)?.usage}function qo(e,t){let{inputTokens:n,outputTokens:r,cacheReadTokens:i,cacheWriteTokens:a,reasoningTokens:o,totalTokens:s}=e;if(!Y(n)||!Y(r)||i!==void 0&&!Y(i)||a!==void 0&&!Y(a)||o!==void 0&&(!Y(o)||o>r))return;let c=Wo([n,...i===void 0?[]:[i],...a===void 0?[]:[a]]);if(c===void 0)return;let l;if(s!==void 0){if(!Y(s))return;let e=s-r;if(!Y(e)||e<c||i!==void 0&&a!==void 0&&e!==c)return;l=s}else{if(i===void 0||a===void 0)return;let e=Wo([c,r]);if(e===void 0)return;l=e}return{inputTokens:n,outputTokens:r,totalTokens:l,...i===void 0?{}:{cacheReadTokens:i},...a===void 0?{}:{cacheWriteTokens:a},...o===void 0?{}:{reasoningTokens:o},...t===void 0?{}:{route:t}}}function Jo(e){if(e.length===0)return;let t=Wo(e.map(e=>e.inputTokens)),n=Wo(e.map(e=>e.outputTokens)),r=Wo(e.map(e=>e.totalTokens));if(t===void 0||n===void 0||r===void 0)return;let i=e.map(e=>e.cacheReadTokens),a=e.map(e=>e.cacheWriteTokens),o=e.map(e=>e.reasoningTokens),s=i.every(Y)?Wo(i):void 0,c=a.every(Y)?Wo(a):void 0,l=o.every(Y)?Wo(o):void 0,u,d=e.map(e=>e.route);if(d.every(e=>e!==void 0)){let e=/* @__PURE__ */ new Map;for(let t of d)e.set(`${t.provider}\0${t.model}`,t);u=[...e.values()]}return{uncachedInputTokens:t,outputTokens:n,totalTokens:r,...s===void 0?{}:{cacheReadTokens:s},...c===void 0?{}:{cacheWriteTokens:c},...l===void 0?{}:{reasoningTokens:l},...u===void 0?{}:{routes:u}}}function Yo(e,t,n){return e.turn===t&&e.step===n}function Xo(e){let t={kind:`idle`},n=[],r,i=!1,a=!1,o=e=>{if(t.kind!==`open`||t.sample===void 0)return!1;let r=qo(t.sample,e);return r!==void 0&&(n.push(r),!0)};for(let n of e){if(a)break;if(n.type===`turn/start`)r!==void 0||t.kind!==`idle`?a=!0:r=n.data.turn;else{if(r===void 0){a=!0;break}if(n.type===`turn/end`)n.data.turn!==r||t.kind!==`idle`||i?a=!0:i=!0;else{if(i){a=!0;break}if(n.type===`step/start`)n.data.turn!==r||t.kind!==`idle`?a=!0:t={kind:`open`,turn:r,step:n.data.step};else if(n.type===`llm/retry-started`)n.data.turn!==r||t.kind!==`settled`||t.by!==`retry`||!Yo(t,n.data.turn,n.data.step)?a=!0:t={kind:`open`,turn:r,step:n.data.step};else if(n.type===`assistant/attempt`){if(n.data.turn!==r||t.kind!==`open`||!Yo(t,n.data.turn,n.data.step)){a=!0;continue}let e=Ko(n.data.stream)??t.sample;t={kind:`open`,turn:r,step:n.data.step,...e===void 0?{}:{sample:e}},o()?t={kind:`finishClosed`,turn:r,step:n.data.step}:a=!0}else if(n.type===`assistant/message`){if(n.data.turn!==r||t.kind!==`open`||!Yo(t,n.data.turn,n.data.step)){a=!0;continue}let e=n.data.usage??Ko(n.data.stream);e!==void 0&&(t={...t,sample:e}),o(Go(n.data.message))?t={kind:`settled`,turn:r,step:n.data.step,by:`message`}:a=!0}else if(n.type===`llm/retry`){if(n.data.turn!==r||t.kind===`idle`||!Yo(t,n.data.turn,n.data.step)){a=!0;continue}(t.kind===`settled`||t.kind===`open`&&!o())&&(a=!0),a||(t={kind:`settled`,turn:r,step:n.data.step,by:`retry`})}else if(n.type===`step/end`){if(n.data.turn!==r||t.kind===`idle`||!Yo(t,n.data.turn,n.data.step)){a=!0;continue}t.kind===`open`&&!o()&&(a=!0),a||(t={kind:`idle`})}}}}return a||!i||t.kind!==`idle`?void 0:Jo(n)}function Zo(e){return e.type!==`assistant/live-chunk`}function Qo(e){if(e.type===`assistant/message`||e.type===`assistant/attempt`||e.type===`assistant/live-chunk`||e.type===`step/start`||e.type===`step/end`||e.type===`llm/retry`||e.type===`llm/retry-started`)return{turn:e.data.turn,step:e.data.step}}function $o(e){let t=e.start?.location??e.matches[0]?.location;return t?.kind===`turn`||t?.kind===`step`?t.turn:void 0}function es(e){return e.finalNode!==void 0&&e.blocks.some(e=>e.kind===`text`&&e.text.trim()!==``)}function ts(e){let t=e.state===void 0?e.matches.find(e=>e.event.type===`turn/end`):e.state.end;if(t?.event.type!==`turn/end`)return null;let n=$o(e);if(n===void 0)return null;let r=n.steps.map(e=>e.data.get(`assistant-step`)).filter(e=>e!==void 0).filter(e=>e.finalNode!==void 0).sort((e,t)=>e.finalNode.seq-t.finalNode.seq),i=r.findLast(es)??null,a=r.at(-1)?.finalNode.seq;for(let t of e.matches){let e=t.event,n=e.type===`tool/call`||e.type===`tool/result`&&e.surfaceOp===`append`||e.type===`turn/end`&&e.data.reason.kind===`error`||e.type===`llm/retry`?e.seq:void 0;n!==void 0&&(a===void 0||n>a)&&(a=n)}let o=e.start?.event.type===`turn/start`?Xo(e.matches.map(e=>e.event).filter(Zo)):void 0;return{turn:t.event.data.turn,seq:t.event.seq,time:t.event.time,closing:i,branchUnavailable:i===null||a!==i.finalNode.seq,...o===void 0?{}:{tokenUsage:o}}}let ns={kind:`turn-tail`,target:`chat`,match:e=>{if(e.type===`turn/start`)return{id:String(e.data.turn),role:`start`};if(e.type===`turn/end`||e.type===`tool/call`||e.type===`tool/result`)return{id:String(e.data.turn),role:`update`};let t=Qo(e);return t===void 0?null:{id:String(t.turn),role:`update`}},start:(e,t)=>{if(t.event.type!==`turn/start`)throw Error(`turn-tail start requires turn/start`);return{turn:t.event.data.turn}},update:(e,t)=>t.event.type===`turn/end`?{...e.state,end:t}:e.state,publication:e=>e.event.type===`turn/end`?`immediate`:`none`,buildLocationData:(e,t)=>{if(t!==`turn`)return null;let n=ts(e);return n===null?null:{kind:`turn`,turn:n.turn,key:`turn-tail`,value:n}},buildViewNode:e=>{let t=$o(e)?.data.get(`turn-tail`);return t===void 0?null:J(e,`turn-tail`,t.seq+Br.finalizedFollowup,t)}};function rs(e){let t=ns.match.bind(ns);e.uiConversation.events.register({...ns,match:{"turn/start":t,"turn/end":t,"tool/call":t,"tool/result":t,"assistant/message":t,"assistant/attempt":t,"assistant/live-chunk":t,"step/start":t,"step/end":t,"llm/retry":t,"llm/retry-started":t}})}function is(e){return e===`read`?`read`:e===`read_image`?`readImage`:e===`grep`||e===`glob`||e.endsWith(`_inspect`)?`search`:e===`write`?`write`:e===`edit`||e===`apply_patch`?`edit`:[`bash`,`pwsh`,`exec_command`,`write_stdin`].includes(e)||e.startsWith(`terminal_`)?`commands`:e===`run_code`?`code`:e===`web_search`?`webSearch`:e===`web_fetch`?`webFetch`:e===`subagent`||e.startsWith(`subagent_`)?`subagents`:[`todo_write`,`create_goal`,`update_goal`,`get_goal`].includes(e)?`plan`:e===`ask_user_question`||e===`request_user_input`?`questions`:`tools`}let as=new Intl.Segmenter(void 0,{granularity:`grapheme`}),os=[`title`,`description`,`objective`,`task`,`task_name`,`name`,`question`,`questions`,`prompt`,`message`,`command`,`cmd`,`queries`,`query`,`pattern`,`url`,`uri`,`file_path`,`path`,`target`,`action`,`status`];function ss(e){let t=e.replace(/\s+/g,` `).trim();if(t.length<=160)return{text:t,truncated:!1};let n=[];for(let{segment:e}of as.segment(t)){if(n.length===160)return{text:`${n.slice(0,159).join(``).trimEnd()}…`,truncated:!0};n.push(e)}return{text:t,truncated:!1}}function cs(e){return ss(typeof e==`string`?e:Array.isArray(e)&&e.every(e=>typeof e==`string`)?e.join(`, `):``).text}function ls(e,t){let n=512;for(;;){let r=e.textPrefix(t,n);if(r===void 0)return;let i=r.charCodeAt(r.length-1);if(i>=55296&&i<=56319){let i=e.textPrefix(t,n+1),a=i.charCodeAt(r.length);a>=56320&&a<=57343?(r=i,n++):i.length===r.length&&!e.isSealed&&!e.complete(t)&&(r=r.slice(0,-1))}let a=ss(r);if(a.truncated||!e.stringExceeds(t,n))return a.text;n*=2}}function us(e){if(!Array.isArray(e))return``;for(let t of e){if(typeof t!=`object`||!t)continue;let e=cs(Reflect.get(t,`question`));if(e!==``)return e}return``}function ds(e){for(let t=e.length-1;t>=0;t--){let n=e[t];if(n?.kind===`assistant-step`&&n.data.status===`running`)for(let e=n.data.blocks.length-1;e>=0;e--){let t=n.data.blocks[e];if(t?.kind!==`reasoning`)continue;let r=t.text.split(/\r?\n[\t ]*\r?\n/);for(let e=r.length-1;e>=0;e--){let t=cs(r[e]?.replaceAll(`**`,``));if(t!==``)return t}}}return``}function fs(e,t){for(let e of os){if(!t.has(e))continue;let n=e===`questions`?us(t.value(e)):ls(t,e)??cs(t.value(e));if(n!==``)return n}return t.closed()?cs(e):``}function ps(e){let t=/* @__PURE__ */ new Map,n=/* @__PURE__ */ new Set,r,i=``,a=-1/0,o,s=e=>{if(n.has(e.callId))return;n.add(e.callId);let c=vi(e)?e:e.call;if(c!==null){let n=is(c.name);vi(e)&&e.time>=a&&(r=n,o=e.phase===`preparing`,i=fs(e.name,e.args),a=e.time),t.set(n,(t.get(n)??0)+1)}for(let t of e.subCalls)s(t)};for(let t of e)t.kind===`tool-call`&&s(t.data.root);return r===void 0&&(i=ds(e)),{counts:[...t].map(([e,t])=>({kind:e,count:t})).sort((e,t)=>t.count-e.count),running:r,runningDetail:i,...o?{preparing:!0}:{}}}let ms=/* @__PURE__ */ new Set([`user`,`steering`,`turn-trigger`,`model-retry`,`turn-error`,`turn-max-tokens`,`turn-tail`]);function hs(e){let t=e.location;return t.kind===`turn`||t.kind===`step`?t.turn.turn:void 0}function gs(e){return ms.has(e.kind)||e.kind===`tool-call`&&pt(e.data.root.name)}function _s(e){return e.kind===`assistant-step`&&e.data.blocks.some(e=>e.kind===`reasoning`&&e.text.trim()!==``)}function vs(e){return e.kind===`assistant-step`&&Dr(e.data.blocks)}function ys(e,t){return e.running===t.running&&e.runningDetail===t.runningDetail&&e.preparing===t.preparing&&e.counts.length===t.counts.length&&e.counts.every((e,n)=>e.kind===t.counts[n]?.kind&&e.count===t.counts[n].count)}function bs(e,t){return e.length===t.length&&e.every((e,n)=>e.key===t[n]?.key&&e.groupPart===t[n].groupPart)}function xs(e,t){return!yi(t)&&(e===void 0||!yi(e))?!1:e===void 0||e.kind!==t.kind||hs(e)!==hs(t)||yi(e)!==yi(t)||_s(e)!==_s(t)||vs(e)!==vs(t)}function Ss(e,t){let n=e.readNode(t);if(n===void 0)throw Error(`Chat grouping input is missing Node ${t}`);return n}function Cs(e,t){let n=/* @__PURE__ */ new Set;for(let r of t){let t=Ss(e,r);t.kind===`question-reply`&&n.add(t.id)}return n}var ws=class{key;turn;members;nodes=[];snapshot;constructor(e,t,n){this.key=e,this.turn=t,this.members=n,this.snapshot={key:e,members:n,data:{turn:t,closed:!1,summary:{counts:[],running:void 0,runningDetail:``}}}}refresh(e,t){let n=this.members.map(t=>Ss(e,t.key)),r=n.length===this.nodes.length&&n.every((e,t)=>e===this.nodes[t]),i=this.snapshot.data,a=r&&i.closed===t?i.summary:ps(n),o=t?{counts:a.counts,running:void 0,runningDetail:``}:a;this.nodes=n,(i.closed!==t||!ys(i.summary,o))&&(this.snapshot={key:this.key,members:this.members,data:{turn:this.turn,closed:t,summary:o}})}},Ts=class{turn;groups=/* @__PURE__ */ new Map;membership=/* @__PURE__ */ new Map;roots=/* @__PURE__ */ new Map;constructor(e){this.turn=e}references(e){return this.roots.get(e)??[]}snapshots(){return[...this.groups.values()].map(e=>e.snapshot)}refresh(e,t){let n=/* @__PURE__ */ new Set;for(let e of t){let t=this.membership.get(e);t!==void 0&&n.add(t)}let r=e.timeline.turns.get(this.turn)?.status===`closed`;if(r)for(let e of this.groups.values())e.snapshot.data.closed||n.add(e.key);let i=[];for(let t of n){let n=this.groups.get(t),a=n.snapshot;n.refresh(e,a.data.closed||r),n.snapshot!==a&&i.push(n.snapshot)}return i}rebuild(e,t){let n=/* @__PURE__ */ new Map,r=/* @__PURE__ */ new Map,i=/* @__PURE__ */ new Map,a=[],o=[],s=(e,t)=>{n.set(e,[...n.get(e)??[],t])},c=n=>{let c=a[0];if(c===void 0)return;let l=this.extendedGroup(a,t)?.key??On(JSON.stringify([`process`,c.key,c.groupPart??null])),u=this.groups.get(l),d=u?.snapshot,f=u!==void 0&&bs(u.members,a)?u:new ws(l,this.turn,a);f.refresh(e,n||e.timeline.turns.get(this.turn)?.status===`closed`),r.set(f.key,f),s(c.key,{kind:`group`,key:f.key});for(let e of a)i.set(e.key,f.key);f.snapshot!==d&&o.push(f.snapshot),a=[]},l,u=!1,d=e.readTurn(this.turn),f=Cs(e,d);for(let t of d){let n=Es(e,t);l!==void 0&&n.previous!==l&&c(!0),l=t,u=n.next!==void 0;let r=Ss(e,t);r.kind===`turn-trigger`&&f.has(r.id)||(gs(r)?(c(!0),s(t,{kind:`node`,key:t})):r.kind===`turn-process`?s(a[0]?.key??t,{kind:`node`,key:t}):r.kind===`assistant-step`?(_s(r)&&a.push({kind:`node`,key:t,groupPart:`reasoning`}),vs(r)&&(c(!0),s(t,{kind:`node`,key:t,groupPart:`response`}))):a.push({kind:`node`,key:t}))}c(u);let p=[...this.groups.keys()].filter(e=>!r.has(e));return this.groups=r,this.membership=i,this.roots=n,{upserts:o,removes:p}}extendedGroup(e,t){let n=e.findIndex(e=>!t.has(e.key)),r=e[n];if(r===void 0)return;let i=this.membership.get(r.key),a=i===void 0?void 0:this.groups.get(i);if(!(a===void 0||n+a.members.length>e.length)){for(let t=0;t<a.members.length;t++){let r=a.members[t],i=e[n+t];if(r.key!==i.key||r.groupPart!==i.groupPart)return}for(let r=n+a.members.length;r<e.length;r++)if(!t.has(e[r].key))return;return a}}};function Es(e,t){let n=e.readPosition(t);if(n===void 0)throw Error(`Chat grouping order is missing position for Node ${t}`);return n}var Ds=class{turns=/* @__PURE__ */ new Map;order=[];pending=null;accept(e){if(e.kind===`replace`){let t=new Set(this.order),n=new Set(e.order.filter(e=>!t.has(e))),r=/* @__PURE__ */ new Map;for(let t of e.order){let i=Es(e,t).turn;if(i===void 0||r.has(i))continue;let a=this.turns.get(i)??new Ts(i);a.rebuild(e,n),r.set(i,a)}this.turns=r,this.order=e.order,this.pending={entries:this.rootEntries(e),groups:{kind:`replace`,snapshots:[...r.values()].flatMap(e=>e.snapshots())}};return}let t=new Set(e.changedTurnOrders),n=/* @__PURE__ */ new Set,r=/* @__PURE__ */ new Map,i=e=>{let t=r.get(e);return t===void 0&&(t=/* @__PURE__ */ new Set,r.set(e,t)),t};for(let r of e.changes){let e=r.previous,a=r.current,o=hs(a);if((e===void 0||!yi(e))&&n.add(a.key),xs(e,a)){let n=e===void 0?void 0:hs(e);n!==void 0&&t.add(n),o!==void 0&&t.add(o)}o!==void 0&&i(o).add(a.key)}for(let t of e.changedTurns)i(t);let a=[],o=[];for(let r of t){let t=this.turns.get(r)??new Ts(r),i=t.rebuild(e,n);a.push(...i.upserts),o.push(...i.removes),e.readTurn(r).length===0?this.turns.delete(r):this.turns.set(r,t)}for(let[n,i]of r)t.has(n)||a.push(...this.turns.get(n)?.refresh(e,i)??[]);let s=e.order!==this.order||t.size>0;this.order=e.order;let c=new Set(a.map(e=>e.key));this.pending=s||a.length>0||o.length>0?{...s?{entries:this.rootEntries(e)}:{},groups:{kind:`apply`,upserts:a,removes:o.filter(e=>!c.has(e))}}:null}rootEntries(e){let t=Cs(e,e.order.filter(t=>Es(e,t).turn===void 0));return e.order.flatMap(n=>{let r=Es(e,n).turn;if(r===void 0){let r=Ss(e,n);return r.kind===`turn-trigger`&&t.has(r.id)?[]:[{kind:`node`,key:n}]}let i=this.turns.get(r);if(i===void 0)throw Error(`Chat grouping order is missing Turn ${r}`);return i.references(n)})}output(){return this.pending}};let Os={kind:`process-groups`,target:`chat`,create:()=>new Ds,update:(e,t)=>(e.state.accept(t),e.state),buildGroups:e=>e.state.output()};function ks(e){Ba(e),Ga(e),Xa(e),gi(e),Ho(e),yo(e),Ea(e),ka(e),eo(e),wo(e),ko(e),rs(e),ja(e),ma(e),e.uiConversation.groups.register(Os)}function As({useNotice:e,dismissNotice:t,keepNoticeOpen:n,renderSlotChain:r,t:i}){let a=e(e=>e);if(a===null)return null;let o={code:a.code,message:i(`message.failure.quota`),dismiss:t,keepOpen:n};return/* @__PURE__ */ (0,f.jsx)(d.Fragment,{children:r(`shell.quota-notice`,o,{fallback:/* @__PURE__ */ (0,f.jsx)(p.Toast,{text:o.message,icon:/* @__PURE__ */ (0,f.jsx)(p.IconWarningOutlineRegular,{size:18}),onDone:t})})},`quota-notice-${String(a.seq)}`)}function X(e){return e==null}function js(e){return e&&typeof e==`object`&&!Array.isArray(e)}function Ms(e,t){return Object.fromEntries(Object.entries(e).filter(([e,n])=>t(e,n)))}function Ns(e,t){return Object.fromEntries(Object.entries(e).map(([e,n])=>[e,t(n,e)]))}function Ps(e,t,n){if(!t)return{...e};let r={};for(let i of t)(n||e[i]!==void 0)&&(r[i]=e[i]);return r}let Fs=Symbol.for(`cosmokit.volatile.write`);function Is(e,t=/* @__PURE__ */ new Set){if(typeof e==`function`)throw TypeError(`volatile config cannot contain functions`);if(typeof e!=`object`||!e)return e;if(t.has(e))throw TypeError(`volatile config cannot contain cycles`);t.add(e);try{if(Array.isArray(e))return Object.freeze(e.map(e=>Is(e,t)));if(Object.getPrototypeOf(e)!==Object.prototype&&Object.getPrototypeOf(e)!==null)throw TypeError(`volatile config objects must be plain objects or arrays`);return Object.freeze(Object.fromEntries(Object.entries(e).map(([e,n])=>[e,Is(n,t)])))}finally{t.delete(e)}}function Ls(e){let t=Is(e);return Object.freeze({get:()=>t,[Fs]:e=>{t=e}})}function Rs(e){return typeof e==`object`&&!!e&&Fs in e}function zs(e,t){return arguments.length===1?t=>zs(e,t):e in globalThis&&t instanceof globalThis[e]||Object.prototype.toString.call(t).slice(8,-1)===e}function Bs(e){return zs(`ArrayBuffer`,e)||zs(`SharedArrayBuffer`,e)}function Vs(e){return Bs(e)||ArrayBuffer.isView(e)}let Hs;(function(e){e.is=Bs,e.isSource=Vs;function t(e){return ArrayBuffer.isView(e)?e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength):e}e.fromSource=t;function n(e){if(e=t(e),typeof Buffer<`u`)return Buffer.from(e).toString(`base64`);let n=``,r=new Uint8Array(e);for(let e=0;e<r.byteLength;e++)n+=String.fromCharCode(r[e]);return btoa(n)}e.toBase64=n;function r(e){return typeof Buffer<`u`?t(Buffer.from(e,`base64`)):Uint8Array.from(atob(e),e=>e.charCodeAt(0))}e.fromBase64=r;function i(e){return e=t(e),typeof Buffer<`u`?Buffer.from(e).toString(`hex`):Array.from(new Uint8Array(e),e=>e.toString(16).padStart(2,`0`)).join(``)}e.toHex=i;function a(e){if(typeof Buffer<`u`)return t(Buffer.from(e,`hex`));let n=e.length%2==0?e:e.slice(0,e.length-1),r=[];for(let e=0;e<n.length;e+=2)r.push(parseInt(`${n[e]}${n[e+1]}`,16));return Uint8Array.from(r).buffer}e.fromHex=a})(Hs||={}),Hs.fromBase64,Hs.toBase64,Hs.fromHex,Hs.toHex;function Us(e,t=/* @__PURE__ */ new Map){if(!e||typeof e!=`object`)return e;if(zs(`Date`,e))return new Date(e.valueOf());if(zs(`RegExp`,e))return new RegExp(e.source,e.flags);if(Bs(e))return e.slice(0);if(ArrayBuffer.isView(e))return e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength);let n=t.get(e);if(n)return n;if(Array.isArray(e)){let n=[];return t.set(e,n),e.forEach((e,r)=>{n[r]=Reflect.apply(Us,null,[e,t])}),n}let r=Object.create(Object.getPrototypeOf(e));t.set(e,r);for(let n of Reflect.ownKeys(e)){let i={...Reflect.getOwnPropertyDescriptor(e,n)};`value`in i&&(i.value=Reflect.apply(Us,null,[i.value,t])),Reflect.defineProperty(r,n,i)}return r}function Ws(e,t,n){let r=/* @__PURE__ */ new Set;function i(e,t){if(e===t)return!0;if(Rs(e)||Rs(t))return Rs(e)&&Rs(t);if(!n&&X(e)&&X(t))return!0;if(typeof e!=typeof t||typeof e!=`object`||!e||!t||r.has(e))return!1;function a(n,r){return n(e)?n(t)?r(e,t):!1:!n(t)&&void 0}r.add(e);try{return a(Array.isArray,(e,t)=>{if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!i(e[n],t[n]))return!1;return!0})??a(zs(`Date`),(e,t)=>e.valueOf()===t.valueOf())??a(zs(`URL`),(e,t)=>e.href===t.href)??a(zs(`RegExp`),(e,t)=>e.source===t.source&&e.flags===t.flags)??a(Bs,(e,t)=>{if(e.byteLength!==t.byteLength)return!1;let n=new Uint8Array(e),r=new Uint8Array(t);for(let e=0;e<n.length;e++)if(n[e]!==r[e])return!1;return!0})??((!n||[e,t].every(e=>Object.getPrototypeOf(e)===Object.prototype||Object.getPrototypeOf(e)===null))&&Object.keys({...e,...t}).every(n=>i(e[n],t[n])))}finally{r.delete(e)}}return i(e,t)}let Gs;(function(e){e.millisecond=1;let t=e.second=1e3,n=e.minute=t*60,r=e.hour=n*60,i=e.day=r*24,a=e.week=i*7,o=(/* @__PURE__ */ new Date()).getTimezoneOffset();function s(e){o=e}e.setTimezoneOffset=s;function c(){return o}e.getTimezoneOffset=c;function l(e=/* @__PURE__ */ new Date,t){return typeof e==`number`&&(e=new Date(e)),t===void 0&&(t=o),Math.floor((e.valueOf()/n-t)/1440)}e.getDateNumber=l;function u(e,t){let r=new Date(e*i);return t===void 0&&(t=o),new Date(+r+t*n)}e.fromDateNumber=u;let d=RegExp(`^${[`w(?:eek(?:s)?)?`,`d(?:ay(?:s)?)?`,`h(?:our(?:s)?)?`,`m(?:in(?:ute)?(?:s)?)?`,`s(?:ec(?:ond)?(?:s)?)?`].map(e=>`(\\d+(?:\\.\\d+)?${e})?`).join(``)}$`);function f(e){let o=d.exec(e);return o?(parseFloat(o[1])*a||0)+(parseFloat(o[2])*i||0)+(parseFloat(o[3])*r||0)+(parseFloat(o[4])*n||0)+(parseFloat(o[5])*t||0):0}e.parseTime=f;function p(e){let t=f(e);return t?e=Date.now()+t:/^\d{1,2}(:\d{1,2}){1,2}$/.test(e)?e=`${(/* @__PURE__ */ new Date()).toLocaleDateString()}-${e}`:/^\d{1,2}-\d{1,2}-\d{1,2}(:\d{1,2}){1,2}$/.test(e)&&(e=`${(/* @__PURE__ */ new Date()).getFullYear()}-${e}`),e?new Date(e):/* @__PURE__ */ new Date}e.parseDate=p;function m(e){let a=Math.abs(e);return a>=i-r/2?Math.round(e/i)+`d`:a>=r-n/2?Math.round(e/r)+`h`:a>=n-t/2?Math.round(e/n)+`m`:a>=t?Math.round(e/t)+`s`:e+`ms`}e.format=m;function h(e,t=2){return e.toString().padStart(t,`0`)}e.toDigits=h;function g(e,t=/* @__PURE__ */ new Date){return e.replace(`yyyy`,t.getFullYear().toString()).replace(`yy`,t.getFullYear().toString().slice(2)).replace(`MM`,h(t.getMonth()+1)).replace(`dd`,h(t.getDate())).replace(`hh`,h(t.getHours())).replace(`mm`,h(t.getMinutes())).replace(`ss`,h(t.getSeconds())).replace(`SSS`,h(t.getMilliseconds(),3))}e.template=g})(Gs||={});let Ks=Symbol.for(`schemastery`),qs=Symbol.for(`ValidationError`);globalThis.__schemastery_index__??=0,globalThis.__schemastery_refs__=void 0;var Z=class extends TypeError{options;name=`ValidationError`;constructor(e,t){let n=`$`;for(let e of t.path||[])typeof e==`string`?n+=`.`+e:typeof e==`number`?n+=`[`+e+`]`:typeof e==`symbol`&&(n+=`[Symbol(${e.toString()})]`);n.startsWith(`.`)&&(n=n.slice(1)),super((n===`$`?``:`${n} `)+e),this.options=t}static is(e){return!!e?.[qs]}};Object.defineProperty(Z.prototype,qs,{value:!0});let Q=function(e){let t=function(e,n={}){return Q.resolve(e,t,n)[0]};if(e.refs){let t=Ns(e.refs,e=>new Q(e)),n=e=>t[e];for(let e in t){let r=t[e];r.sKey=n(r.sKey),r.inner=n(r.inner),r.list=r.list&&r.list.map(n),r.dict=r.dict&&Ns(r.dict,n)}return t[e.uid]}if(Object.assign(t,e),typeof t.callback==`string`)try{t.callback=Function(`return `+t.callback)()}catch{}return Object.defineProperty(t,"uid",{value:globalThis.__schemastery_index__++}),Object.setPrototypeOf(t,Q.prototype),t.meta||={},t.toString=t.toString.bind(t),t};Q.prototype=Object.create(Function.prototype),Q.prototype[Ks]=!0,Object.defineProperty(Q.prototype,"~standard",{get(){return{version:1,vendor:`schemastery`,validate:e=>{try{return{value:Q.resolve(e,this,{})[0]}}catch(e){if(Z.is(e))return{issues:[{message:e.message,path:e.options.path}]};throw e}}}}}),Q.ValidationError=Z,Q.prototype.toJSON=function(){if(globalThis.__schemastery_refs__)return globalThis.__schemastery_refs__[this.uid]??=JSON.parse(JSON.stringify({...this})),this.uid;globalThis.__schemastery_refs__={[this.uid]:{...this}},globalThis.__schemastery_refs__[this.uid]=JSON.parse(JSON.stringify({...this}));let e={uid:this.uid,refs:globalThis.__schemastery_refs__};return globalThis.__schemastery_refs__=void 0,e},Q.prototype.set=function(e,t){return this.dict[e]=t,this},Q.prototype.push=function(e){return this.list.push(e),this};function Js(e,t){let n=typeof e==`string`?{"":e}:{...e};for(let e in t){let r=t[e];r?.$description||r?.$desc?n[e]=r.$description||r.$desc:typeof r==`string`&&(n[e]=r)}return n}function Ys(e){return e?.$value??e?.$inner}function Xs(e){return Ms(e??{},e=>!e.startsWith(`$`))}Q.prototype.i18n=function(e){let t=Q(this),n=Js(t.meta.description,e);return Object.keys(n).length&&(t.meta.description=n),t.dict&&=Ns(t.dict,(t,n)=>t.i18n(Ns(e,e=>Ys(e)?.[n]??e?.[n]))),t.list&&=t.list.map((t,n)=>t.i18n(Ns(e,(e={})=>Array.isArray(Ys(e))?Ys(e)[n]:Array.isArray(e)?e[n]:Xs(e)))),t.inner&&=t.inner.i18n(Ns(e,e=>Ys(e)?Ys(e):Xs(e))),t.sKey&&=t.sKey.i18n(Ns(e,e=>e?.$key)),t},Q.prototype.extra=function(e,t){let n=Q(this);return n.meta={...n.meta,[e]:t},n};for(let e of[`required`,`disabled`,`collapse`,`hidden`,`loose`])Object.assign(Q.prototype,{[e](t=!0){let n=Q(this);return n.meta={...n.meta,[e]:t},n}});Q.prototype.deprecated=function(){let e=Q(this);return e.meta.badges||=[],e.meta.badges.push({text:`deprecated`,type:`danger`}),e},Q.prototype.experimental=function(){let e=Q(this);return e.meta.badges||=[],e.meta.badges.push({text:`experimental`,type:`warning`}),e},Q.prototype.pattern=function(e){let t=Q(this),n=Ps(e,[`source`,`flags`]);return t.meta={...t.meta,pattern:n},t},Q.prototype.simplify=function(e){if(Rs(e)&&(e=e.get()),Ws(e,this.meta.default,this.type===`dict`))return null;if(X(e))return e;if(this.type===`object`||this.type===`dict`){let t={};for(let n in e){let r=(this.type===`object`?this.dict[n]:this.inner)?.simplify(e[n]);(this.type===`dict`||!X(r))&&(t[n]=r)}return Ws(t,this.meta.default,this.type===`dict`)?null:t}if(this.type===`array`||this.type===`tuple`){let t=[];return e.forEach((e,n)=>{let r=this.type===`array`?this.inner:this.list[n],i=r?r.simplify(e):e;t.push(i)}),t}if(this.type===`intersect`){let t={};for(let n of this.list)Object.assign(t,n.simplify(e));return t}if(this.type===`union`)for(let t of this.list)try{return Q.resolve(e,t,{}),t.simplify(e)}catch{}return e},Q.prototype.toString=function(e){return ac[this.type]?.(this,e)??`Schema<${this.type}>`},Q.prototype.role=function(e,t){let n=Q(this);return n.meta={...n.meta,role:e,extra:t},n};for(let e of[`default`,`link`,`comment`,`description`,`max`,`min`,`step`])Object.assign(Q.prototype,{[e](t){let n=Q(this);return n.meta={...n.meta,[e]:t},n}});Q.prototype.volatile=function(){if(this.meta.volatile)throw TypeError(`volatile schema is already wrapped`);return this.extra(`volatile`,!0)};let Zs={},Qs=Symbol(`checked-volatile-schema`);function $s(e,t=[],n=!1,r=/* @__PURE__ */ new Map){let i=r.get(e)??/* @__PURE__ */ new Set;if(i.has(n))return;if(i.add(n),r.set(e,i),e.meta?.volatile&&n)throw new Z(`volatile fields require a fixed object path without an enclosing volatile field`,{path:t});let a=n||!!e.meta?.volatile;if(e.dict)for(let[n,i]of Object.entries(e.dict))$s(i,[...t,n],a,r);if(e.sKey&&$s(e.sKey,[...t,`<key>`],!0,r),e.inner&&(e.type!==`lazy`||e.inner[Ks])&&$s(e.inner,[...t,`*`],!0,r),e.list)for(let n=0;n<e.list.length;n++)$s(e.list[n],[...t,String(n)],!0,r)}Q.extend=function(e,t){Zs[e]=t},Q.resolve=function(e,t,n={},r=!1){if(!t)return[e];if(n[Qs]||($s(t,n.path),n={...n,[Qs]:!0}),t.meta?.volatile){let i=Q(t);i.meta={...t.meta,volatile:!1};let[a,o]=Q.resolve(e,i,n,r);try{return[Ls(a),o]}catch(e){throw new Z(e instanceof Error?e.message:String(e),n)}}if(n.ignore?.(e,t))return[e];if(X(e)&&t.type!==`lazy`){if(t.meta.required)throw new Z(`missing required value`,n);let r=t,i=t.meta.default;for(;r?.type===`intersect`&&X(i);)r=r.list[0],i=r?.meta.default;if(X(i))return[e];e=Us(i)}let i=Zs[t.type];if(!i)throw new Z(`unsupported type "${t.type}"`,n);try{return i(e,t,n,r)}catch(e){if(!t.meta.loose)throw e;return[t.meta.default]}},Q.from=function(e){if(X(e))return Q.any();if([`string`,`number`,`boolean`].includes(typeof e))return Q.const(e).required();if(e[Ks])return e;if(typeof e==`function`)switch(e){case String:return Q.string().required();case Number:return Q.number().required();case Boolean:return Q.boolean().required();case Function:return Q.function().required();default:return Q.is(e).required()}else throw TypeError(`cannot infer schema from ${e}`)},Q.lazy=function(e){let t=new Q({type:`lazy`,builder:e,inner:{toJSON:()=>(t.inner[Ks]||(t.inner=t.builder(),t.inner.meta={...t.meta,...t.inner.meta}),t.inner.toJSON())}});return t},Q.natural=function(){return Q.number().step(1).min(0)},Q.percent=function(){return Q.number().step(.01).min(0).max(1).role(`slider`)},Q.date=function(){return Q.union([Q.is(Date),Q.transform(Q.string().role(`datetime`),(e,t)=>{let n=new Date(e);if(isNaN(+n))throw new Z(`invalid date "${e}"`,t);return n},!0)])},Q.regExp=function(e=``){return Q.union([Q.is(RegExp),Q.transform(Q.string().role(`regexp`,{flag:e}),(t,n)=>{try{return new RegExp(t,e)}catch(e){throw new Z(e.message,n)}},!0)])},Q.arrayBuffer=function(e){return Q.union([Q.is(ArrayBuffer),Q.is(SharedArrayBuffer),Q.transform(Q.any(),(e,t)=>{if(Hs.isSource(e))return Hs.fromSource(e);throw new Z(`expected ArrayBufferSource but got ${e}`,t)},!0),...e?[Q.transform(Q.string(),(t,n)=>{try{return e===`base64`?Hs.fromBase64(t):Hs.fromHex(t)}catch(e){throw new Z(e.message,n)}},!0)]:[]])},Q.extend(`lazy`,(e,t,n,r)=>(t.inner[Ks]||(t.inner=t.builder(),t.inner.meta={...t.meta,...t.inner.meta},$s(t.inner,n.path,!0)),Q.resolve(e,t.inner,n,r))),Q.extend(`any`,e=>[e]),Q.extend(`never`,(e,t,n)=>{throw new Z(`expected nullable but got ${e}`,n)}),Q.extend(`const`,(e,{value:t},n)=>{if(Ws(e,t))return[t];throw new Z(`expected ${t} but got ${e}`,n)});function ec(e,t,n,r,i=!1){let{max:a=1/0,min:o=-1/0}=t;if(e>a)throw new Z(`expected ${n} <= ${a} but got ${e}`,r);if(e<o&&!i)throw new Z(`expected ${n} >= ${o} but got ${e}`,r)}Q.extend(`string`,(e,{meta:t},n)=>{if(typeof e!=`string`)throw new Z(`expected string but got ${e}`,n);if(t.pattern){let r=new RegExp(t.pattern.source,t.pattern.flags);if(!r.test(e))throw new Z(`expect string to match regexp ${r}`,n)}return ec(e.length,t,`string length`,n),[e]});function tc(e,t){let n=e.toString();if(n.includes(`e`))return e*10**t;let r=n.indexOf(`.`);if(r===-1)return e*10**t;let i=n.slice(r+1),a=n.slice(0,r);return i.length<=t?+(a+i.padEnd(t,`0`)):+(a+i.slice(0,t)+`.`+i.slice(t))}function nc(e,t,n){if(n=Math.abs(n),!/^\d+\.\d+$/.test(n.toString()))return(e-t)%n===0;let r=n.toString().indexOf(`.`),i=n.toString().slice(r+1).length;return Math.abs(tc(e,i)-tc(t,i))%tc(n,i)===0}Q.extend(`number`,(e,{meta:t},n)=>{if(typeof e!=`number`)throw new Z(`expected number but got ${e}`,n);ec(e,t,`number`,n);let{step:r}=t;if(r&&!nc(e,t.min??0,r))throw new Z(`expected number multiple of ${r} but got ${e}`,n);return[e]}),Q.extend(`boolean`,(e,t,n)=>{if(typeof e==`boolean`)return[e];throw new Z(`expected boolean but got ${e}`,n)}),Q.extend(`bitset`,(e,{bits:t,meta:n},r)=>{let i=0,a=[];if(typeof e==`number`){i=e;for(let n in t)e&t[n]&&a.push(n)}else if(Array.isArray(e)){a=e;for(let e of a){if(typeof e!=`string`)throw new Z(`expected string but got ${e}`,r);e in t&&(i|=t[e])}}else throw new Z(`expected number or array but got ${e}`,r);return i===n.default?[i]:[i,a]}),Q.extend(`function`,(e,t,n)=>{if(typeof e==`function`)return[e];throw new Z(`expected function but got ${e}`,n)}),Q.extend(`is`,(e,{constructor:t},n)=>{if(typeof t==`function`){if(e instanceof t)return[e];throw new Z(`expected ${t.name} but got ${e}`,n)}{if(X(e))throw new Z(`expected ${t} but got ${e}`,n);let r=Object.getPrototypeOf(e);for(;r;){if(r.constructor?.name===t)return[e];r=Object.getPrototypeOf(r)}throw new Z(`expected ${t} but got ${e}`,n)}});function rc(e,t,n,r){try{let[i,a]=Q.resolve(e[t],n,{...r,path:[...r.path||[],t]});return a!==void 0&&(e[t]=a),i}catch(i){if(!r?.autofix)throw i;return delete e[t],n.meta.volatile?Ls(n.meta.default):n.meta.default}}Q.extend(`array`,(e,{inner:t,meta:n},r)=>{if(!Array.isArray(e))throw new Z(`expected array but got ${e}`,r);return ec(e.length,n,`array length`,r,!X(t.meta.default)),[e.map((n,i)=>rc(e,i,t,r))]}),Q.extend(`dict`,(e,{inner:t,sKey:n},r,i)=>{if(!js(e))throw new Z(`expected object but got ${e}`,r);let a={};for(let o in e){let s;try{s=Q.resolve(o,n,r)[0]}catch(e){if(i)continue;throw e}a[s]=rc(e,o,t,r),e[s]=e[o],o!==s&&delete e[o]}return[a]}),Q.extend(`tuple`,(e,{list:t},n,r)=>{if(!Array.isArray(e))throw new Z(`expected array but got ${e}`,n);let i=t.map((t,r)=>rc(e,r,t,n));return r||i.push(...e.slice(t.length)),[i]});function ic(e,t){for(let n in t)n in e||(e[n]=t[n])}Q.extend(`object`,(e,{dict:t},n,r)=>{if(!js(e))throw new Z(`expected object but got ${e}`,n);let i={};for(let r in t){let a=rc(e,r,t[r],n);(!X(a)||r in e)&&(i[r]=a)}return r||ic(i,e),[i]}),Q.extend(`union`,(e,{list:t,toString:n},r,i)=>{let a=[];for(let n of t)try{return Q.resolve(e,n,r,i)}catch(e){a.push(e)}throw new Z(`expected ${n()} but got ${JSON.stringify(e)}`,r)}),Q.extend(`intersect`,(e,{list:t,toString:n},r,i)=>{if(!t.length)return[e];let a;for(let i of t){let t=Q.resolve(e,i,r,!0)[0];if(!X(t)){if(X(a))a=t;else if(typeof a!=typeof t)throw new Z(`expected ${n()} but got ${JSON.stringify(e)}`,r);else if(typeof t==`object`)ic(a??={},t);else if(a!==t)throw new Z(`expected ${n()} but got ${JSON.stringify(e)}`,r)}}return!i&&js(e)&&ic(a,e),[a]}),Q.extend(`transform`,(e,{inner:t,callback:n,preserve:r},i)=>{let[a,o=e]=Q.resolve(e,t,i,!0);return r?[n(a)]:[n(a),n(o)]});let ac={};function $(e,t,n){ac[e]=n,Object.assign(Q,{[e](...n){let r=new Q({type:e});return t.forEach((e,t)=>{switch(e){case`sKey`:r.sKey=n[t]??Q.string();break;case`inner`:r.inner=Q.from(n[t]);break;case`list`:r.list=n[t].map(Q.from);break;case`dict`:r.dict=Ns(n[t],Q.from);break;case`bits`:r.bits={};for(let e in n[t])typeof n[t][e]==`number`&&(r.bits[e]=n[t][e]);break;case`callback`:{let e=r.callback=n[t];e.toJSON||=()=>e.toString();break}case`constructor`:{let e=r.constructor=n[t];typeof e==`function`&&(e.toJSON||=()=>e.name);break}default:r[e]=n[t]}}),e===`object`||e===`dict`?r.meta.default={}:e===`array`||e===`tuple`?r.meta.default=[]:e===`bitset`&&(r.meta.default=0),r}})}$(`is`,[`constructor`],({constructor:e})=>typeof e==`function`?e.name:e),$(`any`,[],()=>`any`),$(`never`,[],()=>`never`),$(`const`,[`value`],({value:e})=>typeof e==`string`?JSON.stringify(e):e),$(`string`,[],()=>`string`),$(`number`,[],()=>`number`),$(`boolean`,[],()=>`boolean`),$(`bitset`,[`bits`],()=>`bitset`),$(`function`,[],()=>`function`),$(`array`,[`inner`],({inner:e})=>`${e.toString(!0)}[]`),$(`dict`,[`inner`,`sKey`],({inner:e,sKey:t})=>`{ [key: ${t.toString()}]: ${e.toString()} }`),$(`tuple`,[`list`],({list:e})=>`[${e.map(e=>e.toString()).join(`, `)}]`),$(`object`,[`dict`],({dict:e})=>Object.keys(e).length===0?`{}`:`{ ${Object.entries(e).map(([e,t])=>`${e}${t.meta.required?``:`?`}: ${t.toString()}`).join(`, `)} }`),$(`union`,[`list`],({list:e},t)=>{let n=e.map(({toString:e})=>e()).join(` | `);return t?`(${n})`:n}),$(`intersect`,[`list`],({list:e})=>`${e.map(e=>e.toString(!0)).join(` & `)}`),$(`transform`,[`inner`,`callback`,`preserve`],({inner:e},t)=>e.toString(t));let oc=`transcriptView`,sc=[`compact`,`standard`,`detailed`,`verbose`],cc=[...sc,`normal`,`expanded`],lc=`detailed`,uc={linkOpening:Q.union([`sidebar`,`new-tab`]).default(`sidebar`),[oc]:Q.union([...cc]).loose()};Q.object(uc);let dc=`@deepseek-ai/dsh-client-ui-chat/PreferenceRow.module.css`;if(typeof document<`u`&&document.querySelector(`style[data-plugin-css=`+JSON.stringify(dc)+`]`)===null){let e=document.createElement(`style`);e.dataset.plugin=`@deepseek-ai/dsh-client-ui-chat`,e.dataset.pluginCss=dc,e.textContent=`.Zxrp0W_row{border-bottom:.5px solid var(--dsw-alias-border-l2);align-items:center;gap:8px;padding:16px 0;display:flex}.Zxrp0W_rowText{flex-direction:column;flex:1;gap:4px;min-width:0;padding-right:48px;display:flex}.Zxrp0W_title{color:var(--dsw-alias-label-primary);font-size:14px;font-weight:400;line-height:22px}.Zxrp0W_desc{color:var(--dsw-alias-label-tertiary);font-size:12px;font-weight:400;line-height:18px}.Zxrp0W_selector{border-radius:var(--dsw-radius-md);background:var(--dsw-alias-bg-module-platform);height:36px;font:inherit;color:var(--dsw-alias-label-primary);cursor:pointer;border:none;align-items:center;gap:12px;padding:0 14px;font-size:14px;line-height:22px;display:inline-flex}.Zxrp0W_selector:hover{background:var(--dsw-alias-interactive-bg-hover)}.Zxrp0W_chevron{flex:none}`,document.head.appendChild(e)}var fc={chevron:`Zxrp0W_chevron`,desc:`Zxrp0W_desc`,row:`Zxrp0W_row`,rowText:`Zxrp0W_rowText`,selector:`Zxrp0W_selector`,title:`Zxrp0W_title`};function pc({title:e,description:t,value:n,selectedLabel:r,options:i,onSelect:a}){let[o,s]=(0,d.useState)(!1),c=(0,d.useRef)(null),l=()=>{s(!1)},u=e=>{c.current?.focus({preventScroll:!0}),l(),a(e)},m=/* @__PURE__ */ (0,f.jsxs)(`button`,{ref:c,type:`button`,className:fc.selector,"aria-haspopup":`menu`,"aria-expanded":o,onClick:()=>{s(e=>!e)},children:[r,/* @__PURE__ */ (0,f.jsx)(p.IconChevronDownOutlineRegular,{className:fc.chevron})]});return/* @__PURE__ */ (0,f.jsxs)(`div`,{className:fc.row,children:[/* @__PURE__ */ (0,f.jsxs)(`div`,{className:fc.rowText,children:[/* @__PURE__ */ (0,f.jsx)(`div`,{className:fc.title,children:e}),/* @__PURE__ */ (0,f.jsx)(`div`,{className:fc.desc,children:t})]}),/* @__PURE__ */ (0,f.jsx)(p.Menu,{open:o,onClose:l,items:i,selectedId:n,onSelect:u,align:`end`,portal:!0,anchor:m})]})}let mc={compact:`settings.transcript.compact`,standard:`settings.transcript.standard`,detailed:`settings.transcript.detailed`,verbose:`settings.transcript.verbose`};function hc({useTranscriptView:e,setTranscriptView:t,t:n}){let r=e(e=>e);return/* @__PURE__ */ (0,f.jsx)(pc,{title:n(`settings.transcript.title`),description:n(`settings.transcript.description`),value:r,selectedLabel:n(mc[r]),options:sc.map(e=>({id:e,label:n(mc[e])})),onSelect:e=>{t(e)}})}var gc=class{host;defaultMode;unsubscribe;mode;constructor(e,t=lc){this.host=e,this.defaultMode=t,this.mode=(0,m.createSnapshotStore)(t),this.unsubscribe=e.subscribe(()=>{this.adopt()}),this.adopt()}dispose(){this.unsubscribe()}setMode(e){this.mode.getSnapshot()!==e&&(this.mode.set(e),this.host.set(oc,e))}adopt(){let e=this.host.getSnapshot().value;if(e===void 0)return;let t=e.transcriptView,n=t===`normal`||t===`expanded`?`detailed`:t??this.defaultMode;this.mode.getSnapshot()!==n&&this.mode.set(n)}};let _c={compact:{mode:`compact`,foldCompletedTurns:!0,stepGrouping:`collapsed`,liveProcessDetail:!1,settledReasoningPreview:!1},standard:{mode:`standard`,foldCompletedTurns:!0,stepGrouping:`collapsed`,liveProcessDetail:!0,settledReasoningPreview:!0},detailed:{mode:`detailed`,foldCompletedTurns:!0,stepGrouping:`history`,liveProcessDetail:!0,settledReasoningPreview:!0},verbose:{mode:`verbose`,foldCompletedTurns:!1,stepGrouping:`none`,liveProcessDetail:!1,settledReasoningPreview:!0}};function vc(e){return{getSnapshot:()=>_c[e.getSnapshot()],subscribe:t=>e.subscribe(t)}}function yc({useLinkOpening:e,useBrowserAvailable:t,setLinkOpening:n,t:r}){let i=e(e=>e);return t(e=>e)?/* @__PURE__ */ (0,f.jsx)(pc,{title:r(`settings.links.title`),description:r(`settings.links.description`),value:i,selectedLabel:r(i===`sidebar`?`settings.links.sidebar`:`settings.links.newTab`),options:[{id:`sidebar`,label:r(`settings.links.sidebar`)},{id:`new-tab`,label:r(`settings.links.newTab`)}],onSelect:e=>{n(e)}}):null}let bc={getSnapshot:()=>void 0,subscribe:()=>()=>{}};function xc(e,t){let n=e?.source(t)??bc;return(0,d.useSyncExternalStore)(n.subscribe,n.getSnapshot)}let Sc={hooks:{turnData:(e,{turnData:t})=>function(e){return xc(t,e)},disclosure:(e,{disclosureReset:t})=>Mt(t)}},Cc=[`slots`,`sessions`,`uiWorkspace`,`uiSession`,`uiConversation`,`locale`,`configForms`,`remote`,`remote.session`,`sidebarRight`];function wc(e){let t=(0,m.createSnapshotStore)(null),n=0,r=/* @__PURE__ */ new Set,i=/* @__PURE__ */ new WeakMap,a=/* @__PURE__ */ new Set;e.effect(()=>async()=>{await Promise.all([...a].map(e=>e()))},`ui-chat: live quota notices`);let o=o=>{let s=i.get(o);if(s===void 0){let c=o.ctx.effect(()=>{let e=o.eventSource.subscribe(()=>{let{change:e}=o.eventSource.getSnapshot();if(e.kind===`append`)for(let{event:i}of e.entries){if(i.type!==`turn/end`||i.data.reason.kind!==`error`)continue;let{code:e}=i.data.reason.error;r.size>0||e!==`QUOTA`&&e!==`ACCOUNT_QUOTA`||t.set({code:e,seq:++n})}});return()=>{e(),i.delete(o),a.delete(c)}},`ui-chat: Provider binding quota notices`);a.add(c);let l=e.uiConversation.binding(o).target(`chat`);s={getSnapshot:()=>l.getSnapshot()??ie,subscribe:e=>l.subscribe(e)},i.set(o,s)}return s};ks(e),e.uiSession.provide({hooks:[`chat`],resolve:e=>({hooks:{chat:o(e)}})}),e.effect(()=>e.locale.register(K,{zh:Yn,en:Xn}),`ui-chat: dictionaries`);let s=e.locale.bind(K),c=gt(),l=/* @__PURE__ */ new Map,u=e.configForms.get(`ui-chat`),d=(0,m.createSnapshotStore)(u.getSnapshot().value?.linkOpening??`sidebar`);e.effect(()=>u.subscribe(()=>{let e=u.getSnapshot().value?.linkOpening;e!==void 0&&d.set(e)})),e.inject([`sidebarRightTabs`],e=>{let t=e.sidebarRightTabs,n={getSnapshot:()=>t.get(`browser`)!==void 0,subscribe:e=>t.subscribe(e)};e.slots.inject(`settings.general.item`,()=>e.slots.register({name:`settings.general.item`,id:`link-opening`,order:17,locale:K,inject:()=>({hooks:{linkOpening:d,browserAvailable:n},setLinkOpening:e=>{d.set(e),u.set(`linkOpening`,e).catch(()=>{})}})},yc))});let f=new gc(u,`dshDesktop`in globalThis?`standard`:lc),p=vc(f.mode);e.effect(()=>()=>{f.dispose()}),zr(e,p),e.slots.inject(`settings.general.item`,()=>e.slots.register({name:`settings.general.item`,id:`transcript-view`,order:12,locale:K,inject:()=>({hooks:{transcriptView:f.mode},setTranscriptView:e=>{f.setMode(e)}})},hc)),e.slots.inject(`conversation.view`,()=>e.slots.register({name:`conversation.view`,id:`chat`,order:0,label:()=>s(`view.chat`),locale:K,children:{"conversation.chat.node":{kind:`keyed`,scope:`session`,inject:Sc},"conversation.message.images":{kind:`single`,scope:`session`}},store:c,inject:t=>{let n=e.sessions.binding(t);if(n===void 0)throw Error(`ui-chat: unknown session "${t}"`);let r=n.session,i=o(n),a=e.uiConversation.binding(n),s=e.get(`chatMessageEditing`),c=e.get(`chatTurnDiffs`);return{connection:e.get(`connection`),hooks:{presentation:p},keyedHooks:{chatNode:e=>i.getSnapshot().nodes.source(e),chatNodeProcess:e=>i.getSnapshot().nodes.processSource(e),chatGroup:e=>a.snapshot.getSnapshot().views.grouped(`chat`)?.groupSource(e)},fileMentions:n=>e.get(`chatFileMentions`)?.forClosing(n,t),openFile:async(n,r)=>{let i=e.sessions.list.getSnapshot().byId[t]?.cwd,a=N(t,i,n);r?.line===void 0?e.sidebarRight.openResource(a):e.sidebarRight.openResource(a,{params:{line:r.line}}),await Promise.resolve()},openSkill:n=>{let r=e.sessions.scope(t);r!==void 0&&e.get(`inputTriggers`)?.sessionOf(r).openReference(`skill`,{ref:`/${n}`})},resolveLink:e.get(`chatLinks`)?.resolve,openExternalLink:t=>{d.getSnapshot()===`sidebar`&&e.get(`sidebarRightTabs`)?.get(`browser`)!==void 0?e.sidebarRight.openTab(`browser`,{params:{url:t}}):window.open(t,`_blank`,`noopener,noreferrer`)},loadOlder:()=>{r.loadOlder()},loadThrough:e=>r.loadThrough(e),loadImage:Object.assign(n=>e.uiConversation.imageUrl(t,n),{peek:n=>e.uiConversation.peekImageUrl(t,n)}),chatScroll:{save:e=>{e===null?l.delete(t):l.set(t,e)},read:()=>l.get(t)??null},loadTurnDiffs:c?(e,n)=>c.read(t,e,n):void 0,editMessage:s?(e,n)=>s.send(t,e,n):void 0,forkAt:n=>{let r=[...i.getSnapshot().timeline.turns.values()].find(e=>e.end?.seq===n)?.data.get(`turn-tail`)?.closing?.finalNode.messageId;return e.sessions.fork({sessionId:t,atSeq:n,increaseTitle:!0,onCreated:n=>{e.get(`productAnalytics`)?.track(`branch_session_click`,{session_id:n,parent_session_id:t,...r===void 0?{}:{parent_message_id:r},click_position:`footer`})}}).then(t=>{e.uiWorkspace.openSession(t)})}}}},qn)),e.slots.inject(`shell.overlay`,()=>e.slots.register({name:`shell.overlay`,id:`chat.quota-notice`,locale:K,children:{"shell.quota-notice":{kind:`chain`,scope:`root`}},inject:()=>({hooks:{notice:t},dismissNotice:()=>{r.clear(),t.set(null)},keepNoticeOpen:()=>{if(t.getSnapshot()===null)return()=>{};let e=Symbol(`ui-chat quota notice hold`);return r.add(e),()=>{r.delete(e)}}})},As)),e.slots.inject(`conversation.input.dock`,()=>e.slots.register({name:`conversation.input.dock`,id:`file-changes`,order:5,locale:K},D)),e.slots.inject(`conversation.approval.detail`,()=>e.slots.register({name:`conversation.approval.detail`},oe))}return n.EMPTY_CHAT_SNAPSHOT=ie,n.apply=wc,n.inject=Cc,n.isRunningTool=vi,n.isSettledTool=_i,t.exports}});
|
|
14
|
+
`)?o:null,h=i&&m!==null,g=(0,d.useCallback)(()=>{a(e=>!e)},[]),_=(0,d.useMemo)(()=>/* @__PURE__ */ (0,f.jsxs)(f.Fragment,{children:[/* @__PURE__ */ (0,f.jsx)(`span`,{className:dr.separator,"data-shimmer-decoration":!0,"aria-hidden":!0}),/* @__PURE__ */ (0,f.jsx)(`span`,{className:dr.summary,"data-error":l===`error`||void 0,children:/* @__PURE__ */ (0,f.jsx)(p.TextShimmer,{children:s})})]}),[u,l,s]),v=(0,d.useMemo)(()=>h?/* @__PURE__ */ (0,f.jsx)(`pre`,{className:dr.body,"data-error":l===`error`||void 0,children:m}):void 0,[m,h,l]);return/* @__PURE__ */ (0,f.jsxs)(`div`,{className:dr.root,"data-variant":`others`,"data-command":e.name??void 0,"data-state":l,children:[l===`running`&&/* @__PURE__ */ (0,f.jsx)(`span`,{className:En.visuallyHidden,children:t(`row.running`)}),l===`error`&&/* @__PURE__ */ (0,f.jsx)(`span`,{className:En.visuallyHidden,children:t(`row.failed`)}),/* @__PURE__ */ (0,f.jsx)(p.DisclosureRow,{leadingClassName:dr.leading,titleClassName:dr.title,icon:fr,title:c,running:u,open:h,expandable:m!==null,expandOnRowClick:!0,keepContentWhenOpen:!0,onToggle:g,collapsedContent:_,children:v})]})});function hr({node:e,compaction:t,t:n}){return t===void 0?/* @__PURE__ */ (0,f.jsx)(mr,{node:e,t:n,runningSummary:n(`message.compaction.running`),successSummary:n(`message.compaction`)}):/* @__PURE__ */ (0,f.jsx)(le,{node:t,title:n(`message.compaction.commandTitle`),fallbackSummary:e.outcome?.text??null,t:n})}let gr=(0,d.memo)(function({node:e,renderSlot:t,t:n}){let r=e.data,i=(0,d.useMemo)(()=>({node:r}),[r]);return/* @__PURE__ */ (0,f.jsx)(`div`,{className:U.callRow,children:t(`conversation.chat.commandview`,i,{entryKey:r.name??``,fallback:/* @__PURE__ */ (0,f.jsx)(mr,{...i,t:n})})})}),_r=(0,d.memo)(function({node:e,t}){let n=e.data;return/* @__PURE__ */ (0,f.jsx)(`div`,{className:U.callRow,children:/* @__PURE__ */ (0,f.jsx)(hr,{node:n.command,...n.compaction===null?{}:{compaction:n.compaction},t})})});function vr({text:e,update:t=!1,t:n}){let[r,i]=(0,d.useState)(!1);return/* @__PURE__ */ (0,f.jsx)(p.DisclosureRow,{className:V.root,icon:/* @__PURE__ */ (0,f.jsx)(p.IconBrowseOutlineRegular,{size:14}),chevronClassName:V.chevron,title:n(t?`message.systemPromptUpdate`:`message.systemPrompt`),open:r,expandable:!0,expandOnRowClick:!0,onToggle:()=>{i(e=>!e)},children:/* @__PURE__ */ (0,f.jsx)(`div`,{className:V.body,"data-system-prompt-body":!0,children:/* @__PURE__ */ (0,f.jsx)(B,{content:[{type:`text`,text:e}],source:null,t:n})})})}let yr=(0,d.memo)(function({node:e,t}){return/* @__PURE__ */ (0,f.jsx)(vr,{text:e.data.text,update:e.data.update===!0,t})}),br=`@deepseek-ai/dsh-client-ui-chat/TurnProcessNodeView.module.css`;if(typeof document<`u`&&document.querySelector(`style[data-plugin-css=`+JSON.stringify(br)+`]`)===null){let e=document.createElement(`style`);e.dataset.plugin=`@deepseek-ai/dsh-client-ui-chat`,e.dataset.pluginCss=br,e.textContent=`.ty-UXa_root{box-sizing:border-box;width:100%;min-width:0;height:calc(33px + var(--dsh-content-font-delta,0px));border:none;border-bottom:.5px solid var(--dsw-alias-border-l2);color:var(--dsw-alias-label-tertiary);font:inherit;font-size:var(--dsh-content-font-size,14px);cursor:pointer;text-align:left;background:0 0;align-items:center;padding:0 0 8px;transition:color .1s;display:flex}.ty-UXa_root:disabled{cursor:default}.ty-UXa_root:hover:not(:disabled){color:var(--dsw-alias-label-secondary)}.ty-UXa_chevron{width:14px;height:14px;color:inherit;flex:none;margin-left:4px;transition:transform .1s}.ty-UXa_root[data-open] .ty-UXa_chevron{transform:rotate(180deg)}.ty-UXa_label{min-width:0;font-size:inherit;line-height:calc(24px + var(--dsh-content-font-delta,0px));text-overflow:ellipsis;white-space:nowrap;overflow:hidden}.ty-UXa_durationNumber{font-family:var(--ds-font-family-code);font-variant-numeric:tabular-nums}@media (prefers-reduced-motion:reduce){.ty-UXa_root,.ty-UXa_chevron{transition:none}}`,document.head.appendChild(e)}var xr={chevron:`ty-UXa_chevron`,durationNumber:`ty-UXa_durationNumber`,label:`ty-UXa_label`,root:`ty-UXa_root`};let Sr=(0,d.memo)(function({node:e,turnProcess:t,t:n}){if(t===void 0)throw Error(`turn-process node requires Turn process owner state`);let r=!t.foldable||t.open,i=e.location.kind===`turn`||e.location.kind===`step`?e.location.turn:void 0;if(i?.status!==`closed`)return null;let a=t.foldable&&t.hasContent&&!mt(e),o=i.end?.data.reason.kind,s=i.start===void 0||i.end===void 0||i.end.time<=i.start.time?void 0:Math.max(1e3,i.end.time-i.start.time),c=s===void 0||o===`aborted`||o===`error`?void 0:Le(s,n),l=n(o===`aborted`?`message.stopped`:o===`error`?`message.turnProcess.failed`:c===void 0?`message.turnProcess.worked`:`message.turnProcess.took`),u=n(o===`aborted`?`message.stopped`:o===`error`?`message.turnProcess.failed`:`message.turnProcess.worked`);return/* @__PURE__ */ (0,f.jsxs)(f.Fragment,{children:[/* @__PURE__ */ (0,f.jsx)(`span`,{className:En.visuallyHidden,role:`status`,"aria-live":`polite`,"aria-atomic":`true`,children:u}),/* @__PURE__ */ (0,f.jsxs)(`button`,{type:`button`,className:xr.root,"data-open":r||void 0,"data-turn-process":e.data.turn,"data-turn-process-messages":e.data.messageCount,"data-turn-process-tool-calls":e.data.toolCallCount,"data-turn-process-subagents":e.data.subagentCount,disabled:!a,"aria-expanded":t.hasContent?r:void 0,onClick:e=>{e.currentTarget.focus(),t.setOpen(!r)},children:[/* @__PURE__ */ (0,f.jsxs)(`span`,{className:xr.label,children:[l,c?.map((e,t)=>/* @__PURE__ */ (0,f.jsx)(`span`,{className:e.numeric?xr.durationNumber:void 0,children:e.text},t))]}),a&&/* @__PURE__ */ (0,f.jsx)(p.IconChevronDownOutlineRegular,{className:xr.chevron})]})]})});function Cr(e,t,n,r){let[i,a]=(0,d.useState)({}),[o,s]=(0,d.useState)(),[c,l]=(0,d.useState)(0),u=JSON.stringify(t.filter(e=>n.has(e.path)&&e.hunks===void 0).map(e=>[e.path,e.revision]));return(0,d.useEffect)(()=>{let t=JSON.parse(u).filter(([e,t])=>i[e]?.revision!==t);if(!r||t.length===0)return;let n=!0;return s(void 0),Promise.all(t.map(async([t,n])=>[t,{revision:n,diffs:(await r(e,t)).filter(e=>e.path===t)}])).then(e=>{n&&a(t=>({...t,...Object.fromEntries(e)}))},e=>{n&&s(e instanceof Error?e.message:String(e))}),()=>{n=!1}},[e,u,r,i,c]),{diffs:e=>e.hunks??(i[e.path]?.revision===e.revision?i[e.path]?.diffs:void 0),error:o,retry:()=>l(e=>e+1)}}let wr=`@deepseek-ai/dsh-client-ui-chat/TurnChangesCard.module.css`;if(typeof document<`u`&&document.querySelector(`style[data-plugin-css=`+JSON.stringify(wr)+`]`)===null){let e=document.createElement(`style`);e.dataset.plugin=`@deepseek-ai/dsh-client-ui-chat`,e.dataset.pluginCss=wr,e.textContent=`.IG8hNq_card{border:1px solid var(--dsw-alias-border-l2);corner-shape:round;color:var(--dsw-alias-label-primary);font-size:calc(var(--dsh-content-font-size-secondary,13px) + 2px);--dsh-change-stat-font-size:calc(var(--dsh-content-font-size-secondary,13px) + 1px);--dsw-alias-state-success-primary:var(--dsw-alias-file-diff-added-marker);--dsw-alias-state-error-primary:var(--dsw-alias-file-diff-deleted-marker);border-radius:12px;margin:8px 0;line-height:20px;overflow:hidden}.IG8hNq_header{align-items:center;gap:12px;padding:12px;display:flex}.IG8hNq_icon{corner-shape:round;background:color-mix(in srgb, var(--dsw-alias-label-primary) 4%, transparent);width:44px;height:44px;color:var(--dsw-alias-label-secondary);border-radius:12px;flex:none;place-items:center;display:grid}.IG8hNq_text{flex-direction:column;flex:auto;gap:2px;min-width:0;display:flex}.IG8hNq_title{text-overflow:ellipsis;white-space:nowrap;font-weight:600;overflow:hidden}.IG8hNq_review,.IG8hNq_fileHead,.IG8hNq_more{color:inherit;font:inherit;text-align:left;cursor:pointer;background:0 0;border:0}.IG8hNq_review{border:1px solid var(--dsw-alias-border-l2);corner-shape:round;font-size:var(--dsh-content-font-size,14px);white-space:nowrap;border-radius:12px;flex:none;padding:4px 8px;font-weight:500}.IG8hNq_review:hover,.IG8hNq_fileHead:hover,.IG8hNq_more:hover{background:var(--dsw-alias-interactive-bg-hover)}.IG8hNq_review:focus-visible,.IG8hNq_fileHead:focus-visible,.IG8hNq_more:focus-visible{outline:2px solid var(--dsw-alias-label-tertiary);outline-offset:-2px}.IG8hNq_files{border-top:1px solid var(--dsw-alias-border-l2);margin:0;padding:0;list-style:none}.IG8hNq_fileHead{justify-content:space-between;align-items:center;gap:12px;width:100%;min-height:40px;padding:8px 12px;display:flex}.IG8hNq_fileHead .IG8hNq_path{min-width:0;font-size:inherit;--dsw-alias-label-tertiary:var(--dsw-alias-label-secondary);flex:1}.IG8hNq_diff{padding:0 12px 12px}.IG8hNq_file:first-child .IG8hNq_diff:first-child{padding-top:12px}.IG8hNq_more{align-items:center;gap:8px;width:100%;min-height:40px;padding:8px 12px;font-weight:500;display:flex}.IG8hNq_mobileChevron,.IG8hNq_mobileFileIcon,.IG8hNq_mobilePath,.IG8hNq_mobileFullPath{display:none}.IG8hNq_chevron{flex:none;transition:transform .15s}.IG8hNq_chevron[data-open=true]{transform:rotate(180deg)}@media (width<=480px){.IG8hNq_header{grid-template-columns:36px minmax(0,1fr);gap:8px;display:grid}.IG8hNq_icon{width:36px;height:36px}.IG8hNq_review{grid-column:2;justify-self:start}}[data-phone] .IG8hNq_card{-webkit-text-size-adjust:100%;text-size-adjust:100%;min-width:0;max-width:100%;font-size:var(--dsh-content-font-size-secondary,13px);line-height:calc(20px + var(--dsh-content-font-delta-secondary,0px));--dsh-change-stat-font-size:calc(var(--dsh-content-font-size-secondary,13px) - 1px);--dsh-diff-inline-padding:12px;--dsh-diff-body-padding:4px 0 8px}[data-phone] .IG8hNq_header{grid-template-columns:20px minmax(0,1fr) 44px;gap:8px;min-height:52px;padding:0 4px 0 12px;display:grid}[data-phone] .IG8hNq_icon{background:0 0;border-radius:0;width:20px;height:20px}[data-phone] .IG8hNq_icon>svg{width:16px;height:16px}[data-phone] .IG8hNq_text{flex-direction:row;align-items:center;gap:8px}[data-phone] .IG8hNq_title{flex:auto;min-width:0;font-weight:500}[data-phone] .IG8hNq_review{border-radius:var(--dsw-radius-sm);border:0;grid-column:auto;justify-self:stretch;place-items:center;width:44px;height:44px;padding:0;display:grid}[data-phone] .IG8hNq_reviewLabel{display:none}[data-phone] .IG8hNq_mobileChevron,[data-phone] .IG8hNq_mobileFileIcon{color:var(--dsw-alias-label-secondary);flex:none;display:block}[data-phone] .IG8hNq_mobileChevron{transition:transform .15s}[data-phone] .IG8hNq_mobileChevron[data-open=true]{transform:rotate(180deg)}[data-phone] .IG8hNq_fileHead,[data-phone] .IG8hNq_more{gap:8px;min-height:44px;padding:0 12px}[data-phone] .IG8hNq_file+.IG8hNq_file{border-top:1px solid var(--dsw-alias-border-l2)}[data-phone] .IG8hNq_path{display:none}[data-phone] .IG8hNq_mobilePath{flex-direction:column;flex:1;min-width:0;padding-block:4px;display:flex}[data-phone] .IG8hNq_fileName{text-overflow:ellipsis;white-space:nowrap;font-weight:500;overflow:hidden}[data-phone] .IG8hNq_directory,[data-phone] .IG8hNq_mobileFullPath{color:var(--dsw-alias-label-secondary);font-size:calc(11px + var(--dsh-content-font-delta-secondary,0px));line-height:calc(16px + var(--dsh-content-font-delta-secondary,0px));white-space:normal;overflow-wrap:anywhere}[data-phone] .IG8hNq_mobileFullPath{user-select:text;padding:4px 12px;display:block}[data-phone] .IG8hNq_diff,[data-phone] .IG8hNq_file:first-child .IG8hNq_diff:first-child{padding:0}[data-phone] .IG8hNq_diffStatus{overflow-wrap:anywhere;padding:12px;display:block}[data-phone] .IG8hNq_diffStatus button{min-width:44px;min-height:44px}[data-phone] .IG8hNq_inlineDiff{border-radius:0;min-width:0;max-width:100%;margin:0}[data-phone] .IG8hNq_inlineDiff [data-diff-body]{box-sizing:border-box;-webkit-text-size-adjust:100%;text-size-adjust:100%;width:100%;min-width:0;font-size:calc(var(--dsw-font-markdown-code-block-font-size,11px) + var(--dsh-content-font-delta,0px));line-height:calc(var(--dsw-font-markdown-code-block-line-height,19px) + var(--dsh-content-font-delta,0px));tab-size:2;overscroll-behavior-x:contain}[data-phone] .IG8hNq_inlineDiff [data-diff-row=path]{display:none}[data-phone] .IG8hNq_inlineDiff [data-code-block-banner]{gap:8px;min-height:44px;padding:0 8px 0 12px}[data-phone] .IG8hNq_inlineDiff [data-code-block-banner] button{width:44px;height:44px}@media (prefers-reduced-motion:reduce){[data-phone] .IG8hNq_mobileChevron{transition:none}}`,document.head.appendChild(e)}var q={card:`IG8hNq_card`,chevron:`IG8hNq_chevron`,diff:`IG8hNq_diff`,diffStatus:`IG8hNq_diffStatus`,directory:`IG8hNq_directory`,file:`IG8hNq_file`,fileHead:`IG8hNq_fileHead`,fileName:`IG8hNq_fileName`,files:`IG8hNq_files`,header:`IG8hNq_header`,icon:`IG8hNq_icon`,inlineDiff:`IG8hNq_inlineDiff`,mobileChevron:`IG8hNq_mobileChevron`,mobileFileIcon:`IG8hNq_mobileFileIcon`,mobileFullPath:`IG8hNq_mobileFullPath`,mobilePath:`IG8hNq_mobilePath`,more:`IG8hNq_more`,path:`IG8hNq_path`,review:`IG8hNq_review`,reviewLabel:`IG8hNq_reviewLabel`,text:`IG8hNq_text`,title:`IG8hNq_title`};let Tr=(0,d.memo)(function({nodeStore:e,turn:t,t:n,useProjection:r,loadTurnDiffs:i}){let a=S(e,t,r),o=(0,d.useMemo)(()=>{let e=/* @__PURE__ */ new Map;for(let t of a){let n=w(t.path);e.set(n,(e.get(n)??0)+1)}return e},[a]),[s,c]=(0,d.useState)(()=>/* @__PURE__ */ new Set),[l,u]=(0,d.useState)(!1),m=Cr(t,a,s,i),h=(0,d.useMemo)(()=>({codeLabel:n(`diff.code`),wrapLabel:n(`diff.wrap`),unwrapLabel:n(`diff.unwrap`),copy:n(`diff.copy`),copied:n(`diff.copied`),collapseAria:n(`diff.collapseAria`),expandAria:e=>n(`diff.expandAria`,{count:e}),collapse:n(`diff.collapse`),expand:e=>n(`diff.expand`,{count:e})}),[n]);if(a.length===0)return null;let{added:g,removed:_}=C(a),[y]=a,b=a.length===1&&y!==void 0?n(`chat.fileEdited`,{name:w(y.path)}):n(`chat.filesEdited`,{count:a.length}),x=a.some(e=>s.has(e.path)),T=l?a:a.slice(0,3),E=a.length-T.length;return/* @__PURE__ */ (0,f.jsxs)(`section`,{className:q.card,"data-turn-changes":t,children:[/* @__PURE__ */ (0,f.jsxs)(`div`,{className:q.header,children:[/* @__PURE__ */ (0,f.jsx)(`span`,{className:q.icon,"aria-hidden":`true`,children:/* @__PURE__ */ (0,f.jsx)(p.IconFileDiffOutlineRegular,{size:24})}),/* @__PURE__ */ (0,f.jsxs)(`span`,{className:q.text,children:[/* @__PURE__ */ (0,f.jsx)(`span`,{className:q.title,title:b,children:b}),/* @__PURE__ */ (0,f.jsx)(v,{added:g,removed:_})]}),/* @__PURE__ */ (0,f.jsxs)(`button`,{type:`button`,className:q.review,"aria-expanded":x,"aria-label":n(x?`chat.hideChanges`:`chat.viewChanges`),onClick:()=>{c(new Set(x?[]:a.map(e=>e.path))),x||u(!0)},children:[/* @__PURE__ */ (0,f.jsx)(`span`,{className:q.reviewLabel,children:n(x?`chat.hideChanges`:`chat.viewChanges`)}),/* @__PURE__ */ (0,f.jsx)(p.IconChevronDownOutlineRegular,{size:16,className:q.mobileChevron,"data-open":x})]})]}),(a.length>1||x)&&/* @__PURE__ */ (0,f.jsxs)(`ul`,{className:q.files,children:[T.map(e=>{let t=m.diffs(e),r=w(e.path);return/* @__PURE__ */ (0,f.jsxs)(`li`,{className:q.file,children:[a.length>1&&/* @__PURE__ */ (0,f.jsxs)(`button`,{type:`button`,className:q.fileHead,"aria-expanded":s.has(e.path),onClick:()=>{c(t=>{let n=new Set(t);return n.has(e.path)?n.delete(e.path):n.add(e.path),n})},children:[/* @__PURE__ */ (0,f.jsx)(p.IconFileDiffOutlineRegular,{size:16,className:q.mobileFileIcon}),/* @__PURE__ */ (0,f.jsx)(p.PathLabel,{path:e.path,className:q.path}),/* @__PURE__ */ (0,f.jsxs)(`span`,{className:q.mobilePath,children:[/* @__PURE__ */ (0,f.jsx)(`span`,{className:q.fileName,"aria-hidden":`true`,children:r}),(o.get(r)??0)>1&&/* @__PURE__ */ (0,f.jsx)(`span`,{className:q.directory,"aria-hidden":`true`,children:e.path.slice(0,e.path.length-r.length)}),/* @__PURE__ */ (0,f.jsx)(`span`,{className:En.visuallyHidden,children:e.path})]}),/* @__PURE__ */ (0,f.jsx)(v,{added:e.added,removed:e.removed}),/* @__PURE__ */ (0,f.jsx)(p.IconChevronDownOutlineRegular,{size:16,className:q.mobileChevron,"data-open":s.has(e.path)})]}),s.has(e.path)&&/* @__PURE__ */ (0,f.jsxs)(`div`,{className:q.diff,children:[/* @__PURE__ */ (0,f.jsx)(`div`,{className:q.mobileFullPath,children:e.path}),t===void 0?m.error?/* @__PURE__ */ (0,f.jsxs)(`div`,{role:`alert`,className:q.diffStatus,children:[m.error,` `,/* @__PURE__ */ (0,f.jsx)(`button`,{type:`button`,onClick:m.retry,children:n(`chat.retryDiff`)})]}):/* @__PURE__ */ (0,f.jsx)(`span`,{role:`status`,className:q.diffStatus,children:n(`chat.loadingDiff`)}):/* @__PURE__ */ (0,f.jsx)(p.DiffBlock,{diffs:[...t],labels:h,maxLines:1/0,className:q.inlineDiff})]})]},e.path)}),a.length>3&&/* @__PURE__ */ (0,f.jsx)(`li`,{children:/* @__PURE__ */ (0,f.jsxs)(`button`,{type:`button`,className:q.more,"aria-expanded":l,onClick:()=>u(e=>!e),children:[E>0?n(`chat.showMoreFiles`,{count:E}):n(`chat.collapseFiles`),/* @__PURE__ */ (0,f.jsx)(p.IconChevronDownOutlineRegular,{size:16,className:q.chevron,"data-open":l})]})})]})]})});function Er(e){return e.flatMap(e=>e.kind===`text`?[e.text]:[]).join(``)}function Dr(e){return e.some(e=>e.kind===`reasoning`||e.kind===`tool-call`?!1:e.kind!==`text`||e.text.trim()!==``)}let Or=`@deepseek-ai/dsh-client-ui-chat/TurnTailNodeView.module.css`;if(typeof document<`u`&&document.querySelector(`style[data-plugin-css=`+JSON.stringify(Or)+`]`)===null){let e=document.createElement(`style`);e.dataset.plugin=`@deepseek-ai/dsh-client-ui-chat`,e.dataset.pluginCss=Or,e.textContent=`.ONXMya_root{flex-direction:column;gap:16px;display:flex}.ONXMya_actions{margin-top:4px;margin-left:-6px}`,document.head.appendChild(e)}var kr={actions:`ONXMya_actions`,root:`ONXMya_root`};function Ar(e,t,n){let r=e.locations.getTurn(t);for(let t=r.length-1;t>=0;t--){let i=e.nodes.get(r[t]);if(!(i===void 0||i.kind===`turn-tail`||i.kind===`turn-process`||n&&i.kind===`turn-max-tokens`))return i}}let jr=(0,d.memo)(function({node:e,openFile:t,forkAt:n,loadTurnDiffs:r,renderSlot:i,t:a,useChat:o,useSession:s,useProjection:c}){let l=s(e=>e.openState===`open`),u=(0,d.useRef)(!1),[p,m]=(0,d.useState)(!1),[h,g]=(0,d.useState)(),_=e.data,v=o(e=>e.nodes),y=o(e=>(Ar(e,_.turn,!0)?.anchorSeq??-1)>(_.closing?.finalNode.seq??_.seq)),b=o(e=>{if(e.timeline.turnOrder.at(-1)!==_.turn)return!1;let t=Ar(e,_.turn,!1),n=t?.kind===`assistant-step`?t.data.blocks.findLast(e=>e.kind!==`text`&&e.kind!==`reasoning`||e.text.trim()!==``):void 0;return n!==void 0&&Dr([n])}),x=e.location.kind===`turn`||e.location.kind===`step`?e.location.turn:void 0,S=Ue(c,x?.turn,`end`);if(x===void 0)return null;let C=_.closing,w=i(`conversation.chat.turnTail`,{turn:x,seq:C?.finalNode.seq??_.seq,openFile:t});if(C===null)return w===null?null:/* @__PURE__ */ (0,f.jsx)(`div`,{className:kr.root,"data-turn-tail":_.turn,children:w});let T=C.finalNode.messageId,E=T===void 0?null:i(`conversation.chat.assistant-actions`,{messageId:T});return/* @__PURE__ */ (0,f.jsxs)(`div`,{className:kr.root,"data-turn-tail":_.turn,"data-actions-reveal":b?`always`:`hover`,children:[/* @__PURE__ */ (0,f.jsx)(Tr,{nodeStore:v,turn:_.turn,t:a,useProjection:c,loadTurnDiffs:r}),w,/* @__PURE__ */ (0,f.jsx)(He,{text:Er(C.blocks),time:S,clock:`end`,onBranch:()=>{!u.current&&l&&(u.current=!0,m(!0),g(void 0),n(_.seq).catch(e=>{g(e instanceof Error?e.message:String(e))}).finally(()=>{u.current=!1,m(!1)}))},branchUnavailable:!l||p||_.branchUnavailable||y,className:kr.actions,extraActions:E,t:a}),h!==void 0&&/* @__PURE__ */ (0,f.jsx)(`p`,{role:`alert`,children:a(`message.branchFailed`,{message:h})})]})});function Mr(e){return typeof e==`object`&&e&&!Array.isArray(e)?e:{}}function Nr(e,t){return typeof e[t]==`string`?e[t]:``}function Pr(e){let t=Mr(e.source),n=Nr(t,`kind`),r=`message.trigger.request`,i=`request`;switch(n){case`goal`:r=`message.trigger.goal`,i=`goal`;break;case`agent-message`:r=`message.trigger.agent`,i=`agent`;break;case`team-message`:r=`message.trigger.team`,i=`team`;break;case`subagent-settled`:r=`message.trigger.subagent`,i=`subagent`;break;case`webhook`:{let e=Nr(t,`provider`)===`github`;r=e?`message.trigger.github`:`message.trigger.webhook`,i=e?`github`:`webhook`;break}case`schedule`:r=`message.trigger.schedule`,i=`schedule`;break;case`tool-jobs`:r=`message.trigger.job`,i=`job`;break;case`cordis-host-runner`:r=`message.trigger.plugin`,i=`plugin`}return{title:r,icon:i}}let Fr=`@deepseek-ai/dsh-client-ui-chat/TurnTriggerNodeView.module.css`;if(typeof document<`u`&&document.querySelector(`style[data-plugin-css=`+JSON.stringify(Fr)+`]`)===null){let e=document.createElement(`style`);e.dataset.plugin=`@deepseek-ai/dsh-client-ui-chat`,e.dataset.pluginCss=Fr,e.textContent=`.u7aAgG_root{border:.5px solid var(--dsw-alias-border-l1);border-radius:var(--dsw-radius-xl);background:var(--dsw-alias-turn-trigger-bg,var(--dsw-alias-markdown-code-block));min-width:0;transition:background-color .1s}.u7aAgG_root:hover{background:var(--dsw-alias-turn-trigger-bg-hover,var(--dsw-alias-interactive-bg-hover))}.u7aAgG_header{width:100%;color:var(--dsw-alias-label-tertiary);font:inherit;text-align:left;cursor:pointer;background:0 0;border:0;align-items:center;gap:10px;padding:12px 16px;transition:color .1s;display:flex}.u7aAgG_header:hover{color:var(--dsw-alias-label-secondary)}.u7aAgG_icon{color:inherit;flex:none;display:inline-flex}.u7aAgG_title{font-size:var(--dsh-content-font-size,14px);flex:none}.u7aAgG_time{color:inherit;font:var(--dsw-font-xxs-12);flex:none;margin-left:auto}.u7aAgG_chevron,.u7aAgG_openChevron{color:inherit;flex:none}.u7aAgG_openChevron{transform:rotate(180deg)}.u7aAgG_body{padding:0 16px 12px 40px}.u7aAgG_explanation{color:var(--dsw-alias-label-secondary);font:var(--dsw-font-xxs-12);margin:8px 0}.u7aAgG_content{white-space:pre-wrap;overflow-wrap:anywhere;max-height:240px;font:var(--dsw-font-xxs-12);overflow:auto}@media (prefers-reduced-motion:reduce){.u7aAgG_root,.u7aAgG_header{transition:none}}`,document.head.appendChild(e)}var Ir={body:`u7aAgG_body`,chevron:`u7aAgG_chevron`,content:`u7aAgG_content`,explanation:`u7aAgG_explanation`,header:`u7aAgG_header`,icon:`u7aAgG_icon`,openChevron:`u7aAgG_openChevron`,root:`u7aAgG_root`,time:`u7aAgG_time`,title:`u7aAgG_title`};let Lr={request:p.IconContextInjectionOutlineRegular,goal:p.IconGoalOutlineRegular,agent:p.IconPaperPlaneOutlineRegular,team:p.IconAgentPresetOutlineRegular,subagent:p.IconAgentPresetOutlineRegular,github:p.IconBranchOutlineRegular,webhook:p.IconGlobeOutlineRegular,schedule:p.IconClockOutlineRegular,job:p.IconQueueOutlineRegular,plugin:p.IconCordisPluginOutlineRegular};function Rr({node:e,t}){let[n,r]=(0,d.useState)(!1),i=(0,d.useId)(),a=Pr(e.data),o=Lr[a.icon],s=new Date(e.data.time),c=Re(e.data.time,t);return/* @__PURE__ */ (0,f.jsxs)(`section`,{className:Ir.root,"data-turn-trigger":!0,children:[/* @__PURE__ */ (0,f.jsxs)(`button`,{className:Ir.header,type:`button`,"aria-expanded":n,"aria-controls":i,onClick:()=>{r(!n)},children:[/* @__PURE__ */ (0,f.jsx)(`span`,{className:Ir.icon,"aria-hidden":!0,children:/* @__PURE__ */ (0,f.jsx)(o,{size:14})}),/* @__PURE__ */ (0,f.jsx)(`span`,{className:Ir.title,children:t(a.title)}),/* @__PURE__ */ (0,f.jsx)(`time`,{className:Ir.time,dateTime:s.toISOString(),children:c}),/* @__PURE__ */ (0,f.jsx)(p.IconChevronDownOutlineRegular,{size:12,className:n?Ir.openChevron:Ir.chevron})]}),n&&/* @__PURE__ */ (0,f.jsxs)(`div`,{id:i,className:Ir.body,children:[/* @__PURE__ */ (0,f.jsx)(`p`,{className:Ir.explanation,children:t(`message.trigger.explanation`)}),/* @__PURE__ */ (0,f.jsx)(`div`,{className:Ir.content,children:/* @__PURE__ */ (0,f.jsx)(Ee,{content:e.data.content,source:e.data.source,t})})]})]})}function zr(e,t){e.slots.inject(`conversation.chat.node`,()=>e.slots.register({name:`conversation.chat.node`,key:`user`,locale:K},nt)),e.slots.inject(`conversation.chat.node`,()=>e.slots.register({name:`conversation.chat.node`,key:`steering`,locale:K},nt)),e.slots.inject(`conversation.chat.node`,()=>e.slots.register({name:`conversation.chat.node`,key:`context`,locale:K},it)),e.slots.inject(`conversation.chat.node`,()=>e.slots.register({name:`conversation.chat.node`,key:`turn-trigger`,locale:K},Rr)),e.slots.inject(`conversation.chat.node`,()=>e.slots.register({name:`conversation.chat.node`,key:`system-prompt`,locale:K},yr)),e.slots.inject(`conversation.chat.node`,()=>e.slots.register({name:`conversation.chat.node`,key:`assistant-step`,locale:K,inject:()=>({hooks:{presentation:t}})},lr)),e.slots.inject(`conversation.chat.node`,()=>e.slots.register({name:`conversation.chat.node`,key:`command`,locale:K,children:{"conversation.chat.commandview":{kind:`keyed`,scope:`session`}}},gr)),e.slots.inject(`conversation.chat.node`,()=>e.slots.register({name:`conversation.chat.node`,key:`manual-compaction`,locale:K},_r)),e.slots.inject(`conversation.chat.node`,()=>e.slots.register({name:`conversation.chat.node`,key:`compaction`,locale:K},at)),e.slots.inject(`conversation.chat.node`,()=>e.slots.register({name:`conversation.chat.node`,key:`model-retry`,locale:K},ot)),e.slots.inject(`conversation.chat.node`,()=>e.slots.register({name:`conversation.chat.node`,key:`turn-error`,locale:K},st)),e.slots.inject(`conversation.chat.node`,()=>e.slots.register({name:`conversation.chat.node`,key:`turn-max-tokens`,locale:K},ct)),e.slots.inject(`conversation.chat.node`,()=>e.slots.register({name:`conversation.chat.node`,key:`turn-process`,locale:K},Sr)),e.slots.inject(`conversation.chat.node`,()=>e.slots.register({name:`conversation.chat.node`,key:`turn-tail`,locale:K,children:{"conversation.chat.turnTail":{kind:`list`,scope:`session`},"conversation.chat.assistant-actions":{kind:`list`,scope:`session`}}},jr)),e.slots.inject(`conversation.chat.node`,()=>e.slots.register({name:`conversation.chat.node`,key:`unknown`,locale:K},lt))}let Br={interruptedAssistant:-.9,interruptedFollowup:-.8,processControl:-.1,maxTokensNotice:.05,finalizedFollowup:.1};function Vr(e){return e.start?.location??e.matches[0]?.location??{kind:`unresolved`}}function J(e,t,n,r,i={}){return{key:e.key,kind:t,id:e.id,target:`chat`,anchorSeq:n,location:i.location??Vr(e),visibility:i.visibility??`visible`,data:r}}function Hr(e){return typeof e==`object`&&e&&!Array.isArray(e)?e:null}function Ur(e,t){let n=e[t];return typeof n==`string`&&n.length>0?n:null}function Wr(e,t,n){let r=e[t];if(!Array.isArray(r))return[];let i=[];for(let e of r){let t=Hr(e),r=t===null?null:Ur(t,n);r!==null&&!i.includes(r)&&i.push(r)}return i}function Gr(e){return e.length>0?e.join(`, `):null}let Kr=[`instructions`,`catalog`,`snapshot`,`notice`,`relay`,`recall`];function qr(e){let t=Hr(e),n=t===null?null:Ur(t,`form`);return n!==null&&Kr.includes(n)?n:null}function Jr(e){let t=Hr(e),n=t===null?null:Ur(t,`kind`);if(t===null||n===null)return{role:`inject`,label:null};switch(n){case`session-reference`:return{role:`recall`,label:Gr(Wr(t,`references`,`label`))??n};case`agent-instructions`:return{role:`inject`,label:Gr(Wr(t,`changes`,`path`))??n};case`skill-invocation`:return{role:`inject`,label:Ur(t,`name`)??n};default:return{role:`inject`,label:n}}}function Yr(e){let t=Hr(e);return t===null||Ur(t,`kind`)!==`session-reference`?[]:Wr(t,`references`,`label`)}function Xr(e){let t=Hr(e);return t===null||Ur(t,`kind`)!==`skill-invocation`?null:Ur(t,`name`)}function Zr(e){return e.map(Qr)}function Qr(e){switch(e.type){case`text`:return{kind:`text`,text:e.text};case`reasoning`:return{kind:`reasoning`,text:e.text};case`image`:return{kind:`image`,attachment:e.attachment};case`tool-call`:return{kind:`tool-call`,callId:String(e.id),name:e.name,argsRaw:e.arguments};default:return{kind:`other`,block:e}}}function $r(e){switch(e){case`text`:return{kind:`text`,text:``};case`reasoning`:return{kind:`reasoning`,text:``};case`tool-call`:return{kind:`tool-call`,callId:``,name:``,argsRaw:``};default:return{kind:`other`,block:null}}}function ei(e){if(typeof e!=`object`||!e)return{message:String(e)};let t=e,n=typeof t.code==`string`?t.code:void 0;return n===`AUTH`?{code:n,message:``}:{...n===void 0?{}:{code:n},message:typeof t.message==`string`?t.message:JSON.stringify(e)}}function ti(e){switch(e.type){case`text-delta`:case`reasoning-delta`:return e.text!==``;case`tool-call-delta`:return e.argumentsDelta!==``||e.name!==void 0;default:return!1}}function ni(e,t){return{turn:e,step:t,blocks:[],visibleByIndex:[],visibleBlocks:0,firstVisibleSeq:void 0,firstVisibleTime:void 0,firstTokenTime:void 0,final:void 0,usage:void 0}}function ri(e){return e.filter(e=>e!==void 0)}function ii(e){return e===void 0||e.kind===`tool-call`?!1:e.kind===`text`||e.kind===`reasoning`?e.text.trim()!==``:!0}function ai(e){return e.some(ii)}function oi(e){return e.some(e=>e.kind===`text`||e.kind===`reasoning`?e.text.trim()!==``:!0)}function si(e){return{...ni(e.turn,e.step),firstTokenTime:e.firstTokenTime}}function ci(e,t,n,r){if(t.type===`tool-call-delta`){let n=e.blocks[t.index];if(n?.kind===`tool-call`&&n.callId!==``&&(t.name===void 0||t.name===n.name)&&(e.firstTokenTime!==void 0||!ti(t)))return e}let i=[...e.blocks],a=-1,o=!1,s=!1;switch(t.type){case`block-start`:a=t.index,o=e.visibleByIndex[t.index]===!0,i[t.index]=$r(t.blockType),s=ii(i[t.index]);break;case`text-delta`:{let n=i[t.index];a=t.index,o=e.visibleByIndex[t.index]===!0,i[t.index]={kind:`text`,text:(n?.kind===`text`?n.text:``)+t.text},s=n?.kind===`text`&&o||t.text.trim()!==``;break}case`reasoning-delta`:{let n=i[t.index];a=t.index,o=e.visibleByIndex[t.index]===!0,i[t.index]={kind:`reasoning`,text:(n?.kind===`reasoning`?n.text:``)+t.text},s=n?.kind===`reasoning`&&o||t.text.trim()!==``;break}case`tool-call-delta`:{let n=i[t.index];a=t.index,o=e.visibleByIndex[t.index]===!0,i[t.index]={kind:`tool-call`,callId:(n?.kind===`tool-call`?n.callId:``)||String(t.id),name:t.name??(n?.kind===`tool-call`?n.name:``),argsRaw:n?.kind===`tool-call`?n.argsRaw:``};break}case`block-end`:a=t.index,o=e.visibleByIndex[t.index]===!0,i[t.index]=Qr(t.block),s=ii(i[t.index]);break;case`usage`:return{...e,usage:t.usage};default:return e}let c=e.visibleBlocks-Number(o)+Number(s),l=e.visibleByIndex;if(o!==s){let e=[...l];e[a]=s,l=e}let u=ti(t);return{...e,blocks:i,visibleByIndex:l,visibleBlocks:c,...c>0&&e.firstVisibleSeq===void 0?{firstVisibleSeq:n,firstVisibleTime:r}:{},...u&&e.firstTokenTime===void 0?{firstTokenTime:r}:{}}}function li(e,t,n){let r=Zr(n.data.message.content),i=r.map(ii);return{...e,blocks:r,visibleByIndex:i,visibleBlocks:i.reduce((e,t)=>e+Number(t),0),final:t,usage:n.data.usage}}function ui(e){if(e.kind===`step`&&e.step.status===`closed`&&e.step.end!==void 0)return e.step.end;if((e.kind===`step`||e.kind===`turn`)&&e.turn.status===`closed`&&e.turn.end!==void 0)return e.turn.end}function di(e,t){let n=e.final;if(n?.event.type===`assistant/message`){let r=n.event;return{kind:`assistant`,seq:r.seq,messageId:r.data.message.id,time:r.time,turn:e.turn,step:e.step,blocks:Zr(r.data.message.content),usage:r.data.usage,timing:{stepStartTime:t.start?.event.time??null,firstTokenTime:e.firstTokenTime??null,completedTime:r.time},...r.data.interrupted===!0?{interrupted:!0}:{}}}let r=t.start?.location??t.matches.at(-1)?.location,i=r===void 0?void 0:ui(r);if(i===void 0)return;let a=ri(e.blocks);if(oi(a))return{kind:`assistant`,seq:i.seq+Br.interruptedAssistant,time:i.time,turn:e.turn,step:e.step,blocks:a,interrupted:!0}}function fi(e){let t;for(let n of e.matches)n.event.type===`assistant/live-chunk`?(t??=ni(n.event.data.turn,n.event.data.step),t=ci(t,n.event.data.chunk,n.event.seq,n.event.time)):n.event.type===`assistant/message`?(t??=ni(n.event.data.turn,n.event.data.step),t=li(t,n,n.event)):n.event.type===`llm/retry`&&t!==void 0&&(t=si(t));return t}function pi(e){let t=e.state??fi(e);if(t===void 0)return;let n=di(t,e),r=n?.blocks??ri(t.blocks),i=n===void 0?t.visibleBlocks>0:ai(r),a=n?.interrupted===!0?`interrupted`:n===void 0?`running`:`settled`,o=(n?.interrupted===!0?n.seq:t.firstVisibleSeq??n?.seq)??e.matches[0]?.event.seq??0,s=n?.time??t.firstVisibleTime??e.matches[0]?.event.time??0;return{anchorSeq:o,visible:i,settled:n,data:{status:a,turn:t.turn,step:t.step,blocks:r,time:s,...t.usage===void 0?{}:{usage:t.usage},...n===void 0?{}:{finalNode:n}}}}function mi(e){let t=e.start?.location??e.matches.at(-1)?.location;return t?.kind===`step`?t.step.data.get(`assistant-step`):void 0}let hi={kind:`assistant-step`,target:`chat`,match:e=>e.type===`step/start`?{id:`${e.data.turn}:${e.data.step}`,role:`start`}:e.type===`assistant/live-chunk`||e.type===`assistant/message`&&e.surfaceOp===`append`||e.type===`llm/retry`?{id:`${e.data.turn}:${e.data.step}`,role:`update`}:null,start:(e,t)=>{if(t.event.type!==`step/start`)throw Error(`assistant-step start requires step/start`);return ni(t.event.data.turn,t.event.data.step)},update:(e,t)=>t.event.type===`assistant/live-chunk`?ci(e.state,t.event.data.chunk,t.event.seq,t.event.time):t.event.type===`assistant/message`?li(e.state,t,t.event):t.event.type===`llm/retry`?si(e.state):e.state,publication:e=>{if(e.event.type===`step/start`)return`none`;if(e.event.type!==`assistant/live-chunk`)return`immediate`;let t=e.event.data.chunk.type;return t===`usage`||t===`finish`?`none`:`animation-frame`},buildLocationData:(e,t)=>{if(t!==`step`)return null;let n=pi(e);return n===void 0?null:{kind:`step`,turn:n.data.turn,step:n.data.step,key:`assistant-step`,value:n.data}},buildViewNode:e=>{let t=e.current.get(`chat`),n=e.state??fi(e),r=mi(e);if(n===void 0||r===void 0)return t==null?null:{...t,visibility:`hidden`};let i=r.finalNode,a=i===void 0?n.visibleBlocks>0:ai(r.blocks);return i===void 0&&!a&&t==null?null:J(e,`assistant-step`,(i?.interrupted===!0?i.seq:n.firstVisibleSeq??i?.seq)??e.matches[0]?.event.seq??0,r,{visibility:i?.interrupted===!0||a?`visible`:`hidden`})}};function gi(e){let t=hi.match.bind(hi);e.uiConversation.events.register({...hi,match:{"step/start":t,"assistant/live-chunk":t,"assistant/message":t,"llm/retry":t}})}function _i(e){return`kind`in e}function vi(e){return!_i(e)}function yi(e){return e.visibility===`visible`&&e.kind!==`system-prompt`&&(e.kind!==`context`||e.data.content.some(e=>e.type===`tool-addition`||e.type===`tool-removal`))&&(e.kind!==`command`||e.data.name!==`permission`)}function bi(e,t){let n=``,r=!1;for(let i of e){if(n.length>=t*2){r=!0;break}let e=i.length>t*2,a=e?i.slice(0,t*2):i;if(n+=n===``?a:` ${a}`,e){r=!0;break}}let i=n.replace(/\s+/g,` `).trim();return i.length>t-1?`${i.slice(0,t-1).trimEnd()}…`:r?`${i}…`:i}function xi(e){return e.kind===`user`?bi(e.data.content.flatMap(e=>e.type===`text`?[e.text]:[]),50):``}function Si(e){return e.kind===`assistant-step`?bi(e.data.blocks.flatMap(e=>e.kind===`text`?[e.text]:[]),120):``}function Ci(e,t){return e===void 0||t===void 0?e===t:e.turn===t.turn&&e.anchorKey===t.anchorKey&&e.prompt===t.prompt&&e.response===t.response}function wi(e,t,n){let r=t.getTurn(e).map(e=>n.get(e)).filter(e=>e!==void 0&&yi(e)),i=r.find(e=>e.kind===`user`),a=i??r[0];if(a===void 0)return;let o=r.findLast(e=>Si(e)!==``);return{turn:e,anchorKey:a.key,prompt:i===void 0?``:xi(i),response:o===void 0?``:Si(o)}}function Ti(e){let t=e?.location;return t?.kind===`turn`||t?.kind===`step`?t.turn.turn:void 0}function Ei(e,t){return e===t||e!==void 0&&t!==void 0&&e.spec===t.spec&&e.turn===t.turn&&e.turnStarted===t.turnStarted&&e.turnClosed===t.turnClosed&&e.hasExternalProcess===t.hasExternalProcess&&e.hasInterleavedInput===t.hasInterleavedInput&&e.compactAnswer===t.compactAnswer}function Di(e,t,n){let r=t.getTurn(e),i=r.map(e=>n.get(e)).find(e=>e?.kind===`turn-process`);if(i===void 0)return;let a=i.data,o=i.location;if(o.kind!==`turn`&&o.kind!==`step`)return;let s;for(let e of r){let t=n.get(e);(t?.kind===`user`||t?.kind===`steering`||t?.kind===`turn-trigger`)&&(a.controlAnchorSeq===o.turn.start?.seq||t.anchorSeq<a.controlAnchorSeq)&&(s=Math.max(s??t.anchorSeq,t.anchorSeq))}let c=!1,l=!1,u=!0;for(let e of r){let t=n.get(e);t!==void 0&&yi(t)&&t.kind!==`turn-process`&&((t.kind===`user`||t.kind===`steering`||t.kind===`turn-trigger`)&&(s===void 0||t.anchorSeq>s)&&(l=!0,(a.answerAnchorSeq===null||t.anchorSeq<a.answerAnchorSeq)&&(u=!1)),!(ut.has(t.kind)||t.anchorSeq<a.processStartSeq)&&(t.kind!==`assistant-step`||a.answerStep===null||t.data.step!==a.answerStep)&&(c=!0))}return{turn:e,spec:a,turnStarted:o.turn.start!==void 0,turnClosed:o.turn.status===`closed`,hasExternalProcess:c,hasInterleavedInput:l,compactAnswer:u}}var Oi=class{presentations=/* @__PURE__ */ new Map;get(e){let t=Ti(e);return t===void 0?void 0:this.presentations.get(t)}replace(e,t,n){let r=/* @__PURE__ */ new Set;for(let t of e){let e=Ti(n.get(t));e!==void 0&&r.add(e)}let i=/* @__PURE__ */ new Set;for(let e of/* @__PURE__ */ new Set([...this.presentations.keys(),...r]))this.set(e,r.has(e)?Di(e,t,n):void 0)&&i.add(e);return i}update(e,t,n){let r=/* @__PURE__ */ new Set;for(let i of e)this.set(i,Di(i,t,n))&&r.add(i);return r}set(e,t){return!Ei(this.presentations.get(e),t)&&(t===void 0?this.presentations.delete(e):this.presentations.set(e,t),!0)}};let ki=[],Ai=[],ji=[],Mi=[];function Ni(e,t){return e.length===t.length&&e.every((e,n)=>e===t[n])}function Pi(e,t,n){let r=e.get(t);return r===void 0&&(r=n(),e.set(t,r)),r}var Fi=class{read;label;listeners=/* @__PURE__ */ new Set;published;constructor(e,t){this.read=e,this.label=t,this.published=e()}getSnapshot=()=>this.read();subscribe=e=>(this.listeners.add(e),()=>{this.listeners.delete(e)});publish(){let e=this.getSnapshot();this.published!==e&&(this.published=e,(0,m.notifySubscribers)(this.listeners,this.label))}},Ii=class{nodes=/* @__PURE__ */ new Map;current=Mi;dirty=!1;observable;source(){return this.observable??=new Fi(()=>this.read(),`[ui-chat] turn kind nodes`)}set(e){let t=this.nodes.get(e.key);this.nodes.set(e.key,e),(t===void 0||t.data!==e.data||t.anchorSeq!==e.anchorSeq)&&(this.dirty=!0)}delete(e){this.nodes.delete(e),this.dirty=!0}publish(){this.observable?.publish()}read(){return this.dirty&&=(this.current=[...this.nodes.values()].sort((e,t)=>e.anchorSeq-t.anchorSeq).map(e=>e.data),!1),this.current}},Li=class{byKey=/* @__PURE__ */ new Map;turnProcesses=new Oi;sources=/* @__PURE__ */ new Map;processSources=/* @__PURE__ */ new Map;dirtyKeys=/* @__PURE__ */ new Set;dirtyProcessKeys=/* @__PURE__ */ new Set;turnKinds=/* @__PURE__ */ new Map;dirtyTurnKinds=/* @__PURE__ */ new Set;valuesCache=Mi;valuesDirty=!1;get(e){return this.byKey.get(e)}source(e){return Pi(this.sources,e,()=>new Fi(()=>this.get(e),`[ui-chat] node source ${e}`))}turnDataSource(e,t){return this.turnKind(e,t).source()}turnKind(e,t){return Pi(Pi(this.turnKinds,e,()=>/* @__PURE__ */ new Map),t,()=>new Ii)}updateTurnKind(e,t){let n=e===void 0?void 0:Hi(e.location).turn,r=t===void 0?void 0:Hi(t.location).turn;if(e!==void 0&&n!==void 0&&(n!==r||e.kind!==t?.kind)){let t=this.turnKind(n,e.kind);t.delete(e.key),this.dirtyTurnKinds.add(t)}if(t!==void 0&&r!==void 0){let e=this.turnKind(r,t.kind);e.set(t),this.dirtyTurnKinds.add(e)}}processSource(e){return Pi(this.processSources,e,()=>new Fi(()=>this.process(e),`[ui-chat] node process source ${e}`))}process(e){return this.turnProcesses.get(this.get(e))}values(){return this.valuesDirty&&=(this.valuesCache=[...this.byKey.values()],!1),this.valuesCache}replace(e){let t=new Map(this.byKey);this.byKey.clear();for(let n of e)this.byKey.set(n.key,n),t.get(n.key)!==n&&(this.updateTurnKind(t.get(n.key),n),this.dirtyKeys.add(n.key),this.dirtyProcessKeys.add(n.key)),t.delete(n.key);for(let e of t.keys())this.updateTurnKind(t.get(e),void 0),this.dirtyKeys.add(e),this.dirtyProcessKeys.add(e);this.valuesCache=[...this.byKey.values()],this.valuesDirty=!1}upsert(e){let t=!1;for(let n of e)this.byKey.get(n.key)!==n&&(this.updateTurnKind(this.byKey.get(n.key),n),this.byKey.set(n.key,n),this.dirtyKeys.add(n.key),this.dirtyProcessKeys.add(n.key),t=!0);t&&(this.valuesDirty=!0)}touchProcesses(e,t){for(let n of e)for(let e of t.getTurn(n))this.dirtyProcessKeys.add(e)}replaceProcesses(e,t){this.touchProcesses(this.turnProcesses.replace(e,t,this),t)}updateProcesses(e,t){this.touchProcesses(this.turnProcesses.update(e,t,this),t)}publish(){let e=[...this.dirtyKeys],t=[...this.dirtyProcessKeys],n=[...this.dirtyTurnKinds];this.dirtyKeys.clear(),this.dirtyProcessKeys.clear(),this.dirtyTurnKinds.clear();for(let t of e)this.sources.get(t)?.publish();for(let e of t)this.processSources.get(e)?.publish();for(let e of n)e.publish()}},Ri=class{turns=/* @__PURE__ */ new Map;steps=/* @__PURE__ */ new Map;positions=/* @__PURE__ */ new Map;getTurn(e){return this.turns.get(e)??ki}getStep(e,t){return this.steps.get(Vi(e,t))??ki}getPosition(e){return this.positions.get(e)}rebuild(e,t){let n=/* @__PURE__ */ new Map,r=/* @__PURE__ */ new Map,i=/* @__PURE__ */ new Map,a=/* @__PURE__ */ new Set;for(let[o,s]of e.entries()){let c=t.get(s)?.location;if(c===void 0)continue;let l=Hi(c),u=this.positions.get(s),d={turn:l.turn,previous:e[o-1],next:e[o+1]},f=u!==void 0&&u.turn===d.turn&&u.previous===d.previous&&u.next===d.next;if(i.set(s,f?u:d),f||(u?.turn!==void 0&&a.add(u.turn),d.turn!==void 0&&a.add(d.turn)),l.turn===void 0)continue;let p=n.get(l.turn)??[];if(p.push(s),n.set(l.turn,p),l.step===void 0)continue;let m=Vi(l.turn,l.step),h=r.get(m)??[];h.push(s),r.set(m,h)}for(let[e,t]of this.positions)!i.has(e)&&t.turn!==void 0&&a.add(t.turn);return this.positions=i,this.turns=zi(this.turns,n),this.steps=zi(this.steps,r),[...a]}touch(e){let t=/* @__PURE__ */ new Set,n=/* @__PURE__ */ new Set;for(let r of e){let e=Hi(r.location);e.turn!==void 0&&this.turns.get(e.turn)?.includes(r.key)&&(t.add(e.turn),e.step!==void 0&&n.add(Vi(e.turn,e.step)))}for(let e of t){let t=this.turns.get(e);t!==void 0&&this.turns.set(e,[...t])}for(let e of n){let t=this.steps.get(e);t!==void 0&&this.steps.set(e,[...t])}}};function zi(e,t){let n=/* @__PURE__ */ new Map,r=/* @__PURE__ */ new Set([...e.keys(),...t.keys()]);for(let i of r){let r=e.get(i)??ki,a=t.get(i)??ki,o=Ni(r,a)?r:a;a.length>0&&n.set(i,o)}return n}var Bi=class{current=ji;byTurn=/* @__PURE__ */ new Map;items(){return this.current}rebuild(e,t,n){let r=[],i=/* @__PURE__ */ new Map;for(let a of e.turnOrder){let e=wi(a,t,n);if(e===void 0)continue;let o=this.byTurn.get(a),s=o!==void 0&&Ci(o,e)?o:e;r.push(s),i.set(a,s)}this.byTurn=i,r.length===this.current.length&&r.every((e,t)=>e===this.current[t])||(this.current=r)}touch(e,t,n){if(e.size===0)return;let r=this.current.map(r=>{if(!e.has(r.turn))return r;let i=wi(r.turn,t,n);return i===void 0||Ci(r,i)?r:(this.byTurn.set(r.turn,i),i)});r.some((e,t)=>e!==this.current[t])&&(this.current=r)}};function Vi(e,t){return`${e}:${t}`}function Hi(e){return e.kind===`step`?{turn:e.turn.turn,step:e.step.step}:e.kind===`turn`?{turn:e.turn.turn}:{}}function Ui(e){return e.kind===`turn`||e.kind===`step`?e.turn.status:void 0}function Wi(e,t,n){return n||e===void 0||Ui(e.location)!==Ui(t.location)?!0:e.kind===`turn-process`&&t.kind===`turn-process`?e.data!==t.data:e.kind===`assistant-step`&&t.kind===`assistant-step`&&e.data.step!==t.data.step}function Gi(e){let t=/* @__PURE__ */ new Map;for(let n of e){let e=n;e.kind===`turn-process`&&t.set(e.data.turn,{...t.get(e.data.turn),control:e})}for(let n of e){let e=n,r=e.location;if(r.kind!==`turn`&&r.kind!==`step`)continue;let i=t.get(r.turn.turn)??{},a=i.control?.data.controlAnchorSeq;(e.kind===`user`||e.kind===`turn-trigger`||e.kind===`steering`)&&a!==void 0&&(a===r.turn.start?.seq||e.anchorSeq<a)?t.set(r.turn.turn,{...i,openingInputAnchor:Math.max(i.openingInputAnchor??e.anchorSeq,e.anchorSeq)}):ut.has(e.kind)||t.set(r.turn.turn,{...i,earliestProcessAnchor:Math.min(i.earliestProcessAnchor??e.anchorSeq,e.anchorSeq)})}return t}function Ki(e,t){let n=e,r=n.location;if(r.kind!==`turn`&&r.kind!==`step`)return{anchor:n.anchorSeq,rank:0,originalAnchor:n.anchorSeq};let i=t.get(r.turn.turn);if(i===void 0)return{anchor:n.anchorSeq,rank:0,originalAnchor:n.anchorSeq};let a=i.openingInputAnchor;return a!==void 0&&n.anchorSeq<a&&!ut.has(n.kind)?{anchor:a,rank:2,originalAnchor:n.anchorSeq}:i.control!==void 0&&n.key===i.control.key?a===void 0?{anchor:i.earliestProcessAnchor??n.anchorSeq,rank:-1,originalAnchor:n.anchorSeq}:{anchor:a,rank:1,originalAnchor:n.anchorSeq}:{anchor:n.anchorSeq,rank:0,originalAnchor:n.anchorSeq}}function qi(e){let t=e.filter(e=>yi(e)),n=Gi(t);return t.sort((e,t)=>{let r=Ki(e,n),i=Ki(t,n);return r.anchor-i.anchor||r.rank-i.rank||r.originalAnchor-i.originalAnchor||e.key.localeCompare(t.key)})}function Ji(e){let t=e;return t.kind===`user`||t.kind===`steering`?t.data.seq:void 0}function Yi(e){let t=e;if(t.kind===`context`)return{messageSeq:t.data.seq-1,labels:Yr(t.data.source)}}function Xi(e,t){let n=e;if(n.kind!==`user`&&n.kind!==`steering`)return e;let r=n.data.referenceLabels??ki,i=Object.hasOwn(n.data,`referenceLabels`);if(Ni(r,t)&&i===t.length>0)return e;let a={...n.data};return t.length===0?delete a.referenceLabels:a.referenceLabels=t,{...n,data:a}}var Zi=class{messagesBySeq=/* @__PURE__ */ new Map;labelsByMessageSeq=/* @__PURE__ */ new Map;replace(e){this.messagesBySeq.clear(),this.labelsByMessageSeq.clear();for(let t of e){let e=Ji(t);e!==void 0&&this.messagesBySeq.set(e,t.key);let n=Yi(t);n!==void 0&&n.labels.length>0&&this.labelsByMessageSeq.set(n.messageSeq,n.labels)}return e.map(e=>{let t=Ji(e);return t===void 0?e:Xi(e,this.labelsByMessageSeq.get(t)??ki)})}apply(e,t){let n=new Map(e.map(e=>[e.key,e])),r=/* @__PURE__ */ new Set;for(let t of e){let e=Ji(t);e!==void 0&&(this.messagesBySeq.set(e,t.key),r.add(e));let n=Yi(t);if(n===void 0)continue;let i=this.labelsByMessageSeq.get(n.messageSeq);n.labels.length===0?this.labelsByMessageSeq.delete(n.messageSeq):this.labelsByMessageSeq.set(n.messageSeq,i!==void 0&&Ni(i,n.labels)?i:n.labels),r.add(n.messageSeq)}for(let e of r){let r=this.messagesBySeq.get(e);if(r===void 0)continue;let i=n.get(r)??t.get(r);i!==void 0&&n.set(r,Xi(i,this.labelsByMessageSeq.get(e)??ki))}return[...n.values()]}};function Qi(e,t){let n=e;if(n.kind!==`user`&&n.kind!==`steering`)return e;let r=n.data.skillNames??ki,i=Object.hasOwn(n.data,`skillNames`);if(Ni(r,t)&&i===t.length>0)return e;let a={...n.data};return t.length===0?delete a.skillNames:a.skillNames=t,{...n,data:a}}function $i(e){let t=e;if(t.kind===`user`||t.kind===`steering`)return{key:e.key,seq:e.anchorSeq,kind:`message`,name:null};if(t.kind===`context`){let n=Xr(t.data.source);return n===null?null:{key:e.key,seq:e.anchorSeq,kind:`skill`,name:n}}return{key:e.key,seq:e.anchorSeq,kind:`boundary`,name:null}}function ea(e,t){return e.seq===t.seq&&e.kind===t.kind&&e.name===t.name}var ta=class{entries=/* @__PURE__ */ new Map;sorted=[];replace(e){this.entries.clear(),this.sorted=[];for(let t of e){let e=$i(t);e!==null&&(this.entries.set(e.key,e),this.sorted.push(e))}this.sorted.sort((e,t)=>e.seq-t.seq);let t=/* @__PURE__ */ new Map;for(let e=0;e<this.sorted.length;e++){if(this.sorted[e]?.kind===`boundary`)continue;let n=this.runEnd(e);this.assignRun(e,n,t),e=n}return e.map(e=>Qi(e,t.get(e.key)??ki))}apply(e,t){let n=[];for(let t of e){let e=$i(t),r=this.entries.get(t.key);if(r!==void 0){if(e!==null&&ea(r,e)){e.kind===`message`&&n.push(e.seq);continue}this.remove(r),n.push(r.seq)}e!==null&&(this.insert(e),n.push(e.seq))}if(n.length===0)return e;let r=/* @__PURE__ */ new Map;for(let e of n)this.collectAround(e,r);let i=new Map(e.map(e=>[e.key,e]));for(let[e,n]of r){let r=i.get(e)??t.get(e);if(r===void 0)continue;let a=Qi(r,n);(a!==r||i.has(e))&&i.set(e,a)}return[...i.values()]}insert(e){this.sorted.splice(this.lowerBound(e.seq),0,e),this.entries.set(e.key,e)}remove(e){this.sorted.splice(this.sorted.indexOf(e),1),this.entries.delete(e.key)}lowerBound(e){let t=0,n=this.sorted.length;for(;t<n;){let r=t+n>>>1;(this.sorted[r]?.seq??1/0)<e?t=r+1:n=r}return t}runEnd(e){let t=e;for(;t+1<this.sorted.length&&this.sorted[t+1]?.kind!==`boundary`;)t++;return t}runStart(e){let t=e;for(;t-1>=0&&this.sorted[t-1]?.kind!==`boundary`;)t--;return t}assignRun(e,t,n){let r=[];for(let n=e;n<=t;n++){let e=this.sorted[n];e?.kind===`skill`&&e.name!==null&&!r.includes(e.name)&&r.push(e.name)}for(let i=e;i<=t;i++){let e=this.sorted[i];e?.kind===`message`&&n.set(e.key,r)}}collectAround(e,t){let n=this.lowerBound(e),r=this.sorted[n];if(r!==void 0&&r.seq===e&&r.kind!==`boundary`){this.assignRun(this.runStart(n),this.runEnd(n),t);return}n-1>=0&&this.sorted[n-1]?.kind!==`boundary`&&this.assignRun(this.runStart(n-1),n-1,t);let i=r!==void 0&&r.seq===e?n+1:n;i<this.sorted.length&&this.sorted[i]?.kind!==`boundary`&&this.assignRun(i,this.runEnd(i),t)}};let na={anchorSeq:0,nodes:Mi,partial:null,running:null};function ra(e){let t=e;if(e.visibility!==`visible`&&t.kind!==`assistant-step`)return na;switch(t.kind){case`user`:case`steering`:case`context`:case`command`:case`compaction`:case`turn-error`:case`turn-max-tokens`:case`unknown`:return{anchorSeq:t.anchorSeq,nodes:[t.data],partial:null,running:null};case`assistant-step`:{let n=t.data;return n.status===`running`?e.visibility===`visible`?{anchorSeq:t.anchorSeq,nodes:Mi,partial:{turn:n.turn,step:n.step,blocks:n.blocks},running:null}:na:{anchorSeq:t.anchorSeq,nodes:n.finalNode===void 0?Mi:[n.finalNode],partial:null,running:null}}case`tool-call`:{let e=t.data.root;return vi(e)?{anchorSeq:t.anchorSeq,nodes:Mi,partial:null,running:e}:{anchorSeq:t.anchorSeq,nodes:[e],partial:null,running:null}}case`manual-compaction`:{let e=t.data;return{anchorSeq:t.anchorSeq,nodes:e.compaction===null?[e.command]:[e.command,e.compaction],partial:null,running:null}}case`model-retry`:return{anchorSeq:t.anchorSeq,nodes:t.data.attempts,partial:null,running:null};case`turn-tail`:case`system-prompt`:return na;default:return na}}function ia(e,t){return e!==void 0&&e.anchorSeq===t.anchorSeq&&e.partial?.blocks===t.partial?.blocks&&e.partial?.turn===t.partial?.turn&&e.partial?.step===t.partial?.step&&e.running===t.running&&Ni(e.nodes,t.nodes)}var aa=class{contributions=/* @__PURE__ */ new Map;finalizedContributions=/* @__PURE__ */ new Map;runningContributions=/* @__PURE__ */ new Map;partialContributions=/* @__PURE__ */ new Map;finalized=Mi;runningCalls=Mi;partial=null;timeline;turnTimings=/* @__PURE__ */ new Map;turnEnds=/* @__PURE__ */ new Map;replace(e,t){this.contributions.clear(),this.finalizedContributions.clear(),this.runningContributions.clear(),this.partialContributions.clear();for(let t of e){let e=ra(t);this.contributions.set(t.key,e),this.indexContribution(t.key,e)}return this.rebuildFinalized(),this.rebuildRunning(),this.rebuildPartial(),this.updateTimeline(t),this.snapshot()}apply(e,t){let n=!1,r=!1,i=!1;for(let t of e){let e=ra(t),a=this.contributions.get(t.key);ia(a,e)||(n||=sa(a,e),r||=ca(a,e),i||=la(a,e),this.contributions.set(t.key,e),this.indexContribution(t.key,e))}return n&&this.rebuildFinalized(),r&&this.rebuildRunning(),i&&this.rebuildPartial(),this.updateTimeline(t),this.snapshot()}indexContribution(e,t){oa(this.finalizedContributions,e,t,t.nodes.length>0),oa(this.runningContributions,e,t,t.running!==null),oa(this.partialContributions,e,t,t.partial!==null)}rebuildFinalized(){let e=[...this.finalizedContributions.values()].flatMap(e=>e.nodes).sort((e,t)=>e.seq-t.seq);Ni(this.finalized,e)||(this.finalized=e)}rebuildRunning(){let e=[...this.runningContributions.values()].sort((e,t)=>e.anchorSeq-t.anchorSeq).flatMap(e=>e.running===null?[]:[e.running]);Ni(this.runningCalls,e)||(this.runningCalls=e)}rebuildPartial(){let e=[...this.partialContributions.values()].sort((e,t)=>e.anchorSeq-t.anchorSeq).findLast(e=>e.partial!==null)?.partial??null;(this.partial?.blocks!==e?.blocks||this.partial?.turn!==e?.turn||this.partial?.step!==e?.step)&&(this.partial=e)}updateTimeline(e){if(this.timeline===e)return;this.timeline=e;let t=/* @__PURE__ */ new Map,n=/* @__PURE__ */ new Map;for(let r of e.turns.values())r.start!==void 0&&t.set(r.turn,{startTime:r.start.time,...r.end===void 0?{}:{endTime:r.end.time}}),r.end!==void 0&&n.set(r.turn,r.end.seq);this.turnTimings=t,this.turnEnds=n}snapshot(){return{nodes:this.finalized,turnTimings:this.turnTimings,turnEnds:this.turnEnds,partial:this.partial,runningCalls:this.runningCalls}}};function oa(e,t,n,r){r?e.set(t,n):e.delete(t)}function sa(e,t){let n=e?.nodes??Mi;return!Ni(n,t.nodes)||(n.length>0||t.nodes.length>0)&&e?.anchorSeq!==t.anchorSeq}function ca(e,t){return e?.running!==t.running||(e.running!==null||t.running!==null)&&e.anchorSeq!==t.anchorSeq}function la(e,t){return e?.partial?.blocks!==t.partial?.blocks||e?.partial?.turn!==t.partial?.turn||e?.partial?.step!==t.partial?.step||((e?.partial??null)!==null||t.partial!==null)&&e?.anchorSeq!==t.anchorSeq}var ua=class{store=new Li;locations=new Ri;navigation=new Bi;legacy=new aa;referenceLabels=new Zi;skillNames=new ta;order=ki;latestGroupInput;readGroupNode=e=>this.store.get(e);readGroupTurn=e=>this.locations.getTurn(e);readGroupPosition=e=>this.locations.getPosition(e);timeline=null;empty;constructor(){this.empty=this.snapshot({turnOrder:Ai,turns:/* @__PURE__ */ new Map}),this.latestGroupInput={kind:`replace`,order:this.order,readNode:this.readGroupNode,readTurn:this.readGroupTurn,readPosition:this.readGroupPosition,timeline:this.empty.timeline}}replace(e){let t=this.skillNames.replace(this.referenceLabels.replace(e.nodes));return this.store.replace(t),this.order=qi(t).map(e=>e.key),this.locations.rebuild(this.order,this.store),this.store.replaceProcesses(this.order,this.locations),this.navigation.rebuild(e.timeline,this.locations,this.store),this.timeline=e.timeline,this.latestGroupInput={kind:`replace`,order:this.order,readNode:this.readGroupNode,readTurn:this.readGroupTurn,readPosition:this.readGroupPosition,timeline:e.timeline},this.snapshot(e.timeline,this.legacy.replace(t,e.timeline))}apply(e){let t=this.skillNames.apply(this.referenceLabels.apply(e.upserts,this.store),this.store),n=/* @__PURE__ */ new Set,r=!1,i=[],a=[];for(let e of t){let t=this.store.get(e.key);t!==e&&a.push({previous:t,current:e});let o=t===void 0||t.kind!==e.kind||t.anchorSeq!==e.anchorSeq||t.visibility!==e.visibility||fa(t.location)!==fa(e.location);if(r||=o,o||i.push(e),Wi(t,e,o)){let r=t===void 0?void 0:Hi(t.location).turn,i=Hi(e.location).turn;r!==void 0&&n.add(r),i!==void 0&&n.add(i)}}this.store.upsert(t);let o=Ai;if(r){let e=qi(this.store.values()).map(e=>e.key);this.order=Ni(this.order,e)?this.order:e,o=this.locations.rebuild(this.order,this.store)}return this.locations.touch(i),this.store.updateProcesses(n,this.locations),r||e.timeline!==this.timeline?this.navigation.rebuild(e.timeline,this.locations,this.store):this.navigation.touch(da(i),this.locations,this.store),this.timeline=e.timeline,this.latestGroupInput={kind:`apply`,changes:a,order:this.order,readNode:this.readGroupNode,readTurn:this.readGroupTurn,readPosition:this.readGroupPosition,timeline:e.timeline,changedTurns:e.changedTurns??Ai,changedTurnOrders:o},this.snapshot(e.timeline,this.legacy.apply(t,e.timeline))}groupInput(){return this.latestGroupInput}publish(){this.store.publish()}snapshot(e,t=this.legacy.replace(Mi,e)){return{order:this.order,nodes:this.store,locations:this.locations,navigation:this.navigation,timeline:e,legacy:t}}};function da(e){let t=/* @__PURE__ */ new Set;for(let n of e){let e=Hi(n.location).turn;e!==void 0&&t.add(e)}return t}function fa(e){let t=Hi(e);return`${e.kind}:${t.turn??``}:${t.step??``}`}let pa={target:`chat`,create:()=>new ua,isActive:e=>e.order.some(t=>e.nodes.get(t)?.kind!==`command`)};function ma(e){e.uiConversation.views.register(pa)}let ha=/* @__PURE__ */ new Set([`system/message`,`developer/message`,`user/message`,`assistant/message`,`tool/result`]);function ga(e){return ha.has(e.type)?e.surfaceOp!==void 0:!1}function _a(e){return ga(e)&&e.surfaceOp===`append`}function va(e){return ga(e)&&e.surfaceOp!==`append`}function ya(e){if(e.event.type!==`command/run`)throw Error(`command start requires command/run`);let t=e.event.data;return{kind:`command`,seq:e.event.seq,time:e.event.time,commandId:t.commandId,name:t.name,args:t.args??null,outcome:null}}function ba(e,t){if(e.event.type!==`command/done`)throw Error(`command update requires command/done`);let n=e.event.data,r=n.kind===`success`&&n.sourceEventSeq!==void 0&&Number.isSafeInteger(n.sourceEventSeq)&&n.sourceEventSeq>=0?n.sourceEventSeq:void 0;return{kind:`command`,seq:t?.seq??e.event.seq,time:t?.time??e.event.time,commandId:n.commandId,name:t?.name??null,args:t?.args??null,outcome:{kind:n.kind,...n.text===void 0?{}:{text:n.text},...r===void 0?{}:{sourceEventSeq:r}}}}function xa(e){if(e.type!==`user/message`||!va(e))return;let t=e.data.source;if(t.kind===`compact-checkpoint`&&typeof t.compactionId==`string`)return{compactionId:t.compactionId,...t.sourceCommandId===void 0?{}:{sourceCommandId:t.sourceCommandId}}}function Sa(e,t){let n=null,r=null,i=null;if(e?.event.type===`compaction/summary`){let t=e.event.data;if(Array.isArray(t.summary)){let e=t.summary.map(e=>e.type===`text`?e.text:``).join(``);n=e.trim()===``?null:e}r=Array.isArray(t.shadowedSeqs)&&t.shadowedSeqs.every(e=>Number.isSafeInteger(e)&&e>=0)?t.shadowedSeqs.length:null,i=Number.isSafeInteger(t.shadowedTokenCount)&&t.shadowedTokenCount>=0?t.shadowedTokenCount:null}return{kind:`compaction`,seq:t.event.seq,time:t.event.time,summary:n,summaryEventSeq:e?.event.seq??null,shadowedItemCount:r,shadowedTokenCount:i}}function Ca(e){let t=e.matches.find(e=>e.event.type===`command/done`),n=e.matches.find(e=>xa(e.event)!==void 0),r=e.matches.find(e=>e.event.type===`compaction/summary`);if(n===void 0)return t===void 0?void 0:{command:ba(t)};let i=xa(n.event);return i?.sourceCommandId===void 0?t===void 0?void 0:{command:ba(t)}:{command:t===void 0?{kind:`command`,seq:n.event.seq,time:n.event.time,commandId:i.sourceCommandId,name:`compact`,args:null,outcome:null}:{...ba(t),name:`compact`},checkpoint:n,...r===void 0?{}:{summary:r}}}function wa(e,t){return t.event.type===`compaction/summary`?{...e,summary:t}:xa(t.event)===void 0?e:{...e,checkpoint:t}}let Ta={kind:`command`,target:`chat`,match:e=>{if(e.type===`command/run`)return{id:String(e.data.commandId),role:`start`};if(e.type===`command/done`)return{id:String(e.data.commandId),role:`update`};let t=xa(e);return t?.sourceCommandId===void 0?(e.type===`compaction/start`||e.type===`compaction/summary`||e.type===`compaction/end`)&&e.data.sourceCommandId!==void 0?{id:String(e.data.sourceCommandId),role:`update`}:null:{id:String(t.sourceCommandId),role:`update`}},start:(e,t)=>({command:ya(t)}),update:(e,t)=>t.event.type===`command/done`?{...e.state,command:ba(t,e.state.command)}:wa(e.state,t),buildViewNode:e=>{let t=e.state??Ca(e);if(t===void 0)return null;if(t.command.name!==`compact`)return J(e,`command`,t.command.seq,t.command);let n=t.checkpoint===void 0?null:Sa(t.summary,t.checkpoint),r={command:t.command,compaction:n};return J(e,`manual-compaction`,n?.seq??t.command.seq,r)}};function Ea(e){e.uiConversation.events.register(Ta)}function Da(e){let t=e.matches.find(e=>e.event.type===`compaction/summary`),n=e.matches.find(e=>xa(e.event)!==void 0);return{...t===void 0?{}:{summary:t},...n===void 0?{}:{checkpoint:n}}}let Oa={kind:`compaction`,target:`chat`,match:e=>{let t=xa(e);if(t!==void 0&&t.sourceCommandId===void 0)return{id:t.compactionId,role:`update`};if(e.type===`compaction/start`||e.type===`compaction/summary`||e.type===`compaction/end`){if(e.data.sourceCommandId!==void 0)return null;let t=e.data.compactionId;return typeof t!=`string`||t===``?null:{id:t,role:e.type===`compaction/start`?`start`:`update`}}return null},start:()=>({}),update:(e,t)=>wa(e.state,t),buildViewNode:e=>{let t=e.state??Da(e);if(t.checkpoint===void 0)return null;let n=Sa(t.summary,t.checkpoint);return J(e,`compaction`,n.seq,n)}};function ka(e){e.uiConversation.events.register(Oa)}let Aa={kind:`unknown-surface`,target:`chat`,match:e=>e.type!==`assistant/live-chunk`&&_a(e)?{id:String(e.seq),role:`start`}:null,start:(e,t)=>({kind:`unknown`,seq:t.event.seq,time:t.event.time,type:t.event.type,data:t.event.data}),update:e=>e.state,buildViewNode:e=>e.state===void 0?null:J(e,`unknown`,e.state.seq,e.state)};function ja(e){e.uiConversation.events.registerFallback(Aa)}let Ma={kind:`snapshot`,ids:[]},Na=/* @__PURE__ */ new Set;function Pa(e){let t=[],n=e;for(;n.kind===`splice`;)t.push(n),n=n.previous;let r=[...n.ids];for(let e of t.reverse())r.splice(e.start,e.removedCount,...e.inserted);return r}function Fa(e,t){let n;for(let{id:r}of t)e.has(r)&&(n??=new Set(e),n.delete(r));return n??e}function Ia(e,t,n){let r=e?.state.pending??Ma,i=t.inserted,a=t.removedCount??0;if(a>0&&t.outcome!==`canceled`){let e=Pa(r),o=e.splice(t.start,a,...i);return{pending:{kind:`snapshot`,ids:e},currentClaimed:new Set(o.map(e=>e.id)),claimSeq:n,claimedHuman:o.some(e=>e.source.kind===`user`)}}let o=Fa(e?.state.currentClaimed??Na,i);return{pending:{kind:`splice`,previous:r,start:t.start,removedCount:a,inserted:i},currentClaimed:o,claimSeq:e?.state.claimSeq??-1,claimedHuman:e?.state.claimedHuman??!1}}function La(e){let t=`inbox-${e}`;return{kind:t,match:t=>t.type===`agent/inbox/spliced`&&t.data.target===e?{id:String(t.seq),role:`start`}:null,start:(e,n,r)=>{if(n.event.type!==`agent/inbox/spliced`)throw Error(`inbox start requires agent/inbox/spliced`);return Ia(r.previous(t),n.event.data,n.event.seq)},update:e=>e.state,publication:()=>`none`}}let Ra=La(`next-step`),za=La(`next-turn`);function Ba(e){e.uiConversation.events.register(Ra),e.uiConversation.events.register(za)}function Va(e){return e.type!==`user/message`||!va(e)?!1:e.data.source.kind===`compact-checkpoint`}function Ha(e,t){return{kind:`context`,seq:e.seq,time:e.time,content:t.content,source:t.source,producer:Jr(t.source),form:qr(t.source)}}let Ua={kind:`input-message`,target:`chat`,match:e=>e.type===`user/message`&&_a(e)&&!Va(e)?{id:String(e.data.id),role:`start`}:null,start:(e,t,n)=>{let r=t.event;if(r.type!==`user/message`)throw Error(`input-message start requires user/message`);if(r.data.source.kind!==`user`){let e=n.previous(`inbox-next-turn`)?.state,i=n.previous(`inbox-next-step`)?.state,a=t.location,o=a.kind===`step`?a.turn.start?.seq:void 0,s=a.kind===`step`&&a.step.step===1&&o!==void 0&&(i?.claimSeq??-1)>o&&(e?.claimSeq??-1)<o&&i?.claimedHuman===!1&&i.currentClaimed.has(String(r.data.id));return{...Ha(r,r.data),waking:e?.currentClaimed.has(String(r.data.id))===!0||s}}return n.previous(`inbox-next-step`)?.state.currentClaimed.has(String(r.data.id))===!0?{kind:`steering`,messageId:r.data.id,seq:r.seq,time:r.time,content:r.data.content,source:r.data.source}:{kind:`user`,seq:r.seq,time:r.time,content:r.data.content,source:r.data.source}},update:e=>e.state,buildViewNode:e=>e.state===void 0?null:J(e,e.state.kind===`context`&&e.start?.event.type===`user/message`&&e.state.waking===!0?`turn-trigger`:e.state.kind,e.state.seq,e.state)},Wa={...Ua,kind:`developer-message`,match:e=>e.type===`developer/message`?{id:String(e.data.message.id),role:`start`}:null,start:(e,t)=>{let n=t.event;if(n.type!==`developer/message`)throw Error(`developer-message start requires developer/message`);return Ha(n,n.data.message)}};function Ga(e){e.uiConversation.events.register(Ua),e.uiConversation.events.register(Wa)}function Ka(e,t,n){return e.location.kind!==`step`||t===void 0&&!n||t?.turn===e.location.turn.turn&&t.step===e.location.step.step?e.event.seq:e.location.step.step===1?e.location.turn.start?.seq??e.location.step.start?.seq??e.event.seq:e.location.step.start?.seq??e.event.seq}function qa(e,t,n,r){let i=e.current.get(`chat`);return i?.kind===`system-prompt`?i.anchorSeq:Ka(t,n,r)}function Ja(e){return{kind:`system-message`,target:`chat`,match:e=>e.type===`system/message`||`surfaceOp`in e&&e.surfaceOp!==`append`?{id:String(e.seq),role:`start`}:null,start:(t,n,r)=>{if(n.event.type===`assistant/live-chunk`)throw Error(`system-message requires a durable event`);return e(r.previous(`system-message`)?.state,n.event)},update:e=>e.state,buildViewNode:e=>{let t=e.state?.introduced;return t===void 0||t.text===``||e.start?.event.type!==`system/message`||e.start.event.surfaceOp!==`append`?null:J(e,`system-prompt`,t.update?t.seq:Ka(e.start,void 0,!0),{text:t.text,...t.update?{update:!0}:{}})}}}function Ya(e){return{kind:`request-prompt`,target:`chat`,match:e=>e.type===`request/header`?{id:String(e.seq),role:`start`}:null,start:(t,n,r)=>{if(n.event.type!==`request/header`)throw Error(`request-prompt start requires request/header`);let i=r.previous(`request-prompt`)?.state,a=r.previous(`system-message`),o=a?.state.effective,s=n.location.kind===`step`?{turn:n.location.turn.turn,step:n.location.step.step}:{},c=e(i?.prompt,n.event,o),l=c.change?.kind,u=a?.matches[0]?.event,d=o!==void 0&&u?.type===`system/message`&&u.surfaceOp===`append`&&(o.update||i===void 0)&&o.turn===s.turn&&o.step===s.step;return{anchorSeq:qa(t,n,i,n.event.data.reason===`initial`),showsPrompt:!d&&(i===void 0||n.event.data.reason!==`change`||n.event.data.startsSeries===!0||l===`system`||l===`system-and-tools`),...s,...c}},update:e=>e.state,buildViewNode:e=>{let t=e.state;if(t===void 0)return null;let n=e.current.get(`chat`),r=t.showsPrompt&&t.prompt.system!==``;return!r&&n?.kind!==`system-prompt`?null:J(e,`system-prompt`,t.anchorSeq,{text:t.prompt.system},{visibility:r?`visible`:`hidden`})}}}function Xa(e){e.uiConversation.events.register(Ja((t,n)=>e.uiConversation.inspectSystemPrompt(t,n))),e.uiConversation.events.register(Ya((t,n,r)=>e.uiConversation.inspectRequestPrompt(t,n,r)))}function Za(e){if(e.event.type===`llm/retry`)return{kind:`model-retry`,seq:e.event.seq,time:e.event.time,retryState:`scheduled`,...e.event.data}}function Qa(e){return e.kind===`step`&&e.step.status===`closed`||(e.kind===`step`||e.kind===`turn`)&&e.turn.status===`closed`}let $a={kind:`model-retry`,target:`chat`,match:e=>{if(e.type===`llm/retry`){let t=e.data.retryId;return typeof t!=`string`||t===``?null:{id:t,role:e.data.retry===1?`start`:`update`}}if(e.type===`llm/retry-started`){let t=e.data.retryId;return typeof t==`string`&&t!==``?{id:t,role:`update`}:null}return null},start:(e,t)=>{let n=Za(t);if(n===void 0)throw Error(`model-retry start requires a valid llm/retry event`);return{turn:n.turn,step:n.step,attempts:[n]}},update:(e,t)=>{if(t.event.type===`llm/retry`){let n=Za(t);return n===void 0?e.state:{...e.state,attempts:[...e.state.attempts,n]}}if(t.event.type!==`llm/retry-started`)return e.state;let n=t.event.data.retry;return{...e.state,attempts:e.state.attempts.map(e=>e.retry===n?{...e,retryState:`started`}:e)}},buildViewNode:e=>{if(e.state===void 0||e.state.attempts.length===0)return null;let t=e.start?.location??e.matches[0]?.location??{kind:`unresolved`},n=e.state.attempts,r=n.map((e,r)=>r===n.length-1&&e.retryState===`scheduled`&&Qa(t)?{...e,retryState:`cancelled`}:e),i=r.at(-1);if(i===void 0)return null;let a={attempts:r,current:i};return J(e,`model-retry`,r[0]?.seq??i.seq,a)}};function eo(e){e.uiConversation.events.register($a)}let to=/* @__PURE__ */ new WeakMap;function no(e){return JSON.stringify(e)}function ro(e,t){if(e.event.type!==`tool/call`)throw Error(`tool-call start requires tool/call`);return{phase:`start`,callId:String(e.event.data.callId),name:e.event.data.name,argsRaw:e.event.data.arguments,args:t===void 0?Dt.fromText(e.event.data.arguments):t.args.settle(e.event.data.arguments),turn:e.event.data.turn,step:e.event.data.step,time:e.event.time,subCalls:[]}}function io(e,t){let n=t.event;if(n.type!==`assistant/live-chunk`)return e;let r=n.data.chunk,i=e.root;if(r.type===`block-end`&&r.block.type===`tool-call`)return i===void 0||`kind`in i||i.phase!==`preparing`?e:{...e,root:{...i,name:r.block.name,args:i.args.settle(r.block.arguments)}};if(r.type!==`tool-call-delta`)return e;if(i===void 0){if(!r.name)return e;let t=new Dt;return t.append(r.argumentsDelta),{...e,root:{phase:`preparing`,callId:String(r.id),name:r.name,turn:n.data.turn,step:n.data.step,time:n.time,subCalls:[],args:t}}}return`kind`in i||i.phase!==`preparing`||i.args.isSealed||i.args.append(r.argumentsDelta),e}function ao(e,t){let n=e.args.refresh();return!n&&t!==void 0&&!(`kind`in t)&&t.phase===`preparing`&&t.name===e.name&&t.args===e.args?t:n?{...e}:e}function oo(e,t){if(e.event.type!==`tool/result`)return;let n=e.event.data.message;return{kind:`tool-result`,seq:e.event.seq,time:e.event.time,callId:String(n.source.callId),name:t?.name??``,args:t?.args??Dt.EMPTY,call:t===void 0?null:{name:t.name,argsRaw:t.argsRaw},callTime:t?.time??null,content:n.content,isError:n.isError===!0,...e.event.data.error===void 0?{}:{error:e.event.data.error},meta:e.event.data.meta,subCalls:[]}}function so(e,t){return{phase:`start`,callId:t.subCallId,parentCallId:t.parentCallId,name:t.name,argsRaw:no(t.arguments),args:Dt.fromObject(t.arguments),turn:lo(e),step:uo(e),time:e.event.time,subCalls:[]}}function co(e,t,n){return{kind:`tool-result`,seq:e.event.seq,time:e.event.time,callId:t.subCallId,parentCallId:t.parentCallId,name:t.name,args:n!==void 0&&!(`kind`in n)?n.args:Dt.fromObject(t.arguments),call:{name:t.name,argsRaw:no(t.arguments)},callTime:n?.time??null,content:t.content??[],isError:t.isError===!0,...t.error===void 0?{}:{error:t.error},subCalls:[]}}function lo(e){return e.location.kind===`step`||e.location.kind===`turn`?e.location.turn.turn:0}function uo(e){return e.location.kind===`step`?e.location.step.step:0}function fo(e,t,n){if(t===n||e.parents.has(n))return!1;let r=t,i=0,a=/* @__PURE__ */ new Set;for(;r!==void 0;){if(r===n||a.has(r))return!1;a.add(r),i++,r=e.parents.get(r)}let o=[{callId:n,depth:1}],s=/* @__PURE__ */ new Set,c=0;for(let t of o){if(s.has(t.callId))return!1;s.add(t.callId),c=Math.max(c,t.depth);for(let n of e.children.get(t.callId)??[])o.push({callId:n.callId,depth:t.depth+1})}return i+c<=256}function po(e,t){let n=t.event;if(n.type!==`tool/ptc-dispatch-start`&&n.type!==`tool/ptc-dispatch`)return e;let r=n.data,i=String(r.parentCallId),a=String(r.subCallId),o=e.children.get(i)??[],s=o.findIndex(e=>e.callId===a);if(n.type===`tool/ptc-dispatch-start`){if(s>=0||!fo(e,i,a))return e;let n=new Map(e.children);n.set(i,[...o,so(t,r)]);let c=new Map(e.parents);return c.set(a,i),{...e,children:n,parents:c}}if(s<0&&!fo(e,i,a))return e;let c=co(t,r,s<0?void 0:o[s]),l=new Map(e.children);l.set(i,s<0?[...o,c]:o.map((e,t)=>t===s?c:e));let u=new Map(e.parents);return s<0&&u.set(a,i),{...e,children:l,parents:u}}function mo(e,t,n,r=/* @__PURE__ */ new Set,i=1){if(!(`kind`in e)&&e.phase===`preparing`)return e;if(r.has(e.callId)||i>256)return{...e,subCalls:[]};let a=new Set(r);a.add(e.callId);let o=(t.children.get(e.callId)??e.subCalls).map(e=>mo(e,t,n,a,i+1)),s=`kind`in e?void 0:n?.seq,c=`kind`in e?void 0:n?.time,l=to.get(e);if(l!==void 0&&l.interruptionSeq===s&&l.interruptionTime===c&&ho(l.children,o))return l.value;let u=`kind`in e||n===void 0?ho(e.subCalls,o)?e:{...e,subCalls:o}:{kind:`tool-result`,seq:n.seq+Br.interruptedFollowup,time:n.time,callId:e.callId,...e.parentCallId===void 0?{}:{parentCallId:e.parentCallId},name:e.name,args:e.args,call:{name:e.name,argsRaw:e.argsRaw},callTime:e.time,content:[],isError:!0,error:{name:`Interrupted`,code:`interrupted`},subCalls:o};return to.set(e,{children:o,interruptionSeq:s,interruptionTime:c,value:u}),u}function ho(e,t){return e.length===t.length&&e.every((e,n)=>e===t[n])}function go(e){let t=e.start?.location;if(t?.kind===`step`&&t.step.status===`closed`)return t.step.end;if((t?.kind===`step`||t?.kind===`turn`)&&t.turn.status===`closed`)return t.turn.end}function _o(e){let t=e.matches.find(e=>e.event.type===`tool/result`),n=t===void 0?void 0:oo(t);if(n===void 0)return;let r={root:n,children:/* @__PURE__ */ new Map,parents:/* @__PURE__ */ new Map};for(let t of e.matches)r=po(r,t);return r}let vo={kind:`tool-call`,target:`chat`,match:e=>{if(e.type===`assistant/live-chunk`){let t=e.data.chunk;return t.type===`block-end`&&t.block.type===`tool-call`?{id:String(t.block.id),role:`start`}:t.type===`tool-call-delta`?{id:String(t.id),role:`start`}:null}if(e.type===`tool/call`)return{id:String(e.data.callId),role:`start`};if(e.type===`tool/result`&&_a(e))return{id:String(e.data.message.source.callId),role:`update`};if(e.type===`tool/ptc-dispatch-start`||e.type===`tool/ptc-dispatch`){let t=e.data.rootCallId;return typeof t==`string`&&t!==``?{id:t,role:`update`}:null}return null},start:(e,t)=>{let n={root:void 0,children:/* @__PURE__ */ new Map,parents:/* @__PURE__ */ new Map};return t.event.type===`tool/call`?{...n,root:ro(t)}:io(n,t)},update:(e,t)=>{if(t.event.type===`assistant/live-chunk`)return io(e.state,t);if(t.event.type===`tool/call`)return{...e.state,root:ro(t,e.state.root)};if(t.event.type===`tool/result`){let n=e.state.root,r=oo(t,n!==void 0&&!(`kind`in n)&&n.phase===`start`?n:void 0);return r===void 0?e.state:{...e.state,root:r}}return po(e.state,t)},publication:e=>e.event.type===`assistant/live-chunk`?`animation-frame`:`immediate`,buildViewNode:e=>{let t=e.current.get(`chat`),n=e.state??_o(e);if(n?.root===void 0)return t==null?null:t.visibility===`hidden`?t:{...t,visibility:`hidden`};let r=go(e),i=mo(!(`kind`in n.root)&&n.root.phase===`preparing`?ao(n.root,t?.data.root):n.root,n,r),a=e.start?.event.seq??(`kind`in n.root?n.root.seq:e.matches[0]?.event.seq??0),o=!(`kind`in i)&&i.phase===`preparing`&&r!==void 0?`hidden`:`visible`,s=Vr(e),c=pt(i.name)&&s.kind===`step`?{kind:`turn`,turn:s.turn}:s,l=t?.data.root===i?t.data:{root:i};return t?.data===l&&t.anchorSeq===a&&t.visibility===o&&t.location===c?t:J(e,`tool-call`,a,l,{visibility:o,location:c})}};function yo(e){let t=vo.match.bind(vo);e.uiConversation.events.register({...vo,match:{"assistant/live-chunk":t,"tool/call":t,"tool/result":t,"tool/ptc-dispatch-start":t,"tool/ptc-dispatch":t}})}function bo(e){let t=e.start?.location??e.matches[0]?.location;return t?.kind!==`turn`&&t?.kind!==`step`?0:t.turn.steps.at(-1)?.step??0}function xo(e){if(e.event.type!==`turn/end`)return;let t=e.event.data.reason,n=t.kind===`error`?t.error:t.kind===`aborted`&&t.reason.kind===`hook`&&t.reason.reason===`deepseek-account/signed-out`?{message:`Stopped because you signed out of DeepSeek.`,code:`ACCOUNT_SIGNED_OUT`}:void 0;if(n===void 0)return;let r=ei(n);return{seq:e.event.seq,time:e.event.time,message:r.message,...r.code===void 0?{}:{code:r.code}}}function So(e){let t=e.matches.find(e=>xo(e)!==void 0);if(t?.event.type!==`turn/end`)return;let n=xo(t);if(n!==void 0)return{turn:t.event.data.turn,failure:n}}let Co={kind:`turn-error`,target:`chat`,match:e=>e.type===`turn/start`?{id:String(e.data.turn),role:`start`}:e.type===`turn/end`&&(e.data.reason.kind===`error`||e.data.reason.kind===`aborted`&&e.data.reason.reason.kind===`hook`&&e.data.reason.reason.reason===`deepseek-account/signed-out`)?{id:String(e.data.turn),role:`update`}:null,start:(e,t)=>{if(t.event.type!==`turn/start`)throw Error(`turn-error start requires turn/start`);return{turn:t.event.data.turn}},update:(e,t)=>{let n=xo(t);return n===void 0?e.state:{...e.state,failure:n}},buildViewNode:e=>{let t=e.state??So(e);if(t?.failure===void 0)return null;let n=t.failure,r={kind:`turn-error`,seq:n.seq,time:n.time,turn:t.turn,step:bo(e),message:n.message,...n.code===void 0?{}:{code:n.code}};return J(e,`turn-error`,r.seq,r)}};function wo(e){e.uiConversation.events.register(Co)}function To(e){let t=e.start?.location??e.matches[0]?.location;return t?.kind!==`turn`&&t?.kind!==`step`?0:t.turn.steps.at(-1)?.step??0}function Eo(e,t){let n=e.start?.location??e.matches[0]?.location;if(n?.kind!==`turn`&&n?.kind!==`step`)return t;let r=n.turn.data.get(`turn-tail`)?.closing;return r==null?t:r.finalNode.seq+Br.maxTokensNotice}function Do(e){if(e.event.type===`turn/end`&&e.event.data.reason.kind===`max-tokens`)return{turn:e.event.data.turn,seq:e.event.seq,time:e.event.time}}let Oo={kind:`turn-max-tokens`,target:`chat`,match:e=>e.type===`turn/end`&&e.data.reason.kind===`max-tokens`?{id:String(e.data.turn),role:`start`}:null,start:(e,t)=>{let n=Do(t);if(n===void 0)throw Error(`turn-max-tokens start requires a max-tokens turn/end`);return n},update:e=>e.state,buildViewNode:e=>{let t=e.state;if(t===void 0)return null;let n={kind:`turn-max-tokens`,seq:t.seq,time:t.time,turn:t.turn,step:To(e)};return J(e,`turn-max-tokens`,Eo(e,t.seq),n)}};function ko(e){e.uiConversation.events.register(Oo)}function Ao(e){let t=e.data;return typeof t.turn==`number`?t.turn:void 0}function jo(e){if(e.type===`text-delta`||e.type===`reasoning-delta`)return e.text.trim()!==``;if(e.type===`block-start`)return e.blockType!==`text`&&e.blockType!==`reasoning`&&e.blockType!==`tool-call`;if(e.type!==`block-end`)return!1;let t=e.block;return t.type===`tool-call`?!1:t.type===`text`||t.type===`reasoning`?t.text.trim()!==``:!0}function Mo(e){return e.type===`assistant/live-chunk`?jo(e.data.chunk):e.type!==`assistant/attempt`&&e.type===`assistant/message`&&e.surfaceOp===`append`&&Zr(e.data.message.content).some(e=>e.kind===`tool-call`?!1:e.kind===`text`||e.kind===`reasoning`?e.text.trim()!==``:!0)}function No(e,t){return e.type===`tool/call`?pt(e.data.name):e.type===`tool/result`&&t.has(String(e.data.message.source.callId))}function Po(e,t){if(Mo(e))return e.type!==`assistant/live-chunk`&&e.type!==`assistant/message`&&e.type!==`assistant/attempt`?void 0:{kind:`assistant`,seq:e.seq,step:e.data.step};if(!No(e,t)&&(e.type===`tool/call`||e.type===`tool/result`&&e.surfaceOp===`append`||e.type===`llm/retry`))return{kind:`other`,seq:e.seq}}function Fo(e){let t=e.start?.location??e.matches.at(-1)?.location;return t?.kind===`turn`||t?.kind===`step`?t.turn:void 0}function Io(e){let t=e.matches.map(e=>Ao(e.event)).find(e=>e!==void 0);if(t===void 0)return;let n={turn:t,assistantStartByStep:/* @__PURE__ */ new Map,messageCountByStep:/* @__PURE__ */ new Map,messageCount:0,toolCallCount:0,subagentCount:0,contextCompactionCalls:/* @__PURE__ */ new Set};for(let t of e.matches)n=Bo(n,t.event);return n}function Lo(e){return e?.finalNode!==void 0}function Ro(e){let t=e.end?.data.finalAssistantStep;if(t===null)return null;let n=(t===void 0?e.steps.at(-1):e.steps.find(e=>e.step===t))?.data.get(`assistant-step`);return!Lo(n)||n.finalNode.interrupted===!0||!Dr(n.blocks)||t===void 0&&n.blocks.some(e=>e.kind===`tool-call`)?null:n}function zo(e,t){let n=e.controlAnchorSeq??t.start?.seq;if(n===void 0)return null;let r=Ro(t),i={messageCount:r===null?e.messageCount:[...e.messageCountByStep].filter(([e])=>e!==r.step).reduce((e,[,t])=>e+t,0),toolCallCount:e.toolCallCount,subagentCount:e.subagentCount};if(r===null)return{turn:t.turn,controlAnchorSeq:n,processStartSeq:n,answerAnchorSeq:null,answerStep:null,inlineReasoning:!1,...i};let a=r.blocks.some(e=>e.kind===`reasoning`&&e.text.trim()!==``),o=Math.min(...[...e.assistantStartByStep].filter(([e])=>e<r.step).map(([,e])=>e)),s=Math.min(e.otherStartSeq??1/0,o);return{turn:t.turn,controlAnchorSeq:n,processStartSeq:t.start?.seq??(Number.isFinite(s)?s:r.finalNode.seq),answerAnchorSeq:r.finalNode.seq,answerStep:r.step,inlineReasoning:a,...i}}function Bo(e,t){let n=e;if(t.type===`assistant/message`&&t.surfaceOp===`append`&&Dr(Zr(t.data.message.content))){let e=new Map(n.messageCountByStep);e.set(t.data.step,(e.get(t.data.step)??0)+1),n={...n,messageCountByStep:e,messageCount:n.messageCount+1}}if(t.type===`tool/call`){if(pt(t.data.name)){let e=new Set(n.contextCompactionCalls);e.add(String(t.data.callId)),n={...n,contextCompactionCalls:e}}else{let e=ft(t.data.name);n={...n,toolCallCount:n.toolCallCount+ +!e,subagentCount:n.subagentCount+ +!!e}}}let r=Po(t,n.contextCompactionCalls);if(r===void 0)return n;if(r.kind===`other`)return n.otherStartSeq===void 0?{...n,otherStartSeq:r.seq,controlAnchorSeq:Math.min(n.controlAnchorSeq??1/0,r.seq)}:n;if(n.assistantStartByStep.has(r.step))return n;let i=new Map(n.assistantStartByStep);return i.set(r.step,r.seq),{...n,assistantStartByStep:i,controlAnchorSeq:Math.min(n.controlAnchorSeq??1/0,r.seq)}}let Vo={kind:`turn-process`,target:`chat`,match:e=>{if(e.type===`turn/start`)return{id:String(e.data.turn),role:`start`};let t=Ao(e);return t===void 0?null:e.type===`assistant/live-chunk`||e.type===`assistant/message`||e.type===`tool/call`||e.type===`tool/result`||e.type===`llm/retry`||e.type===`step/start`||e.type===`step/end`||e.type===`turn/end`?{id:String(t),role:`update`}:null},start:(e,t)=>{if(t.event.type!==`turn/start`)throw Error(`turn-process start requires turn/start`);return{turn:t.event.data.turn,assistantStartByStep:/* @__PURE__ */ new Map,messageCountByStep:/* @__PURE__ */ new Map,messageCount:0,toolCallCount:0,subagentCount:0,contextCompactionCalls:/* @__PURE__ */ new Set}},update:(e,t)=>Bo(e.state,t.event),publication:e=>{if(e.event.type===`assistant/live-chunk`){let t=e.event.data.chunk.type;return t===`usage`||t===`finish`?`none`:`animation-frame`}return`immediate`},buildLocationData:(e,t,n)=>{if(t!==`turn`)return null;let r=e.state??Io(e);if(r===void 0)return null;let i=Fo(e);if(i===void 0)return null;let a=e.current.get(`chat`),o=i.steps.at(-1);if(n?.kind===`turn`&&n.key===`turn-process`&&a?.kind===`turn-process`&&a.data.answerAnchorSeq===null&&a.data.controlAnchorSeq===r.controlAnchorSeq&&a.data.messageCount===r.messageCount&&a.data.toolCallCount===r.toolCallCount&&a.data.subagentCount===r.subagentCount&&i.status!==`closed`&&o?.status!==`closed`)return n;let s=zo(r,i);return s===null?null:n?.kind===`turn`&&n.turn===s.turn&&n.key===`turn-process`&&dt(n.value,s)?n:{kind:`turn`,turn:i.turn,key:`turn-process`,value:s}},buildViewNode:e=>{let t=Fo(e),n=t?.data.get(`turn-process`);if(t===void 0||n===void 0)return null;let r=e.current.get(`chat`),i=e.state;return r?.kind===`turn-process`&&i!==void 0&&r.data.answerAnchorSeq===null&&r.data.controlAnchorSeq===i.controlAnchorSeq&&r.data.messageCount===i.messageCount&&r.data.toolCallCount===i.toolCallCount&&r.data.subagentCount===i.subagentCount&&t.status!==`closed`&&t.steps.at(-1)?.status!==`closed`&&r.location===(e.start?.location??e.matches[0]?.location)?r:J(e,`turn-process`,n.controlAnchorSeq+Br.processControl,n)}};function Ho(e){let t=Vo.match.bind(Vo);e.uiConversation.events.register({...Vo,match:{"turn/start":t,"assistant/live-chunk":t,"assistant/message":t,"tool/call":t,"tool/result":t,"llm/retry":t,"step/start":t,"step/end":t,"turn/end":t}})}function Uo(e,t){for(let n=e.length-1;n>=0;--n){let r=e[n];if(r.type===`chunk`&&r.chunk.type===t)return r.chunk}}function Y(e){return typeof e==`number`&&Number.isSafeInteger(e)&&e>=0}function Wo(e){let t=0;for(let n of e)if(t+=n,!Number.isSafeInteger(t))return;return t}function Go(e){let{provider:t,model:n}=e.source;return t.length>0&&n.length>0?{provider:t,model:n}:void 0}function Ko(e){return Uo(e,`usage`)?.usage}function qo(e,t){let{inputTokens:n,outputTokens:r,cacheReadTokens:i,cacheWriteTokens:a,reasoningTokens:o,totalTokens:s}=e;if(!Y(n)||!Y(r)||i!==void 0&&!Y(i)||a!==void 0&&!Y(a)||o!==void 0&&(!Y(o)||o>r))return;let c=Wo([n,...i===void 0?[]:[i],...a===void 0?[]:[a]]);if(c===void 0)return;let l;if(s!==void 0){if(!Y(s))return;let e=s-r;if(!Y(e)||e<c||i!==void 0&&a!==void 0&&e!==c)return;l=s}else{if(i===void 0||a===void 0)return;let e=Wo([c,r]);if(e===void 0)return;l=e}return{inputTokens:n,outputTokens:r,totalTokens:l,...i===void 0?{}:{cacheReadTokens:i},...a===void 0?{}:{cacheWriteTokens:a},...o===void 0?{}:{reasoningTokens:o},...t===void 0?{}:{route:t}}}function Jo(e){if(e.length===0)return;let t=Wo(e.map(e=>e.inputTokens)),n=Wo(e.map(e=>e.outputTokens)),r=Wo(e.map(e=>e.totalTokens));if(t===void 0||n===void 0||r===void 0)return;let i=e.map(e=>e.cacheReadTokens),a=e.map(e=>e.cacheWriteTokens),o=e.map(e=>e.reasoningTokens),s=i.every(Y)?Wo(i):void 0,c=a.every(Y)?Wo(a):void 0,l=o.every(Y)?Wo(o):void 0,u,d=e.map(e=>e.route);if(d.every(e=>e!==void 0)){let e=/* @__PURE__ */ new Map;for(let t of d)e.set(`${t.provider}\0${t.model}`,t);u=[...e.values()]}return{uncachedInputTokens:t,outputTokens:n,totalTokens:r,...s===void 0?{}:{cacheReadTokens:s},...c===void 0?{}:{cacheWriteTokens:c},...l===void 0?{}:{reasoningTokens:l},...u===void 0?{}:{routes:u}}}function Yo(e,t,n){return e.turn===t&&e.step===n}function Xo(e){let t={kind:`idle`},n=[],r,i=!1,a=!1,o=e=>{if(t.kind!==`open`||t.sample===void 0)return!1;let r=qo(t.sample,e);return r!==void 0&&(n.push(r),!0)};for(let n of e){if(a)break;if(n.type===`turn/start`)r!==void 0||t.kind!==`idle`?a=!0:r=n.data.turn;else{if(r===void 0){a=!0;break}if(n.type===`turn/end`)n.data.turn!==r||t.kind!==`idle`||i?a=!0:i=!0;else{if(i){a=!0;break}if(n.type===`step/start`)n.data.turn!==r||t.kind!==`idle`?a=!0:t={kind:`open`,turn:r,step:n.data.step};else if(n.type===`llm/retry-started`)n.data.turn!==r||t.kind!==`settled`||t.by!==`retry`||!Yo(t,n.data.turn,n.data.step)?a=!0:t={kind:`open`,turn:r,step:n.data.step};else if(n.type===`assistant/attempt`){if(n.data.turn!==r||t.kind!==`open`||!Yo(t,n.data.turn,n.data.step)){a=!0;continue}let e=Ko(n.data.stream)??t.sample;t={kind:`open`,turn:r,step:n.data.step,...e===void 0?{}:{sample:e}},o()?t={kind:`finishClosed`,turn:r,step:n.data.step}:a=!0}else if(n.type===`assistant/message`){if(n.data.turn!==r||t.kind!==`open`||!Yo(t,n.data.turn,n.data.step)){a=!0;continue}let e=n.data.usage??Ko(n.data.stream);e!==void 0&&(t={...t,sample:e}),o(Go(n.data.message))?t={kind:`settled`,turn:r,step:n.data.step,by:`message`}:a=!0}else if(n.type===`llm/retry`){if(n.data.turn!==r||t.kind===`idle`||!Yo(t,n.data.turn,n.data.step)){a=!0;continue}(t.kind===`settled`||t.kind===`open`&&!o())&&(a=!0),a||(t={kind:`settled`,turn:r,step:n.data.step,by:`retry`})}else if(n.type===`step/end`){if(n.data.turn!==r||t.kind===`idle`||!Yo(t,n.data.turn,n.data.step)){a=!0;continue}t.kind===`open`&&!o()&&(a=!0),a||(t={kind:`idle`})}}}}return a||!i||t.kind!==`idle`?void 0:Jo(n)}function Zo(e){return e.type!==`assistant/live-chunk`}function Qo(e){if(e.type===`assistant/message`||e.type===`assistant/attempt`||e.type===`assistant/live-chunk`||e.type===`step/start`||e.type===`step/end`||e.type===`llm/retry`||e.type===`llm/retry-started`)return{turn:e.data.turn,step:e.data.step}}function $o(e){let t=e.start?.location??e.matches[0]?.location;return t?.kind===`turn`||t?.kind===`step`?t.turn:void 0}function es(e){return e.finalNode!==void 0&&e.blocks.some(e=>e.kind===`text`&&e.text.trim()!==``)}function ts(e){let t=e.state===void 0?e.matches.find(e=>e.event.type===`turn/end`):e.state.end;if(t?.event.type!==`turn/end`)return null;let n=$o(e);if(n===void 0)return null;let r=n.steps.map(e=>e.data.get(`assistant-step`)).filter(e=>e!==void 0).filter(e=>e.finalNode!==void 0).sort((e,t)=>e.finalNode.seq-t.finalNode.seq),i=r.findLast(es)??null,a=r.at(-1)?.finalNode.seq;for(let t of e.matches){let e=t.event,n=e.type===`tool/call`||e.type===`tool/result`&&e.surfaceOp===`append`||e.type===`turn/end`&&e.data.reason.kind===`error`||e.type===`llm/retry`?e.seq:void 0;n!==void 0&&(a===void 0||n>a)&&(a=n)}let o=e.start?.event.type===`turn/start`?Xo(e.matches.map(e=>e.event).filter(Zo)):void 0;return{turn:t.event.data.turn,seq:t.event.seq,time:t.event.time,closing:i,branchUnavailable:i===null||a!==i.finalNode.seq,...o===void 0?{}:{tokenUsage:o}}}let ns={kind:`turn-tail`,target:`chat`,match:e=>{if(e.type===`turn/start`)return{id:String(e.data.turn),role:`start`};if(e.type===`turn/end`||e.type===`tool/call`||e.type===`tool/result`)return{id:String(e.data.turn),role:`update`};let t=Qo(e);return t===void 0?null:{id:String(t.turn),role:`update`}},start:(e,t)=>{if(t.event.type!==`turn/start`)throw Error(`turn-tail start requires turn/start`);return{turn:t.event.data.turn}},update:(e,t)=>t.event.type===`turn/end`?{...e.state,end:t}:e.state,publication:e=>e.event.type===`turn/end`?`immediate`:`none`,buildLocationData:(e,t)=>{if(t!==`turn`)return null;let n=ts(e);return n===null?null:{kind:`turn`,turn:n.turn,key:`turn-tail`,value:n}},buildViewNode:e=>{let t=$o(e)?.data.get(`turn-tail`);return t===void 0?null:J(e,`turn-tail`,t.seq+Br.finalizedFollowup,t)}};function rs(e){let t=ns.match.bind(ns);e.uiConversation.events.register({...ns,match:{"turn/start":t,"turn/end":t,"tool/call":t,"tool/result":t,"assistant/message":t,"assistant/attempt":t,"assistant/live-chunk":t,"step/start":t,"step/end":t,"llm/retry":t,"llm/retry-started":t}})}function is(e){return e===`read`?`read`:e===`read_image`?`readImage`:e===`grep`||e===`glob`||e.endsWith(`_inspect`)?`search`:e===`write`?`write`:e===`edit`||e===`apply_patch`?`edit`:[`bash`,`pwsh`,`exec_command`,`write_stdin`].includes(e)||e.startsWith(`terminal_`)?`commands`:e===`run_code`?`code`:e===`web_search`?`webSearch`:e===`web_fetch`?`webFetch`:e===`subagent`||e.startsWith(`subagent_`)?`subagents`:[`todo_write`,`create_goal`,`update_goal`,`get_goal`].includes(e)?`plan`:e===`ask_user_question`||e===`request_user_input`?`questions`:`tools`}let as=new Intl.Segmenter(void 0,{granularity:`grapheme`}),os=[`title`,`description`,`objective`,`task`,`task_name`,`name`,`question`,`questions`,`prompt`,`message`,`command`,`cmd`,`queries`,`query`,`pattern`,`url`,`uri`,`file_path`,`path`,`target`,`action`,`status`];function ss(e){let t=e.replace(/\s+/g,` `).trim();if(t.length<=160)return{text:t,truncated:!1};let n=[];for(let{segment:e}of as.segment(t)){if(n.length===160)return{text:`${n.slice(0,159).join(``).trimEnd()}…`,truncated:!0};n.push(e)}return{text:t,truncated:!1}}function cs(e){return ss(typeof e==`string`?e:Array.isArray(e)&&e.every(e=>typeof e==`string`)?e.join(`, `):``).text}function ls(e,t){let n=512;for(;;){let r=e.textPrefix(t,n);if(r===void 0)return;let i=r.charCodeAt(r.length-1);if(i>=55296&&i<=56319){let i=e.textPrefix(t,n+1),a=i.charCodeAt(r.length);a>=56320&&a<=57343?(r=i,n++):i.length===r.length&&!e.isSealed&&!e.complete(t)&&(r=r.slice(0,-1))}let a=ss(r);if(a.truncated||!e.stringExceeds(t,n))return a.text;n*=2}}function us(e){if(!Array.isArray(e))return``;for(let t of e){if(typeof t!=`object`||!t)continue;let e=cs(Reflect.get(t,`question`));if(e!==``)return e}return``}function ds(e){for(let t=e.length-1;t>=0;t--){let n=e[t];if(n?.kind===`assistant-step`&&n.data.status===`running`)for(let e=n.data.blocks.length-1;e>=0;e--){let t=n.data.blocks[e];if(t?.kind!==`reasoning`)continue;let r=t.text.split(/\r?\n[\t ]*\r?\n/);for(let e=r.length-1;e>=0;e--){let t=cs(r[e]?.replaceAll(`**`,``));if(t!==``)return t}}}return``}function fs(e,t){for(let e of os){if(!t.has(e))continue;let n=e===`questions`?us(t.value(e)):ls(t,e)??cs(t.value(e));if(n!==``)return n}return t.closed()?cs(e):``}function ps(e){let t=/* @__PURE__ */ new Map,n=/* @__PURE__ */ new Set,r,i=``,a=-1/0,o,s=e=>{if(n.has(e.callId))return;n.add(e.callId);let c=vi(e)?e:e.call;if(c!==null){let n=is(c.name);vi(e)&&e.time>=a&&(r=n,o=e.phase===`preparing`,i=fs(e.name,e.args),a=e.time),t.set(n,(t.get(n)??0)+1)}for(let t of e.subCalls)s(t)};for(let t of e)t.kind===`tool-call`&&s(t.data.root);return r===void 0&&(i=ds(e)),{counts:[...t].map(([e,t])=>({kind:e,count:t})).sort((e,t)=>t.count-e.count),running:r,runningDetail:i,...o?{preparing:!0}:{}}}let ms=/* @__PURE__ */ new Set([`user`,`steering`,`turn-trigger`,`model-retry`,`turn-error`,`turn-max-tokens`,`turn-tail`]);function hs(e){let t=e.location;return t.kind===`turn`||t.kind===`step`?t.turn.turn:void 0}function gs(e){return ms.has(e.kind)||e.kind===`tool-call`&&pt(e.data.root.name)}function _s(e){return e.kind===`assistant-step`&&e.data.blocks.some(e=>e.kind===`reasoning`&&e.text.trim()!==``)}function vs(e){return e.kind===`assistant-step`&&Dr(e.data.blocks)}function ys(e,t){return e.running===t.running&&e.runningDetail===t.runningDetail&&e.preparing===t.preparing&&e.counts.length===t.counts.length&&e.counts.every((e,n)=>e.kind===t.counts[n]?.kind&&e.count===t.counts[n].count)}function bs(e,t){return e.length===t.length&&e.every((e,n)=>e.key===t[n]?.key&&e.groupPart===t[n].groupPart)}function xs(e,t){return!yi(t)&&(e===void 0||!yi(e))?!1:e===void 0||e.kind!==t.kind||hs(e)!==hs(t)||yi(e)!==yi(t)||_s(e)!==_s(t)||vs(e)!==vs(t)}function Ss(e,t){let n=e.readNode(t);if(n===void 0)throw Error(`Chat grouping input is missing Node ${t}`);return n}function Cs(e,t){let n=/* @__PURE__ */ new Set;for(let r of t){let t=Ss(e,r);t.kind===`question-reply`&&n.add(t.id)}return n}var ws=class{key;turn;members;nodes=[];snapshot;constructor(e,t,n){this.key=e,this.turn=t,this.members=n,this.snapshot={key:e,members:n,data:{turn:t,closed:!1,summary:{counts:[],running:void 0,runningDetail:``}}}}refresh(e,t){let n=this.members.map(t=>Ss(e,t.key)),r=n.length===this.nodes.length&&n.every((e,t)=>e===this.nodes[t]),i=this.snapshot.data,a=r&&i.closed===t?i.summary:ps(n),o=t?{counts:a.counts,running:void 0,runningDetail:``}:a;this.nodes=n,(i.closed!==t||!ys(i.summary,o))&&(this.snapshot={key:this.key,members:this.members,data:{turn:this.turn,closed:t,summary:o}})}},Ts=class{turn;groups=/* @__PURE__ */ new Map;membership=/* @__PURE__ */ new Map;roots=/* @__PURE__ */ new Map;constructor(e){this.turn=e}references(e){return this.roots.get(e)??[]}snapshots(){return[...this.groups.values()].map(e=>e.snapshot)}refresh(e,t){let n=/* @__PURE__ */ new Set;for(let e of t){let t=this.membership.get(e);t!==void 0&&n.add(t)}let r=e.timeline.turns.get(this.turn)?.status===`closed`;if(r)for(let e of this.groups.values())e.snapshot.data.closed||n.add(e.key);let i=[];for(let t of n){let n=this.groups.get(t),a=n.snapshot;n.refresh(e,a.data.closed||r),n.snapshot!==a&&i.push(n.snapshot)}return i}rebuild(e,t){let n=/* @__PURE__ */ new Map,r=/* @__PURE__ */ new Map,i=/* @__PURE__ */ new Map,a=[],o=[],s=(e,t)=>{n.set(e,[...n.get(e)??[],t])},c=n=>{let c=a[0];if(c===void 0)return;let l=this.extendedGroup(a,t)?.key??On(JSON.stringify([`process`,c.key,c.groupPart??null])),u=this.groups.get(l),d=u?.snapshot,f=u!==void 0&&bs(u.members,a)?u:new ws(l,this.turn,a);f.refresh(e,n||e.timeline.turns.get(this.turn)?.status===`closed`),r.set(f.key,f),s(c.key,{kind:`group`,key:f.key});for(let e of a)i.set(e.key,f.key);f.snapshot!==d&&o.push(f.snapshot),a=[]},l,u=!1,d=e.readTurn(this.turn),f=Cs(e,d);for(let t of d){let n=Es(e,t);l!==void 0&&n.previous!==l&&c(!0),l=t,u=n.next!==void 0;let r=Ss(e,t);r.kind===`turn-trigger`&&f.has(r.id)||(gs(r)?(c(!0),s(t,{kind:`node`,key:t})):r.kind===`turn-process`?s(a[0]?.key??t,{kind:`node`,key:t}):r.kind===`assistant-step`?(_s(r)&&a.push({kind:`node`,key:t,groupPart:`reasoning`}),vs(r)&&(c(!0),s(t,{kind:`node`,key:t,groupPart:`response`}))):a.push({kind:`node`,key:t}))}c(u);let p=[...this.groups.keys()].filter(e=>!r.has(e));return this.groups=r,this.membership=i,this.roots=n,{upserts:o,removes:p}}extendedGroup(e,t){let n=e.findIndex(e=>!t.has(e.key)),r=e[n];if(r===void 0)return;let i=this.membership.get(r.key),a=i===void 0?void 0:this.groups.get(i);if(!(a===void 0||n+a.members.length>e.length)){for(let t=0;t<a.members.length;t++){let r=a.members[t],i=e[n+t];if(r.key!==i.key||r.groupPart!==i.groupPart)return}for(let r=n+a.members.length;r<e.length;r++)if(!t.has(e[r].key))return;return a}}};function Es(e,t){let n=e.readPosition(t);if(n===void 0)throw Error(`Chat grouping order is missing position for Node ${t}`);return n}var Ds=class{turns=/* @__PURE__ */ new Map;order=[];pending=null;accept(e){if(e.kind===`replace`){let t=new Set(this.order),n=new Set(e.order.filter(e=>!t.has(e))),r=/* @__PURE__ */ new Map;for(let t of e.order){let i=Es(e,t).turn;if(i===void 0||r.has(i))continue;let a=this.turns.get(i)??new Ts(i);a.rebuild(e,n),r.set(i,a)}this.turns=r,this.order=e.order,this.pending={entries:this.rootEntries(e),groups:{kind:`replace`,snapshots:[...r.values()].flatMap(e=>e.snapshots())}};return}let t=new Set(e.changedTurnOrders),n=/* @__PURE__ */ new Set,r=/* @__PURE__ */ new Map,i=e=>{let t=r.get(e);return t===void 0&&(t=/* @__PURE__ */ new Set,r.set(e,t)),t};for(let r of e.changes){let e=r.previous,a=r.current,o=hs(a);if((e===void 0||!yi(e))&&n.add(a.key),xs(e,a)){let n=e===void 0?void 0:hs(e);n!==void 0&&t.add(n),o!==void 0&&t.add(o)}o!==void 0&&i(o).add(a.key)}for(let t of e.changedTurns)i(t);let a=[],o=[];for(let r of t){let t=this.turns.get(r)??new Ts(r),i=t.rebuild(e,n);a.push(...i.upserts),o.push(...i.removes),e.readTurn(r).length===0?this.turns.delete(r):this.turns.set(r,t)}for(let[n,i]of r)t.has(n)||a.push(...this.turns.get(n)?.refresh(e,i)??[]);let s=e.order!==this.order||t.size>0;this.order=e.order;let c=new Set(a.map(e=>e.key));this.pending=s||a.length>0||o.length>0?{...s?{entries:this.rootEntries(e)}:{},groups:{kind:`apply`,upserts:a,removes:o.filter(e=>!c.has(e))}}:null}rootEntries(e){let t=Cs(e,e.order.filter(t=>Es(e,t).turn===void 0));return e.order.flatMap(n=>{let r=Es(e,n).turn;if(r===void 0){let r=Ss(e,n);return r.kind===`turn-trigger`&&t.has(r.id)?[]:[{kind:`node`,key:n}]}let i=this.turns.get(r);if(i===void 0)throw Error(`Chat grouping order is missing Turn ${r}`);return i.references(n)})}output(){return this.pending}};let Os={kind:`process-groups`,target:`chat`,create:()=>new Ds,update:(e,t)=>(e.state.accept(t),e.state),buildGroups:e=>e.state.output()};function ks(e){Ba(e),Ga(e),Xa(e),gi(e),Ho(e),yo(e),Ea(e),ka(e),eo(e),wo(e),ko(e),rs(e),ja(e),ma(e),e.uiConversation.groups.register(Os)}function As({useNotice:e,dismissNotice:t,keepNoticeOpen:n,renderSlotChain:r,t:i}){let a=e(e=>e);if(a===null)return null;let o={code:a.code,message:i(`message.failure.quota`),dismiss:t,keepOpen:n};return/* @__PURE__ */ (0,f.jsx)(d.Fragment,{children:r(`shell.quota-notice`,o,{fallback:/* @__PURE__ */ (0,f.jsx)(p.Toast,{text:o.message,icon:/* @__PURE__ */ (0,f.jsx)(p.IconWarningOutlineRegular,{size:18}),onDone:t})})},`quota-notice-${String(a.seq)}`)}function X(e){return e==null}function js(e){return e&&typeof e==`object`&&!Array.isArray(e)}function Ms(e,t){return Object.fromEntries(Object.entries(e).filter(([e,n])=>t(e,n)))}function Ns(e,t){return Object.fromEntries(Object.entries(e).map(([e,n])=>[e,t(n,e)]))}function Ps(e,t,n){if(!t)return{...e};let r={};for(let i of t)(n||e[i]!==void 0)&&(r[i]=e[i]);return r}let Fs=Symbol.for(`cosmokit.volatile.write`);function Is(e,t=/* @__PURE__ */ new Set){if(typeof e==`function`)throw TypeError(`volatile config cannot contain functions`);if(typeof e!=`object`||!e)return e;if(t.has(e))throw TypeError(`volatile config cannot contain cycles`);t.add(e);try{if(Array.isArray(e))return Object.freeze(e.map(e=>Is(e,t)));if(Object.getPrototypeOf(e)!==Object.prototype&&Object.getPrototypeOf(e)!==null)throw TypeError(`volatile config objects must be plain objects or arrays`);return Object.freeze(Object.fromEntries(Object.entries(e).map(([e,n])=>[e,Is(n,t)])))}finally{t.delete(e)}}function Ls(e){let t=Is(e);return Object.freeze({get:()=>t,[Fs]:e=>{t=e}})}function Rs(e){return typeof e==`object`&&!!e&&Fs in e}function zs(e,t){return arguments.length===1?t=>zs(e,t):e in globalThis&&t instanceof globalThis[e]||Object.prototype.toString.call(t).slice(8,-1)===e}function Bs(e){return zs(`ArrayBuffer`,e)||zs(`SharedArrayBuffer`,e)}function Vs(e){return Bs(e)||ArrayBuffer.isView(e)}let Hs;(function(e){e.is=Bs,e.isSource=Vs;function t(e){return ArrayBuffer.isView(e)?e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength):e}e.fromSource=t;function n(e){if(e=t(e),typeof Buffer<`u`)return Buffer.from(e).toString(`base64`);let n=``,r=new Uint8Array(e);for(let e=0;e<r.byteLength;e++)n+=String.fromCharCode(r[e]);return btoa(n)}e.toBase64=n;function r(e){return typeof Buffer<`u`?t(Buffer.from(e,`base64`)):Uint8Array.from(atob(e),e=>e.charCodeAt(0))}e.fromBase64=r;function i(e){return e=t(e),typeof Buffer<`u`?Buffer.from(e).toString(`hex`):Array.from(new Uint8Array(e),e=>e.toString(16).padStart(2,`0`)).join(``)}e.toHex=i;function a(e){if(typeof Buffer<`u`)return t(Buffer.from(e,`hex`));let n=e.length%2==0?e:e.slice(0,e.length-1),r=[];for(let e=0;e<n.length;e+=2)r.push(parseInt(`${n[e]}${n[e+1]}`,16));return Uint8Array.from(r).buffer}e.fromHex=a})(Hs||={}),Hs.fromBase64,Hs.toBase64,Hs.fromHex,Hs.toHex;function Us(e,t=/* @__PURE__ */ new Map){if(!e||typeof e!=`object`)return e;if(zs(`Date`,e))return new Date(e.valueOf());if(zs(`RegExp`,e))return new RegExp(e.source,e.flags);if(Bs(e))return e.slice(0);if(ArrayBuffer.isView(e))return e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength);let n=t.get(e);if(n)return n;if(Array.isArray(e)){let n=[];return t.set(e,n),e.forEach((e,r)=>{n[r]=Reflect.apply(Us,null,[e,t])}),n}let r=Object.create(Object.getPrototypeOf(e));t.set(e,r);for(let n of Reflect.ownKeys(e)){let i={...Reflect.getOwnPropertyDescriptor(e,n)};`value`in i&&(i.value=Reflect.apply(Us,null,[i.value,t])),Reflect.defineProperty(r,n,i)}return r}function Ws(e,t,n){let r=/* @__PURE__ */ new Set;function i(e,t){if(e===t)return!0;if(Rs(e)||Rs(t))return Rs(e)&&Rs(t);if(!n&&X(e)&&X(t))return!0;if(typeof e!=typeof t||typeof e!=`object`||!e||!t||r.has(e))return!1;function a(n,r){return n(e)?n(t)?r(e,t):!1:!n(t)&&void 0}r.add(e);try{return a(Array.isArray,(e,t)=>{if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!i(e[n],t[n]))return!1;return!0})??a(zs(`Date`),(e,t)=>e.valueOf()===t.valueOf())??a(zs(`URL`),(e,t)=>e.href===t.href)??a(zs(`RegExp`),(e,t)=>e.source===t.source&&e.flags===t.flags)??a(Bs,(e,t)=>{if(e.byteLength!==t.byteLength)return!1;let n=new Uint8Array(e),r=new Uint8Array(t);for(let e=0;e<n.length;e++)if(n[e]!==r[e])return!1;return!0})??((!n||[e,t].every(e=>Object.getPrototypeOf(e)===Object.prototype||Object.getPrototypeOf(e)===null))&&Object.keys({...e,...t}).every(n=>i(e[n],t[n])))}finally{r.delete(e)}}return i(e,t)}let Gs;(function(e){e.millisecond=1;let t=e.second=1e3,n=e.minute=t*60,r=e.hour=n*60,i=e.day=r*24,a=e.week=i*7,o=(/* @__PURE__ */ new Date()).getTimezoneOffset();function s(e){o=e}e.setTimezoneOffset=s;function c(){return o}e.getTimezoneOffset=c;function l(e=/* @__PURE__ */ new Date,t){return typeof e==`number`&&(e=new Date(e)),t===void 0&&(t=o),Math.floor((e.valueOf()/n-t)/1440)}e.getDateNumber=l;function u(e,t){let r=new Date(e*i);return t===void 0&&(t=o),new Date(+r+t*n)}e.fromDateNumber=u;let d=RegExp(`^${[`w(?:eek(?:s)?)?`,`d(?:ay(?:s)?)?`,`h(?:our(?:s)?)?`,`m(?:in(?:ute)?(?:s)?)?`,`s(?:ec(?:ond)?(?:s)?)?`].map(e=>`(\\d+(?:\\.\\d+)?${e})?`).join(``)}$`);function f(e){let o=d.exec(e);return o?(parseFloat(o[1])*a||0)+(parseFloat(o[2])*i||0)+(parseFloat(o[3])*r||0)+(parseFloat(o[4])*n||0)+(parseFloat(o[5])*t||0):0}e.parseTime=f;function p(e){let t=f(e);return t?e=Date.now()+t:/^\d{1,2}(:\d{1,2}){1,2}$/.test(e)?e=`${(/* @__PURE__ */ new Date()).toLocaleDateString()}-${e}`:/^\d{1,2}-\d{1,2}-\d{1,2}(:\d{1,2}){1,2}$/.test(e)&&(e=`${(/* @__PURE__ */ new Date()).getFullYear()}-${e}`),e?new Date(e):/* @__PURE__ */ new Date}e.parseDate=p;function m(e){let a=Math.abs(e);return a>=i-r/2?Math.round(e/i)+`d`:a>=r-n/2?Math.round(e/r)+`h`:a>=n-t/2?Math.round(e/n)+`m`:a>=t?Math.round(e/t)+`s`:e+`ms`}e.format=m;function h(e,t=2){return e.toString().padStart(t,`0`)}e.toDigits=h;function g(e,t=/* @__PURE__ */ new Date){return e.replace(`yyyy`,t.getFullYear().toString()).replace(`yy`,t.getFullYear().toString().slice(2)).replace(`MM`,h(t.getMonth()+1)).replace(`dd`,h(t.getDate())).replace(`hh`,h(t.getHours())).replace(`mm`,h(t.getMinutes())).replace(`ss`,h(t.getSeconds())).replace(`SSS`,h(t.getMilliseconds(),3))}e.template=g})(Gs||={});let Ks=Symbol.for(`schemastery`),qs=Symbol.for(`ValidationError`);globalThis.__schemastery_index__??=0,globalThis.__schemastery_refs__=void 0;var Z=class extends TypeError{options;name=`ValidationError`;constructor(e,t){let n=`$`;for(let e of t.path||[])typeof e==`string`?n+=`.`+e:typeof e==`number`?n+=`[`+e+`]`:typeof e==`symbol`&&(n+=`[Symbol(${e.toString()})]`);n.startsWith(`.`)&&(n=n.slice(1)),super((n===`$`?``:`${n} `)+e),this.options=t}static is(e){return!!e?.[qs]}};Object.defineProperty(Z.prototype,qs,{value:!0});let Q=function(e){let t=function(e,n={}){return Q.resolve(e,t,n)[0]};if(e.refs){let t=Ns(e.refs,e=>new Q(e)),n=e=>t[e];for(let e in t){let r=t[e];r.sKey=n(r.sKey),r.inner=n(r.inner),r.list=r.list&&r.list.map(n),r.dict=r.dict&&Ns(r.dict,n)}return t[e.uid]}if(Object.assign(t,e),typeof t.callback==`string`)try{t.callback=Function(`return `+t.callback)()}catch{}return Object.defineProperty(t,"uid",{value:globalThis.__schemastery_index__++}),Object.setPrototypeOf(t,Q.prototype),t.meta||={},t.toString=t.toString.bind(t),t};Q.prototype=Object.create(Function.prototype),Q.prototype[Ks]=!0,Object.defineProperty(Q.prototype,"~standard",{get(){return{version:1,vendor:`schemastery`,validate:e=>{try{return{value:Q.resolve(e,this,{})[0]}}catch(e){if(Z.is(e))return{issues:[{message:e.message,path:e.options.path}]};throw e}}}}}),Q.ValidationError=Z,Q.prototype.toJSON=function(){if(globalThis.__schemastery_refs__)return globalThis.__schemastery_refs__[this.uid]??=JSON.parse(JSON.stringify({...this})),this.uid;globalThis.__schemastery_refs__={[this.uid]:{...this}},globalThis.__schemastery_refs__[this.uid]=JSON.parse(JSON.stringify({...this}));let e={uid:this.uid,refs:globalThis.__schemastery_refs__};return globalThis.__schemastery_refs__=void 0,e},Q.prototype.set=function(e,t){return this.dict[e]=t,this},Q.prototype.push=function(e){return this.list.push(e),this};function Js(e,t){let n=typeof e==`string`?{"":e}:{...e};for(let e in t){let r=t[e];r?.$description||r?.$desc?n[e]=r.$description||r.$desc:typeof r==`string`&&(n[e]=r)}return n}function Ys(e){return e?.$value??e?.$inner}function Xs(e){return Ms(e??{},e=>!e.startsWith(`$`))}Q.prototype.i18n=function(e){let t=Q(this),n=Js(t.meta.description,e);return Object.keys(n).length&&(t.meta.description=n),t.dict&&=Ns(t.dict,(t,n)=>t.i18n(Ns(e,e=>Ys(e)?.[n]??e?.[n]))),t.list&&=t.list.map((t,n)=>t.i18n(Ns(e,(e={})=>Array.isArray(Ys(e))?Ys(e)[n]:Array.isArray(e)?e[n]:Xs(e)))),t.inner&&=t.inner.i18n(Ns(e,e=>Ys(e)?Ys(e):Xs(e))),t.sKey&&=t.sKey.i18n(Ns(e,e=>e?.$key)),t},Q.prototype.extra=function(e,t){let n=Q(this);return n.meta={...n.meta,[e]:t},n};for(let e of[`required`,`disabled`,`collapse`,`hidden`,`loose`])Object.assign(Q.prototype,{[e](t=!0){let n=Q(this);return n.meta={...n.meta,[e]:t},n}});Q.prototype.deprecated=function(){let e=Q(this);return e.meta.badges||=[],e.meta.badges.push({text:`deprecated`,type:`danger`}),e},Q.prototype.experimental=function(){let e=Q(this);return e.meta.badges||=[],e.meta.badges.push({text:`experimental`,type:`warning`}),e},Q.prototype.pattern=function(e){let t=Q(this),n=Ps(e,[`source`,`flags`]);return t.meta={...t.meta,pattern:n},t},Q.prototype.simplify=function(e){if(Rs(e)&&(e=e.get()),Ws(e,this.meta.default,this.type===`dict`))return null;if(X(e))return e;if(this.type===`object`||this.type===`dict`){let t={};for(let n in e){let r=(this.type===`object`?this.dict[n]:this.inner)?.simplify(e[n]);(this.type===`dict`||!X(r))&&(t[n]=r)}return Ws(t,this.meta.default,this.type===`dict`)?null:t}if(this.type===`array`||this.type===`tuple`){let t=[];return e.forEach((e,n)=>{let r=this.type===`array`?this.inner:this.list[n],i=r?r.simplify(e):e;t.push(i)}),t}if(this.type===`intersect`){let t={};for(let n of this.list)Object.assign(t,n.simplify(e));return t}if(this.type===`union`)for(let t of this.list)try{return Q.resolve(e,t,{}),t.simplify(e)}catch{}return e},Q.prototype.toString=function(e){return ac[this.type]?.(this,e)??`Schema<${this.type}>`},Q.prototype.role=function(e,t){let n=Q(this);return n.meta={...n.meta,role:e,extra:t},n};for(let e of[`default`,`link`,`comment`,`description`,`max`,`min`,`step`])Object.assign(Q.prototype,{[e](t){let n=Q(this);return n.meta={...n.meta,[e]:t},n}});Q.prototype.volatile=function(){if(this.meta.volatile)throw TypeError(`volatile schema is already wrapped`);return this.extra(`volatile`,!0)};let Zs={},Qs=Symbol(`checked-volatile-schema`);function $s(e,t=[],n=!1,r=/* @__PURE__ */ new Map){let i=r.get(e)??/* @__PURE__ */ new Set;if(i.has(n))return;if(i.add(n),r.set(e,i),e.meta?.volatile&&n)throw new Z(`volatile fields require a fixed object path without an enclosing volatile field`,{path:t});let a=n||!!e.meta?.volatile;if(e.dict)for(let[n,i]of Object.entries(e.dict))$s(i,[...t,n],a,r);if(e.sKey&&$s(e.sKey,[...t,`<key>`],!0,r),e.inner&&(e.type!==`lazy`||e.inner[Ks])&&$s(e.inner,[...t,`*`],!0,r),e.list)for(let n=0;n<e.list.length;n++)$s(e.list[n],[...t,String(n)],!0,r)}Q.extend=function(e,t){Zs[e]=t},Q.resolve=function(e,t,n={},r=!1){if(!t)return[e];if(n[Qs]||($s(t,n.path),n={...n,[Qs]:!0}),t.meta?.volatile){let i=Q(t);i.meta={...t.meta,volatile:!1};let[a,o]=Q.resolve(e,i,n,r);try{return[Ls(a),o]}catch(e){throw new Z(e instanceof Error?e.message:String(e),n)}}if(n.ignore?.(e,t))return[e];if(X(e)&&t.type!==`lazy`){if(t.meta.required)throw new Z(`missing required value`,n);let r=t,i=t.meta.default;for(;r?.type===`intersect`&&X(i);)r=r.list[0],i=r?.meta.default;if(X(i))return[e];e=Us(i)}let i=Zs[t.type];if(!i)throw new Z(`unsupported type "${t.type}"`,n);try{return i(e,t,n,r)}catch(e){if(!t.meta.loose)throw e;return[t.meta.default]}},Q.from=function(e){if(X(e))return Q.any();if([`string`,`number`,`boolean`].includes(typeof e))return Q.const(e).required();if(e[Ks])return e;if(typeof e==`function`)switch(e){case String:return Q.string().required();case Number:return Q.number().required();case Boolean:return Q.boolean().required();case Function:return Q.function().required();default:return Q.is(e).required()}else throw TypeError(`cannot infer schema from ${e}`)},Q.lazy=function(e){let t=new Q({type:`lazy`,builder:e,inner:{toJSON:()=>(t.inner[Ks]||(t.inner=t.builder(),t.inner.meta={...t.meta,...t.inner.meta}),t.inner.toJSON())}});return t},Q.natural=function(){return Q.number().step(1).min(0)},Q.percent=function(){return Q.number().step(.01).min(0).max(1).role(`slider`)},Q.date=function(){return Q.union([Q.is(Date),Q.transform(Q.string().role(`datetime`),(e,t)=>{let n=new Date(e);if(isNaN(+n))throw new Z(`invalid date "${e}"`,t);return n},!0)])},Q.regExp=function(e=``){return Q.union([Q.is(RegExp),Q.transform(Q.string().role(`regexp`,{flag:e}),(t,n)=>{try{return new RegExp(t,e)}catch(e){throw new Z(e.message,n)}},!0)])},Q.arrayBuffer=function(e){return Q.union([Q.is(ArrayBuffer),Q.is(SharedArrayBuffer),Q.transform(Q.any(),(e,t)=>{if(Hs.isSource(e))return Hs.fromSource(e);throw new Z(`expected ArrayBufferSource but got ${e}`,t)},!0),...e?[Q.transform(Q.string(),(t,n)=>{try{return e===`base64`?Hs.fromBase64(t):Hs.fromHex(t)}catch(e){throw new Z(e.message,n)}},!0)]:[]])},Q.extend(`lazy`,(e,t,n,r)=>(t.inner[Ks]||(t.inner=t.builder(),t.inner.meta={...t.meta,...t.inner.meta},$s(t.inner,n.path,!0)),Q.resolve(e,t.inner,n,r))),Q.extend(`any`,e=>[e]),Q.extend(`never`,(e,t,n)=>{throw new Z(`expected nullable but got ${e}`,n)}),Q.extend(`const`,(e,{value:t},n)=>{if(Ws(e,t))return[t];throw new Z(`expected ${t} but got ${e}`,n)});function ec(e,t,n,r,i=!1){let{max:a=1/0,min:o=-1/0}=t;if(e>a)throw new Z(`expected ${n} <= ${a} but got ${e}`,r);if(e<o&&!i)throw new Z(`expected ${n} >= ${o} but got ${e}`,r)}Q.extend(`string`,(e,{meta:t},n)=>{if(typeof e!=`string`)throw new Z(`expected string but got ${e}`,n);if(t.pattern){let r=new RegExp(t.pattern.source,t.pattern.flags);if(!r.test(e))throw new Z(`expect string to match regexp ${r}`,n)}return ec(e.length,t,`string length`,n),[e]});function tc(e,t){let n=e.toString();if(n.includes(`e`))return e*10**t;let r=n.indexOf(`.`);if(r===-1)return e*10**t;let i=n.slice(r+1),a=n.slice(0,r);return i.length<=t?+(a+i.padEnd(t,`0`)):+(a+i.slice(0,t)+`.`+i.slice(t))}function nc(e,t,n){if(n=Math.abs(n),!/^\d+\.\d+$/.test(n.toString()))return(e-t)%n===0;let r=n.toString().indexOf(`.`),i=n.toString().slice(r+1).length;return Math.abs(tc(e,i)-tc(t,i))%tc(n,i)===0}Q.extend(`number`,(e,{meta:t},n)=>{if(typeof e!=`number`)throw new Z(`expected number but got ${e}`,n);ec(e,t,`number`,n);let{step:r}=t;if(r&&!nc(e,t.min??0,r))throw new Z(`expected number multiple of ${r} but got ${e}`,n);return[e]}),Q.extend(`boolean`,(e,t,n)=>{if(typeof e==`boolean`)return[e];throw new Z(`expected boolean but got ${e}`,n)}),Q.extend(`bitset`,(e,{bits:t,meta:n},r)=>{let i=0,a=[];if(typeof e==`number`){i=e;for(let n in t)e&t[n]&&a.push(n)}else if(Array.isArray(e)){a=e;for(let e of a){if(typeof e!=`string`)throw new Z(`expected string but got ${e}`,r);e in t&&(i|=t[e])}}else throw new Z(`expected number or array but got ${e}`,r);return i===n.default?[i]:[i,a]}),Q.extend(`function`,(e,t,n)=>{if(typeof e==`function`)return[e];throw new Z(`expected function but got ${e}`,n)}),Q.extend(`is`,(e,{constructor:t},n)=>{if(typeof t==`function`){if(e instanceof t)return[e];throw new Z(`expected ${t.name} but got ${e}`,n)}{if(X(e))throw new Z(`expected ${t} but got ${e}`,n);let r=Object.getPrototypeOf(e);for(;r;){if(r.constructor?.name===t)return[e];r=Object.getPrototypeOf(r)}throw new Z(`expected ${t} but got ${e}`,n)}});function rc(e,t,n,r){try{let[i,a]=Q.resolve(e[t],n,{...r,path:[...r.path||[],t]});return a!==void 0&&(e[t]=a),i}catch(i){if(!r?.autofix)throw i;return delete e[t],n.meta.volatile?Ls(n.meta.default):n.meta.default}}Q.extend(`array`,(e,{inner:t,meta:n},r)=>{if(!Array.isArray(e))throw new Z(`expected array but got ${e}`,r);return ec(e.length,n,`array length`,r,!X(t.meta.default)),[e.map((n,i)=>rc(e,i,t,r))]}),Q.extend(`dict`,(e,{inner:t,sKey:n},r,i)=>{if(!js(e))throw new Z(`expected object but got ${e}`,r);let a={};for(let o in e){let s;try{s=Q.resolve(o,n,r)[0]}catch(e){if(i)continue;throw e}a[s]=rc(e,o,t,r),e[s]=e[o],o!==s&&delete e[o]}return[a]}),Q.extend(`tuple`,(e,{list:t},n,r)=>{if(!Array.isArray(e))throw new Z(`expected array but got ${e}`,n);let i=t.map((t,r)=>rc(e,r,t,n));return r||i.push(...e.slice(t.length)),[i]});function ic(e,t){for(let n in t)n in e||(e[n]=t[n])}Q.extend(`object`,(e,{dict:t},n,r)=>{if(!js(e))throw new Z(`expected object but got ${e}`,n);let i={};for(let r in t){let a=rc(e,r,t[r],n);(!X(a)||r in e)&&(i[r]=a)}return r||ic(i,e),[i]}),Q.extend(`union`,(e,{list:t,toString:n},r,i)=>{let a=[];for(let n of t)try{return Q.resolve(e,n,r,i)}catch(e){a.push(e)}throw new Z(`expected ${n()} but got ${JSON.stringify(e)}`,r)}),Q.extend(`intersect`,(e,{list:t,toString:n},r,i)=>{if(!t.length)return[e];let a;for(let i of t){let t=Q.resolve(e,i,r,!0)[0];if(!X(t)){if(X(a))a=t;else if(typeof a!=typeof t)throw new Z(`expected ${n()} but got ${JSON.stringify(e)}`,r);else if(typeof t==`object`)ic(a??={},t);else if(a!==t)throw new Z(`expected ${n()} but got ${JSON.stringify(e)}`,r)}}return!i&&js(e)&&ic(a,e),[a]}),Q.extend(`transform`,(e,{inner:t,callback:n,preserve:r},i)=>{let[a,o=e]=Q.resolve(e,t,i,!0);return r?[n(a)]:[n(a),n(o)]});let ac={};function $(e,t,n){ac[e]=n,Object.assign(Q,{[e](...n){let r=new Q({type:e});return t.forEach((e,t)=>{switch(e){case`sKey`:r.sKey=n[t]??Q.string();break;case`inner`:r.inner=Q.from(n[t]);break;case`list`:r.list=n[t].map(Q.from);break;case`dict`:r.dict=Ns(n[t],Q.from);break;case`bits`:r.bits={};for(let e in n[t])typeof n[t][e]==`number`&&(r.bits[e]=n[t][e]);break;case`callback`:{let e=r.callback=n[t];e.toJSON||=()=>e.toString();break}case`constructor`:{let e=r.constructor=n[t];typeof e==`function`&&(e.toJSON||=()=>e.name);break}default:r[e]=n[t]}}),e===`object`||e===`dict`?r.meta.default={}:e===`array`||e===`tuple`?r.meta.default=[]:e===`bitset`&&(r.meta.default=0),r}})}$(`is`,[`constructor`],({constructor:e})=>typeof e==`function`?e.name:e),$(`any`,[],()=>`any`),$(`never`,[],()=>`never`),$(`const`,[`value`],({value:e})=>typeof e==`string`?JSON.stringify(e):e),$(`string`,[],()=>`string`),$(`number`,[],()=>`number`),$(`boolean`,[],()=>`boolean`),$(`bitset`,[`bits`],()=>`bitset`),$(`function`,[],()=>`function`),$(`array`,[`inner`],({inner:e})=>`${e.toString(!0)}[]`),$(`dict`,[`inner`,`sKey`],({inner:e,sKey:t})=>`{ [key: ${t.toString()}]: ${e.toString()} }`),$(`tuple`,[`list`],({list:e})=>`[${e.map(e=>e.toString()).join(`, `)}]`),$(`object`,[`dict`],({dict:e})=>Object.keys(e).length===0?`{}`:`{ ${Object.entries(e).map(([e,t])=>`${e}${t.meta.required?``:`?`}: ${t.toString()}`).join(`, `)} }`),$(`union`,[`list`],({list:e},t)=>{let n=e.map(({toString:e})=>e()).join(` | `);return t?`(${n})`:n}),$(`intersect`,[`list`],({list:e})=>`${e.map(e=>e.toString(!0)).join(` & `)}`),$(`transform`,[`inner`,`callback`,`preserve`],({inner:e},t)=>e.toString(t));let oc=`transcriptView`,sc=[`compact`,`standard`,`detailed`,`verbose`],cc=[...sc,`normal`,`expanded`],lc=`standard`,uc={linkOpening:Q.union([`sidebar`,`new-tab`]).default(`sidebar`),[oc]:Q.union([...cc]).loose()};Q.object(uc);let dc=`@deepseek-ai/dsh-client-ui-chat/PreferenceRow.module.css`;if(typeof document<`u`&&document.querySelector(`style[data-plugin-css=`+JSON.stringify(dc)+`]`)===null){let e=document.createElement(`style`);e.dataset.plugin=`@deepseek-ai/dsh-client-ui-chat`,e.dataset.pluginCss=dc,e.textContent=`.Zxrp0W_row{border-bottom:.5px solid var(--dsw-alias-border-l2);align-items:center;gap:8px;padding:16px 0;display:flex}.Zxrp0W_rowText{flex-direction:column;flex:1;gap:4px;min-width:0;padding-right:48px;display:flex}.Zxrp0W_title{color:var(--dsw-alias-label-primary);font-size:14px;font-weight:400;line-height:22px}.Zxrp0W_desc{color:var(--dsw-alias-label-tertiary);font-size:12px;font-weight:400;line-height:18px}.Zxrp0W_selector{border-radius:var(--dsw-radius-md);background:var(--dsw-alias-bg-module-platform);height:36px;font:inherit;color:var(--dsw-alias-label-primary);cursor:pointer;border:none;align-items:center;gap:12px;padding:0 14px;font-size:14px;line-height:22px;display:inline-flex}.Zxrp0W_selector:hover{background:var(--dsw-alias-interactive-bg-hover)}.Zxrp0W_chevron{flex:none}`,document.head.appendChild(e)}var fc={chevron:`Zxrp0W_chevron`,desc:`Zxrp0W_desc`,row:`Zxrp0W_row`,rowText:`Zxrp0W_rowText`,selector:`Zxrp0W_selector`,title:`Zxrp0W_title`};function pc({title:e,description:t,value:n,selectedLabel:r,options:i,onSelect:a}){let[o,s]=(0,d.useState)(!1),c=(0,d.useRef)(null),l=()=>{s(!1)},u=e=>{c.current?.focus({preventScroll:!0}),l(),a(e)},m=/* @__PURE__ */ (0,f.jsxs)(`button`,{ref:c,type:`button`,className:fc.selector,"aria-haspopup":`menu`,"aria-expanded":o,onClick:()=>{s(e=>!e)},children:[r,/* @__PURE__ */ (0,f.jsx)(p.IconChevronDownOutlineRegular,{className:fc.chevron})]});return/* @__PURE__ */ (0,f.jsxs)(`div`,{className:fc.row,children:[/* @__PURE__ */ (0,f.jsxs)(`div`,{className:fc.rowText,children:[/* @__PURE__ */ (0,f.jsx)(`div`,{className:fc.title,children:e}),/* @__PURE__ */ (0,f.jsx)(`div`,{className:fc.desc,children:t})]}),/* @__PURE__ */ (0,f.jsx)(p.Menu,{open:o,onClose:l,items:i,selectedId:n,onSelect:u,align:`end`,portal:!0,anchor:m})]})}let mc={compact:`settings.transcript.compact`,standard:`settings.transcript.standard`,detailed:`settings.transcript.detailed`,verbose:`settings.transcript.verbose`};function hc({useTranscriptView:e,setTranscriptView:t,t:n}){let r=e(e=>e);return/* @__PURE__ */ (0,f.jsx)(pc,{title:n(`settings.transcript.title`),description:n(`settings.transcript.description`),value:r,selectedLabel:n(mc[r]),options:sc.map(e=>({id:e,label:n(mc[e])})),onSelect:e=>{t(e)}})}var gc=class{host;defaultMode;unsubscribe;mode;constructor(e,t=lc){this.host=e,this.defaultMode=t,this.mode=(0,m.createSnapshotStore)(t),this.unsubscribe=e.subscribe(()=>{this.adopt()}),this.adopt()}dispose(){this.unsubscribe()}setMode(e){this.mode.getSnapshot()!==e&&(this.mode.set(e),this.host.set(oc,e))}adopt(){let e=this.host.getSnapshot().value;if(e===void 0)return;let t=e.transcriptView,n=t===`normal`||t===`expanded`?`detailed`:t??this.defaultMode;this.mode.getSnapshot()!==n&&this.mode.set(n)}};let _c={compact:{mode:`compact`,foldCompletedTurns:!0,stepGrouping:`collapsed`,liveProcessDetail:!1,settledReasoningPreview:!1},standard:{mode:`standard`,foldCompletedTurns:!0,stepGrouping:`collapsed`,liveProcessDetail:!0,settledReasoningPreview:!0},detailed:{mode:`detailed`,foldCompletedTurns:!0,stepGrouping:`history`,liveProcessDetail:!0,settledReasoningPreview:!0},verbose:{mode:`verbose`,foldCompletedTurns:!1,stepGrouping:`none`,liveProcessDetail:!1,settledReasoningPreview:!0}};function vc(e){return{getSnapshot:()=>_c[e.getSnapshot()],subscribe:t=>e.subscribe(t)}}function yc({useLinkOpening:e,useBrowserAvailable:t,setLinkOpening:n,t:r}){let i=e(e=>e);return t(e=>e)?/* @__PURE__ */ (0,f.jsx)(pc,{title:r(`settings.links.title`),description:r(`settings.links.description`),value:i,selectedLabel:r(i===`sidebar`?`settings.links.sidebar`:`settings.links.newTab`),options:[{id:`sidebar`,label:r(`settings.links.sidebar`)},{id:`new-tab`,label:r(`settings.links.newTab`)}],onSelect:e=>{n(e)}}):null}let bc={getSnapshot:()=>void 0,subscribe:()=>()=>{}};function xc(e,t){let n=e?.source(t)??bc;return(0,d.useSyncExternalStore)(n.subscribe,n.getSnapshot)}let Sc={hooks:{turnData:(e,{turnData:t})=>function(e){return xc(t,e)},disclosure:(e,{disclosureReset:t})=>Mt(t)}},Cc=[`slots`,`sessions`,`uiWorkspace`,`uiSession`,`uiConversation`,`locale`,`configForms`,`remote`,`remote.session`,`sidebarRight`];function wc(e){let t=(0,m.createSnapshotStore)(null),n=0,r=/* @__PURE__ */ new Set,i=/* @__PURE__ */ new WeakMap,a=/* @__PURE__ */ new Set;e.effect(()=>async()=>{await Promise.all([...a].map(e=>e()))},`ui-chat: live quota notices`);let o=o=>{let s=i.get(o);if(s===void 0){let c=o.ctx.effect(()=>{let e=o.eventSource.subscribe(()=>{let{change:e}=o.eventSource.getSnapshot();if(e.kind===`append`)for(let{event:i}of e.entries){if(i.type!==`turn/end`||i.data.reason.kind!==`error`)continue;let{code:e}=i.data.reason.error;r.size>0||e!==`QUOTA`&&e!==`ACCOUNT_QUOTA`||t.set({code:e,seq:++n})}});return()=>{e(),i.delete(o),a.delete(c)}},`ui-chat: Provider binding quota notices`);a.add(c);let l=e.uiConversation.binding(o).target(`chat`);s={getSnapshot:()=>l.getSnapshot()??ie,subscribe:e=>l.subscribe(e)},i.set(o,s)}return s};ks(e),e.uiSession.provide({hooks:[`chat`],resolve:e=>({hooks:{chat:o(e)}})}),e.effect(()=>e.locale.register(K,{zh:Yn,en:Xn}),`ui-chat: dictionaries`);let s=e.locale.bind(K),c=gt(),l=/* @__PURE__ */ new Map,u=e.configForms.get(`ui-chat`),d=(0,m.createSnapshotStore)(u.getSnapshot().value?.linkOpening??`sidebar`);e.effect(()=>u.subscribe(()=>{let e=u.getSnapshot().value?.linkOpening;e!==void 0&&d.set(e)})),e.inject([`sidebarRightTabs`],e=>{let t=e.sidebarRightTabs,n={getSnapshot:()=>t.get(`browser`)!==void 0,subscribe:e=>t.subscribe(e)};e.slots.inject(`settings.general.item`,()=>e.slots.register({name:`settings.general.item`,id:`link-opening`,order:17,locale:K,inject:()=>({hooks:{linkOpening:d,browserAvailable:n},setLinkOpening:e=>{d.set(e),u.set(`linkOpening`,e).catch(()=>{})}})},yc))});let f=new gc(u,`dshDesktop`in globalThis?`standard`:lc),p=vc(f.mode);e.effect(()=>()=>{f.dispose()}),zr(e,p),e.slots.inject(`settings.general.item`,()=>e.slots.register({name:`settings.general.item`,id:`transcript-view`,order:12,locale:K,inject:()=>({hooks:{transcriptView:f.mode},setTranscriptView:e=>{f.setMode(e)}})},hc)),e.slots.inject(`conversation.view`,()=>e.slots.register({name:`conversation.view`,id:`chat`,order:0,label:()=>s(`view.chat`),locale:K,children:{"conversation.chat.node":{kind:`keyed`,scope:`session`,inject:Sc},"conversation.message.images":{kind:`single`,scope:`session`}},store:c,inject:t=>{let n=e.sessions.binding(t);if(n===void 0)throw Error(`ui-chat: unknown session "${t}"`);let r=n.session,i=o(n),a=e.uiConversation.binding(n),s=e.get(`chatMessageEditing`),c=e.get(`chatTurnDiffs`);return{connection:e.get(`connection`),hooks:{presentation:p},keyedHooks:{chatNode:e=>i.getSnapshot().nodes.source(e),chatNodeProcess:e=>i.getSnapshot().nodes.processSource(e),chatGroup:e=>a.snapshot.getSnapshot().views.grouped(`chat`)?.groupSource(e)},fileMentions:n=>e.get(`chatFileMentions`)?.forClosing(n,t),openFile:async(n,r)=>{let i=e.sessions.list.getSnapshot().byId[t]?.cwd,a=N(t,i,n);r?.line===void 0?e.sidebarRight.openResource(a):e.sidebarRight.openResource(a,{params:{line:r.line}}),await Promise.resolve()},openSkill:n=>{let r=e.sessions.scope(t);r!==void 0&&e.get(`inputTriggers`)?.sessionOf(r).openReference(`skill`,{ref:`/${n}`})},resolveLink:e.get(`chatLinks`)?.resolve,openExternalLink:t=>{d.getSnapshot()===`sidebar`&&e.get(`sidebarRightTabs`)?.get(`browser`)!==void 0?e.sidebarRight.openTab(`browser`,{params:{url:t}}):window.open(t,`_blank`,`noopener,noreferrer`)},loadOlder:()=>{r.loadOlder()},loadThrough:e=>r.loadThrough(e),loadImage:Object.assign(n=>e.uiConversation.imageUrl(t,n),{peek:n=>e.uiConversation.peekImageUrl(t,n)}),chatScroll:{save:e=>{e===null?l.delete(t):l.set(t,e)},read:()=>l.get(t)??null},loadTurnDiffs:c?(e,n)=>c.read(t,e,n):void 0,editMessage:s?(e,n)=>s.send(t,e,n):void 0,forkAt:n=>{let r=[...i.getSnapshot().timeline.turns.values()].find(e=>e.end?.seq===n)?.data.get(`turn-tail`)?.closing?.finalNode.messageId;return e.sessions.fork({sessionId:t,atSeq:n,increaseTitle:!0,onCreated:n=>{e.get(`productAnalytics`)?.track(`branch_session_click`,{session_id:n,parent_session_id:t,...r===void 0?{}:{parent_message_id:r},click_position:`footer`})}}).then(t=>{e.uiWorkspace.openSession(t)})}}}},qn)),e.slots.inject(`shell.overlay`,()=>e.slots.register({name:`shell.overlay`,id:`chat.quota-notice`,locale:K,children:{"shell.quota-notice":{kind:`chain`,scope:`root`}},inject:()=>({hooks:{notice:t},dismissNotice:()=>{r.clear(),t.set(null)},keepNoticeOpen:()=>{if(t.getSnapshot()===null)return()=>{};let e=Symbol(`ui-chat quota notice hold`);return r.add(e),()=>{r.delete(e)}}})},As)),e.slots.inject(`conversation.input.dock`,()=>e.slots.register({name:`conversation.input.dock`,id:`file-changes`,order:5,locale:K},D)),e.slots.inject(`conversation.approval.detail`,()=>e.slots.register({name:`conversation.approval.detail`},oe))}return n.EMPTY_CHAT_SNAPSHOT=ie,n.apply=wc,n.inject=Cc,n.isRunningTool=vi,n.isSettledTool=_i,t.exports}});
|