@shytv/ai-chart 0.0.0-stage → 0.0.1
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 +74 -2
- package/dist/App.d.ts +1 -0
- package/dist/chat/ChatApp.d.ts +5 -0
- package/dist/chat/ChatRuntimeProvider.d.ts +9 -0
- package/dist/components/attachment-state.d.ts +10 -0
- package/dist/components/attachment.aui.d.ts +4 -0
- package/dist/components/collapsible-root.d.ts +4 -0
- package/dist/components/conversation-list.d.ts +5 -0
- package/dist/components/file.d.ts +49 -0
- package/dist/components/follow-up-suggestions.aui.d.ts +2 -0
- package/dist/components/href.d.ts +8 -0
- package/dist/components/image.d.ts +55 -0
- package/dist/components/markdown-text.d.ts +8 -0
- package/dist/components/media-player.d.ts +16 -0
- package/dist/components/reasoning.aui.d.ts +22 -0
- package/dist/components/reasoning.d.ts +25 -0
- package/dist/components/surfaces.d.ts +37 -0
- package/dist/components/thread.aui.d.ts +34 -0
- package/dist/components/tool-fallback.aui.d.ts +46 -0
- package/dist/components/tool-group.aui.d.ts +34 -0
- package/dist/components/tooltip-icon-button.d.ts +7 -0
- package/dist/components/ui/avatar.d.ts +11 -0
- package/dist/components/ui/button.d.ts +10 -0
- package/dist/components/ui/dialog.d.ts +17 -0
- package/dist/components/ui/skeleton.d.ts +2 -0
- package/dist/components/ui/textarea.d.ts +3 -0
- package/dist/components/ui/tooltip.d.ts +6 -0
- package/dist/components/useIsomorphicLayoutEffect.d.ts +2 -0
- package/dist/favicon.svg +1 -0
- package/dist/hooks/use-attachment-src.d.ts +1 -0
- package/dist/hooks/use-copy-to-clipboard.d.ts +7 -0
- package/dist/icons.svg +24 -0
- package/dist/index.cjs +117 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +42000 -0
- package/dist/lib/composables/monarchTokens.d.ts +203 -0
- package/dist/lib/composables/tools.d.ts +3 -0
- package/dist/lib/composables/v6/monarchTokens.d.ts +205 -0
- package/dist/lib/utils.d.ts +1 -0
- package/dist/main.d.ts +0 -0
- package/dist/services/chat-adapter.d.ts +39 -0
- package/dist/services/conversation-adapter.d.ts +51 -0
- package/dist/style.css +2 -0
- package/package.json +70 -4
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t,t.exports),e=null),t.exports),s=(e,n)=>{let r={};for(var i in e)t(r,i,{get:e[i],enumerable:!0});return n||t(r,Symbol.toStringTag,{value:`Module`}),r},c=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},l=(e,t,n)=>(c(e,t,`default`),n&&c(n,t,`default`)),u=(n,r,o)=>(o=n==null?{}:e(i(n)),c(r||!n||!n.__esModule||!a.call(n,`default`)?t(o,`default`,{value:n,enumerable:!0}):o,n));let d=require("react"),f=u(d,1);d=u(d);let p=require("react-dom");p=u(p,1);let m=require("monaco-editor");var h=((e,t=21)=>(n=t)=>{let r=``,i=n|0;for(;i-->0;)r+=e[Math.random()*e.length|0];return r})(`0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz`,7),g=`__error__`,_=e=>e.startsWith(g);function v(e,t){if(t===`*`)return!0;let n=t.split(`,`).map(e=>e.trim().toLowerCase()),r=e.name.toLowerCase(),i=e.type.split(`;`,1)[0].trim().toLowerCase();for(let e of n){if(e.startsWith(`.`)&&r.endsWith(e)||e.includes(`/`)&&e===i)return!0;if(e.endsWith(`/*`)){let t=e.split(`/`)[0];if(i.startsWith(`${t}/`))return!0}}return!1}function y(e){let t=h();return e.type===`image`?{id:t,type:`image`,name:e.filename??`image`,content:[e],status:{type:`complete`}}:e.type===`file`?{id:t,type:`document`,name:e.filename??`document`,contentType:e.mimeType,content:[e],status:{type:`complete`}}:e.type===`audio`?{id:t,type:`audio`,name:`audio.${e.audio.format}`,contentType:`audio/${e.audio.format}`,content:[e],status:{type:`complete`}}:{id:t,type:`data`,name:e.name,content:[e],status:{type:`complete`}}}function b(e){let t=[];for(let n of e)n.type!==`text`&&t.push(y(n));return t}var x=String.raw`"(?:[^"\\\u0000-\u001f]|\\(?:["\\/bfnrt]|u[\da-fA-F]{4})){1,1024}"`,S=new RegExp(String.raw`:([\w-]{1,64})(?:\[([^\]\n]{1,1024})\](?:\{name=([^}\n]{1,1024})\})?|\{label=(${x})(?: name=(${x}))?\})`,`gu`),C={serialize(e){if(e.label.includes(`]`)||e.id!==e.label&&e.id.includes(`}`)){let t=e.id===e.label?``:` name=${JSON.stringify(e.id)}`;return`:${e.type}{label=${JSON.stringify(e.label)}${t}}`}let t=e.id===e.label?``:`{name=${e.id}}`;return`:${e.type}[${e.label}]${t}`},parse(e){let t=[],n=0;for(let r of e.matchAll(S)){r.index>n&&t.push({kind:`text`,text:e.slice(n,r.index)});let i=r[4]===void 0?r[2]:JSON.parse(r[4]),a=r[5]===void 0?r[3]??i:JSON.parse(r[5]);t.push({kind:`mention`,type:r[1],label:i,id:a}),n=r.index+r[0].length}return n<e.length&&t.push({kind:`text`,text:e.slice(n)}),t}},w=(e,t,n)=>{let r=e=>{console.error(`[assistant-ui] ${n} listener threw an error`,e)};for(let n of e)try{let e=n(typeof t==`function`?t():t);e!==null&&(typeof e==`object`||typeof e==`function`)&&`then`in e&&typeof e.then==`function`&&Promise.resolve(e).catch(r)}catch(e){r(e)}},T=e=>e.content.filter(e=>e.type===`text`).map(e=>e.text).join(`
|
|
2
|
+
|
|
3
|
+
`),E=`ui://`,D=e=>!!e?.startsWith(E),O=e=>e.display===`text`||e.display!==`questions`&&e.allowFreeform===!0,k=(e,...t)=>Object.assign(Object.create(null),e,...t),A=`
|
|
4
|
+
|
|
5
|
+
`,j=e=>e>=55296&&e<=56319,M=(e,t)=>{let n=``;for(let{system:r}of e){let e=n?A:``,i=t-n.length-e.length,a=i<r.length&&j(r.charCodeAt(i-1))?i-1:i;if(a<=0||(n+=e+r.slice(0,a),r.length>a))break}return n},N=(e,t)=>{if(t.mergeSystem){if(t.maxSystemLength!==void 0)throw Error(`Pass either maxSystemLength or mergeSystem, not both. Apply the cap inside mergeSystem instead.`);return t.mergeSystem(e)}return t.maxSystemLength===void 0?e.map(e=>e.system).join(A):M(e,t.maxSystemLength)},P=e=>{if(!e.overwrite)return e;let{overwrite:t,...n}=e;return n},F=(e,t={})=>{let n=Array.from(e).map(e=>e.getModelContext()).sort((e,t)=>(t.priority??0)-(e.priority??0)),r=k(),i=[],a=n.reduce((e,t)=>{let n=t.priority??0;if(t.system&&i.push({system:t.system,priority:n}),t.tools)for(let[i,a]of Object.entries(t.tools)){let t=e.tools!==void 0&&Object.hasOwn(e.tools,i)?e.tools[i]:void 0;if(t&&t!==a){let o=r[i];if(o===n){if(!a.overwrite)throw Error(`You tried to define a tool with the name ${i}, but it already exists.`);e.tools[i]=P(a);continue}let s=o>n?t:a,c=o>n?a:t;e.tools[i]=P({...c,...s}),r[i]=Math.max(o,n)}else e.tools||=k(),e.tools[i]=P(a),Object.hasOwn(r,i)||(r[i]=n)}return t.config&&(e.config={...t.config,...e.config}),t.callSettings&&(e.callSettings={...t.callSettings,...e.callSettings}),t.unstable_composerMetadata&&(e.unstable_composerMetadata={...t.unstable_composerMetadata,...e.unstable_composerMetadata}),e},{}),o=N(i,t);return o&&(a.system=o),a};function I(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function L(e,t=0){return t>100?!1:e===null||typeof e==`string`||typeof e==`boolean`?!0:typeof e==`number`?!Number.isNaN(e)&&Number.isFinite(e):Array.isArray(e)?e.every(e=>L(e,t+1)):I(e)?Object.entries(e).every(([e,n])=>typeof e==`string`&&L(n,t+1)):!1}var R=100,z=(e,t,n)=>{if(e===t)return!0;if(n>R||e==null||t==null)return!1;if(Array.isArray(e))return!Array.isArray(t)||e.length!==t.length?!1:e.every((e,r)=>z(e,t[r],n+1));if(Array.isArray(t)||!I(e)||!I(t))return!1;let r=Object.keys(e),i=Object.keys(t);return r.length===i.length&&r.every(r=>Object.hasOwn(t,r)&&z(e[r],t[r],n+1))},ee=(e,t)=>!L(e)||!L(t)?!1:z(e,t,0);function te(e){let t=e.metadata;if(!t||typeof t!=`object`)return;let n=t.custom;if(!n||typeof n!=`object`)return;let r=n.interactables;return Array.isArray(r)?r:void 0}function ne(e){return`update_${e.replace(/[^a-zA-Z0-9_-]/g,`_`)}`}var B=e=>{if(!I(e))return;let t=e.id;return typeof t==`string`||typeof t==`number`?t:void 0};function re(e,t,n=[]){if(!I(e)||!I(t))return t;let r={...e,...t},[i,...a]=n;return i!==void 0&&Object.hasOwn(t,i)&&(r[i]=re(e[i],t[i],a)),r}function ie(e,t,n,r){let i=Array.isArray(t.set)?[...t.set]:[...e];if(t.clear===!0&&(i=[]),Array.isArray(t.remove)&&t.remove.length>0){let e=new Set(t.remove);i=i.filter(t=>{let n=B(t);return n===void 0?!e.has(t):!e.has(n)})}let a=t.update;if(Array.isArray(a)&&a.length>0){let e=new Map;for(let t of a){let n=B(t);n!==void 0&&!Number.isNaN(n)&&!e.has(n)&&e.set(n,t)}let t=r?.[0]===`update`?{patch:a[Number(r[1])],rest:r.slice(2)}:void 0;i=i.map(n=>{let r=B(n);if(r===void 0||!I(n))return n;let i=e.get(r);return i?t&&i===t.patch?re(n,i,t.rest):{...n,...i}:n})}if(Array.isArray(t.add)&&t.add.length>0){let e=n?t.add.map(e=>{if(!I(e)||e.id!==void 0)return e;let t=n();return t===void 0?e:{...e,id:t}}):t.add;i=[...i,...e]}return i}function V(e,t,n){if(!I(e)||!I(t))return t;let r=I(n?.arrayBaseline)?n.arrayBaseline:e,i=n?.partialPath,a=Object.entries(e);for(let[o,s]of Object.entries(t)){let t=r[o],c=i?.[0]===o?i.slice(1):void 0;if(Array.isArray(t)&&I(s)){let e=n?.idFactory&&(n.idKeyedFields===void 0||n.idKeyedFields.has(o))?()=>n.idFactory?.(o):void 0;a.push([o,ie(t,s,e,c)])}else c?a.push([o,re(e[o],s,c)]):a.push([o,s])}return Object.fromEntries(a)}function ae(e,t){if(!I(e)||!I(t))return;for(let n of Object.keys(e))if(!Object.hasOwn(t,n))return;let n=[];for(let[r,i]of Object.entries(t))Object.hasOwn(e,r)&&ee(e[r],i)||n.push([r,i]);let r=n.length;if(r!==0&&r!==Object.keys(t).length)return Object.fromEntries(n)}var oe=e=>{if(!e||typeof e!=`object`)return;let t=e;return t.type===`tool-call`?t:void 0},se=e=>{if(typeof e==`string`&&e.startsWith(`{`))try{e=JSON.parse(e)}catch{return}return I(e)?e:void 0},ce=(e,t,n)=>e.toolCallId===t&&(e.toolName===n||se(e.result)?.interactable===n),le=(e,t)=>{if(!e.args||typeof e.args!=`object`)return!1;let n=se(e.result);if(n?.success===!1)return!1;if(typeof n?.id==`string`)return n.id===t;let r=e.args.id;return r===t||r===void 0},ue=e=>{let t=se(e)?.addedItemIds;if(!I(t))return;let n=new Map;for(let[e,r]of Object.entries(t)){if(!Array.isArray(r))continue;let t=r.filter(e=>typeof e==`string`);t.length>0&&n.set(e,t)}if(n.size!==0)return e=>n.get(e)?.shift()},de=new WeakMap;function fe(e,t,n){let r=de.get(e);r||(r=new Map,de.set(e,r));let i=r.get(n);i||(i=new Map,r.set(n,i));let a=i.get(t);if(a)return a;let o=ne(n),s=[],c=()=>s[s.length-1];for(let r of e)if(r.role===`user`){let e=te(r)?.find(e=>e.id===t);if(!e)continue;if(e.partial){let t=c();t&&s.push({state:V(t.state,e.state),origin:`user-edit`})}else s.push({state:e.state,origin:`user-edit`})}else if(r.role===`assistant`)for(let e of r.content??[]){let r=oe(e);if(r){if(ce(r,t,n))r.args&&typeof r.args==`object`&&s.push({state:r.args,origin:`create`,toolCallId:t});else if(r.toolName===o&&le(r,t)){let e=c();if(e){let{id:t,...n}=r.args,i=ue(r.result);s.push({state:i?V(e.state,n,{idFactory:i}):V(e.state,n),origin:`update`,toolCallId:r.toolCallId})}}}}return i.set(t,s),s}function pe(e,t,n){let r=fe(e,t,n),i=r[r.length-1];return i?{state:i.state}:void 0}function me(e,t){if(!e)return;let{interactables:n,...r}=e,i={...r};if(Array.isArray(n)){let e=[];for(let r of n){process.env.NODE_ENV!==`production`&&!L(r.state)&&console.warn(`[Interactables] state for "${r.name}" (${r.id}) is not JSON-equatable (an undefined, NaN, Infinity, function, or symbol value?). It will be re-snapshotted on every send, recreating per-message growth. Use plain JSON values.`);let n=pe(t,r.id,r.name);if(!n){e.push({id:r.id,name:r.name,state:r.state});continue}if(ee(r.state,n.state))continue;let i=ae(n.state,r.state);e.push(i?{id:r.id,name:r.name,state:i,partial:!0}:{id:r.id,name:r.name,state:r.state})}e.length&&(i.interactables=e)}return Object.keys(i).length?i:void 0}var he=e=>e,ge=new Set([`$$typeof`,`nodeType`,`then`,`__v_raw`,`__v_isRef`,`__v_isReactive`,`__v_isReadonly`,`__v_isShallow`,`__v_skip`]),_e=(e,t)=>{if(e===Symbol.toStringTag)return t;if(typeof e!=`symbol`){if(e===`toJSON`)return()=>t;if(!ge.has(e))return!1}},ve=class{getOwnPropertyDescriptor(e,t){let n=this.get(e,t);if(n!==void 0)return{value:n,writable:!1,enumerable:!0,configurable:!0}}set(){return!1}setPrototypeOf(){return!1}defineProperty(){return!1}deleteProperty(){return!1}preventExtensions(){return!1}},ye=Symbol(`assistant-ui.store.clientId`),be=Symbol(`assistant-ui.store.instanceTag`),xe=new WeakSet,Se=new Set([`call`,`apply`,`bind`]),Ce=(e,t)=>{let n=new Proxy((()=>{}),{apply:()=>(t(),n),get:(n,r)=>Se.has(r)?Reflect.get(n,r):r===`source`?e.source:r===`query`?e.query:r===`name`?e.name:r===ye?Oe(t()):t()[r],has:(e,n)=>n===`source`||n===`query`||n===`name`||n===ye||n in t(),ownKeys:()=>Reflect.ownKeys(t()),getOwnPropertyDescriptor:(e,n)=>{if(typeof n!=`symbol`&&n in t())return{value:t()[n],writable:!1,enumerable:!0,configurable:!0}}});return xe.add(n),n},we=(e,t)=>{let n=()=>{throw Error(e)},r=new Proxy((()=>{}),{apply:n,get:(e,r)=>{if(Se.has(r))return Reflect.get(e,r);if(r===`source`||r===`query`)return null;if(r===`name`)return t;if(r===ye)return n();let i=_e(r,`AssistantClientAccessor`);return i===!1?n():i},has:(e,t)=>t===`source`||t===`query`||t===`name`,ownKeys:()=>[],getOwnPropertyDescriptor:()=>void 0});return xe.add(r),r},Te=e=>{if(xe.has(e))return!1;let t=e[ye];return t!==void 0&&t!==e},Ee=e=>e?.source!=null,De=e=>e?.source===null,Oe=e=>e[ye]??e,ke=e=>e[be]??Oe(e),Ae=e=>e===`optional`||e===`subscribe`||e===`on`||e===`__proto__`||typeof e==`symbol`,je=e=>{let t=[];for(let n in e)Ae(n)||t.push(n);return t},Me=class extends ve{#e;constructor(e){super(),this.#e=e}get(e,t){let n=_e(t,`OptionalAssistantClient`);if(n!==!1)return n;if(Ae(t))return;let r=this.#e[t];return Ee(r)?r:void 0}ownKeys(){return je(this.#e)}has(e,t){return!Ae(t)&&t in this.#e}},Ne=e=>new Proxy({},new Me(e)),Pe=null;function Fe(e,t){e.currentIndex=0,e.wipContextDeps=null,e.wipCommitCallbacks=[];let n=Pe;Pe=e;try{if(t(),e.isFirstRender=!1,e.cells.length!==e.currentIndex)throw Error(`Rendered ${e.currentIndex} hooks but expected ${e.cells.length}. Hooks must be called in the exact same order in every render.`)}finally{Pe=n}}function Ie(){if(!Pe)throw Error(`No resource fiber available`);return Pe}function Le(){return Pe}var Re=typeof process<`u`&&(process.env.NODE_ENV===`development`||process.env.NODE_ENV===`test`),ze=(e,t)=>({onError:t,version:0,committedVersion:0,dispatchUpdate:e,changelog:[],committedLog:[],unsettledCount:0,rollbackCallbacks:[]}),Be=e=>{e.committedVersion=e.version;for(let t of e.changelog)t.logged=!1,t.settled||(t.settled=!0,e.unsettledCount--),e.committedLog.push(t);e.changelog.length=0,e.unsettledCount===0&&(e.committedLog.length=0),e.rollbackCallbacks.length=0},Ve=(e,t)=>{let n=e.version>t;if(e.version=t,n){for(let t=0;t<e.rollbackCallbacks.length;t++)e.rollbackCallbacks[t]();if(e.rollbackCallbacks.length=0,t<=e.committedVersion){let n=[];for(;e.committedVersion-n.length>t;){let t=e.committedLog.pop();if(t===void 0){if(Re)throw Error(`tap: committed history is shorter than the replay base.`);break}Ge(t.fiber,t.cell),t.cell.workInProgress=t.prevState,n.push({record:t,prevState:t.prevState,eagerState:t.eagerState,hasEagerState:t.hasEagerState})}if(n.length>0){let t=e.committedVersion;We(e,()=>{for(let t=n.length-1;t>=0;t--){let r=n[t];r.record.prevState=r.prevState,r.record.eagerState=r.eagerState,r.record.hasEagerState=r.hasEagerState,e.committedLog.push(r.record)}e.committedVersion=t})}e.committedVersion=t;for(let t of e.changelog)t.logged=!1;e.changelog.length=0}else{for(;e.committedVersion+e.changelog.length>t;)e.changelog.pop().logged=!1;for(let t=0;t<e.changelog.length;t++)He(e.changelog[t]);Be(e)}}},He=e=>{Ge(e.fiber,e.cell),e.queued||(e.queued=!0,(e.cell.queue??=[]).push(e))},Ue=(e,t)=>{e.wipCommitCallbacks.push(t)},We=(e,t)=>{e.rollbackCallbacks.push(t)},Ge=(e,t)=>{t.isDirty||(t.isDirty=!0,e.markDirty?.(),We(e.root,()=>{if(t.queue!==null){for(let e of t.queue)e.queued=!1;t.queue=null}t.workInProgress=t.current,t.isDirty=!1}))},Ke=()=>{throw Error(`Rendered more hooks than during the previous render. Hooks must be called in the exact same order in every render.`)},qe=()=>{throw Error(`Hook order changed between renders`)},Je=e=>({type:e,setup:void 0,setupDeps:void 0,cleanup:void 0,deps:null,generation:0});function Ye(e,t,n){let r=Ie(),i=r.currentIndex++,a=r.cells[i],o=a===void 0?Je(n):a.type===n?a:qe();if(a===void 0&&(r.isFirstRender||Ke(),r.cells[i]=o,n===`insertion`?(r.insertionCells??=[]).push(o):r.effectCells.push(o)),o.deps!==null&&!!t!=!!o.deps)throw Error(`useEffect called with and without dependencies across re-renders`);let s=r.isRefreshing;Ue(r,()=>{o.setup=e,o.setupDeps=t,s&&(o.deps=null),o.generation++})}function Xe(e,t){Ye(e,t,`effect`)}function Ze(e){let t=Ie(),n=t.currentIndex++,r=t.cells[n];if(r===void 0){t.isFirstRender||Ke();let r={current:e};return t.cells[n]={type:`ref`,ref:r},r}return r.type===`ref`?r.ref:qe()}var Qe=Symbol(`tap.Context.defaultValue`),$e=e=>e,et=new Map,tt=new Set,nt=()=>new Map(et),rt=(e,t)=>{let n=et;et=e;try{return t()}finally{et=n}},it=(e,t)=>{e[Qe]=t},at=e=>typeof e==`object`&&!!e&&Qe in e,ot=e=>typeof e==`object`&&!!e&&`$$typeof`in e&&e.$$typeof===Symbol.for(`react.context`),st=e=>at(e)||ot(e),ct=e=>{if(!at(e)){if(ot(e))it(e,e._currentValue??e._currentValue2);else throw Error("A tap resource's `use()` only accepts a tap context.")}},lt=(e,t,n)=>{if(typeof e!=`object`||!e)throw Error(`useContextProvider only accepts a React context.`);ct(e);let r=e,i=Ie(),a=Ze(void 0),o=a.current===void 0||!Object.is(a.current.value,t);Xe(()=>{a.current={value:t}},[t]);let s=et.get(r),c=s!==void 0||et.has(r);et.set(r,{value:t,source:i});try{return ut(r,o,n)}finally{c?et.set(r,s):et.delete(r)}},ut=(e,t,n)=>{let r=tt.has(e);t?tt.add(e):tt.delete(e);try{return n()}finally{r?tt.add(e):tt.delete(e)}},dt=e=>{ct(e);let t=e,n=ft(t,e),r=Ie();return(r.wipContextDeps??=new Map).set(t,n.source),n.value},ft=(e,t)=>et.get(e)??{value:$e(t)[Qe],source:null},pt=(e,t,n,r)=>{if(!r)return n;let i=n;for(let[n,a]of r)a!==t&&a!==e&&(i??=new Map).set(n,a);return i},mt=(e,t=e.wipContextDeps)=>{let n=Le();n&&t&&(n.wipContextDeps=pt(n,e,n.wipContextDeps,t))},ht=()=>tt.size>0,gt=e=>{if(!e.contextDeps||!ht())return!1;for(let t of tt.keys())if(e.contextDeps.has(t))return!0;return!1},_t=(e,t,n)=>{if(e.isNeverMounted)throw Error(`Resource updated before mount`);let r=!1,i=!0;e.root.unsettledCount++,e.root.dispatchUpdate(()=>(r||(r=!0,n&&e.root.changelog.length===0&&!t.cell.isDirty&&!t.hasEagerState&&(t.prevState=t.cell.workInProgress,t.eagerState=n(t.cell.workInProgress,t.action),t.hasEagerState=!0,i=!Object.is(t.cell.current,t.eagerState),!i&&!t.settled&&(t.settled=!0,e.root.unsettledCount--))),i),()=>(r=!0,i=!0,He(t),t.logged||(t.logged=!0,e.root.changelog.push(t)),!0))},vt=(e,t,n,r,i)=>{let a=r?r(n):n;Re&&e.devStrictMode&&r&&r(n);let o={type:`reducer`,workInProgress:a,current:a,isDirty:!1,queue:null,renderQueue:null,reducer:t,dispatch:n=>{let r=Le();if(r!==null){if(r!==e)throw Error(`Cannot update a resource while rendering a different resource.`);(e.renderPendingCells??=new Set).add(o),(o.renderQueue??=[]).push(n)}else _t(e,{fiber:e,cell:o,action:n,hasEagerState:!1,eagerState:void 0,prevState:o.current,settled:!1,queued:!1,logged:!1},i?t:void 0)}};return o};function yt(e,t,n,r){let i=Ie(),a=i.currentIndex++,o=i.cells[a],s=(()=>{if(o!==void 0)return o.type===`reducer`?o:qe();i.isFirstRender||Ke();let s=vt(i,e,t,n,r);return i.cells[a]=s,s})(),c=s.queue;if(c!==null){let t=e===s.reducer;for(let n=0;n<c.length;n++){let r=c[n];!r.hasEagerState||!t||!Object.is(r.prevState,s.workInProgress)?(r.prevState=s.workInProgress,r.eagerState=e(s.workInProgress,r.action),r.hasEagerState=!0,Re&&i.devStrictMode&&(r.eagerState=e(s.workInProgress,r.action))):Re&&i.devStrictMode&&e(s.workInProgress,r.action),r.queued=!1,s.workInProgress=r.eagerState}s.queue=null}if(s.reducer=e,s.renderQueue!==null){let t=s.workInProgress;for(let n of s.renderQueue)t=e(t,n);s.renderQueue=null,i.renderPendingCells?.delete(s),Object.is(t,s.workInProgress)||(Ge(i,s),s.workInProgress=t)}return s.isDirty&&Ue(i,()=>{s.current=s.workInProgress,s.isDirty=!1}),[s.workInProgress,s.dispatch]}function bt(e,t,n){return yt(e,t,n,!1)}var xt=(e,t)=>typeof t==`function`?t(e):t,St=e=>e===void 0?void 0:typeof e==`function`?e():e;function Ct(e){return yt(xt,e,St,!0)}var wt=(e,t)=>{Re&&e.length!==t.length&&console.error(`The final argument passed to a hook changed size between renders. The order and size of this array must remain constant.
|
|
6
|
+
|
|
7
|
+
Previous: [${e.join(`, `)}]\nIncoming: [${t.join(`, `)}]`);for(let n=0;n<e.length&&n<t.length;n++)if(!Object.is(e[n],t[n]))return!1;return!0},Tt=(e,t)=>{Ue(e,()=>{t.current=t.wip,t.currentDeps=t.wipDeps,t.wipIsRefreshing=!1,t.isDirty=!1})},Et=(e,t)=>{let n=Ie(),r=n.currentIndex++,i=n.cells[r];if(i===void 0){n.isFirstRender||Ke();let a=e();return Re&&n.devStrictMode&&e(),i={type:`memo`,current:a,currentDeps:t,wip:a,wipDeps:t,wipIsRefreshing:!1,isDirty:!1},n.cells[r]=i,a}i.type!==`memo`&&qe();let a=i;if(a.wipIsRefreshing&&!n.isRefreshing&&(a.wip=a.current,a.wipDeps=a.currentDeps,a.wipIsRefreshing=!1,a.isDirty=!1),!n.isRefreshing&&wt(a.wipDeps,t))return a.isDirty&&Tt(n,a),a.wip;let o=e();return Re&&n.devStrictMode&&e(),a.wip=o,a.wipDeps=t,a.wipIsRefreshing=n.isRefreshing,a.isDirty||(a.isDirty=!0,We(n.root,()=>{a.wip=a.current,a.wipDeps=a.currentDeps,a.wipIsRefreshing=!1,a.isDirty=!1})),Tt(n,a),o},Dt=(e,t)=>Et(()=>e,t);function Ot(e,t){Ye(e,t,`insertion`)}function kt(e){let t=Ie(),n=Ze(e);return n.current!==e&&Ue(t,()=>{n.current=e}),Ze(((...e)=>{if(Re&&Le())throw Error(`useEffectEvent cannot be called during render`);return n.current(...e)})).current}var At=e=>typeof e==`object`&&!!e&&typeof e.then==`function`,jt=()=>{},Mt=e=>{let t=e;switch(typeof t.status==`string`?t.status!==`fulfilled`&&t.status!==`rejected`&&e.then(jt,jt):(t.status=`pending`,e.then(e=>{t.status===`pending`&&(t.status=`fulfilled`,t.value=e)},e=>{t.status===`pending`&&(t.status=`rejected`,t.reason=e)})),t.status){case`fulfilled`:return t.value;case`rejected`:throw t.reason;default:throw e}},Nt=e=>At(e)?Mt(e):dt(e),Pt=!1,Ft=(e,t,n=t)=>{let r=Ie().isNeverMounted,i=r?n():t();!Re||Pt||r&&n!==t||Object.is(i,t())||(Pt=!0,console.error(`The result of getSnapshot should be cached to avoid an infinite loop`));let[,a]=bt(e=>e+1,0),o=Ze(0),s=kt(()=>{try{if(Object.is(i,t()))return o.current=0,!1}catch{}return!0});return Xe(()=>e(()=>{s()&&a()}),[e]),Xe(()=>{if(s()){if(++o.current>50)throw o.current=0,Error(`Maximum update depth exceeded. The result of getSnapshot should be cached to avoid an infinite loop.`);a()}},[e,i,t]),i},It=(e,t)=>{},Lt=0,Rt=()=>{let e=Ze(null);return e.current??=`:tap${Lt++}:`,e.current},zt=(e,t,n)=>{let r=()=>{if(!e)return;let n=t();if(typeof e==`function`){let t=e(n);return typeof t==`function`?t:()=>e(null)}return e.current=n,()=>{e.current=null}};n==null?Xe(r):Xe(r,[...n,e])},Bt=f.default;function Vt(e){let t=(0,f.useRef)(e);return(0,f.useInsertionEffect)(()=>{t.current=e}),(0,f.useCallback)(((...e)=>t.current(...e)),[])}var Ht=Bt.useEffectEvent??Vt,Ut=s({Children:()=>un,Fragment:()=>an,Suspense:()=>dn,cloneElement:()=>sn,createContext:()=>pn,createElement:()=>on,default:()=>f.default,forwardRef:()=>nn,isValidElement:()=>cn,lazy:()=>ln,memo:()=>rn,use:()=>mn,useCallback:()=>Jt,useContext:()=>hn,useDebugValue:()=>Qt,useDeferredValue:()=>fn,useEffect:()=>W,useEffectEvent:()=>Xt,useId:()=>en,useImperativeHandle:()=>tn,useInsertionEffect:()=>$t,useLayoutEffect:()=>Yt,useMemo:()=>qt,useReducer:()=>Kt,useRef:()=>U,useState:()=>H,useSyncExternalStore:()=>Zt});l(Ut,require("react"));var Wt=()=>Le()!==null,Gt=f.default,H=e=>Wt()?Ct(e):Gt.useState(e),Kt=(e,t,n)=>Wt()?bt(e,t,n):Gt.useReducer(e,t,n),U=e=>Wt()?Ze(e):Gt.useRef(e),qt=(e,t)=>Wt()?Et(e,t):Gt.useMemo(e,t),Jt=(e,t)=>Wt()?Dt(e,t):Gt.useCallback(e,t),W=(e,t)=>Wt()?Xe(e,t):Gt.useEffect(e,t),Yt=(e,t)=>Wt()?Xe(e,t):Gt.useLayoutEffect(e,t),Xt=e=>Wt()?kt(e):Ht(e),Zt=(e,t,n)=>Wt()?Ft(e,t,n):Gt.useSyncExternalStore(e,t,n),Qt=(e,t)=>Wt()?void 0:Gt.useDebugValue(e,t),$t=(e,t)=>Wt()?Ot(e,t):Gt.useInsertionEffect(e,t),en=()=>Wt()?Rt():Gt.useId(),tn=(e,t,n)=>Wt()?zt(e,t,n):Gt.useImperativeHandle(e,t,n),nn=e=>Gt.forwardRef(e),rn=(e,t)=>Gt.memo(e,t),an=Gt.Fragment,on=(...e)=>Gt.createElement(...e),sn=(...e)=>Gt.cloneElement(...e),cn=e=>Gt.isValidElement(e),ln=e=>Gt.lazy(e),un=Gt.Children,dn=Gt.Suspense,fn=(e,t)=>Gt.useDeferredValue(e,t),pn=e=>{let t=Gt.createContext(e);return it(t,e),t},mn=e=>{if(Wt()&&st(e))return Nt(e);if(Gt.use)return Gt.use(e);if(st(e))return Gt.useContext(e);throw Error(`React.use() requires React 19 outside a tap resource.`)},hn=e=>Wt()&&st(e)?Nt(e):Gt.useContext(e),gn=Symbol.for(`react.memo_cache_sentinel`),_n=e=>Array(e).fill(gn),vn=(e,t)=>{let n=e.memoCache,r=n.workInProgress;if(r===null){let t=n.current;r=t===null?[]:t.map(e=>e.slice()),n.workInProgress=r,We(e.root,()=>{n.workInProgress=null,n.refreshedIndices=null})}let i=n.index++,a=r[i];return n.refreshedIndices?.has(i)&&!e.isRefreshing&&(n.refreshedIndices.delete(i),a=n.current?.[i]?.slice()??_n(t),r[i]=a),a===void 0||e.isRefreshing?(a=_n(t),r[i]=a,e.isRefreshing&&(n.refreshedIndices??=new Set).add(i)):Re&&a.length!==t&&console.error(`Expected a constant size argument for each invocation of c(). The previous cache was allocated with size ${a.length} but size ${t} was requested.`),a},yn=e=>vn(Ie(),e),bn=(e,t)=>{if(e.length!==0){if(e.length===1)throw e[0];for(let t of e)console.error(t);throw AggregateError(e,t)}},xn=50,Sn={schedulers:new Set,tasks:[],notifies:[],isScheduled:!1},Cn=null,wn,Tn=class{_isDirty=!1;_task;onError;constructor(e,t){this._task=e,this.onError=t}get isDirty(){return this._isDirty}markDirty(){if(Cn&&(Cn.get(this)??0)>=xn)throw Error(`Maximum update depth exceeded. This can happen when a resource repeatedly calls setState inside useEffect.`);this._isDirty=!0,Sn.schedulers.add(this),kn()}runTask(){Cn?.set(this,(Cn.get(this)??0)+1),this._isDirty=!1,this._task()}settle(){this._isDirty=!1}},En=new Tn(()=>{let e=Sn.tasks.splice(0),t=[];for(let{run:n,onError:r}of e)try{n()}catch(e){if(wn&&r)try{r(e)}catch(e){t.push(e)}else t.push(e)}bn(t,`Errors occurred while running scheduled tasks`)}),Dn=(e,t)=>{En.markDirty(),Sn.tasks.push({run:e,onError:t})},On=(e,t)=>{Cn===null?e():Sn.notifies.push({run:e,onError:t})},kn=()=>{Sn.isScheduled||(Sn.isScheduled=!0,jn())},An=(e=!1)=>{let t=Cn,n=wn,r=[];Cn=new Map,wn=e?r:void 0;try{for(let t of Sn.schedulers)if(Sn.schedulers.delete(t),t.isDirty)try{t.runTask()}catch(n){if(e&&t.onError)try{t.onError(n)}catch(e){r.push(e)}else r.push(n)}}finally{if(Cn=t,wn=n,Sn.schedulers.clear(),Sn.isScheduled=!1,Cn===null){let t=Sn.notifies;for(;t.length>0;){let{run:n,onError:i}=t.shift();try{n()}catch(t){if(e&&i)try{i(t)}catch(e){r.push(e)}else r.push(t)}}}}bn(r,`Errors occurred during flushSync`)},jn=(()=>{if(typeof MessageChannel<`u`){let e=null,t;return()=>{if(!e){let n=new MessageChannel;n.port1.onmessage=()=>{e?.unref?.(),An(!0)},e=n.port1,t=n.port2}e.ref?.(),t.postMessage(null)}}return()=>setTimeout(()=>An(!0),0)})(),Mn=e=>{if(Cn!==null)return Re&&console.warn(`flushTapSync was called from inside a render or commit. The flush is deferred until the current pass completes.`),e();let t=Sn;Sn={schedulers:new Set,tasks:[],notifies:[],isScheduled:!0};try{let t=e();return An(),t}finally{let e=Sn;Sn=t;for(let t of e.tasks)Sn.tasks.push(t);if(Sn.tasks.length>0&&En.markDirty(),e.schedulers.size>0){for(let t of e.schedulers)Sn.schedulers.add(t);kn()}}};function Nn(e){if(e.length===0)return;let t;for(let n=0;n<e.length;n++)try{e[n]()}catch(e){(t??=[]).push(e)}t!==void 0&&bn(t,`Errors during commit`)}function Pn(e){let t=e.setup,n=e.setupDeps,r=e.generation,i;try{let e=t();if(e!==void 0&&typeof e!=`function`)throw Error(`An effect function must either return a cleanup function or nothing. Received: ${typeof e}`);i=e}finally{e.generation===r?(e.cleanup=i,e.deps=n):i?.()}}var Fn=e=>e.setup===void 0?!1:e.deps===null||e.setupDeps===void 0||!wt(e.deps,e.setupDeps);function In(e,t){let n;for(let t of e)Fn(t)&&(n??=[]).push(t);if(n===void 0)return t;for(let e of n)if(e.deps=null,e.cleanup!==void 0)try{e.cleanup()}catch(e){(t??=[]).push(e)}finally{e.cleanup=void 0}for(let e of n)try{Pn(e)}catch(e){(t??=[]).push(e)}return t}function Ln(e,t=!0){let n;e.insertionCells!==null&&t&&(n=In(e.insertionCells,n)),n=In(e.effectCells,n),n!==void 0&&bn(n,`Errors during commit`)}function Rn(e){let t;for(let n of e)if(n.deps=null,n.cleanup)try{n.cleanup?.()}catch(e){(t??=[]).push(e)}finally{n.cleanup=void 0}t!==void 0&&bn(t,`Errors during cleanup`)}var zn={useState:Ct,useReducer:bt,useRef:Ze,useMemo:Et,useCallback:Dt,useEffect:Xe,useLayoutEffect:Xe,useInsertionEffect:Ot,useEffectEvent:kt,useContext:dt,use:Nt,useSyncExternalStore:Ft,useDebugValue:It,useId:Rt,useImperativeHandle:zt,useMemoCache:yn},Bn=f.default,Vn=Bn.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE??Bn.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,Hn=Vn==null?null:`H`in Vn?{get current(){return Vn.H},set current(e){Vn.H=e}}:`ReactCurrentDispatcher`in Vn?{get current(){return Vn.ReactCurrentDispatcher.current},set current(e){Vn.ReactCurrentDispatcher.current=e}}:null;function Un(e){if(!Hn)return e();let t=Hn.current;Hn.current=zn;try{return e()}finally{Hn.current=t}}function Wn(e,t,n=void 0,r){return{hook:e,root:t,markDirty:n,devStrictMode:r,cells:[],effectCells:[],insertionCells:null,hostCells:null,contextDeps:null,wipContextDeps:null,wipCommitCallbacks:null,memoCache:{current:null,workInProgress:null,refreshedIndices:null,index:0},renderPendingCells:null,currentIndex:0,isRefreshing:!1,isFirstRender:!0,isMounted:!1,isReleased:!1,isNeverMounted:!0}}function Gn(e){e.wipCommitCallbacks=null,e.wipContextDeps=null,e.memoCache.workInProgress=null,e.memoCache.refreshedIndices=null}function Kn(e,t,n){try{t?(e.isReleased=!0,e.insertionCells!==null&&Rn(e.insertionCells)):e.isMounted&&(e.isMounted=!1,Rn(e.effectCells))}catch(e){(n??=[]).push(e)}if(e.hostCells!==null){for(let r of e.hostCells)if(r.fiber!==null&&(n=Kn(r.fiber,t,n)),r.fibers!==null)for(let{fiber:e}of r.fibers.values())n=Kn(e,t,n)}return n}function qn(e,t=!0){let n;t&&(n=Kn(e,!0,n)),n=Kn(e,!1,n),n!==void 0&&bn(n,`Errors during cleanup`)}function Jn(e){let t;for(let n of e)n.isReleased&&(t=Kn(n,!0,t));for(let n of e)t=Kn(n,!1,t);t!==void 0&&bn(t,`Errors during cleanup`)}function Yn(e,t){if(e.renderPendingCells!==null){for(let t of e.renderPendingCells)t.renderQueue=null;e.renderPendingCells.clear()}let n=0,r,i=e.isRefreshing;e.isRefreshing=i||(Le()?.isRefreshing??!1);try{do{if(++n>25)throw Error(`Too many re-renders. tap limits the number of renders to prevent an infinite loop.`);e.memoCache.index=0,Fe(e,()=>{r=Un(()=>e.hook(...t))})}while((e.renderPendingCells?.size??0)>0)}catch(t){throw Gn(e),t}finally{e.isRefreshing=i}return mt(e),r}function Xn(e){let t=e.wipCommitCallbacks;e.wipCommitCallbacks=null;let n=Re&&!e.isMounted&&e.devStrictMode===`root`;e.isMounted=!0,e.isNeverMounted=!1,t!==null&&(e.contextDeps=e.wipContextDeps,Be(e.root),e.memoCache.workInProgress!==null&&(e.memoCache.current=e.memoCache.workInProgress,e.memoCache.workInProgress=null,e.memoCache.refreshedIndices=null),Nn(t)),n&&(Ln(e,t!==null),qn(e,!1),e.isMounted=!0),Ln(e,!n&&t!==null)}var Zn=()=>{let e=Ie();return e.devStrictMode?e.isFirstRender?`child`:`root`:null},Qn=()=>null,$n=()=>{if(!Re)return Qn;let e=U(0);H(()=>e.current++);let t=e.current===2,n=U(!1),r=U(!0);return r.current=!0,W(()=>{f.default.version?.startsWith(`18.`)&&(r.current||(n.current=!0),r.current=!1)},[]),()=>t||n.current?`child`:null},er=()=>Le()?Zn:$n(),tr=e=>{let t=Ie(),n=t.currentIndex++,r=t.cells[n],i;if(r===void 0){t.isFirstRender||Ke();let r=e instanceof Map;i={type:`host`,fiber:r?null:e,fibers:r?e:null},t.cells[n]=i,(t.hostCells??=[]).push(i)}else r.type!==`host`&&qe(),i=r;return i.fibers===null&&i.fiber!==e&&Ue(t,()=>{i.fiber=e}),i},nr=(e,t)=>{if(!(e instanceof Map))return t(e);for(let{fiber:n}of e.values())t(n)},rr=e=>{e.isReleased=!1},ir=e=>{e.isReleased=!0,e.isMounted||queueMicrotask(()=>{e.isReleased&&qn(e,!0)})},ar=e=>{$t(()=>(nr(e,rr),()=>nr(e,ir)),[e]),W(()=>()=>{Jn(e instanceof Map?Array.from(e.values(),({fiber:e})=>e):[e])},[e])},or=e=>Le()?tr(e):(ar(e),null),sr=()=>{let e=U(0),t=e.current,n=Ie();return{version:t,markDirty:qt(()=>()=>{e.current++,n.markDirty?.()},[n]),root:n.root}},cr=()=>{let[e]=H(()=>ze((e,t)=>{let i=!1;r(t=>(i=!e(),i?t:t+1)),i||n(()=>e()&&t())})),[t,n]=Kt((t,n)=>(Ve(e,t),t+ +!!n()),0),[,r]=H(0);return Ve(e,t),{root:e,version:t,markDirty:void 0}},lr=()=>{let e=er(),t=Le()===null,n=t?e():null,{root:r,version:i,markDirty:a}=t?cr():sr();return{version:i,createFiber:Jt((i,o,s)=>Wn(i,r,s?()=>{s(),a?.()}:a,t?n:e()),[])}},ur=e=>e(),dr=e=>{let t=[];for(let n of e)try{n()}catch(e){t.push(e)}bn(t,`Errors occurred while notifying Tap root subscribers`)},fr=(e,t,n,r)=>{let i=new Tn(()=>c.handleUpdate(),r),a=[],o=ze((e,t)=>{(a.length!==0||e())&&(a.push(t),i.markDirty())},r),s=Wn(ur,o,void 0,t),c={scheduler:i,queue:a,fiber:s,subscribers:new Set,pendingHostRender:!1,isMounted:!1,hasRendered:!1,committedRender:e,context:new Map,value:void 0,applyQueue:()=>{Ve(o,o.committedVersion);for(let e of a)Re&&s.devStrictMode&&e(),e();return Ve(o,o.committedVersion+o.changelog.length),a.length},publish:(e,t)=>{i.isDirty||o.committedVersion!==t||c.value===e||(c.value=e,On(()=>dr(c.subscribers),r))},finishFlush:(e,t,n)=>{Be(o),a.splice(0,n),c.pendingHostRender=!1,a.length===0&&i.settle(),c.isMounted&&Xn(s),c.publish(e,t)},handleUpdate:()=>{let e=c.applyQueue(),t;try{Re&&s.devStrictMode&&rt(c.context,()=>Yn(s,[c.committedRender])),t=rt(c.context,()=>Yn(s,[c.committedRender]))}catch(e){if(Ve(o,o.committedVersion),At(e)){let t=()=>{c.isMounted&&i.markDirty()};e.then(t,t);return}if(c.isMounted){c.pendingHostRender=!0,n(e=>e+1);return}throw e}if(i.isDirty)throw Error(`Scheduler is dirty, this should never happen`);c.finishFlush(t,o.version,e)}};return c},pr=e=>{let t=Le()===null,n=Le()?.root.onError,[,r]=H(0),i=er(),a=U(null),o=a.current??=fr(e,i(),r,n),s=nt(),c=o.scheduler.isDirty||o.pendingHostRender?o.applyQueue():0,l=rt(s,()=>Yn(o.fiber,[e])),u={render:e,context:s,value:l,drained:c,wip:o.fiber.wipCommitCallbacks,version:o.fiber.root.version,processed:!1};return o.hasRendered||(o.hasRendered=!0,o.committedRender=e,o.context=s,o.value=l),W(()=>(o.isMounted=!0,()=>{o.isMounted=!1}),[o]),or(o.fiber),W(()=>{Re&&t&&(o.fiber.devStrictMode??=i()),u.processed?o.fiber.isMounted||(Xn(o.fiber),o.queue.length&&!o.scheduler.isDirty&&o.scheduler.markDirty()):(u.processed=!0,o.committedRender=u.render,o.context=u.context,o.fiber.wipCommitCallbacks===u.wip?u.drained>0&&o.fiber.root.version===u.version?o.finishFlush(u.value,u.version,u.drained):(Xn(o.fiber),o.publish(u.value,u.version)):o.scheduler.isDirty||o.handleUpdate())}),qt(()=>({getValue:()=>o.value,subscribe:e=>(o.subscribers.add(e),()=>o.subscribers.delete(e))}),[o])},mr=(e,t)=>{let n=!1,r=Wn(pr,ze((i,a)=>{i()&&(a(),Dn(()=>{!n&&r.isMounted&&(Re&&r.devStrictMode&&Yn(r,[e]),Yn(r,[e]),Xn(r))},t?.onError))},t?.onError),void 0,Re?`root`:null),i=()=>{try{return Re&&r.devStrictMode&&Yn(r,[e]),Yn(r,[e])}catch(e){throw At(e)?Error(`createTapRoot suspended during its initial render; resolve the data first or use useTapRoot under a Suspense boundary.`):e}},a=()=>Mn(()=>Dn(()=>{n||Xn(r)})),o=()=>{n||(n=!0,qn(r))},s,c=()=>s??=i();if(!t?.mountOnSubscribe){let e=c();return a(),{...e,unmount:o}}let l=0,u=()=>Dn(()=>{l===0&&r.isMounted&&qn(r,!1)},t?.onError);return{getValue:()=>c().getValue(),subscribe:e=>{let t=c().subscribe(e);if(l++===0&&!r.isMounted&&!n)try{a()}catch(e){try{qn(r,!1)}finally{l--,t()}throw e}let i=!0;return()=>{i&&(i=!1,t(),--l===0&&u())}},unmount:o}};function hr(e){return(...t)=>({hook:e,args:t})}function gr(e,t,n){return typeof t==`function`?(...n)=>gr(e,t(...n)):n?{...t,key:e,deps:n}:{...t,key:e}}var _r=(e,t)=>({fiber:e,key:t,currentDeps:null,current:null,wipDeps:null,wip:null});function vr(e){let{version:t,createFiber:n}=lr(),r=U(null),i=r.current??=_r(n(e.hook,e.key),e.key),a=qt(()=>i.fiber.hook===e.hook&&i.key===e.key&&!i.fiber.isReleased?i.fiber:n(e.hook,e.key),[i,e.hook,e.key,n]);i.wipDeps=i.currentDeps,i.wip=i.current;let o=[a,t,e.args];(Le()?.isRefreshing||gt(a)||i.currentDeps===null||!wt(i.currentDeps,o))&&(i.wipDeps=o,i.wip={value:Yn(a,e.args)});let s=i.wip,c=or(a);return W(()=>{if(i.currentDeps=i.wipDeps,i.current=i.wip,i.fiber=a,i.key=e.key,Xn(a),c!==null)return()=>{c.fiber!==a&&qn(a,!0)}},[i,c,a,e.key,s]),s.value}var yr=(e,t,n)=>{let r=U(null),i=r.current??={currentDeps:null,current:null},a=!n&&i.currentDeps&&wt(i.currentDeps,t)?i.current:e();return W(()=>{i.currentDeps=t,i.current=a}),a},br=(e,t)=>{let n=e.get(t);n&&(n.isDirty=!0)},xr=(e,t)=>!e.isDirty&&!gt(e.fiber)&&(e.committedElement===t||t.deps!==void 0&&e.committedDeps!==void 0&&wt(e.committedDeps,t.deps)),Sr=e=>{if(!ht())return!1;for(let{fiber:t}of e.values())if(gt(t))return!0;return!1};function Cr(e){let[t]=H(()=>new Map),{version:n,createFiber:r}=lr(),i=Le()?.isRefreshing??!1,a=Sr(t),o=!1,s=yr(()=>{let n=new Set,a=[],s=0;for(let c=0;c<e.length;c++){let l=e[c],u=l.key;if(u===void 0)throw Error(`useResources did not provide a key for array at index ${c}`);if(n.has(u))throw Error(`Duplicate key ${u} in useResources`);n.add(u);let d=t.get(u);if(!d){let e=r(l.hook,l.key,()=>br(t,u));d={fiber:e,next:{value:Yn(e,l.args),deps:l.deps,element:l},isDirty:!1,committedDeps:void 0,committedElement:void 0,committedValue:void 0},s++,t.set(u,d)}else if(d.fiber.hook!==l.hook){let e=r(l.hook,l.key,()=>br(t,u)),n=Yn(e,l.args);d.next={value:n,deps:l.deps,element:l,remount:e},o=!0}else if(!i&&xr(d,l))typeof d.next==`object`&&Gn(d.fiber),d.fiber.contextDeps&&mt(d.fiber,d.fiber.contextDeps),d.next=`skip`;else{let e=Yn(d.fiber,l.args);d.next={value:e,deps:l.deps,element:l}}a.push(typeof d.next==`object`?d.next.value:d.committedValue)}if(t.size>a.length-s)for(let e of t.keys())n.has(e)||(t.get(e).next=`delete`,o=!0);return a},[e,t,r,n],i||a);return or(t),W(()=>{if(o){let e=[];for(let[n,r]of t.entries()){let i=r.next;i===`delete`?(e.push(r.fiber),t.delete(n)):i!==`skip`&&i.remount&&(e.push(r.fiber),r.fiber=i.remount)}for(let t of e)t.isReleased=!0;Jn(e)}for(let e of t.values()){let t=e.next;t===`skip`?!e.fiber.isNeverMounted&&!e.fiber.isMounted&&Xn(e.fiber):t!==`delete`&&(Xn(e.fiber),e.committedDeps=t.deps,e.committedElement=t.element,e.committedValue=t.value,e.isDirty=!1,e.next=`skip`)}},[s,t,o]),i?s.slice():s}var wr=e=>e(),Tr=e=>{let{createFiber:t}=lr(),[n]=H(()=>t(wr,void 0)),r=Yn(n,[e]);or(n);let i=!1,a=()=>{i&&n.isMounted||(i=!0,Xn(n))};return W(a),{value:r,effects:a}},Er=()=>()=>{},Dr=`You are using a component or hook that requires an AuiProvider. Wrap your component in an <AuiProvider> component.`,Or=class extends ve{#e;#t;#n;#r;constructor(e,t,n){super(),this.#e=e,this.#t=t,this.#n=n}get(e,t){if(t===`subscribe`||t===`on`)return Er;if(t===`optional`)return this.#r??=Ne(this.#n());let n=_e(t,this.#e);return n===!1?we(this.#t(String(t)),String(t)):n}ownKeys(){return[`subscribe`,`on`,`optional`]}getOwnPropertyDescriptor(e,t){if(t!==`optional`)return super.getOwnPropertyDescriptor(e,t);let n=this.get(e,t);if(n!==void 0)return{value:n,writable:!1,enumerable:!1,configurable:!0}}has(e,t){return t===`subscribe`||t===`on`||t===`optional`}},kr=((e,t)=>{let n=new Proxy({},new Or(e,t,()=>n));return n})(`DefaultAssistantClient`,()=>Dr),Ar=()=>new Proxy({},{get(e,t){let n=_e(t,`AssistantClient`);return n===!1?we(`The current scope does not have a "${String(t)}" property.`,String(t)):n}}),jr=pn(kr),Mr=()=>{},Nr=new WeakMap,Pr=e=>Nr.get(e)??Mr,Fr=(e,t)=>{Nr.set(e,t)},Ir=()=>hn(jr),Lr=(e,t)=>lt(jr,e,t),Rr=Symbol(`assistant-ui.transform-scopes`);function zr(e,t){let n=e;if(n[Rr])throw Error(`transformScopes is already attached to this resource`);n[Rr]=t}function Br(e){return e[Rr]}var Vr=e=>typeof e==`string`?{scope:e.split(`.`)[0],event:e}:{scope:e.scope,event:e.event},Hr=f.default.__COMPILER_RUNTIME?.c??(e=>(0,f.useMemo)(()=>{let t=_n(e);return t[gn]=!0,t},[])),Ur=()=>Le()!==null,G=e=>Ur()?yn(e):Hr(e),Wr=Symbol(`assistant-ui.store.clientIndex`),Gr=e=>e[Wr],Kr=pn([]),qr=()=>mn(Kr),Jr=(e,t)=>{let n=G(3),r=qr(),i;return n[0]!==e||n[1]!==r?(i=[...r,e],n[0]=e,n[1]=r,n[2]=i):i=n[2],lt(Kr,i,t)},Yr=pn(null),Xr=Symbol(`aui.scope-effect-unapplied`),Zr=(e,t)=>lt(Yr,e,t),Qr=()=>{let e=mn(Yr);if(!e)throw Error(`AssistantTapContext is not available`);return e},$r=()=>Qr().clientRef,ei=()=>mn(Yr)?.invalidate,ti=()=>mn(Yr)!==null,ni=()=>{let e=G(5),t=mn(Yr)?.markChanged,n;e[0]===t?n=e[1]:(n=t?{readers:new Set,version:0}:void 0,e[0]=t,e[1]=n);let r=n,i;return e[2]!==t||e[3]!==r?(i={signal:r,markChanged:t},e[2]=t,e[3]=r,e[4]=i):i=e[4],i},ri=(e,t,n,r)=>{let i=G(8),a;i[0]!==e||i[1]!==n||i[2]!==t?(a=()=>{if(e===void 0)return;let r=e.current;if(r===null)throw Error(`useAssistantScopeEffect ran before the client was committed. This is likely an internal bug in assistant-ui.`);let i=()=>{let n=e.current?.[t];return n!==void 0&&Ee(n)?ke(n):void 0},a=Xr,o,s=e=>{if(o?.(),o=void 0,a=Xr,e!==void 0){let e=n();o=typeof e==`function`?e:void 0}a=e};s(i());let c=r.subscribe(()=>{let e=i();e!==a&&s(e)});return()=>{c(),o?.()}},i[0]=e,i[1]=n,i[2]=t,i[3]=a):a=i[3];let o;i[4]!==e||i[5]!==r||i[6]!==t?(o=[e,t,...r],i[4]=e,i[5]=r,i[6]=t,i[7]=o):o=i[7],W(a,o)},ii=(e,t,n)=>{let{clientRef:r}=Qr();ri(r,e,t,n)},ai=()=>{let e=G(3),{emit:t}=Qr(),n=qr(),r;return e[0]!==n||e[1]!==t?(r=(e,r)=>{t(e,r,n)},e[0]=n,e[1]=t,e[2]=r):r=e[2],Xt(r)},oi=[],si=-1,ci=null,li=e=>{ci&&(e?ci.signals.includes(e)||(ci.signals.push(e),ci.versions.push(e.version)):ci.untracked=!0)},ui=e=>{si++;let t=oi[si]??={signals:[],versions:[],untracked:!1};t.signals.length=0,t.versions.length=0,t.untracked=!1;let n=ci;ci=t;try{return{value:e(),signals:[...t.signals],untracked:t.untracked}}finally{ci=n,si--,n&&(n.untracked||=t.untracked,t.signals.forEach(li))}},di=(e,t)=>e.length===t.length&&e.every(e=>t.includes(e)),fi=(e,t)=>{si++;let n=oi[si]??={signals:[],versions:[],untracked:!1};n.signals.length=0,n.versions.length=0,n.untracked=!1;let r=ci;ci=n;try{let r=e(),i=t.current;if(n.untracked||n.signals.length===0)t.current=null;else if(i&&di(i.signals,n.signals))for(let e=0;e<i.signals.length;e++)i.versions[e]=i.signals[e].version;else t.current={signals:[...n.signals],versions:[...n.versions]};return r}finally{ci=r,si--,r&&(r.untracked||=n.untracked,n.signals.forEach(li))}},pi=(e,t)=>{let n=U(null),r=U(null),i=ti(),a=Zt(qt(()=>t=>{let i,a,o=!1,s=()=>{let t=n.current,r=t?.signals??null;if(i!==void 0&&(i===null||r===null?i===r:di(i,r)))return!1;let o=!1;if(i)for(let e of i)r?.includes(e)||e.readers.delete(c);return t===null?a??=e(c):(a?.(),a=void 0,t.signals.forEach((e,n)=>{i?.includes(e)||(o||=e.version!==t.versions[n],e.readers.add(c))})),i=r&&[...r],o};function c(){o||(t(),s())}s();let l=()=>{s()&&t()};return r.current=l,()=>{if(o=!0,a?.(),i)for(let e of i)e.readers.delete(c);r.current===l&&(r.current=null)}},[e]),i?t:()=>fi(t,n),t);return W(()=>{r.current?.()}),a},mi=Symbol(`assistant-ui.store.getValue`),hi=Symbol(`assistant-ui.store.signal`),gi=e=>e[hi],_i=e=>{let t=qr().at(-1),n=t&&gi(t),r=ei();W(()=>{if(n&&r&&e)return e(()=>r(n))},[e,n,r])},vi=e=>{let t=e[mi];if(!t)throw Error(`Client scope contains a non-client resource. Ensure your Derived get() returns a client created with useClientResource(), not a plain resource.`);return li(gi(e)),t.getState?.()},yi=new Map;function bi(e){let t=yi.get(e);return t||(t=function(...t){if(!this||typeof this!=`object`)throw Error(`Method "${String(e)}" called without proper context. This may indicate the function was called incorrectly.`);let n=this[mi];if(!n)throw Error(`Method "${String(e)}" called on invalid client proxy. Ensure you are calling this method on a valid client instance.`);let r=n[e];if(!r)throw Error(`Method "${String(e)}" is not implemented.`);if(typeof r!=`function`)throw Error(`"${String(e)}" is not a function.`);return li(this[hi]),r(...t)},yi.set(e,t)),t}var xi=class extends ve{boundFns;cachedReceiver;outputRef;tagRef;index;signal;self;constructor(e,t,n,r){super(),this.outputRef=e,this.tagRef=t,this.index=n,this.signal=r}get(e,t,n){if(t===mi)return this.outputRef.current;if(t===hi)return this.signal;if(t===Wr)return this.index;if(t===ye)return this.self;if(t===be)return this.tagRef.current;let r=_e(t,`ClientProxy`);if(r!==!1)return r;let i=this.outputRef.current[t];if(typeof i==`function`){if(n===void 0)return i;this.boundFns&&this.cachedReceiver===n||(this.boundFns=new Map,this.cachedReceiver=n);let e=this.boundFns.get(t);return e||(e=bi(t).bind(n),this.boundFns.set(t,e)),e}return i}ownKeys(){return Object.keys(this.outputRef.current)}has(e,t){return t===mi||t===hi||t===Wr||t===ye||t===be||t in this.outputRef.current}},Si=class extends ve{targetRef;signal;constructor(e,t){super(),this.targetRef=e,this.signal=t}get(e,t){return t===hi?this.signal:(li(this.signal),this.targetRef.current[t])}ownKeys(){return li(this.signal),Reflect.ownKeys(this.targetRef.current)}has(e,t){return li(this.signal),t in this.targetRef.current}getOwnPropertyDescriptor(e,t){li(this.signal);let n=Reflect.getOwnPropertyDescriptor(this.targetRef.current,t)?.value;if(n!==void 0)return{value:n,writable:!1,enumerable:!0,configurable:!0}}},Ci=e=>{let t=U(e),{signal:n,markChanged:r}=ni(),i=qt(()=>{let e=new Si(t,n);return new Proxy({},e)},[n]);return W(()=>{t.current!==e&&(t.current=e,n&&r(n))},[r,n,e]),i},wi=e=>{let t=U(null),n=U(null),r=qt(()=>({}),[e.hook,e.key]),i=qr().length,{signal:a,markChanged:o}=ni(),s=qt(()=>{let e=new xi(t,n,i,a),r=new Proxy({},e);return e.self=r,r},[i,a]),c=Jr(s,function(){return vr(e)});return t.current||(t.current=c,n.current=r),W(()=>{let e=t.current!==c||n.current!==r;t.current=c,n.current=r,e&&a&&o(a)}),{methods:s,state:c.getState?.(),key:e.key}},Ti=hr(wi),Ei=0,Di=0,Oi=e=>{Ei++,Di++;try{return e()}finally{Di--,Ei++}},ki=e=>{let t,n=new Map,r=-1,i=t=>{if(Di===0)return vi(e[t]());if(r!==Ei)n.clear(),r=Ei;else{let e=n.get(t);if(e)return e.signals.forEach(li),e.untracked&&li(void 0),e.state}let{value:i,signals:a,untracked:o}=ui(()=>vi(e[t]()));return n.set(t,{state:i,signals:a,untracked:o}),i};class a extends ve{get(t,n){let r=_e(n,`OptionalAssistantState`);if(r!==!1)return r;let a=n;if(!Ae(a)&&Ee(e[a]))return i(a)}ownKeys(){return je(e)}has(t,n){return!Ae(n)&&n in e}}class o extends ve{get(e,n){let r=_e(n,`AssistantState`);if(r!==!1)return r;if(n===`optional`)return t??=new Proxy({},new a);let o=n;if(!Ae(o))return i(o)}ownKeys(){return[...je(e),`optional`]}has(t,n){return n===`optional`||!Ae(n)&&n in e}}return new Proxy({},new o)},Ai=new WeakMap,ji=e=>{let t=Ai.get(e);return t||(t=ki(e),Ai.set(e,t)),t},Mi=pn(void 0),Ni=(e,t)=>{let n=mn(Mi);return lt(Mi,e??n,t)},Pi=()=>mn(Mi),Fi=(e,t)=>{if(Array.isArray(e)!==Array.isArray(t))return!1;if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!Object.is(e[n],t[n]))return!1;return!0}let n=Object.keys(e);return n.length===Object.keys(t).length&&n.every(n=>Object.hasOwn(t,n)&&Object.is(e[n],t[n]))},Ii=Symbol(`assistant-ui.derived-hook`),Li=e=>{e[Ii]=!0},Ri=e=>e[Ii]===!0,zi=e=>{try{e()}catch(e){console.error(`NotificationManager: subscriber callback error`,e)}},Bi=e=>{console.error(`NotificationManager: event listener error`,e)},Vi=(e,t,n)=>{try{let r=e(t,n);r!==null&&(typeof r==`object`||typeof r==`function`)&&typeof r.then==`function`&&Promise.resolve(r).catch(Bi)}catch(e){Bi(e)}},Hi=()=>{let e=new Map,t=new Set,n=new Set,r=new Set;return{on(n,r){let i=r;if(n===`*`)return t.add(i),()=>t.delete(i);let a=e.get(n);return a||(a=new Set,e.set(n,a)),a.add(i),()=>{a.delete(i),a.size===0&&e.get(n)===a&&e.delete(n)}},emit(n,r,i){(e.has(n)||t.size!==0)&&queueMicrotask(()=>{let a=e.get(n);if(a)for(let e of a)Vi(e,r,i);if(t.size>0){let e={event:n,payload:r};for(let n of t)Vi(n,e,i)}})},subscribe(e){return n.add(e),()=>n.delete(e)},markChanged(e){e.version++,r.add(e)},invalidate(e){e.version++,Oi(()=>{for(let t of[...e.readers])zi(t)})},notifySubscribers(){Oi(()=>{for(let e of n)zi(e);if(r.size===0)return;let e=new Set;for(let t of r)for(let n of t.readers)e.add(n);r.clear();for(let t of e)zi(t)})}}},Ui=()=>H(Hi)[0],Wi=()=>{let[e]=H(()=>({controller:new AbortController,generation:0}));return $t(()=>{let t=++e.generation;return()=>queueMicrotask(()=>{e.generation===t&&e.controller.abort()})},[e]),e.controller.signal},Gi=e=>{let t=qt(()=>({}),[]);return t.v!==void 0&&Fi(t.v,e)?t.v:(t.v=e,e)},Ki=e=>{let t=G(2),n=U(void 0),r;return t[0]===e?r=t[1]:(r=t=>{let r=e(t);return n.current!==void 0&&Fi(n.current,r)?n.current:(n.current=r,r)},t[0]=e,t[1]=r),r},qi=(()=>{try{return process.env.NODE_ENV===`development`||process.env.NODE_ENV===`test`}catch{return!1}})(),Ji=(e,t)=>{let n={...e},r=new Set,i=!0;for(;i;){i=!1;for(let e of Object.values(n)){if(r.has(e.hook))continue;r.add(e.hook);let a=Br(e.hook);if(a){a(n,t),i=!0;break}}}return n},Yi=e=>Ri(e.hook),Xi=e=>{if(!Yi(e))return{source:`root`,query:{}};let t=e.args[0];return{source:t.source,query:t.query??{}}},Zi=Symbol.for(`aui.event-receiver-ref`),Qi=(e,t)=>{let n=e===kr?Ar():e,r=Object.create(n);Object.assign(r,t);let i;return Object.defineProperty(r,"optional",{get:()=>i??=Ne(r),enumerable:!1}),r},$i=({notifications:e,clientRef:t})=>qt(()=>({subscribe:e.subscribe,on:function(n,r){if(!this)throw Error(`const { on } = useAui() is not supported. Use aui.on() instead.`);let{scope:i,event:a}=Vr(n),o=n[Zi];if(i!==`*`&&!o&&De(this[i]))throw Error(`Scope "${i}" is not available. Use { scope: "*", event: "${a}" } to listen globally.`);let s=e.on(a,(e,n)=>{if(i===`*`)return r(e);let a=((o??t).current??this)[i];if(!Ee(a))return;let s=Oe(a);if(s===n[Gr(s)])return r(e)});if(i!==`*`){if(o){if(t.parent===kr)return s}else if(De(t.parent[i]))return s}let c=t.parent.on(n,r);return()=>{s(),c()}}}),[e,t]),ea=e=>{let t=G(5),n;t[0]===e?n=t[1]:(n=Xi(e),t[0]=e,t[1]=n);let{source:r,query:i}=n,a=Gi(i),o;return t[2]!==r||t[3]!==a?(o={source:r,query:a},t[2]=r,t[3]=a,t[4]=o):o=t[4],Gi(o)},ta=e=>Te(e)?()=>(li(void 0),e):()=>e,na=(e,t)=>{let n=G(3),r;return n[0]!==t||n[1]!==e?(r=t?e:Ti(e),n[0]=t,n[1]=e,n[2]=r):r=n[2],vr(r)},ra=hr((e,t)=>{let n=Ir(),r=Yi(t),i=na(t,r),a=r?i:i.methods,o=ea(t),s=qt(()=>Ce({name:e,...o},ta(a)),[e,o,a]);return n[e]=s,s}),ia=e=>{let t=G(2),n;return t[0]===e?n=t[1]:(n=e.map(ma),t[0]=e,t[1]=n),Cr(n)},aa=(e,t)=>{let n=Gi(t),r=qt(()=>({}),[]);return r.deps!==n&&(r.deps=n,r.client=e),r.client},oa=({parent:e,entries:t,clientRef:n,notifications:r})=>{let i=Qi(e,$i({notifications:r,clientRef:n}));return{client:aa(i,[e,...Zr(qt(()=>({clientRef:n,emit:r.emit,markChanged:r.markChanged,invalidate:r.invalidate}),[n,r.emit,r.markChanged,r.invalidate]),function(){return Lr(i,function(){return ia(t)})})])}},sa=({parent:e,entries:t,destroySignal:n})=>{let r=U({parent:e,current:null}).current,{value:i,effects:a}=Tr(function(){let i=Ui(),{client:a}=Ni(n,function(){return oa({parent:e,entries:t,clientRef:r,notifications:i})});return W(()=>e.subscribe(i.notifySubscribers),[e,i]),W(()=>i.notifySubscribers()),a});return $t(()=>{r.parent=e,r.current=i},[i,e,r]),{client:i,effects:a}},ca=({parent:e,entries:t,destroySignal:n})=>{let r=U({parent:e,current:null}).current,{value:i,effects:a}=Tr(function(){let i=Ui(),a=pr(function(){return Ni(n,function(){return oa({parent:e,entries:t,clientRef:r,notifications:i})})}),o=Zt(a.subscribe,()=>a.getValue().client,()=>a.getValue().client);return W(()=>{let t=()=>Mn(()=>{r.current=a.getValue().client,i.notifySubscribers()}),n=a.subscribe(t),o=e.subscribe(t);return()=>{n(),o()}},[a,e,i]),o});return $t(()=>{r.parent=e,r.current=i},[i,e,r]),{client:i,effects:a}},la=(e,t,n,r)=>{let{get:i}=r.args[0],a=pi(e.subscribe,()=>i(e)),o=ea(r),s=qt(()=>Ce({name:n,...o},ta(a)),[n,o,a]);return t[n]=s,s},ua=(e,t)=>{if(qi){let[e]=H(()=>t.map(([e])=>e).join(`,`)),n=t.find(([,e])=>!Yi(e));if(n)throw Error(`Scope "${n[0]}" is a root scope but this useAui mounted derived-only; remount with a new key to change scope kinds.`);let r=t.map(([e])=>e).join(`,`);if(r!==e)throw Error(`A derived-only config mounted scopes [${e}] but now has [${r}]; remount with a new key to change the scope set.`)}let n=U({parent:e,current:null}).current,r=Qi(e,{subscribe:e.subscribe,on:function(t,r){if(!this)throw Error(`const { on } = useAui() is not supported. Use aui.on() instead.`);let{scope:i,event:a}=Vr(t);if(i===`*`)return e.on(t,r);let o=t[Zi];if(!o&&De(this[i]))throw Error(`Scope "${i}" is not available. Use { scope: "*", event: "${a}" } to listen globally.`);return e.on({scope:i,event:a,[Zi]:o??n},r)}}),i=aa(r,[e,...t.map(([t,n])=>la(e,r,t,n))]);return $t(()=>{n.parent=e,n.current=i},[i,e,n]),i},da=(e,t)=>{let n=G(8),r;n[0]!==t||n[1]!==e?(r=Object.entries(Ji(t,e)),n[0]=t,n[1]=e,n[2]=r):r=n[2];let i=r,a;n[3]===i?a=n[4]:(a=()=>i.length===0||i.some(ha),n[3]=i,n[4]=a);let[o]=H(a),s;return n[5]!==i||n[6]!==o?(s={entries:i,rooted:o},n[5]=i,n[6]=o,n[7]=s):s=n[7],s},fa=(e,t,n,r)=>{let{entries:i,rooted:a}=da(e,t);return a?n({parent:e,entries:i,destroySignal:r}):{client:ua(e,i)}},pa=(e,t,n)=>fa(e,t,sa,n);function K(e){let t=Ir();if(e){let{client:n,effects:r}=fa(t,e,ca,Wi());return r&&Fr(n,r),n}return t}function ma(e){let[t,n]=e;return gr(t,ra(t,n))}function ha(e){let[,t]=e;return!Yi(t)}var q=e=>{let t=G(5),n=K(),r;t[0]===n?r=t[1]:(r=ji(n),t[0]=n,t[1]=r);let i=r,a;t[2]!==i||t[3]!==e?(a=()=>e(i),t[2]=i,t[3]=e,t[4]=a):a=t[4];let o=pi(n.subscribe,a);if(typeof o==`object`&&o&&(o===i||o===i.optional))throw Error(`You tried to return the entire AssistantState. This is not supported due to technical limitations.`);return Qt(o),o},ga=e=>{let t=G(3),{get:n}=e,r=K(),i;return t[0]!==r||t[1]!==n?(i=()=>n(r),t[0]=r,t[1]=n,t[2]=i):i=t[2],q(i)};Li(ga);var _a=hr(ga),va=e=>typeof e.getConfig==`function`,ya=()=>()=>{},ba=e=>{if(!va(e))return{getConfig:()=>e,subscribe:ya};let t=null;return{getConfig:()=>(t??={value:e.getConfig()}).value,subscribe:n=>(t=null,e.subscribe(()=>{t=null,n()}))}},xa=e=>typeof e.getClient==`function`&&!(`on`in e),Sa=e=>xa(e)?e:{getClient:()=>e,subscribe:e.subscribe},Ca=new WeakMap,wa=(e,t)=>{let n=Sa(t?.parent??kr),r=ba(e),i={parent:n.getClient(),current:null},a=new AbortController,o=Hi(),s=Ca.get(n),c=()=>s?.()??n.getClient(),l,u,d=null,f=()=>mr(function(){let[,e]=Kt(e=>e+1,0),t=c();$t(()=>{d=e,l=t});let s=Zt(n.subscribe,n.getClient,n.getClient),u=Zt(r.subscribe,r.getConfig,r.getConfig),f=Object.entries(Ji(u,s)),p=Ni(a.signal,function(){return oa({parent:s,entries:f,clientRef:i,notifications:o})});return i.current===null&&(i.current=p.client),p},{mountOnSubscribe:!0}),p=f(),m=()=>{i.parent=n.getClient(),i.current=p.getValue().client,u=c(),Mn(o.notifySubscribers)},h=!1,g=!1,_=(e=!1)=>{if(!e&&Object.is(l,c()))return!1;if(!h)p.unmount(),i.current=null,p=f(),p.getValue(),l=c();else{g=!0;try{Mn(()=>d?.())}finally{g=!1}}return!0},v=()=>{let e=h&&t?.parent!==void 0&&!s&&!g;g=!1,_(e)||m()},y=()=>{_(!s)||s&&Object.is(u,c())||m()},b=0,x=null,S=!1,C=()=>{let e=n.subscribe(y),t;try{t=p.subscribe(v),h=!0}catch(t){throw e(),t}i.parent=n.getClient(),i.current=p.getValue().client,x=()=>{x=null,t(),e()}},w=()=>{x?.(),p.unmount()},T={getClient:()=>(p.getValue(),!h&&l===void 0&&(l=c()),_(),p.getValue().client),subscribe:e=>{if(S)return()=>{};let t=o.subscribe(e);if(b++===0){try{C()}catch(e){throw b--,t(),e}S&&w()}let n=!0;return()=>{n&&(n=!1,t(),--b===0&&x?.())}},destroy:()=>{S||(S=!0,a.abort(),b>0&&x===null||w())}};return Ca.set(T,()=>p.getValue()),T},Ta=e=>{if(e.key===void 0)throw Error(`useClientLookup: Element has no key`);return e.key};function Ea(e){let t=G(12),n;t[0]===e?n=t[1]:(n=e.map(ka),t[0]=e,t[1]=n);let r=Cr(n),i;t[2]===e?i=t[3]:(i=e.reduce(Oa,Object.create(null)),t[2]=e,t[3]=i);let a=i,o;t[4]===r?o=t[5]:(o=r.map(Da),t[4]=r,t[5]=o);let s=o,c;t[6]!==a||t[7]!==r?(c=e=>{if(`index`in e){if(e.index<0||e.index>=r.length)throw Error(`useClientLookup: index ${e.index} out of bounds (length: ${r.length}) (ignore if recovered)`);return r[e.index].methods}let t=a[e.key];if(t===void 0)throw Error(`useClientLookup: key "${e.key}" not found (ignore if recovered)`);return r[t].methods},t[6]=a,t[7]=r,t[8]=c):c=t[8];let l;return t[9]!==s||t[10]!==c?(l={state:s,get:c},t[9]=s,t[10]=c,t[11]=l):l=t[11],l}function Da(e){return e.state}function Oa(e,t,n){return e[Ta(t)]=n,e}function ka(e){return gr(Ta(e),Ti(e),e.deps)}var Aa=e=>new Proxy({},{get:(t,n)=>Reflect.get(e.getClient(),n),has:(t,n)=>n in e.getClient(),ownKeys:()=>{let t=e.getClient(),n=new Set(Reflect.ownKeys(t));for(let e in t)n.add(e);return[...n]},getOwnPropertyDescriptor:(t,n)=>{let r=e.getClient();if(n in r)return{configurable:!0,enumerable:!0,value:Reflect.get(r,n)}}}),ja=(e,t=0)=>t===0?Math.abs(e.scrollHeight-e.scrollTop-e.clientHeight)<=1||e.scrollHeight<=e.clientHeight:e.scrollHeight-t-e.scrollTop-e.clientHeight<=1||e.scrollHeight-t<=e.clientHeight,Ma=(e,t=0)=>t===0?e.scrollHeight>e.clientHeight+1:e.scrollHeight-t>e.clientHeight+1,Na=e=>e.nodeType===Node.ELEMENT_NODE,Pa=(e,t)=>{let n=[],r=typeof ResizeObserver<`u`?new ResizeObserver(()=>t()):null;if(r){r.observe(e);for(let t of e.children)r.observe(t);n.push(()=>r.disconnect())}if(typeof MutationObserver<`u`){let i=new MutationObserver(n=>{if(r){for(let t of n)if(t.target===e){for(let e of t.addedNodes)Na(e)&&r.observe(e);for(let e of t.removedNodes)Na(e)&&r.unobserve(e)}}n.some(e=>e.type!==`attributes`||e.attributeName!==`style`)&&t()});i.observe(e,{childList:!0,subtree:!0,attributes:!0,characterData:!0}),n.push(()=>i.disconnect())}return()=>{for(let e of n)e()}},Fa=`[data-message-id]`,Ia=`[aria-expanded], summary`,La=`textarea, select, [contenteditable]:not([contenteditable='false']), input:not([type='checkbox']):not([type='radio']):not([type='button']):not([type='submit']):not([type='reset']):not([type='image']):not([type='range']):not([type='file']):not([type='color'])`,Ra=new Set([` `,`ArrowUp`,`ArrowDown`,`PageUp`,`PageDown`,`Home`,`End`]),za=e=>{let t=e.closest(Ia);if(!t)return!1;if(t.tagName===`SUMMARY`)return t.parentElement?.hasAttribute(`open`)===!1;let n=t.getAttribute(`aria-haspopup`);return t.getAttribute(`aria-expanded`)===`false`&&(n===null||n===`false`)&&t.getAttribute(`role`)!==`combobox`},Ba=(e,t)=>e.getBoundingClientRect().top-t.getBoundingClientRect().top,Va=e=>{let t=e.querySelector(Fa),n=t?.dataset.messageId;return t&&n?{id:n,offset:Ba(t,e)}:null},Ha=e=>{let{top:t,bottom:n}=e.getBoundingClientRect(),r=null;for(let i of e.querySelectorAll(Fa)){let e=i.getBoundingClientRect();if(e.bottom<=t)continue;if(e.top>=n)break;let a=i.dataset.messageId;if(a){if(e.top>=t)return{id:a,offset:e.top-t};r??={id:a,offset:e.top-t}}}return r},Ua=(e,t)=>{for(let n of e.querySelectorAll(Fa))if(n.dataset.messageId===t)return n;return null},Wa=e=>{let t=null,n=null,r=null,i=!0,a=!0,o=!1,s=!1,c=0,l=0,u=new Map,d=!1,f=!1,p=0,m=0,h=0,g=0,_=null,v=null,y=null,b=0,x=e=>{if(!t)return!1;let n=Ua(t,e.id);if(!n)return!1;let r=Ba(n,t)-e.offset;return b=t.scrollTop+r,Math.abs(r)>=1&&t.scrollTo({top:b,behavior:`instant`}),b=t.scrollTop,!0},S=t=>{t!==i&&(i=t,e.onAtBottomChange(t))},C=()=>{_!==null&&(cancelAnimationFrame(_),_=null)},w=(e=`auto`)=>{t&&(a=!0,o=!1,s=!1,r=e,y=null,t.scrollTo?.({top:t.scrollHeight,behavior:e}),p=t.scrollTop,m=t.scrollHeight)},T=e=>{r=e,typeof requestAnimationFrame<`u`&&(C(),_=requestAnimationFrame(()=>{_=null,w(e)}))},E=({preserveFollow:n=!1,insetShrank:i=!1}={})=>{if(!t)return;y&&Math.abs(t.scrollTop-b)>=1&&(y=null);let{autoScroll:l,holdFollow:u}=e.getOptions(),d=ja(t,c),f=t.scrollTop<p&&t.scrollHeight>=m;u||d||l&&(n||r!==null||o||!f&&!i)||(a=!1),r!==null&&!d&&p<t.scrollTop||(d?(Ma(t,c)&&(r=null,o&&s&&(o=!1),s=!1),a=!0):f&&(r=null,C(),a=!1),(d||r===null)&&S(d)),p=t.scrollTop,m=t.scrollHeight,v=Va(t)},D=()=>E(),O=()=>{if(_!==null)return;let{autoScroll:t,holdFollow:n}=e.getOptions();r&&n?r=null:r?w(r):!n&&t&&a&&!o?w(`instant`):y&&!x(y)&&(y=null)},k=()=>{if(!t)return;let{scrollHeight:e,clientHeight:n}=t;(e!==h||n!==g)&&(h=e,g=n,O(),E())},A=()=>{(r!==null||_!==null)&&(r=null,C(),E({preserveFollow:!0}))},j=e=>{e.key!==`Enter`&&!Ra.has(e.key)||e.target?.closest?.(La)||A()},M=e=>{let t=e.target;t?.closest?.(Fa)&&!t.closest(La)&&za(t)&&(o=!0,s=!1,r=null,C())},N=e=>{if(e.type===`keydown`){let t=e;if(!Ra.has(t.key)||e.target?.closest?.(La))return}else if(e.type===`pointerdown`&&e.target!==t)return;s=!0},P=()=>{y=null},F=()=>{d?e.getOptions().scrollToBottomOnInitialize&&!f&&(f=!0,r===null&&T(`instant`)):f=!1},I=()=>{let t=l;for(let e of u.values())t+=e;if(c===t)return;let n=t>c;c=t,e.onContentInsetChange?.(t),n&&O(),E({insetShrank:!n})};return{attach:e=>{n?.(),t=e,r=null,p=e.scrollTop,m=e.scrollHeight,h=0,g=0,f=!1,a=!0,o=!1,s=!1,v=null,y=null,b=e.scrollTop,S(!0);let i=Pa(e,k);e.addEventListener(`scroll`,D),e.addEventListener(`pointerdown`,A),e.addEventListener(`wheel`,A,{passive:!0}),e.addEventListener(`touchstart`,A,{passive:!0}),e.addEventListener(`keydown`,j),e.addEventListener(`click`,M,!0);for(let t of[`pointerdown`,`wheel`,`touchmove`,`keydown`])e.addEventListener(t,N,{passive:!0});for(let t of[`pointerdown`,`wheel`,`touchstart`,`keydown`])e.addEventListener(t,P,{passive:!0});F(),c>0&&O();let l=()=>{if(n===l){i(),e.removeEventListener(`scroll`,D),e.removeEventListener(`pointerdown`,A),e.removeEventListener(`wheel`,A),e.removeEventListener(`touchstart`,A),e.removeEventListener(`keydown`,j),e.removeEventListener(`click`,M,!0);for(let t of[`pointerdown`,`wheel`,`touchmove`,`keydown`])e.removeEventListener(t,N);for(let t of[`pointerdown`,`wheel`,`touchstart`,`keydown`])e.removeEventListener(t,P);C(),t===e&&(t=null),n=null}};return n=l,l},get isAtBottom(){return i},scrollToBottom:w,messagesPrepended:n=>{if(!t||e.getOptions().autoScroll&&a&&!o||r!==null)return;let i=v;if(i?.id===n&&x(i))y=Ha(t)??i;else{let e=t.scrollHeight-(m-p);Math.abs(t.scrollTop-e)>=1&&t.scrollTo({top:e,behavior:`instant`})}p=t.scrollTop,m=t.scrollHeight},setContentInset:e=>{l!==e&&(l=e,I())},registerContentInset:()=>{let e=Symbol();return u.set(e,0),{setHeight:t=>{u.has(e)&&u.get(e)!==t&&(u.set(e,t),I())},unregister:()=>{u.delete(e)&&I()}}},setHasMessages:e=>{d=e,F()},runStarted:()=>{y=null,o=!1,s=!1,e.getOptions().scrollToBottomOnRunStart&&T(`auto`)},threadSwitched:()=>{y=null,o=!1,s=!1,e.getOptions().scrollToBottomOnThreadSwitch&&T(`instant`)},dispose:()=>{n?.(),C()}}},Ga=Symbol(`skip-update`),Ka=(e,...t)=>{let n=[];for(let r of e)try{r(...t)}catch(e){n.push(e)}if(n.length===1)throw n[0];if(n.length>1){for(let e of n)console.error(e);throw AggregateError(n)}},qa=e=>{Ka(e)},Ja=(e,t)=>{try{e()}catch(e){console.error(`[assistant-ui] Subscription rollback cleanup threw`,e)}throw t},Ya=(e,t)=>e===void 0||t===void 0?e===t:Fi(e,t),Xa=class{_subscribers=new Set;subscribe(e){return this._subscribers.add(e),()=>this._subscribers.delete(e)}waitForUpdate(){return new Promise(e=>{let t=this.subscribe(()=>{t(),e()})})}_notifySubscribers(){Ka(this._subscribers)}},Za=class extends Xa{_state;constructor(e){super(),this._state=e,this.subscribe=this.subscribe.bind(this),this.getState=this.getState.bind(this),this.getServerSnapshot=()=>e}getState(){return this._state}getServerSnapshot;setState(e){Object.is(e,this._state)||(this._state=e,this._notifySubscribers())}},Qa=class{_subscriptions=new Set;_connection;get isConnected(){return!!this._connection}notifySubscribers(e,t){t?w(this._subscriptions,e,t):Ka(this._subscriptions,e)}_updateConnection(){if(this._subscriptions.size>0){if(this._connection)return;this._connection=this._connect()}else{let e=this._connection;this._connection=void 0,e?.()}}subscribe(e){this._subscriptions.add(e);try{this._updateConnection()}catch(t){throw this._subscriptions.delete(e),t}return()=>{this._subscriptions.delete(e),this._updateConnection()}}},$a=class extends Qa{get path(){return this.binding.path}binding;constructor(e){super(),this.binding=e;let t=e.getState();if(t===Ga)throw Error(`Entry not available in the store`);this._previousState=t}_previousState;getState=()=>(this.isConnected||this._syncState(),this._previousState);_syncState(){let e=this.binding.getState();return e===Ga||Ya(e,this._previousState)?!1:(this._previousState=e,!0)}_connect(){let e=this.binding.subscribe(()=>{this._syncState()&&this.notifySubscribers()});try{return this._syncState(),e}catch(t){throw Ja(e,t)}}},eo=class extends Qa{get path(){return this.binding.path}binding;constructor(e){super(),this.binding=e}_previousStateDirty=!0;_previousState;getState=()=>{if(!this.isConnected||this._previousStateDirty){let e=this.binding.getState();e===Ga||this._previousState!==void 0&&Ya(e,this._previousState)||(this._previousState=e),this._previousStateDirty=!1}if(this._previousState===void 0)throw Error(`Entry not available in the store`);return this._previousState};_connect(){let e=this.binding.subscribe(()=>{this._previousStateDirty=!0,this.notifySubscribers()});return this._previousStateDirty=!0,e}},to=class extends Qa{get path(){return this.binding.path}binding;constructor(e){super(),this.binding=e}getState(){return this.binding.getState()}outerSubscribe(e){return this.binding.subscribe(e)}_connect(){let e=()=>{this.notifySubscribers()},t=this.binding.getState(),n=t?.subscribe(e),r=()=>{let r=this.binding.getState();if(r===t)return;t=r;let i=n;n=void 0;try{i?.()}finally{n=r?.subscribe(e),e()}},i;try{i=this.outerSubscribe(r)}catch(e){throw Ja(()=>n?.(),e)}return()=>qa([()=>i(),()=>n?.()])}},no=class extends Qa{config;constructor(e){super(),this.config=e}getState(){return this.config.binding.getState()}outerSubscribe(e){return this.config.binding.subscribe(e)}_connect(){let e=`Runtime event "${this.config.event}"`,t=t=>{this.notifySubscribers(t,e)},n=this.config.binding.getState(),r=n?.unstable_on(this.config.event,t),i=()=>{let e=this.config.binding.getState();if(e===n)return;n=e;let i=r;r=void 0;try{i?.()}finally{r=e?.unstable_on(this.config.event,t),this.config.notifyOnRebind&&t({})}},a;try{a=this.outerSubscribe(i)}catch(e){throw Ja(()=>r?.(),e)}return()=>qa([()=>a(),()=>r?.()])}},ro=class{_providers=new Map;_providerUnsubscribes=new Map;_getMergeOptions;constructor(e=()=>({})){this._getMergeOptions=e}getModelContext(){return F(new Set(this._providers.values()),this._getMergeOptions())}registerModelContextProvider(e){let t=Symbol();this._providers.set(t,e);let n;try{n=e.subscribe?.(()=>{this.notifySubscribers()})}catch(e){this._providers.delete(t);try{this.notifySubscribers()}catch(e){console.error(e)}throw e}this._providerUnsubscribes.set(t,n),this.notifySubscribers();let r=!1;return()=>{if(r)return;r=!0,this._providers.delete(t);let e=this._providerUnsubscribes.get(t);this._providerUnsubscribes.delete(t);let n=!1,i,a=e=>{try{e()}catch(e){n?console.error(e):(n=!0,i=e)}};if(e&&a(e),a(()=>this.notifySubscribers()),n)throw i}}_subscribers=new Set;notifySubscribers(){Ka(this._subscribers)}subscribe(e){return this._subscribers.add(e),()=>{this._subscribers.delete(e)}}},io=(e,t=`The operation was aborted`)=>{if(e.reason!==void 0)return e.reason;let n=Error(t);return n.name=`AbortError`,n},ao=(e,t)=>{if(!e)try{return Promise.resolve(t())}catch(e){return Promise.reject(e)}return e.aborted?Promise.reject(io(e)):new Promise((n,r)=>{let i=!1,a=()=>e.removeEventListener(`abort`,c),o=e=>{i||(i=!0,a(),n(e))},s=e=>{i||(i=!0,a(),r(e))},c=()=>s(io(e));e.addEventListener(`abort`,c,{once:!0});let l;try{l=t()}catch(e){s(e);return}Promise.resolve(l).then(o,s)})},oo=((e,t=21)=>(n=t)=>{let r=``,i=n|0;for(;i-->0;)r+=e[Math.random()*e.length|0];return r})(`0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz`,7),so=new Set([`__proto__`,`constructor`,`prototype`]);function co(e){if(so.has(e))throw Error(`Unsafe gorp path segment: ${e}`)}var lo=class{_state;_strict;_logged=new Set;_warnedClamp=!1;constructor(e=null,t={}){this._state=e,this._strict=t.strict??!0}get state(){return this._state}logOnce(e,t){this._logged.has(e)||this._logged.size>=20||(this._logged.add(e),t())}append(e){this._state=e.reduce((e,t)=>{if(this._strict)return this.apply(e,t);try{return this.apply(e,t)}catch(n){return this.logOnce(`skip:${String(n)}`,()=>console.error(`Skipped unappliable gorp operation: ${String(n)}`,t)),e}},this._state)}apply(e,t){let n=t.type;switch(n){case`set`:return this.updatePath(e,t.path,()=>t.value);case`append-text`:return this.updatePath(e,t.path,e=>{if(typeof e!=`string`)throw Error(`Expected string at path [${t.path.join(`, `)}]`);return e+t.value});default:throw Error(`Invalid operation type: ${n}`)}}updatePath(e,t,n){if(t.length===0)return n(e);let r=[],i=e;for(let e=0;e<t.length;e++){if(i??={},typeof i!=`object`)throw Error(`Invalid path: [${t.slice(e).join(`, `)}]`);let n=t[e];if(co(n),Array.isArray(i)){let a=Number(n);if(!Number.isInteger(a)||String(a)!==String(n))throw Error(`Expected array index at [${t.slice(e).join(`, `)}]`);if(a<0)throw Error(`Insert array index out of bounds`);if(a>i.length){if(this._strict)throw Error(`Insert array index out of bounds`);this._warnedClamp||(this._warnedClamp=!0,console.warn(`Clamped out-of-bounds gorp array index ${a} to ${i.length}`)),a=i.length}r.push({kind:`array`,state:i,key:a}),i=Object.hasOwn(i,a)?i[a]:void 0}else{let e=i;r.push({kind:`object`,state:e,key:n}),i=Object.hasOwn(e,n)?e[n]:void 0}}let a=n(i);for(let e=r.length-1;e>=0;e--){let t=r[e];if(t.kind===`array`){let e=[...t.state];e[t.key]=a,a=e}else{let e={...t.state};e[t.key]=a,a=e}}return a}},uo=/[0-9a-fA-F]/;function fo(e){let t=[`ROOT`],n=-1,r=null,i=0,a=[],o;function s(){o!==void 0&&(a.push(JSON.parse(`"${o}"`)),o=void 0)}function c(e,i,a){switch(e){case`"`:n=i,t.pop(),t.push(a),t.push(`INSIDE_STRING`),s();break;case`f`:case`t`:case`n`:n=i,r=i,t.pop(),t.push(a),t.push(`INSIDE_LITERAL`);break;case`-`:t.pop(),t.push(a),t.push(`INSIDE_NUMBER`),s();break;case`0`:case`1`:case`2`:case`3`:case`4`:case`5`:case`6`:case`7`:case`8`:case`9`:n=i,t.pop(),t.push(a),t.push(`INSIDE_NUMBER`),s();break;case`{`:n=i,t.pop(),t.push(a),t.push(`INSIDE_OBJECT_START`),s();break;case`[`:n=i,t.pop(),t.push(a),t.push(`INSIDE_ARRAY_START`),s()}}function l(e,r){switch(e){case`,`:t.pop(),t.push(`INSIDE_OBJECT_AFTER_COMMA`);break;case`}`:n=r,t.pop(),o=a.pop()}}function u(e,r){switch(e){case`,`:t.pop(),t.push(`INSIDE_ARRAY_AFTER_COMMA`),o=(Number(o)+1).toString();break;case`]`:n=r,t.pop(),o=a.pop()}}for(let s=0;s<e.length;s++){let d=e[s];switch(t[t.length-1]){case`ROOT`:c(d,s,`FINISH`);break;case`INSIDE_OBJECT_START`:switch(d){case`"`:t.pop(),t.push(`INSIDE_OBJECT_KEY`),o=``;break;case`}`:n=s,t.pop(),o=a.pop()}break;case`INSIDE_OBJECT_AFTER_COMMA`:d===`"`&&(t.pop(),t.push(`INSIDE_OBJECT_KEY`),o=``);break;case`INSIDE_OBJECT_KEY`:switch(d){case`"`:t.pop(),t.push(`INSIDE_OBJECT_AFTER_KEY`);break;case`\\`:t.push(`INSIDE_STRING_ESCAPE`),o+=d;break;default:o+=d}break;case`INSIDE_OBJECT_AFTER_KEY`:d===`:`&&(t.pop(),t.push(`INSIDE_OBJECT_BEFORE_VALUE`));break;case`INSIDE_OBJECT_BEFORE_VALUE`:c(d,s,`INSIDE_OBJECT_AFTER_VALUE`);break;case`INSIDE_OBJECT_AFTER_VALUE`:l(d,s);break;case`INSIDE_STRING`:switch(d){case`"`:t.pop(),n=s,o=a.pop();break;case`\\`:t.push(`INSIDE_STRING_ESCAPE`);break;default:n=s}break;case`INSIDE_ARRAY_START`:switch(d){case`]`:n=s,t.pop(),o=a.pop();break;default:o=`0`,c(d,s,`INSIDE_ARRAY_AFTER_VALUE`)}break;case`INSIDE_ARRAY_AFTER_VALUE`:switch(d){case`,`:t.pop(),t.push(`INSIDE_ARRAY_AFTER_COMMA`),o=(Number(o)+1).toString();break;case`]`:n=s,t.pop(),o=a.pop();break;default:n=s}break;case`INSIDE_ARRAY_AFTER_COMMA`:c(d,s,`INSIDE_ARRAY_AFTER_VALUE`);break;case`INSIDE_STRING_ESCAPE`:{t.pop();let e=t[t.length-1];d===`u`?(t.push(`INSIDE_STRING_UNICODE_ESCAPE`),i=0):e===`INSIDE_STRING`&&(n=s),e===`INSIDE_OBJECT_KEY`&&(o+=d);break}case`INSIDE_STRING_UNICODE_ESCAPE`:{let e=t[t.length-2];if(!uo.test(d)){t.pop(),s--;break}i++,i===4&&(t.pop(),e===`INSIDE_STRING`&&(n=s)),e===`INSIDE_OBJECT_KEY`&&(o+=d);break}case`INSIDE_NUMBER`:switch(d){case`0`:case`1`:case`2`:case`3`:case`4`:case`5`:case`6`:case`7`:case`8`:case`9`:n=s;break;case`e`:case`E`:case`-`:case`+`:case`.`:break;case`,`:t.pop(),o=a.pop(),t[t.length-1]===`INSIDE_ARRAY_AFTER_VALUE`&&u(d,s),t[t.length-1]===`INSIDE_OBJECT_AFTER_VALUE`&&l(d,s);break;case`}`:t.pop(),o=a.pop(),t[t.length-1]===`INSIDE_OBJECT_AFTER_VALUE`&&l(d,s);break;case`]`:t.pop(),o=a.pop(),t[t.length-1]===`INSIDE_ARRAY_AFTER_VALUE`&&u(d,s);break;default:t.pop(),o=a.pop()}break;case`INSIDE_LITERAL`:{let i=e.substring(r,s+1);!`false`.startsWith(i)&&!`true`.startsWith(i)&&!`null`.startsWith(i)?(t.pop(),t[t.length-1]===`INSIDE_OBJECT_AFTER_VALUE`?l(d,s):t[t.length-1]===`INSIDE_ARRAY_AFTER_VALUE`&&u(d,s)):n=s;break}}}let d=e.slice(0,n+1);for(let n=t.length-1;n>=0;n--)switch(t[n]){case`INSIDE_STRING`:d+=`"`;break;case`INSIDE_OBJECT_KEY`:case`INSIDE_OBJECT_AFTER_KEY`:case`INSIDE_OBJECT_AFTER_COMMA`:case`INSIDE_OBJECT_START`:case`INSIDE_OBJECT_BEFORE_VALUE`:case`INSIDE_OBJECT_AFTER_VALUE`:d+=`}`;break;case`INSIDE_ARRAY_START`:case`INSIDE_ARRAY_AFTER_COMMA`:case`INSIDE_ARRAY_AFTER_VALUE`:d+=`]`;break;case`INSIDE_LITERAL`:{let t=e.substring(r,e.length);`true`.startsWith(t)?d+=`true`.slice(t.length):`false`.startsWith(t)?d+=`false`.slice(t.length):`null`.startsWith(t)&&(d+=`null`.slice(t.length))}}return[d,a]}var po=u(o(((e,t)=>{var n=typeof Buffer<`u`,r=/"(?:_|\\u005[Ff])(?:_|\\u005[Ff])(?:p|\\u0070)(?:r|\\u0072)(?:o|\\u006[Ff])(?:t|\\u0074)(?:o|\\u006[Ff])(?:_|\\u005[Ff])(?:_|\\u005[Ff])"\s*:/,i=/"(?:c|\\u0063)(?:o|\\u006[Ff])(?:n|\\u006[Ee])(?:s|\\u0073)(?:t|\\u0074)(?:r|\\u0072)(?:u|\\u0075)(?:c|\\u0063)(?:t|\\u0074)(?:o|\\u006[Ff])(?:r|\\u0072)"\s*:/;function a(e,t,a){a==null&&typeof t==`object`&&t&&(a=t,t=void 0),n&&Buffer.isBuffer(e)&&(e=e.toString()),e&&e.charCodeAt(0)===65279&&(e=e.slice(1));let s=JSON.parse(e,t);if(typeof s!=`object`||!s)return s;let c=a&&a.protoAction||`error`,l=a&&a.constructorAction||`error`;if(c===`ignore`&&l===`ignore`)return s;if(c!==`ignore`&&l!==`ignore`){if(r.test(e)===!1&&i.test(e)===!1)return s}else if(c!==`ignore`&&l===`ignore`){if(r.test(e)===!1)return s}else if(i.test(e)===!1)return s;return o(s,{protoAction:c,constructorAction:l,safe:a&&a.safe})}function o(e,{protoAction:t=`error`,constructorAction:n=`error`,safe:r}={}){let i=[e];for(;i.length;){let e=i;i=[];for(let a of e){if(t!==`ignore`&&Object.prototype.hasOwnProperty.call(a,`__proto__`)){if(r===!0)return null;if(t===`error`)throw SyntaxError(`Object contains forbidden prototype property`);delete a.__proto__}if(n!==`ignore`&&Object.prototype.hasOwnProperty.call(a,`constructor`)&&a.constructor!==null&&typeof a.constructor==`object`&&Object.prototype.hasOwnProperty.call(a.constructor,`prototype`)){if(r===!0)return null;if(n===`error`)throw SyntaxError(`Object contains forbidden prototype property`);delete a.constructor}for(let e in a){let t=a[e];t&&typeof t==`object`&&i.push(t)}}}return e}function s(e,t,n){let{stackTraceLimit:r}=Error;Error.stackTraceLimit=0;try{return a(e,t,n)}finally{Error.stackTraceLimit=r}}function c(e,t){let{stackTraceLimit:n}=Error;Error.stackTraceLimit=0;let r;try{r=a(e,t,{safe:!0})}catch{r=void 0}finally{Error.stackTraceLimit=n}return r}t.exports=s,t.exports.default=s,t.exports.parse=s,t.exports.safeParse=c,t.exports.scan=o}))(),1),mo=Symbol(`aui.parse-partial-json-object.meta`),ho=e=>e?.[mo],go=e=>{if(e.length===0)return{[mo]:{state:`partial`,partialPath:[]}};try{let t=po.default.parse(e);if(typeof t!=`object`||!t)throw Error(`argsText is expected to be an object`);return t[mo]={state:`complete`,partialPath:[]},t}catch{try{let[t,n]=fo(e),r=po.default.parse(t);if(typeof r!=`object`||!r)throw Error(`argsText is expected to be an object`);return r[mo]={state:`partial`,partialPath:n},r}catch{return}}},_o=(e,t,n)=>{if(typeof e!=`object`||!e)return t.state;if(t.state===`complete`)return`complete`;if(n.length===0)return t.state;let[r,...i]=n;if(!Object.hasOwn(e,r))return`partial`;let[a,...o]=t.partialPath;if(r!==a)return`complete`;let s=e[r];return _o(s,{state:`partial`,partialPath:o},i)},vo=(e,t)=>{let n=ho(e);if(!n)throw Error(`unable to determine object state`);return _o(e,n,t.map(String))},yo=/^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?$/,bo=/^-?$|^-?(?:0|[1-9]\d*)(?:\.\d*)?$|^-?(?:0|[1-9]\d*)(?:\.\d+)?[eE][+-]?\d*$/,xo=/^[\t\n\r ]$/,So=/^[0-9a-fA-F]$/,Co={'"':`"`,"\\":`\\`,"/":`/`,b:`\b`,f:`\f`,n:`
|
|
8
|
+
`,r:`\r`,t:` `},wo=e=>typeof e==`object`&&!!e,To=(e,t,n)=>{e[t]=n},Eo=e=>{if(Array.isArray(e))return[...e];let t={};for(let n of Object.keys(e))t[n]=e[n];return t},Do=(e,t,n,r)=>{let i=(e,a)=>{let o=r.has(e)?e:Eo(e);r.add(o);let s=t[a];if(a===t.length-1)return To(o,s,n),wo(n)&&r.add(n),o;let c=o[s];if(!wo(c))throw Error(`Invalid incremental JSON path`);return To(o,s,i(c,a+1)),o};return i(e,0)},Oo=(e,t,n)=>{let r=go(``);for(let t of Object.keys(e))To(r,t,e[t]);let i=ho(r);return i.state=t,i.partialPath=n.map(String),r},ko=e=>{let t=[e];for(;t.length>0;){let e=t.pop();for(let n of Object.keys(e)){let r=e[n];if(!wo(r))continue;let i=Eo(r);To(e,n,i),t.push(i)}}return e},Ao=class e{text;mode=`start`;root={};frames=[];token;args;publishedArgs;ownedContainers;constructor(e){this.args=e,this.publishedArgs=e}static from(t=``,n=go(``)){let r=new e(n);t.length!==0&&(r.text={length:t.length,previous:void 0,value:t});let i=t.trimEnd().endsWith(`}`)?go(t):void 0;return i&&ho(i)?.state===`complete`?(r.args=i,r.publishedArgs=i,r.mode=`complete`,r):(r.consumeDelta(t,!0),r.args=r.snapshot(n),r.args!==n&&(r.publishedArgs=r.mode===`fallback`?r.args:void 0),r)}get currentTextLength(){return this.text?.length??0}get currentArgs(){return this.publishedArgs??=ko(this.args)}append(t){if(t.length===0)return this;if(this.currentTextLength===0)return e.from(t,this.args);if(this.mode===`complete`){let n=e.from(this.accumulatedText()+t,this.args);return n.args===this.args&&(n.publishedArgs=this.currentArgs),n}let n=this.clone(),r=this.args;return n.consumeDelta(t),n.text={length:(this.text?.length??0)+t.length,previous:this.text,value:t},n.args=n.snapshot(r),n.publishedArgs=n.args===r?this.currentArgs:n.mode===`fallback`?n.args:void 0,n}clone(){let t=new e(this.args);return t.text=this.text,t.mode=this.mode,t.root=this.root,t.frames=this.frames.map(e=>({...e,path:[...e.path]})),t.token=this.token?{...this.token,...`path`in this.token&&this.token.path?{path:[...this.token.path]}:void 0}:void 0,t}snapshot(e){return this.mode===`fallback`?go(this.accumulatedText())??e:this.mode===`start`?e:Oo(this.root,this.mode===`complete`?`complete`:`partial`,this.partialPath())}accumulatedText(){let e=[];for(let t=this.text;t;t=t.previous)e.push(t.value);return e.reverse().join(``)}partialPath(){return this.mode===`complete`?[]:this.token&&(this.token.kind===`number`||this.token.kind===`string`&&this.token.role===`value`)?this.token.path:this.frames.at(-1)?.path??[]}isFallback(){return this.mode===`fallback`}consumeDelta(e,t=!1){if(!this.isFallback()){this.ownedContainers=t?new Set([this.root]):new Set;for(let t of e)if(this.consumeCharacter(t),this.isFallback())break;!this.isFallback()&&this.token?.kind===`string`&&this.token.role===`value`?this.writeValue(this.token.path,this.token.value):!this.isFallback()&&this.token?.kind===`number`&&yo.test(this.token.value)&&this.writeValue(this.token.path,Number(this.token.value)),this.ownedContainers=void 0}}consumeCharacter(e){let t=!0;for(;t&&this.mode!==`fallback`;){if(t=!1,this.token){t=this.consumeToken(e);continue}if(this.mode===`complete`){xo.test(e)||(this.mode=`fallback`);continue}if(this.mode===`start`){if(xo.test(e))continue;if(e!==`{`){this.mode=`fallback`;continue}this.mode=`parsing`,this.frames.push({kind:`object`,path:[],state:`first-key-or-end`});continue}let n=this.frames.at(-1);n?n.kind===`object`?this.consumeObjectCharacter(n,e):this.consumeArrayCharacter(n,e):this.mode=`fallback`}}consumeObjectCharacter(e,t){if(!xo.test(t))switch(e.state){case`first-key-or-end`:t===`}`?this.closeContainer():t===`"`?(e.state=`key`,this.startKeyString()):this.mode=`fallback`;break;case`key`:t===`"`?this.startKeyString():this.mode=`fallback`;break;case`colon`:t===`:`?e.state=`value`:this.mode=`fallback`;break;case`value`:this.startValue(t,[...e.path,e.key]);break;case`comma-or-end`:t===`,`?(e.state=`key`,e.key=void 0):t===`}`?this.closeContainer():this.mode=`fallback`}}consumeArrayCharacter(e,t){if(!xo.test(t))switch(e.state){case`first-value-or-end`:t===`]`?this.closeContainer():(e.state=`value`,this.startValue(t,[...e.path,e.index]));break;case`value`:this.startValue(t,[...e.path,e.index]);break;case`comma-or-end`:t===`,`?(e.index+=1,e.state=`value`):t===`]`?this.closeContainer():this.mode=`fallback`}}startValue(e,t){if(e===`{`)this.writeValue(t,{}),this.frames.push({kind:`object`,path:t,state:`first-key-or-end`});else if(e===`[`)this.writeValue(t,[]),this.frames.push({kind:`array`,path:t,state:`first-value-or-end`,index:0});else if(e===`"`)this.writeValue(t,``),this.startValueString(t);else if(e===`t`||e===`f`||e===`n`){let n=e===`t`?`true`:e===`f`?`false`:`null`;this.writeValue(t,n===`true`||n!==`false`&&null),this.token={kind:`literal`,value:n,offset:1}}else e===`-`||e>=`0`&&e<=`9`?(this.token={kind:`number`,path:t,value:e},yo.test(e)&&this.writeValue(t,Number(e))):this.mode=`fallback`}startKeyString(){this.token={kind:`string`,role:`key`,value:``,escape:`none`,unicode:``}}startValueString(e){this.token={kind:`string`,role:`value`,path:e,value:``,escape:`none`,unicode:``}}consumeToken(e){let t=this.token;return t.kind===`string`?this.consumeString(t,e):t.kind===`number`?this.consumeNumber(t,e):this.consumeLiteral(t,e)}consumeString(e,t){if(e.escape===`unicode`)return So.test(t)?(e.unicode+=t,e.unicode.length===4&&(e.value+=String.fromCharCode(Number.parseInt(e.unicode,16)),e.escape=`none`,e.unicode=``),!1):(this.mode=`fallback`,!1);if(e.escape===`single`){if(t===`u`)return e.escape=`unicode`,!1;let n=Co[t];return n===void 0?this.mode=`fallback`:(e.value+=n,e.escape=`none`),!1}if(t===`\\`)return e.escape=`single`,!1;if(t.charCodeAt(0)<32)return this.mode=`fallback`,!1;if(t!==`"`)return e.value+=t,!1;if(this.token=void 0,e.role===`key`){let t=this.frames.at(-1);if(!t||t.kind!==`object`||e.value===`__proto__`||e.value===`prototype`&&t.path.at(-1)===`constructor`)return this.mode=`fallback`,!1;t.key=e.value,t.state=`colon`}else this.writeValue(e.path,e.value),this.finishValue();return!1}consumeNumber(e,t){if(t>=`0`&&t<=`9`||t===`e`||t===`E`||t===`+`||t===`-`||t===`.`){let n=e.value+t;return bo.test(n)?(e.value=n,yo.test(e.value)&&this.writeValue(e.path,Number(e.value)),!1):(this.mode=`fallback`,!1)}return yo.test(e.value)?(this.token=void 0,this.finishValue(),!0):(this.mode=`fallback`,!1)}consumeLiteral(e,t){return t===e.value[e.offset]?(e.offset+=1,e.offset===e.value.length&&(this.token=void 0,this.finishValue()),!1):(this.mode=`fallback`,!1)}finishValue(){let e=this.frames.at(-1);!e||e.state!==`value`?this.mode=`fallback`:e.state=`comma-or-end`}closeContainer(){this.frames.pop(),this.frames.length===0?this.mode=`complete`:this.finishValue()}writeValue(e,t){try{this.root=Do(this.root,e,t,this.ownedContainers??new Set)}catch{this.mode=`fallback`}}},jo=class{_streamStartTime;_firstTokenTime;_totalChunks=0;_toolCallIds=new Set;constructor(){this._streamStartTime=Date.now()}recordChunk(){this._totalChunks++}recordFirstToken(){this._firstTokenTime===void 0&&(this._firstTokenTime=Date.now())}recordToolCallStart(e){this._toolCallIds.add(e)}getTiming(e,t){let n=Date.now()-this._streamStartTime,r=e&&e>0?e:t?Math.ceil(t.length/4):void 0,i=r&&n>0?r/n*1e3:void 0;return{streamStartTime:this._streamStartTime,...this._firstTokenTime===void 0?void 0:{firstTokenTime:this._firstTokenTime-this._streamStartTime},totalStreamTime:n,...r===void 0?void 0:{tokenCount:r},...i===void 0?void 0:{tokensPerSecond:i},totalChunks:this._totalChunks,toolCallCount:this._toolCallIds.size}}},Mo=(e,t)=>({...e,parts:t,get content(){return this.parts}}),No=(e,t)=>Mo(e,[...e.parts,t]),Po=({unstable_state:e=null}={})=>({role:`assistant`,status:{type:`running`},parts:[],get content(){return this.parts},metadata:{unstable_state:e,unstable_data:[],unstable_annotations:[],steps:[],custom:{}}}),Fo=16,Io=(e,t,n,r)=>{let i=t.path.length===1?e.parts[t.path[0]]:void 0;if(i===void 0)return n(`no-part:${t.type}`,`Dropped ${t.type} chunk: no part at path [${t.path.join(`, `)}]`),e;let a=t.path[0],o=r(i);return o===i?e:Mo(e,[...e.parts.slice(0,a),o,...e.parts.slice(a+1)])},Lo=(e,t,n)=>{let r=t.part;if(r.type===`text`||r.type===`reasoning`)return No(e,{type:r.type,text:``,status:{type:`running`},...r.providerMetadata!=null&&{providerMetadata:r.providerMetadata},...r.type===`reasoning`&&r.unstable_summary!==void 0?{unstable_summary:r.unstable_summary}:void 0,...r.type===`reasoning`?{timing:{startedAt:Date.now()}}:void 0,...r.parentId&&{parentId:r.parentId}});if(r.type===`tool-call`)return No(e,{type:`tool-call`,state:`partial-call`,status:{type:`running`,isArgsComplete:!1},toolCallId:r.toolCallId,toolName:r.toolName,argsText:``,args:{},timing:{startedAt:Date.now()},...r.parentId&&{parentId:r.parentId}});if(r.type===`source`)return No(e,{type:`source`,sourceType:r.sourceType,id:r.id,url:r.url,...r.title?{title:r.title}:void 0,...r.parentId&&{parentId:r.parentId}});if(r.type===`file`)return No(e,{type:`file`,mimeType:r.mimeType,data:r.data,...r.parentId&&{parentId:r.parentId}});if(r.type===`data`)return No(e,{type:`data`,name:r.name,data:r.data,...r.parentId&&{parentId:r.parentId}});{let t=String(r.type);return n(`unsupported-part-start:${t}`,`Unsupported part-start type ${t}: inserting an empty reasoning part to preserve part indices`),No(e,{type:`reasoning`,text:``,status:{type:`running`}})}},Ro=(e,t,n)=>Io(e,t,n,e=>e.type===`tool-call`?e.state===`partial-call`?{...e,state:`call`,status:e.status.type===`running`?{type:`running`,isArgsComplete:!0}:e.status}:e:(n(`wrong-part:tool-call-args-text-finish`,`Dropped tool-call-args-text-finish chunk: part is not a tool-call`),e)),zo=(e,t,n)=>Io(e,t,n,e=>{if(e.type===`tool-call`&&e.isPreliminary)return e;let n=(e.type===`text`||e.type===`reasoning`)&&t.providerMetadata!=null?{providerMetadata:t.providerMetadata}:{};return e.type===`reasoning`&&e.timing!==void 0?{...e,...n,status:{type:`complete`,reason:`unknown`},timing:{...e.timing,completedAt:e.timing.completedAt??Date.now()}}:{...e,...n,status:{type:`complete`,reason:`unknown`}}}),Bo=(e,t,n,r)=>Io(e,t,n,e=>{if(e.type===`text`||e.type===`reasoning`)return{...e,text:e.text+t.textDelta,...t.providerMetadata!=null&&{providerMetadata:t.providerMetadata}};if(e.type===`tool-call`){let n=e.argsText+t.textDelta,i=r.get(e),a=i?i.append(t.textDelta):n.length===0?Ao.from(``):Ao.from(n,e.args),o=a.currentArgs,s={...e,argsText:n,args:o};return r.set(s,a),s}return n(`wrong-part:text-delta`,`Dropped text-delta chunk: part is neither text nor tool-call`),e}),Vo=(e,t,n)=>Io(e,t,n,e=>{if(e.type===`tool-call`){let n=t.isPreliminary===!0;if(n&&e.state===`result`)return e;let{isPreliminary:r,modelContent:i,...a}=e,o=e.status.type===`running`?e.status:{type:`running`,isArgsComplete:e.state!==`partial-call`};return n?{...a,state:e.state===`partial-call`?`partial-call`:`call`,...t.artifact===void 0?{}:{artifact:t.artifact},result:t.result,isError:t.isError??!1,isPreliminary:!0,...t.modelContent===void 0?{}:{modelContent:t.modelContent},...t.messages===void 0?{}:{messages:t.messages},status:o}:{...a,state:`result`,...e.timing===void 0?{}:{timing:{...e.timing,completedAt:e.timing.completedAt??Date.now()}},...t.artifact===void 0?{}:{artifact:t.artifact},result:t.result,isError:t.isError??!1,...t.modelContent===void 0?{}:{modelContent:t.modelContent},...t.messages===void 0?{}:{messages:t.messages},status:{type:`complete`,reason:`stop`}}}return n(`wrong-part:result`,`Dropped result chunk: part is not a tool-call`),e}),Ho=(e,t)=>{if(e.status?.type===`incomplete`&&e.status?.reason===`error`)return e;let n=Uo(t);return{...e,status:n}},Uo=e=>e.finishReason===`tool-calls`?{type:`requires-action`,reason:`tool-calls`}:e.finishReason===`stop`||e.finishReason===`unknown`?{type:`complete`,reason:e.finishReason}:{type:`incomplete`,reason:e.finishReason},Wo=(e,t)=>({...e,metadata:{...e.metadata,unstable_annotations:[...e.metadata.unstable_annotations,...t.annotations]}}),Go=(e,t)=>({...e,metadata:{...e.metadata,unstable_data:[...e.metadata.unstable_data,...t.data]}}),Ko=(e,t)=>({...e,metadata:{...e.metadata,steps:[...e.metadata.steps,{state:`started`,messageId:t.messageId}]}}),qo=(e,t)=>{let n=e.metadata.steps.slice(),r=n.length-1;return n.length>0&&n[r]?.state===`started`?n[r]={...n[r],state:`finished`,finishReason:t.finishReason,usage:t.usage,isContinued:t.isContinued}:n.push({state:`finished`,messageId:oo(),finishReason:t.finishReason,usage:t.usage,isContinued:t.isContinued}),{...e,metadata:{...e.metadata,steps:n}}},Jo=(e,t)=>{let n=t.severity===`critical`||t.severity===`warning`||t.severity===`info`?t.severity:void 0;return{...e,status:{type:`incomplete`,reason:`error`,error:{code:t.code??`unknown`,message:t.error??`unknown error`,...n!==void 0&&{severity:n}}}}},Yo=(e,t,n)=>(n.append(t.operations),{...e,metadata:{...e.metadata,unstable_state:n.state}}),Xo=e=>{let t=0;for(let n of e.metadata.steps)n.state===`finished`&&n.usage&&(t+=n.usage.outputTokens);return t},Zo=(e,t,n=0)=>{let r=n>0?n:Xo(t);if(r>0)return e.getTiming(r);let i=``;for(let e of t.parts)(e.type===`text`||e.type===`reasoning`)&&(i+=e.text);return e.getTiming(void 0,i||void 0)},Qo=e=>{let t=!1;return()=>{t||(t=!0,queueMicrotask(()=>{t=!1,e()}))}},$o=class extends TransformStream{constructor({initialMessage:e,throttle:t,onError:n,strict:r=!0}={}){let i=e??Po(),a,o,s=new jo,c=new WeakMap,l=new Set,u=(e,t)=>{l.has(e)||l.size>=Fo||(l.add(e),console.warn(t))},d,f=t?Qo(()=>{d?.enqueue(i)}):()=>{d?.enqueue(i)};super({start(e){d=e},transform(e){s.recordChunk();let t=e.type;switch(t){case`part-start`:i=Lo(i,e,u),e.part.type===`tool-call`&&s.recordToolCallStart(e.part.toolCallId);break;case`tool-call-args-text-finish`:i=Ro(i,e,u);break;case`part-finish`:i=zo(i,e,u);break;case`text-delta`:{let t=Bo(i,e,u,c);t!==i&&s.recordFirstToken(),i=t;break}case`result`:i=Vo(i,e,u);break;case`message-finish`:o=e.usage?.outputTokens,i=Ho(i,e);break;case`annotations`:i=Wo(i,e);break;case`data`:i=Go(i,e);break;case`step-start`:i=Ko(i,e);break;case`step-finish`:i=qo(i,e);break;case`error`:i=Jo(i,e),n?.(e.error);break;case`update-state`:a??=new lo(i.metadata.unstable_state,{strict:r}),i=Yo(i,e,a);break;default:throw Error(`Unsupported chunk type: ${t}`)}i.status.type!==`running`&&(i={...i,metadata:{...i.metadata,timing:Zo(s,i,o)}}),f()},flush(e){if(i.status?.type===`running`){let t=i.parts?.some(e=>e.type===`tool-call`&&(e.state===`call`||e.state===`partial-call`)&&(e.result===void 0||e.isPreliminary))??!1;i=Ho(i,{type:`message-finish`,path:[],finishReason:t?`tool-calls`:`unknown`,usage:{inputTokens:0,outputTokens:0}}),i={...i,metadata:{...i.metadata,timing:Zo(s,i,o)}},e.enqueue(i)}}})}};function es(){let e=this.getReader(),t=!1,n=Promise.resolve(),r=e=>{let t=n.then(e);return n=t.then(()=>void 0,()=>void 0),t},i=async n=>{if(!t){t=!0;try{return e.cancel(n)}finally{e.releaseLock()}}},a={next:()=>r(async()=>{if(t)return{done:!0,value:void 0};try{let n=await e.read();return n.done&&(t=!0,e.releaseLock()),n}catch(n){throw t=!0,e.releaseLock(),n}}),return:e=>r(async()=>(await i(e),{done:!0,value:e})),throw:e=>r(async()=>{throw await i(void 0),e}),[Symbol.asyncIterator](){return this}},o=Symbol.asyncDispose;return o&&Object.defineProperty(a,o,{value:async()=>{await a.return()},writable:!0,configurable:!0}),a}function ts(e){return e[Symbol.asyncIterator]??=es,e}var ns=class e{readable;constructor(e){this.readable=e}static fromAssistantStream(t){return new e(t.pipeThrough(new $o))}async unstable_result(){let e;for await(let t of this)e=t;return e||{role:`assistant`,status:{type:`complete`,reason:`unknown`},parts:[],content:[],metadata:{unstable_state:null,unstable_data:[],unstable_annotations:[],steps:[],custom:{}}}}[Symbol.asyncIterator](){return ts(this.readable)[Symbol.asyncIterator]()}tee(){let[t,n]=this.readable.tee();return[new e(t),new e(n)]}},rs=Symbol.for(`aui.tool-response`),is=`<no result>`,as=class e{get[rs](){return!0}artifact;result;isError;isPreliminary;modelContent;messages;constructor(e){e.artifact!==void 0&&(this.artifact=e.artifact);let t=e.result;this.result=t===void 0?is:t,this.isError=e.isError??!1,e.isPreliminary&&(this.isPreliminary=!0),e.modelContent!==void 0&&(this.modelContent=e.modelContent),e.messages!==void 0&&(this.messages=e.messages)}static[Symbol.hasInstance](e){return typeof e==`object`&&!!e&&rs in e}static toResponse(t){return t instanceof e?t:new e({result:t===void 0?is:t})}},os=class extends TransformStream{constructor(e){super();let t=e(super.readable);Object.defineProperty(this,"readable",{value:t,writable:!1})}},ss=(e,t)=>new ReadableStream({start(n){return e.start?.(t(n))},pull(n){return e.pull?.(t(n))},cancel(t){return e.cancel?.(t)}}),cs=(e,t)=>{let n;return[ss({start(e){n=e},cancel(e){return t?.(n,e)}},e),n]};function ls(e,t,n){try{let r=e();if(typeof r==`object`&&r&&`then`in r)return r.then(t,n);t(r)}catch(e){n(e)}}var us=()=>{let e,t,n=new Promise((n,r)=>{e=n,t=r});if(!e||!t)throw Error(`Failed to create promise`);return{promise:n,resolve:e,reject:t}},ds=()=>{let e=[],t=!1,n=!1,r=!1,i,a,o,s=0,c,l,u=e=>{for(let t of e.holds)t.reached.resolve();e.holds=[]},d=()=>{if(a=void 0,!l){let t=e.splice(0);for(let e of t)e.orderedFinish?.delivered.resolve(),u(e);l=Promise.all(t.map(async e=>{try{await e.reader.cancel().catch(()=>void 0),await e.pipeTask}finally{e.reader.releaseLock()}})).then(()=>void 0)}return l},f=e=>{n||r||(r=!0,console.error(e),d(),i.error(e),c?.reject(e),c=void 0)},p=a=>{a.promise||=a.reader.read().then(async({done:o,value:l})=>{if(!(n||r)){if(o)a.orderedFinish?.delivered.resolve(),e.splice(e.indexOf(a),1),a.reader.releaseLock(),u(a),t&&e.length===0&&s===0&&i.close();else{if(a.gate&&(await a.gate,a.gate=void 0,n||r))return;for(;a.holds[0]&&a.delivered>=a.holds[0].writtenBefore;)if(await a.holds[0].flushed,a.holds.shift(),n||r)return;if(l.type===`part-finish`&&a.orderedFinish&&(await a.orderedFinish.previous(),n||r))return;i.enqueue(l),a.delivered++;for(let e of a.holds)a.delivered>=e.writtenBefore&&e.reached.resolve();l.type===`part-finish`&&a.orderedFinish?.delivered.resolve()}a.promise=void 0,c?.resolve(),c=void 0}}).catch(e=>{a.promise=void 0,f(e)})},m=new ReadableStream({start(e){i=e},pull(){return c=us(),e.forEach(e=>{p(e)}),c.promise},async cancel(){n=!0;let e=d();c?.resolve(),c=void 0,await e}}),h=(e,t)=>{let n={writtenBefore:e.written(),reached:us(),flushed:t};return e.delivered>=n.writtenBefore&&n.reached.resolve(),e.holds.push(n),n.reached.promise},g=l=>{let u=l.type===`step-finish`||l.type===`message-finish`||l.type===`error`;if((e.length>0||u)&&(a=void 0),!a){let l=[];a=l,s++;let d=o,p=u?e.filter(e=>e.written):[],m=d||p.length>0?us():void 0,g=m?p.map(e=>h(e,m.promise)):[];m&&(o=m.promise),Promise.resolve().then(async()=>{if(d&&await d,g.length>0&&await Promise.all(g),s--,a===l&&(a=void 0),!(n||r)){for(let e of l)i.enqueue(e);t&&e.length===0&&s===0&&i.close(),c?.resolve(),c=void 0}}).catch(f).finally(()=>{m&&(m.resolve(),o===m.promise&&(o=void 0))})}a.push(l),u&&(a=void 0)};return{readable:m,isSealed(){return t},isCancelled(){return n},isErrored(){return r},seal(){t||n||r||(t=!0,e.length===0&&s===0&&i.close())},addStream:(i,s,c)=>{let l=s?.catch(()=>void 0);if(n||r){i.cancel().catch(()=>void 0);return}if(t)throw i.cancel().catch(()=>void 0),Error(`Cannot add streams after the run callback has settled.`);a=void 0;let u={reader:i.getReader(),pipeTask:l,orderedFinish:c?.orderedFinish,written:c?.written,delivered:0,gate:o,holds:[]};e.push(u),p(u)},enqueue(e){if(!(n||r)){if(t)throw Error(`Cannot add streams after the run callback has settled.`);g(e)}}}},fs=e=>e instanceof TypeError,ps=(e,t,n)=>{try{e.enqueue(t)}catch(e){if(!fs(e))throw e;n?.(e)}},ms=e=>{try{e.close()}catch(e){if(!fs(e))throw e}},hs=class{_controller;_strict;_isClosed=!1;_ignoreAppends=!1;_warnedDropped=!1;constructor(e,t={}){this._controller=e,this._strict=t.strict??!0}append(e,t){if(this._ignoreAppends)return this;let n={type:`text-delta`,path:[],textDelta:e,...t!=null&&{providerMetadata:t}};if(this._isClosed){if(this._strict)throw TypeError(`Cannot append to a closed TextStreamController`);return ps(this._controller,n,this._warnDroppedAfterClose),this}return ps(this._controller,n),this}_warnDroppedAfterClose=e=>{this._warnedDropped||(this._warnedDropped=!0,console.error(`Dropped text delta for closed stream: ${String(e)}`))};close(e){this._isClosed||(this._isClosed=!0,ps(this._controller,{type:`part-finish`,path:[],...e!=null&&{providerMetadata:e}}),ms(this._controller))}__internal_close(){this._isClosed||(this._ignoreAppends=!0,this.close())}__internal_truncate(){this._isClosed||(this._ignoreAppends=!0,this._isClosed=!0,ms(this._controller))}},gs=class{_isClosed=!1;_hasArgsText=!1;_argsTextState=`open`;_controller;_argsTextController;_options;constructor(e,t={}){this._controller=e,this._options=t,this._argsTextController=new hs({enqueue:e=>{if(this._argsTextState!==`open`)throw TypeError(`Cannot append to finished tool-call args`);e.type===`text-delta`?(this._hasArgsText=!0,this._controller.enqueue(e)):(this._argsTextState=`finishing`,queueMicrotask(()=>this._finishArgsText()))},close:()=>{}},{strict:this._options.strict})}_finishArgsText(){this._argsTextState===`finishing`&&(this._argsTextState=`finished`,this._hasArgsText||ps(this._controller,{type:`text-delta`,textDelta:`{}`,path:[]}),ps(this._controller,{type:`tool-call-args-text-finish`,path:[]}))}get argsText(){return this._argsTextController}async setResponse(e){if(this._isClosed)return;let t=e.result;ps(this._controller,{type:`result`,path:[],...e.artifact===void 0?{}:{artifact:e.artifact},result:t===void 0?is:t,isError:e.isError??!1,...e.isPreliminary?{isPreliminary:!0}:{},...e.modelContent===void 0?{}:{modelContent:e.modelContent},...e.messages===void 0?{}:{messages:e.messages}}),e.isPreliminary?(this._argsTextController.close(),this._finishArgsText()):await this.close()}async close(){this._isClosed||(this._isClosed=!0,this._options.onClose?.(),this._argsTextController.close(),this._finishArgsText(),ps(this._controller,{type:`part-finish`,path:[]}),ms(this._controller))}__internal_truncate(){this._isClosed||(this._isClosed=!0,this._finishArgsText(),this._argsTextController.__internal_truncate(),this._argsTextState=`finished`,ms(this._controller))}},_s=class{value=-1;up(){return++this.value}},vs=class extends TransformStream{constructor(e){super({transform(t,n){n.enqueue({...t,path:[e,...t.path]})}})}};TransformStream;var ys=class extends TransformStream{constructor(e){let t=new _s,n=new Map;super({transform(r,i){r.type===`part-start`&&r.path.length===0&&n.set(t.up(),e.up());let[a,...o]=r.path;if(a===void 0){i.enqueue(r);return}let s=n.get(a);if(s===void 0)throw Error(`Path not found`);i.enqueue({...r,path:[s,...o]})}})}},bs=e=>{let t=0,[n,r]=cs(n=>e({get desiredSize(){return n.desiredSize},enqueue(e){n.enqueue(e),t++},close(){n.close()},error(e){n.error(e)}}));return[n,r,()=>t]},xs=class e{_state;_parentId;constructor(e,t={}){this._state=e||{strict:t.strict??!0,merger:ds(),contentCounter:new _s,openInputs:new Set,lastToolCallFinish:Promise.resolve()}}get __internal_isClosed(){return this._state.merger.isSealed()||this._state.merger.isCancelled()||this._state.merger.isErrored()}get __internal_isCancelled(){return this._state.merger.isCancelled()}__internal_getReadable(){return this._state.merger.readable}__internal_endOpenInputs(){this._state.append=void 0;for(let e of this._state.openInputs)e();this._state.openInputs.clear()}__internal_subscribeToClose(e){this._state.closeSubscriber=e}_addTransformedStream(e,t,n){if(e.locked)throw TypeError(`Cannot merge a stream that is already locked to a reader.`);let r=e.pipeTo(t.writable).catch(async e=>{throw await t.writable.abort(e).catch(()=>void 0),e});return this._state.merger.addStream(t.readable,r,n),r}_trackOpenInput(e,t){let{openInputs:n}=this._state;n.add(t);let r=()=>n.delete(t);e.then(r,r)}_addPart(e,t,n,r,i){this._state.append&&(this._state.append.controller.close(),this._state.append=void 0),this.enqueue({type:`part-start`,part:e,path:[]});let a=this._addTransformedStream(t,new vs(this._state.contentCounter.value),{orderedFinish:i,written:n});r&&this._trackOpenInput(a,r)}merge(e){this._addTransformedStream(e,new ys(this._state.contentCounter))}appendText(e){(this._state.append?.kind!==`text`||this._state.append.parentId!==this._parentId)&&(this._state.append={kind:`text`,parentId:this._parentId,controller:this.addTextPart()}),this._state.append.controller.append(e)}appendReasoning(e,t){(t!==void 0||this._state.append?.kind!==`reasoning`||this._state.append.parentId!==this._parentId)&&(this._state.append={kind:`reasoning`,parentId:this._parentId,controller:this.addReasoningPart(t)}),(t===void 0||e.length!==0)&&this._state.append.controller.append(e)}addTextPart(e){let[t,n,r]=bs(e=>new hs(e,{strict:this._state.strict}));return this._addPart(this._withParentIdOption({type:`text`,...e}),t,r,()=>n.__internal_close()),n}addReasoningPart(e){let[t,n,r]=bs(e=>new hs(e,{strict:this._state.strict}));return this._addPart(this._withParentIdOption({type:`reasoning`,...e}),t,r,()=>n.__internal_close()),n}addToolCallPart(e){let t=typeof e==`string`?{toolName:e}:e,n=t.toolName,r=t.toolCallId??oo(),i=us(),a=Promise.resolve(),[o,s,c]=bs(e=>new gs(e,{strict:this._state.strict,onClose:()=>{a=this._state.lastToolCallFinish,this._state.lastToolCallFinish=i.promise}}));return this._addPart({type:`tool-call`,toolName:n,toolCallId:r,...this._parentId&&{parentId:this._parentId}},o,c,()=>s.__internal_truncate(),{previous:()=>a,delivered:i}),t.argsText!==void 0&&(s.argsText.append(t.argsText),s.argsText.close()),t.args!==void 0&&(s.argsText.append(JSON.stringify(t.args)),s.argsText.close()),t.response!==void 0&&s.setResponse(t.response),s}_finishedPartStream(){return new ReadableStream({start(e){e.enqueue({type:`part-finish`,path:[]}),e.close()}})}_withParentIdOption(e){return this._parentId?{...e,parentId:this._parentId}:e}appendSource(e){this._addPart(this._withParentIdOption(e),this._finishedPartStream(),()=>1)}appendFile(e){this._addPart(this._withParentIdOption(e),this._finishedPartStream(),()=>1)}appendData(e){this._addPart(this._withParentIdOption(e),this._finishedPartStream(),()=>1)}enqueue(e){this._state.merger.enqueue(e),e.type===`part-start`&&e.path.length===0&&this._state.contentCounter.up()}withParentId(t){let n=new e(this._state);return n._parentId=t,n}close(){this._state.append?.controller?.close(),this._state.merger.seal(),this._state.closeSubscriber?.()}};function Ss(e,t={}){let n=new xs(void 0,t);return(async()=>{try{await e(n)}catch(e){n.__internal_isClosed?n.__internal_isCancelled||console.error(e):(n.enqueue({type:`error`,path:[],error:String(e)}),n.__internal_endOpenInputs())}finally{n.__internal_isClosed||n.close()}})(),n.__internal_getReadable()}function Cs(e={}){let{resolve:t,promise:n}=us(),r;return[Ss(e=>(r=e,r.__internal_subscribeToClose(t),n),e),r]}var ws=class extends TransformStream{constructor(){let e=[];super({transform(t,n){if(t.type===`part-start`){if(t.path.length!==0){n.error(Error(`Nested parts are not supported`));return}e.push(t.part),n.enqueue(t)}else if(t.type===`text-delta`||t.type===`result`||t.type===`part-finish`||t.type===`tool-call-args-text-finish`){if(t.path.length!==1){n.error(Error(`${t.type} chunks must have a path of length 1`));return}let r=t.path[0];if(r<0||r>=e.length){n.error(Error(`Invalid path index: ${r}`));return}let i=e[r];n.enqueue({...t,meta:i})}else n.enqueue(t)}})}};function Ts(e,t){let n=e;for(let e of t){if(n==null||!Object.hasOwn(n,e))return;n=n[e]}return n}var Es=class{resolve;reject;disposed=!1;fieldPath;get isDisposed(){return this.disposed}constructor(e,t,n){this.resolve=e,this.reject=t,this.fieldPath=n}update(e){if(!this.disposed)try{if(vo(e,this.fieldPath)===`complete`){let t=Ts(e,this.fieldPath);t!==void 0&&(this.resolve(t),this.dispose())}}catch(e){this.reject(e),this.dispose()}}end(e){if(!this.disposed)try{let t=Ts(e,this.fieldPath);this.resolve(t)}catch(e){this.reject(e)}finally{this.dispose()}}error(e){this.disposed||(this.reject(e),this.dispose())}dispose(){this.disposed=!0}},Ds=class{controller;disposed=!1;fieldPath;get isDisposed(){return this.disposed}constructor(e,t){this.controller=e,this.fieldPath=t}update(e){if(!this.disposed)try{let t=Ts(e,this.fieldPath);t!==void 0&&this.controller.enqueue(t),vo(e,this.fieldPath)===`complete`&&(this.controller.close(),this.dispose())}catch(e){this.controller.error(e),this.dispose()}}end(){this.disposed||(this.controller.close(),this.dispose())}error(e){this.disposed||(this.controller.error(e),this.dispose())}dispose(){this.disposed=!0}},Os=class{controller;disposed=!1;fieldPath;lastValue=void 0;get isDisposed(){return this.disposed}constructor(e,t){this.controller=e,this.fieldPath=t}update(e){if(!this.disposed)try{let t=Ts(e,this.fieldPath);if(t!==void 0&&typeof t==`string`){let e=t.substring(this.lastValue?.length||0);this.lastValue=t,this.controller.enqueue(e)}vo(e,this.fieldPath)===`complete`&&(this.controller.close(),this.dispose())}catch(e){this.controller.error(e),this.dispose()}}end(){this.disposed||(this.controller.close(),this.dispose())}error(e){this.disposed||(this.controller.error(e),this.dispose())}dispose(){this.disposed=!0}},ks=class{controller;disposed=!1;fieldPath;nextIndex=0;get isDisposed(){return this.disposed}constructor(e,t){this.controller=e,this.fieldPath=t}update(e){if(!this.disposed)try{let t=Ts(e,this.fieldPath);if(!Array.isArray(t))return;for(;this.nextIndex<t.length&&vo(e,[...this.fieldPath,this.nextIndex])===`complete`;this.nextIndex++)this.controller.enqueue(t[this.nextIndex]);vo(e,this.fieldPath)===`complete`&&(this.controller.close(),this.dispose())}catch(e){this.controller.error(e),this.dispose()}}end(){this.disposed||(this.controller.close(),this.dispose())}error(e){this.disposed||(this.controller.error(e),this.dispose())}dispose(){this.disposed=!0}},As=class{argTextDeltas;handles=new Set;accumulatedText=``;parser;args=void 0;finished=!1;failure=void 0;constructor(e){this.argTextDeltas=e,this.processStream()}async processStream(){try{let e=this.argTextDeltas.getReader();for(;;){let{value:t,done:n}=await e.read();if(n)break;this.accumulatedText+=t,this.handles.size!==0&&this.parseCurrentArgs(t)&&this.updateHandles()}}catch(e){this.failure={reason:e}}finally{this.finished=!0;for(let e of this.handles)this.settleHandle(e);this.handles.clear()}}settleHandle(e){this.failure?e.error(this.failure.reason):e.end(this.args)}parseCurrentArgs(e){if(this.parser?.currentTextLength===this.accumulatedText.length)return!1;let t=this.args;return this.parser=this.parser&&e!==void 0&&this.parser.currentTextLength+e.length===this.accumulatedText.length?this.parser.append(e):Ao.from(this.accumulatedText,this.args),this.args=this.parser.currentArgs,this.args!==t}updateHandles(){for(let e of this.handles)e.update(this.args),e.isDisposed&&this.handles.delete(e)}activateHandle(e){this.parseCurrentArgs(),e.update(this.args),e.isDisposed||(this.finished?this.settleHandle(e):this.handles.add(e))}get(...e){return new Promise((t,n)=>{let r=new Es(t,n,e);this.activateHandle(r)})}streamValues(...e){let t=e,n;return ts(new ReadableStream({start:e=>{n=new Ds(e,t),this.activateHandle(n)},cancel:()=>{n&&(n.dispose(),this.handles.delete(n))}}))}streamText(...e){let t=e,n;return ts(new ReadableStream({start:e=>{n=new Os(e,t),this.activateHandle(n)},cancel:()=>{n&&(n.dispose(),this.handles.delete(n))}}))}forEach(...e){let t=e,n;return ts(new ReadableStream({start:e=>{n=new ks(e,t),this.activateHandle(n)},cancel:()=>{n&&(n.dispose(),this.handles.delete(n))}}))}},js=class{promise;constructor(e){this.promise=e}get(){return this.promise}},Ms=class{args;response;writable;resolve;argsText=``;constructor(){let e=new TransformStream;this.writable=e.writable,this.args=new As(e.readable);let{promise:t,resolve:n}=us();this.resolve=n,this.response=new js(t)}async appendArgsTextDelta(e){let t=this.writable.getWriter();try{await t.write(e)}catch(e){console.warn(e)}finally{t.releaseLock()}this.argsText+=e}async finishArgsText(){let e=this.writable.getWriter();try{await e.close()}catch(e){console.warn(e)}finally{e.releaseLock()}}setResponse(e){this.resolve(e)}result={get:async()=>(await this.response.get()).result}},Ns=Symbol.for(`assistant-stream.tool-execution-id`),Ps=(e,t,n,r,i)=>{try{let a=t?.(n,r,i);Promise.resolve(a).catch(t=>{console.error(`[assistant-stream] ${e} callback threw an error`,t)})}catch(t){console.error(`[assistant-stream] ${e} callback threw an error`,t)}},Fs=e=>e.join(`,`),Is=(e,t)=>{let n={...e};return Object.defineProperty(n,Ns,{value:t,enumerable:!0}),n},Ls=class extends os{constructor(e){let t=e,n=new Map,r=new Map,i=new Set,a=new Map,o=0;super(e=>{let s=new TransformStream({async transform(e,s){let c=a.get(Fs(e.path));switch((e.type!==`part-finish`||e.meta.type!==`tool-call`)&&s.enqueue(c?Is(e,c):e),e.type){case`part-start`:{let n=o;if(o+=1,e.part.type===`tool-call`){let i=new Ms,o=Symbol();a.set(String(n),o),r.set(o,i);let s=t.streamCall({reader:i,toolCallId:e.part.toolCallId,toolName:e.part.toolName,executionId:o});s&&Promise.resolve(s).catch(e=>{console.error(`[assistant-stream] streamCall callback threw an error`,e)})}break}case`text-delta`:if(e.meta.type===`tool-call`){let t=a.get(Fs(e.path)),n=t?r.get(t):void 0;if(!n)throw Error(`No controller found for tool call`);await n.appendArgsTextDelta(e.textDelta)}break;case`result`:{if(e.meta.type!==`tool-call`)break;let t=a.get(Fs(e.path)),n=t?r.get(t):void 0;if(!n)throw Error(`No controller found for tool call`);if(i.add(t),e.isPreliminary)break;n.setResponse(new as({result:e.result,artifact:e.artifact,isError:e.isError,modelContent:e.modelContent,messages:e.messages}));break}case`tool-call-args-text-finish`:{if(e.meta.type!==`tool-call`)break;let{toolCallId:o,toolName:c}=e.meta,l=a.get(Fs(e.path)),u=l?r.get(l):void 0;if(!u)throw Error(`No controller found for tool call`);if(await u.finishArgsText(),i.has(l))break;let d=!1,f=ls(()=>{let e;try{e=po.default.parse(u.argsText)}catch(e){throw Error(`Function parameter parsing failed. ${JSON.stringify(e.message)}`)}let n=t.execute({toolCallId:o,toolName:c,args:e,executionId:l});return n!==void 0&&(d=!0,Ps(`onExecutionStart`,t.onExecutionStart,o,c,l)),n},n=>{if(d&&Ps(`onExecutionEnd`,t.onExecutionEnd,o,c,l),n===void 0)return;let r=new as({artifact:n.artifact,result:n.result,isError:n.isError,messages:n.messages,modelContent:n.modelContent});u.setResponse(r),ps(s,Is({type:`result`,path:e.path,...r},l))},n=>{d&&Ps(`onExecutionEnd`,t.onExecutionEnd,o,c,l);let r=new as({result:String(n),isError:!0});u.setResponse(r),ps(s,Is({type:`result`,path:e.path,...r},l))});f&&n.set(l,f);break}case`part-finish`:{if(e.meta.type!==`tool-call`)break;let t=a.get(Fs(e.path)),o=t?n.get(t):void 0,c=()=>{t&&(n.delete(t),r.delete(t),i.delete(t),a.delete(Fs(e.path)))};o?o.then(()=>{c(),ps(s,e)}):(c(),s.enqueue(e))}}},async flush(){await Promise.all(n.values())}});return e.pipeThrough(new ws).pipeThrough(s)})}},Rs=Symbol.for(`assistant-stream.tool-execution-id`),zs=Symbol(`assistant-stream.tool-aborted`),Bs=e=>typeof e==`object`&&!!e&&`~standard`in e&&e[`~standard`].version===1,Vs=e=>typeof e?.then==`function`,Hs=async(e,t,n=!1)=>{let r,i=new Promise(e=>{r=()=>{n?queueMicrotask(()=>queueMicrotask(()=>e(zs))):e(zs)},t.aborted?r():t.addEventListener(`abort`,r,{once:!0})});try{return await Promise.race([e,i])}finally{t.removeEventListener(`abort`,r)}},Us=()=>new as({result:`Tool execution was cancelled.`,isError:!0});function Ws(e,t,n,r){let i=e?.[n.toolName];return i?.execute?(async e=>{if(t.aborted)return Us();let a=e,o=n.args;if(Bs(i.parameters)){let e=i.parameters[`~standard`].validate(n.args),r=Vs(e)?await Hs(e,t):e;if(r===zs)return Us();r.issues?a=i.experimental_onSchemaValidationError??(()=>{throw Error(`Function parameter validation failed. ${JSON.stringify(r.issues)}`)}):o=r.value}if(t.aborted)return Us();let s=await Hs((async()=>{let e={toolCallId:n.toolCallId,abortSignal:t,human:e=>r(n.toolCallId,e,n.executionId),[Rs]:n.executionId},s=await a(o,e),c=as.toResponse(s);if(i.toModelOutput&&!c.isError&&c.modelContent===void 0)try{let e=await i.toModelOutput({toolCallId:n.toolCallId,input:o,output:c.result});return new as({result:c.result,artifact:c.artifact,isError:c.isError,messages:c.messages,modelContent:e})}catch(e){console.warn(`[assistant-stream] tool "${n.toolName}" toModelOutput threw; falling back to default projection.`,e)}return c})(),t,!0);return s===zs?Us():s})(i.execute):void 0}function Gs(e,t,n,r,i){let a={toolCallId:r.toolCallId,abortSignal:t,human:e=>i(r.toolCallId,e,r.executionId),[Rs]:r.executionId};return e?.[r.toolName]?.streamCall?.(n,a)}function Ks(e,t,n,r){let i=typeof e==`function`?e:()=>e,a=typeof t==`function`?t:()=>t,o=r,s=n;return new Ls({execute:e=>Ws(i(),a(),e,s),streamCall:({reader:e,...t})=>Gs(i(),a(),e,t,s),onExecutionStart:o?.onExecutionStart,onExecutionEnd:o?.onExecutionEnd})}var qs=Symbol.for(`assistant-ui.message-not-sent`),Js=class extends Error{[qs]=!0;constructor(e=`The message was not sent.`){super(e),this.name=`MessageNotSentError`}},Ys=e=>typeof e==`object`&&!!e&&qs in e,Xs=`application/octet-stream`;function Zs(e,t=Xs){let n=e.match(/^data:([^;,]*)(?:;[^;,]+)*;base64,(.*)$/i);return n?{mimeType:n[1]?n[1].toLowerCase():t,data:n[2].replace(/%([\da-f]{2})/gi,(e,t)=>String.fromCharCode(Number.parseInt(t,16)))}:null}var Qs={entries:32,payloadLength:16384,logLength:65536},$s=64,ec=e=>{let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null},tc=(e,t,n)=>{if(e===null)return!0;switch(typeof e){case`string`:case`boolean`:return!0;case`number`:return Number.isFinite(e);case`object`:break;default:return!1}if(n>$s||t.has(e))return!1;t.add(e);let r=Array.isArray(e)?e.every(e=>tc(e,t,n+1)):ec(e)&&Object.values(e).every(e=>tc(e,t,n+1));return t.delete(e),r},nc=e=>typeof e==`object`&&!!e&&!Array.isArray(e),rc=e=>e===`action`||e===`human-response`;function ic(e,t=Date.now()){let{type:n,payload:r}=e;if(!rc(n))throw Error(`Unknown tool interaction type: ${String(n)}`);if(!tc(r,new Set,0))throw Error(`A tool interaction payload must be plain JSON.`);if(n===`action`&&!nc(r))throw Error(`An action interaction payload must be a JSON object.`);let i=JSON.stringify(r);if(i.length>Qs.payloadLength)throw Error(`A tool interaction payload is limited to ${Qs.payloadLength} characters of JSON.`);return{type:n,occurredAt:t,payload:JSON.parse(i)}}function ac(e,t){let n=[...e?.entries??[],t],r=e?.omitted??0;for(;n.length>1&&(n.length>Qs.entries||JSON.stringify(n).length>Qs.logLength);)n.shift(),r+=1;return r>0?{entries:n,omitted:r}:{entries:n}}var oc=e=>{if(!nc(e))return;let{type:t,occurredAt:n,payload:r}=e;if(rc(t)&&typeof n==`number`&&Number.isFinite(n)&&tc(r,new Set,0))return t===`action`?nc(r)?{type:t,occurredAt:n,payload:r}:void 0:{type:t,occurredAt:n,payload:r}};function sc(e){if(!nc(e))return;let{entries:t,omitted:n}=e,r=Array.isArray(t)?t.flatMap(e=>{let t=oc(e);return t?[t]:[]}):[],i=typeof n==`number`&&Number.isInteger(n)&&n>0?n:0;for(;r.length>1&&(r.length>Qs.entries||JSON.stringify(r).length>Qs.logLength);)r.shift(),i+=1;if(r.length!==0||i!==0)return i>0?{entries:r,omitted:i}:{entries:r}}var cc=(e,t,n)=>{if(e?.startsWith(`data-`))return{type:`data`,name:e.substring(5),data:t,...typeof n==`string`&&{id:n}}},lc=(e,t,n)=>{let{role:r,id:i,createdAt:a,attachments:o,status:s,metadata:c}=e,l={id:i??t,createdAt:a??new Date},u=typeof e.content==`string`?[{type:`text`,text:e.content}]:e.content,d=({image:e,...t})=>typeof e==`string`?Zs(e)?.mimeType.startsWith(`image/`)||/^(https:\/\/|blob:)/i.test(e)?{...t,image:e}:(console.warn(`Invalid image data format detected`),null):null;if(r!==`user`&&o?.length)throw Error(`attachments are only supported for user messages`);if(r!==`assistant`&&s)throw Error(`status is only supported for assistant messages`);if(r!==`assistant`&&c?.steps)throw Error(`metadata.steps is only supported for assistant messages`);switch(r){case`assistant`:return{...l,role:r,content:u.map(e=>{let t=e.type;switch(t){case`text`:return e.text?.trim()?e:null;case`reasoning`:return!e.text?.trim()&&!e.unstable_summary?.trim()?null:e.text==null?{...e,text:``}:e;case`file`:case`source`:return e;case`image`:return d(e);case`data`:return e;case`generative-ui`:return e;case`tool-call`:{let{parentId:t,messages:n,unstable_interactions:r,...i}=e,a=sc(r),o={...i,toolCallId:e.toolCallId||`tool-${h()}`,...t!==void 0&&{parentId:t},...n!==void 0&&{messages:n},...a!==void 0&&{unstable_interactions:a}};return e.args?{...o,args:e.args,argsText:e.argsText??JSON.stringify(e.args)}:{...o,args:go(e.argsText??``)??{},argsText:e.argsText??``}}case`audio`:throw Error(`Unsupported assistant message part type: ${t}`);default:{let n=t,r=cc(n,e.data,e.id);if(r)return r;throw Error(`Unsupported assistant message part type: ${n}`)}}}).filter(e=>!!e),status:s??n,metadata:{...c?.runId!==void 0&&{runId:c.runId},unstable_state:c?.unstable_state??null,unstable_annotations:c?.unstable_annotations??[],unstable_data:c?.unstable_data??[],custom:c?.custom??{},steps:c?.steps??[],...c?.timing&&{timing:c.timing},...c?.submittedFeedback&&{submittedFeedback:c.submittedFeedback},...c?.isOptimistic&&{isOptimistic:!0},...c?.modality&&{modality:c.modality}}};case`user`:return{...l,role:r,content:u.filter(e=>e.type!==`text`||e.text!=null).map(e=>{let t=e.type;switch(t){case`text`:case`image`:case`audio`:case`file`:case`data`:return e;case`reasoning`:case`source`:case`generative-ui`:case`tool-call`:throw Error(`Unsupported user message part type: ${t}`);default:{let n=t,r=cc(n,e.data,e.id);if(r)return r;throw Error(`Unsupported user message part type: ${n}`)}}}),attachments:(o??[]).map(e=>({...e,content:(e.content??[]).map(e=>cc(e.type,e.data,`id`in e?e.id:void 0)??e)})),metadata:{custom:c?.custom??{},...c?.isOptimistic&&{isOptimistic:!0},...c?.modality&&{modality:c.modality}}};case`system`:if(u.length!==1||u[0].type!==`text`)throw Error(`System messages must have exactly one text message part.`);return{...l,role:r,content:u,metadata:{custom:c?.custom??{}}};default:throw Error(`Unknown message role: ${r}`)}},uc=Symbol(`innerMessage`),dc=Symbol(`innerMessages`),fc=[],pc=(e,t)=>{uc in e||(e[uc]=t)},mc=e=>{let t=`messages`in e&&!(`type`in e&&e.type===`tool-call`)?e.messages:e,n=t[dc]||t[uc];return n?Array.isArray(n)?n:(t[dc]=[n],t[dc]):fc},hc=`__external_store_fallback_`,gc=(e,t)=>{let n=new Set,r=[];for(let i=e.length-1;i>=0;i--){let a=e[i];n.has(a.id)?t(a.id):(n.add(a.id),r.push(a))}return r.length===e.length?e:r.reverse()},_c=Object.freeze({type:`complete`}),vc=Object.freeze({type:`running`}),yc=Object.freeze({cancelled:Object.freeze({type:`incomplete`,reason:`cancelled`}),length:Object.freeze({type:`incomplete`,reason:`length`}),"content-filter":Object.freeze({type:`incomplete`,reason:`content-filter`}),other:Object.freeze({type:`incomplete`,reason:`other`}),error:Object.freeze({type:`incomplete`,reason:`error`})}),bc=e=>{let t=e.status;if(!t||typeof t!=`object`)return;let{type:n}=t;if(n===`running`)return vc;if(n===`complete`)return _c;if(n!==`incomplete`)return;let{reason:r}=t;return yc[r===`cancelled`||r===`length`||r===`content-filter`||r===`other`||r===`error`?r:`other`]},xc=e=>e.interrupt!=null||e.approval!=null&&e.approval.approved===void 0&&e.approval.resolution===void 0,Sc=(e,t,n)=>{if(e.role!==`assistant`)return _c;if(n.type===`tool-call`)return n.result===void 0||n.isPreliminary||xc(n)?e.status:_c;if(e.status.type===`running`){let e=bc(n);if(e)return e}let r=t===Math.max(0,e.content.length-1);return e.status.type===`requires-action`?_c:r?e.status:_c},Cc=e=>e.type===`tool-call`&&e.result===void 0,wc=e=>{if(e.type!==`tool-call`||e.result!==void 0)return!1;let t=e.messages?.at(-1);return t?.role===`assistant`&&t.status.type===`running`},Tc=e=>e.type===`tool-call`&&xc(e),Ec=Symbol(`autoStatus`),Dc=Object.freeze(Object.assign({type:`running`},{[Ec]:!0})),Oc=Object.freeze(Object.assign({type:`complete`,reason:`unknown`},{[Ec]:!0})),kc=Object.freeze(Object.assign({type:`incomplete`,reason:`cancelled`},{[Ec]:!0})),Ac=Object.freeze(Object.assign({type:`requires-action`,reason:`tool-calls`},{[Ec]:!0})),jc=Object.freeze(Object.assign({type:`requires-action`,reason:`interrupt`},{[Ec]:!0})),Mc=e=>e[Ec]===!0,Nc=(e,t,n,r,i,a,o)=>e&&i!=null?Object.assign({type:`incomplete`,reason:`error`,error:i},{[Ec]:!0}):e&&t?Dc:n?jc:o&&!a?Dc:r?Ac:a?kc:Oc,Pc=e=>Nc(!1,!1,typeof e!=`string`&&e.some(Tc),typeof e!=`string`&&e.some(Cc)),Fc=(e,t,n)=>Nc(t,n,typeof e!=`string`&&e.some(Tc),typeof e!=`string`&&e.some(Cc),void 0,void 0,typeof e!=`string`&&e.some(wc)),Ic={fromArray:e=>{let t=e.map(e=>lc(e,e.id??h(),Pc(e.content)));return{messages:t.map((e,n)=>({parentId:n>0?t[n-1].id:null,message:e}))}},fromBranchableArray:(e,t)=>({...t?.headId===void 0?void 0:{headId:t.headId},messages:e.map(({message:e,parentId:t})=>{if(!e.id)throw Error(`ExportedMessageRepository.fromBranchableArray: Each message must have an 'id' field set.`);return{parentId:t,message:lc(e,e.id,Pc(e.content))}})})},Lc=e=>{let t=e;for(;t.next;)t=t.next;return`current`in t?t:null},Rc=(e,t)=>{let n=new Set(e.map(e=>e.message.id)),r=new Set,i=new Map,a=[];for(let o of e){let{parentId:e}=o;if(e!==null&&n.has(e)&&!r.has(e)&&!t(e)){let t=i.get(e);t?t.push(o):i.set(e,[o])}else for(let e=a.push(o)-1;e<a.length;e++){let{id:t}=a[e].message;if(r.has(t))continue;r.add(t);let n=i.get(t);n&&(i.delete(t),a.push(...n))}}for(let e of i.values())a.push(...e);return a},zc=class{_value=null;func;constructor(e){this.func=e}get value(){return this._value===null&&(this._value=this.func()),this._value}dirty(){this._value=null}},Bc=class{messages=new Map;head=null;root={children:[],next:null};updateLevels(e,t){let n=[{message:e,level:t}];for(;n.length>0;){let e=n.pop();e.message.level=e.level;for(let t of e.message.children){let r=this.messages.get(t);r&&n.push({message:r,level:e.level+1})}}}selectPathTo(e){for(let t=e;t;t=t.prev)(t.prev??this.root).next=t}performOp(e,t,n){let r=t.prev??this.root,i=e??this.root;if(n!==`relink`||r!==i){if(n===`relink`){for(let n=e;n;n=n.prev)if(n.current.id===t.current.id)throw Error(`MessageRepository(performOp/relink): A message with the same id already exists in the parent tree. This error occurs if the same message id is found multiple times. This is likely an internal bug in assistant-ui.`)}if(n!==`link`&&(r.children=r.children.filter(e=>e!==t.current.id),r.next===t)){let e=r.children.at(-1),t=e?this.messages.get(e):null;if(t===void 0)throw Error(`MessageRepository(performOp/cut): Fallback sibling message not found. This is likely an internal bug in assistant-ui.`);r.next=t}if(n!==`cut`){i.children=[...i.children,t.current.id],t.prev=e,Lc(t)===this.head?this.selectPathTo(t):i.next===null&&(i.next=t,this.head===i&&(this.head=Lc(t)));let n=e?e.level+1:0;this.updateLevels(t,n)}}}_messages=new zc(()=>{let e=Array((this.head?.level??-1)+1);for(let t=this.head;t;t=t.prev)e[t.level]=t.current;return e});get headId(){return this.head?.current.id??null}get canonicalHeadId(){let e=this.head;for(;e?.current.metadata?.isOptimistic;)e=e.prev;return e?.current.id??null}getMessages(e){if(e===void 0||e===this.head?.current.id)return this._messages.value;let t=this.messages.get(e);if(!t)throw Error(`MessageRepository(getMessages): Head message not found. This is likely an internal bug in assistant-ui.`);let n=Array(t.level+1);for(let e=t;e;e=e.prev)n[e.level]=e.current;return n}addOrUpdateMessage(e,t){let n=this.messages.get(t.id),r=e?this.messages.get(e):null;if(r===void 0)throw Error(`MessageRepository(addOrUpdateMessage): Parent message not found. This is likely an internal bug in assistant-ui.`);if(n){this.performOp(r,n,`relink`),n.current=t,this._messages.dirty();return}let i={prev:r,current:t,next:null,children:[],level:r?r.level+1:0};this.messages.set(t.id,i),this.performOp(r,i,`link`),this.head===r&&(this.head=i,this.selectPathTo(i)),this._messages.dirty()}getMessage(e){let t=this.messages.get(e);if(!t)throw Error(`MessageRepository(updateMessage): Message not found. This is likely an internal bug in assistant-ui.`);return{parentId:t.prev?.current.id??null,message:t.current,index:t.level}}deleteMessage(e,t){let n=this.messages.get(e);if(!n)throw Error(`MessageRepository(deleteMessage): Message not found. This is likely an internal bug in assistant-ui.`);let r=t===void 0?n.prev:t===null?null:this.messages.get(t);if(r===void 0)throw Error(`MessageRepository(deleteMessage): Replacement not found. This is likely an internal bug in assistant-ui.`);for(let e=r;e;e=e.prev)if(e===n)throw Error(`MessageRepository(deleteMessage): Replacement is the deleted message or one of its descendants. This is likely an internal bug in assistant-ui.`);for(let e of n.children){let t=this.messages.get(e);if(!t)throw Error(`MessageRepository(deleteMessage): Child message not found. This is likely an internal bug in assistant-ui.`);this.performOp(r,t,`relink`)}this.performOp(null,n,`cut`),this.messages.delete(e),this.head===n&&(this.head=Lc(r??this.root)),this._messages.dirty()}hasChildren(e){return(this.messages.get(e)?.children.length??0)>0}getBranches(e){let t=this.messages.get(e);if(!t)throw Error(`MessageRepository(getBranches): Message not found. This is likely an internal bug in assistant-ui.`);let{children:n}=t.prev??this.root;return n}evictOffBranchOptimisticMessages(e,t){if(!e)return;let n=new Set;for(let e=t;e;e=e.prev)n.add(e.current.id);let r=[];for(let t=e;t&&!n.has(t.current.id);t=t.prev)t.current.metadata?.isOptimistic&&r.push(t.current.id);for(let e of r)this.messages.has(e)&&this.deleteMessage(e)}switchToBranch(e){let t=this.messages.get(e);if(!t)throw Error(`MessageRepository(switchToBranch): Branch not found. This is likely an internal bug in assistant-ui.`);let n=this.head;this.selectPathTo(t),this.head=Lc(t),this.evictOffBranchOptimisticMessages(n,this.head),this._messages.dirty()}setHead(e,t){if(e===null){this.clear();return}let n=this.messages.get(e);if(!n)throw Error(`MessageRepository(${t?`resetHead`:`import`}): Branch not found. This is likely an internal bug in assistant-ui.`);let r=this.head;if(t&&n.children.length>0){let e=[...n.children];for(;e.length>0;){let t=e.pop(),n=this.messages.get(t);if(n){for(let t of n.children)e.push(t);this.messages.delete(t)}}n.children=[],n.next=null}this.head=n,this.selectPathTo(n),this.evictOffBranchOptimisticMessages(r,this.head),this._messages.dirty()}resetHead(e){this.setHead(e,!0)}clear(){this.messages.clear(),this.head=null,this.root={children:[],next:null},this._messages.dirty()}export(){let e=[],t=[...this.root.children].reverse();for(;t.length>0;){let n=this.messages.get(t.pop());if(!n)continue;for(let e=n.children.length-1;e>=0;e--)t.push(n.children[e]);if(n.current.metadata?.isOptimistic)continue;let r=n.prev;for(;r&&r.current.metadata?.isOptimistic;)r=r.prev;e.push({message:n.current,parentId:r?.current.id??null})}return{headId:this.exportedHeadId(),messages:e}}exportedHeadId(){let e=this.head;for(;e?.current.metadata?.isOptimistic;)e=e.prev;if(e===this.head)return e?.current.id??null;for(;;){let t=this.exportedChild(e??this.root);if(!t)return e?.current.id??null;e=t}}exportedChild(e){let t=e.next;if(t){if(!t.current.metadata?.isOptimistic)return t;let e=this.exportedChild(t);if(e)return e}let n=t?e.children.indexOf(t.current.id):e.children.length,r=[...e.children.slice(0,n).reverse(),...e.children.slice(n+1).reverse()];for(let e of r){let t=this.messages.get(e);if(!t)continue;if(!t.current.metadata?.isOptimistic)return t;let n=this.exportedChild(t);if(n)return n}return null}import({headId:e,messages:t}){let n=Rc(t,e=>this.messages.has(e));for(let{message:e,parentId:t}of n)this.addOrUpdateMessage(t,e);let r=e??n.at(-1)?.message.id??null;this.setHead(r,!1)}},Vc=Object.freeze([]),Hc=new WeakMap,Uc=e=>{let t=e.__internal_setDispatchTransform;t&&Hc.get(t)?.bindNext()},Wc=e=>{let t=e.__internal_setDispatchTransform;return t?Hc.get(t)?.getCurrent():void 0},Gc=hr(()=>{let e=G(4),[t,n]=H(Kc),r;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(r=(e,t)=>(n(n=>{let r=k(n.renderers);return r[e]=[...r[e]??[],t],{...n,renderers:r}}),()=>{n(n=>{let r=k(n.renderers),i=r[e]?.filter(e=>e!==t)??[];return i.length>0?r[e]=i:delete r[e],{...n,renderers:r}})}),e[0]=r):r=e[0];let i=r,a;e[1]===Symbol.for(`react.memo_cache_sentinel`)?(a=e=>(n(t=>({...t,fallbacks:[...t.fallbacks,e]})),()=>{n(t=>({...t,fallbacks:t.fallbacks.filter(t=>t!==e)}))}),e[1]=a):a=e[1];let o=a,s;return e[2]===t?s=e[3]:(s={getState:()=>t,setDataUI:i,setFallbackDataUI:o},e[2]=t,e[3]=s),s});function Kc(){return{renderers:k(),fallbacks:[]}}var qc=()=>()=>{},Jc=()=>Zt(qc,Xc,Zc),Yc=(e,t)=>{(Jc()?W:Yt)(e,t)};function Xc(){return!1}function Zc(){return typeof document>`u`}var Qc=(e,t)=>e.length===t.length&&e.every((e,n)=>Object.is(e,t[n])),$c=(e,t)=>{let[n]=H(()=>({pending:void 0}));W(()=>{let r=n.pending;n.pending=void 0;let i;return r!==void 0&&Qc(r.deps,t)?i=r:(r?.cleanup?.(),i={deps:t,cleanup:e()}),()=>{n.pending=i,queueMicrotask(()=>{n.pending===i&&(n.pending=void 0,i.cleanup?.())})}},t)},el=[],tl={modelName:void 0,toolNames:el},nl=(e,t)=>e===t||Fi(e,t),rl=(e,t)=>{let n=e.getModelContext(),r=n.config?.modelName,i=n.tools?Object.keys(n.tools).sort():el,a=i.length?i:el;return r===t.modelName&&nl(a,t.toolNames)?t:{modelName:r,toolNames:a}},il=hr((e={})=>{let t=U(e);$t(()=>{t.current=e});let n=qt(()=>new ro(()=>t.current),[]),{maxSystemLength:r,mergeSystem:i}=e,a=U({maxSystemLength:r,mergeSystem:i});W(()=>{let e=a.current;(e.maxSystemLength!==r||e.mergeSystem!==i)&&(a.current={maxSystemLength:r,mergeSystem:i},n.notifySubscribers())},[n,r,i]);let[o,s]=H(()=>rl(n,tl));return W(()=>(s(e=>rl(n,e)),n.subscribe(()=>{s(e=>rl(n,e))})),[n]),{getState:()=>rl(n,o),getModelContext:()=>n.getModelContext(),subscribe:e=>n.subscribe(e),register:e=>n.registerModelContextProvider(e)}}),al=(e,t)=>{if(t.status?.type!==`running`&&t.status?.type!==`requires-action`){let n=e.complete;return typeof n==`function`?n({args:t.args,result:t.result}):n??null}let n=e.running;return typeof n==`function`?n({args:t.args}):n??null},ol=e=>e.display===void 0?e.type===`human`:e.display===`standalone`,sl=e=>function(t){return al(e,t)},cl=e=>{let t=G(16),{toolkit:n,mcpApp:r}=e,i;t[0]===r?i=t[1]:(i=r?[gr(`mcpApp`,r)]:[],t[0]=r,t[1]=i);let a=Cr(i)[0],[o,s]=H(ul),c;t[2]!==a||t[3]!==o?(c={toolUIs:o,mcpApp:a},t[2]=a,t[3]=o,t[4]=c):c=t[4];let l=c,u=$r(),d;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(d=(e,t,n)=>{let r={render:t,renderText:n?.renderText,standalone:n?.standalone??!1};return s(t=>{let n=k(t);return n[e]=[...n[e]??[],r],n}),()=>{s(t=>{let n=t[e]?.filter(e=>e!==r)??[],i=k(t);return n.length>0?(i[e]=n,i):(delete i[e],i)})}},t[5]=d):d=t[5];let f=d,p,m;t[6]===n?(p=t[7],m=t[8]):(p=()=>{if(!n)return;let e=[];for(let[t,r]of Object.entries(n)){let n=`render`in r?r.render:void 0,i=`renderText`in r?r.renderText:void 0,a=n??(i?sl(i):void 0);a&&e.push(f(t,a,{standalone:ol(r),renderText:i}))}return()=>qa(e)},m=[n,f],t[6]=n,t[7]=p,t[8]=m),W(p,m);let h;t[9]!==u||t[10]!==n?(h=()=>{if(!n)return;let e=Object.entries(n).reduce(dl,k());return u.current.modelContext().register({getModelContext:()=>({tools:e})})},t[9]=u,t[10]=n,t[11]=h):h=t[11];let g;t[12]===n?g=t[13]:(g=[n],t[12]=n,t[13]=g),ii(`modelContext`,h,g);let _;return t[14]===l?_=t[15]:(_={getState:()=>l,setToolUI:f},t[14]=l,t[15]=_),_},ll=hr(cl);zr(cl,(e,t)=>{!e.modelContext&&t.modelContext.source===null&&(e.modelContext=il())});function ul(){return k()}function dl(e,t){let[n,r]=t;if(r.type===`mcp`)return e;let{display:i,render:a,renderText:o,...s}=r;return e[n]=s,e}var fl=(e,t)=>(_i(t?.live?e.subscribe:void 0),Zt(e.subscribe,e.getState,e.getServerSnapshot)),pl=Symbol.for(`assistant-ui.silent-runtime-action`),ml=e=>typeof e==`object`&&!!e&&pl in e,hl=(e,t)=>{let n=t();return n.catch(t=>{ml(t)||console.error(`[assistant-ui] ${e} failed:`,t)}),n},gl=hr(e=>{let t=G(9),{runtime:n}=e,r=fl(n),i;t[0]===r?i=t[1]:(i=()=>r,t[0]=r,t[1]=i);let a,o;t[2]===n?(a=t[3],o=t[4]):(a=()=>hl(`attachment remove`,n.remove),o=()=>n,t[2]=n,t[3]=a,t[4]=o);let s;return t[5]!==i||t[6]!==a||t[7]!==o?(s={getState:i,remove:a,__internal_getRuntime:o},t[5]=i,t[6]=a,t[7]=o,t[8]=s):s=t[8],s}),_l=hr(({item:e,onMove:t,onRemove:n})=>({getState:()=>e,steer:()=>t({lane:`steer`,insertAfter:null}),move:t,remove:n})),vl=hr(e=>{let t=G(5),{runtime:n,index:r}=e,i;t[0]!==r||t[1]!==n?(i=n.getAttachmentByIndex(r),t[0]=r,t[1]=n,t[2]=i):i=t[2];let a=i,o;return t[3]===a?o=t[4]:(o=gl({runtime:a}),t[3]=a,t[4]=o),vr(o)}),yl=(e,t,n)=>({text:e.text,role:e.role,attachments:t,runConfig:e.runConfig,isEditing:e.isEditing,canCancel:e.canCancel,canSend:e.canSend,attachmentAccept:e.attachmentAccept,isEmpty:e.isEmpty,type:e.type??`thread`,dictation:e.dictation,quote:e.quote,queue:n,submission:e.submission,inTransit:e.inTransit}),bl=(e,t,n)=>{let r,i;return()=>{let a=e.getState();return a===t?n:(a!==r&&(r=a,i=yl(a,n.attachments,n.queue)),i)}},xl=hr(e=>{let t=G(56),{threadIdRef:n,messageIdRef:r,runtime:i,isSuggestion:a}=e,o;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(o={live:!0},t[0]=o):o=t[0];let s=fl(i,o),c=ai(),l=U(!1),u,d;t[1]!==c||t[2]!==r||t[3]!==i||t[4]!==n?(u=()=>{let e=[],t=i.unstable_on(`send`,e=>{let t=l.current;l.current=!1,c(`composer.send`,{threadId:n.current,...r&&{messageId:r.current},chars:e.chars,attachments:e.attachments,...t?{suggestion:!0}:void 0})});e.push(t);let a=i.unstable_on(`attachmentAdd`,e=>{c(`composer.attachmentAdd`,{threadId:n.current,...r&&{messageId:r.current},...e.contentType?{contentType:e.contentType}:void 0})});return e.push(a),e.push(i.unstable_on(`attachmentAddError`,e=>{c(`composer.attachmentAddError`,{threadId:n.current,...r&&{messageId:r.current},...e.attachmentId&&{attachmentId:e.attachmentId},reason:e.reason,message:e.message,...e.contentType?{contentType:e.contentType}:void 0})})),e.push(i.unstable_on(`textChange`,e=>{c(`composer.textChange`,{threadId:n.current,...r&&{messageId:r.current},text:e.text,origin:e.origin})})),()=>qa(e)},d=[i,c,n,r],t[1]=c,t[2]=r,t[3]=i,t[4]=n,t[5]=u,t[6]=d):(u=t[5],d=t[6]),W(u,d);let f;if(t[7]!==i||t[8]!==s.attachments){let e;t[10]===i?e=t[11]:(e=(e,t)=>gr(e.id,vl({runtime:i,index:t}),[i,t]),t[10]=i,t[11]=e),f=s.attachments.map(e),t[7]=i,t[8]=s.attachments,t[9]=f}else f=t[9];let p=Ea(f),m=s.queue,h;if(t[12]!==m||t[13]!==i){let e;t[15]===i?e=t[16]:(e=e=>gr(e.id,_l({item:e,onMove:t=>i.moveQueueItem(e.id,t),onRemove:()=>i.removeQueueItem(e.id)})),t[15]=i,t[16]=e),h=m.map(e),t[12]=m,t[13]=i,t[14]=h}else h=t[14];let g=Ea(h),_;t[17]!==p.state||t[18]!==m||t[19]!==s?(_=yl(s,p.state,m),t[17]=p.state,t[18]=m,t[19]=s,t[20]=_):_=t[20];let v=_,y;t[21]!==i||t[22]!==s||t[23]!==v?(y=bl(i,s,v),t[21]=i,t[22]=s,t[23]=v,t[24]=y):y=t[24];let b=y,x;t[25]!==a||t[26]!==i?(x=e=>{let t=i.getState();l.current=t.canSend&&(a?.(t.text)??!1),i.send(e)},t[25]=a,t[26]=i,t[27]=x):x=t[27];let S;t[28]!==c||t[29]!==r||t[30]!==i||t[31]!==n?(S=()=>{!r&&i.getState().canCancel&&c(`composer.cancel`,{threadId:n.current}),i.cancel()},t[28]=c,t[29]=r,t[30]=i,t[31]=n,t[32]=S):S=t[32];let C=i.beginEdit??Sl,w;t[33]===p?w=t[34]:(w=e=>`id`in e?p.get({key:e.id}):p.get(e),t[33]=p,t[34]=w);let T;t[35]===g?T=t[36]:(T=e=>`id`in e?g.get({key:e.id}):g.get(e),t[35]=g,t[36]=T);let E;t[37]===i?E=t[38]:(E=()=>i,t[37]=i,t[38]=E);let D;return t[39]!==b||t[40]!==i.addAttachment||t[41]!==i.clearAttachments||t[42]!==i.reset||t[43]!==i.setQuote||t[44]!==i.setRole||t[45]!==i.setRunConfig||t[46]!==i.setText||t[47]!==i.startDictation||t[48]!==i.stopDictation||t[49]!==C||t[50]!==w||t[51]!==T||t[52]!==E||t[53]!==x||t[54]!==S?(D={getState:b,setText:i.setText,setRole:i.setRole,setRunConfig:i.setRunConfig,addAttachment:i.addAttachment,reset:i.reset,clearAttachments:i.clearAttachments,send:x,cancel:S,beginEdit:C,startDictation:i.startDictation,stopDictation:i.stopDictation,setQuote:i.setQuote,attachment:w,queueItem:T,__internal_getRuntime:E},t[39]=b,t[40]=i.addAttachment,t[41]=i.clearAttachments,t[42]=i.reset,t[43]=i.setQuote,t[44]=i.setRole,t[45]=i.setRunConfig,t[46]=i.setText,t[47]=i.startDictation,t[48]=i.stopDictation,t[49]=C,t[50]=w,t[51]=T,t[52]=E,t[53]=x,t[54]=S,t[55]=D):D=t[55],D});function Sl(){throw Error(`beginEdit is not supported in this runtime`)}var Cl=e=>({get current(){return e()}}),wl=new WeakMap,Tl=e=>{let t=wl.get(e);if(t)return t;let n=new Map,r=e.map(e=>{let t=e.type===`tool-call`?e.toolCallId:`id`in e?e.id:void 0;if(!t)return;let r=`${e.type}:${t}`;return n.set(r,(n.get(r)??0)+1),r}),i=e.map((e,t)=>{let i=r[t];return i&&n.get(i)===1?i:`${e.type}@${t}`});return wl.set(e,i),i},El=hr(e=>{let t=G(17),{runtime:n}=e,r=fl(n),i;t[0]===r?i=t[1]:(i=()=>r,t[0]=r,t[1]=i);let a,o,s;t[2]===n?(a=t[3],o=t[4],s=t[5]):(a=e=>n.addToolResult(e),o=e=>n.resumeToolCall(e),s=e=>n.respondToToolApproval(e),t[2]=n,t[3]=a,t[4]=o,t[5]=s);let c;t[6]===n.unstable_recordInteraction?c=t[7]:(c=n.unstable_recordInteraction&&{unstable_recordInteraction:e=>n.unstable_recordInteraction(e)},t[6]=n.unstable_recordInteraction,t[7]=c);let l;t[8]===n?l=t[9]:(l=()=>n,t[8]=n,t[9]=l);let u;return t[10]!==i||t[11]!==a||t[12]!==o||t[13]!==s||t[14]!==c||t[15]!==l?(u={getState:i,addToolResult:a,resumeToolCall:o,respondToToolApproval:s,...c,__internal_getRuntime:l},t[10]=i,t[11]=a,t[12]=o,t[13]=s,t[14]=c,t[15]=l,t[16]=u):u=t[16],u}),Dl=hr(e=>{let t=G(5),{runtime:n,index:r}=e,i;t[0]!==r||t[1]!==n?(i=n.getAttachmentByIndex(r),t[0]=r,t[1]=n,t[2]=i):i=t[2];let a=i,o;return t[3]===a?o=t[4]:(o=gl({runtime:a}),t[3]=a,t[4]=o),vr(o)}),Ol=hr(e=>{let t=G(5),{runtime:n,index:r}=e,i;t[0]!==r||t[1]!==n?(i=n.getMessagePartByIndex(r),t[0]=r,t[1]=n,t[2]=i):i=t[2];let a=i,o;return t[3]===a?o=t[4]:(o=El({runtime:a}),t[3]=a,t[4]=o),vr(o)}),kl=hr(e=>{let t=G(78),{runtime:n,threadIdRef:r,threadId:i,isLast:a}=e,o=fl(n),s=ai(),[c,l]=H(!1),[u,d]=H(!1),f;t[0]===n?f=t[1]:(f=Cl(()=>n.getState().id),t[0]=n,t[1]=f);let p=f,m=U(o.status),h;t[2]!==s||t[3]!==n||t[4]!==i?(h=e=>{s(e,{threadId:i,messageId:n.getState().id})},t[2]=s,t[3]=n,t[4]=i,t[5]=h):h=t[5];let g=h,_,v;t[6]!==s||t[7]!==o.id||t[8]!==o.status||t[9]!==i?(_=()=>{let e=o.status,t=m.current;m.current=e,e?.type===`incomplete`&&e.reason===`error`&&(t?.type!==`incomplete`||t.reason!==`error`)&&s(`message.error`,{threadId:i,messageId:o.id,reason:`error`})},v=[o.status,o.id,s,i],t[6]=s,t[7]=o.id,t[8]=o.status,t[9]=i,t[10]=_,t[11]=v):(_=t[10],v=t[11]),W(_,v);let y;t[12]!==p||t[13]!==n.composer||t[14]!==r?(y=xl({runtime:n.composer,threadIdRef:r,messageIdRef:p}),t[12]=p,t[13]=n.composer,t[14]=r,t[15]=y):y=t[15];let b=wi(y),x;if(t[16]!==n||t[17]!==o.content){let e;t[19]===n?e=t[20]:(e=(e,t)=>gr(e,Ol({runtime:n,index:t}),[n,t]),t[19]=n,t[20]=e),x=Tl(o.content).map(e),t[16]=n,t[17]=o.content,t[18]=x}else x=t[18];let S=Ea(x),C;t[21]===o.attachments?C=t[22]:(C=o.attachments??[],t[21]=o.attachments,t[22]=C);let w;if(t[23]!==n||t[24]!==C){let e;t[26]===n?e=t[27]:(e=(e,t)=>gr(e.id,Dl({runtime:n,index:t}),[n,t]),t[26]=n,t[27]=e),w=C.map(e),t[23]=n,t[24]=C,t[25]=w}else w=t[25];let T=Ea(w),E=o,D;t[28]===a?D=t[29]:(D=a===!1?{isLast:a}:{},t[28]=a,t[29]=D);let O;t[30]!==b.state||t[31]!==c||t[32]!==u||t[33]!==S.state||t[34]!==D||t[35]!==E?(O={...E,...D,parts:S.state,composer:b.state,isCopied:c,isHovering:u},t[30]=b.state,t[31]=c,t[32]=u,t[33]=S.state,t[34]=D,t[35]=E,t[36]=O):O=t[36];let k=O,A;t[37]===k?A=t[38]:(A=()=>k,t[37]=k,t[38]=A);let j;t[39]===b.methods?j=t[40]:(j=()=>b.methods,t[39]=b.methods,t[40]=j);let M;t[41]===n?M=t[42]:(M=()=>n.delete(),t[41]=n,t[42]=M);let N,P;t[43]!==g||t[44]!==n?(N=e=>(g(`message.reload`),n.reload(e)),P=()=>(g(`message.speak`),n.speak()),t[43]=g,t[44]=n,t[45]=N,t[46]=P):(N=t[45],P=t[46]);let F,I;t[47]===n?(F=t[48],I=t[49]):(F=()=>n.stopSpeaking(),I=e=>n.submitFeedback(e),t[47]=n,t[48]=F,t[49]=I);let L;t[50]!==g||t[51]!==n?(L=e=>(g(`message.branchSwitched`),n.switchToBranch(e)),t[50]=g,t[51]=n,t[52]=L):L=t[52];let R;t[53]===n?R=t[54]:(R=()=>n.unstable_getCopyText(),t[53]=n,t[54]=R);let z;t[55]!==S||t[56]!==o.content?(z=e=>{if(`index`in e)return S.get({index:e.index});{let t=o.content.findIndex(t=>t.type===`tool-call`&&t.toolCallId===e.toolCallId);return S.get({index:t})}},t[55]=S,t[56]=o.content,t[57]=z):z=t[57];let ee;t[58]===T?ee=t[59]:(ee=e=>`id`in e?T.get({key:e.id}):T.get(e),t[58]=T,t[59]=ee);let te;t[60]===g?te=t[61]:(te=e=>{e&&g(`message.copied`),l(e)},t[60]=g,t[61]=te);let ne;t[62]===n?ne=t[63]:(ne=()=>n,t[62]=n,t[63]=ne);let B;return t[64]!==A||t[65]!==j||t[66]!==M||t[67]!==N||t[68]!==P||t[69]!==F||t[70]!==I||t[71]!==L||t[72]!==R||t[73]!==z||t[74]!==ee||t[75]!==te||t[76]!==ne?(B={getState:A,composer:j,delete:M,reload:N,speak:P,stopSpeaking:F,submitFeedback:I,switchToBranch:L,getCopyText:R,part:z,attachment:ee,setIsCopied:te,setIsHovering:d,__internal_getRuntime:ne},t[64]=A,t[65]=j,t[66]=M,t[67]=N,t[68]=P,t[69]=F,t[70]=I,t[71]=L,t[72]=R,t[73]=z,t[74]=ee,t[75]=te,t[76]=ne,t[77]=B):B=t[77],B}),Al=hr(e=>{let t=G(7),{type:n}=e,r;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(r=[],t[0]=r):r=t[0];let i;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(i={},t[1]=i):i=t[1];let a;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(a=[],t[2]=a):a=t[2];let o;t[3]===n?o=t[4]:(o={isEditing:!1,isEmpty:!0,text:``,attachmentAccept:`*`,attachments:r,role:`user`,runConfig:i,canCancel:!1,canSend:!1,type:n,dictation:void 0,quote:void 0,queue:a,submission:void 0,inTransit:void 0},t[3]=n,t[4]=o);let s=o,c;return t[5]===s?c=t[6]:(c={getState:()=>s,setText:jl,setRole:Ml,setRunConfig:Nl,addAttachment:Pl,clearAttachments:Fl,attachment:Il,reset:Ll,send:Rl,cancel:zl,startDictation:Bl,stopDictation:Vl,beginEdit:Hl,setQuote:Ul,queueItem:Wl},t[5]=s,t[6]=c),c});function jl(){throw Error(`Not supported`)}function Ml(){throw Error(`Not supported`)}function Nl(){throw Error(`Not supported`)}function Pl(){throw Error(`Not supported`)}function Fl(){throw Error(`Not supported`)}function Il(){throw Error(`Not supported`)}function Ll(){throw Error(`Not supported`)}function Rl(){throw Error(`Not supported`)}function zl(){throw Error(`Not supported`)}function Bl(){throw Error(`Not supported`)}function Vl(){throw Error(`Not supported`)}function Hl(){throw Error(`Not supported`)}function Ul(){throw Error(`Not supported`)}function Wl(){throw Error(`Not supported`)}var Gl=hr(e=>{let t=G(8),{part:n,isMessageRunning:r}=e,i;t[0]!==r||t[1]!==n?(i=r?bc(n)??_c:_c,t[0]=r,t[1]=n,t[2]=i):i=t[2];let a;t[3]!==n||t[4]!==i?(a={...n,status:i},t[3]=n,t[4]=i,t[5]=a):a=t[5];let o=a,s;return t[6]===o?s=t[7]:(s={getState:()=>o,addToolResult:Jl,resumeToolCall:Yl,respondToToolApproval:Xl,unstable_recordInteraction:Zl},t[6]=o,t[7]=s),s}),Kl=hr(({attachment:e})=>({getState:()=>e,remove:()=>{throw Error(`Not supported`)}})),ql=hr(e=>{let t=G(38),{message:n,index:r,isLast:i,branchNumber:a,branchCount:o,submission:s}=e,c=i===void 0||i,l=a===void 0?1:a,u=o===void 0?1:o,[d,f]=H(!1),[p,m]=H(!1),h=n.role===`assistant`&&n.status.type===`running`,g,_;if(t[0]!==h||t[1]!==n.content){let e=Tl(n.content);g=Ea,_=n.content.map((t,n)=>gr(e[n],Gl({part:t,isMessageRunning:h}),[t,h])),t[0]=h,t[1]=n.content,t[2]=g,t[3]=_}else g=t[2],_=t[3];let v=g(_),y;t[4]!==n.attachments||t[5]!==s?.attachments?(y=s?.attachments??n.attachments??[],t[4]=n.attachments,t[5]=s?.attachments,t[6]=y):y=t[6];let b;t[7]===y?b=t[8]:(b=y.map(Ql),t[7]=y,t[8]=b);let x=Ea(b),S;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(S=Al({type:`edit`}),t[9]=S):S=t[9];let C=wi(S),w=C.state,E;t[10]!==u||t[11]!==l||t[12]!==w||t[13]!==r||t[14]!==d||t[15]!==p||t[16]!==c||t[17]!==n||t[18]!==v.state||t[19]!==s?(E={...n,parts:v.state,composer:w,parentId:null,index:r,isLast:c,branchNumber:l,branchCount:u,speech:void 0,isCopied:d,isHovering:p,submission:s},t[10]=u,t[11]=l,t[12]=w,t[13]=r,t[14]=d,t[15]=p,t[16]=c,t[17]=n,t[18]=v.state,t[19]=s,t[20]=E):E=t[20];let D=E,O;t[21]===D?O=t[22]:(O=()=>D,t[21]=D,t[22]=O);let k;t[23]===C.methods?k=t[24]:(k=()=>C.methods,t[23]=C.methods,t[24]=k);let A;t[25]!==n.content||t[26]!==v?(A=e=>`index`in e?v.get({index:e.index}):v.get({index:n.content.findIndex(t=>t.type===`tool-call`&&t.toolCallId===e.toolCallId)}),t[25]=n.content,t[26]=v,t[27]=A):A=t[27];let j;t[28]===x?j=t[29]:(j=e=>`id`in e?x.get({key:e.id}):x.get(e),t[28]=x,t[29]=j);let M;t[30]===n?M=t[31]:(M=()=>T(n),t[30]=n,t[31]=M);let N;return t[32]!==O||t[33]!==k||t[34]!==A||t[35]!==j||t[36]!==M?(N={getState:O,composer:k,part:A,attachment:j,delete:$l,reload:eu,speak:tu,stopSpeaking:nu,submitFeedback:ru,switchToBranch:iu,getCopyText:M,setIsCopied:f,setIsHovering:m},t[32]=O,t[33]=k,t[34]=A,t[35]=j,t[36]=M,t[37]=N):N=t[37],N});function Jl(){throw Error(`Not supported`)}function Yl(){throw Error(`Not supported`)}function Xl(){throw Error(`Not supported`)}async function Zl(){}function Ql(e){return gr(e.id,Kl({attachment:e}),[e])}function $l(){throw Error(`Not supported in ThreadMessageProvider`)}function eu(){throw Error(`Not supported in ThreadMessageProvider`)}function tu(){throw Error(`Not supported in ThreadMessageProvider`)}function nu(){throw Error(`Not supported in ThreadMessageProvider`)}function ru(){throw Error(`Not supported in ThreadMessageProvider`)}function iu(){throw Error(`Not supported in ThreadMessageProvider`)}var au=e=>lc({role:e.role,content:e.role===`system`||e.text?[{type:`text`,text:e.text}]:[],attachments:[],metadata:{custom:{...e.quote?{quote:e.quote}:{}}}},e.id,{type:`complete`,reason:`unknown`}),ou=e=>{let t=qt(()=>({}),[]),n=t.state,r=[];e.suggestions.forEach(e=>{let t=n?.suggestions[r.length];r.push(t&&Fi(t,e)?t:e)});let i=n&&Fi(r,n.suggestions)?n:{suggestions:r};return t.state=i,i},su=hr(e=>({getState:()=>e})),cu=e=>{let t=G(9),n=ou(e),r;t[0]===n.suggestions?r=t[1]:(r=n.suggestions.map(uu),t[0]=n.suggestions,t[1]=r);let i=Ea(r),a;t[2]===n?a=t[3]:(a=()=>n,t[2]=n,t[3]=a);let o;t[4]===i?o=t[5]:(o=e=>{let{index:t}=e;return i.get({index:t})},t[4]=i,t[5]=o);let s;return t[6]!==a||t[7]!==o?(s={getState:a,suggestion:o},t[6]=a,t[7]=o,t[8]=s):s=t[8],s},lu=hr(e=>{let t=G(4),n;t[0]===e?n=t[1]:(n=e.map(du),t[0]=e,t[1]=n);let r;return t[2]===n?r=t[3]:(r={suggestions:n},t[2]=n,t[3]=r),cu(r)});function uu(e,t){return gr(t,su(e),[e])}function du(e){return{title:e.title??e.prompt,label:e.label??``,prompt:e.prompt}}var fu=e=>`reason`in e?e.reason:void 0,pu=e=>`error`in e?e.error:void 0,mu=32,hu=new WeakMap,gu=e=>hu.get(e)??e.id,_u=(e,t,n)=>`status`in e&&e.status?Sc(e,t,n):_c,vu=()=>{let e=[],t=new Map;return n=>{let r=[],i=new Map,a=!0,o=(e,n,s,c)=>{if(!(s>mu))for(let[l,u]of e.entries())for(let[e,d]of u.content.entries()){if(d.type!==`tool-call`||d.messages===void 0)continue;let f=d.messages,p=_u(u,e,d),m=fu(p),h=pu(p),g=`${c}${l}.${e}`,_=t.get(g),v=_?.part===d&&_.statusType===p.type&&_.statusReason===m&&Object.is(_.statusError,h)&&_.messages===f&&_.task.messageId===u.id&&_.task.parentTaskId===n&&_.task.depth===s?_.task:{id:d.toolCallId,toolName:d.toolName,args:d.args,result:d.result,...d.isError===void 0?void 0:{isError:d.isError},status:p,timing:d.timing,messageId:u.id,parentTaskId:n,depth:s,messages:f};v!==_?.task&&(a=!1,hu.set(v,g)),r.push(v),i.set(g,{task:v,part:d,statusType:p.type,statusReason:m,statusError:h,messages:f}),o(f,v.id,s+1,`${g}.`)}};o(n,null,0,``);let s=a&&r.length===e.length&&r.every((t,n)=>t===e[n])?e:r;return e=s,t=i,s}},yu=hr(({task:e})=>({getState:()=>e})),bu=hr(e=>{let t=G(8),{runtime:n,id:r,threadIdRef:i,threadId:a,isLast:o}=e,s;t[0]!==r||t[1]!==n?(s=n.getMessageById(r),t[0]=r,t[1]=n,t[2]=s):s=t[2];let c=s,l;return t[3]!==o||t[4]!==c||t[5]!==a||t[6]!==i?(l=kl({runtime:c,threadIdRef:i,threadId:a,isLast:o}),t[3]=o,t[4]=c,t[5]=a,t[6]=i,t[7]=l):l=t[7],vr(l)}),xu=hr(e=>{let t=G(118),{runtime:n}=e,r=fl(n),i=ai(),a,o;t[0]!==i||t[1]!==n?(a=()=>{let e=[];for(let t of[`runStart`,`runEnd`,`initialize`,`modelContextUpdate`]){let r=n.unstable_on(t,()=>{let e=n.getState()?.threadId||`unknown`;i(`thread.${t}`,{threadId:e})});e.push(r)}return e.push(n.unstable_on(`historyWriteError`,e=>{let t=n.getState()?.threadId||`unknown`;i(`thread.historyWriteError`,{threadId:t,operation:e.operation,messageIds:e.messageIds,message:e.message})}),n.unstable_on(`toolApprovalAnswered`,e=>{let t=n.getState()?.threadId||`unknown`;i(`thread.toolApprovalAnswered`,{threadId:t,...e})})),()=>qa(e)},o=[n,i],t[0]=i,t[1]=n,t[2]=a,t[3]=o):(a=t[2],o=t[3]),W(a,o);let s;t[4]===n?s=t[5]:(s=Cl(()=>n.getState().threadId),t[4]=n,t[5]=s);let c=s,l;t[6]!==i||t[7]!==n?(l=e=>{i(e,{threadId:n.getState().threadId})},t[6]=i,t[7]=n,t[8]=l):l=t[8];let u=l,d;t[9]===n?d=t[10]:(d=e=>n.getState().suggestions.some(t=>t.prompt===e),t[9]=n,t[10]=d);let f=d,p;t[11]!==f||t[12]!==n.composer||t[13]!==c?(p=xl({runtime:n.composer,threadIdRef:c,isSuggestion:f}),t[11]=f,t[12]=n.composer,t[13]=c,t[14]=p):p=t[14];let m=wi(p),h;t[15]===r.suggestions?h=t[16]:(h=lu(r.suggestions),t[15]=r.suggestions,t[16]=h);let g=wi(h),_;t[17]===Symbol.for(`react.memo_cache_sentinel`)?(_=vu(),t[17]=_):_=t[17];let v=_,y;t[18]===r.messages?y=t[19]:(y=v(r.messages),t[18]=r.messages,t[19]=y);let b=y,x;t[20]===b?x=t[21]:(x=b.map(Su),t[20]=b,t[21]=x);let S=Ea(x),C=m.state.submission,w=m.state.inTransit,T;t[22]===w?T=t[23]:(T=w??[],t[22]=w,t[23]=T);let E;t[24]===C?E=t[25]:(E=C?[C]:[],t[24]=C,t[25]=E);let D;t[26]!==T||t[27]!==E?(D=[...T,...E],t[26]=T,t[27]=E,t[28]=D):D=t[28];let O=D,k;t[29]===O?k=t[30]:(k=O.map(au),t[29]=O,t[30]=k);let A=k,j=r.messages.length-1,M;if(t[31]!==j||t[32]!==O||t[33]!==A||t[34]!==n||t[35]!==r.messages||t[36]!==r.threadId||t[37]!==c){let e;t[39]!==j||t[40]!==O.length||t[41]!==n||t[42]!==r.threadId||t[43]!==c?(e=(e,t)=>{let i=t===j&&O.length>0?!1:void 0;return gr(e.id,bu({runtime:n,id:e.id,threadIdRef:c,threadId:r.threadId,isLast:i}),[n,e.id,c,r.threadId,i])},t[39]=j,t[40]=O.length,t[41]=n,t[42]=r.threadId,t[43]=c,t[44]=e):e=t[44];let i=r.messages.map(e),a;t[45]!==O||t[46]!==A||t[47]!==r.messages.length?(a=O.map((e,t)=>gr(e.id,ql({message:A[t],submission:e,index:r.messages.length+t,isLast:t===O.length-1}),[A[t],e,r.messages.length,t,O.length])),t[45]=O,t[46]=A,t[47]=r.messages.length,t[48]=a):a=t[48],M=[...i,...a],t[31]=j,t[32]=O,t[33]=A,t[34]=n,t[35]=r.messages,t[36]=r.threadId,t[37]=c,t[38]=M}else M=t[38];let N=Ea(M),P=N.state.length===0&&!r.isLoading,F=r.canResume??!1,I;t[49]!==m.state||t[50]!==N.state||t[51]!==r.capabilities||t[52]!==r.extras||t[53]!==r.hasEarlier||t[54]!==r.isDisabled||t[55]!==r.isLoading||t[56]!==r.isLoadingEarlier||t[57]!==r.isRunning||t[58]!==r.isSendDisabled||t[59]!==r.speech||t[60]!==r.state||t[61]!==r.suggestions||t[62]!==r.voice||t[63]!==P||t[64]!==F||t[65]!==b?(I={isEmpty:P,isDisabled:r.isDisabled,isSendDisabled:r.isSendDisabled,isLoading:r.isLoading,hasEarlier:r.hasEarlier,isLoadingEarlier:r.isLoadingEarlier,isRunning:r.isRunning,canResume:F,capabilities:r.capabilities,state:r.state,suggestions:r.suggestions,extras:r.extras,speech:r.speech,voice:r.voice,composer:m.state,messages:N.state,tasks:b},t[49]=m.state,t[50]=N.state,t[51]=r.capabilities,t[52]=r.extras,t[53]=r.hasEarlier,t[54]=r.isDisabled,t[55]=r.isLoading,t[56]=r.isLoadingEarlier,t[57]=r.isRunning,t[58]=r.isSendDisabled,t[59]=r.speech,t[60]=r.state,t[61]=r.suggestions,t[62]=r.voice,t[63]=P,t[64]=F,t[65]=b,t[66]=I):I=t[66];let L=I,R;t[67]===L?R=t[68]:(R=()=>L,t[67]=L,t[68]=R);let z;t[69]===m.methods?z=t[70]:(z=()=>m.methods,t[69]=m.methods,t[70]=z);let ee;t[71]===g?ee=t[72]:(ee=()=>g.methods,t[71]=g,t[72]=ee);let te;t[73]!==S||t[74]!==b?(te=e=>{if(`id`in e){let t=b.find(t=>t.id===e.id);return S.get({key:t?gu(t):e.id})}return S.get(e)},t[73]=S,t[74]=b,t[75]=te):te=t[75];let ne;t[76]!==i||t[77]!==f||t[78]!==n?(ne=e=>{let t=typeof e==`string`?{content:[{type:`text`,text:e}]}:e;if((t.role??`user`)===`user`){let e=t.content.map(Cu).join(``);i(`composer.send`,{threadId:n.getState().threadId,chars:e.length,attachments:t.attachments?.length??0,...f(e)?{suggestion:!0}:void 0})}n.append(e)},t[76]=i,t[77]=f,t[78]=n,t[79]=ne):ne=t[79];let B;t[80]!==u||t[81]!==n||t[82]!==r.isRunning?(B=()=>{r.isRunning&&u(`thread.cancelRun`),n.cancelRun()},t[80]=u,t[81]=n,t[82]=r.isRunning,t[83]=B):B=t[83];let re;t[84]===n?re=t[85]:(re=()=>n.loadEarlier(),t[84]=n,t[85]=re);let ie;t[86]!==u||t[87]!==n?(ie=()=>{n.connectVoice(),u(`thread.voiceStarted`)},t[86]=u,t[87]=n,t[88]=ie):ie=t[88];let V;t[89]===N?V=t[90]:(V=e=>`id`in e?N.get({key:e.id}):N.get(e),t[89]=N,t[90]=V);let ae;t[91]===n?ae=t[92]:(ae=()=>n,t[91]=n,t[92]=ae);let oe;return t[93]!==n.deleteMessage||t[94]!==n.disconnectVoice||t[95]!==n.export||t[96]!==n.getModelContext||t[97]!==n.getVoiceVolume||t[98]!==n.import||t[99]!==n.importExternalState||t[100]!==n.muteVoice||t[101]!==n.reset||t[102]!==n.resumeRun||t[103]!==n.startRun||t[104]!==n.stopSpeaking||t[105]!==n.subscribeVoiceVolume||t[106]!==n.unmuteVoice||t[107]!==R||t[108]!==z||t[109]!==ee||t[110]!==te||t[111]!==ne||t[112]!==B||t[113]!==re||t[114]!==ie||t[115]!==V||t[116]!==ae?(oe={getState:R,composer:z,suggestions:ee,task:te,append:ne,deleteMessage:n.deleteMessage,startRun:n.startRun,resumeRun:n.resumeRun,importExternalState:n.importExternalState,cancelRun:B,loadEarlier:re,getModelContext:n.getModelContext,export:n.export,import:n.import,reset:n.reset,stopSpeaking:n.stopSpeaking,connectVoice:ie,disconnectVoice:n.disconnectVoice,getVoiceVolume:n.getVoiceVolume,subscribeVoiceVolume:n.subscribeVoiceVolume,muteVoice:n.muteVoice,unmuteVoice:n.unmuteVoice,message:V,__internal_getRuntime:ae},t[93]=n.deleteMessage,t[94]=n.disconnectVoice,t[95]=n.export,t[96]=n.getModelContext,t[97]=n.getVoiceVolume,t[98]=n.import,t[99]=n.importExternalState,t[100]=n.muteVoice,t[101]=n.reset,t[102]=n.resumeRun,t[103]=n.startRun,t[104]=n.stopSpeaking,t[105]=n.subscribeVoiceVolume,t[106]=n.unmuteVoice,t[107]=R,t[108]=z,t[109]=ee,t[110]=te,t[111]=ne,t[112]=B,t[113]=re,t[114]=ie,t[115]=V,t[116]=ae,t[117]=oe):oe=t[117],oe});function Su(e){return gr(gu(e),yu({task:e}),[e])}function Cu(e){return e.type===`text`?e.text:``}var wu=e=>{let t=G(4),n=ai(),r=U(e),i,a;t[0]!==n||t[1]!==e?(i=()=>{let t=r.current;t!==e&&(r.current=e,n(`threads.selectionChanged`,{threadId:e,previousThreadId:t}))},a=[e,n],t[0]=n,t[1]=e,t[2]=i,t[3]=a):(i=t[2],a=t[3]),W(i,a)},Tu=(e,t,n)=>{let r=G(8),i=n===void 0?t:n,a=ai(),o=t&&i,s;r[0]!==o||r[1]!==e?(s={isMain:o,threadId:e},r[0]=o,r[1]=e,r[2]=s):s=r[2];let c=U(s),l,u;r[3]!==a||r[4]!==t||r[5]!==e?(l=()=>{let n=c.current;(n.isMain!==t||n.threadId!==e)&&(c.current={isMain:t,threadId:e},a(t?`threadListItem.switchedTo`:`threadListItem.switchedAway`,{threadId:e}))},u=[t,e,a],r[3]=a,r[4]=t,r[5]=e,r[6]=l,r[7]=u):(l=r[6],u=r[7]),W(l,u)},Eu=(e,t)=>hl(`thread list ${e}`,t),Du=hr(e=>{let t=G(27),{runtime:n,mainThreadIsRunning:r}=e,i=r!==void 0&&r,a=fl(n),o;bb0:{let e=a.isRunning||a.isMain&&i;if(e===a.isRunning){o=a;break bb0}let n;t[0]!==e||t[1]!==a?(n={...a,isRunning:e},t[0]=e,t[1]=a,t[2]=n):n=t[2],o=n}let s=o;Tu(a.id,a.isMain);let c;t[3]===s?c=t[4]:(c=()=>s,t[3]=s,t[4]=c);let l,u,d,f,p,m,h;t[5]===n?(l=t[6],u=t[7],d=t[8],f=t[9],p=t[10],m=t[11],h=t[12]):(u=e=>Eu(`switch`,()=>n.switchTo(e)),d=e=>Eu(`rename`,()=>n.rename(e)),f=e=>Eu(`update custom metadata`,()=>n.updateCustom(e)),p=()=>Eu(`archive`,()=>n.archive()),m=()=>Eu(`unarchive`,()=>n.unarchive()),h=()=>Eu(`delete`,()=>n.delete()),l=e=>Eu(`generate title`,()=>n.generateTitle(e)),t[5]=n,t[6]=l,t[7]=u,t[8]=d,t[9]=f,t[10]=p,t[11]=m,t[12]=h);let g;t[13]===n?g=t[14]:(g=()=>n,t[13]=n,t[14]=g);let _;return t[15]!==n.detach||t[16]!==n.initialize||t[17]!==l||t[18]!==g||t[19]!==c||t[20]!==u||t[21]!==d||t[22]!==f||t[23]!==p||t[24]!==m||t[25]!==h?(_={getState:c,switchTo:u,rename:d,updateCustom:f,archive:p,unarchive:m,delete:h,generateTitle:l,initialize:n.initialize,detach:n.detach,__internal_getRuntime:g},t[15]=n.detach,t[16]=n.initialize,t[17]=l,t[18]=g,t[19]=c,t[20]=u,t[21]=d,t[22]=f,t[23]=p,t[24]=m,t[25]=h,t[26]=_):_=t[26],_}),Ou=(e,t)=>{let[n]=H(()=>({committed:void 0,unmounted:!1,waiters:new Set,delayed:new WeakMap}));return W(()=>{if(n.committed={state:e},!Object.is(e,t()))return;let r=[...n.waiters];n.waiters.clear();for(let e of r)e()}),W(()=>(n.unmounted=!1,()=>{n.unmounted=!0,n.committed=void 0;let e=[...n.waiters];n.waiters.clear();for(let t of e)t()}),[n]),Jt(e=>{let r=n.delayed.get(e);if(r)return r;let i=e.then(e=>new Promise(r=>{let i=n.committed;if(n.unmounted||i!==void 0&&Object.is(i.state,t())){r(e);return}let a=()=>{clearTimeout(o),n.waiters.delete(a),r(e)},o=setTimeout(a,100);n.waiters.add(a)}));return n.delayed.set(e,i),i},[n,t])},ku=hr(e=>{let t=G(6),{runtime:n,id:r,mainThreadIsRunning:i}=e,a;t[0]!==r||t[1]!==n?(a=n.getItemById(r),t[0]=r,t[1]=n,t[2]=a):a=t[2];let o=a,s;return t[3]!==i||t[4]!==o?(s=Du({runtime:o,mainThreadIsRunning:i}),t[3]=i,t[4]=o,t[5]=s):s=t[5],vr(s)}),Au=hr(e=>{let t=G(55),{runtime:n,__internal_assistantRuntime:r}=e,i=fl(n),a=Ou(i,n.getState);wu(i.mainThreadId);let o=ai(),s,c;t[0]!==o||t[1]!==n?(s=()=>n.unstable_subscribeThreadEvents(e=>{let{threadId:t,type:r}=e;t!==n.getState().mainThreadId&&o(`thread.${r}`,{threadId:t})}),c=[n,o],t[0]=o,t[1]=n,t[2]=s,t[3]=c):(s=t[2],c=t[3]),W(s,c);let l;t[4]===n.main?l=t[5]:(l=xu({runtime:n.main}),t[4]=n.main,t[5]=l);let u=wi(l),d;t[6]!==u.state||t[7]!==n||t[8]!==i.threadItems?(d=Object.keys(i.threadItems).map(e=>gr(e,ku({runtime:n,id:e,mainThreadIsRunning:u.state.isRunning}),[n,e,u.state.isRunning])),t[6]=u.state,t[7]=n,t[8]=i.threadItems,t[9]=d):d=t[9];let f=Ea(d),p=i.newThreadId??null,m;t[10]!==u.state||t[11]!==i.archivedThreadIds||t[12]!==i.canUnarchive||t[13]!==i.hasMore||t[14]!==i.isLoading||t[15]!==i.isLoadingMore||t[16]!==i.loadError||t[17]!==i.mainThreadId||t[18]!==i.switchError||t[19]!==i.threadIds||t[20]!==p||t[21]!==f.state?(m={canUnarchive:i.canUnarchive,mainThreadId:i.mainThreadId,newThreadId:p,isLoading:i.isLoading,loadError:i.loadError,switchError:i.switchError,isLoadingMore:i.isLoadingMore,hasMore:i.hasMore,threadIds:i.threadIds,archivedThreadIds:i.archivedThreadIds,threadItems:f.state,main:u.state},t[10]=u.state,t[11]=i.archivedThreadIds,t[12]=i.canUnarchive,t[13]=i.hasMore,t[14]=i.isLoading,t[15]=i.isLoadingMore,t[16]=i.loadError,t[17]=i.mainThreadId,t[18]=i.switchError,t[19]=i.threadIds,t[20]=p,t[21]=f.state,t[22]=m):m=t[22];let h=m,g;t[23]===h?g=t[24]:(g=()=>h,t[23]=h,t[24]=g);let _;t[25]===u.methods?_=t[26]:(_=()=>u.methods,t[25]=u.methods,t[26]=_);let v;t[27]!==h||t[28]!==f?(v=e=>{if(e===`main`)return f.get({key:h.mainThreadId});if(`id`in e)return f.get({key:e.id});let{index:t,archived:n}=e,r=n!==void 0&&n?h.archivedThreadIds[t]:h.threadIds[t];return f.get({key:r})},t[27]=h,t[28]=f,t[29]=v):v=t[29];let y,b;t[30]===n?(y=t[31],b=t[32]):(y=(e,t)=>Eu(`switch`,()=>n.switchToThread(e,t)),b=()=>Eu(`create`,()=>n.switchToNewThread()),t[30]=n,t[31]=y,t[32]=b);let x,S;t[33]!==a||t[34]!==n?(x=()=>a(n.getLoadThreadsPromise()),S=()=>a(n.reload()),t[33]=a,t[34]=n,t[35]=x,t[36]=S):(x=t[35],S=t[36]);let C;t[37]===n?C=t[38]:(C=()=>n.reloadMainThread(),t[37]=n,t[38]=C);let w;t[39]!==a||t[40]!==n?(w=()=>a(n.loadMore()),t[39]=a,t[40]=n,t[41]=w):w=t[41];let T;t[42]===r?T=t[43]:(T=()=>r,t[42]=r,t[43]=T);let E;return t[44]!==y||t[45]!==b||t[46]!==x||t[47]!==S||t[48]!==C||t[49]!==w||t[50]!==T||t[51]!==g||t[52]!==_||t[53]!==v?(E={getState:g,thread:_,item:v,switchToThread:y,switchToNewThread:b,getLoadThreadsPromise:x,reload:S,reloadMainThread:C,loadMore:w,__internal_getAssistantRuntime:T},t[44]=y,t[45]=b,t[46]=x,t[47]=S,t[48]=C,t[49]=w,t[50]=T,t[51]=g,t[52]=_,t[53]=v,t[54]=E):E=t[54],E}),ju=(e,t)=>{e.thread??=_a({source:`threads`,query:{type:`main`},get:e=>e.threads.thread(`main`)}),e.threadListItem??=_a({source:`threads`,query:{type:`main`},get:e=>e.threads.item(`main`)}),e.composer??=_a({source:`thread`,query:{},get:e=>e.threads.thread(`main`).composer()}),!e.modelContext&&t.modelContext.source===null&&(e.modelContext=il()),!e.suggestions&&t.suggestions.source===null&&(e.suggestions=_a({source:`thread`,query:{},get:e=>e.thread.suggestions()}))},Mu=e=>{let t=G(7),n=$r(),r;t[0]!==n||t[1]!==e?(r=()=>e.registerModelContextProvider(n.current.modelContext()),t[0]=n,t[1]=e,t[2]=r):r=t[2];let i;t[3]===e?i=t[4]:(i=[e],t[3]=e,t[4]=i),ii(`modelContext`,r,i);let a;return t[5]===e?a=t[6]:(a=Au({runtime:e.threads,__internal_assistantRuntime:e}),t[5]=e,t[6]=a),vr(a)},Nu=hr(Mu);zr(Mu,(e,t)=>{ju(e,t),!e.tools&&t.tools.source===null&&(e.tools=ll({})),!e.dataRenderers&&t.dataRenderers.source===null&&(e.dataRenderers=Gc())});var Pu=e=>{let{children:t,condition:n}=e;return q(n)?t:null};Pu.displayName=`AuiIf`;var Fu=o((e=>{var t=require("react"),n=Symbol.for(`react.element`),r=Symbol.for(`react.fragment`),i=Object.prototype.hasOwnProperty,a=t.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,o={key:!0,ref:!0,__self:!0,__source:!0};function s(e,t,r){var s,c={},l=null,u=null;for(s in r!==void 0&&(l=``+r),t.key!==void 0&&(l=``+t.key),t.ref!==void 0&&(u=t.ref),t)i.call(t,s)&&!o.hasOwnProperty(s)&&(c[s]=t[s]);if(e&&e.defaultProps)for(s in t=e.defaultProps,t)c[s]===void 0&&(c[s]=t[s]);return{$$typeof:n,type:e,key:l,ref:u,props:c,_owner:a.current}}e.Fragment=r,e.jsx=s,e.jsxs=s})),Iu=o((e=>{process.env.NODE_ENV!==`production`&&(function(){"use strict";var t=require("react"),n=Symbol.for(`react.element`),r=Symbol.for(`react.portal`),i=Symbol.for(`react.fragment`),a=Symbol.for(`react.strict_mode`),o=Symbol.for(`react.profiler`),s=Symbol.for(`react.provider`),c=Symbol.for(`react.context`),l=Symbol.for(`react.forward_ref`),u=Symbol.for(`react.suspense`),d=Symbol.for(`react.suspense_list`),f=Symbol.for(`react.memo`),p=Symbol.for(`react.lazy`),m=Symbol.for(`react.offscreen`),h=Symbol.iterator,g=`@@iterator`;function _(e){if(typeof e!=`object`||!e)return null;var t=h&&e[h]||e[g];return typeof t==`function`?t:null}var v=t.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function y(e){b(`error`,e,[...arguments].slice(1))}function b(e,t,n){var r=v.ReactDebugCurrentFrame.getStackAddendum();r!==``&&(t+=`%s`,n=n.concat([r]));var i=n.map(function(e){return String(e)});i.unshift(`Warning: `+t),Function.prototype.apply.call(console[e],console,i)}var x=Symbol.for(`react.module.reference`);function S(e){return!!(typeof e==`string`||typeof e==`function`||e===i||e===o||e===a||e===u||e===d||e===m||typeof e==`object`&&e&&(e.$$typeof===p||e.$$typeof===f||e.$$typeof===s||e.$$typeof===c||e.$$typeof===l||e.$$typeof===x||e.getModuleId!==void 0))}function C(e,t,n){var r=e.displayName;if(r)return r;var i=t.displayName||t.name||``;return i===``?n:n+`(`+i+`)`}function w(e){return e.displayName||`Context`}function T(e){if(e==null)return null;if(typeof e.tag==`number`&&y(`Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue.`),typeof e==`function`)return e.displayName||e.name||null;if(typeof e==`string`)return e;switch(e){case i:return`Fragment`;case r:return`Portal`;case o:return`Profiler`;case a:return`StrictMode`;case u:return`Suspense`;case d:return`SuspenseList`}if(typeof e==`object`)switch(e.$$typeof){case c:return w(e)+`.Consumer`;case s:return w(e._context)+`.Provider`;case l:return C(e,e.render,`ForwardRef`);case f:var t=e.displayName||null;return t===null?T(e.type)||`Memo`:t;case p:var n=e,m=n._payload,h=n._init;try{return T(h(m))}catch{return null}}return null}var E=Object.assign,D=0,O,k,A,j,M,N,P;function F(){}F.__reactDisabledLog=!0;function I(){if(D===0){O=console.log,k=console.info,A=console.warn,j=console.error,M=console.group,N=console.groupCollapsed,P=console.groupEnd;var e={configurable:!0,enumerable:!0,value:F,writable:!0};Object.defineProperties(console,{info:e,log:e,warn:e,error:e,group:e,groupCollapsed:e,groupEnd:e})}D++}function L(){if(D--,D===0){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:E({},e,{value:O}),info:E({},e,{value:k}),warn:E({},e,{value:A}),error:E({},e,{value:j}),group:E({},e,{value:M}),groupCollapsed:E({},e,{value:N}),groupEnd:E({},e,{value:P})})}D<0&&y(`disabledDepth fell below zero. This is a bug in React. Please file an issue.`)}var R=v.ReactCurrentDispatcher,z;function ee(e,t,n){if(z===void 0)try{throw Error()}catch(e){var r=e.stack.trim().match(/\n( *(at )?)/);z=r&&r[1]||``}return`
|
|
9
|
+
`+z+e}var te=!1,ne=new(typeof WeakMap==`function`?WeakMap:Map);function B(e,t){if(!e||te)return``;var n=ne.get(e);if(n!==void 0)return n;var r;te=!0;var i=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var a=R.current;R.current=null,I();try{if(t){var o=function(){throw Error()};if(Object.defineProperty(o.prototype,"props",{set:function(){throw Error()}}),typeof Reflect==`object`&&Reflect.construct){try{Reflect.construct(o,[])}catch(e){r=e}Reflect.construct(e,[],o)}else{try{o.call()}catch(e){r=e}e.call(o.prototype)}}else{try{throw Error()}catch(e){r=e}e()}}catch(t){if(t&&r&&typeof t.stack==`string`){for(var s=t.stack.split(`
|
|
10
|
+
`),c=r.stack.split(`
|
|
11
|
+
`),l=s.length-1,u=c.length-1;l>=1&&u>=0&&s[l]!==c[u];)u--;for(;l>=1&&u>=0;l--,u--)if(s[l]!==c[u]){if(l!==1||u!==1)do if(l--,u--,u<0||s[l]!==c[u]){var d=`
|
|
12
|
+
`+s[l].replace(` at new `,` at `);return e.displayName&&d.includes(`<anonymous>`)&&(d=d.replace(`<anonymous>`,e.displayName)),typeof e==`function`&&ne.set(e,d),d}while(l>=1&&u>=0);break}}}finally{te=!1,R.current=a,L(),Error.prepareStackTrace=i}var f=e?e.displayName||e.name:``,p=f?ee(f):``;return typeof e==`function`&&ne.set(e,p),p}function re(e,t,n){return B(e,!1)}function ie(e){var t=e.prototype;return!!(t&&t.isReactComponent)}function V(e,t,n){if(e==null)return``;if(typeof e==`function`)return B(e,ie(e));if(typeof e==`string`)return ee(e);switch(e){case u:return ee(`Suspense`);case d:return ee(`SuspenseList`)}if(typeof e==`object`)switch(e.$$typeof){case l:return re(e.render);case f:return V(e.type,t,n);case p:var r=e,i=r._payload,a=r._init;try{return V(a(i),t,n)}catch{}}return``}var ae=Object.prototype.hasOwnProperty,oe={},se=v.ReactDebugCurrentFrame;function ce(e){if(e){var t=e._owner,n=V(e.type,e._source,t?t.type:null);se.setExtraStackFrame(n)}else se.setExtraStackFrame(null)}function le(e,t,n,r,i){var a=Function.call.bind(ae);for(var o in e)if(a(e,o)){var s=void 0;try{if(typeof e[o]!=`function`){var c=Error((r||`React class`)+`: `+n+" type `"+o+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof e[o]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw c.name=`Invariant Violation`,c}s=e[o](t,o,r,n,null,`SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED`)}catch(e){s=e}s&&!(s instanceof Error)&&(ce(i),y("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",r||`React class`,n,o,typeof s),ce(null)),s instanceof Error&&!(s.message in oe)&&(oe[s.message]=!0,ce(i),y(`Failed %s type: %s`,n,s.message),ce(null))}}var ue=Array.isArray;function de(e){return ue(e)}function fe(e){return typeof Symbol==`function`&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||`Object`}function pe(e){try{return me(e),!1}catch{return!0}}function me(e){return``+e}function he(e){if(pe(e))return y(`The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.`,fe(e)),me(e)}var ge=v.ReactCurrentOwner,_e={key:!0,ref:!0,__self:!0,__source:!0},ve,ye,be={};function xe(e){if(ae.call(e,`ref`)){var t=Object.getOwnPropertyDescriptor(e,`ref`).get;if(t&&t.isReactWarning)return!1}return e.ref!==void 0}function Se(e){if(ae.call(e,`key`)){var t=Object.getOwnPropertyDescriptor(e,`key`).get;if(t&&t.isReactWarning)return!1}return e.key!==void 0}function Ce(e,t){if(typeof e.ref==`string`&&ge.current&&t&&ge.current.stateNode!==t){var n=T(ge.current.type);be[n]||(y(`Component "%s" contains the string ref "%s". Support for string refs will be removed in a future major release. This case cannot be automatically converted to an arrow function. We ask you to manually fix this case by using useRef() or createRef() instead. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref`,T(ge.current.type),e.ref),be[n]=!0)}}function we(e,t){var n=function(){ve||(ve=!0,y("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",t))};n.isReactWarning=!0,Object.defineProperty(e,"key",{get:n,configurable:!0})}function Te(e,t){var n=function(){ye||(ye=!0,y("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",t))};n.isReactWarning=!0,Object.defineProperty(e,"ref",{get:n,configurable:!0})}var Ee=function(e,t,r,i,a,o,s){var c={$$typeof:n,type:e,key:t,ref:r,props:s,_owner:o};return c._store={},Object.defineProperty(c._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(c,"_self",{configurable:!1,enumerable:!1,writable:!1,value:i}),Object.defineProperty(c,"_source",{configurable:!1,enumerable:!1,writable:!1,value:a}),Object.freeze&&(Object.freeze(c.props),Object.freeze(c)),c};function De(e,t,n,r,i){var a,o={},s=null,c=null;for(a in n!==void 0&&(he(n),s=``+n),Se(t)&&(he(t.key),s=``+t.key),xe(t)&&(c=t.ref,Ce(t,i)),t)ae.call(t,a)&&!_e.hasOwnProperty(a)&&(o[a]=t[a]);if(e&&e.defaultProps){var l=e.defaultProps;for(a in l)o[a]===void 0&&(o[a]=l[a])}if(s||c){var u=typeof e==`function`?e.displayName||e.name||`Unknown`:e;s&&we(o,u),c&&Te(o,u)}return Ee(e,s,c,i,r,ge.current,o)}var Oe=v.ReactCurrentOwner,ke=v.ReactDebugCurrentFrame;function Ae(e){if(e){var t=e._owner,n=V(e.type,e._source,t?t.type:null);ke.setExtraStackFrame(n)}else ke.setExtraStackFrame(null)}var je=!1;function Me(e){return typeof e==`object`&&!!e&&e.$$typeof===n}function Ne(){if(Oe.current){var e=T(Oe.current.type);if(e)return`
|
|
13
|
+
|
|
14
|
+
Check the render method of \``+e+"`."}return``}function Pe(e){if(e!==void 0){var t=e.fileName.replace(/^.*[\\\/]/,``),n=e.lineNumber;return`
|
|
15
|
+
|
|
16
|
+
Check your code at `+t+`:`+n+`.`}return``}var Fe={};function Ie(e){var t=Ne();if(!t){var n=typeof e==`string`?e:e.displayName||e.name;n&&(t=`
|
|
17
|
+
|
|
18
|
+
Check the top-level render call using <`+n+`>.`)}return t}function Le(e,t){if(e._store&&!e._store.validated&&e.key==null){e._store.validated=!0;var n=Ie(t);if(!Fe[n]){Fe[n]=!0;var r=``;e&&e._owner&&e._owner!==Oe.current&&(r=` It was passed a child from `+T(e._owner.type)+`.`),Ae(e),y(`Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.`,n,r),Ae(null)}}}function Re(e,t){if(typeof e==`object`){if(de(e))for(var n=0;n<e.length;n++){var r=e[n];Me(r)&&Le(r,t)}else if(Me(e))e._store&&(e._store.validated=!0);else if(e){var i=_(e);if(typeof i==`function`&&i!==e.entries)for(var a=i.call(e),o;!(o=a.next()).done;)Me(o.value)&&Le(o.value,t)}}}function ze(e){var t=e.type;if(t!=null&&typeof t!=`string`){var n;if(typeof t==`function`)n=t.propTypes;else if(typeof t==`object`&&(t.$$typeof===l||t.$$typeof===f))n=t.propTypes;else return;if(n){var r=T(t);le(n,e.props,`prop`,r,e)}else t.PropTypes!==void 0&&!je&&(je=!0,y("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",T(t)||`Unknown`));typeof t.getDefaultProps==`function`&&!t.getDefaultProps.isReactClassApproved&&y("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function Be(e){for(var t=Object.keys(e.props),n=0;n<t.length;n++){var r=t[n];if(r!==`children`&&r!==`key`){Ae(e),y("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",r),Ae(null);break}}e.ref!==null&&(Ae(e),y("Invalid attribute `ref` supplied to `React.Fragment`."),Ae(null))}function Ve(e,t,r,a,o,s){var c=S(e);if(!c){var l=``;(e===void 0||typeof e==`object`&&e&&Object.keys(e).length===0)&&(l+=` You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.`);var u=Pe(o);l+=u||Ne();var d;e===null?d=`null`:de(e)?d=`array`:e!==void 0&&e.$$typeof===n?(d=`<`+(T(e.type)||`Unknown`)+` />`,l=` Did you accidentally export a JSX literal instead of a component?`):d=typeof e,y(`React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s`,d,l)}var f=De(e,t,r,o,s);if(f==null)return f;if(c){var p=t.children;if(p!==void 0){if(a){if(de(p)){for(var m=0;m<p.length;m++)Re(p[m],e);Object.freeze&&Object.freeze(p)}else y(`React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.`)}else Re(p,e)}}return e===i?Be(f):ze(f),f}function He(e,t,n){return Ve(e,t,n,!0)}function Ue(e,t,n){return Ve(e,t,n,!1)}var We=Ue,Ge=He;e.Fragment=i,e.jsx=We,e.jsxs=Ge})()})),J=o(((e,t)=>{t.exports=process.env.NODE_ENV===`production`?Fu():Iu()}))(),Lu=he({}),Ru=({effects:e})=>{"use no memo";return Yc(e),null},zu=nn(function(e,t){"use no memo";let{config:n,children:r}=e,i=`extends`in e,a=`value`in e,o=Ir();if(qi){if(i&&a)throw Error("AuiProvider: pass either `extends` or `value`, not both.");if(i&&e.extends===void 0)throw Error("AuiProvider: `extends` must be a client or null, not undefined.");if(i&&!n)throw Error("AuiProvider: `extends` requires a `config`.");if(a&&n)throw Error("AuiProvider: pass either `value` or `config`, not both.");if(!a&&!n)throw Error("AuiProvider: a `config` is required.");if(!i&&!a&&o!==kr)throw Error(`A parent AuiProvider exists — pass extends={aui} to inherit it or extends={null} to isolate.`)}let s=i?e.extends??kr:a?e.value??kr:o,c=Wi(),{client:l,effects:u}=pa(s,n??Lu,c);return tn(t,()=>l,[l]),(0,J.jsx)(Mi.Provider,{value:c,children:(0,J.jsxs)(jr.Provider,{value:l,children:[(0,J.jsx)(Ru,{effects:Pr(s)}),u&&(0,J.jsx)(Ru,{effects:u}),r]})})}),Bu=e=>{let t=K(),n=U(!1),r=n.current?null:e(t);return q(()=>n.current?e(t):r),()=>(n.current=!0,e(t))},Vu=Object.freeze({});function Hu(e){let t=G(3),{getItemState:n,children:r}=e,i=Bu(n),a;return t[0]!==r||t[1]!==i?(a=r(i),t[0]=r,t[1]=i,t[2]=a):a=t[2],Uu(a)}var Uu=e=>{let t=typeof e==`object`&&e&&`type`in e?e:null,n=t?.type,r=t?.key;return qt(()=>t,[n,r,typeof t?.props==`object`&&t.props!=null&&Object.entries(t.props).length===0?Vu:t?.props])??e},Wu=(e,t)=>{let n=G(11),r=K(),i=Xt(t),a;n[0]===e?a=n[1]:(a=Vr(e),n[0]=e,n[1]=a);let{scope:o,event:s}=a,c;n[2]!==r||n[3]!==i||n[4]!==s||n[5]!==o?(c=()=>r.on({scope:o,event:s},i),n[2]=r,n[3]=i,n[4]=s,n[5]=o,n[6]=c):c=n[6];let l;n[7]!==r||n[8]!==s||n[9]!==o?(l=[r,o,s],n[7]=r,n[8]=s,n[9]=o,n[10]=l):l=n[10],W(c,l)},Gu=e=>e._core?.RenderComponent,Ku=({runtime:e,aui:t,config:n,children:r})=>{"use no memo";let i=Gu(e),a=he({...n,threads:Nu(e)});return(0,J.jsxs)(zu,{extends:t,config:a,children:[i&&(0,J.jsx)(i,{}),r]})},qu=rn(e=>{let t=G(5),{runtime:n,aui:r,config:i,children:a}=e,o=r===void 0?null:r,s;return t[0]!==o||t[1]!==a||t[2]!==i||t[3]!==n?(s=(0,J.jsx)(Ku,{runtime:n,aui:o,config:i,children:a}),t[0]=o,t[1]=a,t[2]=i,t[3]=n,t[4]=s):s=t[4],s}),Ju=pn(null),Yu=(e,t)=>lt(Ju,e,t),Xu=()=>hn(Ju),Zu={},Qu=e=>{let t=Gi(e??Zu);return e==null?null:t},$u=class{cache=new WeakMap;convertMessages(e,t){return e.map((e,n)=>{let r=t(this.cache.get(e),e,n);return this.cache.set(e,r),r})}},ed=(e,t)=>{if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0};Object.freeze({});var td=e=>{let t=G(6),{index:n,children:r}=e,i=K(),a;t[0]===n?a=t[1]:(a=he({attachment:_a({source:`message`,query:{type:`index`,index:n},get:e=>e.message.attachment({index:n})})}),t[0]=n,t[1]=a);let o=a,s;return t[2]!==i||t[3]!==r||t[4]!==o?(s=(0,J.jsx)(zu,{extends:i,config:o,children:r}),t[2]=i,t[3]=r,t[4]=o,t[5]=s):s=t[5],s},nd=e=>{let t=G(6),{index:n,children:r}=e,i=K(),a;t[0]===n?a=t[1]:(a=he({attachment:_a({source:`composer`,query:{type:`index`,index:n},get:e=>e.composer.attachment({index:n})})}),t[0]=n,t[1]=a);let o=a,s;return t[2]!==i||t[3]!==r||t[4]!==o?(s=(0,J.jsx)(zu,{extends:i,config:o,children:r}),t[2]=i,t[3]=r,t[4]=o,t[5]=s):s=t[5],s},rd=e=>{let t=G(6),{runtime:n,children:r}=e,i=K(),a;t[0]===n?a=t[1]:(a=he({threadListItem:Du({runtime:n})}),t[0]=n,t[1]=a);let o=a,s;return t[2]!==i||t[3]!==r||t[4]!==o?(s=(0,J.jsx)(zu,{extends:i,config:o,children:r}),t[2]=i,t[3]=r,t[4]=o,t[5]=s):s=t[5],s},id=e=>{let t=G(6),{index:n,children:r}=e,i=K(),a;t[0]===n?a=t[1]:(a=he({message:_a({source:`thread`,query:{type:`index`,index:n},get:e=>e.thread.message({index:n})}),composer:_a({source:`message`,query:{},get:e=>e.thread.message({index:n}).composer()})}),t[0]=n,t[1]=a);let o=a,s;return t[2]!==i||t[3]!==r||t[4]!==o?(s=(0,J.jsx)(zu,{extends:i,config:o,children:r}),t[2]=i,t[3]=r,t[4]=o,t[5]=s):s=t[5],s},ad=e=>{let t=G(6),{index:n,children:r}=e,i=K(),a;t[0]===n?a=t[1]:(a=he({part:_a({source:`message`,query:{type:`index`,index:n},get:e=>e.message.part({index:n})})}),t[0]=n,t[1]=a);let o=a,s;return t[2]!==i||t[3]!==r||t[4]!==o?(s=(0,J.jsx)(zu,{extends:i,config:o,children:r}),t[2]=i,t[3]=r,t[4]=o,t[5]=s):s=t[5],s},od=hr(e=>{let t=G(7),{text:n,isRunning:r}=e,i;t[0]===r?i=t[1]:(i=r?{type:`running`}:{type:`complete`},t[0]=r,t[1]=i);let a;t[2]!==i||t[3]!==n?(a={type:`text`,text:n,status:i},t[2]=i,t[3]=n,t[4]=a):a=t[4];let o=a,s;return t[5]===o?s=t[6]:(s={getState:()=>o,addToolResult:cd,resumeToolCall:ld,respondToToolApproval:ud,unstable_recordInteraction:dd},t[5]=o,t[6]=s),s}),sd=e=>{let t=G(7),{text:n,isRunning:r,children:i}=e,a=r!==void 0&&r,o=K(),s;t[0]!==a||t[1]!==n?(s=he({part:od({text:n,isRunning:a})}),t[0]=a,t[1]=n,t[2]=s):s=t[2];let c=s,l;return t[3]!==o||t[4]!==i||t[5]!==c?(l=(0,J.jsx)(zu,{extends:o,config:c,children:i}),t[3]=o,t[4]=i,t[5]=c,t[6]=l):l=t[6],l};function cd(){throw Error(`Not supported`)}function ld(){throw Error(`Not supported`)}function ud(){throw Error(`Not supported`)}async function dd(){throw Error(`Not supported`)}var fd=e=>{for(let t of e)if(t?.status.type===`running`)return vc;return e.at(-1)?.status??_c},pd=(e,t)=>{let n={running:0,complete:0,incomplete:0,requiresAction:0},r=_c,i=!1,a,o,s=!0;for(let c of t){let t=e[c]?.timing;switch(t&&(a=Math.min(a??t.startedAt,t.startedAt),t.completedAt===void 0?s=!1:o=Math.max(o??t.completedAt,t.completedAt)),r=e[c]?.status??_c,r.type){case`running`:n.running++,i=!0;break;case`complete`:n.complete++;break;case`incomplete`:n.incomplete++;break;case`requires-action`:n.requiresAction++}}let c=a===void 0?void 0:!i&&s&&o!==void 0?{startedAt:a,completedAt:o}:{startedAt:a};return{status:i?vc:r,counts:n,...c&&{timing:c}}},md=hr(e=>{let t=G(11),{parts:n,getMessagePart:r}=e,[i,a]=H(!0),o;t[0]===n?o=t[1]:(o=fd(n),t[0]=n,t[1]=o);let s=o,c;t[2]!==i||t[3]!==n||t[4]!==s?(c={parts:n,collapsed:i,status:s},t[2]=i,t[3]=n,t[4]=s,t[5]=c):c=t[5];let l=c,u;t[6]===l?u=t[7]:(u=()=>l,t[6]=l,t[7]=u);let d;return t[8]!==r||t[9]!==u?(d={getState:u,setCollapsed:a,part:r},t[8]=r,t[9]=u,t[10]=d):d=t[10],d}),hd=pn(null),gd=e=>{let t=G(13),{startIndex:n,endIndex:r,children:i}=e,a=q(_d).slice(n,r+1),o;t[0]!==r||t[1]!==n?(o=e=>Tl(e.message.parts).slice(n,r+1),t[0]=r,t[1]=n,t[2]=o):o=t[2];let s=q(Ki(o)),c;t[3]!==s||t[4]!==n?(c={partKeys:s,startIndex:n},t[3]=s,t[4]=n,t[5]=c):c=t[5];let l=c,u=K(),d=he({chainOfThought:md({parts:a,getMessagePart:e=>{let{index:t}=e;if(t<0||t>=a.length)throw Error(`ChainOfThought part index ${t} is out of bounds (0..${a.length-1})`);return u.message.part({index:n+t})}})}),f;t[6]!==i||t[7]!==d||t[8]!==u?(f=(0,J.jsx)(zu,{extends:u,config:d,children:i}),t[6]=i,t[7]=d,t[8]=u,t[9]=f):f=t[9];let p;return t[10]!==l||t[11]!==f?(p=(0,J.jsx)(hd.Provider,{value:l,children:f}),t[10]=l,t[11]=f,t[12]=p):p=t[12],p};function _d(e){return e.message.parts}var vd=e=>{let t=G(7),{index:n,archived:r,children:i}=e,a=K(),o;t[0]!==r||t[1]!==n?(o=he({threadListItem:_a({source:`threads`,query:{type:`index`,index:n,archived:r},get:e=>e.threads.item({index:n,archived:r})})}),t[0]=r,t[1]=n,t[2]=o):o=t[2];let s=o,c;return t[3]!==a||t[4]!==i||t[5]!==s?(c=(0,J.jsx)(zu,{extends:a,config:s,children:i}),t[3]=a,t[4]=i,t[5]=s,t[6]=c):c=t[6],c},yd=e=>{let t=G(6),{index:n,children:r}=e,i=K(),a;t[0]===n?a=t[1]:(a=he({suggestion:_a({source:`suggestions`,query:{index:n},get:e=>e.suggestions.suggestion({index:n})})}),t[0]=n,t[1]=a);let o=a,s;return t[2]!==i||t[3]!==r||t[4]!==o?(s=(0,J.jsx)(zu,{extends:i,config:o,children:r}),t[2]=i,t[3]=r,t[4]=o,t[5]=s):s=t[5],s},bd=e=>{let t=G(6),{index:n,children:r}=e,i=K(),a;t[0]===n?a=t[1]:(a=he({queueItem:_a({source:`composer`,query:{type:`index`,index:n},get:e=>e.composer.queueItem({index:n})})}),t[0]=n,t[1]=a);let o=a,s;return t[2]!==i||t[3]!==r||t[4]!==o?(s=(0,J.jsx)(zu,{extends:i,config:o,children:r}),t[2]=i,t[3]=r,t[4]=o,t[5]=s):s=t[5],s},xd=(e,t)=>{Promise.resolve(t).catch(t=>{Ys(t)||console.error(`[assistant-ui] ${e} failed`,t)})},Sd=class{get path(){return this._core.path}_core;constructor(e){this._core=e,this.__internal_bindMethods()}__internal_bindMethods(){this.getState=this.getState.bind(this),this.remove=this.remove.bind(this),this.subscribe=this.subscribe.bind(this)}getState(){return this._core.getState()}subscribe(e){return this._core.subscribe(e)}},Cd=class extends Sd{_composerApi;constructor(e,t){super(e),this._composerApi=t}remove(){let e=this._composerApi.getState();if(!e)throw Error(`Composer is not available`);return e.removeAttachment(this.getState().id)}},wd=class extends Cd{get source(){return`thread-composer`}},Td=class extends Cd{get source(){return`edit-composer`}},Ed=class extends Sd{get source(){return`message`}remove(){throw Error(`Message attachments cannot be removed`)}},Dd=Object.freeze([]),Od=Object.freeze({}),kd=e=>Object.freeze({type:`thread`,isEditing:e?.isEditing??!1,canCancel:e?.canCancel??!1,canSend:e?.canSend??!1,isEmpty:e?.isEmpty??!0,attachments:e?.attachments??Dd,text:e?.text??``,role:e?.role??`user`,runConfig:e?.runConfig??Od,attachmentAccept:e?.attachmentAccept??``,dictation:e?.dictation,quote:e?.quote,queue:e?.queue??Dd,submission:e?.submission,inTransit:e?.inTransit??Dd,value:e?.text??``}),Ad=e=>Object.freeze({type:`edit`,isEditing:e?.isEditing??!1,canCancel:e?.canCancel??!1,canSend:e?.canSend??!1,isEmpty:e?.isEmpty??!0,text:e?.text??``,role:e?.role??`user`,attachments:e?.attachments??Dd,runConfig:e?.runConfig??Od,attachmentAccept:e?.attachmentAccept??``,dictation:e?.dictation,quote:e?.quote,queue:e?.queue??Dd,submission:e?.submission,inTransit:e?.inTransit??Dd,parentId:e?.parentId??null,sourceId:e?.sourceId??null,value:e?.text??``}),jd=class{get path(){return this._core.path}_core;constructor(e){this._core=e}__internal_bindMethods(){this.setText=this.setText.bind(this),this.setRunConfig=this.setRunConfig.bind(this),this.getState=this.getState.bind(this),this.subscribe=this.subscribe.bind(this),this.addAttachment=this.addAttachment.bind(this),this.reset=this.reset.bind(this),this.clearAttachments=this.clearAttachments.bind(this),this.send=this.send.bind(this),this.cancel=this.cancel.bind(this),this.steerQueueItem=this.steerQueueItem.bind(this),this.moveQueueItem=this.moveQueueItem.bind(this),this.removeQueueItem=this.removeQueueItem.bind(this),this.setRole=this.setRole.bind(this),this.getAttachmentByIndex=this.getAttachmentByIndex.bind(this),this.startDictation=this.startDictation.bind(this),this.stopDictation=this.stopDictation.bind(this),this.setQuote=this.setQuote.bind(this),this.unstable_on=this.unstable_on.bind(this)}setText(e,t){let n=this._core.getState();if(!n)throw Error(`Composer is not available`);n.setText(e,t)}setRunConfig(e){let t=this._core.getState();if(!t)throw Error(`Composer is not available`);t.setRunConfig(e)}addAttachment(e){let t=this._core.getState();if(!t)throw Error(`Composer is not available`);return t.addAttachment(e)}reset(){let e=this._core.getState();if(!e)throw Error(`Composer is not available`);return e.reset()}clearAttachments(){let e=this._core.getState();if(!e)throw Error(`Composer is not available`);return e.clearAttachments()}send(e){let t=this._core.getState();if(!t)throw Error(`Composer is not available`);t.send(e)}cancel(){let e=this._core.getState();if(!e)throw Error(`Composer is not available`);e.cancel()}steerQueueItem(e){this.moveQueueItem(e,{lane:`steer`,insertAfter:null})}moveQueueItem(e,t){let n=this._core.getState();if(!n)throw Error(`Composer is not available`);n.moveQueueItem(e,t)}removeQueueItem(e){let t=this._core.getState();if(!t)throw Error(`Composer is not available`);t.removeQueueItem(e)}setRole(e){let t=this._core.getState();if(!t)throw Error(`Composer is not available`);t.setRole(e)}startDictation(){let e=this._core.getState();if(!e)throw Error(`Composer is not available`);e.startDictation()}stopDictation(){let e=this._core.getState();if(!e)throw Error(`Composer is not available`);e.stopDictation()}setQuote(e){let t=this._core.getState();if(!t)throw Error(`Composer is not available`);t.setQuote(e)}subscribe(e){return this._core.subscribe(e)}_eventSubscriptionSubjects=new Map;unstable_on(e,t){let n=this._eventSubscriptionSubjects.get(e);return n||(n=new no({event:e,binding:this._core}),this._eventSubscriptionSubjects.set(e,n)),n.subscribe(t)}},Md=class extends jd{get path(){return this._core.path}get type(){return`thread`}_getState;constructor(e){let t=new eo({path:e.path,getState:()=>kd(e.getState()),subscribe:t=>e.subscribe(t)});super({path:e.path,getState:()=>e.getState(),subscribe:e=>t.subscribe(e)}),this._getState=t.getState.bind(t),this.__internal_bindMethods()}getState(){return this._getState()}getAttachmentByIndex(e){return new wd(new $a({path:{...this.path,attachmentSource:`thread-composer`,attachmentSelector:{type:`index`,index:e},ref:`${this.path.ref}.attachments[${e}]`},getState:()=>{let t=this.getState().attachments[e];return t?{...t,source:`thread-composer`}:Ga},subscribe:e=>this._core.subscribe(e)}),this._core)}},Nd=class extends jd{get path(){return this._core.path}get type(){return`edit`}_getState;_beginEdit;constructor(e,t){let n=new eo({path:e.path,getState:()=>Ad(e.getState()),subscribe:t=>e.subscribe(t)});super({path:e.path,getState:()=>e.getState(),subscribe:e=>n.subscribe(e)}),this._beginEdit=t,this._getState=n.getState.bind(n),this.__internal_bindMethods()}__internal_bindMethods(){super.__internal_bindMethods(),this.beginEdit=this.beginEdit.bind(this)}getState(){return this._getState()}beginEdit(){this._beginEdit()}getAttachmentByIndex(e){return new Td(new $a({path:{...this.path,attachmentSource:`edit-composer`,attachmentSelector:{type:`index`,index:e},ref:`${this.path.ref}.attachments[${e}]`},getState:()=>{let t=this.getState().attachments[e];return t?{...t,source:`edit-composer`}:Ga},subscribe:e=>this._core.subscribe(e)}),this._core)}},Pd={"allow-once":!0,"allow-always":!0,"reject-once":!1,"reject-always":!1},Fd=(e,t)=>{let n=e.questions??[];if(n.length===0)throw Error(`Tool approval "${e.id}" has display "questions" but declares no questions`);let r=new Set;for(let t of n){if(r.has(t.id))throw Error(`Tool approval "${e.id}" declares question "${t.id}" more than once`);r.add(t.id)}for(let n of Object.keys(t))if(!r.has(n))throw Error(`Tool approval "${e.id}" has no question with id "${n}"`);for(let r of n){let n=Object.hasOwn(t,r.id)?t[r.id]:void 0,i=n?.optionIds??[],a=n?.text;if(!Array.isArray(i)||a!==void 0&&typeof a!=`string`)throw Error(`Question "${r.id}" takes optionIds as an array and text as a string`);if(i.length===0&&(a===void 0||a.trim()===``))throw Error(`Tool approval "${e.id}" is missing an answer to question "${r.id}"`);if(i.length>1&&!r.multiple)throw Error(`Question "${r.id}" takes one option, not ${i.length}`);if(new Set(i).size!==i.length)throw Error(`Question "${r.id}" lists an option more than once`);for(let e of i)if(!r.options?.some(t=>t.id===e))throw Error(`Question "${r.id}" has no option with id "${e}"`);if(a!==void 0&&(r.options?.length??0)>0&&!r.allowFreeform)throw Error(`Question "${r.id}" does not accept a typed answer; it must declare allowFreeform`)}},Id=(e,t)=>{let n=t.reason;if(`answers`in t){if(`approved`in t||`optionId`in t||`text`in t)throw Error(`Tool approval "${e.id}" takes its answers alone, without approved, optionId or text`);return Fd(e,t.answers),{approvalId:e.id,approved:!0,answers:t.answers,...n!=null&&{reason:n}}}if(`approved`in t&&t.approved===!1&&!(`optionId`in t)&&t.text===void 0)return{approvalId:e.id,approved:!1,...n!=null&&{reason:n}};throw Error(`Tool approval "${e.id}" asks questions; respond with answers, or with approved: false to dismiss it`)},Ld=(e,t)=>{if(e.display===`questions`)return Id(e,t);if(`answers`in t)throw Error(`Tool approval "${e.id}" asks no questions; answers only resolve a display "questions" request`);let n=t.text;if(n!==void 0&&!O(e))throw Error(`Tool approval "${e.id}" does not accept a free-form answer; the request must declare display "text" or allowFreeform`);let r,i;if(`optionId`in t){let n=e.options?.find(e=>e.id===t.optionId);if(!n)throw Error(`Tool approval has no option with id "${t.optionId}"`);if(`approved`in t)r=t.approved;else{if(!Object.hasOwn(Pd,n.kind))throw Error(`Tool approval option "${n.id}" has a custom kind "${n.kind}"; respond with an explicit approved value instead`);r=Pd[n.kind]}i=n.id}else if(`approved`in t)r=t.approved;else{if(e.display!==`text`&&e.display!==`select`)throw Error(`Tool approval "${e.id}" is a decision, not a question; respond with an explicit approved value, optionally alongside the answer`);r=!0}return{approvalId:e.id,approved:r,...i!==void 0&&{optionId:i},...n!==void 0&&{text:n},...t.reason!=null&&{reason:t.reason}}},Rd=class{get path(){return this.contentBinding.path}contentBinding;messageApi;threadApi;interactionState;interactionMessageId;interactionThreadId;interactionCore;constructor(e,t,n){this.contentBinding=e,this.messageApi=t,this.threadApi=n,this.interactionState=e.getState(),this.interactionMessageId=this.interactionState.type===`tool-call`?t?.getState().id:void 0,this.interactionThreadId=this.interactionState.type===`tool-call`?this.threadApi?.getStateState?.().threadId:void 0,this.interactionCore=this.interactionState.type===`tool-call`?n?.getState():void 0,this.__internal_bindMethods()}__internal_bindMethods(){this.addToolResult=this.addToolResult.bind(this),this.resumeToolCall=this.resumeToolCall.bind(this),this.respondToToolApproval=this.respondToToolApproval.bind(this),this.unstable_recordInteraction=this.unstable_recordInteraction.bind(this),this.getState=this.getState.bind(this),this.subscribe=this.subscribe.bind(this)}getState(){return this.contentBinding.getState()}getInteractionCore(){let e=this.interactionThreadId!==void 0&&this.threadApi?.getStateState?.().threadId===this.interactionThreadId?this.threadApi.getState():this.interactionCore;if(!e)throw Error(`Thread API is not available`);return e}addToolResult(e){let t=this.interactionState;if(t.type!==`tool-call`)throw Error(`Tried to add tool result to non-tool message part`);if(!this.messageApi)throw Error(`Message API is not available. This is likely a bug in assistant-ui.`);if(!this.threadApi)throw Error(`Thread API is not available`);let n=this.interactionMessageId;if(n===void 0)throw Error(`Message is not available`);let r=t.toolName,i=t.toolCallId,a=as.toResponse(e);this.getInteractionCore().addToolResult({messageId:n,toolName:r,toolCallId:i,result:a.result,isError:a.isError,...a.artifact!==void 0&&{artifact:a.artifact},...a.modelContent!==void 0&&{modelContent:a.modelContent}})}resumeToolCall(e){let t=this.interactionState;if(t.type!==`tool-call`)throw Error(`Tried to resume tool call on non-tool message part`);if(!this.threadApi)throw Error(`Thread API is not available`);this.getInteractionCore().resumeToolCall({toolCallId:t.toolCallId,payload:e}),this.unstable_recordInteraction({type:`human-response`,payload:e}).catch(()=>{})}respondToToolApproval(e){let t=this.interactionState;if(t.type!==`tool-call`)throw Error(`Tried to respond to tool approval on non-tool message part`);if(!this.threadApi)throw Error(`Thread API is not available`);let n=this.getInteractionCore(),r=this.interactionMessageId===void 0?void 0:n.getMessageById(this.interactionMessageId)?.message.content.find(e=>e.type===`tool-call`&&e.toolCallId===t.toolCallId),i=r?.type===`tool-call`?r.approval:void 0;if(!i||i.approved!==void 0||i.resolution!==void 0)throw Error(`Tool call has no pending approval`);return n.respondToToolApproval(Ld(i,e))}async unstable_recordInteraction(e){let t=this.interactionState;if(t.type!==`tool-call`)throw Error(`Tried to record interaction on non-tool message part`);let n=this.interactionMessageId;if(n===void 0)throw Error(`Message is not available`);let r=this.getInteractionCore();if(!r.unstable_recordToolInteraction)throw Error(`Runtime does not support recording tool interactions.`);await r.unstable_recordToolInteraction({messageId:n,toolCallId:t.toolCallId,interaction:ic(e)})}subscribe(e){return this.contentBinding.subscribe(e)}},zd=(e,t)=>{let n=e.content[t];if(!n)return Ga;let r=Sc(e,t,n);return Object.freeze({...n,[uc]:n[uc],status:r})},Bd=class{get path(){return this._core.path}_core;_threadBinding;constructor(e,t){this._core=e,this._threadBinding=t,this.composer=new Nd(new to({path:{...this.path,ref:`${this.path.ref}.composer`,composerSource:`edit`},getState:this._getEditComposerRuntimeCore,subscribe:e=>this._threadBinding.subscribe(e)}),()=>this._threadBinding.getState().beginEdit(this._core.getState().id)),this.__internal_bindMethods()}__internal_bindMethods(){this.reload=this.reload.bind(this),this.delete=this.delete.bind(this),this.getState=this.getState.bind(this),this.subscribe=this.subscribe.bind(this),this.getMessagePartByIndex=this.getMessagePartByIndex.bind(this),this.getMessagePartByToolCallId=this.getMessagePartByToolCallId.bind(this),this.getAttachmentByIndex=this.getAttachmentByIndex.bind(this),this.unstable_getCopyText=this.unstable_getCopyText.bind(this),this.speak=this.speak.bind(this),this.stopSpeaking=this.stopSpeaking.bind(this),this.submitFeedback=this.submitFeedback.bind(this),this.switchToBranch=this.switchToBranch.bind(this)}composer;_getEditComposerRuntimeCore=()=>this._threadBinding.getState().getEditComposer(this._core.getState().id);getState(){return this._core.getState()}delete(){let e=this._core.getState();return this._threadBinding.getState().deleteMessage(e.id)}reload(e={}){let t=this._getEditComposerRuntimeCore(),n=t??this._threadBinding.getState().composer,r=t??n,{runConfig:i=r.runConfig}=e,a=this._core.getState();if(a.role!==`assistant`)throw Error(`Can only reload assistant messages`);xd(`Message reload`,this._threadBinding.getState().startRun({parentId:a.parentId,sourceId:a.id,runConfig:i}))}speak(){let e=this._core.getState();return this._threadBinding.getState().speak(e.id)}stopSpeaking(){let e=this._core.getState();if(this._threadBinding.getState().speech?.messageId===e.id)this._threadBinding.getState().stopSpeaking();else throw Error(`Message is not being spoken`)}submitFeedback({type:e,comment:t}){let n=this._core.getState();this._threadBinding.getState().submitFeedback({messageId:n.id,type:e,...t===void 0?void 0:{comment:t}})}switchToBranch({position:e,branchId:t}){let n=this._core.getState();if(t&&e)throw Error(`May not specify both branchId and position`);if(!t&&!e)throw Error(`Must specify either branchId or position`);let r=this._threadBinding.getState().getBranches(n.id),i=t;if(e===`previous`?i=r[n.branchNumber-2]:e===`next`&&(i=r[n.branchNumber]),!i)throw Error(`Branch not found`);this._threadBinding.getState().switchToBranch(i)}unstable_getCopyText(){return T(this.getState())}subscribe(e){return this._core.subscribe(e)}getMessagePartByIndex(e){if(e<0)throw Error(`Message part index must be >= 0`);return new Rd(new $a({path:{...this.path,ref:`${this.path.ref}.content[${e}]`,messagePartSelector:{type:`index`,index:e}},getState:()=>zd(this.getState(),e),subscribe:e=>this._core.subscribe(e)}),this._core,this._threadBinding)}getMessagePartByToolCallId(e){return new Rd(new $a({path:{...this.path,ref:`${this.path.ref}.content[toolCallId=${JSON.stringify(e)}]`,messagePartSelector:{type:`toolCallId`,toolCallId:e}},getState:()=>{let t=this._core.getState(),n=t.content.findIndex(t=>t.type===`tool-call`&&t.toolCallId===e);return n===-1?Ga:zd(t,n)},subscribe:e=>this._core.subscribe(e)}),this._core,this._threadBinding)}getAttachmentByIndex(e){return new Ed(new $a({path:{...this.path,ref:`${this.path.ref}.attachments[${e}]`,attachmentSource:`message`,attachmentSelector:{type:`index`,index:e}},getState:()=>{let t=this.getState().attachments?.[e];return t?{...t,source:`message`}:Ga},subscribe:e=>this._core.subscribe(e)}))}},Vd=(e,t)=>typeof t==`string`?{createdAt:new Date,parentId:e.at(-1)?.id??null,sourceId:null,runConfig:{},role:`user`,content:[{type:`text`,text:t}],attachments:[],metadata:{custom:{}}}:{createdAt:t.createdAt??new Date,parentId:t.parentId===void 0?e.at(-1)?.id??null:t.parentId,sourceId:t.sourceId??null,role:t.role??`user`,content:t.content,attachments:t.attachments??[],metadata:t.metadata??{custom:{}},runConfig:t.runConfig??{},startRun:t.startRun},Hd=e=>({parentId:e.parentId??null,sourceId:e.sourceId??null,runConfig:e.runConfig??{},...e.stream?{stream:e.stream}:{}}),Ud=e=>({parentId:e.parentId??null,sourceId:e.sourceId??null,runConfig:e.runConfig??{}}),Wd=e=>{if(e.isRunning!==void 0)return e.isRunning;let t=e.messages.at(-1);return t?.role===`assistant`&&t.status.type===`running`},Gd=(e,t)=>Object.freeze({threadId:t.id,metadata:t,capabilities:e.capabilities,isDisabled:e.isDisabled,isSendDisabled:e.isSendDisabled,isLoading:e.isLoading,hasEarlier:e.hasEarlier??!1,isLoadingEarlier:e.isLoadingEarlier??!1,isRunning:Wd(e),canResume:e.canResume??!1,messages:e.messages,state:e.state,suggestions:e.suggestions,extras:e.extras,speech:e.speech,voice:e.voice}),Kd=class{get path(){return this._threadBinding.path}get __internal_threadBinding(){return this._threadBinding}_threadBinding;_stateBinding;constructor(e,t){let n=new $a({path:e.path,getState:()=>Gd(e.getState(),t.getState()),subscribe:n=>{let r=e.subscribe(n),i=t.subscribe(n);return()=>qa([r,i])}});this._stateBinding=n,this._threadBinding={path:e.path,getState:()=>e.getState(),getStateState:()=>n.getState(),outerSubscribe:t=>e.outerSubscribe(t),subscribe:t=>e.subscribe(t)},this.composer=new Md(new to({path:{...this.path,ref:`${this.path.ref}.composer`,composerSource:`thread`},getState:()=>this._threadBinding.getState().composer,subscribe:e=>this._threadBinding.subscribe(e)})),this.__internal_bindMethods()}__internal_bindMethods(){this.append=this.append.bind(this),this.deleteMessage=this.deleteMessage.bind(this),this.resumeRun=this.resumeRun.bind(this),this.loadEarlier=this.loadEarlier.bind(this),this.importExternalState=this.importExternalState.bind(this),this.exportExternalState=this.exportExternalState.bind(this),this.startRun=this.startRun.bind(this),this.cancelRun=this.cancelRun.bind(this),this.unstable_notifySessionReset=this.unstable_notifySessionReset.bind(this),this.stopSpeaking=this.stopSpeaking.bind(this),this.connectVoice=this.connectVoice.bind(this),this.disconnectVoice=this.disconnectVoice.bind(this),this.muteVoice=this.muteVoice.bind(this),this.unmuteVoice=this.unmuteVoice.bind(this),this.getVoiceVolume=this.getVoiceVolume.bind(this),this.subscribeVoiceVolume=this.subscribeVoiceVolume.bind(this),this.export=this.export.bind(this),this.import=this.import.bind(this),this.reset=this.reset.bind(this),this.getMessageByIndex=this.getMessageByIndex.bind(this),this.getMessageById=this.getMessageById.bind(this),this.subscribe=this.subscribe.bind(this),this.unstable_on=this.unstable_on.bind(this),this.getModelContext=this.getModelContext.bind(this),this.getState=this.getState.bind(this)}composer;getState(){return this._threadBinding.getStateState()}append(e){xd(`Message append`,this._threadBinding.getState().append(Vd(this._threadBinding.getState().messages,e)))}deleteMessage(e){return this._threadBinding.getState().deleteMessage(e)}subscribe(e){return this._stateBinding.subscribe(e)}getModelContext(){return this._threadBinding.getState().getModelContext()}startRun(e){return this._threadBinding.getState().startRun(Ud(e))}resumeRun(e){return this._threadBinding.getState().resumeRun(Hd(e))}exportExternalState(){return this._threadBinding.getState().exportExternalState()}importExternalState(e){this._threadBinding.getState().importExternalState(e)}cancelRun(){this._threadBinding.getState().cancelRun()}loadEarlier(){return this._threadBinding.getState().loadEarlier?.()??Promise.resolve()}unstable_notifySessionReset(){this._threadBinding.getState().unstable_notifySessionReset()}stopSpeaking(){return this._threadBinding.getState().stopSpeaking()}connectVoice(){this._threadBinding.getState().connectVoice()}disconnectVoice(){this._threadBinding.getState().disconnectVoice()}getVoiceVolume(){return this._threadBinding.getState().getVoiceVolume()}subscribeVoiceVolume(e){return this._threadBinding.getState().subscribeVoiceVolume(e)}muteVoice(){this._threadBinding.getState().muteVoice()}unmuteVoice(){this._threadBinding.getState().unmuteVoice()}export(){return this._threadBinding.getState().export()}import(e){this._threadBinding.getState().import(e)}reset(e){this._threadBinding.getState().reset(e)}getMessageByIndex(e){if(e<0)throw Error(`Message index must be >= 0`);return this._getMessageRuntime({...this.path,ref:`${this.path.ref}.messages[${e}]`,messageSelector:{type:`index`,index:e}},()=>{let t=this._threadBinding.getState().messages,n=t[e];if(n)return{message:n,parentId:t[e-1]?.id??null,index:e}})}getMessageById(e){return this._getMessageRuntime({...this.path,ref:`${this.path.ref}.messages[messageId=${JSON.stringify(e)}]`,messageSelector:{type:`messageId`,messageId:e}},()=>this._threadBinding.getState().getMessageById(e))}_getMessageRuntime(e,t){return new Bd(new $a({path:e,getState:()=>{let{message:e,parentId:n,index:r}=t()??{},{messages:i,speech:a}=this._threadBinding.getState();if(!e||n===void 0||r===void 0)return Ga;let o=this._threadBinding.getState().getBranches(e.id);return{...e,[uc]:e[uc],index:r,isLast:i.at(-1)?.id===e.id,parentId:n,branchNumber:o.indexOf(e.id)+1,branchCount:o.length,speech:a?.messageId===e.id?a:void 0}},subscribe:e=>this._threadBinding.subscribe(e)}),this._threadBinding)}_eventSubscriptionSubjects=new Map;unstable_on(e,t){let n=this._eventSubscriptionSubjects.get(e);return n||(n=new no({event:e,binding:this._threadBinding,notifyOnRebind:e===`modelContextUpdate`}),this._eventSubscriptionSubjects.set(e,n)),n.subscribe(t)}},qd=(e,t)=>({attachments:[],attachmentAccept:`*`,async addAttachment(){throw e},async removeAttachment(){throw e},isEditing:t,canCancel:!1,canSend:!1,isEmpty:!0,text:``,setText(){throw e},role:`user`,setRole(){throw e},runConfig:{},setRunConfig(){throw e},async reset(){},async clearAttachments(){},send(){throw e},cancel(){},queue:[],moveQueueItem(){},removeQueueItem(){},dictation:void 0,startDictation(){throw e},stopDictation(){},quote:void 0,setQuote(){throw e},subscribe(){return()=>{}},unstable_on(){return()=>{}}}),Jd=class extends Xa{switchToBranch(){throw this.error}append(){throw this.error}deleteMessage(){throw this.error}startRun(){throw this.error}resumeRun(){throw this.error}cancelRun(){throw this.error}unstable_notifySessionReset(){throw this.error}addToolResult(){throw this.error}resumeToolCall(){throw this.error}respondToToolApproval(){throw this.error}async unstable_recordToolInteraction(e){throw this.error}speak(){throw this.error}stopSpeaking(){throw this.error}connectVoice(){throw this.error}disconnectVoice(){throw this.error}muteVoice(){throw this.error}unmuteVoice(){throw this.error}submitFeedback(){throw this.error}exportExternalState(){throw this.error}importExternalState(){throw this.error}beginEdit(){throw this.error}import(){throw this.error}reset(){throw this.error}getModelContext(){return{}}getEditComposer(){}getVoiceVolume=()=>0;subscribeVoiceVolume=()=>()=>{};speech=void 0;voice=void 0;capabilities={switchToBranch:!1,switchBranchDuringRun:!1,edit:!1,delete:!1,reload:!1,refetchThread:!1,cancel:!1,unstable_copy:!1,speech:!1,dictation:!1,voice:!1,attachments:!1,feedback:!1,queue:!1,answerToolCall:!1};isDisabled=!1;isSendDisabled=!1;state=null;suggestions=[];extras=void 0;unstable_on(){return()=>{}}},Yd=e=>{let t=G(6),{adapters:n,children:r}=e,i=hn(Ju),a;t[0]!==n||t[1]!==i?(a={...i,...n},t[0]=n,t[1]=i,t[2]=a):a=t[2];let o=a,s;return t[3]!==r||t[4]!==o?(s=(0,J.jsx)(Ju.Provider,{value:o,children:r}),t[3]=r,t[4]=o,t[5]=s):s=t[5],s},Xd=new WeakMap,Zd=e=>{let t=Xd.get(e);return t||(t=new AbortController,Xd.set(e,t)),t.signal},Qd=new WeakMap,$d=e=>{let t=Qd.get(e);return t||(t=new AbortController,Qd.set(e,t)),t},ef=e=>$d(e).signal,tf=e=>{let t=Xd.get(e);t?.signal.aborted||(Xd.delete(e),t?.abort())},nf=(e,t)=>{try{e()}catch(e){console.error(`[assistant-ui] ${t} cleanup threw while discarding a thread runtime`,e)}},rf=e=>{e.voice&&nf(()=>e.disconnectVoice(),`Voice`),e.composer.dictation&&nf(()=>e.composer.stopDictation(),`Dictation`);let t=e.__internal_getEditComposers?.()??e.messages.map(t=>e.getEditComposer(t.id));for(let e of t)e?.dictation&&nf(()=>e.stopDictation(),`Dictation`);e.speech&&nf(()=>e.stopSpeaking(),`Speech`)},af=e=>{rf(e),tf(e)},of=e=>{let t=Xd.get(e)??new AbortController;Xd.set(e,t),t.abort(),$d(e).abort(),rf(e)},sf=class{get path(){return this._core.path}_core;_threadListBinding;constructor(e,t){this._core=e,this._threadListBinding=t,this.__internal_bindMethods()}__internal_bindMethods(){this.switchTo=this.switchTo.bind(this),this.rename=this.rename.bind(this),this.updateCustom=this.updateCustom.bind(this),this.archive=this.archive.bind(this),this.unarchive=this.unarchive.bind(this),this.delete=this.delete.bind(this),this.initialize=this.initialize.bind(this),this.generateTitle=this.generateTitle.bind(this),this.subscribe=this.subscribe.bind(this),this.unstable_on=this.unstable_on.bind(this),this.getState=this.getState.bind(this),this.detach=this.detach.bind(this)}getState(){return this._core.getState()}switchTo(e){let t=this._core.getState();return this._threadListBinding.switchToThread(t.id,e)}rename(e){let t=this._core.getState();return this._threadListBinding.rename(t.id,e)}updateCustom(e){let t=this._core.getState();if(!this._threadListBinding.updateCustom)throw Error(`Thread list runtime does not support updating custom metadata`);return this._threadListBinding.updateCustom(t.id,e)}archive(){let e=this._core.getState();return this._threadListBinding.archive(e.id)}unarchive(){let e=this._core.getState();return this._threadListBinding.unarchive(e.id)}delete(){let e=this._core.getState();return this._threadListBinding.delete(e.id)}initialize(){let e=this._core.getState();return this._threadListBinding.initialize(e.id)}generateTitle(e){let t=this._core.getState();return this._threadListBinding.generateTitle(t.id,e)}unstable_on(e,t){let n=this._core.getState().isMain,r=this._core.getState().id;return this.subscribe(()=>{let i=this._core.getState(),a=i.isMain,o=i.id;(n!==a||r!==o)&&(n=a,r=o,e===`switchedTo`&&!a||e===`switchedAway`&&a||w([t],{},`Thread list item "${e}"`))})}subscribe(e){return this._core.subscribe(e)}detach(){let e=this._core.getState();this._threadListBinding.detach(e.id)}__internal_getRuntime(){return this}},cf=Promise.resolve(),lf=()=>{},uf=e=>({canUnarchive:e.canUnarchive??!0,mainThreadId:e.mainThreadId,newThreadId:e.newThreadId,threadIds:e.threadIds,archivedThreadIds:e.archivedThreadIds,isLoading:e.isLoading,loadError:e.loadError,switchError:e.switchError,isLoadingMore:e.isLoadingMore??!1,hasMore:e.hasMore??!1,threadItems:e.threadItems}),df=(e,t)=>{if(t===void 0)return Ga;let n=e.getItemById(t);return n?{id:n.id,remoteId:n.remoteId,externalId:n.externalId,title:n.title,status:n.status,lastMessageAt:n.lastMessageAt,custom:n.custom,isMain:n.id===e.mainThreadId,isRunning:e.unstable_isThreadRunning?.(n.id)??!1}:Ga},ff=class{_getState;_stateBinding;_core;_runtimeFactory;constructor(e,t=Kd){this._core=e,this._runtimeFactory=t;let n=new eo({path:{},getState:()=>uf(e),subscribe:t=>e.subscribe(t)});this._getState=n.getState.bind(n),this._stateBinding=n,this._mainThreadListItemRuntime=new sf(new $a({path:{ref:`threadItems[main]`,threadSelector:{type:`main`}},getState:()=>df(this._core,this._core.mainThreadId),subscribe:e=>this._core.subscribe(e)}),this._core),this.main=new t(new to({path:{ref:`threads.main`,threadSelector:{type:`main`}},getState:()=>e.getMainThreadRuntimeCore(),subscribe:t=>e.subscribe(t)}),this._mainThreadListItemRuntime),this.__internal_bindMethods()}__internal_bindMethods(){this.switchToThread=this.switchToThread.bind(this),this.switchToNewThread=this.switchToNewThread.bind(this),this.unstable_subscribeThreadEvents=this.unstable_subscribeThreadEvents.bind(this),this.getLoadThreadsPromise=this.getLoadThreadsPromise.bind(this),this.reload=this.reload.bind(this),this.reloadMainThread=this.reloadMainThread.bind(this),this.loadMore=this.loadMore.bind(this),this.getState=this.getState.bind(this),this.subscribe=this.subscribe.bind(this),this.getById=this.getById.bind(this),this.getItemById=this.getItemById.bind(this),this.getItemByIndex=this.getItemByIndex.bind(this),this.getArchivedItemByIndex=this.getArchivedItemByIndex.bind(this)}switchToThread(e,t){return this._core.switchToThread(e,t)}switchToNewThread(){return this._core.switchToNewThread()}unstable_subscribeThreadEvents(e){return this._core.unstable_subscribeThreadEvents?.(e)??lf}getLoadThreadsPromise(){return this._core.getLoadThreadsPromise()}reload(){return this._core.reload?.()??cf}reloadMainThread(){return this._core.reloadMainThread?.()??cf}loadMore(){return this._core.loadMore?.()??cf}getState(){return this._getState()}subscribe(e){return this._stateBinding.subscribe(e)}_mainThreadListItemRuntime;main;get mainItem(){return this._mainThreadListItemRuntime}_createItemStateBinding(e){return new $a({path:{ref:`threadItems[threadId=${e}]`,threadSelector:{type:`threadId`,threadId:e}},getState:()=>df(this._core,e),subscribe:e=>this._core.subscribe(e)})}getById(e){return new this._runtimeFactory(new to({path:{ref:`threads[threadId=${JSON.stringify(e)}]`,threadSelector:{type:`threadId`,threadId:e}},getState:()=>this._core.getThreadRuntimeCore(e),subscribe:e=>this._core.subscribe(e)}),this._createItemStateBinding(e))}getItemByIndex(e){return new sf(new $a({path:{ref:`threadItems[${e}]`,threadSelector:{type:`index`,index:e}},getState:()=>df(this._core,this._core.threadIds[e]),subscribe:e=>this._core.subscribe(e)}),this._core)}getArchivedItemByIndex(e){return new sf(new $a({path:{ref:`archivedThreadItems[${e}]`,threadSelector:{type:`archiveIndex`,index:e}},getState:()=>df(this._core,this._core.archivedThreadIds[e]),subscribe:e=>this._core.subscribe(e)}),this._core)}getItemById(e){return new sf(this._createItemStateBinding(e),this._core)}},pf=class{threads;_thread;_core;constructor(e){this._core=e,this.threads=new ff(e.threads),this._thread=this.threads.main,this.__internal_bindMethods()}__internal_bindMethods(){this.registerModelContextProvider=this.registerModelContextProvider.bind(this)}get thread(){return this._thread}registerModelContextProvider(e){return this._core.registerModelContextProvider(e)}},mf=class{_contextProvider=new ro;registerModelContextProvider(e){return this._contextProvider.registerModelContextProvider(e)}getModelContextProvider(){return this._contextProvider}},hf=Object.freeze([]),gf=`DEFAULT_THREAD_ID`,_f=Object.freeze([gf]),vf=Object.freeze({id:gf,remoteId:void 0,externalId:void 0,status:`regular`}),yf=Promise.resolve(),bf=Object.freeze(k({[gf]:vf})),xf=class extends Xa{_mainThreadId=gf;_threads=_f;_archivedThreads=hf;_threadData=bf;adapter={};get isLoading(){return this.adapter.isLoading??!1}get canUnarchive(){return!!this.adapter.onUnarchive}get newThreadId(){}get threadIds(){return this._threads}get archivedThreadIds(){return this._archivedThreads}get threadItems(){return this._threadData}getLoadThreadsPromise(){return yf}_mainThread;get mainThreadId(){return this._mainThreadId}threadFactory;constructor(e={},t){super(),this.threadFactory=t,this.__internal_setAdapter(e,!0)}getMainThreadRuntimeCore(){return this._mainThread}getThreadRuntimeCore(){throw Error(`Method not implemented.`)}getItemById(e){return Object.hasOwn(this._threadData,e)?this._threadData[e]:void 0}__internal_setAdapter(e,t=!1){let n=this.adapter;this.adapter=e;let r=e.threadId??gf,i=e.threads??hf,a=e.archivedThreads??hf,o=n.threadId??gf,s=n.threads??hf,c=n.archivedThreads??hf;(t||(n.isLoading??!1)!==(e.isLoading??!1)||!!n.onUnarchive!=!!e.onUnarchive||o!==r||s!==i||c!==a)&&((s!==i||c!==a||o!==r)&&(this._threadData=k(Object.fromEntries(e.threads?.map(e=>[e.id,{...e,remoteId:e.remoteId,externalId:e.externalId,status:`regular`}])??[]),Object.fromEntries(e.archivedThreads?.map(e=>[e.id,{...e,remoteId:e.remoteId,externalId:e.externalId,status:`archived`}])??[]))),(s!==i||this._threads===_f&&o!==r)&&(this._threads=this.adapter.threads?.map(e=>e.id)??hf),c!==a&&(this._archivedThreads=this.adapter.archivedThreads?.map(e=>e.id)??hf),(t||o!==r)&&(t||of(this._mainThread),this._mainThreadId=r,this._mainThread=this.threadFactory()),Object.hasOwn(this._threadData,this._mainThreadId)||(this._threadData=k(this._threadData,{[this._mainThreadId]:{id:this._mainThreadId,remoteId:void 0,externalId:void 0,status:`regular`}})),this._notifySubscribers())}async reloadMainThread(){this._mainThread.unstable_refetchThread&&await this._mainThread.unstable_refetchThread()}async switchToThread(e,t){if(this._mainThreadId===e)return;let n=this.adapter.onSwitchToThread;if(!n)throw Error(`External store adapter does not support switching to thread`);await n(e)}async switchToNewThread(){let e=this.adapter.onSwitchToNewThread;if(!e)throw Error(`External store adapter does not support switching to new thread`);await e()}async rename(e,t){let n=this.adapter.onRename;if(!n)throw Error(`External store adapter does not support renaming`);await n(e,t)}async updateCustom(e,t){let n=this.adapter.onUpdateCustom;if(!n)throw Error(`External store adapter does not support updating custom metadata`);await n(e,t)}async detach(){}async archive(e){let t=this.adapter.onArchive;if(!t)throw Error(`External store adapter does not support archiving`);await t(e)}async unarchive(e){let t=this.adapter.onUnarchive;if(!t)throw Error(`External store adapter does not support unarchiving`);await t(e)}async delete(e){let t=this.adapter.onDelete;if(!t)throw Error(`External store adapter does not support deleting`);await t(e)}initialize(e){return Promise.resolve({remoteId:e,externalId:void 0})}generateTitle(){throw Error(`Method not implemented.`)}},Sf=class{_generation=0;begin(){return this._generation++,this.current()}current(){let e=this._generation;return{isCurrent:()=>e===this._generation}}invalidate(){this._generation++}};function*Cf(e,t){let n=[{type:`messages`,values:e,index:0}],r,i=e=>{if(!r){r=new WeakSet;for(let e of n)e.type===`messages`&&r.add(e.values)}return!r.has(e.values)&&(r.add(e.values),n.push(e),!0)};for(;n.length>0;){let e=n[n.length-1];if(e.index>=e.values.length){n.pop(),e.type===`messages`&&r?.delete(e.values);continue}if(e.type===`messages`){let t=e.values[e.index++];if(t?.role!==`assistant`||!Array.isArray(t.content))continue;n.push({type:`content`,values:t.content,messageId:t.id,index:0});continue}let a=e.values[e.index++];a&&a.type===`tool-call`&&(yield{part:a,messageId:e.messageId},a.messages?.length&&t?.shouldDescend?.(a)!==!1&&i({type:`messages`,values:a.messages,index:0}))}}var wf=e=>`content`in e&&!(`lastModified`in e),Tf=e=>e.status.type===`complete`,Ef=class{operations=new Set;uploading=new Map;start(){let e={cancelled:!1,attachmentIds:new Set};return this.operations.add(e),e}accept(e,t){if(e.cancelled)return!1;e.attachmentIds.add(t.id);let n=this.uploading.get(t.id);return n?.operation!==e&&(n||t.status.type===`running`)&&this.uploading.set(t.id,{operation:e,waiters:n?.waiters??new Set}),t.status.type!==`running`&&this.settle(t.id,e),!0}finish(e){this.operations.delete(e);for(let t of e.attachmentIds)this.settle(t,e)}isCancelled(e){return e.cancelled}cancel(e){for(let t of[...this.operations])t.attachmentIds.has(e)&&(t.cancelled=!0,this.operations.delete(t));this.settle(e)}cancelAll(e){for(let t of[...this.operations])e&&[...t.attachmentIds].some(t=>e.has(t))||(t.cancelled=!0,this.operations.delete(t));for(let t of[...this.uploading.keys()])e?.has(t)||this.settle(t)}whenSendable(e){let t=this.uploading.get(e);if(t)return new Promise(e=>t.waiters.add(e))}settle(e,t){let n=this.uploading.get(e);if(n&&!(t&&n.operation!==t)){this.uploading.delete(e);for(let e of n.waiters)e()}}},Df=async(e,t)=>{if(Symbol.asyncIterator in e){let n,r=!1;for await(let i of e)if(n===void 0&&(n=i.id),i.id!==n)r||=(console.warn(`[assistant-ui] AttachmentAdapter.add() yielded multiple attachment ids; only the first id is accepted`),!0);else if(!t(i))break}else t(await e)},Of=class{entries=new WeakMap;removals=new WeakMap;beginRemoval(e){let t=this.removals.get(e);return t?.phase!==`pending`&&(t?t.phase=`pending`:this.removals.set(e,{phase:`pending`,dispatched:!1,retried:!1,abandoned:!1}),!0)}abandonRemoval(e){let t=this.removals.get(e);t&&(t.abandoned=!0),this.removals.delete(e)}isRemoved(e){return this.removals.has(e)}shouldRemoveOnClear(e){let t=this.removals.get(e);return!t||t.dispatched&&t.retried&&t.phase===`failed`}isRemovalPending(e){return this.removals.get(e)?.phase===`pending`}async remove(e,t,n){let r=this.removals.get(e);try{if(!Tf(e)){if(!t)throw Error(`Attachments are not supported`);await t.remove(e)}r.phase=`complete`}catch(e){throw r.phase=`failed`,n?.(e,e instanceof Error?e.message:String(e)),this.retryDispatched(r),e}}dispatchRemoval(e,t){let n=this.removals.get(e);n&&(n.dispatched=!0,n.retry=t,this.retryDispatched(n))}retryDispatched(e){!e.abandoned&&e.dispatched&&e.phase===`failed`&&!e.retried&&e.retry&&(e.retried=!0,e.retry())}restore(e){let t=this.removals.get(e);if(!t||t.dispatched||t.phase!==`failed`)return e;let n={...e},r=this.entries.get(e);return r&&this.entries.set(n,r),n}restoreUnsent(e){let t=this.removals.get(e);if(!(t?.dispatched||t?.phase===`complete`))return this.restore(e)}adoptFrom(e,t){let n=e.removals.get(t);n&&this.removals.set(t,n);let r=e.entries.get(t);r&&this.entries.set(t,r)}isSameRemoval(e,t){let n=this.removals.get(e);return n!==void 0&&n===this.removals.get(t)}reconcileFailures(e,t,n){let r=new Map;return n.forEach((e,n)=>{e.status===`rejected`&&r.set(t[n].id,e.reason)}),e.map(e=>{if(!r.has(e.id)||Tf(e)||this.isRemoved(e))return e;let t=r.get(e.id);return this.transfer(e,{...e,status:{type:`incomplete`,reason:`error`,message:t instanceof Error?t.message:String(t)}})})}async send(e,t,n){if(Tf(e))return e;let r=this.entries.get(e)??{};if(r.result)return r.result;if(!t)throw Error(`Attachments are not supported`);this.entries.set(e,r);let i=await t.send(e,n?{signal:n}:void 0);return r.result=i,i}transfer(e,t){let n=this.entries.get(e);n&&this.entries.set(t,n);let r=this.removals.get(e);return r&&this.removals.set(t,r),t}},kf=(e,t,n=()=>!0)=>{let r=new Set,i=new Set;for(let a of e){let e=t(a)?.find(e=>!a.known.has(e)&&!r.has(e)&&n(a,e));e!==void 0&&(r.add(e),i.add(a))}return{landed:i,claimed:r}},Af=(e,t)=>e.filter(e=>!t.landed.has(e)).map(e=>({...e,known:new Set([...e.known,...t.claimed])})),jf=class{_host;constructor(e){this._host=e}rebase(e){if(!this._dictation)return;this._dictationBaseText=e,this._currentInterimText=``;let{status:t,inputDisabled:n}=this._dictation;this._dictation=n?{status:t,inputDisabled:n}:{status:t}}cancel(){if(!this._dictationSession)return;let e=this._activeDictationSessionId;try{this._dictationSession.cancel()}catch(e){console.error(`[assistant-ui] Dictation session cancel threw`,e)}finally{this._cleanupDictation({sessionId:e})}}_dictation;_dictationSession;_stoppingDictationSession;_dictationUnsubscribes=[];_dictationBaseText=``;_currentInterimText=``;_dictationSessionIdCounter=0;_activeDictationSessionId;_isCleaningDictation=!1;get dictation(){return this._dictation}_isActiveSession(e,t){return this._activeDictationSessionId===e&&this._dictationSession===t}startDictation(){let e=this._host.getAdapter();if(!e)throw Error(`Dictation adapter not configured`);let t=this._dictationSession!==void 0;if(this._dictationSession){let e=this._dictationSession;this._cleanupDictation({notify:!1}),this._stopDictationSession(e)}let n=e.disableInputDuringDictation??!1;this._dictationBaseText=this._host.getText(),this._currentInterimText=``;let r;try{r=e.listen()}catch(e){if(t)try{this._host.notify()}catch(e){console.error(`[assistant-ui] Dictation replacement rollback notification threw`,e)}throw e}this._dictationSession=r;let i=++this._dictationSessionIdCounter;this._activeDictationSessionId=i,this._dictation={status:r.status,inputDisabled:n};try{this._host.notify()}catch(e){console.error(`[assistant-ui] Dictation start notification threw`,e)}if(!this._isActiveSession(i,r))return;let a=[],o=()=>{for(let e of a.splice(0))try{e()}catch(e){console.error(`[assistant-ui] Dictation cleanup threw`,e)}},s=e=>(a.push(e),this._isActiveSession(i,r)?!0:(o(),!1));try{if(!s(r.onSpeech(e=>{if(!this._isActiveSession(i,r))return;let t=e.isFinal!==!1,n=this._dictationBaseText&&!this._dictationBaseText.endsWith(` `)&&e.transcript?` `:``;if(t){if(this._dictationBaseText=this._dictationBaseText+n+e.transcript,this._currentInterimText=``,this._host.setText(this._dictationBaseText),this._dictation){let{transcript:e,...t}=this._dictation;this._dictation=t}this._host.notify()}else this._currentInterimText=n+e.transcript,this._host.setText(this._dictationBaseText+this._currentInterimText),this._dictation&&={...this._dictation,transcript:e.transcript},this._host.notify()}))||!s(r.onSpeechStart(()=>{this._isActiveSession(i,r)&&(this._dictation={status:{type:`running`},inputDisabled:n,...this._dictation?.transcript&&{transcript:this._dictation.transcript}},this._host.notify())}))||!s(r.onSpeechEnd(()=>{this._cleanupDictation({sessionId:i})})))return;let e=setInterval(()=>{this._isActiveSession(i,r)&&r.status.type===`ended`&&this._cleanupDictation({sessionId:i})},100);if(!s(()=>clearInterval(e)))return;this._dictationUnsubscribes.push(...a.splice(0))}catch(e){if(o(),this._isActiveSession(i,r))try{r.cancel()}catch(e){console.error(`[assistant-ui] Dictation session cancel threw`,e)}finally{this._cleanupDictation({sessionId:i})}throw e}}stopDictation(){if(!this._dictationSession)return;let e=this._dictationSession;if(this._stoppingDictationSession===e)return;this._stoppingDictationSession=e;let t=this._activeDictationSessionId;this._stopDictationSession(e,()=>this._cleanupDictation({sessionId:t}))}_stopDictationSession(e,t=()=>{}){let n;try{n=e.stop()}catch(e){console.error(`[assistant-ui] Dictation session stop threw`,e),t();return}n.then(t,e=>{console.error(`[assistant-ui] Dictation session stop rejected`,e),t()})}_cleanupDictation(e){if(e?.sessionId!==void 0&&e.sessionId!==this._activeDictationSessionId||this._isCleaningDictation)return;this._isCleaningDictation=!0;let t=e=>{try{e()}catch(e){console.error(`[assistant-ui] Dictation cleanup threw`,e)}};try{let n=this._dictationUnsubscribes;this._dictationUnsubscribes=[],this._dictationSession=void 0,this._stoppingDictationSession=void 0,this._activeDictationSessionId=void 0,this._dictation=void 0,this._dictationBaseText=``,this._currentInterimText=``;for(let e of n)t(e);e?.notify!==!1&&t(()=>this._host.notify())}finally{this._isCleaningDictation=!1}}},Mf=class extends Xa{isEditing=!0;enrichWithComposerMetadata(e,t){return t?{...e,metadata:{...e.metadata,custom:{...e.metadata?.custom,...t}}}:e}get attachmentAccept(){return this.getAttachmentAdapter()?.accept??`*`}_attachments=[];get attachments(){return this._attachments}setAttachments(e){this._attachments=e,this._notifySubscribers()}get isEmpty(){return!this.text.trim()&&!this.sendableAttachments.length}get sendableAttachments(){return this.attachments.filter(e=>!this._attachmentSends.isRemoved(e))}_text=``;_dictationSessionController=new jf({getAdapter:()=>this.getDictationAdapter(),getText:()=>this._text,setText:e=>this._writeText(e,`user`),notify:()=>this._notifySubscribers()});get text(){return this._text}_role=`user`;get role(){return this._role}_runConfig={};get runConfig(){return this._runConfig}_quote=void 0;get quote(){return this._quote}setQuote(e){this._quote!==e&&(this._quote=e,this._notifySubscribers())}setText(e,t){this._text!==e&&(this._writeText(e,t?.origin??`external`),this._rebaseDictation(e),this._notifySubscribers())}_pendingTextChanges=[];_isFlushingTextChanges=!1;_notifyDepth=0;_writeText(e,t){this._text!==e&&(this._text=e,this._pendingTextChanges.push({text:e,origin:t}))}_notifySubscribers(){this._notifyDepth++;try{super._notifySubscribers()}finally{--this._notifyDepth===0&&this._flushTextChanges()}}_flushTextChanges(){if(!this._isFlushingTextChanges){this._isFlushingTextChanges=!0;for(let e=this._pendingTextChanges.shift();e;e=this._pendingTextChanges.shift())this._notifyEventSubscribers(`textChange`,e);this._isFlushingTextChanges=!1}}_rebaseDictation(e){this._dictationSessionController.rebase(e)}setRole(e){this._role!==e&&(this._role=e,this._notifySubscribers())}setRunConfig(e){this._runConfig!==e&&(this._runConfig=e,this._notifySubscribers())}_submission;_submissionSend;_inTransit=[];_inTransitSubmissions=[];_sendGeneration=0;_draftEpoch=0;_attachmentAddOperations=new Ef;_attachmentSends=new Of;get submission(){return this._submission}get inTransit(){return this._inTransitSubmissions}get isSubmitting(){return this._submission!==void 0}get detachesDraftOnSend(){return!0}threadMessageIds(e){}settleInTransit(){if(this._inTransit.length===0)return;let e=kf(this._inTransit,e=>this.threadMessageIds(e.submission.role));e.landed.size!==0&&(this._setInTransit(Af(this._inTransit,e)),this._notifySubscribers())}_setInTransit(e){this._inTransit=e,this._inTransitSubmissions=e.map(e=>e.submission)}_leaveTransit(e){let t=this._inTransit.filter(t=>t.submission!==e);return t.length!==this._inTransit.length&&(this._setInTransit(t),!0)}_cancelAttachmentAdd(e){this._attachmentAddOperations.cancel(e)}_cancelAllAttachmentAdds(){this._attachmentAddOperations.cancelAll()}_emptyTextAndAttachments(){this._attachments=[],this._writeText(``,`reset`),this._rebaseDictation(``),this._notifySubscribers()}_draftUploadsToRemove(){return this._attachments.filter(e=>!Tf(e)&&this._attachmentSends.shouldRemoveOnClear(e))}async _onClearAttachments(e){let t=this.getAttachmentAdapter();t&&await Promise.all(e.map(e=>(this._attachmentSends.beginRemoval(e),this._attachmentSends.remove(e,t))))}async reset(){this._cancelAllAttachmentAdds(),this._draftEpoch++,this._sendGeneration++;let e=this._discardSubmission();if(this._attachments.length===0&&this._text===``&&this._role===`user`&&Object.keys(this._runConfig).length===0&&this._quote===void 0){await e;return}this._role=`user`,this._runConfig={},this._quote=void 0;let t=this._onClearAttachments(this._draftUploadsToRemove());this._emptyTextAndAttachments(),await Promise.all([t,e])}async clearAttachments(){this._draftEpoch++,this._attachmentAddOperations.cancelAll(this.detachesDraftOnSend?new Set(this._submission?.attachments.map(e=>e.id)):void 0);let e=this._draftUploadsToRemove();if(this.isSubmitting)for(let e of this._attachments)this._attachmentSends.beginRemoval(e);let t=this._onClearAttachments(e);this.setAttachments([]),await t}async send(e){if(!this.canSend||this.isSubmitting)return;this._dictationSessionController.cancel();let t=this.sendableAttachments;if(!this.text.trim()&&t.length===0)return;let n={id:h(),role:this.role,text:this.text,quote:this._quote,attachments:t},r={options:e,runConfig:this.runConfig},i=t.filter(Tf),a=i.length===t.length;if(a||(this._submission=n,this._submissionSend={...r,controller:new AbortController}),this.detachesDraftOnSend){let e=new Set(t);this._attachments=this._attachments.filter(t=>!e.has(t)),this._writeText(``,`send`),this._rebaseDictation(``),this._quote=void 0}let o=++this._sendGeneration;this._notifySubscribers(),a?this._dispatch(o,n,i,r,!1):await this._prepareSubmission(o)}async _prepareSubmission(e){let t=this.getAttachmentAdapter(),n=(this._submission?.attachments??[]).flatMap(e=>{let t=this._attachmentAddOperations.whenSendable(e.id);return t?[t]:[]});if(n.length>0&&(await Promise.all(n),e!==this._sendGeneration))return;let r=this._submission,i=this._submissionSend;if(!r||!i)return;let a=r.attachments.filter(e=>!this._attachmentSends.isRemoved(e));for(let e of a)this._cancelAttachmentAdd(e.id);let o=await Promise.allSettled(a.map(e=>this._attachmentSends.send(e,t,i.controller.signal)));if(e!==this._sendGeneration)return;let s=o.find(e=>e.status===`rejected`);if(s){this._returnSubmissionToDraft(a,o,s.reason);return}let c=o.flatMap((e,t)=>this._attachmentSends.isRemoved(a[t])||e.status===`rejected`?[]:[e.value]),l=this._submission??r;!l.text.trim()&&c.length===0?(this._endSubmission(),this._returnToDraft(l)):this._dispatch(e,l,c,i,!0)}_dispatch(e,t,n,r,i){let a={createdAt:new Date,role:t.role,content:t.text?[{type:`text`,text:t.text}]:[],attachments:n,runConfig:r.runConfig,metadata:{custom:{...t.quote?{quote:t.quote}:{}}}},o={...t,attachments:n},s=new Map(t.attachments.filter(e=>!this._attachmentSends.isRemoved(e)).map((e,t)=>[e,n[t]])),c={...t,attachments:t.attachments.map(e=>s.get(e)??e)},l=this.queue.length;if(i){if(this._submission=void 0,this._submissionSend=void 0,!this.detachesDraftOnSend){let e=new Map(t.attachments.map((e,t)=>[e.id,c.attachments[t]]));this._attachments=this._attachments.map(t=>e.get(t.id)??t)}let e=this.threadMessageIds(t.role);e&&this._setInTransit([...this._inTransit,{submission:o,known:new Set(e)}])}let u=this.cleanupOwner,d=u._draftEpoch,f;try{f=this.handleSend(a,r.options)}catch(t){console.error(`[assistant-ui] Failed to send the message`,t),this._leaveTransit(o),e===this._sendGeneration?this._returnToDraft(c):this._notifySubscribers();return}if(f&&f.catch(t=>{let n=this._leaveTransit(o);e===this._sendGeneration&&Ys(t)?this._returnToDraft(c):n&&this._notifySubscribers()}),i)for(let e of t.attachments)Tf(e)||this._attachmentSends.dispatchRemoval(e,()=>void this._retrySubmittedRemoval(e,u,d));this._notifyEventSubscribers(`send`,{chars:t.text.length,attachments:n.length}),i&&(this.queue.length>l&&this._leaveTransit(o),this._notifySubscribers(),this.settleInTransit())}_returnSubmissionToDraft(e,t,n){let r=this._submission;if(!r)return;let i=this._attachmentSends.reconcileFailures(r.attachments,e,t);this._endSubmission(),this._returnToDraft({...r,attachments:i}),console.error(`[assistant-ui] Failed to send attachments`,n)}_endSubmission(){this._sendGeneration++,this._submission=void 0,this._submissionSend=void 0}__internal_dispose(){this._cancelAllAttachmentAdds(),this._submission&&(this._submissionSend?.controller.abort(),this._endSubmission(),this._notifySubscribers())}cancelSubmission(){let e=this._submission;e&&(this._submissionSend?.controller.abort(),this._endSubmission(),this._returnToDraft(e))}_returnToDraft(e){if(this.detachesDraftOnSend){let t=e.attachments.flatMap(e=>{let t=this._attachmentSends.restoreUnsent(e);return t?[t]:[]});this._attachments=[...t,...this._attachments];let n=[e.text,this._text].filter(Boolean).join(`
|
|
19
|
+
`);this._writeText(n,`return`),this._rebaseDictation(n),this._quote=this._quote??e.quote}else{let t=new Map(e.attachments.flatMap(e=>{let t=this._attachmentSends.restoreUnsent(e);return t?[[e.id,t]]:[]}));this._attachments=this._attachments.flatMap(e=>{let n=this._attachmentSends.restoreUnsent(e);return n?[t.get(e.id)??n]:[]})}this._notifySubscribers()}async _discardSubmission(){let e=this._submission;if(!e)return;this._submissionSend?.controller.abort(),this._endSubmission(),this._notifySubscribers();let t=this.getAttachmentAdapter();if(!t)return;let n=new Set(this._attachments.map(e=>e.id));await Promise.all(e.attachments.filter(e=>!Tf(e)&&!n.has(e.id)&&!this._attachmentSends.isRemovalPending(e)).map(async e=>t.remove(e)))}restoreDraft(e){return this._text.trim()||this._quote!==void 0||this._attachments.length>0?!1:(this._writeText(e.text,`return`),this._rebaseDictation(e.text),this._quote=e.quote,this._attachments=e.attachments??[],this._notifySubscribers(),!0)}retractDraft(e){let t=e.attachments===void 0?this._attachments.length===0:this._attachments===e.attachments;this._text===e.text&&this._quote===e.quote&&t&&(this._writeText(``,`send`),this._rebaseDictation(``),this._quote=void 0,this._attachments=[],this._notifySubscribers())}cancel(){this.detachesDraftOnSend||(this._dictationSessionController.cancel(),this.isSubmitting&&(this._submissionSend?.controller.abort(),this._endSubmission(),this._notifySubscribers())),this.handleCancel()}get queue(){return Vc}moveQueueItem(e,t){}removeQueueItem(e){}async addAttachment(e){if(wf(e)){let t=this.getAttachmentAdapter();if(t&&!v({name:e.name,type:e.contentType??``},t.accept)){let n=`File type ${e.contentType||`unknown`} is not accepted. Accepted types: ${t.accept}`,r=Error(n);throw this._safeEmitAttachmentAddError(`not-accepted`,n,void 0,r,e.contentType),r}let n={id:e.id??h(),type:e.type??`document`,name:e.name,contentType:e.contentType,content:e.content,status:{type:`complete`}};this._attachments=[...this._attachments,n],this._notifySubscribers(),this._notifyEventSubscribers(`attachmentAdd`,{...n.contentType?{contentType:n.contentType}:void 0});return}let t=this.getAttachmentAdapter();if(!t){let t=`Attachments are not supported`,n=Error(t);throw this._safeEmitAttachmentAddError(`no-adapter`,t,void 0,n,e.type),n}if(!v({name:e.name,type:e.type},t.accept)){let n=`File type ${e.type||`unknown`} is not accepted. Accepted types: ${t.accept}`,r=Error(n);throw this._safeEmitAttachmentAddError(`not-accepted`,n,void 0,r,e.type),r}let n=this._attachmentAddOperations.start(),r=e=>{if(!this._attachmentAddOperations.accept(n,e))return!1;let t=this._submission,r=t?.attachments.some(t=>t.id===e.id)??!1;t&&r&&(this._submission={...t,attachments:t.attachments.map(t=>t.id===e.id?this._attachmentSends.transfer(t,e):t)});let i=this._attachments.findIndex(t=>t.id===e.id);return i===-1?r||(this._attachments=[...this._attachments,e]):this._attachments=[...this._attachments.slice(0,i),e,...this._attachments.slice(i+1)],this._notifySubscribers(),!0},i;try{await Df(t.add({file:e}),e=>(i=e,r(e)))}catch(t){if(this._attachmentAddOperations.isCancelled(n))return;throw i&&r({...i,status:{type:`incomplete`,reason:`error`,message:t instanceof Error?t.message:String(t)}}),this._safeEmitAttachmentAddError(`adapter-error`,t instanceof Error?t.message:String(t),i?.id,t instanceof Error?t:void 0,i?.contentType||e.type),t}finally{this._attachmentAddOperations.finish(n)}this._attachmentAddOperations.isCancelled(n)||(i?.status.type===`incomplete`&&i.status.reason===`error`?this._safeEmitAttachmentAddError(`adapter-error`,i.status.message??`Attachment upload did not complete successfully.`,i.id,void 0,i.contentType||e.type):this._notifyEventSubscribers(`attachmentAdd`,{...i?.contentType?{contentType:i.contentType}:e.type?{contentType:e.type}:void 0}))}_safeEmitAttachmentAddError(e,t,n,r,i){try{this._notifyEventSubscribers(`attachmentAddError`,{reason:e,message:t,...n!==void 0&&{attachmentId:n},...r!==void 0&&{error:r},...i?{contentType:i}:void 0})}catch(e){console.error(`[assistant-ui] attachmentAddError subscriber threw:`,e)}}async removeAttachment(e){let t=this._attachments.find(t=>t.id===e)??this._submission?.attachments.find(t=>t.id===e);if(!t)throw Error(`Attachment not found`);let n=this.getAttachmentAdapter();if(!Tf(t)&&!n)throw Error(`Attachments are not supported`);if(!this._attachmentSends.beginRemoval(t))return;this._cancelAttachmentAdd(e),this._notifySubscribers(),await this._attachmentSends.remove(t,n,(e,n)=>{let r=e=>this._attachmentSends.transfer(e,{...e,status:{type:`incomplete`,reason:`error`,message:n}}),i=this._submission;i&&(this._submission={...i,attachments:i.attachments.map(e=>!Tf(e)&&this._attachmentSends.isSameRemoval(e,t)?r(e):e)}),this._attachments.some(e=>this._attachmentSends.isSameRemoval(e,t))&&(this._attachments=this._attachments.map(e=>!Tf(e)&&this._attachmentSends.isSameRemoval(e,t)?r(e):e),this._submission||(this._attachments=this._attachments.map(e=>this._attachmentSends.isSameRemoval(e,t)?this._attachmentSends.restore(e):e))),this._notifySubscribers()});let r=this._submission;r&&(this._submission={...r,attachments:r.attachments.filter(e=>!this._attachmentSends.isSameRemoval(e,t))}),this._attachments.some(e=>this._attachmentSends.isSameRemoval(e,t))&&(this._attachments=this._attachments.filter(e=>!this._attachmentSends.isSameRemoval(e,t))),this._notifySubscribers()}get cleanupOwner(){return this}_adoptCleanupFailure(e,t,n){this._draftEpoch===n&&(this._attachments.some(e=>e.id===t.id)||(this._attachmentSends.adoptFrom(e,t),this._attachments=[t,...this._attachments],this._notifySubscribers()))}async _retrySubmittedRemoval(e,t,n){this._attachmentSends.beginRemoval(e),await this._attachmentSends.remove(e,this.getAttachmentAdapter(),(r,i)=>{console.error(`[assistant-ui] Failed to remove sent attachment`,r);let a=this._attachmentSends.transfer(e,{...e,status:{type:`incomplete`,reason:`error`,message:i}});t._adoptCleanupFailure(this._attachmentSends,a,n)}).catch(()=>{})}get dictation(){return this._dictationSessionController.dictation}startDictation(){this._dictationSessionController.startDictation()}stopDictation(){this._dictationSessionController.stopDictation()}_eventSubscribers=new Map;_notifyEventSubscribers(e,t){let n=this._eventSubscribers.get(e);n&&w(n,t,`Composer runtime "${e}"`)}unstable_on(e,t){let n=t,r=this._eventSubscribers.get(e);return r||(r=new Set,this._eventSubscribers.set(e,r)),r.add(n),()=>{this._eventSubscribers.get(e)?.delete(n)}}},Nf=e=>e.capabilities?.cancel?Wd(e):!1,Pf=class extends Mf{get canCancel(){return this.isSubmitting||Nf(this.runtime)}get canSend(){if(this.runtime.isDisabled||this.isEmpty||this.runtime.isSendDisabled||this.isSubmitting)return!1;let e=this.runtime.voice;return!e||e.canSendText&&this.role===`user`&&this.sendableAttachments.length===0}addAttachment(e){return this.runtime.isDisabled?Promise.resolve():super.addAttachment(e)}startDictation(){this.runtime.isDisabled||super.startDictation()}cancel(){this.isSubmitting?(this.cancelSubmission(),Nf(this.runtime)&&super.cancel()):super.cancel()}threadMessageIds(e){return this.runtime.messages.filter(t=>t.role===e).map(e=>e.id)}_queueCache;get queue(){let e=this.runtime.getSteerQueueItems?.()??Vc,t=this.runtime.getQueueItems?.()??Vc,n=this._queueCache;if(n&&n.steer===e&&n.queue===t)return n.flat;let r=e.length===0?t:t.length===0?e:[...e,...t];return this._queueCache={steer:e,queue:t,flat:r},r}moveQueueItem(e,t){this.runtime.moveQueueItem?.(e,t)}removeQueueItem(e){this.runtime.removeQueueItem?.(e)}getAttachmentAdapter(){return this.runtime.adapters?.attachments}getDictationAdapter(){return this.runtime.adapters?.dictation}runtime;constructor(e){super(),this.runtime=e,this.connect()}connect(){let e=!1,t=this.runtime.isDisabled,n=this.runtime.isSendDisabled,r=this.runtime.voice?.canSendText,i=this.queue;return this.runtime.subscribe(()=>{this.settleInTransit();let a=!1,o=this.canCancel;e!==o&&(e=o,a=!0),t!==this.runtime.isDisabled&&(t=this.runtime.isDisabled,a=!0),n!==this.runtime.isSendDisabled&&(n=this.runtime.isSendDisabled,a=!0);let s=this.runtime.voice?.canSendText;r!==s&&(r=s,a=!0),i!==this.queue&&(i=this.queue,a=!0),a&&this._notifySubscribers()})}async handleSend(e,t){return this.runtime.append({...e,parentId:this.runtime.messages.at(-1)?.id??null,sourceId:null,startRun:t?.startRun,steer:t?.steer})}async handleCancel(){this.runtime.cancelRun()}},Ff=class extends Mf{get canCancel(){return!0}get detachesDraftOnSend(){return!1}get cleanupOwner(){return this.runtime.composer instanceof Mf?this.runtime.composer:this}get canSend(){return!this.runtime.isDisabled&&!this.isEmpty&&!this.runtime.voice&&!this.isSubmitting}addAttachment(e){return this.runtime.isDisabled?Promise.resolve():super.addAttachment(e)}startDictation(){this.runtime.isDisabled||super.startDictation()}getAttachmentAdapter(){return this.runtime.adapters?.attachments}getDictationAdapter(){return this.runtime.adapters?.dictation}_nonTextPassthrough;_parentId;_sourceId;runtime;endEditCallback;onMessageNotSent;_ended=!1;constructor(e,t,{parentId:n,message:r,onMessageNotSent:i}){super(),this.runtime=e,this.onMessageNotSent=i;let a=e.voice!==void 0,o=e.isDisabled,s=e.subscribe(()=>{let t=e.voice!==void 0,n=e.isDisabled;(t!==a||n!==o)&&(a=t,o=n,this._notifySubscribers())});this.endEditCallback=()=>{s(),t()},this._parentId=n,this._sourceId=r.id,this.setText(T(r)),this.setRole(r.role);let c;r.role===`user`?(c=[...r.attachments??[],...b(r.content)],this._nonTextPassthrough=[]):(c=r.attachments??[],this._nonTextPassthrough=r.content.filter(e=>e.type!==`text`)),this.setAttachments(c),this.setQuote(r.metadata.custom.quote),this.setRunConfig({...e.composer.runConfig})}get parentId(){return this._parentId}get sourceId(){return this._sourceId}async handleSend(e,t){let n=this._nonTextPassthrough.length>0?[...e.content,...this._nonTextPassthrough]:e.content,r={...e,content:n,parentId:this._parentId,sourceId:this._sourceId,startRun:t?.startRun},i=this.runtime.append(r);this.handleCancel();try{await i}catch(e){throw Ys(e)&&this.onMessageNotSent?.(r),e}}handleCancel(){this._ended||(this._ended=!0,this.reset().catch(e=>{console.error(`[assistant-ui] Failed to clear cancelled edit`,e)}),this.endEditCallback(),this._notifySubscribers())}},If=class{voiceMessages=[];voiceGeneration=0;_cachedMergedMessages=null;_cachedVoiceGeneration=-1;_cachedMergedBase=null;host;constructor(e){this.host=e}markMessagesDirty(){this.voiceGeneration++,this._cachedMergedMessages=null}dropMessage(e,t){let n=this.voiceMessages.findIndex(t=>t.id===e);n!==-1&&(this.voiceMessages.splice(n,1),this.host.markVoiceMessagesDirty(),t&&this.host.notify())}getMessages(){if(this.voiceMessages.length===0)return this.host.getBaseMessages();let e=this.host.getBaseMessages();if(this._cachedVoiceGeneration!==this.voiceGeneration||this._cachedMergedBase!==e){let t=new Set(e.map(e=>e.id));this._cachedMergedMessages=[...e,...this.voiceMessages.filter(e=>!t.has(e.id))],this._cachedVoiceGeneration=this.voiceGeneration,this._cachedMergedBase=e}return this._cachedMergedMessages}replaceAssistantMessage(e,t){this._currentAssistantMsg===e&&(this._currentAssistantMsg=t)}isVoiceMessage(e){return e!==null&&this.voiceMessages.some(t=>t.id===e)}_voiceSession;_voiceUnsubs=[];voice;_voiceVolume=0;_voiceVolumeSubscribers=new Set;getVoiceVolume=()=>this._voiceVolume;subscribeVoiceVolume=e=>(this._voiceVolumeSubscribers.add(e),()=>this._voiceVolumeSubscribers.delete(e));_toVoiceSessionState(e,t,n){return{status:t,isMuted:e.isMuted,mode:n,canSendText:t.type===`running`&&e.sendText!==void 0}}isRunActive(){if(this.host.isRunning())return!0;let e=this.host.getBaseMessages().at(-1);return e?.role===`assistant`&&(e.status.type===`running`||e.status.type===`requires-action`)}getVoiceCommitBarrier(){if(!this.host.isLoading())return;let e=this.host.captureGeneration();return(async()=>{for(;this.host.isLoading()&&!e.aborted;)await new Promise(t=>{let n=()=>{r(),e.removeEventListener(`abort`,n),t()},r=this.host.subscribe(n);e.addEventListener(`abort`,n)})})()}connectVoice(){let e=this.host.adapter();if(!e)throw Error(`Voice adapter not configured`);if(this.host.isRunActive())throw Error(`Cannot start a voice session while a run is in progress or paused on a pending tool action`);let t=this._voiceSession!==void 0;try{this._disconnectVoice(!1)}catch(e){console.error(`[assistant-ui] Voice cleanup threw before reconnect`,e)}if(this._voiceSession!==void 0)return;let n;try{n=e.connect({})}catch(e){throw t&&this._voiceSession===void 0&&this.host.onDisconnected(),e}if(n.status.type===`ended`){try{n.disconnect()}finally{t&&this._voiceSession===void 0&&this.host.onDisconnected()}return}this._voiceSession=n;let r=[];this._voiceUnsubs=r;let i=()=>{if(this._voiceSession===n&&this._voiceUnsubs===r)return!1;try{Ka(r.splice(0))}catch(e){console.error(`[assistant-ui] Detached voice setup cleanup threw`,e)}return!0};try{let e=`listening`;if(this.voice=this._toVoiceSessionState(n,n.status,e),this._voiceVolume=0,this.host.notify(),i()||(r.push(n.onStatusChange(t=>{if(this._voiceSession===n){if(t.type===`ended`){this._voiceSession=void 0,this.voice=void 0,this._voiceVolume=0;try{Ka([()=>this._finishVoiceAssistantMessage(!1),()=>{this._voiceSession===void 0&&this.host.onDisconnected()},()=>w(this._voiceVolumeSubscribers,void 0,`Voice volume`),()=>this.host.notify()])}finally{i()}}else this.voice=this._toVoiceSessionState(n,t,e),this.host.notify()}})),i())||(r.push(n.onModeChange(t=>{this._voiceSession===n&&(e=t,this.voice&&(this.voice={...this.voice,mode:t},this.host.notify()))})),i())||(r.push(n.onVolumeChange(e=>{this._voiceSession===n&&(this._voiceVolume=e,w(this._voiceVolumeSubscribers,void 0,`Voice volume`))})),i()))return;r.push(n.onTranscript(e=>{this._voiceSession===n&&this._handleVoiceTranscript(e)})),i()||this.host.onConnected()}catch(e){if(this._voiceSession===n&&this._voiceUnsubs===r){try{this._disconnectVoice(!1)}catch(e){console.error(`[assistant-ui] Voice rollback cleanup threw`,e)}t&&this._voiceSession===void 0&&this.host.onDisconnected()}else i();throw e}}_currentAssistantMsg=null;_observeVoiceCommit(e){new Promise(t=>t(e())).catch(e=>{console.error(`[assistant-ui] Voice message commit failed`,e)})}_handleVoiceTranscript(e){let t=this._voiceSession;if(this.host.ensureInitialized(),this._voiceSession===t){if(e.role===`user`){if(this._finishVoiceAssistantMessage(),this._voiceSession!==t)return;this._currentAssistantMsg=null,e.isFinal&&this._observeVoiceCommit(()=>this._commitVoiceUserMessage({id:h(),role:`user`,content:[{type:`text`,text:e.text}],metadata:{modality:`voice`,custom:{}},createdAt:new Date,attachments:[]}))}else{let t=e.isFinal?{type:`complete`,reason:`stop`}:{type:`running`};if(!this._currentAssistantMsg)this._currentAssistantMsg={id:h(),role:`assistant`,content:[{type:`text`,text:e.text}],metadata:{unstable_state:this.host.state(),unstable_annotations:[],unstable_data:[],steps:[],modality:`voice`,custom:{}},status:t,createdAt:new Date},this.voiceMessages.push(this._currentAssistantMsg);else{let n=this.voiceMessages.indexOf(this._currentAssistantMsg);if(n===-1)return;let r={...this._currentAssistantMsg,content:[{type:`text`,text:e.text}],status:t};this.voiceMessages[n]=r,this._currentAssistantMsg=r}if(e.isFinal){let e=this._currentAssistantMsg;this._observeVoiceCommit(()=>this.host.commitVoiceMessage(e)),this._currentAssistantMsg=null}this.host.markVoiceMessagesDirty(),this.host.notify()}}}_commitVoiceUserMessage(e){this.voiceMessages.push(e);try{return this.host.commitVoiceMessage(e)}finally{this.host.markVoiceMessagesDirty(),this.host.notify()}}async appendToVoiceSession(e){let t=this._voiceSession;if(!this.voice?.canSendText||!t?.sendText)throw Error(`Cannot send a text message while a voice session is connected`);let n=e.content.filter(e=>e.type===`text`);if(e.role!==`user`||e.sourceId!=null||e.parentId!==this.host.resolveAppendParent(this.host.messages().at(-1)?.id??null)||e.attachments?.length||n.length!==e.content.length||!n.some(e=>e.text.trim()))throw Error(`Only a plain text user message can be sent while a voice session is connected`);let r=this.host.enrichAppendMetadata(e);this.host.ensureInitialized();let i=this.host.captureGeneration();try{await t.sendText(T(e))}catch(e){if(i.aborted)return;let t=new Js;throw t.cause=e,t}if(!i.aborted){if(this._voiceSession!==t||(this._finishVoiceAssistantMessage(!1),this._voiceSession!==t))throw new Js(`The voice session ended before the typed message was recorded`);this._currentAssistantMsg=null,await this._commitVoiceUserMessage({id:h(),role:`user`,content:n,metadata:{custom:{...r.metadata?.custom}},createdAt:e.createdAt,attachments:[]})}}_finishVoiceAssistantMessage(e=!0){let t=this.voiceMessages.at(-1);if(t?.role===`assistant`&&t.status.type===`running`){let n=this.voiceMessages.length-1;this.voiceMessages[n]={...t,status:{type:`complete`,reason:`stop`}},this._observeVoiceCommit(()=>this.host.commitVoiceMessage(this.voiceMessages[n])),this._currentAssistantMsg=null,this.host.markVoiceMessagesDirty(),e&&this.host.notify()}}disconnectVoice(){this._disconnectVoice(!0)}_disconnectVoice(e){this._finishVoiceAssistantMessage(!1),this._currentAssistantMsg=null;let t=this._voiceUnsubs.splice(0);this._voiceUnsubs=[];let n=this._voiceSession;this._voiceSession=void 0,this.voice=void 0,this._voiceVolume=0;let r=this.host.stopSpeakingForVoiceMessage();this.voiceMessages=[],this.host.markVoiceMessagesDirty();try{Ka([...t,...r?[r]:[],...n?[()=>n.disconnect()]:[],()=>w(this._voiceVolumeSubscribers,void 0,`Voice volume`),()=>this.host.notify()])}finally{e&&n&&this._voiceSession===void 0&&this.host.onDisconnected()}}muteVoice(){if(!this._voiceSession)throw Error(`No active voice session`);this._voiceSession.mute(),this.voice={...this.voice,isMuted:!0},this.host.notify()}unmuteVoice(){if(!this._voiceSession)throw Error(`No active voice session`);this._voiceSession.unmute(),this.voice={...this.voice,isMuted:!1},this.host.notify()}},Lf=class extends Xa{_isInitialized=!1;repository=new Bc;_voiceController=new If({adapter:()=>this.adapters?.voice,isRunning:()=>this.isRunning===!0,isRunActive:()=>this._isRunActive(),isLoading:()=>this.isLoading,getBaseMessages:()=>this._getBaseMessages(),messages:()=>this.messages,state:()=>this.state,notify:()=>this._notifySubscribers(),subscribe:e=>this.subscribe(e),captureGeneration:()=>Zd(this),ensureInitialized:()=>this.ensureInitialized(),commitVoiceMessage:e=>this._commitVoiceMessage(e),markVoiceMessagesDirty:()=>this._markVoiceMessagesDirty(),onConnected:()=>this._onVoiceConnected(),onDisconnected:()=>this._onVoiceDisconnected(),enrichAppendMetadata:e=>this.enrichAppendMetadata(e),resolveAppendParent:e=>this._resolveAppendParent(e),stopSpeakingForVoiceMessage:()=>this.speech&&this._isVoiceMessage(this.speech.messageId)?this._stopSpeaking:void 0});get _voiceMessages(){return this._voiceController.voiceMessages}set _voiceMessages(e){this._voiceController.voiceMessages=e}get _voiceGeneration(){return this._voiceController.voiceGeneration}set _voiceGeneration(e){this._voiceController.voiceGeneration=e}_markVoiceMessagesDirty(){this._voiceController.markMessagesDirty()}_getBaseMessages(){return this.repository.getMessages()}_commitVoiceMessage(e){}_onMessageMetadataChanged(e,t){}_dropVoiceMessage(e,t){this._voiceController.dropMessage(e,t)}get messages(){return this._voiceController.getMessages()}get state(){let e;for(let t of this.messages)t.role===`assistant`&&(e=t);return e?.metadata.unstable_state??null}composer=new Pf(this);_contextProvider;constructor(e){super(),this._contextProvider=e,ef(this).addEventListener(`abort`,()=>{this.composer.__internal_dispose();for(let e of this._editComposers.values())e.__internal_dispose()})}getModelContext(){return this._contextProvider.getModelContext()}enrichAppendMetadata(e,t=e.parentId){if(e.role!==`user`)return e;let n=this.messages,r=t===null?-1:n.findIndex(e=>e.id===t),i=me(this.getModelContext().unstable_composerMetadata,n.slice(0,r+1));return i?{...e,metadata:{...e.metadata,custom:{...e.metadata?.custom,...i}}}:e}_editComposers=new Map;_editAttempts=new WeakMap;getEditComposer(e){return this._editComposers.get(e)}__internal_getEditComposers(){return this._editComposers.values()}_isVoiceMessage(e){return this._voiceController.isVoiceMessage(e)}_resolveAppendParent(e){return this._isVoiceMessage(e)?this._getBaseMessages().at(-1)?.id??null:e}beginEdit(e){if(this.voice)throw Error(`Cannot edit a message while a voice session is connected`);if(this._isVoiceMessage(e))throw Error(`Voice transcript messages cannot be edited`);if(this._editComposers.has(e))throw Error(`Edit already in progress`);let t=this.repository.getMessage(e),n=this.repository,r=Zd(this),i={};this._editAttempts.set(t.message,i);let a=(o,s)=>{let c=new Ff(this,()=>this._editComposers.delete(e),{parentId:t.parentId,message:o,onMessageNotSent:o=>{let s=this.getMessageById(e);r.aborted||this.repository!==n||this._editAttempts.get(t.message)!==i||this._editComposers.has(e)||s?.message!==t.message||s.parentId!==t.parentId||!this.messages.includes(t.message)||this.voice||a(lc(o,e,{type:`complete`,reason:`unknown`}),o.runConfig??{})}});c.setRunConfig(s),this._editComposers.set(e,c),this._notifySubscribers()};a(t.message,{...this.composer.runConfig})}getMessageById(e){try{return this.repository.getMessage(e)}catch{let t=this.repository.getMessages(),n=this._voiceMessages.findIndex(t=>t.id===e);return n===-1?void 0:{parentId:n>0?this._voiceMessages[n-1].id:t.at(-1)?.id??null,message:this._voiceMessages[n],index:t.length+n}}}getBranches(e){return this._voiceMessages.some(t=>t.id===e)?[]:this.repository.getBranches(e)}switchToBranch(e){this.repository.switchToBranch(e),this._notifySubscribers()}_notifyEventSubscribers(e,t){let n=this._eventSubscribers.get(e);n&&w(n,t,`Thread runtime "${e}"`)}_notifyToolApprovalAnswered(e,t,n,r){this._notifyEventSubscribers(`toolApprovalAnswered`,{messageId:e,toolCallId:t,toolName:n,approved:r})}submitFeedback({messageId:e,type:t,comment:n}){let r=this.adapters?.feedback,i=this.getMessageById(e);if(!i)throw Error(`Message not found: ${e}`);let{message:a,parentId:o}=i,s=n?.trim(),c={type:t,...s?{comment:s}:void 0};if(r?.submit({message:a,...c}),a.role===`assistant`){let t={...a,metadata:{...a.metadata,submittedFeedback:c}},n=this._voiceMessages.findIndex(t=>t.id===e);n===-1?(this.repository.addOrUpdateMessage(o,t),this._onMessageMetadataChanged(a,t)):(this._voiceMessages[n]=t,this._voiceController.replaceAssistantMessage(a,t),this._markVoiceMessagesDirty())}this._notifySubscribers()}_stopSpeaking;_replacingSpeech=!1;speech;speak(e){let t=this.adapters?.speech;if(!t)throw Error(`Speech adapter not configured`);let n=this.getMessageById(e);if(!n)throw Error(`Message not found: ${e}`);let{message:r}=n;if(this._replacingSpeech)return;let i=this._stopSpeaking,a;try{this._replacingSpeech=!0;try{i?.()}finally{this._replacingSpeech=!1}a=t.speak(T(r))}catch(e){if(i&&!this._stopSpeaking)try{this._notifySubscribers()}catch(e){console.error(`[assistant-ui] Speech rollback notification threw`,e)}throw e}let o,s=()=>{this._stopSpeaking=void 0,this.speech=void 0;let e=o;o=void 0,e?.()},c=()=>{if(this._stopSpeaking===c)try{s()}finally{a.cancel()}},l=()=>{this._stopSpeaking===c&&(a.status.type===`ended`?Ka([s,()=>this._notifySubscribers()]):(this.speech={messageId:e,status:a.status},this._notifySubscribers()))};this._stopSpeaking=c;try{if(o=a.subscribe(l),this._stopSpeaking!==c){o();return}l()}catch(e){if(this._stopSpeaking===c)try{Ka([c,()=>this._notifySubscribers()])}catch(e){console.error(`[assistant-ui] Speech rollback cleanup threw`,e)}throw e}}stopSpeaking(){if(!this._stopSpeaking)throw Error(`No message is being spoken`);Ka([this._stopSpeaking,()=>this._notifySubscribers()])}get voice(){return this._voiceController.voice}set voice(e){this._voiceController.voice=e}getVoiceVolume=()=>this._voiceController.getVoiceVolume();subscribeVoiceVolume=e=>this._voiceController.subscribeVoiceVolume(e);_onVoiceConnected(){}_onVoiceDisconnected(){}_isRunActive(){return this._voiceController.isRunActive()}_getVoiceCommitBarrier(){return this._voiceController.getVoiceCommitBarrier()}connectVoice(){this._voiceController.connectVoice()}async _appendToVoiceSession(e){return this._voiceController.appendToVoiceSession(e)}disconnectVoice(){this._voiceController.disconnectVoice()}muteVoice(){this._voiceController.muteVoice()}unmuteVoice(){this._voiceController.unmuteVoice()}ensureInitialized(){return!this._isInitialized&&(this._isInitialized=!0,this._notifyEventSubscribers(`initialize`,{}),!0)}export(){return this.repository.export()}import(e){this.ensureInitialized(),this.repository.clear(),this.repository.import(e),this._notifySubscribers()}reset(e){this.import(Ic.fromArray(e??[]))}_eventSubscribers=new Map;unstable_on(e,t){let n=t;if(e===`modelContextUpdate`)return this._contextProvider.subscribe?.(()=>w([n],{},`Thread runtime "${e}"`))??(()=>{});let r=this._eventSubscribers.get(e);return r||(r=new Set,this._eventSubscribers.set(e,r)),r.add(n),e===`initialize`&&this._isInitialized&&queueMicrotask(()=>{r.has(n)&&w([n],{},`Thread runtime "${e}"`)}),()=>{this._eventSubscribers.get(e)?.delete(n)}}},Rf=class{pending;get isLoading(){return this.pending!==void 0}load(e,t,n){if(this.pending)return this.pending;if(!e)return Promise.resolve();let r=Promise.resolve().then(()=>e()).catch(t).finally(()=>{this.pending=void 0,n(!1)});return this.pending=r,n(!0),r}},zf=Symbol.for(`assistant-stream.tool-execution-id`),Bf=Promise.resolve(),Vf=e=>{try{return JSON.parse(e),!0}catch{return!1}},Hf=e=>{try{return JSON.parse(e)}catch{return}},Uf=(e,t)=>{let n=Hf(e),r=Hf(t);return n===void 0||r===void 0?!1:ee(n,r)},Wf=e=>e.result!==void 0&&e.isPreliminary!==!0,Gf=e=>e[zf],Kf=class{_getTools;_callbacks;_isClientToolCall;_entries=new Map;_humanInput=new Map;_executing=new Set;_discardedToolCallIds=new Set;_settledResolvers=[];_statuses=new Map;_ac=new AbortController;_retiredAc;_pendingRestore=!0;_lastSnapshot=null;_isRunning=!1;_controller;_pipelineDead=!1;_pipelineRestartUsed=!1;constructor(e,t,n){this._getTools=e,this._callbacks=t,this._isClientToolCall=n,this._initPipeline()}_initPipeline(){let[e,t]=Cs();this._controller=t;let n=Ks(()=>this._getWrappedTools(),()=>this._ac.signal,(e,t,n)=>this._onHumanInput(e,t,n),{onExecutionStart:(e,t,n)=>this._onExecutionStart(e,n),onExecutionEnd:(e,t,n)=>this._onExecutionEnd(e,n)});e.pipeThrough(n).pipeThrough(new ws).pipeTo(new WritableStream({write:e=>{try{if(e.type!==`result`)return;this._handleResultChunk(e)}catch(e){console.error(`[ToolInvocationTracker] result chunk handling failed`,e)}}})).catch(e=>{console.error(`[ToolInvocationTracker] stream pipeline failed; will attempt single restart on next setState`,e),this._pipelineDead=!0})}setState(e){try{if(this._pipelineDead){if(this._pipelineRestartUsed)return;this._pipelineRestartUsed=!0,this._pipelineDead=!1;let e=new Set;for(let[t,n]of this._entries)n.executionId&&this._executing.has(n.executionId)&&e.add(t);this._demoteEntriesToRestored(),this._executing.clear(),this._humanInput.size===0?this._ac.abort():this._retiredAc=this._ac,this._ac=new AbortController;let t=new Map(this._statuses);for(let n of e)this._humanInput.has(n)||t.delete(n);t.size!==this._statuses.size&&(this._statuses=t,this._invokeOnStatusesChange()),this._resolveSettledResolvers(),this._initPipeline()}if(this._lastSnapshot&&this._lastSnapshot.messages===e.messages&&this._lastSnapshot.isRunning===e.isRunning&&this._lastSnapshot.isLoading===e.isLoading)return;e.isLoading===!0&&(this._pendingRestore=!0);let t=this._isRunning;this._isRunning=e.isRunning;try{this._processMessages(e.messages,e.discardedToolCallIds)}catch(e){throw this._isRunning=t,e}this._lastSnapshot=e,this._pendingRestore=!1}catch(e){console.error(`[ToolInvocationTracker] setState failed; snapshot dropped`,e)}}reset(){try{this._pendingRestore=!0,this._entries.clear(),this._discardedToolCallIds.clear(),this._lastSnapshot=null,this.abort(),this._statuses.size>0&&(this._statuses=new Map,this._invokeOnStatusesChange())}catch(e){console.error(`[ToolInvocationTracker] reset failed`,e)}}abort(e){try{if(this._humanInput.forEach(({executionId:e,reject:t},n)=>{try{t(Error(`Tool execution aborted`))}catch{}this._endHumanRequest(n,e)}),this._humanInput.clear(),e?.discardPending)for(let[e,t]of this._entries)t.controller&&(t.hasResult||t.executeStarted||(this._discardedToolCallIds.add(e),t.skipExecute=!0,t.discarded=!0));if(this._retiredAc?.abort(),this._retiredAc=void 0,this._ac.abort(),this._ac=new AbortController,this._executing.size===0)return Bf;let t=new Set(this._executing);return new Promise(e=>{this._settledResolvers.push({executionIds:t,resolve:e})})}catch(e){return console.error(`[ToolInvocationTracker] abort failed`,e),Bf}}_endHumanRequest(e,t){if(this._executing.has(t)){this._setStatus(e,{type:`executing`});return}let n=this._entries.get(e)?.executionId;(n===void 0||n===t)&&this._deleteStatus(e)}resume(e,t){try{let n=this._humanInput.get(e);return n?(this._humanInput.delete(e),this._endHumanRequest(e,n.executionId),n.resolve(t),!0):!1}catch(e){return console.error(`[ToolInvocationTracker] resume failed`,e),!1}}getStatuses(){return this._statuses}_getWrappedTools(){let e=this._getTools();if(e)return Object.fromEntries(Object.entries(e).map(([e,t])=>{let n=t.execute,r=t.streamCall;return n===void 0&&r===void 0?[e,t]:[e,{...t,...n!==void 0&&{execute:(...[e,t])=>{let r=Gf(t),i=this._captureExecution(t.toolCallId,r);return!i||i.skipExecute?new Promise(()=>{}):(i.executeStarted=!0,n(e,t))}},...r!==void 0&&{streamCall:(...[e,t])=>{let n=Gf(t),i=this._captureExecution(t.toolCallId,n);if(i&&!i.discarded)return r(e,t)}}}]}))}_captureExecution(e,t){if(t===void 0)return;let n=this._entries.get(e);if(n?.controller)return n.executionId===void 0&&(n.executionId=t),n.executionId===t?n:void 0}_onHumanInput(e,t,n){return new Promise((r,i)=>{let a=this._entries.get(e);if(!a?.controller||a.executionId!==n){i(Error(`Tool execution aborted`));return}let o=this._humanInput.get(e);if(o)try{o.reject(Error(`Human input request was superseded by a new request`))}catch{}this._humanInput.set(e,{executionId:n,resolve:r,reject:i}),this._setStatus(e,{type:`interrupt`,payload:{type:`human`,payload:t}})})}_onExecutionStart(e,t){this._captureExecution(e,t)&&(this._entries.get(e).skipExecute||(this._executing.add(t),this._humanInput.get(e)?.executionId!==t&&this._setStatus(e,{type:`executing`})))}_onExecutionEnd(e,t){if(t===void 0||!this._executing.delete(t))return;this._entries.get(e)?.executionId===t&&this._deleteStatus(e);let n=[];this._settledResolvers.forEach(({executionIds:e,resolve:t})=>{if([...e].some(e=>this._executing.has(e)))n.push({executionIds:e,resolve:t});else try{t()}catch{}}),this._settledResolvers.length=0,this._settledResolvers.push(...n)}_handleResultChunk(e){let t=e.meta.toolCallId,n=Gf(e),r=this._entries.get(t);r&&r.executionId===n&&(r?.hasResult||r.skipExecute||this._invokeOnResult({type:`add-tool-result`,toolCallId:t,toolName:e.meta.toolName,result:e.result,isError:e.isError,...e.artifact!==void 0&&{artifact:e.artifact},...e.modelContent!==void 0&&{modelContent:e.modelContent}}))}_invokeOnResult(e){try{this._callbacks.onResult(e)}catch(e){console.error(`[ToolInvocationTracker] onResult callback threw; result dropped`,e)}}_invokeOnStatusesChange(){try{this._callbacks.onStatusesChange(this._statuses)}catch(e){console.error(`[ToolInvocationTracker] onStatusesChange callback threw; status change not propagated`,e)}}_setStatus(e,t){let n=new Map(this._statuses);n.set(e,t),this._statuses=n,this._invokeOnStatusesChange()}_deleteStatus(e){if(!this._statuses.has(e))return;let t=new Map(this._statuses);t.delete(e),this._statuses=t,this._invokeOnStatusesChange()}_resolveSettledResolvers(){let e=this._settledResolvers.splice(0);for(let{resolve:t}of e)try{t()}catch{}}_warnProviderOwnedSkip(e,t){process.env.NODE_ENV!==`production`&&this._getTools()?.[e]?.execute!==void 0&&console.warn(`[ToolInvocationTracker] the runtime reports this tool call as provider-owned, so the registered execute is skipped; the provider has to hand the call to the client for it to run (see EDGE_CASES.md A.9)`,{toolCallId:t,toolName:e})}_shouldCloseArgsStream({argsText:e,hasResult:t,clientOwned:n}){return t?!0:Vf(e)?n||!this._isRunning:!1}_startActiveEntry(e,t,n,r,i){let a={toolName:t,controller:this._controller.addToolCallPart({toolName:t,toolCallId:e}),argsText:``,hasResult:!1,skipExecute:n,discarded:r,argsComplete:!1,clientOwned:i};return this._entries.set(e,a),a}_demoteEntriesToRestored(){for(let[e,t]of this._entries)t.controller&&(!t.argsComplete&&!t.hasResult?this._entries.delete(e):this._entries.set(e,{toolName:t.toolName,argsText:t.argsText,hasResult:t.hasResult}))}_processArgsText(e,t){if(!e.controller)return;let n=t.result!==void 0;if(t.argsText!==e.argsText){let r=!0;if(e.argsComplete)Uf(e.argsText,t.argsText)?(e.argsText=t.argsText,r=!1):(process.env.NODE_ENV!==`production`&&console.warn(`[ToolInvocationTracker] argsText changed after first completion; not re-firing streamCall (see EDGE_CASES.md A.4)`,{previous:e.argsText,next:t.argsText,toolCallId:t.toolCallId}),e.argsText=t.argsText,r=!1);else if(!t.argsText.startsWith(e.argsText)){if(Vf(e.argsText)&&Vf(t.argsText)&&Uf(e.argsText,t.argsText)){let i=this._shouldCloseArgsStream({argsText:t.argsText,hasResult:n,clientOwned:e.clientOwned});i&&e.controller.argsText.close(),e.argsText=t.argsText,e.argsComplete=i,r=!1}else process.env.NODE_ENV!==`production`&&console.warn(`[ToolInvocationTracker] argsText regressed mid-stream; not restarting (see EDGE_CASES.md A.2)`,{previous:e.argsText,next:t.argsText,toolCallId:t.toolCallId}),r=!1}if(r&&e.controller){let r=t.argsText.slice(e.argsText.length);e.controller.argsText.append(r);let i=this._shouldCloseArgsStream({argsText:t.argsText,hasResult:n,clientOwned:e.clientOwned});i&&e.controller.argsText.close(),e.argsText=t.argsText,e.argsComplete=i}}!e.argsComplete&&e.controller&&this._shouldCloseArgsStream({argsText:e.argsText,hasResult:n,clientOwned:e.clientOwned})&&(e.controller.argsText.close(),e.argsComplete=!0)}_processMessages(e,t){let n=this._pendingRestore;for(let{part:r}of Cf(e)){let e=this._entries.get(r.toolCallId);if(n){e?.controller||this._entries.set(r.toolCallId,{toolName:r.toolName,argsText:r.argsText,hasResult:Wf(r)});continue}let i=e,a=this._discardedToolCallIds.has(r.toolCallId);if(Wf(r)&&this._discardedToolCallIds.delete(r.toolCallId),i&&!i.controller){if(i.hasResult||(r.argsText===i.argsText||Vf(i.argsText)&&Vf(r.argsText)&&Uf(i.argsText,r.argsText))&&!Wf(r))continue;this._entries.delete(r.toolCallId),i=void 0}if(!i){let e=a||t?.has(r.toolCallId)===!0;e&&!Wf(r)&&this._discardedToolCallIds.add(r.toolCallId);let n=this._isClientToolCall?.(r),o=r.result===void 0&&n===!1;o&&this._warnProviderOwnedSkip(r.toolName,r.toolCallId),i=this._startActiveEntry(r.toolCallId,r.toolName,r.result!==void 0||o||e,e,n===!0)}if(r.result!==void 0&&(i.skipExecute=!0),r.approval!==void 0&&(i.skipExecute=!0),this._processArgsText(i,r),r.result!==void 0&&!i.hasResult){let{controller:e}=i;if(!e)continue;i.argsComplete=!0,e.setResponse(new as({result:r.result,artifact:r.artifact,isError:r.isError,isPreliminary:r.isPreliminary,...r.modelContent===void 0?{}:{modelContent:r.modelContent}})),Wf(r)&&(i.hasResult=!0,e.close())}}}},qf=Object.freeze([]),Jf=new WeakMap,Yf=(e,t)=>e?.type===t?.type&&e?.comment===t?.comment,Xf=new WeakMap,Zf=(e,t)=>{Promise.resolve(t).catch(t=>{console.error(`[ExternalStoreThreadRuntimeCore] ${e} callback rejected`,t)})},Qf=(e,t)=>e&&t[t.length-1]?.role!==`assistant`,$f=class extends Lf{_capabilities={switchToBranch:!1,switchBranchDuringRun:!1,edit:!1,delete:!1,reload:!1,refetchThread:!1,cancel:!1,unstable_copy:!1,speech:!1,dictation:!1,voice:!1,attachments:!1,feedback:!1,queue:!1,answerToolCall:!1};get capabilities(){return this._capabilities}_messages;isDisabled;isSendDisabled;get isLoading(){return this._store.isLoading??!1}_pendingResume;_clearPendingResume(e){e&&this._pendingResume===e&&(this._pendingResume=void 0,this._notifySubscribers())}get canResume(){return!!this._store.canResume&&!!this._store.onResume&&!this._pendingResume&&!this.isDisabled&&!Wd(this)&&!this.isLoading&&!this.voice}get hasEarlier(){return this._store.hasEarlier===!0&&this._store.onLoadEarlier!==void 0}_loadEarlier=new Rf;get isLoadingEarlier(){return this._loadEarlier.isLoading}loadEarlier(){let e=this._store.onLoadEarlier;return this._loadEarlier.load(this.hasEarlier?e:void 0,e=>{console.error(`[ExternalStoreThreadRuntimeCore] onLoadEarlier callback rejected`,e)},()=>this._notifySubscribers())}get isRunning(){return this._hasExecutingTools(this._store)?!0:this._store.isRunning}_getBaseMessages(){return this._messages}get state(){return this._store.state??super.state}get adapters(){return this._store.adapters}get unstable_refetchThread(){if(this._store.onRefetchThread)return()=>this._store.onRefetchThread()}suggestions=[];extras=void 0;_converter=new $u;_createdAtById=new Map;_submittedFeedback=new Map;_pendingDeleteEvictions=new Map;_pendingDeleteWindows=new Set;_openDeleteWindow(e){let t=this.repository.getMessages(),n=t.findIndex(t=>t.id===e)+1,r={prefix:new Set(t.slice(0,n).map(e=>e.id)),suffix:new Set(t.slice(n).map(e=>e.id))};if(r.suffix.size===0)return r;this._pendingDeleteWindows.add(r);for(let[e,t]of this._pendingDeleteEvictions)r.prefix.has(e)||(t.calls.size>0?t.reloaded=!0:this._pendingDeleteEvictions.delete(e));return r}_closeDeleteWindows(e){for(let t of this._pendingDeleteWindows)[...t.suffix].every(t=>!e.has(t))&&this._pendingDeleteWindows.delete(t)}_optimistic=null;_storeMessages=[];_importedMessageIds;_runStartLeases=new Sf;_runCancellationLeases=new Sf;_cancelRunResyncLeases=new Sf;_cancelledToolTurn=null;_cancelledRunIds=new Set;_pendingCancelResyncs=new Set;_movedLeaf;_store;_getInitializePromise;__internal_setGetInitializePromise(e){this._getInitializePromise=e}_queueDispatchTransform=e=>{let t=this._transformedQueue&&Wc(this._transformedQueue);if(t&&ef(this).aborted&&t!==this._queueDispatchTransform)return t(e);let n=t?void 0:Jf.get(e),r=n&&!ef(n).aborted?n:this;r._pendingDeleteWindows.clear(),r._settleCancelResyncs();let i=r.messages.at(-1)?.id??null;return r.enrichAppendMetadata({...e,parentId:i},i)};_transformedQueue;_toolInvocations=null;_toolStatuses=new Map;_effectiveIsRunning=!1;_inTrackerUpdate=!1;_pendingRunningRefresh=!1;_onMessageMetadataChanged(e,t){if(this._storeMessages=this._storeMessages.map(e=>e.id===t.id?t:e),t.id.startsWith(`__external_store_fallback_`))return;let n=this._submittedFeedback.get(t.id),r=n&&Yf(e.metadata.submittedFeedback,n.feedback)?n.external:e.metadata.submittedFeedback,i=t.metadata.submittedFeedback;i&&this._submittedFeedback.set(t.id,{feedback:i,external:r,source:n?.message===e?n.source:e,message:t})}_applySubmittedFeedback(e){if(this._submittedFeedback.size===0)return e;for(let e of this._submittedFeedback.keys())try{this.repository.getMessage(e)}catch{this._submittedFeedback.delete(e)}return e.map(e=>{let t=this._submittedFeedback.get(e.id);if(!t)return e;if(e.role!==`assistant`||!Yf(e.metadata.submittedFeedback,t.external))return this._submittedFeedback.delete(e.id),e;if(t.source===e)return t.message;let n={...e,metadata:{...e.metadata,submittedFeedback:t.feedback}};return t.source=e,t.message=n,n})}_runTrackerUpdate(e){this._inTrackerUpdate=!0;try{e()}finally{this._inTrackerUpdate=!1}this._pendingRunningRefresh&&(this._pendingRunningRefresh=!1,this._refreshEffectiveIsRunning())}_refreshEffectiveIsRunning(){this._effectiveIsRunning!==this._getEffectiveIsRunning(this._store)&&this._updateStoreSnapshot(this._store,!1)}_hasExecutingTools(e){if(e.unstable_enableToolInvocations!==!0||this._toolInvocations===null)return!1;for(let e of this._toolStatuses.values())if(e.type===`executing`)return!0;return!1}_getEffectiveIsRunning(e){return(e.isRunning??!1)||this._hasExecutingTools(e)}beginEdit(e){if(!this._store.onEdit)throw Error(`Runtime does not support editing.`);super.beginEdit(e)}constructor(e,t){super(e),this.__internal_setAdapter(t)}__internal_setAdapter(e){this._store!==e&&this._updateStoreSnapshot(e)}_evictPlaceholder(){if(this._optimistic){try{this.repository.getMessage(this._optimistic.id)}catch{return}this.repository.deleteMessage(this._optimistic.id)}}_updateStoreSnapshot(e,t=!0,n=!1){let r=this._effectiveIsRunning;this.isDisabled=e.isDisabled??!1,this.isSendDisabled=e.isSendDisabled??!1;let i=this._store;this._store=e;let a=this._getEffectiveIsRunning(e),o=e.unstable_messageRepositoryInstance,s=o!==void 0&&o!==this.repository;if(s){this.repository=o,this._createdAtById.clear(),this._cancelledToolTurn=null,this._cancelledRunIds.clear(),this._pendingResume=void 0,this._pendingDeleteEvictions.clear(),this._pendingDeleteWindows.clear(),this._submittedFeedback.clear(),this._movedLeaf=void 0;let e=this.repository.getMessages(),t=e.at(-1);this._optimistic=t?.metadata.isOptimistic?{id:t.id,parentId:e.at(-2)?.id??null}:null}i?.queue!==e.queue&&(this._transformedQueue=void 0,e.queue?.__internal_setDispatchTransform?.(this._queueDispatchTransform),e.queue?.__internal_setDispatchTransform&&(this._transformedQueue=e.queue)),this.extras!==e.extras&&(this.extras=e.extras);let c=e.suggestions??qf;Fi(this.suggestions,c)||(this.suggestions=c);let l={switchToBranch:this._store.setMessages!==void 0,switchBranchDuringRun:!1,edit:this._store.onEdit!==void 0,delete:this._store.onDelete!==void 0||this._store.setMessages!==void 0,reload:this._store.onReload!==void 0,refetchThread:this._store.onRefetchThread!==void 0,cancel:this._store.onCancel!==void 0,speech:this._store.adapters?.speech!==void 0,dictation:this._store.adapters?.dictation!==void 0,voice:this._store.adapters?.voice!==void 0,unstable_copy:this._store.unstable_capabilities?.copy!==!1,attachments:!!this._store.adapters?.attachments,feedback:!!this._store.adapters?.feedback,queue:this._store.queue!==void 0,answerToolCall:this._store.onAddToolResult!==void 0||this._store.onResumeToolCall!==void 0||this._store.onRespondToToolApproval!==void 0||this._store.unstable_enableToolInvocations===!0};Fi(this._capabilities,l)||(this._capabilities=l);let u,d=!1,f=!1;if(e.messageRepository){if(this._importedMessageIds=void 0,!n&&i&&!s&&i.isRunning===e.isRunning&&i.messageRepository===e.messageRepository&&r===a){t&&this._pendingDeleteWindows.size>0&&this._closeDeleteWindows(new Set(e.messageRepository.messages.map(({message:e})=>e.id))),this._notifySubscribers();return}let o=e.messageRepository.messages;t&&this._pendingDeleteWindows.size>0&&this._closeDeleteWindows(new Set(o.map(({message:e})=>e.id)));let c=e.messageRepository.headId??o.at(-1)?.message.id??null;if(this._evictPlaceholder(),i&&!n&&!s&&i.messageRepository===e.messageRepository)this.repository.import({headId:c,messages:[]}),u=this.repository.getMessages();else{let e=new Set(o.map(({message:e})=>e.id)),t=this._applySubmittedFeedback(o.map(({message:e})=>e));for(let e=0;e<o.length;e++)this.repository.addOrUpdateMessage(o[e].parentId,t[e]);for(let{message:t}of this.repository.export().messages)e.has(t.id)||this.repository.deleteMessage(t.id);this._pendingDeleteEvictions.clear(),this.repository.import({headId:c,messages:[]}),u=this.repository.getMessages()}}else if(e.messages){if(i){if(i.convertMessage!==e.convertMessage)this._converter=new $u;else if(!n&&!s&&i.isRunning===e.isRunning&&i.messages===e.messages&&r===a){t&&this._pendingDeleteWindows.size>0&&this._closeDeleteWindows(new Set(this._storeMessages.map(e=>e.id))),this._notifySubscribers();return}}u=e.convertMessage?this._converter.convertMessages(e.messages,(t,n,r)=>{if(!e.convertMessage)return n;let i=r===(e.messages?.length??0)-1,o=`${hc}${r}`;if(t&&(t.role!==`assistant`||!Mc(t.status)||t.status===Fc(t.content,i,a))){if(t.id.startsWith(`__external_store_fallback_`)&&t.id!==o){let e={...t,id:o};return pc(e,n),e}return t}let s=e.convertMessage(n,r);if(s.createdAt==null&&s.id!=null){let e=this._createdAtById.get(s.id)??new Date;this._createdAtById.set(s.id,e),s={...s,createdAt:e}}let c=lc(s,o,Fc(s.content,i,a));return pc(c,n),c}):e.messages,u=gc(u,e=>{console.warn(`ExternalStoreThreadRuntimeCore: duplicate message id "${e}" in the provided messages array; keeping the last occurrence.`)}),u=this._applySubmittedFeedback(u);let o=this._importedMessageIds;d=o!==void 0&&ed(o,u.map(e=>e.id)),d||(f=o!==void 0,this._importedMessageIds=void 0);let c=new Set(u.map(e=>e.id)),l=new Map;for(let e=1;e<u.length;e++){let t=u[e].id,n=u[e-1].id,r;try{r=this.repository.getMessage(t).parentId}catch{continue}if(r===n)continue;let i=this.repository.getMessages(t),a=i.findIndex(e=>e.id===n);if(a!==-1)for(let e=a+1;e<i.length-1;e++){let t=i[e];c.has(t.id)||l.set(t.id,t)}}for(let e=0;e<u.length;e++){let t=u[e],n=u[e-1];this.repository.addOrUpdateMessage(n?.id??null,t)}for(let[e,t]of l)this._evictDeletedMessage(e,t,!1);if(this._pendingDeleteEvictions.size>0&&i?.messages!==e.messages||t&&this._pendingDeleteWindows.size>0){let n=new Set(u.map(e=>e.id));if(t&&this._closeDeleteWindows(n),i?.messages!==e.messages){for(let[e,t]of this._pendingDeleteEvictions)if(!t.reloaded){if(n.has(e))t.calls.size===0&&this._pendingDeleteEvictions.delete(e);else{this._pendingDeleteEvictions.delete(e);try{this.repository.getMessage(e)}catch{continue}this.repository.deleteMessage(e)}}}}}else throw Error(`ExternalStoreAdapter must provide either 'messages' or 'messageRepository'`);this._storeMessages=u,u.length>0&&this.ensureInitialized();let p=this._movedLeaf;if(p){if(p.generation.aborted||!p.resyncLease.isCurrent()||this.composer.text!==p.draft.text)this._movedLeaf=void 0;else{let e=u.findIndex(e=>e.id===p.id);e!==-1&&(T(u[e])===p.draft.text?e<u.length-1&&(this.composer.retractDraft(p.draft),this._movedLeaf=void 0):this._movedLeaf=void 0)}}if(this._effectiveIsRunning=a,r!==a){if(a){let e=this._cancelledToolTurn;if(e?.lease.isCurrent()){let t=u.at(-1);t?.role===`assistant`&&e.messageIds.has(t.id)?this._cancelledToolTurn=null:(t?.role===`assistant`?u.at(-2)?.id??null:t?.id??null)===e.parentId&&(e.parentOpen=!1)}this._notifyEventSubscribers(`runStart`,{})}else this._notifyEventSubscribers(`runEnd`,{})}let m=null;if(Qf(a,u)){let e=u.at(-1)?.id??null;f&&this.repository.resetHead(e),this._optimistic?.parentId!==e&&(this._optimistic={id:h(),parentId:e}),m=this._optimistic.id,this.repository.addOrUpdateMessage(e,lc({role:`assistant`,content:[],metadata:{isOptimistic:!0}},m,{type:`running`}))}m===null&&(this._optimistic=null);let g=m??u.at(-1)?.id??null;e.messageRepository||d?this.repository.import({headId:g,messages:[]}):this.repository.resetHead(g);let _=this.repository.getMessages();if(this._messages&&ed(this._messages,_)||(this._messages=_),this._voiceMessages.length>0){let e=new Set(this._messages.map(e=>e.id)),t=this._voiceMessages.filter(t=>!e.has(t.id));t.length!==this._voiceMessages.length&&(this._voiceMessages=t,this._markVoiceMessagesDirty())}t&&(s&&this._runTrackerUpdate(()=>this._toolInvocations?.reset()),this._runTrackerUpdate(()=>this._driveToolInvocations())),this._notifySubscribers()}_driveToolInvocations(){if(!this._store.unstable_enableToolInvocations){this._toolInvocations&&(this._toolInvocations.reset(),this._toolInvocations=null,this._toolStatuses=new Map,this._store.setToolStatuses?.({}));return}let e=Xf.get(this.repository);if(e||(e=this._createToolInvocations(),Xf.set(this.repository,e)),this._toolInvocations=e.tracker,e.host!==this){e.host._toolInvocations===e.tracker&&(e.host._toolInvocations=null),e.host=this;let t=e.tracker.getStatuses();(t.size>0||this._toolStatuses.size>0)&&this._applyToolStatuses(t)}let t=this._getDiscardedToolCallIds();this._toolInvocations.setState({messages:this._messages,isRunning:this._getEffectiveIsRunning(this._store),...t&&{discardedToolCallIds:t},...this._store.isLoading!==void 0&&{isLoading:this._store.isLoading}})}_getDiscardedToolCallIds(){let e=this._cancelledToolTurn;if(!e&&this._cancelledRunIds.size===0)return;let t=new Set;for(let n=0;n<this._messages.length;n++){let r=this._messages[n];if(r.role!==`assistant`||r.metadata.isOptimistic)continue;let i=r.metadata.runId;if(i===void 0||!this._cancelledRunIds.has(i)){if(!e)continue;if(!e.messageIds.has(r.id)){if(!e.parentOpen||(this._messages[n-1]?.id??null)!==e.parentId)continue;e.messageIds.add(r.id)}}for(let{part:e}of Cf([r]))t.add(e.toolCallId)}return t}_createToolInvocations(){let e={host:this,tracker:new Kf(()=>e.host.getModelContext().tools,{onResult:t=>e.host._dispatchToolResult(t),onStatusesChange:t=>e.host._applyToolStatuses(t)},t=>e.host._store.unstable_isClientToolCall?.(t))};return e}_dispatchToolResult(e){try{let t=this._findMessageIdForToolCall(e.toolCallId);if(t===void 0)return;Zf(`onAddToolResult`,this._store.onAddToolResult?.({messageId:t,toolCallId:e.toolCallId,toolName:e.toolName,result:e.result,isError:e.isError,...e.artifact!==void 0&&{artifact:e.artifact},...e.modelContent!==void 0&&{modelContent:e.modelContent}}))}catch(e){console.error(`[ExternalStoreThreadRuntimeCore] onAddToolResult dispatch failed`,e)}}_applyToolStatuses(e){let t=this._hasExecutingTools(this._store);this._toolStatuses=e;try{this._store.setToolStatuses?.(Object.fromEntries(e))}finally{t!==this._hasExecutingTools(this._store)&&(this._inTrackerUpdate?this._pendingRunningRefresh=!0:this._updateStoreSnapshot(this._store))}}_toolCallToMessageId=new Map;_messagesForToolCallIndex=null;_findMessageIdForToolCall(e){if(this._messagesForToolCallIndex!==this._messages){this._toolCallToMessageId.clear();for(let{part:e,messageId:t}of Cf(this._messages))this._toolCallToMessageId.set(e.toolCallId,t);this._messagesForToolCallIndex=this._messages}return this._toolCallToMessageId.get(e)}switchToBranch(e){if(!this._store.setMessages)throw Error(`Runtime does not support switching branches.`);if(this._getEffectiveIsRunning(this._store))return;let t=this._store.unstable_onBranchChange,n=this._pendingResume,r=t||n?this.repository.canonicalHeadId:null;this.repository.switchToBranch(e),this._pendingDeleteWindows.clear();for(let[e,t]of this._pendingDeleteEvictions)t.calls.size>0?t.reloaded=!0:this._pendingDeleteEvictions.delete(e);this.updateMessages(this.repository.getMessages()),n&&this.repository.canonicalHeadId!==r&&this._clearPendingResume(n),t&&this._notifyBranchChange(r,t)}_notifyBranchChange(e,t){let n=this.repository.canonicalHeadId;n!==e&&t({headId:n,visibleMessageIds:this.repository.getMessages().map(e=>e.id)})}async append(e){let t={...e,parentId:this._resolveAppendParent(e.parentId)};if(this.voice)return this._pendingDeleteWindows.clear(),this._appendToVoiceSession(t);if(this._isVoiceMessage(t.sourceId))throw Error(`Voice transcript messages cannot be edited`);let n=t.sourceId!=null||t.parentId!==(this._getBaseMessages().at(-1)?.id??null),r=!n&&this._store.queue&&this._store.queue===this._transformedQueue?void 0:this.enrichAppendMetadata(t),i=Zd(this);this.ensureInitialized();let a=this._getInitializePromise?.();if(!n&&this._store.queue&&(a&&await a,i.aborted))return;let o=n?void 0:this._store.queue;if(o&&o===this._transformedQueue||(t=r??this.enrichAppendMetadata(t)),o)o===this._transformedQueue&&(Wc(o)||Jf.set(t,this),o.__internal_setDispatchTransform?.(this._queueDispatchTransform),Uc(o)),t.steer??this._getEffectiveIsRunning(this._store)?o.steer(t):o.enqueue(t);else{if(a?.catch(()=>{}),t.startRun??t.role===`user`){let e=this._toolInvocations?.abort({discardPending:!0});e&&e!==Bf&&await e}if(!i.aborted){if(n||this._pendingDeleteWindows.clear(),this._settleCancelResyncs(),n){if(!this._store.onEdit)throw Error(`Runtime does not support editing messages.`);let e=this._openDeleteWindow(t.parentId);try{await this._store.onEdit(t)}catch(t){throw this._pendingDeleteWindows.delete(e),t}}else await this._store.onNew(t)}}}_commitVoiceMessage(e){let t=Zd(this);if(t.aborted){this._dropVoiceMessage(e.id,!1);return}let n=this._getVoiceCommitBarrier();if(!n){this._store.onVoiceTranscript?.(e);return}let r=this.repository;return n.then(()=>{t.aborted||this.repository!==r?this._dropVoiceMessage(e.id,!0):this._store.onVoiceTranscript?.(e)})}async deleteMessage(e){if(this._store.onDelete){let t=this.repository.getMessages().find(t=>t.id===e),n=Symbol(),r=this._pendingDeleteEvictions.get(e);if(t){let i=!1;for(let t of this._pendingDeleteWindows)if(!t.prefix.has(e)){i=!0;break}(!r||e.startsWith(`__external_store_fallback_`)&&r.message!==t)&&(r={calls:new Set,reloaded:i,message:t}),i&&(r.reloaded=!0),r.calls.add(n),this._pendingDeleteEvictions.set(e,r)}let i=!1;try{await this._store.onDelete(e),i=!0}finally{r&&this._pendingDeleteEvictions.get(e)===r&&r.calls.delete(n)&&(r.reloaded&&i?(r.reloaded=!1,this._storeMessages.some(t=>t.id===e)||(this._pendingDeleteEvictions.delete(e),this._evictDeletedMessage(e,r.message))):r.reloaded&&r.calls.size===0&&this._pendingDeleteEvictions.delete(e))}return}if(!this._store.setMessages)throw Error(`Runtime does not support deleting messages.`);this._getEffectiveIsRunning(this._store)&&await this._toolInvocations?.abort();let t=this.repository.getMessages();if(t.findIndex(t=>t.id===e)===-1)throw Error(`Message not found.`);this._pendingDeleteEvictions.clear(),this.updateMessages(t.filter(t=>t.id!==e)),this._evictDeletedMessage(e)}_evictDeletedMessage(e,t,n=!0){if(!e.startsWith(`__external_store_fallback_`)||t){try{let n=this.repository.getMessage(e).message;if(e.startsWith(`__external_store_fallback_`)&&n!==t)return}catch{return}this.repository.deleteMessage(e),n&&this._publishRepositoryMessages()}}_publishRepositoryMessages(){let e=this.repository.getMessages();ed(this._messages,e)||(this._messages=e),this._notifySubscribers()}getQueueItems(){return this._store?.queue?.items??Vc}getSteerQueueItems(){return this._store?.queue?.steerItems??Vc}moveQueueItem(e,t){this._store?.queue?.move(e,t)}removeQueueItem(e){this._store?.queue?.remove(e)}_restoreMovedLeafForRun(e){let t=this._movedLeaf;t?.id===e&&t.resyncLease.isCurrent()&&!t.generation.aborted&&this._storeMessages.some(e=>e.id===t.id)&&(this._cancelRunResyncLeases.invalidate(),this._movedLeaf=void 0,this.composer.retractDraft(t.draft),this._updateStoreSnapshot(this._store,!1,!0))}async startRun(e){if(!this._store.onReload)throw Error(`Runtime does not support reloading messages.`);if(this.voice)throw Error(`Cannot start a run while a voice session is connected`);if(this._isVoiceMessage(e.sourceId))throw Error(`Voice transcript messages cannot be reloaded`);this._restoreMovedLeafForRun(e.parentId),this._runStartLeases.begin(),this._cancelledToolTurn?.parentId===e.parentId&&(this._cancelledToolTurn.parentOpen=!1);let t=this._openDeleteWindow(e.parentId),n=this._runCancellationLeases.current();try{if(await this._toolInvocations?.abort({discardPending:!0}),!n.isCurrent()){this._pendingDeleteWindows.delete(t);return}await this._store.onReload(e.parentId,e)}catch(e){throw this._pendingDeleteWindows.delete(t),e}}async resumeRun(e){if(!this._store.onResume)throw Error(`Runtime does not support resuming runs.`);if(this.voice)throw Error(`Cannot start a run while a voice session is connected`);if(this._isVoiceMessage(e.sourceId))throw Error(`Voice transcript messages cannot be reloaded`);let t=this._store;if(this._pendingResume)return this._pendingResume;let n=async()=>{this._pendingDeleteWindows.clear(),this._restoreMovedLeafForRun(e.parentId),this._runStartLeases.begin(),this._cancelledToolTurn=null,await t.onResume(e)};if(t.canResume!==!0)return n();let r,i=new Promise((e,t)=>{r=()=>{try{e(n())}catch(e){t(e)}}}).finally(()=>{this._clearPendingResume(i)});return this._pendingResume=i,this._notifySubscribers(),r(),i}exportExternalState(){if(!this._store.onExportExternalState)throw Error(`Runtime does not support exporting external states.`);return this._store.onExportExternalState()}importExternalState(e){if(!this._store.onLoadExternalState)throw Error(`Runtime does not support importing external states.`);this._pendingDeleteWindows.clear(),this._cancelRunResyncLeases.invalidate(),this._cancelledToolTurn=null,this._cancelledRunIds.clear();let t=this._pendingResume;this._runTrackerUpdate(()=>this._toolInvocations?.reset()),this._store.onLoadExternalState(e),this._clearPendingResume(t)}unstable_notifySessionReset(){this._cancelRunResyncLeases.invalidate(),this._cancelledToolTurn=null,this._cancelledRunIds.clear(),this._clearPendingResume(this._pendingResume),this._runTrackerUpdate(()=>this._toolInvocations?.reset()),this._store.queue?.__internal_notifyCancelled?.()}cancelRun(){if(!this._store.onCancel)throw Error(`Runtime does not support cancelling runs.`);this._pendingDeleteWindows.clear();let e=this._getEffectiveIsRunning(this._store);this._runCancellationLeases.invalidate();let t=Zd(this),n=this._cancelRunResyncLeases.current();if(this._store.activeRunId!==void 0&&this._cancelledRunIds.add(this._store.activeRunId),e){let e=this._storeMessages.filter(e=>!e.metadata.isOptimistic),t=e.at(-1);this._cancelledToolTurn={messageIds:new Set(t?.role===`assistant`?[t.id]:[]),parentId:t?.role===`assistant`?e.at(-2)?.id??null:t?.id??null,parentOpen:!0,lease:this._runStartLeases.current()}}this._toolInvocations?.abort({discardPending:!0}),this._store.queue?.__internal_notifyCancelled?.(),Zf(`onCancel`,this._store.onCancel()),this.dropEmptyOptimisticHead();let r=this.repository.getMessages(),i=r[r.length-1],a=i?.id??null,o=this._runStartLeases.current(),s=e&&this._store.setMessages!==void 0&&i?.role===`user`&&i.id===r.at(-1)?.id&&i.content.every(e=>e.type===`text`)?i:void 0,c;if(s){let e={text:T(s),attachments:s.attachments,quote:s.metadata.custom.quote};this.composer.restoreDraft(e)&&(this.repository.deleteMessage(s.id),c={id:s.id,draft:e,resyncLease:n,generation:t},this._movedLeaf=c)}this._publishRepositoryMessages();let l=()=>{if(t.aborted||!n.isCurrent())return;if((!this._getEffectiveIsRunning(this._store)||o.isCurrent()&&(this.repository.getMessages().at(-2)?.id??null)===a)&&this.dropEmptyOptimisticHead(),c){let e=this.repository.getMessages();this._movedLeaf===c&&e.at(-1)?.id===c.id&&this.composer.text===c.draft.text&&this.repository.deleteMessage(c.id)}this._publishRepositoryMessages();let e=this._messages.filter(e=>e.id!==this._optimistic?.id);ed(e,this._storeMessages)||this.updateMessages(e)};this._pendingCancelResyncs.add(l),setTimeout(()=>{this._pendingCancelResyncs.delete(l),l()},0)}_settleCancelResyncs(){for(let e of this._pendingCancelResyncs)e()}dropEmptyOptimisticHead(){let e=this.repository.getMessages().at(-1);e&&e.metadata.isOptimistic&&e.content.length===0&&this.repository.deleteMessage(e.id)}addToolResult(e){if(!this._store.onAddToolResult)throw Error(`Runtime does not support tool results.`);Zf(`onAddToolResult`,this._store.onAddToolResult(e))}resumeToolCall(e){if(!(this._toolInvocations?.resume(e.toolCallId,e.payload)??!1)){if(this._store.onResumeToolCall)this._store.onResumeToolCall(e);else throw Error(`Tool call ${e.toolCallId} is not waiting for resume.`)}}respondToToolApproval(e){if(!this._store.onRespondToToolApproval)throw Error(`Runtime does not support tool approvals.`);let t=this.messages.findLast(t=>t.role===`assistant`&&t.content.some(t=>t.type===`tool-call`&&t.approval?.id===e.approvalId)),n=t?.content.find(t=>t.type===`tool-call`&&t.approval?.id===e.approvalId);try{return Promise.resolve(this._store.onRespondToToolApproval(e)).then(()=>{t&&n?.type===`tool-call`&&this._notifyToolApprovalAnswered(t.id,n.toolCallId,n.toolName,e.approved)})}catch(e){return Promise.reject(e)}}async unstable_recordToolInteraction(e){if(!this._store.unstable_onRecordToolInteraction)throw Error(`Runtime does not support recording tool interactions.`);await this._store.unstable_onRecordToolInteraction(e)}reset(e){let t=this._pendingResume;this._pendingDeleteWindows.clear(),this._cancelRunResyncLeases.invalidate(),this._cancelledToolTurn=null,this._cancelledRunIds.clear(),this._submittedFeedback.clear(),this._importedMessageIds=void 0;let n=new Bc;n.import(Ic.fromArray(e??[])),this.updateMessages(n.getMessages()),this._clearPendingResume(t)}import(e){if(!this._store.onImport)throw Error(`Runtime does not support importing messages.`);let t=this._pendingResume;this._pendingDeleteWindows.clear(),this._cancelRunResyncLeases.invalidate(),this._cancelledToolTurn=null,this._cancelledRunIds.clear(),this._submittedFeedback.clear(),super.import(e),this._clearPendingResume(t);let n=this.repository.getMessages();this._importedMessageIds=n.map(e=>e.id),this._store.onImport(n)}updateMessages=e=>{this._storeMessages=e,this._store.convertMessage===void 0?this._store.setMessages?.(e):this._store.setMessages?.(e.flatMap(mc))}},ep=e=>e.adapters?.threadList??{},tp=class extends mf{threads;_adapter;constructor(e){super(),this._adapter=e,this.threads=new xf(ep(e),()=>new $f(this._contextProvider,this._adapter))}setAdapter(e){this._adapter=e,this.threads.__internal_setAdapter(ep(e)),this.threads.getMainThreadRuntimeCore().__internal_setAdapter(e)}},np=class{thread;history;lastHistory;session=0;copied=new Map;failedIds=new Set;interactions=new Map;overlaid=new WeakMap;pending=!1;inFlight=new WeakSet;timer;waiters=[];warned=!1;signature(e){try{return JSON.stringify({role:e.role,content:e.content,attachments:e.role===`user`?e.attachments:void 0,status:e.role===`assistant`?e.status:void 0,metadata:e.metadata})??e}catch{return e}}branch(){return(this.thread?.messages??[]).filter(e=>!e.metadata.isOptimistic&&!e.id.startsWith(`__external_store_fallback_`)&&!_(e.id)&&(e.role!==`assistant`||e.status.type!==`running`)).map(e=>{let t=this.interactions.get(e.id);if(!t)return e;let n=this.overlaid.get(e);if(n&&n.logs.size===t.size&&[...t].every(([e,t])=>n.logs.get(e)===t))return n.message;let r={...e,content:e.content.map(e=>{if(e.type!==`tool-call`)return e;let n=t.get(e.toolCallId);return n?{...e,unstable_interactions:n}:e})};return this.overlaid.set(e,{logs:new Map(t),message:r}),r})}seed(){for(let e of this.branch())!this.copied.has(e.id)&&!this.failedIds.has(e.id)&&this.copied.set(e.id,this.signature(e))}attach(e,t){t!==this.lastHistory&&(this.copied.clear(),this.failedIds.clear(),this.interactions.clear(),this.overlaid=new WeakMap,this.lastHistory=t,this.session+=1),this.thread=e,this.history=t,this.seed();let n=e.unstable_on(`runStart`,()=>this.seed()),r=e.unstable_on(`runEnd`,()=>this.schedule());return()=>{n(),r(),this.timer!==void 0&&clearTimeout(this.timer),this.timer=void 0,this.pending=!1;let e=Error(`History copy was detached.`);for(let t of this.waiters.splice(0))t.reject(e);this.thread=void 0,this.history=void 0}}recordInteraction=async e=>{let t=this.thread,n=t?.messages.find(t=>t.id===e.messageId),r=n?.content.find(t=>t.type===`tool-call`&&t.toolCallId===e.toolCallId);if(!t||!n||r?.type!==`tool-call`)throw Error(`Tool call is not available.`);let i=Wd(t);i||this.seed();let a=this.interactions.get(n.id);a||(a=new Map,this.interactions.set(n.id,a)),a.set(e.toolCallId,ac(a.get(e.toolCallId)??sc(r.unstable_interactions),e.interaction)),i||await this.schedule(!0)};schedule(e=!1){this.pending=!0;let t=e?new Promise((e,t)=>{this.waiters.push({resolve:e,reject:t})}):Promise.resolve();return this.history&&!this.inFlight.has(this.history)&&this.timer===void 0&&(this.timer=setTimeout(()=>{this.timer=void 0,this.flush()},0)),t}async flush(){if(!this.pending||!this.history)return;let e=this.history,t=this.session;this.pending=!1,this.inFlight.add(e);let n=this.waiters.splice(0),r=this.branch(),i=r.map(e=>[e.id,this.signature(e)]).filter(([e,t])=>this.copied.get(e)!==t);try{if(i.length>0&&(await e.unstable_copy?.(r,i.map(([e])=>e)),t===this.session))for(let[e,t]of i)this.copied.set(e,t),this.failedIds.delete(e);for(let e of n)e.resolve()}catch(e){if(t===this.session)for(let[e]of i)this.failedIds.add(e);this.warned||(this.warned=!0,console.warn(`[useExternalStoreRuntime] Failed to copy history.`,e));for(let t of n)t.reject(e)}finally{this.inFlight.delete(e),this.pending&&this.schedule()}}},rp=pn(!1),ip=e=>lt(rp,!0,e),ap=()=>hn(rp),op=e=>{let{modelContext:t,feedback:n,history:r}=Xu()??{},[i]=H(()=>new np),a=!!r?.unstable_copy&&!e.unstable_persistsHistory&&!e.adapters?.threadList,o=qt(()=>{let t=n&&!e.adapters?.feedback?{...e,adapters:{...e.adapters,feedback:n}}:e;return!a||e.unstable_onRecordToolInteraction?t:{...t,unstable_onRecordToolInteraction:i.recordInteraction}},[a,n,i,e]),[s]=H(()=>new tp(o)),c=ap(),[l]=H(()=>({generation:0}));$t(()=>{if(c)return;let e=++l.generation;return()=>queueMicrotask(()=>{l.generation===e&&of(s.threads.getMainThreadRuntimeCore())})},[c,l,s]),$c(()=>()=>{tf(s.threads.getMainThreadRuntimeCore())},[s]),W(()=>{s.setAdapter(o)}),$c(()=>{if(a&&r)return i.attach(s.threads.getMainThreadRuntimeCore(),r)},[a,r,i,s]),W(()=>{if(t)return s.registerModelContextProvider(t)},[t,s]);let[u]=H(()=>new pf(s));return u},sp=class extends Error{[pl]=!0;constructor(){super(`Thread list was destroyed while an operation was pending.`),this.name=`ThreadListDestroyedError`}},cp=({threadId:e,generation:t,runtimeHook:n,publish:r,itemRuntime:i,publishInCommit:a})=>{let o=ip(n),s=o?.thread?.__internal_threadBinding,c=Jt(()=>{s&&r(e,s.getState(),t)},[e,t,s,r]),l=U(!1);!a&&!l.current&&c(),Yc(()=>{if(s)return l.current=!0,c(),s.outerSubscribe(c)},[s,c]);let u=U(void 0),d=Xt(()=>{let e=u.current;if(e===void 0||!s)return;let t=s.getState(),n=t.__internal_setGetThreadId;typeof n==`function`&&n.call(t,()=>e)});W(()=>{d()},[s]);let f=U(void 0),p=U(!1),m=U(i.getState().status===`new`),h=Xt(()=>{if(p.current||i.getState().status!==`new`&&!m.current)return;p.current=!0,m.current=!1;let e=i.initialize();f.current=e,e.then(({remoteId:e})=>{u.current=e,d()},()=>{}),e.catch(()=>{f.current===e&&(f.current=void 0,p.current=!1)})}),g=Xt(()=>(h(),f.current));return W(()=>{if(!s)return;let e=s.getState(),t=e.__internal_setGetInitializePromise;typeof t==`function`&&t.call(e,g)},[s]),W(()=>{if(o?.threads?.main)return p.current=!1,o.threads.main.unstable_on(`initialize`,h)},[o]),o},lp=hr(({threadId:e,generation:t,parentList:n,runtimeHook:r,parentClient:i,adapters:a,publish:o,destroySignal:s,publishInCommit:c=!1})=>{let l=qt(()=>new sf(new $a({path:{ref:`threadItems[threadId=${e}]`,threadSelector:{type:`threadId`,threadId:e}},getState:()=>{let t=n.getItemById(e);return t?{id:t.id,remoteId:t.remoteId,externalId:t.externalId,title:t.title,lastMessageAt:t.lastMessageAt,custom:t.custom,status:t.status,isMain:t.id===n.mainThreadId,isRunning:n.unstable_isThreadRunning?.(t.id)??!1}:Ga},subscribe:e=>n.subscribe(e)}),n),[n,e]),{client:u}=pa(i,{threadListItem:Du({runtime:l})});return Ni(s,function(){return Lr(u,function(){return Yu(a,function(){return cp({threadId:e,generation:t,runtimeHook:r,publish:o,itemRuntime:l,publishInCommit:c})})})})}),up=[`runStart`,`runEnd`,`initialize`,`modelContextUpdate`],dp=e=>e?.runtime!==void 0&&e.mountError===void 0&&e.publishedGeneration===e.generation,fp=e=>{let t=G(3),{detectorRef:n}=e,r,i;return t[0]===n?(r=t[1],i=t[2]):(r=()=>{n.current=!0},i=[n],t[0]=n,t[1]=r,t[2]=i),Yc(r,i),null},pp=class extends Xa{runtimeHook;adapterStore=new Za({defaultAdapters:null,threadAdapters:new Map});hostStore=new Za({threads:[],hookEpoch:0});pendingThreadAdapters=new Map;instances=new Map;nextGeneration=0;disposed=!1;parent;publishInCommit;constructor(e,t,n=!1){super(),this.parent=t,this.publishInCommit=n,this.runtimeHook=e}_whenRuntimeAttached(e){return new Promise((t,n)=>{let r=()=>{let r=this.instances.get(e);r?r.mountError?(i(),n(r.mountError.error)):dp(r)&&(i(),t(r.runtime)):(i(),n(Error(`Thread was deleted before runtime was started`)))},i=this.subscribe(r);r()})}startThreadRuntime(e){if(this.disposed)return Promise.reject(new sp);if(!this.instances.has(e)){let t=this.nextGeneration++;this.instances.set(e,{generation:t,isRunning:!1,destroy:new AbortController}),this._syncHostThreads()}return this._whenRuntimeAttached(e)}_retireThreadRuntime(e){try{e.unsubscribeRunning?.()}finally{e.unsubscribeRunning=void 0,e.runtime&&af(e.runtime),e.destroy.abort(),e.destroy=new AbortController,e.generation=this.nextGeneration++,e.mountError=void 0}}__internal_restartThreadRuntime(e){let t=this.instances.get(e);if(!t)return this.startThreadRuntime(e);try{this._retireThreadRuntime(t)}finally{this._syncHostThreads(),this._notifySubscribers()}return this._whenRuntimeAttached(e)}getThreadRuntimeCore(e){let t=this.instances.get(e);if(t)return t.runtime}__internal_hasThreadRuntime(e){return this.instances.has(e)}__internal_isThreadRuntimeAttached(e){return dp(this.instances.get(e))}__internal_isThreadRunning(e){return this.instances.get(e)?.isRunning??!1}runningSubscribers=new Set;__internal_subscribeRunningChanged(e){return this.runningSubscribers.add(e),()=>this.runningSubscribers.delete(e)}threadEventSubscribers=new Set;__internal_subscribeThreadEvents(e){return this.threadEventSubscribers.add(e),()=>this.threadEventSubscribers.delete(e)}_publish=(e,t,n)=>{this._publishThreadRuntime(e,t,n)};_failThreadRuntime(e,t,n){let r=this.instances.get(e);r?.generation!==t||dp(r)&&r.committedGeneration===t||(r.mountError={error:n},queueMicrotask(()=>this._notifySubscribers()))}_publishThreadRuntime(e,t,n){let r=this.instances.get(e);if(!r||r.generation!==n)return;let i=r.runtime,a=r.publishedGeneration;r.mountError=void 0,r.runtime=t,r.publishedGeneration=n;try{i!==t&&this._trackRunning(e,r)}finally{try{this._notifySubscribers(),i!==void 0&&i!==t&&Ka(this.replacedSubscribers)}finally{a===n&&i!==void 0&&i!==t&&of(i)}}}replacedSubscribers=new Set;__internal_subscribeRuntimeReplaced(e){return this.replacedSubscribers.add(e),()=>this.replacedSubscribers.delete(e)}_trackRunning(e,t){let n=t.unsubscribeRunning;t.unsubscribeRunning=void 0;try{n?.()}finally{let n=t.runtime;if(!n)this._setRunning(t,!1);else{let r=Wd(n);t.isRunning!==r&&(t.isRunning=r,queueMicrotask(()=>Ka(this.runningSubscribers)));let i=[n.subscribe(()=>{this._setRunning(t,Wd(n))}),...up.map(t=>n.unstable_on(t,()=>{w(this.threadEventSubscribers,{threadId:e,type:t},`Thread event "${t}"`)}))];t.unsubscribeRunning=()=>qa(i)}}}_setRunning(e,t){e.isRunning!==t&&(e.isRunning=t,Ka(this.runningSubscribers))}stopThreadRuntime(e){let t=this.instances.get(e);try{t?.unsubscribeRunning?.()}finally{t?.runtime&&of(t.runtime),t?.destroy.abort(),this.instances.delete(e),this.pendingThreadAdapters.delete(e),this._syncHostThreads(),this._notifySubscribers()}}setRuntimeHook(e){if(this.runtimeHook===e)return;this.runtimeHook=e;let t=this.hostStore.getState().hookEpoch+1;try{qa(Array.from(this.instances.values(),e=>()=>this._retireThreadRuntime(e)))}finally{this._syncHostThreads(t)}}__internal_setDefaultAdapters(e){let t=this.adapterStore.getState();t.defaultAdapters!==e&&this.adapterStore.setState({...t,defaultAdapters:e})}__internal_setThreadAdapters(e,t){let n=this.adapterStore.getState(),r=new Map(n.threadAdapters);t===null?r.delete(e):r.set(e,t),this.adapterStore.setState({...n,threadAdapters:r})}__internal_dispose(){this.disposed=!0;for(let e of[...this.instances.keys()])try{this.stopThreadRuntime(e)}catch(e){console.error(`[assistant-ui] Thread runtime cleanup threw while stopping a thread`,e)}}_syncHostThreads(e){let t=this.hostStore.getState();this.hostStore.setState({...t,hookEpoch:e??t.hookEpoch,threads:Array.from(this.instances.entries()).map(([e,{generation:t,destroy:n}])=>({id:e,generation:t,destroySignal:n.signal}))})}_threadElements(e,{threads:t,hookEpoch:n},r){let i=this.runtimeHook;return t.map(({id:a,generation:o,destroySignal:s})=>{let c=this.pendingThreadAdapters.has(a)?this.pendingThreadAdapters.get(a):r.threadAdapters.get(a)??r.defaultAdapters;return gr(`${a}:${o}:${n}`,lp({threadId:a,generation:o,parentList:this.parent,runtimeHook:()=>{try{return i()}catch(e){if(e!==null&&(typeof e==`object`||typeof e==`function`)&&`then`in e&&typeof e.then==`function`)throw e;for(let n of t)this._failThreadRuntime(n.id,n.generation,e);throw e}},parentClient:e,adapters:c,publish:this._publish,publishInCommit:this.publishInCommit,destroySignal:s}),[a,o,this.parent,i,e,c,this._publish,this.publishInCommit,s])})}__internal_useHost(e){let t=fl(this.hostStore),n=fl(this.adapterStore);return Cr(this._threadElements(e,t,n))}__internal_RenderThreadRuntimes=({provider:e})=>(fl(this.hostStore),Array.from(this.instances.entries()).map(([t,{generation:n}])=>(0,J.jsx)(this._OuterActiveThreadProvider,{threadId:t,provider:e},`${t}:${n}`)));__internal_Host=({parentClient:e})=>{let t=fl(this.hostStore),n=fl(this.adapterStore),r=Xu(),i=this._threadElements(e,t,{...n,defaultAdapters:n.defaultAdapters??r}),{effects:a}=Tr(function(){return Cr(i)});return Yc(()=>{try{a();for(let{id:e,generation:n}of t.threads){let t=this.instances.get(e);t?.generation===n&&(t.committedGeneration=n)}}catch(e){for(let{id:n,generation:r}of t.threads)this._failThreadRuntime(n,r,e);throw e}}),null};_OuterActiveThreadProvider=rn(({threadId:e,provider:t})=>{let n=qt(()=>new ff(this.parent).getItemById(e),[e]),r=U(!1);return W(()=>{if(process.env.NODE_ENV!==`production`&&t!==an){let e=setTimeout(()=>{r.current||console.warn("RemoteThreadListAdapter.unstable_Provider did not render its `children` synchronously. Render `children` on first commit; deferring them behind a loading state, Suspense boundary, or `useEffect` gate strands the runtime host and leaves the thread without context.")},100);return()=>clearTimeout(e)}},[t]),(0,J.jsx)(rd,{runtime:n,children:(0,J.jsx)(t,{children:(0,J.jsx)(this._AdapterSink,{threadId:e,detectorRef:r})})})});_AdapterSink=({threadId:e,detectorRef:t})=>{let n=Xu();return this.pendingThreadAdapters.set(e,n),Yc(()=>(this.__internal_setThreadAdapters(e,n),()=>{this.pendingThreadAdapters.get(e)===n&&this.pendingThreadAdapters.delete(e),this.__internal_setThreadAdapters(e,null)}),[e,n]),(0,J.jsx)(fp,{detectorRef:t})}};function mp(e,t,n,...r){if(!n)return;let i=n=>{try{console.error(`[${e}] ${t} callback threw an error`,n)}catch{}};try{let e=n(...r);if(e!==null&&(typeof e==`object`||typeof e==`function`)&&`then`in e&&typeof e.then==`function`)return Promise.resolve(e).then(()=>void 0,e=>i(e))}catch(e){i(e)}}var hp=(e,t,n)=>n.reduce((e,n)=>n?.(e,t)??e,e),gp=class extends Xa{_pendingTransforms=[];_completedOptimistics=[];_nextTransformOrder=0;_epoch=0;_baseValue;_cachedValue;constructor(e){super(),this._baseValue=e,this._cachedValue=e}_updateState(){let e=[...this._pendingTransforms.map(e=>({order:e.order,apply:t=>hp(t,e.task,[e.loading,e.optimistic])})),...this._completedOptimistics.map(({order:e,optimistic:t})=>({order:e,apply:t}))].sort((e,t)=>e.order-t.order);this._cachedValue=e.reduce((e,t)=>t.apply(e),this._baseValue),this._notifySubscribers()}get baseValue(){return this._baseValue}get value(){return this._cachedValue}update(e){this._baseValue=e,this._updateState()}reset(e){this._epoch++,this._pendingTransforms.length=0,this._completedOptimistics.length=0,this._baseValue=e,this._cachedValue=e,this._notifySubscribers()}async optimisticUpdate(e){let t=this._epoch,n=this._nextTransformOrder++,r=e.execute(),i={...e,order:n,task:r};try{this._pendingTransforms.push(i),this._updateState();let n=await r;if(t!==this._epoch)return n;this._baseValue=hp(this._baseValue,n,[e.optimistic,e.then]);for(let t of this._completedOptimistics)(e.then||t.order>i.order)&&(this._baseValue=t.optimistic(this._baseValue));return e.optimistic&&(this._completedOptimistics.push({order:i.order,optimistic:e.optimistic}),this._completedOptimistics.sort((e,t)=>e.order-t.order)),n}finally{let e=this._pendingTransforms.indexOf(i);e>-1&&this._pendingTransforms.splice(e,1);try{this._updateState()}finally{this._pendingTransforms.length===0&&(this._completedOptimistics.length=0)}}}},_p=Error("This is the empty thread, a placeholder for the main thread. You cannot perform any actions on this thread instance. This error is probably because you tried to call a thread method in your render function. Call the method inside a `useEffect` hook instead."),vp=new class extends Jd{get error(){return _p}messages=[];composer=qd(_p,!0);isLoading=!0;getMessageById(){}getBranches(){return[]}export(){return{messages:[]}}subscribe(){return()=>{}}waitForUpdate(){return Promise.reject(_p)}};function yp(e){return e}var bp=`__LOCALID_`,xp=e=>e||void 0,Sp=(e,t)=>{let n=[...t.threadIds],r=[...t.archivedThreadIds],i=k(t.threadIdMap),a=k(t.threadData),o=new Set([...n,...r]);for(let t of e){switch(t.status){case`regular`:case`archived`:break;default:{let e=t.status;throw Error(`Unsupported state: ${e}`)}}let e=i[t.remoteId],s=e===void 0?void 0:a[e],c=s?.id??t.remoteId,l=e??yp(c),u=s!==void 0&&s.status!==`new`?s.initializeTask:void 0;o.has(c)?s!==void 0&&s.status!==t.status&&(t.status===`regular`?(r=r.filter(e=>e!==c),n.push(c)):(n=n.filter(e=>e!==c),r.push(c))):(o.add(c),t.status===`regular`?n.push(c):r.push(c)),i[c]=l,i[t.remoteId]=l,a[l]={...s?.localOrigin===!0?{localOrigin:!0}:{},id:c,remoteId:t.remoteId,externalId:t.externalId,status:t.status,title:t.title,lastMessageAt:t.lastMessageAt,custom:t.custom,initializeTask:u??Promise.resolve({remoteId:t.remoteId,externalId:t.externalId})}}return{threadIds:n,archivedThreadIds:r,threadIdMap:i,threadData:a}},Cp=(e,t)=>({...e,...Sp([t],{threadIds:[...e.threadIds],archivedThreadIds:[...e.archivedThreadIds],threadIdMap:e.threadIdMap,threadData:e.threadData})}),wp=()=>({isLoading:!0,loadError:void 0,switchError:void 0,isLoadingMore:!1,cursor:void 0,newThreadId:void 0,threadIds:[],archivedThreadIds:[],threadIdMap:k(),threadData:k()}),Tp=(e,t)=>{let n=yp(t.id);return{...e,newThreadId:t.id,threadIdMap:k(e.threadIdMap,{[t.id]:n}),threadData:k(e.threadData,{[n]:t})}},Ep=(e,t)=>{let n=`${bp}${t??h()}`;for(;e.threadIdMap[n];)n=`${bp}${h()}`;return{id:n,state:Tp(e,{status:`new`,id:n,remoteId:void 0,externalId:void 0,title:void 0,custom:void 0,localOrigin:!0})}},Dp=(e,t,n)=>{let r=new Set(e.threadIds),i=new Set(e.archivedThreadIds),a=[],o=[],s=(e,t)=>e.has(t.id)||t.remoteId!==void 0&&e.has(t.remoteId);for(let t of Object.values(e.threadData)){let e=n.get(t.id);e!==void 0&&e!==`new`||e===void 0&&t.localOrigin!==!0||(t.status===`regular`&&!s(r,t)?(a.push(t),r.add(t.id)):t.status===`archived`&&!s(i,t)&&(o.push(t),i.add(t.id)))}if(a.length===0&&o.length===0)return e;let c=(e,t)=>{let n=e.indexOf(t.id);if(n!==-1)return n;let r=t.remoteId===void 0?-1:e.indexOf(t.remoteId);return r===-1?2**53-1:r};return a.sort((e,n)=>c(t.threadIds,e)-c(t.threadIds,n)),o.sort((e,n)=>c(t.archivedThreadIds,e)-c(t.archivedThreadIds,n)),{...e,threadIds:[...a.map(e=>e.id),...e.threadIds],archivedThreadIds:[...o.map(e=>e.id),...e.archivedThreadIds]}},Op=e=>new Map(Object.values(e.threadData).map(e=>[e.id,e.status])),kp=(e,t,n)=>{let r=Sp(t.threads,{threadIds:[],archivedThreadIds:[],threadIdMap:{...e.threadIdMap},threadData:{...e.threadData}});return Dp({...e,isLoading:!1,loadError:void 0,cursor:xp(t.nextCursor),threadIds:r.threadIds,archivedThreadIds:r.archivedThreadIds,threadIdMap:r.threadIdMap,threadData:r.threadData},e,n)},Ap=(e,t)=>{let n=Sp(t.threads,{threadIds:[...e.threadIds],archivedThreadIds:[...e.archivedThreadIds],threadIdMap:{...e.threadIdMap},threadData:{...e.threadData}});return{...e,isLoadingMore:!1,cursor:xp(t.nextCursor),threadIds:n.threadIds,archivedThreadIds:n.archivedThreadIds,threadIdMap:n.threadIdMap,threadData:n.threadData}},Y=(e,t)=>{let n=Object.hasOwn(e.threadIdMap,t)?e.threadIdMap[t]:void 0;if(n!==void 0)return Object.hasOwn(e.threadData,n)?e.threadData[n]:void 0},jp=(e,t,n,r,i)=>{let a=yp(t),o=Object.hasOwn(e.threadData,a)?e.threadData[a]:void 0;if(!o)return{state:e,removedMappingId:void 0,survivorMappingId:a};let s=Object.hasOwn(e.threadIdMap,n)?e.threadIdMap[n]:void 0,c=s!==void 0&&s!==a&&Object.hasOwn(e.threadData,s)?e.threadData[s]:void 0,l=s!==void 0&&c!==void 0?{mappingId:s,data:c}:void 0,u=i!==void 0&&Object.hasOwn(e.threadIdMap,i)?e.threadIdMap[i]:void 0,d=l!==void 0&&u===l.mappingId?l.mappingId:a,f=l===void 0?void 0:d===a?l.mappingId:a,p=r??l?.data.externalId,m=k(e.threadData);f!==void 0&&delete m[f];let h={...o,id:d,initializeTask:Promise.resolve({remoteId:n,externalId:p}),remoteId:n,externalId:p};m[d]={...l?.data,...h,title:o.title??l?.data.title,lastMessageAt:(`lastMessageAt`in o?o.lastMessageAt:void 0)??(l&&`lastMessageAt`in l.data?l.data.lastMessageAt:void 0),custom:o.custom??l?.data.custom};let g=k(e.threadIdMap);if(f!==void 0)for(let[e,t]of Object.entries(g))t===f&&(g[e]=d);g[t]=d,g[n]=d;let _=e=>l===void 0?e:e.filter(e=>e!==l.data.id).map(e=>e===o.id?d:e);return{state:{...e,threadIds:_(e.threadIds),archivedThreadIds:_(e.archivedThreadIds),threadIdMap:g,threadData:m},removedMappingId:f,survivorMappingId:d}},Mp=(e,t,n,r)=>{let i=Y(e,t);if(!i)return e;let{id:a,status:o}=i;if(o===n)return e;let s;if(n!==`deleted`){if(i.status===`new`){if(r===void 0)return e;s={...i,initializeTask:r,status:n}}else s={...i,status:n}}let c={...e};switch(o){case`new`:c.newThreadId=void 0;break;case`regular`:c.threadIds=c.threadIds.filter(e=>e!==a);break;case`archived`:c.archivedThreadIds=c.archivedThreadIds.filter(e=>e!==a);break;default:throw Error(`Unsupported state: ${o}`)}switch(n){case`regular`:c.threadIds=[a,...c.threadIds];break;case`archived`:c.archivedThreadIds=[a,...c.archivedThreadIds];break;case`deleted`:{let n=e.threadIdMap[t],r=k(c.threadData);delete r[n],c.threadData=r;let i=k(c.threadIdMap);for(let[e,t]of Object.entries(i))t===n&&delete i[e];c.threadIdMap=i;break}default:throw Error(`Unsupported state: ${n}`)}return s!==void 0&&(c.threadData={...c.threadData,[a]:s}),c},Np=(e,t,n)=>Mp(e,t,n,void 0),Pp=(e,t,n)=>Mp(e,t,`regular`,n),Fp=(e,t,n)=>{let r=Np(e,t,`deleted`);return n===void 0?r:Np(r,n,`deleted`)},Ip=class{pending=new Map;aliases=new Map;nextOrder=0;resolve(e){let t=this.aliases.get(e);for(;t!==void 0;)e=t,t=this.aliases.get(e);return e}merge(e,t){let n=this.resolve(e),r=this.resolve(t);if(n===r)return;this.aliases.set(r,n);let i=[...this.pending.get(n)??[],...this.pending.get(r)??[]].sort((e,t)=>Number(t.running)-Number(e.running)||e.order-t.order);if(this.pending.delete(r),i.length===0)return;let a;for(let e of i)e.previous=a,a=e.done;this.pending.set(n,i)}reserve(e,t){let n=t?.remoteId===void 0?t?.initializeTask:void 0,r=this.resolve(e),i=this.pending.get(r)??[],a,o=new Promise(e=>{a=e}),s={order:this.nextOrder++,done:o,previous:i.at(-1)?.done,running:!1};i.push(s),this.pending.set(r,i);let c=!1,l=()=>{a();let t=this.resolve(e),n=this.pending.get(t);n.splice(n.indexOf(s),1),n.length===0&&this.pending.delete(t)},u=async e=>{let t;do t=s.previous,t&&await t;while(t!==s.previous);return e()};return{run:async e=>{c=!0;try{return n&&await n.catch(()=>{}),await u(()=>(s.running=!0,e()))}finally{u(l)}},cancel:()=>{c||(c=!0,u(l))}}}},Lp=class extends Error{[pl]=!0;constructor(){super(`Thread list adapter changed while an operation was pending.`),this.name=`ThreadListAdapterChangedError`}},Rp=e=>e.status?.type!==`running`,zp=async(e,t)=>{let n=ns.fromAssistantStream(e);for await(let e of n){let n=e.parts.filter(e=>e.type===`text`)[0]?.text;n?.trim()&&await t(n)}},Bp=new WeakMap,Vp=new WeakMap;function Hp(e,t){let n=Vp.get(e);n===void 0&&(n=new Map,Vp.set(e,n));let r=n.get(t);return r===void 0&&(r={runEnded:!1,renamed:!1,messages:void 0},n.set(t,r)),r}var Up=new WeakMap;function Wp(e,t){for(let n of Up.get(e)??[])n(t)}function Gp(e,t){let n=e.get(t);return n===void 0&&(n={generations:new Set,pendingClaim:null,inFlightClaims:new Set,manualClaim:null,latestGeneration:null,nextOrder:0},e.set(t,n)),n}function Kp(e,t,n){n.generations.size===0&&!Bp.has(n)&&n.pendingClaim===null&&n.inFlightClaims.size===0&&n.manualClaim===null&&e.get(t)===n&&e.delete(t)}function qp(e,t){return!t.superseded&&(e.latestGeneration?.order??0)<=t.order}function Jp(e){let t=e.latestGeneration;for(;t!==null&&t.automatic;)t=t.outranked;return t}function Yp(e,t){return(Jp(e)?.order??0)<t.order}function Xp(e,t,n){let r=Gp(e,t),i,a=new Promise(e=>{i=e}),o={title:n,order:++r.nextOrder,settled:a,settle:i,renamed:void 0};r.pendingClaim=o,r.inFlightClaims.add(o),Wp(r,a);for(let e of r.generations)e.order<o.order&&(e.claim=o,e.claims.push(o));return o}function Zp(e,t,n,r){n.renamed=r,n.settle(r);let i=e.get(t);i!==void 0&&(r&&(Hp(e,t).renamed=!0),i.inFlightClaims.delete(n),r&&Yp(i,n)&&(i.manualClaim?.order??0)<n.order&&(i.manualClaim=n),i.pendingClaim===n&&(i.pendingClaim=r?null:Qp(i,i.inFlightClaims)),Kp(e,t,i))}function Qp(e,t){let n=null;for(let r of t)r.renamed!==!1&&Yp(e,r)&&(n===null||r.order>n.order)&&(n=r);return n}function $p(e,t,n){let r=n.manualClaim;if(r!==null)return n.manualClaim=null,Kp(e,t,n),r.title}function em(e,t){e.latestGeneration===t&&(e.latestGeneration=t.outranked);let n=[...t.hiddenManual===null?[]:[t.hiddenManual],...t.beforeGenerationClaims].reduce((e,t)=>t.renamed===!0&&(e?.order??0)<t.order?t:e,null);for(let n=e.latestGeneration;n!==null;n=n.outranked)n.outranked===t&&(n.outranked=t.outranked);for(let r of e.generations)n!==null&&!r.automatic&&r.order>t.order&&(r.hiddenManual?.order??0)<n.order&&(r.hiddenManual=n);n!==null&&Yp(e,n)&&(e.manualClaim?.order??0)<n.order&&(e.manualClaim=n);for(let n of e.generations)n!==t&&n.automatic&&n.claim===null&&(n.claim=Qp(e,[...n.claims,...e.inFlightClaims,...e.manualClaim===null?[]:[e.manualClaim]]))}function tm(e,t){e.delete(t)}function nm(e,t,n){let r=Gp(e,t);if(n&&r.pendingClaim===null&&$p(e,t,r)!==void 0)return null;let i,a=new Promise(e=>{i=e}),o={automatic:n,order:++r.nextOrder,claim:n?r.pendingClaim:null,claims:n&&r.pendingClaim!==null?[r.pendingClaim]:[],beforeGenerationClaims:n?[]:[...r.inFlightClaims],outranked:r.latestGeneration,hiddenManual:n?null:r.manualClaim,superseded:!1,persisted:a,settlePersisted:i};return n||(r.pendingClaim=null,r.manualClaim=null),r.latestGeneration=o,r.generations.add(o),Up.has(r)&&Wp(r,a.then(e=>e!==void 0)),o}async function rm(e){let{states:t,threadId:n,automatic:r,afterRun:i}=e,a=Gp(t,n),o=Hp(t,n);if(i){if(o.runEnded||o.renamed){Kp(t,n,a);return}o.runEnded=!0;let r=o.messages!==void 0&&o.messages.some(e=>e.role===`assistant`)&&o.messages.length===e.messages?.length&&o.messages.every((t,n)=>t===e.messages[n]);if(o.messages=void 0,r){Kp(t,n,a);return}Bp.set(a,(Bp.get(a)??0)+1);let s=!1;try{for(;a.generations.size>0||a.inFlightClaims.size>0;)if(await Promise.all([...[...a.generations].map(e=>e.persisted),...[...a.inFlightClaims].map(e=>e.settled)]),t.get(n)!==a)return;if(o.renamed||i())return;s=!0}finally{let e=Bp.get(a)-1;e===0?Bp.delete(a):Bp.set(a,e),s||Kp(t,n,a)}}else r&&!o.runEnded&&(o.messages=e.messages);let s=r?[...a.generations].filter(e=>!e.automatic):[],c=s.length>0,l=a.nextOrder;c&&Bp.set(a,(Bp.get(a)??0)+1);let u;try{if(c){let e=new Set(s),r=()=>{let t=!1;for(let n of a.generations)n.automatic||e.has(n)||(e.add(n),t=!0);for(let n=a.latestGeneration;n!==null;n=n.outranked)n.automatic||n.order<=l||e.has(n)||(e.add(n),t=!0);return t};for(;;){r();let i=await Promise.all([...e].map(e=>e.persisted));if(t.get(n)!==a)return;if(!(r()||[...a.generations].some(e=>!e.automatic))){if(i.some(e=>e!==void 0))return;break}}}u=nm(t,n,r)}finally{if(c){let e=Bp.get(a)-1;e===0?Bp.delete(a):Bp.set(a,e),Kp(t,n,a)}}if(u===null)return;let d=()=>t.get(n)===a,f=async t=>{d()&&await e.generate(t)},p=async t=>{d()&&await e.rename(t)},m,h=async t=>{d()&&(await e.applyTitle(t),m=t)},g,_=u.order,v=!1,y,b=async(t,n)=>{let r=a.nextOrder,i=[],o=e=>i.push(e),s=Up.get(a);s===void 0&&(s=new Set,Up.set(a,s)),s.add(o);try{await p(t),g=t}catch(t){try{for(;d();){let t=i.length,o=await Promise.all(i);if(i.length!==t)continue;if(o.some(Boolean)||t===0&&(a.nextOrder!==r||!n()))break;let s=a.nextOrder,c=await e.readTitle();if(!d())break;if(a.nextOrder===s&&i.length===t){if(t===0&&!n())break;g=c,await h(c);break}}}catch{}throw t}finally{s.delete(o),s.size===0&&Up.delete(a)}},x=async e=>{let t=await e.settled;if(u.claim===e){if(!t){a.pendingClaim===e&&(a.pendingClaim=null);let t=Qp(a,r?[...u.claims,...a.inFlightClaims,...a.manualClaim===null?[]:[a.manualClaim]]:u.claims);if(u.claim=t,t!==null)return}return t}},S=()=>r&&$p(t,n,a)!==void 0,C=async()=>{for(;!u.superseded;){let e=a.latestGeneration;if(e===null||e.order<=u.order||(await e.persisted,a.latestGeneration===e))return}},w=async()=>{if(g!==void 0)for(;;){let e=u.claim;if(e!==null&&Yp(a,e)&&(e.order>_||e.renamed===!0&&e.title!==g)){await x(e)===!0&&(await b(e.title,()=>u.claim===e&&Yp(a,e)),_=e.order);continue}let t=a.latestGeneration;if(t===null||t===u||t.order<=_)return;let n=await t.persisted;if(a.latestGeneration===t){if(n===void 0||n===g)return;await b(n,()=>a.latestGeneration===t&&(u.claim?.order??0)<=t.order),_=t.order}}},T=async()=>{for(u.beforeGenerationClaims.length>0&&await Promise.all(u.beforeGenerationClaims.map(e=>e.settled));;){for(;u.claim!==null;){let e=await x(u.claim);if(e!==void 0){if(e){u.superseded=!0;return}if(S())return;break}}if(r&&!qp(a,u)){if(await C(),!qp(a,u))return}else{if(!qp(a,u))return;break}}for(await f(async e=>{v=!0,y=e,e!==void 0&&(g=e);let t=u.claim;if(t!==null){if(await x(t)!==!1)return;if(S()){u.superseded=!0;return}}g!==void 0&&qp(a,u)&&await h(y)});;){let e=u.claim;if(e===null)return;let t=await x(e);if(t!==void 0){if(t===!1){if(S())return;v&&g!==void 0&&qp(a,u)&&await h(y);return}if(!Yp(a,e)){if(await C(),!Yp(a,e))return;if(u.claim!==e)continue}if(await b(e.title,()=>u.claim===e&&qp(a,u)),_=e.order,u.claim===e){if(!qp(a,u))return;await h(e.title),u.superseded=!0;return}}}};try{if(await T(),g!==void 0&&await C(),await w(),g!==void 0&&qp(a,u)){let e=u.claim;e!==null&&e.renamed===!0&&Yp(a,e)?m!==e.title&&await h(e.title):e===null&&v&&m!==y&&await h(y)}}finally{g===void 0&&em(a,u),u.settlePersisted(g),a.generations.delete(u),Kp(t,n,a)}}var im=(e,t)=>Error(`Thread "${e}" not found while ${t}.`),am=(e,t,n)=>Error(`Thread "${e}" has status "${t}", so it cannot ${n}.`),om=wp(),sm=class extends Xa{_options;_hookManager;_runtimeAdapters;_loadThreadsPromise;_loadMorePromise;_loadGeneration=0;_adapterGeneration=0;_listedAdapterGeneration=0;_replaceListOnNextLoad=!1;_staleThreadIdsOnReplace;_staleThreadsAdapter;_switchGeneration=0;_disposedSwitchGeneration;_switchTask;_supersedeAttachmentWait;_switchError;_titleStates=new Map;_mutations=new Ip;_automaticTitles=new Map;_runningThreads=new Set;_destroyController=new AbortController;_mainThreadId;_state=new gp(om);_useAdaptersProvider=({children:e})=>{let t=this._options.adapter.unstable_useAdapters;return t===void 0?e:(0,J.jsx)(this._SynthesizedAdapters,{useAdapters:t,children:e})};_SynthesizedAdapters=({useAdapters:e,children:t})=>{let n=Qu(e());return n==null?t:(0,J.jsx)(Yd,{adapters:n,children:t})};resolveProvider(e){return e.unstable_Provider===void 0?e.unstable_useAdapters===void 0?an:this._useAdaptersProvider:e.unstable_Provider}_exposedItems;_getExposedItems(){let e=this._state.value,t=this._exposedItems;if(t?.state===e&&t.mainThreadId===this._mainThreadId)return t;let n=new Set;for(let t of[e.newThreadId,...e.threadIds,...e.archivedThreadIds,this._mainThreadId]){if(t===void 0)continue;let r=Y(e,t);r!==void 0&&n.add(r.id)}let r=Object.entries(e.threadData),i=r.every(([,e])=>n.has(e.id))?e.threadData:k(Object.fromEntries(r.filter(([,e])=>n.has(e.id))));return this._exposedItems={state:e,mainThreadId:this._mainThreadId,ids:n,items:i},this._exposedItems}get threadItems(){return this._getExposedItems().items}getLoadThreadsPromise(){if(!this._loadThreadsPromise){let e=this._loadGeneration,t=this._switchGeneration,n=!1,r=!1,i=Op(this._state.baseValue),a=(e,t)=>{this._loadThreadsPromise=void 0,console.error(`[assistant-ui] thread list load failed:`,t);let r={...e,isLoading:!1,loadError:t};return this._replaceListOnNextLoad?(this._replaceListOnNextLoad=!1,this._listedAdapterGeneration=this._adapterGeneration,n=!0,this._replaceWithThreads(r,[],void 0)):r};this._loadThreadsPromise=this._state.optimisticUpdate({execute:async()=>{try{return{success:!0,response:await this._options.adapter.list()}}catch(e){return{success:!1,error:e}}},loading:t=>e===this._loadGeneration?{...t,isLoading:!0,loadError:void 0}:t,then:(t,o)=>{if(e!==this._loadGeneration)return t;if(!o.success)return a(t,o.error);let s=o.response,c=!1;try{return c=this._replaceListOnNextLoad,r=!0,c?(this._replaceListOnNextLoad=!1,this._listedAdapterGeneration=this._adapterGeneration,n=!0,this._replaceWithThreads({...t,loadError:void 0},s.threads,xp(s.nextCursor))):kp(t,s,i)}catch(e){return c&&(this._replaceListOnNextLoad=!0),a(t,e)}}}).catch(t=>{e===this._loadGeneration&&this._state.update(a(this._state.baseValue,t))}).then(()=>{(r||n)&&this._reapplyControlledThread(n,t)})}return this._loadThreadsPromise}loadMore(){if(this._loadMorePromise)return this._loadMorePromise;let e=this._state.value;if(e.cursor===void 0||e.isLoading)return Promise.resolve();let t=this._loadGeneration,n=this._options.adapter,r=e.cursor,i=!1,a=this._state.optimisticUpdate({execute:()=>n.list({after:r}),loading:e=>t===this._loadGeneration?{...e,isLoadingMore:!0}:e,then:(e,r)=>t!==this._loadGeneration||n!==this._options.adapter?e:(i=!0,Ap(e,r))}).catch(e=>{t===this._loadGeneration&&console.error(`[assistant-ui] thread list loadMore failed:`,e)}).then(()=>{this._loadMorePromise===a&&(this._loadMorePromise=void 0),i&&this._reapplyControlledThread(!1)});return this._loadMorePromise=a,a}_reapplyControlledThread(e,t=this._switchGeneration){let n=this._options.threadId;if(n===void 0)return;let r=this.getItemById(n);e&&t!==this._switchGeneration&&this._controlledSwitchGeneration!==this._switchGeneration||!e&&(r===void 0||this._controlledSwitchGeneration!==this._switchGeneration)||r?.id!==this._mainThreadId&&this._switchToThreadFromProp(n).catch(()=>{})}constructor(e,t,n){super(),this._state.subscribe(()=>{this._notifySubscribers(),this._notifyThreadIdChange()}),this._runtimeAdapters={modelContext:t},this._hookManager=new pp(e.runtimeHook,this),this._hookManager.__internal_setDefaultAdapters(this._runtimeAdapters),this._hookManager.__internal_subscribeRunningChanged(()=>{for(let e of Object.values(this._state.value.threadData))if(this._hookManager.__internal_isThreadRunning(e.id))this._runningThreads.add(e.id);else if(this._runningThreads.delete(e.id)){let t=this._hookManager.getThreadRuntimeCore(e.id)?.messages.filter(Rp);if(!t||e.status===`new`)continue;let n=this._adapterGeneration;queueMicrotask(()=>{!this._destroyController.signal.aborted&&n===this._adapterGeneration&&this.getItemById(e.id)&&this._generateTitle(e.id,{automatic:!0},()=>this._destroyController.signal.aborted?void 0:t,!0).catch(e=>{ml(e)||console.error(`[assistant-ui] Thread title generation failed`,e)})})}this._notifySubscribers()}),this._hookManager.__internal_subscribeRuntimeReplaced(()=>{queueMicrotask(()=>this._notifySubscribers())}),this.providerStore=new Za(this.resolveProvider(e.adapter)),this.__internal_setOptions(e),this._startSwitchToNewThread(!0,n)}_initialThreadLoaded=!1;providerStore;__internal_setOptions(e){if(this._options===e)return;let t=this._options!==void 0&&this._options.adapter!==e.adapter,n=this._initialThreadLoaded&&this._options!==void 0&&this._options.threadId!==e.threadId;t&&!this._replaceListOnNextLoad&&(this._staleThreadsAdapter=this._options.adapter),this._options=e,this.providerStore.setState(this.resolveProvider(e.adapter)),this._hookManager.setRuntimeHook(e.runtimeHook),t&&(this._loadGeneration++,this._adapterGeneration++,this._mutations=new Ip,this._nextSwitchGeneration(),this._switchTask=void 0,this._loadThreadsPromise=void 0,this._loadMorePromise=void 0,this._replaceListOnNextLoad=!0,this._staleThreadIdsOnReplace=new Set([...Object.values(this._state.baseValue.threadData),...Object.values(this._state.value.threadData).filter(e=>Y(this._state.baseValue,e.id)?.status===`new`)].filter(e=>e.status!==`new`).map(e=>e.id)),this._titleStates.clear(),this._disarmAutomaticTitles(),this._runningThreads.clear(),this._state.update({...this._state.baseValue,cursor:void 0,loadError:void 0})),n&&this._switchToThreadFromProp(e.threadId).catch(()=>{})}_requireAdapterGeneration(e){if(e!==this._adapterGeneration)throw new Lp}_isOtherAdaptersThread(e,t,n){let r=Y(e,n);return r!==void 0&&(this._staleThreadIdsOnReplace?.has(r.id)?this._staleThreadsAdapter:this._options.adapter)!==t}_updateStatusFromAdapter(e,t,n,r){return this._isOtherAdaptersThread(e,t,n)?e:Np(e,n,r)}_requireAdapterSettled(){if(this._replaceListOnNextLoad)throw new Lp}_replaceWithThreads(e,t,n){let r=[];if(e.newThreadId){let t=Object.hasOwn(e.threadIdMap,e.newThreadId)?e.threadIdMap[e.newThreadId]:void 0,n=t&&Object.hasOwn(e.threadData,t)?e.threadData[t]:void 0;n?.status===`new`&&r.push(n)}let i=this._staleThreadIdsOnReplace;if(i){let n=new Map(t.map(e=>[e.remoteId,e]));for(let t of Object.values(e.threadData)){if(!i.has(t.id)){if(t.status!==`new`&&t.remoteId===void 0)continue;r.push(t);continue}if(t.remoteId===void 0||t.localOrigin!==!0||Y(this._state.value,t.id)===void 0)continue;let e=n.get(t.remoteId);e!==void 0&&r.push({...t,initializeTask:Promise.resolve({remoteId:e.remoteId,externalId:e.externalId})})}}let a={threadIds:[],archivedThreadIds:[],threadIdMap:k(),threadData:k()};for(let e of r){let t=yp(e.id);Object.hasOwn(a.threadData,t)||(a.threadIdMap[e.id]=t,e.remoteId!==void 0&&(a.threadIdMap[e.remoteId]=t),a.threadData[t]=e)}let{threadIds:o,archivedThreadIds:s,threadIdMap:c,threadData:l}=Sp(t,a);this._staleThreadIdsOnReplace=void 0,this._staleThreadsAdapter=void 0;for(let e of r){if(e.remoteId===void 0)continue;let t=yp(e.id),n=Object.hasOwn(l,t)?l[t]:void 0;n!==void 0&&(n.status===`regular`&&!o.includes(n.id)?o.push(n.id):n.status===`archived`&&!s.includes(n.id)&&s.push(n.id))}let u={...e,isLoading:!1,cursor:n,threadIds:o,archivedThreadIds:s,threadIdMap:c,threadData:l,newThreadId:e.newThreadId!==void 0&&!Object.hasOwn(c,e.newThreadId)?void 0:e.newThreadId};if(Y(u,this._mainThreadId)===void 0){let e=u.newThreadId;if(e!==void 0)this._mainThreadId=e;else{let e=Ep(u);this._mainThreadId=e.id,u=e.state}this._options.threadId===void 0?this._notifyThreadIdChange():this._lastNotifiedThreadId=void 0}let d=new Set(Object.values(u.threadData).map(e=>e.id));for(let t of Object.values(e.threadData))if(!d.has(t.id)){this._disarmAutomaticTitle(t.id),this._runningThreads.delete(t.id);try{this._hookManager.stopThreadRuntime(t.id)}catch(e){console.error(`[assistant-ui] Thread runtime cleanup threw while stopping a thread`,e)}}return this._hookManager.startThreadRuntime(this._mainThreadId).then(()=>this._notifySubscribers(),()=>void 0),u}__internal_load(){if(this.getLoadThreadsPromise(),this._initialThreadLoaded)return;this._initialThreadLoaded=!0;let e=this._options.threadId??this._options.initialThreadId;e!==void 0&&(this._options.threadId===void 0?this.switchToThread(e):this._switchToThreadFromProp(e)).catch(()=>{})}async reloadMainThread(){let e=this._mainThreadId;if(e===void 0||this.getItemById(e)?.status===`new`)return;let t=this._hookManager.getThreadRuntimeCore(e);try{t?.unstable_refetchThread?await t.unstable_refetchThread():await this._hookManager.__internal_restartThreadRuntime(e)}catch(t){if(e!==this._mainThreadId)return;throw t}e===this._mainThreadId&&this._notifySubscribers()}reload(){return this._loadGeneration++,this._loadThreadsPromise=void 0,this._loadMorePromise=void 0,this._state.update({...this._state.baseValue,cursor:void 0}),this.getLoadThreadsPromise()}get isLoading(){return this._state.value.isLoading}get canUnarchive(){return!!this._options.adapter.unarchive}get loadError(){return this._state.value.loadError}get switchError(){return this._switchError}_setSwitchError(e){this._switchError!==e&&(this._switchError=e,this._notifySubscribers())}get isLoadingMore(){return this._state.value.isLoadingMore}get hasMore(){return this._state.value.cursor!==void 0}get threadIds(){return this._state.value.threadIds}get archivedThreadIds(){return this._state.value.archivedThreadIds}get newThreadId(){return this._state.value.newThreadId}get mainThreadId(){return this._mainThreadId}_lastNotifiedThreadId=void 0;_newThreadIntent;_clearNewThreadIntent(){this._newThreadIntent?.unsubscribe(),this._newThreadIntent=void 0}_notifyThreadIdChange(e=!0){let t=this._mainThreadId===void 0?void 0:Y(this._state.value,this._mainThreadId),n=t?.remoteId;n!==void 0&&this._newThreadIntent?.generation===this._switchGeneration&&this._newThreadIntent.id===this._mainThreadId||n===void 0&&t&&t.status!==`new`||this._lastNotifiedThreadId!==n&&(this._lastNotifiedThreadId=n,e&&mp(`assistant-ui`,`onThreadIdChange`,this._options.onThreadIdChange,n))}getMainThreadRuntimeCore(){return this._hookManager.getThreadRuntimeCore(this._mainThreadId)||vp}getThreadRuntimeCore(e){let t=this.getItemById(e);if(!t)throw im(e,`getting its runtime`);let n=this._hookManager.getThreadRuntimeCore(t.id);if(!n)throw Error(`Runtime for thread "${e}" not found while getting its runtime.`);return n}unstable_isThreadRunning(e){let t=this.getItemById(e);return t?this._hookManager.__internal_isThreadRunning(t.id):!1}unstable_subscribeThreadEvents(e){return this._hookManager.__internal_subscribeThreadEvents(e)}_getExposedItem(e){let t=Y(this._state.value,e);if(t!==void 0&&this._getExposedItems().ids.has(t.id))return t}getItemById(e){let t=Y(this._state.value,e);if(t!==void 0&&(this._getExposedItems().ids.has(t.id)||this._hookManager.__internal_hasThreadRuntime(t.id)))return t}switchToThread(e,t){return this._controlledSwitchTask!==void 0&&this._controlledSwitchGeneration===this._switchGeneration&&this._supersedeAttachmentWait===void 0&&Y(this._state.value,e)?.id===this._mainThreadId?Promise.resolve():this._startSwitchToThread(e,t,!0)}_nextSwitchGeneration(){return this._supersedeAttachmentWait?.(),this._supersedeAttachmentWait=void 0,++this._switchGeneration}_raceDispose(e,t){let n=this._destroyController.signal;return ao(n,t).catch(t=>{if(!(t===n.reason&&this._disposedSwitchGeneration!==void 0&&e<this._disposedSwitchGeneration))throw t})}_startSwitchToThread(e,t,n){if(this._supersedeAttachmentWait&&this._switchTask&&Y(this._state.value,e)?.id===this._mainThreadId)return this._switchTask;this._clearNewThreadIntent();let r=this._nextSwitchGeneration();this._setSwitchError(void 0);let i=this._raceDispose(r,()=>this._switchToThread(e,t,r,n)).catch(t=>{throw r===this._switchGeneration&&!ml(t)&&Y(this._state.value,e)?.id!==this._mainThreadId&&this._setSwitchError({threadId:e,error:t}),t});return this._switchTask=i,i}async _switchToThread(e,t,n,r){if(this._replaceListOnNextLoad&&e!==this._state.value.newThreadId)throw new Lp;let i=Y(this._state.value,e);if(!i){let t=this._options.adapter;if(await this._state.optimisticUpdate({execute:()=>t.fetch(e),then:(e,t)=>n===this._switchGeneration?Cp(e,t):e}),n!==this._switchGeneration)return;i=Y(this._state.value,e)}if(!i)throw im(e,`switching to it`);if(this._mainThreadId===i.id)return;let a=this.mainThreadId!==void 0,o=this._hookManager.startThreadRuntime(i.id);if(a?await o:o.then(()=>this._notifySubscribers(),()=>void 0),n!==this._switchGeneration)return;let s=Y(this._state.value,i.id);if(s?.id===i.id&&!(s.status===`archived`&&t?.unarchive!==!1&&this._options.adapter.unarchive&&(await s.initializeTask,n!==this._switchGeneration||(s=Y(this._state.value,i.id),s?.id!==i.id)||s.status===`archived`&&(await this._unarchive(s.id,s),n!==this._switchGeneration||(s=Y(this._state.value,i.id),s?.id!==i.id))))){for(this._setMainThreadId(s.id);a&&!this._hookManager.__internal_isThreadRuntimeAttached(s.id);)if(await this._waitForReplacement(s.id),n!==this._switchGeneration)return;this._notifySubscribers(),this._notifyThreadIdChange(r)}}_setMainThreadId(e){if(this._mainThreadId=e,this._destroyController.signal.aborted||this._hookManager.getThreadRuntimeCore(e))return;let t=()=>this._notifySubscribers();this._hookManager.startThreadRuntime(e).then(t,t)}async _waitForReplacement(e){let t,n=new Promise(e=>{t=e});this._supersedeAttachmentWait=t;try{await Promise.race([this._hookManager.startThreadRuntime(e),n])}finally{this._supersedeAttachmentWait===t&&(this._supersedeAttachmentWait=void 0)}}switchToNewThread(){return this._startSwitchToNewThread(!0)}_controlledSwitchGeneration;_controlledSwitchTask;_switchToThreadFromProp(e){let t=e===void 0?Eu(`create`,()=>this._startSwitchToNewThread(!1)):Eu(`switch`,()=>this._startSwitchToThread(e,void 0,!1));this._controlledSwitchGeneration=this._switchGeneration,this._controlledSwitchTask=t;let n=()=>{this._controlledSwitchTask===t&&(this._controlledSwitchTask=void 0,this._newThreadIntent?.generation===this._controlledSwitchGeneration&&this._clearNewThreadIntent())};return t.then(n,n),t}__internal_retryControlledThread(){let e=this._options.threadId;e!==void 0&&this._switchError?.threadId===e&&this._switchToThreadFromProp(e).catch(()=>{})}_startSwitchToNewThread(e,t){this._clearNewThreadIntent();let n=this._nextSwitchGeneration();!e&&this._state.baseValue.newThreadId===this._mainThreadId&&(this._newThreadIntent={id:this._mainThreadId,generation:n,unsubscribe:()=>{}}),this._setSwitchError(void 0);let r=this._raceDispose(n,()=>this._switchToNewThread(n,e,t));return this._switchTask=r,r}async _switchToNewThread(e,t,n){for(;e===this._switchGeneration;){for(;this._state.baseValue.newThreadId!==void 0&&this._state.value.newThreadId===void 0;)if(await this._state.waitForUpdate(),e!==this._switchGeneration)return;let r=this._state.value.newThreadId;if(r===void 0){let e=Ep(this._state.baseValue,n);r=e.id,this._state.update(e.state)}let i=Y(this._state.value,r);if(i?.status!==`new`)continue;if(i.id===this._mainThreadId){if(!t){let t=this._state.subscribe(()=>{e===this._switchGeneration?Y(this._state.value,r)?.status!==`new`&&(t(),queueMicrotask(()=>{e===this._switchGeneration&&this._switchToThreadFromProp(void 0).catch(()=>{})})):t()});this._newThreadIntent={id:i.id,generation:e,unsubscribe:t}}return}let a=this._hookManager.startThreadRuntime(i.id);if(this.mainThreadId===void 0?a.then(()=>this._notifySubscribers(),()=>void 0):await a,e!==this._switchGeneration)return;let o=Y(this._state.value,i.id);if(o?.status===`new`&&o.id===i.id){this._setMainThreadId(o.id),this._clearNewThreadIntent(),this._notifySubscribers(),this._notifyThreadIdChange(t);return}}}initialize=async e=>{let t=this._options.adapter,n=this._adapterGeneration;if(this._state.value.newThreadId!==e){this._requireAdapterSettled();let t=Y(this._state.value,e);if(!t)throw im(e,`initializing it`);if(t.status===`new`)throw am(e,t.status,`be initialized here`);let{remoteId:r,externalId:i}=await t.initializeTask;return this._requireAdapterGeneration(n),{remoteId:r,externalId:i}}this._requireAdapterGeneration(n);let r=Y(this._state.value,e)?.custom,i=r===void 0?t.initialize(e):t.initialize(e,{custom:r}),a,o=this._state.optimisticUpdate({execute:()=>i,optimistic:t=>this._listedAdapterGeneration>n?t:Pp(t,e,i),then:(t,{remoteId:r,externalId:i})=>{if(n!==this._adapterGeneration)return t;let o=jp(t,e,r,i,e);return a=o.removedMappingId,a!==void 0&&this._mutations.merge(o.survivorMappingId,a),a===this._mainThreadId&&this._setMainThreadId(o.survivorMappingId),o.state}});this._armAutomaticTitle(e,o);let{remoteId:s,externalId:c}=await o.finally(()=>{this._leaveRemovedMainThread(e).catch(()=>{})});return this._requireAdapterGeneration(n),a!==void 0&&this._hookManager.stopThreadRuntime(a),{remoteId:s,externalId:c}};_armAutomaticTitle(e,t){if(this._destroyController.signal.aborted)return;this._automaticTitles.get(e)?.();let n,r,i=[],a=!1,o=!1,s=!0,c=()=>{if(!s)return;let t=this.getItemById(e);if(!t){this._disarmAutomaticTitle(e);return}let l=this._hookManager.getThreadRuntimeCore(t.id);l!==n&&(r?.(),n=l,r=l?.subscribe(c));let u=n?.messages.filter(Rp);u?.length&&(i=u),a&&!o&&n&&!n.isLoading&&i.length!==0&&(this._replaceListOnNextLoad?(o=!0,this._state.waitForUpdate().then(()=>{o=!1,c()})):(o=!0,this._generateTitle(e,{automatic:!0},()=>s?i:void 0).then(t=>{o=!1,s&&(t?this._disarmAutomaticTitle(e):c())},t=>{s&&(this._disarmAutomaticTitle(e),ml(t)||console.error(`[assistant-ui] Thread title generation failed`,t))})))},l=this._hookManager.subscribe(c);this._automaticTitles.set(e,()=>{s=!1,l(),r?.()}),t.then(()=>{a=!0,c()},()=>{s&&this._disarmAutomaticTitle(e)}),c()}_disarmAutomaticTitle(e){this._automaticTitles.get(e)?.(),this._automaticTitles.delete(e)}_disarmAutomaticTitles(){for(let e of[...this._automaticTitles.keys()])this._disarmAutomaticTitle(e)}generateTitle=async(e,t)=>{await this._generateTitle(e,t)};_generateTitle=async(e,t,n,r=!1)=>{this._requireAdapterSettled();let i=this._options.adapter,a=this._adapterGeneration,o=this.getItemById(e);if(!o)throw im(e,`generating its title`);if(o.status===`new`)throw am(e,o.status,`generate a title`);let{remoteId:s}=await o.initializeTask;this._requireAdapterGeneration(a);let c=n?.();if(n&&!c)return!1;let l=this._hookManager.getThreadRuntimeCore(o.id);if(!l||n&&l.isLoading)return!1;let u=l.messages.filter(Rp),d=r?c:u.length?u:c??u,f=()=>Y(this._state.baseValue,o.id)===void 0;return await rm({states:this._titleStates,threadId:o.id,automatic:t?.automatic===!0,messages:d,generate:async e=>{if(f())return;let t=await i.generateTitle(s,d);this._requireAdapterGeneration(a),await zp(t,e)},rename:async e=>{await this._mutations.reserve(o.id,o).run(async()=>{this._requireAdapterGeneration(a),f()||await i.rename(s,e)})},readTitle:async()=>{if(this._requireAdapterGeneration(a),f())return;let{title:e}=await i.fetch(s);return this._requireAdapterGeneration(a),e},applyTitle:async e=>{await this._state.optimisticUpdate({execute:async()=>{},optimistic:t=>{if(a!==this._adapterGeneration)return t;let n=Y(t,o.id);return n?{...t,threadData:{...t.threadData,[n.id]:{...n,title:e}}}:t}})},afterRun:r?()=>{if(this._requireAdapterGeneration(a),this._destroyController.signal.aborted)throw new sp;return this.getItemById(o.id)?.title}:void 0}),!0};async rename(e,t){this._requireAdapterSettled();let n=this._options.adapter,r=this._adapterGeneration,i=this._getExposedItem(e);if(!i)throw im(e,`renaming it`);if(i.status===`new`)throw am(e,i.status,`be renamed`);let a=Xp(this._titleStates,i.id,t),o=this._mutations.reserve(i.id,i);try{let s=await this._state.optimisticUpdate({execute:()=>o.run(async()=>{let{remoteId:e}=await i.initializeTask;return this._requireAdapterGeneration(r),n.rename(e,t)}),optimistic:r=>{if(this._isOtherAdaptersThread(r,n,e))return r;let i=Y(r,e);return i?{...r,threadData:{...r.threadData,[i.id]:{...i,title:t}}}:r}});return Zp(this._titleStates,i.id,a,!0),s}catch(e){throw Zp(this._titleStates,i.id,a,!1),e}}async updateCustom(e,t){this._requireAdapterSettled();let n=this._options.adapter,r=this._adapterGeneration,i=this._getExposedItem(e);if(!i)throw im(e,`updating its custom metadata`);let a=r=>{if(this._isOtherAdaptersThread(r,n,e))return r;let i=Y(r,e);return i?{...r,threadData:{...r.threadData,[i.id]:{...i,custom:t}}}:r};if(i.status===`new`){this._state.update(a(this._state.baseValue));return}if(!n.updateCustom)throw Error(`Remote thread list adapter does not support updating custom metadata`);let o=this._mutations.reserve(i.id,i);return this._state.optimisticUpdate({execute:()=>o.run(async()=>{let{remoteId:e}=await i.initializeTask;if(this._requireAdapterGeneration(r),!n.updateCustom)throw Error(`Remote thread list adapter does not support updating custom metadata`);return n.updateCustom(e,t)}),optimistic:a})}async _ensureThreadIsNotMain(e){if(e===this.newThreadId)throw Error(`Cannot ensure new thread is not main`);let t;for(;this._isMainThread(e);){if(e===this.newThreadId)throw Error(`Cannot ensure new thread is not main`);let n=this._switchTask,r=!n||n===t;r&&(n=this.switchToNewThread()),t=n;try{await n}catch(e){if(r&&this._switchTask===n)throw e}}}_isMainThread(e){return(this.getItemById(e)?.id??e)===this._mainThreadId}async _leaveRemovedMainThread(e){let t=this._mainThreadId,n=this.getItemById(t);if(n!==void 0&&(n.status!==`archived`||!this._isMainThread(e)))return;let r=this._state.baseValue.newThreadId!==void 0&&this._state.value.newThreadId===void 0;if(n===void 0&&!r){let e=this._state.value.newThreadId;if(e===void 0){let t=Ep(this._state.baseValue);e=t.id,this._state.update(t.state)}this._mainThreadId=Y(this._state.value,e)?.id??e,this._hookManager.stopThreadRuntime(t),this._hookManager.startThreadRuntime(this._mainThreadId).then(()=>this._notifySubscribers(),()=>void 0),this._notifySubscribers(),this._notifyThreadIdChange()}else await this._ensureThreadIsNotMain(t),this.getItemById(t)===void 0&&this._hookManager.stopThreadRuntime(t)}async archive(e){this._requireAdapterSettled();let t=this._options.adapter,n=this._adapterGeneration,r=this._getExposedItem(e);if(!r)throw im(e,`archiving it`);if(r.status!==`regular`)throw am(e,r.status,`be archived`);let i=this._mutations.reserve(r.id,r);try{do await this._ensureThreadIsNotMain(r.id);while(r.id===this._mainThreadId);this._requireAdapterGeneration(n),await this._state.optimisticUpdate({execute:()=>i.run(async()=>{let{remoteId:e}=await r.initializeTask;return this._requireAdapterGeneration(n),t.archive(e)}),optimistic:e=>this._updateStatusFromAdapter(e,t,r.id,`archived`)})}finally{i.cancel()}await this._leaveRemovedMainThread(r.id)}unarchive(e){return this._unarchive(e,this._getExposedItem(e))}async _unarchive(e,t){this._requireAdapterSettled();let n=this._options.adapter,r=this._adapterGeneration;if(!t)throw im(e,`unarchiving it`);if(t.status!==`archived`)throw am(e,t.status,`be unarchived`);if(!n.unarchive)throw Error(`Remote thread list adapter does not support unarchiving`);let i=this._mutations.reserve(t.id,t);return this._state.optimisticUpdate({execute:()=>i.run(async()=>{try{let{remoteId:e}=await t.initializeTask;if(this._requireAdapterGeneration(r),!n.unarchive)throw Error(`Remote thread list adapter does not support unarchiving`);return await n.unarchive(e)}catch(e){throw r===this._adapterGeneration&&await this._ensureThreadIsNotMain(t.id),e}}),optimistic:e=>this._updateStatusFromAdapter(e,n,t.id,`regular`)})}async delete(e){this._requireAdapterSettled();let t=this._options.adapter,n=this._adapterGeneration,r=this._getExposedItem(e);if(!r)throw im(e,`deleting it`);if(r.status!==`regular`&&r.status!==`archived`)throw am(e,r.status,`be deleted`);let i=Y(this._state.baseValue,r.id),a=this._mutations.reserve(r.id,r),o;try{do await this._ensureThreadIsNotMain(r.id);while(r.id===this._mainThreadId);this._requireAdapterGeneration(n),await this._state.optimisticUpdate({execute:()=>a.run(async()=>({remoteId:o}=await r.initializeTask,this._requireAdapterGeneration(n),await t.delete(o))),optimistic:e=>this._isOtherAdaptersThread(e,t,r.id)?e:Fp(e,r.id,this._options.adapter===t?o:void 0)})}catch(e){a.cancel();let o=()=>{if(n===this._adapterGeneration)return;let e=Y(this._state.baseValue,r.id);e?.status===`new`&&e===i&&this._mainThreadId!==e.id?(this._state.update(Fp(this._state.baseValue,r.id,void 0)),this._hookManager.stopThreadRuntime(r.id),tm(this._titleStates,r.id)):this._replaceListOnNextLoad&&e!==void 0&&e.status!==`new`&&e.remoteId===void 0&&this._mainThreadId!==e.id&&!this._isOtherAdaptersThread(this._state.baseValue,t,r.id)&&(this._state.update(Np(this._state.baseValue,r.id,`deleted`)),this._hookManager.stopThreadRuntime(r.id),tm(this._titleStates,r.id))};n!==this._adapterGeneration&&this._replaceListOnNextLoad&&Y(this._state.baseValue,r.id)?.status===`new`?r.initializeTask.then(o,()=>{}):o();let s=this._options.threadId;throw this._switchGeneration===this._controlledSwitchGeneration&&s!==void 0&&this._mainThreadId!==r.id&&this.getItemById(s)?.id===r.id&&this._switchToThreadFromProp(s).catch(()=>{}),e}this._isOtherAdaptersThread(this._state.value,t,r.id)||(this._hookManager.stopThreadRuntime(r.id),tm(this._titleStates,r.id),await this._leaveRemovedMainThread(r.id))}__internal_dispose(){this._clearNewThreadIntent(),this._disposedSwitchGeneration=this._switchGeneration,this._nextSwitchGeneration(),this._destroyController.abort(new sp),this._disarmAutomaticTitles(),this._runningThreads.clear(),this._hookManager.__internal_dispose()}async detach(e){let t=this._adapterGeneration,n=this.getItemById(e);if(!n)throw im(e,`detaching it`);if(n.status!==`regular`&&n.status!==`archived`)throw am(e,n.status,`be detached`);do await this._ensureThreadIsNotMain(n.id);while(n.id===this._mainThreadId);this._requireAdapterGeneration(t),this._runningThreads.delete(n.id),this._hookManager.stopThreadRuntime(n.id)}boundIdsStore=new Za([]);__internal_RenderComponent=()=>{let e=en();W(()=>(this.boundIdsStore.setState([...this.boundIdsStore.getState(),e]),()=>{this.boundIdsStore.setState(this.boundIdsStore.getState().filter(t=>t!==e))}),[e]);let t=fl(this.boundIdsStore),n=fl(this.providerStore),r=K();return(t.length===0||t[0]===e)&&(0,J.jsxs)(Yd,{adapters:this._runtimeAdapters,children:[(0,J.jsx)(this._hookManager.__internal_RenderThreadRuntimes,{provider:n}),(0,J.jsx)(this._hookManager.__internal_Host,{parentClient:r})]})}},cm=(()=>{try{return process.env.NODE_ENV===`development`||process.env.NODE_ENV===`test`}catch{return!1}})(),lm=(e,t)=>function(){let n=en(),r=K();W(()=>(t.setState([...t.getState(),n]),()=>t.setState(t.getState().filter(e=>e!==n))),[n]);let i=fl(t);return i.length===0||i[0]===n?on(e.__internal_Host,{parentClient:r}):null},um=class{handle;hookManager;boundIdsStore=new Za([]);get aui(){return this.handle.getClient()}cachedItems;cachedItemMap;pendingItems=new Map;mainReport;constructor(e,t,n,r=!0){this.handle=t,this.hookManager=new pp(n,this,!0),this.__internal_RenderComponent=lm(this.hookManager,this.boundIdsStore),r&&this.hookManager.startThreadRuntime(`${bp}${e}`).catch(()=>{})}__internal_RenderComponent;__internal_ensureThread=async e=>{let t={item:e,source:this.state.threadItems};this.pendingItems.set(e.id,t);try{await this.hookManager.startThreadRuntime(e.id)}finally{this.pendingItems.get(e.id)===t&&this.pendingItems.delete(e.id)}};__internal_isThreadAttached=e=>this.hookManager.__internal_isThreadRuntimeAttached(e);__internal_dispose(){this.hookManager.__internal_dispose()}get state(){return this.aui.threads.getState()}get actions(){let e=this.aui.threads.__internal_getRawActions?.();if(!e)throw Error(`Remote thread list is not mounted.`);return e}get isLoading(){return this.state.isLoading}get canUnarchive(){return this.state.canUnarchive}get loadError(){return this.state.loadError}get switchError(){return this.state.switchError}get isLoadingMore(){return this.state.isLoadingMore}get hasMore(){return this.state.hasMore}get mainThreadId(){return this.state.mainThreadId}get newThreadId(){return this.state.newThreadId??void 0}get threadIds(){return this.state.threadIds}get archivedThreadIds(){return this.state.archivedThreadIds}get threadItems(){let e=this.state.threadItems;return(this.cachedItems?.length!==e.length||e.some((e,t)=>e!==this.cachedItems?.[t]))&&(this.cachedItems=[...e],this.cachedItemMap=Object.fromEntries(e.map(e=>[e.id,e]))),this.cachedItemMap}getMainThreadRuntimeCore(){return this.hookManager.getThreadRuntimeCore(this.mainThreadId)??vp}getThreadRuntimeCore(e){let t=this.getItemById(e);if(!t)throw Error(`Thread "${e}" not found while getting its runtime.`);return this.hookManager.getThreadRuntimeCore(t.id)??vp}unstable_isThreadRunning(e){let t=this.getItemById(e);return t?this.hookManager.__internal_isThreadRunning(t.id):!1}unstable_subscribeThreadEvents(e){return this.hookManager.__internal_subscribeThreadEvents(e)}getItemById(e){let t=this.state.threadItems,n=this.pendingItems.get(e);return t.find(t=>t.id===e||t.remoteId===e)??this.aui.threads.__internal_getThreadBody?.(e)?.__internal_getRuntime?.().getState().metadata??(n?.source===t?n.item:void 0)}switchToThread(e,t){return this.actions.switchToThread(e,t)}switchToNewThread(){return this.actions.switchToNewThread()}getLoadThreadsPromise(){return this.aui.threads.getLoadThreadsPromise()}reload(){return this.aui.threads.reload()}loadMore(){return this.aui.threads.loadMore()}detach(e){return this.actions.detach(e)}rename(e,t){return this.actions.rename(e,t)}async updateCustom(e,t){return this.aui.threads.item({id:e}).updateCustom(t)}archive(e){return this.actions.archive(e)}unarchive(e){return this.actions.unarchive(e)}delete(e){return this.actions.delete(e)}initialize(e){return this.actions.initialize(e)}generateTitle(e,t){let n=this.getItemById(e)?.id??e,r=this.hookManager.getThreadRuntimeCore(n)?.messages.filter(Rp);return this.actions.generateTitle(e,r,t)}__internal_announceMainRemoteId=e=>{let t=this.untilReported(()=>this.getItemById(this.mainThreadId)?.remoteId===e);this.mainReport=t,t.then(()=>{this.mainReport===t&&(this.mainReport=void 0)})};async reloadMainThread(){this.mainReport&&await this.mainReport;let e=this.mainThreadId;if(this.getItemById(e)?.status===`new`)return;let t=this.getMainThreadRuntimeCore();try{t.unstable_refetchThread?await t.unstable_refetchThread():await this.hookManager.__internal_restartThreadRuntime(e)}catch(t){if(e!==this.mainThreadId)return;throw t}}untilReported(e){return new Promise(t=>{let n=!1,r,i=()=>{n||(n=!0,clearTimeout(o),r?.(),t())},a=()=>{e()&&i()},o=setTimeout(i,100);r=this.handle.subscribe(a),n?r():a()})}subscribe(e){let t=this.handle.subscribe(e),n=this.hookManager.subscribe(e),r=this.hookManager.__internal_subscribeRunningChanged(e);return()=>{t(),n(),r()}}},dm=Promise.resolve(),fm=hr(e=>{let t=G(19),{data:n,isMain:r,isInitialMain:i,isRunning:a,onSwitchTo:o,onRename:s,onUpdateCustom:c,onArchive:l,onUnarchive:u,onDelete:d}=e,f;t[0]!==n.custom||t[1]!==n.id||t[2]!==n.status||t[3]!==n.title||t[4]!==a?(f={id:n.id,remoteId:void 0,externalId:void 0,title:n.title,status:n.status,custom:n.custom,isRunning:a},t[0]=n.custom,t[1]=n.id,t[2]=n.status,t[3]=n.title,t[4]=a,t[5]=f):f=t[5];let p=f;Tu(n.id,r,i);let m;t[6]===p?m=t[7]:(m=()=>p,t[6]=p,t[7]=m);let h;t[8]===n.id?h=t[9]:(h=async()=>({remoteId:n.id,externalId:void 0}),t[8]=n.id,t[9]=h);let g;return t[10]!==l||t[11]!==d||t[12]!==s||t[13]!==o||t[14]!==u||t[15]!==c||t[16]!==m||t[17]!==h?(g={getState:m,switchTo:o,rename:s,updateCustom:c,archive:l,unarchive:u,delete:d,generateTitle:vm,initialize:h,detach:ym},t[10]=l,t[11]=d,t[12]=s,t[13]=o,t[14]=u,t[15]=c,t[16]=m,t[17]=h,t[18]=g):g=t[18],g}),pm=()=>{let e=new Map,t,n,r=()=>{n?.(),n=void 0;for(let n of e.values())n.abort(t?.reason)};return{signalFor(t,n){let r=e.get(t);return r||(r=new AbortController,n?.aborted&&r.abort(n.reason),e.set(t,r)),r.signal},release(t){e.get(t)?.abort(),e.delete(t)},releaseAll(){for(let t of e.values())t.abort();e.clear()},bindOwner(e){t!==e&&(n?.(),n=void 0,t=e,e&&(e.aborted?r():(e.addEventListener(`abort`,r),n=()=>e.removeEventListener(`abort`,r))))}}},mm=hr(({destroySignal:e,thread:t})=>Ni(e,function(){return wi(t).methods})),hm=`main`,gm=e=>{let t=G(78),{thread:n,onSwitchToThread:r,onSwitchToNewThread:i,onDelete:a}=e,o=Pi(),[s]=H(pm),[c]=H(bm),l,u;t[0]!==s||t[1]!==o?(l=()=>{s.bindOwner(o)},u=[s,o],t[0]=s,t[1]=o,t[2]=l,t[3]=u):(l=t[2],u=t[3]),W(l,u);let[d,f]=H(xm),{threads:p,mainThreadId:m}=d,g;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(g=e=>f(t=>({...t,threads:e(t.threads)})),t[4]=g):g=t[4];let _=g;wu(m);let v;t[5]!==c||t[6]!==r?(v=e=>{c.has(e)&&(f(t=>({...t,mainThreadId:e})),r?.(e))},t[5]=c,t[6]=r,t[7]=v):v=t[7];let y=v,b;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(b=(e,t)=>{_(n=>n.map(n=>n.id===e?{...n,title:t}:n))},t[8]=b):b=t[8];let x=b,S;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(S=e=>{_(t=>t.map(t=>t.id===e?{...t,status:`archived`}:t))},t[9]=S):S=t[9];let C=S,w;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(w=e=>{_(t=>t.map(t=>t.id===e?{...t,status:`regular`}:t))},t[10]=w):w=t[10];let T=w,E;t[11]===Symbol.for(`react.memo_cache_sentinel`)?(E=(e,t)=>{_(n=>n.map(n=>n.id===e?{...n,custom:t}:n))},t[11]=E):E=t[11];let D=E,O;t[12]!==c||t[13]!==s||t[14]!==a?(O=e=>{s.release(e);let t=`thread-${h()}`;c.delete(e),c.size===0&&c.add(t),f(n=>{let r=n.threads.filter(t=>t.id!==e);return r.length===0?{threads:[{id:t,title:`New Thread`,status:`regular`}],mainThreadId:t}:{threads:r,mainThreadId:n.mainThreadId===e?(r.find(Sm)??r[0]).id:n.mainThreadId}}),a?.(e)},t[12]=c,t[13]=s,t[14]=a,t[15]=O):O=t[15];let k=O,A;t[16]!==c||t[17]!==i?(A=()=>{let e=`thread-${h()}`;c.add(e),f(t=>({threads:[...t.threads,{id:e,title:`New Thread`,status:`regular`}],mainThreadId:e})),i?.()},t[16]=c,t[17]=i,t[18]=A):A=t[18];let j=A,M;t[19]!==s||t[20]!==m||t[21]!==o||t[22]!==n?(M=gr(m,mm({destroySignal:s.signalFor(m,o),thread:n(m)})),t[19]=s,t[20]=m,t[21]=o,t[22]=n,t[23]=M):M=t[23];let N=wi(M),P;if(t[24]!==k||t[25]!==y||t[26]!==N.state||t[27]!==m||t[28]!==p){let e;t[30]!==k||t[31]!==y||t[32]!==N.state||t[33]!==m?(e=e=>gr(e.id,fm({data:e,isMain:e.id===m,isInitialMain:e.id===hm,isRunning:e.id===m&&N.state.isRunning,onSwitchTo:()=>y(e.id),onRename:t=>x(e.id,t),onUpdateCustom:t=>D(e.id,t),onArchive:()=>C(e.id),onUnarchive:()=>T(e.id),onDelete:()=>k(e.id)})),t[30]=k,t[31]=y,t[32]=N.state,t[33]=m,t[34]=e):e=t[34],P=p.map(e),t[24]=k,t[25]=y,t[26]=N.state,t[27]=m,t[28]=p,t[29]=P}else P=t[29];let F=Ea(P),I,L,R,z,ee,te,ne,B,re,ie;if(t[35]!==m||t[36]!==p){let e=p.filter(Cm),n=p.filter(wm);I=m,L=null,R=!1,z=!0,ee=void 0,te=void 0,ne=!1,B=!1,re=e.map(Tm),ie=n.map(Em),t[35]=m,t[36]=p,t[37]=I,t[38]=L,t[39]=R,t[40]=z,t[41]=ee,t[42]=te,t[43]=ne,t[44]=B,t[45]=re,t[46]=ie}else I=t[37],L=t[38],R=t[39],z=t[40],ee=t[41],te=t[42],ne=t[43],B=t[44],re=t[45],ie=t[46];let V;t[47]!==N.state||t[48]!==I||t[49]!==L||t[50]!==R||t[51]!==z||t[52]!==ee||t[53]!==te||t[54]!==ne||t[55]!==B||t[56]!==re||t[57]!==ie||t[58]!==F.state?(V={mainThreadId:I,newThreadId:L,isLoading:R,canUnarchive:z,loadError:ee,switchError:te,isLoadingMore:ne,hasMore:B,threadIds:re,archivedThreadIds:ie,threadItems:F.state,main:N.state},t[47]=N.state,t[48]=I,t[49]=L,t[50]=R,t[51]=z,t[52]=ee,t[53]=te,t[54]=ne,t[55]=B,t[56]=re,t[57]=ie,t[58]=F.state,t[59]=V):V=t[59];let ae=V,oe;t[60]===ae?oe=t[61]:(oe=()=>ae,t[60]=ae,t[61]=oe);let se;t[62]===N.methods?se=t[63]:(se=()=>N.methods.unstable_refetchThread?.()??dm,t[62]=N.methods,t[63]=se);let ce;t[64]!==m||t[65]!==ae||t[66]!==F||t[67]!==p?(ce=e=>{if(e===`main`){let e=p.findIndex(e=>e.id===m);return F.get({index:e})}if(`id`in e){let t=p.findIndex(t=>t.id===e.id);return F.get({index:t})}let t=(e.archived?ae.archivedThreadIds:ae.threadIds)[e.index];if(t===void 0)return F.get({index:-1});let n=p.findIndex(e=>e.id===t);return F.get({index:n})},t[64]=m,t[65]=ae,t[66]=F,t[67]=p,t[68]=ce):ce=t[68];let le;t[69]===N.methods?le=t[70]:(le=()=>N.methods,t[69]=N.methods,t[70]=le);let ue;return t[71]!==j||t[72]!==y||t[73]!==oe||t[74]!==se||t[75]!==ce||t[76]!==le?(ue={getState:oe,switchToThread:y,switchToNewThread:j,getLoadThreadsPromise:Dm,reload:Om,reloadMainThread:se,loadMore:km,item:ce,thread:le},t[71]=j,t[72]=y,t[73]=oe,t[74]=se,t[75]=ce,t[76]=le,t[77]=ue):ue=t[77],ue},_m=(e,t)=>{e.thread??=_a({source:`threads`,query:{type:`main`},get:e=>e.threads.thread(`main`)}),e.threadListItem??=_a({source:`threads`,query:{type:`main`},get:e=>e.threads.item(`main`)}),e.composer??=_a({source:`thread`,query:{},get:e=>e.threads.thread(`main`).composer()}),!e.modelContext&&t.modelContext.source===null&&(e.modelContext=il()),!e.tools&&t.tools.source===null&&(e.tools=ll({})),!e.dataRenderers&&t.dataRenderers.source===null&&(e.dataRenderers=Gc()),!e.suggestions&&t.suggestions.source===null&&(e.suggestions=_a({source:`thread`,query:{},get:e=>e.thread.suggestions()}))};zr(gm,_m);function vm(){}function ym(){}function bm(){return new Set([hm])}function xm(){return{threads:[{id:hm,title:`Main Thread`,status:`regular`}],mainThreadId:hm}}function Sm(e){return e.status===`regular`}function Cm(e){return e.status===`regular`}function wm(e){return e.status===`archived`}function Tm(e){return e.id}function Em(e){return e.id}function Dm(){return dm}function Om(){return dm}function km(){return dm}var Am=hr(({useAdapters:e,thread:t})=>{let n=Xu(),r=Qu(e()),i=r?.history!=null&&t.key===void 0;return W(()=>{cm&&i&&console.warn(`[assistant-ui] RemoteThreadList received a history adapter, but the thread factory is unkeyed. Key the thread resource by thread id (withKey) so switching threads reloads history.`)},[i]),Yu(qt(()=>r==null?n:{...n,...r},[n,r]),function(){return wi(t).methods})}),jm=Promise.resolve(),Mm=wp(),Nm=(e,t)=>Error(`Thread "${e}" was not found while ${t}.`),Pm=(e,t,n)=>Error(`Thread "${e}" has status "${t}", so it cannot ${n}.`),Fm=e=>({remoteId:e.remoteId,externalId:e.externalId}),Im=hr(e=>{let t=G(22),{data:n,isMain:r,isInitialMain:i,isRunning:a,onSwitchTo:o,onRename:s,onUpdateCustom:c,onArchive:l,onUnarchive:u,onDelete:d,onGenerateTitle:f,onInitialize:p,onDetach:m}=e,h=`lastMessageAt`in n?n.lastMessageAt:void 0,g;t[0]!==n.custom||t[1]!==n.externalId||t[2]!==n.id||t[3]!==n.remoteId||t[4]!==n.status||t[5]!==n.title||t[6]!==a||t[7]!==h?(g={id:n.id,remoteId:n.remoteId,externalId:n.externalId,title:n.title,lastMessageAt:h,status:n.status,custom:n.custom,isRunning:a},t[0]=n.custom,t[1]=n.externalId,t[2]=n.id,t[3]=n.remoteId,t[4]=n.status,t[5]=n.title,t[6]=a,t[7]=h,t[8]=g):g=t[8];let _=g;Tu(n.id,r,i);let v;t[9]===_?v=t[10]:(v=()=>_,t[9]=_,t[10]=v);let y;return t[11]!==l||t[12]!==d||t[13]!==m||t[14]!==f||t[15]!==p||t[16]!==s||t[17]!==o||t[18]!==u||t[19]!==c||t[20]!==v?(y={getState:v,switchTo:o,rename:s,updateCustom:c,archive:l,unarchive:u,delete:d,generateTitle:f,initialize:p,detach:m},t[11]=l,t[12]=d,t[13]=m,t[14]=f,t[15]=p,t[16]=s,t[17]=o,t[18]=u,t[19]=c,t[20]=v,t[21]=y):y=t[21],y}),Lm=(e,t)=>{let n=[e.newThreadId,...e.threadIds,...e.archivedThreadIds,t].filter(e=>e!==void 0),r=new Set,i=new Set,a=[];for(let t of n){let n=Y(e,t);n&&!r.has(n.id)&&(n.remoteId!==void 0&&i.has(n.remoteId)||(r.add(n.id),n.remoteId!==void 0&&i.add(n.remoteId),a.push(n)))}return a},Rm=(e,t,n)=>{let r=Y(e,n);if(r!==void 0)return[e.newThreadId,...e.threadIds,...e.archivedThreadIds,t].some(t=>t!==void 0&&Y(e,t)?.id===r.id)?r:void 0},zm=(e,t,n)=>{let r=Y(t,n);return e.id===n||e.id===r?.id||r?.remoteId!==void 0&&(e.id===r.remoteId||e.remoteId===r.remoteId)},Bm=(e,t,n)=>{if(t===n)return!0;let r=Y(e,t);return r!==void 0&&zm(r,e,n)},Vm=hr(({id:e,remoteId:t,item:n,thread:r,onAutomaticTitle:i})=>{let a=Ir(),[o,s]=H(!1),c=wi(n(o)),{client:l}=pa(a,{threadListItem:_a({source:`threads`,query:{type:`id`,id:e},get:()=>c.methods})});return Lr(l,function(){let n=wi(r),a=n.state.isRunning===!0,o=U(!1);W(()=>{s(a)},[a]);let c=n.state.messages;return W(()=>{i(e,c,t!==void 0,n.state.isLoading,o.current&&!a),o.current=a}),n.methods})}),Hm=e=>Ci(e),Um=e=>{let t=G(32),{listState:n,mainThreadId:r,initialMainId:i,startedIds:a,pendingAutomaticTitles:o,backgroundThreads:s,lifetimes:c,ownerDestroySignal:l,threadFactory:u,useAdapters:d,onSwitchTo:f,onRename:p,onUpdateCustom:m,onArchive:h,onUnarchive:g,onDelete:_,onGenerateTitle:v,onInitialize:y,onDetach:b}=e,x;bb0:{if(!s){let e;t[0]===r?e=t[1]:(e=[r],t[0]=r,t[1]=e),x=e;break bb0}let e;if(t[2]!==n||t[3]!==a){let r=new Set,i=new Set;e=[];for(let t of a){let a=Y(n,t);a&&!r.has(a.id)&&(a.remoteId!==void 0&&i.has(a.remoteId)||(r.add(a.id),a.remoteId!==void 0&&i.add(a.remoteId),e.push(a.id)))}t[2]=n,t[3]=a,t[4]=e}else e=t[4];x=e}let S=x,C;t[5]!==s||t[6]!==n||t[7]!==v||t[8]!==o?(C=(e,t,r,i,a)=>{let c=o.get(e);if(c===void 0&&!(s&&a))return;let l=t.filter(Rp),u=(t,n)=>{v(e,t,{automatic:!0},n!==void 0&&n).catch(Km)};if(c!==void 0){l.length>0&&o.set(e,l);let t=l.length>0?l:c;r&&!i&&t.length>0&&(o.delete(e),u(t))}let d=Y(n,e);s&&a&&d&&d.status!==`new`&&u(l,!0)},t[5]=s,t[6]=n,t[7]=v,t[8]=o,t[9]=C):C=t[9];let w=C,T=(e,t,a)=>Im({data:e,isMain:a&&zm(e,n,r),isInitialMain:e.id===i,isRunning:t,onSwitchTo:t=>Eu(`switch`,()=>f(e.id,t)),onRename:t=>Eu(`rename`,()=>p(e.id,t)),onUpdateCustom:t=>Eu(`update custom metadata`,()=>m(e.id,t)),onArchive:()=>Eu(`archive`,()=>h(e.id)),onUnarchive:()=>Eu(`unarchive`,()=>g(e.id)),onDelete:()=>Eu(`delete`,()=>_(e.id)),onGenerateTitle:t=>Eu(`generate title`,()=>v(e.id,s?k(e.id)?.messages:F.state.messages,t)),onInitialize:()=>y(e.id),onDetach:()=>Eu(`detach`,()=>b(e.id))}),E=Ea(S.map(e=>{let t=u(e),r=s&&t.key===void 0?gr(e,t):t,i=d===void 0?r:Am({useAdapters:d,thread:r}),a=Y(n,e),o=s&&a!==void 0?Vm({id:e,remoteId:a.remoteId,item:e=>T(a,e,!1),thread:i,onAutomaticTitle:w}):i;return gr(s?e:t.key??`main`,mm({destroySignal:c.signalFor(e,l),thread:o}))})),D;t[10]!==S||t[11]!==n?(D=e=>{let t=S.indexOf(e);return t===-1?S.findIndex(t=>Bm(n,t,e)):t},t[10]=S,t[11]=n,t[12]=D):D=t[12];let O=D,k=e=>{let t=O(e);return t===-1?void 0:E.state[t]},A;t[13]!==s||t[14]!==E||t[15]!==O||t[16]!==r?(A=e=>{if(!s&&e!==r)return;let t=O(e);return t===-1?void 0:E.get({index:t})},t[13]=s,t[14]=E,t[15]=O,t[16]=r,t[17]=A):A=t[17];let j=A,M,N,P;if(t[18]!==E||t[19]!==O||t[20]!==r){let e=O(r);P=E.state[e],M=Hm,N=E.get({index:e}),t[18]=E,t[19]=O,t[20]=r,t[21]=M,t[22]=N,t[23]=P}else M=t[21],N=t[22],P=t[23];let F={state:P,methods:M(N)},I;t[24]!==n||t[25]!==r?(I=Lm(n,r),t[24]=n,t[25]=r,t[26]=I):I=t[26];let L=I,R=Ea(L.map(e=>gr(e.id,T(e,s?k(e.id)?.isRunning??!1:zm(e,n,r)&&F.state.isRunning,!0)))),z;return t[27]!==j||t[28]!==L||t[29]!==F||t[30]!==R?(z={mainThreadClient:F,itemOrder:L,threadListItems:R,bodyMethodsOf:j},t[27]=j,t[28]=L,t[29]=F,t[30]=R,t[31]=z):z=t[31],z},Wm=e=>{let{adapter:t,thread:n,threadId:r,onThreadIdChange:i,onSwitchToThread:a,onSwitchToNewThread:o,onDelete:s,__internal_ensureThread:c,__internal_isThreadAttached:l,__internal_preserveDraftOnAdapterChange:u,__internal_reopenControlledThreadOnAdapterChange:d}=e,f=Pi(),p=$r(),[m]=H(pm);W(()=>{m.bindOwner(f)},[m,f]);let h=en(),g=Jc(),[{store:_,initialMainId:v,session:y}]=H(()=>{let n=Ep(Mm,e.__internal_initialThreadIdSeed??(g?h:void 0));return{store:new gp(n.state),initialMainId:n.id,session:{adapter:t,adapterAtLoad:t,adapterGeneration:0,titleStates:new Map,mutations:new Ip,pendingAutomaticTitles:new Map,loadGeneration:0,switchGeneration:0,startedIds:new Set([n.id]),pendingEnsures:new Map,loadPromise:void 0,loadMorePromise:void 0,lastNotifiedRemoteId:void 0,lastControlledThreadId:void 0,controlledSwitchGeneration:void 0,controlledSwitchAdapter:void 0,controlledReloadPending:!1,replaceListPending:!1,switchTask:void 0,pendingSwitchGeneration:void 0,settleSwitch:void 0,newThreadIntent:void 0,supersedeAttachmentWait:void 0,mainThreadId:n.id,isFirstThreadIdEffect:!0,onThreadIdChange:i,onSwitchToThread:a,onSwitchToNewThread:o}}}),b=Zt(e=>_.subscribe(e),()=>_.value,()=>_.value),x=Ou(b,Jt(()=>_.value,[_])),[S,C]=H(v),[w,T]=H([v]),[E]=H(e.backgroundThreads===!0),[D,O]=H(0),k=Jt(e=>{y.mainThreadId=e,y.startedIds.add(e);let t=y.pendingEnsures.get(e);t&&(t.wasStarted=!0),C(e),T(t=>t.includes(e)?t:[...t,e])},[y]);wu(S),W(()=>{y.adapter=t,y.mainThreadId=S,y.onThreadIdChange=i,y.onSwitchToThread=a,y.onSwitchToNewThread=o},[t,S,o,a,i,y]);let A=Jt((e,t)=>{if(e!==void 0&&y.newThreadIntent?.generation===y.switchGeneration&&y.newThreadIntent.id===y.mainThreadId)return;let n=Y(_.value,y.mainThreadId);e===void 0&&n&&n.status!==`new`||y.lastNotifiedRemoteId!==e&&(y.lastNotifiedRemoteId=e,t&&mp(`assistant-ui`,`onThreadIdChange`,y.onThreadIdChange,e))},[y,_]);W(()=>_.subscribe(()=>{let e=Y(_.value,y.mainThreadId);e&&A(e.remoteId,!0)}),[A,y,_]);let j=Jt(()=>{if(y.loadPromise)return y.loadPromise;let e=y.replaceListPending,t=y.loadGeneration,n=y.adapter,r=Op(_.baseValue),i=(t,n)=>{if(!e)return kp(t,n,r);let i=new Map(n.threads.map(e=>[e.remoteId,e])),a=t;for(let[e,t]of r){if(t===`new`)continue;let n=Y(a,e);if(!n||n.status===`new`)continue;let r=n.remoteId===void 0?void 0:i.get(n.remoteId);a=r?{...a,threadData:{...a.threadData,[n.id]:{...n,initializeTask:Promise.resolve({remoteId:r.remoteId,externalId:r.externalId})}}}:Fp(a,e,n.remoteId)}if(a=kp(a,n,r),!Y(a,y.mainThreadId)){let e=a.newThreadId;if(e===void 0){let t=Ep(a);e=t.id,a=t.state}k(e),A(void 0,y.lastControlledThreadId===void 0&&y.controlledSwitchGeneration!==y.switchGeneration)}for(let e of y.startedIds)Y(a,e)||(y.startedIds.delete(e),m.release(e));return T([...y.startedIds]),a};return y.loadPromise=_.optimisticUpdate({execute:()=>n.list(),loading:e=>t===y.loadGeneration?{...e,isLoading:!0,loadError:void 0}:e,then:(e,r)=>t===y.loadGeneration?(y.adapterAtLoad=n,y.replaceListPending=!1,i(e,r)):e}).catch(n=>{t===y.loadGeneration&&(console.error(`[assistant-ui] thread list load failed:`,n),y.loadPromise=void 0,y.replaceListPending=!1,_.update({...e?i(_.baseValue,{threads:[]}):_.baseValue,isLoading:!1,loadError:n}))}).then(()=>O(e=>e+1)),y.loadPromise},[k,m,A,y,_]),M=Jt(()=>{let e=t!==y.adapterAtLoad;if(y.loadGeneration++,y.loadPromise=void 0,y.loadMorePromise=void 0,e){let e=u?_.baseValue.newThreadId:void 0,n=e===void 0?void 0:Y(_.baseValue,e),r=n?.status===`new`?n:void 0;y.adapterGeneration++,y.mutations=new Ip,y.titleStates.clear(),y.pendingAutomaticTitles.clear();let i=y.lastControlledThreadId!==void 0&&(d||y.controlledSwitchAdapter===t)&&y.controlledSwitchGeneration===y.switchGeneration;if(y.supersedeAttachmentWait?.(),y.switchGeneration++,y.settleSwitch?.(),y.controlledReloadPending=i,i&&(y.controlledSwitchGeneration=y.switchGeneration),y.switchTask=void 0,y.pendingSwitchGeneration=void 0,y.pendingEnsures.clear(),y.adapterAtLoad=t,c)return _.reset({..._.baseValue,cursor:void 0,isLoading:!0,loadError:void 0}),y.replaceListPending=!0,j();if(r)for(let e of y.startedIds)e!==r.id&&m.release(e);else m.releaseAll();let a=r?{id:r.id,state:Tp(Mm,r)}:Ep(Mm);_.reset({...a.state,isLoading:!0}),y.startedIds=new Set([a.id]),k(a.id),T([a.id]),A(void 0,!i)}else _.update({..._.baseValue,cursor:void 0});return j()},[t,k,c,j,m,A,u,d,y,_]);W(()=>{j()},[j]),W(()=>{c&&t!==y.adapterAtLoad&&M()},[t,c,M,y]);let N=t.unstable_useAdapters===void 0&&t.unstable_Provider!==void 0,P=U(!1);W(()=>{N?cm&&!P.current&&(P.current=!0,console.warn(c?`[assistant-ui] useRemoteThreadListRuntime mounted with an adapter without unstable_Provider, so it ignores RemoteThreadListAdapter.unstable_Provider on this adapter. Expose unstable_useAdapters so per-thread history loads.`:`[assistant-ui] RemoteThreadList ignores RemoteThreadListAdapter.unstable_Provider. Expose unstable_useAdapters so per-thread history loads on this entry. useRemoteThreadListRuntime renders unstable_Provider only when the adapter it mounts with has one.`)):P.current=!1},[N,c]);let F=Jt(()=>{if(y.loadMorePromise)return y.loadMorePromise;let e=_.value;if(e.cursor===void 0||e.isLoading)return jm;let t=y.loadGeneration,n=e.cursor,r=y.adapter,i=_.optimisticUpdate({execute:()=>r.list({after:n}),loading:e=>t===y.loadGeneration?{...e,isLoadingMore:!0}:e,then:(e,n)=>t===y.loadGeneration?Ap(e,n):e}).catch(e=>{t===y.loadGeneration&&console.error(`[assistant-ui] thread list loadMore failed:`,e)}).then(()=>{y.loadMorePromise===i&&(y.loadMorePromise=void 0),O(e=>e+1)});return y.loadMorePromise=i,i},[y,_]),I=Jt((e,t)=>{if(f?.aborted)return Promise.reject(new sp);if(y.supersedeAttachmentWait&&y.switchTask&&t!==void 0&&Bm(_.value,t,y.mainThreadId))return y.switchTask;y.supersedeAttachmentWait?.(),y.supersedeAttachmentWait=void 0,y.newThreadIntent?.unsubscribe(),y.newThreadIntent=void 0;let n=++y.switchGeneration;y.settleSwitch?.(),y.controlledReloadPending=!1,_.baseValue.switchError!==void 0&&_.update({..._.baseValue,switchError:void 0});let r,i,a=new Promise((e,t)=>{r=e,i=t});y.switchTask=a,y.pendingSwitchGeneration=n;let o,s=()=>{o?.(),y.newThreadIntent?.generation===n&&(y.newThreadIntent.unsubscribe(),y.newThreadIntent=void 0),f?.removeEventListener(`abort`,l),y.pendingSwitchGeneration===n&&(y.pendingSwitchGeneration=void 0,y.settleSwitch=void 0),r()},l=()=>{n===y.switchGeneration?(o?.(),y.switchGeneration++,y.pendingSwitchGeneration=void 0,y.settleSwitch=void 0,y.supersedeAttachmentWait?.(),y.supersedeAttachmentWait=void 0,i(new sp)):s()};return f?.addEventListener(`abort`,l,{once:!0}),c&&(y.settleSwitch=s),e(n).then(()=>{if(!c||n!==y.switchGeneration||f?.aborted){s();return}let e=()=>{p.current.threads.getState().mainThreadId===y.mainThreadId&&s()};o=p.current.subscribe(e),e()},e=>{y.newThreadIntent?.generation===n&&(y.newThreadIntent.unsubscribe(),y.newThreadIntent=void 0),f?.removeEventListener(`abort`,l),y.pendingSwitchGeneration===n&&(y.pendingSwitchGeneration=void 0,y.settleSwitch=void 0),t!==void 0&&n===y.switchGeneration&&!ml(e)&&!Bm(_.value,t,y.mainThreadId)&&_.update({..._.baseValue,switchError:{threadId:t,error:e}}),i(e)}),a},[p,c,f,y,_]),L=Jt(async(e,t,n,r,i=!1)=>{let a=Y(_.value,e);if(!a){let t=y.adapter;if(await _.optimisticUpdate({execute:()=>t.fetch(e),then:(e,t)=>r===y.switchGeneration?Cp(e,t):e}),r!==y.switchGeneration)return;a=Y(_.value,e)}if(!a)throw Nm(e,`switching to it`);if(Bm(_.value,a.id,y.mainThreadId)){i&&await c?.(a);return}let o=a.id,s=c?y.pendingEnsures.get(o)??{wasStarted:y.startedIds.has(o),count:0}:void 0;s&&(y.pendingEnsures.set(o,s),s.count++,y.startedIds.add(o),T(e=>e.includes(o)?e:[...e,o]));try{if(c&&(await c(a),r!==y.switchGeneration))return;let e=Y(_.value,o);if(e?.id!==o)return;if(e.status===`archived`&&t?.unarchive!==!1&&y.adapter.unarchive){let{remoteId:t}=await e.initializeTask;if(r!==y.switchGeneration||(e=Y(_.value,o),e?.id!==o))return;if(e.status===`archived`){let n=y.mutations.reserve(o),i=y.adapter,a=y.adapterGeneration;if(await _.optimisticUpdate({execute:()=>n.run(async()=>{if(ne(a),!i.unarchive)throw Error(`Remote thread list adapter does not support unarchiving`);return i.unarchive(t)}),optimistic:e=>Np(e,o,`regular`)}),r!==y.switchGeneration||(e=Y(_.value,o),e?.id!==o))return}}if(r!==y.switchGeneration||i&&e.status!==`new`)return;for(k(e.id);c&&l?.(e.id)===!1;){let t,n=new Promise(e=>{t=e});y.supersedeAttachmentWait=t;try{await Promise.race([c(e),n])}finally{y.supersedeAttachmentWait===t&&(y.supersedeAttachmentWait=void 0)}if(r!==y.switchGeneration)return}A(e.remoteId,n),i?y.onSwitchToNewThread?.():y.onSwitchToThread?.(e.id)}finally{s&&(s.count--,y.pendingEnsures.get(o)===s&&s.count===0&&(y.pendingEnsures.delete(o),!s.wasStarted&&!Bm(_.value,o,y.mainThreadId)&&(y.startedIds.delete(o),T(e=>e.filter(e=>e!==o)),m.release(o))))}},[k,c,l,m,A,y,_]),R=Jt((e,t,n=!0)=>n&&y.controlledSwitchGeneration===y.switchGeneration&&y.pendingSwitchGeneration===y.switchGeneration&&y.supersedeAttachmentWait===void 0&&Bm(_.value,e,y.mainThreadId)?jm:I(r=>L(e,t,n,r),e),[L,y,I,_]),z=Jt((e=!0,t=!1)=>{let n=async r=>{for(t&&_.baseValue.newThreadId===y.mainThreadId&&(y.newThreadIntent={id:y.mainThreadId,generation:r,unsubscribe:()=>{}});r===y.switchGeneration;){for(;_.baseValue.newThreadId!==void 0&&_.value.newThreadId===void 0;)if(await _.waitForUpdate(),r!==y.switchGeneration)return;let i=_.value.newThreadId;if(i===void 0){let e=Ep(_.baseValue);_.update(e.state),i=e.id}let a=Y(_.value,i)?.id??i;if(Bm(_.value,a,y.mainThreadId)){if(t){let e=_.subscribe(()=>{r===y.switchGeneration?Y(_.value,a)?.status!==`new`&&(e(),queueMicrotask(()=>{r===y.switchGeneration&&Eu(`create`,()=>{let e=I(n);return y.controlledSwitchGeneration=y.switchGeneration,y.controlledSwitchAdapter=y.adapter,e})})):e()});y.newThreadIntent={id:a,generation:r,unsubscribe:e}}return L(a,void 0,e,r,!0)}if(await L(a,void 0,e,r,!0),r!==y.switchGeneration||Y(_.value,a)?.status===`new`)return}};return I(n)},[L,y,I,_]);W(()=>{if(typeof window>`u`||typeof document>`u`)return;let e=()=>{_.value.loadError!==void 0&&j();let e=_.value.switchError;e!==void 0&&e.threadId===r&&Eu(`switch`,()=>{let e=R(r,void 0,!1);return y.controlledSwitchGeneration=y.switchGeneration,y.controlledSwitchAdapter=y.adapter,e})},t=()=>{document.visibilityState===`visible`&&e()};return window.addEventListener(`online`,e),document.addEventListener(`visibilitychange`,t),()=>{window.removeEventListener(`online`,e),document.removeEventListener(`visibilitychange`,t)}},[j,y,_,R,r]);let ee=Jt(async e=>{if(e===_.value.newThreadId)throw Error(`Cannot ensure new thread is not main`);let t;for(;Bm(_.value,e,y.mainThreadId);){if(e===_.value.newThreadId)throw Error(`Cannot ensure new thread is not main`);let n=y.switchTask,r=!n||n===t;r&&(n=z()),t=n;try{await n}catch(e){if(r&&y.switchTask===n)throw e}}},[y,_,z]),te=Jt(async e=>{let t=Y(_.value,y.mainThreadId);if(t!==void 0&&(t.status!==`archived`||!Bm(_.value,e,y.mainThreadId)))return;let n=_.baseValue.newThreadId!==void 0&&_.value.newThreadId===void 0;if(t===void 0&&!n){let e=_.value.newThreadId,t;if(e!==void 0)t=Y(_.value,e)?.id??e;else{let e=Ep(_.baseValue);_.update(e.state),t=e.id}k(t),A(void 0,!0),y.onSwitchToNewThread?.()}else await ee(y.mainThreadId)},[k,ee,A,y,_]),ne=Jt(e=>{if(e!==y.adapterGeneration)throw new Lp},[y]),B=Jt(async e=>{let t=y.adapter,n=y.adapterGeneration;if(_.value.newThreadId!==e){let t=Y(_.value,e);if(!t)throw Nm(e,`initializing it`);if(t.status===`new`)throw Pm(e,t.status,`be initialized here`);let r=Fm(await t.initializeTask);return ne(n),r}ne(n);let r=Y(_.value,e)?.custom,i=r===void 0?t.initialize(e):t.initialize(e,{custom:r});E&&y.pendingAutomaticTitles.set(e,[]);let a,o,s=_.optimisticUpdate({execute:()=>i,optimistic:t=>Pp(t,e,i),then:(t,{remoteId:r,externalId:i})=>{if(n!==y.adapterGeneration)return t;let s=jp(t,e,r,i,E?e:y.mainThreadId);return a=s.removedMappingId,a!==void 0&&y.mutations.merge(s.survivorMappingId,a),a===y.mainThreadId&&(o=s.survivorMappingId),s.state}}),c;try{c=await s}catch(t){throw y.pendingAutomaticTitles.delete(e),t}return ne(n),a!==void 0&&(y.startedIds.delete(a),T(e=>e.filter(e=>e!==a))),o!==void 0&&y.mainThreadId===a&&k(o),e===y.mainThreadId&&A(c.remoteId,!0),te(e).catch(()=>{}),Fm(c)},[k,E,te,A,ne,y,_]),re=Jt(async(e,t)=>{let n=y.adapter,r=y.adapterGeneration,i=Rm(_.value,y.mainThreadId,e);if(!i)throw Nm(e,`renaming it`);if(i.status===`new`)throw Pm(e,i.status,`be renamed`);let a=Xp(y.titleStates,i.id,t),o=y.mutations.reserve(i.id,i);return _.optimisticUpdate({execute:()=>o.run(async()=>{let{remoteId:e}=await i.initializeTask;return ne(r),n.rename(e,t)}),optimistic:n=>{let r=Y(n,e);return r?{...n,threadData:{...n.threadData,[r.id]:{...r,title:t}}}:n}}).then(e=>(Zp(y.titleStates,i.id,a,!0),e),e=>{throw Zp(y.titleStates,i.id,a,!1),e})},[ne,y,_]),ie=Jt(async(e,t)=>{let n=y.adapter,r=y.adapterGeneration,i=Rm(_.value,y.mainThreadId,e);if(!i)throw Nm(e,`updating its custom metadata`);let a=n=>{let r=Y(n,e);return r?{...n,threadData:{...n.threadData,[r.id]:{...r,custom:t}}}:n};if(i.status===`new`){_.update(a(_.baseValue));return}if(!n.updateCustom)throw Error(`Remote thread list adapter does not support updating custom metadata`);let o=y.mutations.reserve(i.id,i);return _.optimisticUpdate({execute:()=>o.run(async()=>{let{remoteId:e}=await i.initializeTask;if(ne(r),!n.updateCustom)throw Error(`Remote thread list adapter does not support updating custom metadata`);return n.updateCustom(e,t)}),optimistic:a})},[ne,y,_]),V=Jt(async e=>{let t=y.adapter,n=y.adapterGeneration,r=Rm(_.value,y.mainThreadId,e);if(!r)throw Nm(e,`archiving it`);if(r.status!==`regular`)throw Pm(e,r.status,`be archived`);let i=y.mutations.reserve(r.id,r);try{do await ee(r.id);while(Bm(_.value,r.id,y.mainThreadId));ne(n),await _.optimisticUpdate({execute:()=>i.run(async()=>{let{remoteId:e}=await r.initializeTask;return ne(n),t.archive(e)}),optimistic:e=>Np(e,r.id,`archived`)})}finally{i.cancel()}await te(r.id)},[ee,te,ne,y,_]),ae=Jt(async e=>{let t=y.adapter,n=y.adapterGeneration,r=Rm(_.value,y.mainThreadId,e);if(!r)throw Nm(e,`unarchiving it`);if(r.status!==`archived`)throw Pm(e,r.status,`be unarchived`);if(!t.unarchive)throw Error(`Remote thread list adapter does not support unarchiving`);let i=y.mutations.reserve(r.id,r);return _.optimisticUpdate({execute:()=>i.run(async()=>{try{let{remoteId:e}=await r.initializeTask;if(ne(n),!t.unarchive)throw Error(`Remote thread list adapter does not support unarchiving`);return await t.unarchive(e)}catch(e){throw n===y.adapterGeneration&&await ee(r.id),e}}),optimistic:e=>Np(e,r.id,`regular`)})},[ee,ne,y,_]),oe=Jt(async e=>{let t=y.adapter,n=y.adapterGeneration,r=Rm(_.value,y.mainThreadId,e);if(!r)throw Nm(e,`deleting it`);if(r.status!==`regular`&&r.status!==`archived`)throw Pm(e,r.status,`be deleted`);let i=y.mutations.reserve(r.id,r),a,o;try{do await ee(r.id);while(Bm(_.value,r.id,y.mainThreadId));ne(n),o=await _.optimisticUpdate({execute:()=>i.run(async()=>({remoteId:a}=await r.initializeTask,ne(n),t.delete(a))),optimistic:e=>Fp(e,r.id,a)})}finally{i.cancel()}return await te(r.id),Y(_.value,r.id)===void 0&&(m.release(r.id),tm(y.titleStates,r.id),y.pendingAutomaticTitles.delete(r.id),s?.(r.id)),o},[ee,te,m,s,ne,y,_]),se=Jt(async(e,t,n,r=!1)=>{let i=y.adapter,a=y.adapterGeneration,o=Y(_.value,e);if(!o)throw Nm(e,`generating its title`);if(o.status===`new`)throw Pm(e,o.status,`generate a title`);let{remoteId:s}=await o.initializeTask;if(ne(a),!E&&!Bm(_.value,o.id,y.mainThreadId)||!t)return;let c=()=>Y(_.baseValue,o.id)===void 0;await rm({states:y.titleStates,threadId:o.id,automatic:n?.automatic===!0,messages:t,generate:async e=>{if(c())return;let n=await i.generateTitle(s,t);ne(a),await zp(n,e)},rename:async e=>{await y.mutations.reserve(o.id,o).run(async()=>{ne(a),c()||await i.rename(s,e)})},readTitle:async()=>{if(ne(a),c())return;let{title:e}=await i.fetch(s);return ne(a),e},applyTitle:async e=>{await _.optimisticUpdate({execute:async()=>{},optimistic:t=>{if(a!==y.adapterGeneration)return t;let n=Y(t,o.id);return n?{...t,threadData:{...t.threadData,[n.id]:{...n,title:e}}}:t}})},afterRun:r?()=>{if(ne(a),f?.aborted)throw new sp;return Y(_.value,o.id)?.title}:void 0})},[E,f,ne,y,_]),ce=Jt(async e=>{do await ee(e);while(Bm(_.value,e,y.mainThreadId));m.release(e),y.startedIds.delete(e),T(t=>t.filter(t=>t!==e))},[ee,m,y,_]),{mainThreadClient:le,itemOrder:ue,threadListItems:de,bodyMethodsOf:fe}=Um({listState:b,mainThreadId:S,initialMainId:v,startedIds:w,pendingAutomaticTitles:y.pendingAutomaticTitles,backgroundThreads:E,lifetimes:m,ownerDestroySignal:f,threadFactory:n,useAdapters:c?void 0:t.unstable_useAdapters,onSwitchTo:(e,t)=>R(e,t),onRename:(e,t)=>re(e,t),onUpdateCustom:(e,t)=>x(ie(e,t)),onArchive:e=>V(e),onUnarchive:e=>ae(e),onDelete:e=>oe(e),onGenerateTitle:(e,t,n,r)=>se(e,t,n,r),onInitialize:async e=>Fm(await B(e)),onDetach:e=>ce(e)});W(()=>{let e=()=>{y.newThreadIntent?.unsubscribe(),y.newThreadIntent=void 0};return f?.addEventListener(`abort`,e,{once:!0}),()=>{f?.removeEventListener(`abort`,e),e()}},[f,y]);let pe=Y(b,S)?.remoteId;W(()=>{A(pe,!0)},[pe,A,i]),W(()=>{if(y.isFirstThreadIdEffect){if(y.isFirstThreadIdEffect=!1,y.lastControlledThreadId=r,r===void 0)return;Eu(`switch`,()=>{let e=R(r,void 0,!1);return y.controlledSwitchGeneration=y.switchGeneration,y.controlledSwitchAdapter=y.adapter,e})}else Object.is(y.lastControlledThreadId,r)||(y.lastControlledThreadId=r,r===void 0?Eu(`create`,()=>{let e=z(!1,!0);return y.controlledSwitchGeneration=y.switchGeneration,y.controlledSwitchAdapter=y.adapter,e}):Eu(`switch`,()=>{let e=R(r,void 0,!1);return y.controlledSwitchGeneration=y.switchGeneration,y.controlledSwitchAdapter=y.adapter,e}))},[y,z,R,r]),W(()=>{let e=y.lastControlledThreadId;if(b.isLoading||b.isLoadingMore||e===void 0||y.controlledSwitchGeneration!==y.switchGeneration||!d&&y.controlledReloadPending&&b.loadError!==void 0||!y.controlledReloadPending&&Y(b,e)===void 0)return;let t=d&&y.controlledReloadPending;y.controlledReloadPending=!1,Bm(b,e,y.mainThreadId)||Eu(`switch`,()=>{let n=R(e,void 0,!1),r=y.switchGeneration,i=y.adapter;return y.controlledSwitchGeneration=r,y.controlledSwitchAdapter=i,t&&n.catch(()=>{y.switchGeneration===r&&y.controlledSwitchGeneration===r&&y.lastControlledThreadId===e&&y.adapter===i&&(y.controlledReloadPending=!0)}),n})},[D]);let me=qt(()=>({mainThreadId:S,newThreadId:b.newThreadId??null,isLoading:b.isLoading,canUnarchive:!!t.unarchive,loadError:b.loadError,switchError:b.switchError,isLoadingMore:b.isLoadingMore,hasMore:b.cursor!==void 0,threadIds:b.threadIds,archivedThreadIds:b.archivedThreadIds,threadItems:de.state,main:le.state}),[b.archivedThreadIds,t.unarchive,b.cursor,b.isLoading,b.loadError,b.switchError,b.isLoadingMore,b.newThreadId,b.threadIds,le.state,S,de.state]),he=()=>Y(_.value,S)?.status===`new`?jm:le.methods.unstable_refetchThread?.()??jm;return{getState:()=>me,switchToThread:(e,t)=>{Eu(`switch`,()=>R(e,t))},switchToNewThread:()=>{Eu(`create`,()=>z())},getLoadThreadsPromise:()=>x(j()),reload:()=>x(M()),reloadMainThread:he,loadMore:()=>x(F()),item:e=>{if(e===`main`){let e=ue.findIndex(e=>zm(e,b,S));return de.get({index:e})}if(`id`in e){let t=ue.findIndex(t=>zm(t,b,e.id));return de.get({index:t})}let t=(e.archived?b.archivedThreadIds:b.threadIds)[e.index];if(t===void 0)return de.get({index:-1});let n=ue.findIndex(e=>zm(e,b,t));return de.get({index:n})},thread:()=>le.methods,__internal_getRawActions:()=>({switchToThread:R,switchToNewThread:z,rename:re,archive:V,unarchive:ae,delete:oe,detach:ce,generateTitle:se,initialize:B,reload:M,reloadMainThread:he,getLoadThreadsPromise:j,loadMore:F}),__internal_getThreadBody:fe}},Gm=hr(Wm);zr(Wm,_m);function Km(e){ml(e)||console.error(`[assistant-ui] Thread title generation failed`,e)}var qm=e=>{let t=G(18),{clientCore:n,threadId:r,startThread:i}=e,a=K(),o=n.hookManager,s=r,c=Pi(),l,u;t[0]!==c||t[1]!==s||t[2]!==o||t[3]!==i?(l=()=>{i&&o.startThreadRuntime(s).catch(Xm);let e=()=>o.stopThreadRuntime(s);return c?.addEventListener(`abort`,e,{once:!0}),()=>c?.removeEventListener(`abort`,e)},u=[o,s,c,i],t[0]=c,t[1]=s,t[2]=o,t[3]=i,t[4]=l,t[5]=u):(l=t[4],u=t[5]),W(l,u);let d;if(t[6]!==a.subscribe||t[7]!==a.threadListItem||t[8]!==s||t[9]!==o){let e;t[11]!==s||t[12]!==o?(e=()=>o.getThreadRuntimeCore(s)??vp,t[11]=s,t[12]=o,t[13]=e):e=t[13];let n;t[14]===o?n=t[15]:(n=e=>o.subscribe(e),t[14]=o,t[15]=n);let r;t[16]===a.threadListItem?r=t[17]:(r=()=>({...a.threadListItem.getState(),isMain:!1}),t[16]=a.threadListItem,t[17]=r),d=new Kd(new to({path:{ref:`threads[${s}]`,threadSelector:{type:`threadId`,threadId:s}},getState:e,subscribe:n}),new $a({path:{ref:`threadItems[${s}]`,threadSelector:{type:`threadId`,threadId:s}},getState:r,subscribe:a.subscribe})),t[6]=a.subscribe,t[7]=a.threadListItem,t[8]=s,t[9]=o,t[10]=d}else d=t[10];return d},Jm=e=>{let t=K(),n=U(t);return $t(()=>{n.current=t},[t]),Lr(qt(()=>Aa({getClient:()=>n.current,subscribe:e=>n.current.subscribe(e)}),[]),function(){return qm(e)})},Ym=hr(e=>{let t=G(2),n=Jm(e),r;return t[0]===n?r=t[1]:(r=xu({runtime:n}),t[0]=n,t[1]=r),vr(r)});function Xm(){}var Zm={getState:()=>0,getServerSnapshot:()=>0,subscribe:()=>()=>{}},Qm=e=>{let t=G(35),{optionsStore:n,generationStore:r,assistantRuntime:i,initialThreadIdSeed:a,clientCore:o}=e,s=fl(n),c=fl(r??Zm),[l,u]=H(s.threadId!==void 0||s.initialThreadId===void 0),d;t[0]!==o||t[1]!==l?(d={clientCore:o,startThread:l},t[0]=o,t[1]=l,t[2]=d):d=t[2];let f=d,p;t[3]!==c||t[4]!==f?(p=e=>gr(`${e}:${c}`,Ym({...f,threadId:e})),t[3]=c,t[4]=f,t[5]=p):p=t[5];let m=p,h=$r(),g;t[6]!==i||t[7]!==h?(g=()=>(typeof i==`function`?i():i).registerModelContextProvider(h.current.modelContext()),t[6]=i,t[7]=h,t[8]=g):g=t[8];let _;t[9]===i?_=t[10]:(_=[i],t[9]=i,t[10]=_),ii(`modelContext`,g,_);let v=U(s.initialThreadId),y;t[11]!==h||t[12]!==s.threadId?(y=()=>{s.threadId===void 0&&v.current!==void 0&&h.current.threads.__internal_getRawActions?.().switchToThread(v.current).finally(()=>u(!0)).catch(eh)},t[11]=h,t[12]=s.threadId,t[13]=y):y=t[13];let b;t[14]===h?b=t[15]:(b=[h],t[14]=h,t[15]=b),W(y,b);let x=s.onThreadIdChange,S;t[16]!==o||t[17]!==x?(S=e=>(o.__internal_announceMainRemoteId(e),x?.(e)),t[16]=o,t[17]=x,t[18]=S):S=t[18];let C=S,w;t[19]!==o.__internal_ensureThread||t[20]!==o.__internal_isThreadAttached||t[21]!==a||t[22]!==C||t[23]!==s.adapter||t[24]!==s.threadId||t[25]!==m?(w=Gm({adapter:s.adapter,thread:m,threadId:s.threadId,onThreadIdChange:C,backgroundThreads:!0,__internal_ensureThread:o.__internal_ensureThread,__internal_isThreadAttached:o.__internal_isThreadAttached,__internal_initialThreadIdSeed:a,__internal_preserveDraftOnAdapterChange:!0,__internal_reopenControlledThreadOnAdapterChange:!0}),t[19]=o.__internal_ensureThread,t[20]=o.__internal_isThreadAttached,t[21]=a,t[22]=C,t[23]=s.adapter,t[24]=s.threadId,t[25]=m,t[26]=w):w=t[26];let T=vr(w),E;t[27]===o?E=t[28]:(E=()=>o.reloadMainThread(),t[27]=o,t[28]=E);let D;t[29]===i?D=t[30]:(D=()=>typeof i==`function`?i():i,t[29]=i,t[30]=D);let O;return t[31]!==D||t[32]!==E||t[33]!==T?(O={...T,reloadMainThread:E,__internal_getAssistantRuntime:D},t[31]=D,t[32]=E,t[33]=T,t[34]=O):O=t[34],O},$m=hr(Qm);zr(Qm,_m);function eh(){}var th=class extends mf{threads;constructor(e,t){super(),this.threads=new sm(e,this._contextProvider,t)}get RenderComponent(){return this.threads.__internal_RenderComponent}},nh=class extends mf{threads;optionsStore;constructor(e,t,n){super(),this.optionsStore=new Za(e);let r=this.optionsStore,i=this._contextProvider;this.threads=new um(t,n,function(){let e=fl(r),t=Xu(),n=e.adapter.unstable_useAdapters,a=Qu(vr(qt(()=>hr(function(e){return n?.call(e)}),[n])(e.adapter)));return Yu(qt(()=>({modelContext:i,...t,...a}),[t,a]),e.runtimeHook)},e.threadId!==void 0||e.initialThreadId===void 0)}get RenderComponent(){return this.threads.__internal_RenderComponent}},rh=(e,t)=>{let[n]=H(()=>new th(e,t)),[r]=H(()=>({generation:0})),i=U(!1);W(()=>{cm&&!i.current&&(i.current=!0,console.warn(`[assistant-ui] RemoteThreadListAdapter.unstable_Provider is deprecated and will be removed in a future minor release. Return the same adapters from unstable_useAdapters and drop unstable_Provider so useRemoteThreadListRuntime runs on the RemoteThreadList client.`))},[]),$t(()=>{let e=++r.generation;return()=>queueMicrotask(()=>{r.generation===e&&n.threads.__internal_dispose()})},[n,r]),W(()=>{n.threads.__internal_setOptions(e)},[n,e]);let a=e.adapter;W(()=>{n.threads.__internal_load()},[n,a]),W(()=>{if(typeof window>`u`||typeof document>`u`)return;let e=()=>{n.threads.loadError!==void 0&&n.threads.reload(),n.threads.__internal_retryControlledThread()},t=()=>{document.visibilityState===`visible`&&e()};return window.addEventListener(`online`,e),document.addEventListener(`visibilitychange`,t),()=>{window.removeEventListener(`online`,e),document.removeEventListener(`visibilitychange`,t)}},[n]);let[o]=H(()=>new pf(n));return o},ih=(e,t)=>{let[n]=H(()=>{let n=wa({getConfig:()=>he({threads:$m({optionsStore:r.optionsStore,assistantRuntime:()=>i,initialThreadIdSeed:t,clientCore:r.threads})}),subscribe:()=>()=>{}}),r=new nh(e,t,n),i=new pf(r);return{assistantRuntime:i,core:r,handle:n,generation:0}});return Yc(()=>n.handle.subscribe(()=>{}),[n]),$t(()=>{let e=++n.generation;return()=>queueMicrotask(()=>{n.generation===e&&(n.handle.destroy(),n.core.threads.__internal_dispose())})},[n]),Yc(()=>{n.core.optionsStore.setState(e)},[n,e]),n.assistantRuntime},ah=e=>{let t=en(),n=Jc(),[r]=H(()=>e.adapter.unstable_Provider===void 0?`client`:`legacy`),[i]=H(()=>n?t:r===`client`?Math.random().toString(36).slice(2):``);return r===`legacy`?rh(e,n?i:void 0):ih(e,i)},oh=e=>{let[t]=H(()=>new Za(e.runtimeHook));Yc(()=>{t.setState(e.runtimeHook)},[t,e.runtimeHook]);let n=U(e.initialThreadId),[r]=H(()=>function(){return fl({subscribe:t.subscribe,getState:t.getState,getServerSnapshot:t.getState})()}),i=Xt(t=>e.onThreadIdChange?.(t)),a=qt(()=>({adapter:e.adapter,allowNesting:e.allowNesting,threadId:e.threadId,initialThreadId:n.current,runtimeHook:r,onThreadIdChange:i}),[e.adapter,e.allowNesting,e.threadId,r]);if(K().threadListItem.source!==null){if(!a.allowNesting)throw Error(`useRemoteThreadListRuntime cannot be nested inside another RemoteThreadListRuntime. Set allowNesting: true to allow nesting (the inner runtime will become a no-op).`);return e.runtimeHook()}return ah(a)},sh=e=>{let t=G(6),{id:n,children:r}=e,i=K(),a;t[0]===n?a=t[1]:(a=he({message:_a({source:`thread`,query:{type:`id`,id:n},get:e=>e.thread.message({id:n})}),composer:_a({source:`message`,query:{},get:e=>e.thread.message({id:n}).composer()})}),t[0]=n,t[1]=a);let o=a,s;return t[2]!==i||t[3]!==r||t[4]!==o?(s=(0,J.jsx)(zu,{extends:i,config:o,children:r}),t[2]=i,t[3]=r,t[4]=o,t[5]=s):s=t[5],s},ch=(e,t)=>e.Message===t.Message&&e.EditComposer===t.EditComposer&&e.UserEditComposer===t.UserEditComposer&&e.AssistantEditComposer===t.AssistantEditComposer&&e.SystemEditComposer===t.SystemEditComposer&&e.UserMessage===t.UserMessage&&e.AssistantMessage===t.AssistantMessage&&e.SystemMessage===t.SystemMessage,lh=()=>null,uh=new WeakMap,dh=(e,t)=>{let n=uh.get(e);return n||(n=new Set(e.map(e=>e.id)),uh.set(e,n)),n.has(t)},fh=(e,t,n)=>{switch(t){case`user`:return n?e.UserEditComposer??e.EditComposer??e.UserMessage??e.Message:e.UserMessage??e.Message;case`assistant`:return n?e.AssistantEditComposer??e.EditComposer??e.AssistantMessage??e.Message:e.AssistantMessage??e.Message;case`system`:return n?e.SystemEditComposer??e.EditComposer??e.SystemMessage??e.Message??lh:e.SystemMessage??e.Message??lh;default:throw Error(`Unknown message role: ${t}`)}},ph=e=>{let t=G(6),{components:n}=e,r=q(yh),i=q(bh),a;t[0]!==n||t[1]!==i||t[2]!==r?(a=fh(n,r,i),t[0]=n,t[1]=i,t[2]=r,t[3]=a):a=t[3];let o=a,s;return t[4]===o?s=t[5]:(s=(0,J.jsx)(o,{}),t[4]=o,t[5]=s),s},mh=rn(e=>{let t=G(5),{index:n,components:r}=e,i;t[0]===r?i=t[1]:(i=(0,J.jsx)(ph,{components:r}),t[0]=r,t[1]=i);let a;return t[2]!==n||t[3]!==i?(a=(0,J.jsx)(id,{index:n,children:i}),t[2]=n,t[3]=i,t[4]=a):a=t[4],a},(e,t)=>e.index===t.index&&ch(e.components,t.components));mh.displayName=`ThreadPrimitive.MessageByIndex`;var hh=rn(e=>{let t=G(7),{messageId:n,components:r}=e,i;if(t[0]===n?i=t[1]:(i=e=>dh(e.thread.messages,n),t[0]=n,t[1]=i),!q(i))return null;let a;t[2]===r?a=t[3]:(a=(0,J.jsx)(ph,{components:r}),t[2]=r,t[3]=a);let o;return t[4]!==n||t[5]!==a?(o=(0,J.jsx)(sh,{id:n,children:a}),t[4]=n,t[5]=a,t[6]=o):o=t[6],o},(e,t)=>e.messageId===t.messageId&&ch(e.components,t.components));hh.displayName=`ThreadPrimitive.Unstable_MessageById`;var gh=({children:e})=>{let t=q(Ki(e=>e.thread.messages.map(e=>e.id)));return qt(()=>t.length===0?null:t.map((t,n)=>(0,J.jsx)(id,{index:n,children:(0,J.jsx)(Hu,{getItemState:e=>e.thread.message({index:n}).getState(),children:t=>e({get message(){return t()}})})},t)),[t,e])},_h=e=>{let t=G(4),{components:n,children:r}=e;if(n){let e;return t[0]===n?e=t[1]:(e=(0,J.jsx)(gh,{children:()=>(0,J.jsx)(ph,{components:n})}),t[0]=n,t[1]=e),e}let i;return t[2]===r?i=t[3]:(i=(0,J.jsx)(gh,{children:r}),t[2]=r,t[3]=i),i};_h.displayName=`ThreadPrimitive.Messages`;var vh=rn(_h,(e,t)=>e.children||t.children?e.children===t.children:ch(e.components,t.components));function yh(e){return e.message.role}function bh(e){return e.message.composer.isEditing}var xh=e=>{let t=e.message.metadata;if(t&&typeof t==`object`)return t.custom?.quote},Sh=class extends Error{componentName;constructor(e,t=`Component "${e}" is not in the generative-ui allowlist.`){super(t),this.name=`GenerativeUIRenderError`,this.componentName=e}},Ch=e=>typeof e==`object`&&!!e&&!Array.isArray(e),wh=e=>e==null?[]:Array.isArray(e)?e:[e],Th=(e,...t)=>{typeof process<`u`&&process.env.NODE_ENV!==`production`&&console.warn(e,...t)},Eh=64,Dh=(e,t,n,r,i=0)=>{if(i>Eh)return Th(`[generative-ui] Skipping node nested past ${Eh} levels at ${r}.`),null;if(e==null)return null;if(typeof e==`string`||typeof e==`number`)return e;if(Array.isArray(e))return e.map((e,a)=>Dh(e,t,n,`${r}/${a}`,i+1));if(!Ch(e)||!(`component`in e)||typeof e.component!=`string`)return Th(`[generative-ui] Skipping malformed node at ${r}:`,e),null;let{component:a,props:o,children:s,key:c}=e,l=Object.hasOwn(t,a)?t[a]:void 0;if(!l){if(n)return(0,J.jsx)(n,{component:a,props:o},c??r);throw new Sh(a)}return on(l,{...o??{},key:c??r},...wh(s).map((e,a)=>Dh(e,t,n,`${r}/${a}`,i+1)))},Oh=e=>{let t=G(11),{spec:n,components:r,Fallback:i}=e,a=n?.root,o;t[0]===a?o=t[1]:(o=wh(a),t[0]=a,t[1]=o);let s=o,c;if(t[2]!==i||t[3]!==r||t[4]!==s){let e;t[6]!==i||t[7]!==r?(e=(e,t)=>Dh(e,r,i,`${t}`),t[6]=i,t[7]=r,t[8]=e):e=t[8],c=s.map(e),t[2]=i,t[3]=r,t[4]=s,t[5]=c}else c=t[5];let l;return t[9]===c?l=t[10]:(l=(0,J.jsx)(J.Fragment,{children:c}),t[9]=c,t[10]=l),l};Oh.displayName=`GenerativeUIRender`;var kh=e=>{let t=G(4),{components:n,spec:r,Fallback:i}=e,a=q(Ah),o=r??a;if(!o)return null;let s;return t[0]!==i||t[1]!==n||t[2]!==o?(s=(0,J.jsx)(Oh,{spec:o,components:n,Fallback:i}),t[0]=i,t[1]=n,t[2]=o,t[3]=s):s=t[3],s};kh.displayName=`MessagePrimitive.GenerativeUI`;function Ah(e){let t=e.part;return t?.type===`generative-ui`?t.spec:void 0}var jh=(e,t,n)=>(e.toolUIs[t.toolName]?.[0]?.render??null)||n||(D(t.mcp?.app?.resourceUri)&&e.mcpApp?e.mcpApp.render:null),Mh=e=>{let t=-1;return{startGroup:e=>{t===-1&&(t=e)},endGroup:(n,r)=>{t!==-1&&(r.push({type:e,startIndex:t,endIndex:n}),t=-1)},finalize:(n,r)=>{t!==-1&&r.push({type:e,startIndex:t,endIndex:n})}}},Nh=(e,t,n)=>{let r=[];if(t){let t=Mh(`chainOfThoughtGroup`);for(let n=0;n<e.length;n++){let i=e[n];i===`tool-call`||i===`reasoning`?t.startGroup(n):(t.endGroup(n-1,r),r.push({type:`single`,index:n}))}t.finalize(e.length-1,r)}else{let t=Mh(`toolGroup`),n=Mh(`reasoningGroup`);for(let i=0;i<e.length;i++){let a=e[i];a===`tool-call`?(n.endGroup(i-1,r),t.startGroup(i)):a===`reasoning`?(t.endGroup(i-1,r),n.startGroup(i)):(t.endGroup(i-1,r),n.endGroup(i-1,r),r.push({type:`single`,index:i}))}t.finalize(e.length-1,r),n.finalize(e.length-1,r)}if(n){let e=new Set;for(let t of r){if(t.type===`single`)continue;let r=n[t.startIndex];r?.includes(`:`)&&!e.has(r)&&(e.add(r),t.idKey=`id:${r}`)}}return r},Ph=e=>{let t=G(10),n=q(Ki(rg)),r=q(Ki(ig)),i;bb0:{if(n.length===0){let e;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(e=[],t[0]=e):e=t[0];let n;t[1]===r?n=t[2]:(n={ranges:e,partIds:r},t[1]=r,t[2]=n),i=n;break bb0}let a;t[3]!==n||t[4]!==r||t[5]!==e?(a=Nh(n,e,r),t[3]=n,t[4]=r,t[5]=e,t[6]=a):a=t[6];let o;t[7]!==r||t[8]!==a?(o={ranges:a,partIds:r},t[7]=r,t[8]=a,t[9]=o):o=t[9],i=o}return i},Fh=e=>{let t=G(11),n,r,i;t[0]===e?(n=t[1],r=t[2],i=t[3]):({ByName:n,Fallback:r,...i}=e,t[0]=e,t[1]=n,t[2]=r,t[3]=i);let a;t[4]!==n||t[5]!==r||t[6]!==i?(a=e=>jh(e.tools,i,n)??r,t[4]=n,t[5]=r,t[6]=i,t[7]=a):a=t[7];let o=q(a);if(!o)return null;let s;return t[8]!==o||t[9]!==i?(s=(0,J.jsx)(o,{...i}),t[8]=o,t[9]=i,t[10]=s):s=t[10],s},Ih=(e,t,n)=>e.renderers[t]?.[0]||(e.fallbacks[0]??n),Lh=e=>{let t=G(9),n,r;t[0]===e?(n=t[1],r=t[2]):({Fallback:n,...r}=e,t[0]=e,t[1]=n,t[2]=r);let i;t[3]!==n||t[4]!==r.name?(i=e=>Ih(e.dataRenderers,r.name,n),t[3]=n,t[4]=r.name,t[5]=i):i=t[5];let a=q(i);if(!a)return null;let o;return t[6]!==a||t[7]!==r?(o=(0,J.jsx)(a,{...r}),t[6]=a,t[7]=r,t[8]=o):o=t[8],o},Rh={Text:()=>null,Reasoning:()=>null,Source:()=>null,Image:()=>null,File:()=>null,Unstable_Audio:()=>null,ToolGroup:({children:e})=>e,ReasoningGroup:({children:e})=>e},zh=e=>{let t=G(54),{components:n}=e,r;t[0]===n?r=t[1]:(r=n===void 0?{}:n,t[0]=n,t[1]=r);let{Text:i,Reasoning:a,Image:o,Source:s,File:c,Unstable_Audio:l,tools:u,data:d,generativeUI:f}=r,p=i===void 0?Rh.Text:i,m=a===void 0?Rh.Reasoning:a,h=o===void 0?Rh.Image:o,g=s===void 0?Rh.Source:s,_=c===void 0?Rh.File:c,v=l===void 0?Rh.Unstable_Audio:l,y;t[2]===u?y=t[3]:(y=u===void 0?{}:u,t[2]=u,t[3]=y);let b=y,x=K(),S=q(ag),C=S.type;if(C===`tool-call`){let e=x.part.addToolResult,n=x.part.resumeToolCall,r=x.part.respondToToolApproval,i=x.part.unstable_recordInteraction;if(`Override`in b){let a;t[4]===i?a=t[5]:(a=i&&{unstable_recordInteraction:i},t[4]=i,t[5]=a);let o;return t[6]!==e||t[7]!==S||t[8]!==r||t[9]!==n||t[10]!==a||t[11]!==b.Override?(o=(0,J.jsx)(b.Override,{...S,addResult:e,resume:n,respondToApproval:r,...a}),t[6]=e,t[7]=S,t[8]=r,t[9]=n,t[10]=a,t[11]=b.Override,t[12]=o):o=t[12],o}let a;t[13]!==S.toolName||t[14]!==b.by_name?(a=b.by_name&&Object.hasOwn(b.by_name,S.toolName)?b.by_name[S.toolName]:void 0,t[13]=S.toolName,t[14]=b.by_name,t[15]=a):a=t[15];let o=a,s;t[16]===i?s=t[17]:(s=i&&{unstable_recordInteraction:i},t[16]=i,t[17]=s);let c;return t[18]!==o||t[19]!==e||t[20]!==S||t[21]!==r||t[22]!==n||t[23]!==s||t[24]!==b.Fallback?(c=(0,J.jsx)(Fh,{...S,ByName:o,Fallback:b.Fallback,addResult:e,resume:n,respondToApproval:r,...s}),t[18]=o,t[19]=e,t[20]=S,t[21]=r,t[22]=n,t[23]=s,t[24]=b.Fallback,t[25]=c):c=t[25],c}if(S.status?.type===`requires-action`)throw Error(`Encountered unexpected requires-action status`);switch(C){case`text`:{let e;return t[26]!==p||t[27]!==S?(e=(0,J.jsx)(p,{...S}),t[26]=p,t[27]=S,t[28]=e):e=t[28],e}case`reasoning`:{let e;return t[29]!==m||t[30]!==S?(e=(0,J.jsx)(m,{...S}),t[29]=m,t[30]=S,t[31]=e):e=t[31],e}case`source`:{let e;return t[32]!==g||t[33]!==S?(e=(0,J.jsx)(g,{...S}),t[32]=g,t[33]=S,t[34]=e):e=t[34],e}case`image`:{let e;return t[35]!==h||t[36]!==S?(e=(0,J.jsx)(h,{...S}),t[35]=h,t[36]=S,t[37]=e):e=t[37],e}case`file`:{let e;return t[38]!==_||t[39]!==S?(e=(0,J.jsx)(_,{...S}),t[38]=_,t[39]=S,t[40]=e):e=t[40],e}case`audio`:{let e;return t[41]!==v||t[42]!==S?(e=(0,J.jsx)(v,{...S}),t[41]=v,t[42]=S,t[43]=e):e=t[43],e}case`data`:{let e;t[44]!==d||t[45]!==S.name?(e=(d?.by_name&&Object.hasOwn(d.by_name,S.name)?d.by_name[S.name]:void 0)??d?.Fallback,t[44]=d,t[45]=S.name,t[46]=e):e=t[46];let n=e,r;return t[47]!==n||t[48]!==S?(r=(0,J.jsx)(Lh,{...S,Fallback:n}),t[47]=n,t[48]=S,t[49]=r):r=t[49],r}case`generative-ui`:{if(!f?.components)return typeof process<`u`&&process.env.NODE_ENV!==`production`&&console.warn("MessagePrimitive.Parts received a generative-ui part but no `components.generativeUI.components` allowlist was provided. Pass an allowlist or render with <MessagePrimitive.GenerativeUI />."),null;let e=S,n;return t[50]!==f.Fallback||t[51]!==f.components||t[52]!==e.spec?(n=(0,J.jsx)(Oh,{spec:e.spec,components:f.components,Fallback:f.Fallback}),t[50]=f.Fallback,t[51]=f.components,t[52]=e.spec,t[53]=n):n=t[53],n}default:return console.warn(`Unknown message part type: ${C}`),null}},Bh=rn(e=>{let t=G(5),{index:n,components:r}=e,i;t[0]===r?i=t[1]:(i=(0,J.jsx)(zh,{components:r}),t[0]=r,t[1]=i);let a;return t[2]!==n||t[3]!==i?(a=(0,J.jsx)(ad,{index:n,children:i}),t[2]=n,t[3]=i,t[4]=a):a=t[4],a},(e,t)=>e.index===t.index&&e.components?.Text===t.components?.Text&&e.components?.Reasoning===t.components?.Reasoning&&e.components?.Source===t.components?.Source&&e.components?.Image===t.components?.Image&&e.components?.File===t.components?.File&&e.components?.Unstable_Audio===t.components?.Unstable_Audio&&e.components?.tools===t.components?.tools&&e.components?.data===t.components?.data&&e.components?.generativeUI===t.components?.generativeUI&&e.components?.ToolGroup===t.components?.ToolGroup&&e.components?.ReasoningGroup===t.components?.ReasoningGroup);Bh.displayName=`MessagePrimitive.PartByIndex`;var Vh=e=>{let t=G(6),{status:n,component:r}=e,i=n.type===`running`,a;t[0]!==r||t[1]!==n?(a=(0,J.jsx)(r,{type:`text`,text:``,status:n}),t[0]=r,t[1]=n,t[2]=a):a=t[2];let o;return t[3]!==i||t[4]!==a?(o=(0,J.jsx)(sd,{text:``,isRunning:i,children:a}),t[3]=i,t[4]=a,t[5]=o):o=t[5],o},Hh=Object.freeze({type:`complete`}),Uh=Object.freeze({type:`running`}),Wh=rn(e=>{let t=G(6),{components:n}=e,r=q(og);if(n?.Empty){let e;return t[0]!==n.Empty||t[1]!==r?(e=(0,J.jsx)(n.Empty,{status:r}),t[0]=n.Empty,t[1]=r,t[2]=e):e=t[2],e}if(r.type!==`running`)return null;let i=n?.Text??Rh.Text,a;return t[3]!==r||t[4]!==i?(a=(0,J.jsx)(Vh,{status:r,component:i}),t[3]=r,t[4]=i,t[5]=a):a=t[5],a},(e,t)=>e.components?.Empty===t.components?.Empty&&e.components?.Text===t.components?.Text),Gh=rn(e=>{let t=G(4),{components:n,enabled:r}=e,i;if(t[0]===r?i=t[1]:(i=e=>{if(!r||e.message.parts.length===0)return!1;let t=e.message.parts[e.message.parts.length-1];return t?.type!==`text`&&t?.type!==`reasoning`},t[0]=r,t[1]=i),!q(i))return null;let a;return t[2]===n?a=t[3]:(a=(0,J.jsx)(Wh,{components:n}),t[2]=n,t[3]=a),a},(e,t)=>e.enabled===t.enabled&&e.components?.Empty===t.components?.Empty&&e.components?.Text===t.components?.Text),Kh=rn(e=>{let t=G(4),{Quote:n}=e,r=q(xh);if(!r)return null;let i;return t[0]!==n||t[1]!==r.messageId||t[2]!==r.text?(i=(0,J.jsx)(n,{text:r.text,messageId:r.messageId}),t[0]=n,t[1]=r.messageId,t[2]=r.text,t[3]=i):i=t[3],i}),qh=()=>{let e=G(9),t=K(),n=q(sg),r=q(cg),i=t.part.unstable_recordInteraction;if(!r||n.type!==`tool-call`)return null;let a;e[0]===i?a=e[1]:(a=i&&{unstable_recordInteraction:i},e[0]=i,e[1]=a);let o;return e[2]!==r||e[3]!==t.part.addToolResult||e[4]!==t.part.respondToToolApproval||e[5]!==t.part.resumeToolCall||e[6]!==n||e[7]!==a?(o=(0,J.jsx)(r,{...n,addResult:t.part.addToolResult,resume:t.part.resumeToolCall,respondToApproval:t.part.respondToToolApproval,...a}),e[2]=r,e[3]=t.part.addToolResult,e[4]=t.part.respondToToolApproval,e[5]=t.part.resumeToolCall,e[6]=n,e[7]=a,e[8]=o):o=e[8],o},Jh=()=>{let e=G(3),t=q(lg),n=q(ug);if(!n||t.type!==`data`)return null;let r=t,i;return e[0]!==n||e[1]!==r?(i=(0,J.jsx)(n,{...r}),e[0]=n,e[1]=r,e[2]=i):i=e[2],i},Yh=()=>{let e=G(2),t=q(dg);if(t===`tool-call`){let t;return e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,J.jsx)(qh,{}),e[0]=t):t=e[0],t}if(t===`data`){let t;return e[1]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,J.jsx)(Jh,{}),e[1]=t):t=e[1],t}return null},Xh=Object.freeze({type:`text`,text:``,status:Uh}),Zh=({children:e})=>{let t=K(),n=q(e=>e.dataRenderers);return(0,J.jsx)(Hu,{getItemState:e=>e.part.getState(),children:r=>e({get part(){let e=r();if(e.type===`tool-call`){let n=jh(t.tools.getState(),e)!==null,r=t.part;return{...e,toolUI:n?(0,J.jsx)(qh,{}):null,addResult:r.addToolResult,resume:r.resumeToolCall,respondToApproval:r.respondToToolApproval,...r.unstable_recordInteraction&&{unstable_recordInteraction:r.unstable_recordInteraction}}}if(e.type===`data`){let t=Ih(n,e.name,void 0)!==void 0;return{...e,dataRendererUI:t?(0,J.jsx)(Jh,{}):null}}return e}})})},Qh=e=>{let t=G(5),{index:n,children:r}=e,i;t[0]===r?i=t[1]:(i=(0,J.jsx)(Zh,{children:r}),t[0]=r,t[1]=i);let a;return t[2]!==n||t[3]!==i?(a=(0,J.jsx)(ad,{index:n,children:i}),t[2]=n,t[3]=i,t[4]=a):a=t[4],a},$h=e=>{let t=G(11),{children:n}=e,r=q(Ki(fg)),i=r.length,a=q(pg),o=i===0&&a;if(i===0){if(!o)return null;let e;t[0]===n?e=t[1]:(e=n({part:Xh}),t[0]=n,t[1]=e);let r;return t[2]===e?r=t[3]:(r=(0,J.jsx)(sd,{text:``,isRunning:!0,children:e}),t[2]=e,t[3]=r),r}let s;if(t[4]!==n||t[5]!==r){let e;t[7]===n?e=t[8]:(e=(e,t)=>(0,J.jsx)(Qh,{index:t,children:e=>n(e)??(0,J.jsx)(Yh,{})},e),t[7]=n,t[8]=e),s=r.map(e),t[4]=n,t[5]=r,t[6]=s}else s=t[6];let c;return t[9]===s?c=t[10]:(c=(0,J.jsx)(J.Fragment,{children:s}),t[9]=s,t[10]=c),c},eg=e=>{let t=G(5),{components:n,unstable_showEmptyOnNonTextEnd:r,children:i}=e,a=r===void 0||r;if(i){let e;return t[0]===i?e=t[1]:(e=(0,J.jsx)($h,{children:i}),t[0]=i,t[1]=e),e}let o;return t[2]!==n||t[3]!==a?(o=(0,J.jsx)(tg,{components:n,unstable_showEmptyOnNonTextEnd:a}),t[2]=n,t[3]=a,t[4]=o):o=t[4],o};eg.displayName=`MessagePrimitive.Parts`;var tg=e=>{let t=G(18),{components:n,unstable_showEmptyOnNonTextEnd:r}=e,i=q(mg),{ranges:a,partIds:o}=Ph(!!n?.ChainOfThought),s;bb0:{if(i===0){let e;t[0]===n?e=t[1]:(e=(0,J.jsx)(Wh,{components:n}),t[0]=n,t[1]=e),s=e;break bb0}let e;if(t[2]!==n||t[3]!==a||t[4]!==o){let r;t[6]!==n||t[7]!==o?(r=e=>{if(e.type===`single`)return(0,J.jsx)(Bh,{index:e.index,components:n},o[e.index]);let t=JSON.stringify([e.type,e.idKey??e.startIndex]);if(e.type===`chainOfThoughtGroup`){let r=n?.ChainOfThought;return r?(0,J.jsx)(gd,{startIndex:e.startIndex,endIndex:e.endIndex,children:(0,J.jsx)(r,{})},t):null}if(e.type===`toolGroup`){let r=n?.ToolGroup??Rh.ToolGroup;return(0,J.jsx)(r,{startIndex:e.startIndex,endIndex:e.endIndex,children:Array.from({length:e.endIndex-e.startIndex+1},(t,r)=>{let i=e.startIndex+r;return(0,J.jsx)(Bh,{index:i,components:n},o[i])})},t)}{let r=n?.ReasoningGroup??Rh.ReasoningGroup;return(0,J.jsx)(r,{startIndex:e.startIndex,endIndex:e.endIndex,children:Array.from({length:e.endIndex-e.startIndex+1},(t,r)=>{let i=e.startIndex+r;return(0,J.jsx)(Bh,{index:i,components:n},o[i])})},t)}},t[6]=n,t[7]=o,t[8]=r):r=t[8],e=a.map(r),t[2]=n,t[3]=a,t[4]=o,t[5]=e}else e=t[5];s=e}let c=s,l;t[9]===n?l=t[10]:(l=n?.Quote&&(0,J.jsx)(Kh,{Quote:n.Quote}),t[9]=n,t[10]=l);let u;t[11]!==n||t[12]!==r?(u=(0,J.jsx)(Gh,{components:n,enabled:r}),t[11]=n,t[12]=r,t[13]=u):u=t[13];let d;return t[14]!==c||t[15]!==l||t[16]!==u?(d=(0,J.jsxs)(J.Fragment,{children:[l,c,u]}),t[14]=c,t[15]=l,t[16]=u,t[17]=d):d=t[17],d};function ng(e){return e.type}function rg(e){return e.message.parts.map(ng)}function ig(e){return Tl(e.message.parts)}function ag(e){return e.part}function og(e){return e.message.status??Hh}function sg(e){return e.part}function cg(e){return e.part.type===`tool-call`?jh(e.tools,e.part):null}function lg(e){return e.part}function ug(e){return e.part.type===`data`?Ih(e.dataRenderers,e.part.name,void 0)??null:null}function dg(e){return e.part.type}function fg(e){return Tl(e.message.parts)}function pg(e){return(e.message.status?.type??`complete`)===`running`}function mg(e){return e.message.parts.length}var hg=Symbol.for(`@assistant-ui/groupBy.memoKey`),gg=e=>{let t=e,n=((e,n)=>{if(e.type===`tool-call`){if((D(e.mcp?.app?.resourceUri)||(n?.toolUIs?.[e.toolName]?.[0]?.standalone??!1))&&t[`standalone-tool-call`]!==void 0)return t[`standalone-tool-call`];let r=t[`tool-call:${e.toolName}`];return r===void 0?t[`tool-call`]??[]:r}return t[e.type]??[]}),r=Object.keys(e).sort().map(t=>[t,e[t]]);return n[hg]=`groupPartByType:${JSON.stringify(r)}`,n},_g=e=>{let t=e.nextChildIdx++;return e.nodeKey===``?String(t):`${e.nodeKey}.${t}`},vg=(e,t)=>{if(!(t===void 0||e.claimed.has(t)))return e.claimed.add(t),`id:${t}`},yg=(e,t)=>{let n={key:``,nodeKey:``,indices:[],children:[],nextChildIdx:0,claimed:new Set},r=[n],i=()=>{let e=r.pop(),n=r[r.length-1],i=t?.[e.indices[0]];n.children.push({type:`group`,key:e.key,nodeKey:e.nodeKey,idKey:vg(n,i?.includes(`:`)?i:void 0),indices:e.indices,children:e.children})};for(let n=0;n<e.length;n++){let a=e[n],o=0;for(;o<r.length-1&&o<a.length&&r[o+1].key===a[o];)o++;for(;r.length-1>o;)i();for(;r.length-1<a.length;){let e=r[r.length-1];r.push({key:a[r.length-1],nodeKey:_g(e),indices:[],children:[],nextChildIdx:0,claimed:new Set})}let s=r[r.length-1];s.children.push({type:`part`,index:n,nodeKey:_g(s),idKey:vg(s,t?.[n])});for(let e=1;e<r.length;e++)r[e].indices.push(n)}for(;r.length>1;)i();return n.children},bg=(e,t,n)=>{if(!n)return!1;switch(e){case`never`:return!1;case`always`:return!0;case`empty`:return t.length===0;case`no-text`:{let e=t[t.length-1];return e===void 0||e.type!==`text`&&e.type!==`reasoning`}}},xg=()=>{throw Error("MessagePrimitive.GroupedParts: rendered `children` under a leaf part. `children` is only meaningful for `group-…` cases — add a matching case for the part type or return `null` to use registered UIs.")},Sg=(e,t,n)=>{if(e.type===`part`)return(0,J.jsx)(Qh,{index:e.index,children:({part:e})=>n({part:e,children:(0,J.jsx)(xg,{})})??(0,J.jsx)(Yh,{})},e.idKey?`part-${e.idKey}`:`part-${e.index}`);let{status:r,counts:i,timing:a}=pd(t,e.indices),o={type:e.key,status:r,counts:i,indices:e.indices,...a&&{timing:a}};return(0,J.jsx)(an,{children:n({part:o,children:(0,J.jsx)(J.Fragment,{children:e.children.map(e=>Sg(e,t,n))})})},JSON.stringify([e.key,e.idKey??e.nodeKey]))},Cg=({groupBy:e,indicator:t=`no-text`,children:n})=>{let r=q(Ki(e=>e.message.parts)),i=q(e=>e.tools.toolUIs),a=q(e=>t!==`never`&&e.message.status?.type===`running`),o=qt(()=>{let t={toolUIs:i};return yg(r.map(n=>e(n,t)??[]),Tl(r))},[r,e[hg]??e,i]);return(0,J.jsxs)(J.Fragment,{children:[o.map(e=>Sg(e,r,n)),bg(t,r,a)&&n({part:{type:`indicator`},children:(0,J.jsx)(xg,{})})]})};Cg.displayName=`MessagePrimitive.GroupedParts`;var wg=new WeakMap,Tg=e=>wg.get(e);Object.freeze([]);var Eg=e=>e.length===1?{type:`part`,index:e[0],nodeKey:`0`,idKey:void 0}:{type:`group`,key:`group-row`,nodeKey:`0`,idKey:void 0,indices:e,children:e.map((e,t)=>({type:`part`,index:e,nodeKey:`0.${t}`,idKey:void 0}))},Dg=e=>{let t=G(7),{row:n,children:r}=e,i=q(Ki(jg));if(n.indices.some(e=>e>=i.length))return null;let a;if(t[0]!==r||t[1]!==i||t[2]!==n){let e=Tg(n)??Eg(n.indices),o;t[4]!==r||t[5]!==n?(o=e=>r({type:`part`,row:n,part:e.part,children:e.children}),t[4]=r,t[5]=n,t[6]=o):o=t[6],a=Sg(e,i,o),t[0]=r,t[1]=i,t[2]=n,t[3]=a}else a=t[3];return a},Og=({row:e,children:t})=>(0,J.jsx)(Hu,{getItemState:e=>e.message.getState(),children:n=>t({type:`message`,row:e,get message(){return n()}})}),kg=({row:e,children:t})=>(0,J.jsx)(Hu,{getItemState:e=>e.message.getState(),children:n=>t({type:`turn-end`,row:e,get message(){return n()}})}),Ag=rn(e=>{let t=G(8),{row:n,children:r}=e,i;if(t[0]===n.messageId?i=t[1]:(i=e=>dh(e.thread.messages,n.messageId),t[0]=n.messageId,t[1]=i),!q(i))return null;let a;t[2]!==r||t[3]!==n?(a=n.type===`message`?(0,J.jsx)(Og,{row:n,children:r}):n.type===`part`?(0,J.jsx)(Dg,{row:n,children:r}):(0,J.jsx)(kg,{row:n,children:r}),t[2]=r,t[3]=n,t[4]=a):a=t[4];let o;return t[5]!==n.messageId||t[6]!==a?(o=(0,J.jsx)(sh,{id:n.messageId,children:a}),t[5]=n.messageId,t[6]=a,t[7]=o):o=t[7],o},(e,t)=>e.row===t.row&&e.children===t.children);Ag.displayName=`ThreadPrimitive.Row`;function jg(e){return e.message.parts}var Mg=rn(e=>{let t=G(5),{children:n}=e,r=q(xh);if(!r)return null;let i;t[0]!==n||t[1]!==r?(i=n(r),t[0]=n,t[1]=r,t[2]=i):i=t[2];let a;return t[3]===i?a=t[4]:(a=(0,J.jsx)(J.Fragment,{children:i}),t[3]=i,t[4]=a),a});Mg.displayName=`MessagePrimitive.Quote`;var Ng=(e,t)=>{switch(t.type){case`image`:return e?.Image??e?.Attachment;case`document`:return e?.Document??e?.Attachment;case`file`:return e?.File??e?.Attachment;default:return e?.Attachment}},Pg=e=>{let t=G(5),{components:n}=e,r=q(Rg);if(!r)return null;let i;t[0]!==r||t[1]!==n?(i=Ng(n,r),t[0]=r,t[1]=n,t[2]=i):i=t[2];let a=i;if(!a)return null;let o;return t[3]===a?o=t[4]:(o=(0,J.jsx)(a,{}),t[3]=a,t[4]=o),o},Fg=rn(e=>{let t=G(5),{index:n,components:r}=e,i;t[0]===r?i=t[1]:(i=(0,J.jsx)(Pg,{components:r}),t[0]=r,t[1]=i);let a;return t[2]!==n||t[3]!==i?(a=(0,J.jsx)(td,{index:n,children:i}),t[2]=n,t[3]=i,t[4]=a):a=t[4],a},(e,t)=>e.index===t.index&&e.components?.Image===t.components?.Image&&e.components?.Document===t.components?.Document&&e.components?.File===t.components?.File&&e.components?.Attachment===t.components?.Attachment);Fg.displayName=`MessagePrimitive.AttachmentByIndex`;var Ig=({children:e})=>{let t=q(Ki(e=>e.message.role===`user`?(e.message.submission?.attachments??e.message.attachments??[]).map(e=>e.id):[]));return qt(()=>t.map((t,n)=>(0,J.jsx)(td,{index:n,children:(0,J.jsx)(Hu,{getItemState:e=>e.message.attachment({index:n}).getState(),children:t=>e({get attachment(){return t()}})})},t)),[t,e])},Lg=e=>{let t=G(4),{components:n,children:r}=e;if(n){let e;return t[0]===n?e=t[1]:(e=(0,J.jsx)(Ig,{children:e=>{let{attachment:t}=e,r=Ng(n,t);return r?(0,J.jsx)(r,{}):null}}),t[0]=n,t[1]=e),e}let i;return t[2]===r?i=t[3]:(i=(0,J.jsx)(Ig,{children:r}),t[2]=r,t[3]=i),i};Lg.displayName=`MessagePrimitive.Attachments`;function Rg(e){return e.attachment}var zg=(e,t)=>{switch(t.type){case`image`:return e?.Image??e?.Attachment;case`document`:return e?.Document??e?.Attachment;case`file`:return e?.File??e?.Attachment;default:return e?.Attachment}},Bg=e=>{let t=G(5),{components:n}=e,r=q(Wg);if(!r)return null;let i;t[0]!==r||t[1]!==n?(i=zg(n,r),t[0]=r,t[1]=n,t[2]=i):i=t[2];let a=i;if(!a)return null;let o;return t[3]===a?o=t[4]:(o=(0,J.jsx)(a,{}),t[3]=a,t[4]=o),o},Vg=rn(e=>{let t=G(5),{index:n,components:r}=e,i;t[0]===r?i=t[1]:(i=(0,J.jsx)(Bg,{components:r}),t[0]=r,t[1]=i);let a;return t[2]!==n||t[3]!==i?(a=(0,J.jsx)(nd,{index:n,children:i}),t[2]=n,t[3]=i,t[4]=a):a=t[4],a},(e,t)=>e.index===t.index&&e.components?.Image===t.components?.Image&&e.components?.Document===t.components?.Document&&e.components?.File===t.components?.File&&e.components?.Attachment===t.components?.Attachment);Vg.displayName=`ComposerPrimitive.AttachmentByIndex`;var Hg=({children:e})=>{let t=q(Ki(e=>e.composer.attachments.map(e=>e.id)));return qt(()=>t.map((t,n)=>(0,J.jsx)(nd,{index:n,children:(0,J.jsx)(Hu,{getItemState:e=>e.composer.attachment({index:n}).getState(),children:t=>e({get attachment(){return t()}})})},t)),[t,e])},Ug=e=>{let t=G(4),{components:n,children:r}=e;if(n){let e;return t[0]===n?e=t[1]:(e=(0,J.jsx)(Hg,{children:e=>{let{attachment:t}=e,r=zg(n,t);return r?(0,J.jsx)(r,{}):null}}),t[0]=n,t[1]=e),e}let i;return t[2]===r?i=t[3]:(i=(0,J.jsx)(Hg,{children:r}),t[2]=r,t[3]=i),i};Ug.displayName=`ComposerPrimitive.Attachments`;function Wg(e){return e.attachment}var Gg=rn(({children:e})=>{let t=q(Ki(e=>e.composer.queue.map(e=>e.id)));return qt(()=>t.map((t,n)=>(0,J.jsx)(bd,{index:n,children:(0,J.jsx)(Hu,{getItemState:e=>e.composer.queueItem({index:n}).getState(),children:t=>e({get queueItem(){return t()}})})},t)),[t,e])});Gg.displayName=`ComposerPrimitive.Queue`;var Kg=rn(e=>{let t=G(6),{index:n,archived:r,components:i}=e,a=r!==void 0&&r,o=i.ThreadListItem,s;t[0]===o?s=t[1]:(s=(0,J.jsx)(o,{}),t[0]=o,t[1]=s);let c;return t[2]!==a||t[3]!==n||t[4]!==s?(c=(0,J.jsx)(vd,{index:n,archived:a,children:s}),t[2]=a,t[3]=n,t[4]=s,t[5]=c):c=t[5],c},(e,t)=>e.index===t.index&&e.archived===t.archived&&e.components.ThreadListItem===t.components.ThreadListItem);Kg.displayName=`ThreadListPrimitive.ItemByIndex`;var qg=({archived:e,children:t})=>{let n=q(Ki(t=>e?t.threads.archivedThreadIds:t.threads.threadIds));return qt(()=>n.map((n,r)=>(0,J.jsx)(vd,{index:r,archived:e,children:(0,J.jsx)(Hu,{getItemState:t=>t.threads.item({index:r,archived:e}).getState(),children:e=>t({get threadListItem(){return e()}})})},n)),[n,e,t])},Jg=e=>{let t=G(8),{archived:n,components:r,children:i}=e,a=n!==void 0&&n;if(r){let e=r.ThreadListItem,n;t[0]===e?n=t[1]:(n=()=>(0,J.jsx)(e,{}),t[0]=e,t[1]=n);let i;return t[2]!==a||t[3]!==n?(i=(0,J.jsx)(qg,{archived:a,children:n}),t[2]=a,t[3]=n,t[4]=i):i=t[4],i}let o;return t[5]!==a||t[6]!==i?(o=(0,J.jsx)(qg,{archived:a,children:i}),t[5]=a,t[6]=i,t[7]=o):o=t[7],o};Jg.displayName=`ThreadListPrimitive.Items`;var Yg=e=>{let{children:t}=e;return q(Xg)?t:null};Yg.displayName=`MessagePartPrimitive.InProgress`;function Xg(e){return e.part.status.type===`running`}var Zg=e=>{let t=G(2),{fallback:n}=e,r=q(Qg)||n,i;return t[0]===r?i=t[1]:(i=(0,J.jsx)(J.Fragment,{children:r}),t[0]=r,t[1]=i),i};Zg.displayName=`ThreadListItemPrimitive.Title`;function Qg(e){return e.threadListItem.title}var $g=e=>{let t=new Map;return e.map(e=>{let n=JSON.stringify([e.title,e.label,e.prompt]),r=t.get(n)??0;return t.set(n,r+1),r===0?n:`${n}:${r}`})},e_=e=>{let t=G(2),{components:n}=e,r=n.Suggestion,i;return t[0]===r?i=t[1]:(i=(0,J.jsx)(r,{}),t[0]=r,t[1]=i),i},t_=rn(e=>{let t=G(5),{index:n,components:r}=e,i;t[0]===r?i=t[1]:(i=(0,J.jsx)(e_,{components:r}),t[0]=r,t[1]=i);let a;return t[2]!==n||t[3]!==i?(a=(0,J.jsx)(yd,{index:n,children:i}),t[2]=n,t[3]=i,t[4]=a):a=t[4],a},(e,t)=>e.index===t.index&&e.components.Suggestion===t.components.Suggestion);t_.displayName=`ThreadPrimitive.SuggestionByIndex`;var n_=({children:e})=>{let t=q(Ki(e=>$g(e.suggestions.suggestions)));return qt(()=>t.length===0?null:t.map((t,n)=>(0,J.jsx)(yd,{index:n,children:(0,J.jsx)(Hu,{getItemState:e=>e.suggestions.suggestion({index:n}).getState(),children:t=>e({get suggestion(){return t()}})})},t)),[t,e])},r_=e=>{let t=G(4),{components:n,children:r}=e;if(n){let e;return t[0]===n?e=t[1]:(e=(0,J.jsx)(n_,{children:()=>(0,J.jsx)(e_,{components:n})}),t[0]=n,t[1]=e),e}let i;return t[2]===r?i=t[3]:(i=(0,J.jsx)(n_,{children:r}),t[2]=r,t[3]=i),i};r_.displayName=`ThreadPrimitive.Suggestions`;var i_=rn(r_,(e,t)=>e.children||t.children?e.children===t.children:e.components.Suggestion===t.components.Suggestion),a_=e=>{let t=G(3),n;return t[0]!==e.dictation||t[1]!==e.editing?(n=t=>{if(e.editing===!0&&!t.composer.isEditing||e.editing===!1&&t.composer.isEditing)return!1;let n=t.composer.dictation!=null;return!(e.dictation===!0&&!n||e.dictation===!1&&n)},t[0]=e.dictation,t[1]=e.editing,t[2]=n):n=t[2],q(n)},o_=e=>{let t=G(3),n,r;return t[0]===e?(n=t[1],r=t[2]):({children:n,...r}=e,t[0]=e,t[1]=n,t[2]=r),a_(r)?n:null};o_.displayName=`ComposerPrimitive.If`;var s_=e=>e.thread.isDisabled||!e.composer.canSend||e.thread.isRunning&&!e.thread.capabilities.queue&&e.thread.voice===void 0,c_=e=>e.thread.isDisabled||e.thread.isRunning||e.thread.voice!==void 0||!e.thread.canResume||e.composer.type!==`thread`||!e.composer.isEmpty,l_=e=>!e.composer.canCancel,u_=e=>e.composer.isEditing||e.optional.message?.submission!==void 0||e.optional.thread?.isDisabled===!0||e.optional.thread?.voice!==void 0||e.optional.thread?.capabilities.edit===!1,d_=e=>e.thread.isRunning||e.thread.isDisabled||e.thread.voice!==void 0||e.message.role!==`assistant`||!e.thread.capabilities.reload,f_=e=>(e.message.role!==`assistant`||e.message.status?.type!==`running`)&&e.message.parts.some(e=>e.type===`text`&&e.text.length>0),p_=e=>!f_(e),m_=e=>e.optional.thread?.capabilities.speech!==!0||!f_(e),h_=e=>e.message.branchNumber<=1||!e.thread.capabilities.switchToBranch||e.thread.isRunning&&!e.thread.capabilities.switchBranchDuringRun,g_=e=>e.message.branchNumber>=e.message.branchCount||!e.thread.capabilities.switchToBranch||e.thread.isRunning&&!e.thread.capabilities.switchBranchDuringRun,__=e=>e.isSendDisabled?`blocked`:e.voice===void 0?e.isRunning?e.capabilities.queue?`queued`:`blocked`:`now`:e.voice.canSendText?`now`:`blocked`,v_=(e,t)=>e.thread.isDisabled||t&&__(e.thread)===`blocked`,y_=e=>{if(e.message.status?.type!==`incomplete`||e.message.status.reason!==`error`)return;let t=e.message.status.error;return typeof t==`string`?t:typeof t==`object`&&t&&`message`in t&&typeof t.message==`string`?t.message:t??`An error occurred`},b_=e=>!e.threads.hasMore||e.threads.isLoading||e.threads.isLoadingMore,x_=e=>!e.threads.canUnarchive,S_=()=>{let e=G(5),t=K(),n=q(s_),r;e[0]===t?r=e[1]:(r=e=>{t.composer.send(e)},e[0]=t,e[1]=r);let i=r,a;return e[2]!==n||e[3]!==i?(a={send:i,disabled:n},e[2]=n,e[3]=i,e[4]=a):a=e[4],a},C_=()=>{let e=G(5),t=K(),n=q(c_),r;e[0]===t?r=e[1]:(r=()=>{xd(`Resume`,t.thread().resumeRun({parentId:t.thread().getState().messages.at(-1)?.id??null}))},e[0]=t,e[1]=r);let i=r,a;return e[2]!==n||e[3]!==i?(a={resume:i,disabled:n},e[2]=n,e[3]=i,e[4]=a):a=e[4],a},w_=()=>{let e=G(5),t=K(),n=q(l_),r;e[0]===t?r=e[1]:(r=()=>{t.composer.cancel()},e[0]=t,e[1]=r);let i=r,a;return e[2]!==i||e[3]!==n?(a={cancel:i,disabled:n},e[2]=i,e[3]=n,e[4]=a):a=e[4],a},T_=()=>{let e=G(5),t=K(),n=q(E_),r;e[0]===t?r=e[1]:(r=()=>{t.composer.startDictation()},e[0]=t,e[1]=r);let i=r,a;return e[2]!==n||e[3]!==i?(a={startDictation:i,disabled:n},e[2]=n,e[3]=i,e[4]=a):a=e[4],a};function E_(e){return e.thread.isDisabled||e.composer.dictation!=null||!e.thread.capabilities.dictation||!e.composer.isEditing}var D_=()=>{let e=G(5),t=K(),n=q(O_),r;e[0]===t?r=e[1]:(r=e=>t.composer.addAttachment(e),e[0]=t,e[1]=r);let i=r,a;return e[2]!==i||e[3]!==n?(a={addAttachment:i,disabled:n},e[2]=i,e[3]=n,e[4]=a):a=e[4],a};function O_(e){return e.thread.isDisabled||!e.composer.isEditing}var k_=e=>{let t=G(20),n;t[0]===e?n=t[1]:(n=e===void 0?{}:e,t[0]=e,t[1]=n);let{copiedDuration:r,copyToClipboard:i}=n,a=r===void 0?3e3:r,o=K(),s=q(p_),c=q(A_),l=q(j_),u=q(M_),d=q(N_),f=U(void 0),p=U(void 0),m=U(0),h=U(c),g,_;t[2]===c?(g=t[3],_=t[4]):(g=()=>{h.current=c},_=[c],t[2]=c,t[3]=g,t[4]=_),$t(g,_);let v;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(v=()=>()=>{m.current+=1,f.current!==void 0&&(clearTimeout(f.current),f.current=void 0,p.current?.(!1),p.current=void 0)},t[5]=v):v=t[5];let y;t[6]!==o.message||t[7]!==c?(y=[o.message,c],t[6]=o.message,t[7]=c,t[8]=y):y=t[8],W(v,y);let b;t[9]!==o.message||t[10]!==d||t[11]!==a||t[12]!==i||t[13]!==u||t[14]!==c?(b=()=>{if(!i)return;let e=u?d:o.message.getCopyText();if(!e)return;let t=m.current,n=c,r=o.message.setIsCopied,s;try{s=i(e)}catch{return}Promise.resolve(s).then(()=>{t===m.current&&n===h.current&&(f.current!==void 0&&clearTimeout(f.current),p.current=r,r(!0),f.current=setTimeout(()=>{f.current=void 0,h.current,r(!1),p.current=void 0},a))},P_)},t[9]=o.message,t[10]=d,t[11]=a,t[12]=i,t[13]=u,t[14]=c,t[15]=b):b=t[15];let x=b,S=s||!i,C;return t[16]!==x||t[17]!==l||t[18]!==S?(C={copy:x,disabled:S,isCopied:l},t[16]=x,t[17]=l,t[18]=S,t[19]=C):C=t[19],C};function A_(e){return e.message.id}function j_(e){return e.message.isCopied}function M_(e){return e.composer.isEditing}function N_(e){return e.composer.text}function P_(){}var F_=()=>{let e=G(5),t=K(),n=q(u_),r;e[0]===t?r=e[1]:(r=()=>{t.composer.beginEdit()},e[0]=t,e[1]=r);let i=r,a;return e[2]!==n||e[3]!==i?(a={edit:i,disabled:n},e[2]=n,e[3]=i,e[4]=a):a=e[4],a},I_=()=>{let e=G(5),t=K(),n=q(d_),r;e[0]===t?r=e[1]:(r=()=>{t.message.reload()},e[0]=t,e[1]=r);let i=r,a;return e[2]!==n||e[3]!==i?(a={reload:i,disabled:n},e[2]=n,e[3]=i,e[4]=a):a=e[4],a},L_=()=>{let e=G(5),t=K(),n=q(z_),r;e[0]===t?r=e[1]:(r=()=>{t.message.submitFeedback({type:`positive`})},e[0]=t,e[1]=r);let i=r,a;return e[2]!==n||e[3]!==i?(a={submit:i,isSubmitted:n},e[2]=n,e[3]=i,e[4]=a):a=e[4],a},R_=()=>{let e=G(5),t=K(),n=q(B_),r;e[0]===t?r=e[1]:(r=()=>{t.message.submitFeedback({type:`negative`})},e[0]=t,e[1]=r);let i=r,a;return e[2]!==n||e[3]!==i?(a={submit:i,isSubmitted:n},e[2]=n,e[3]=i,e[4]=a):a=e[4],a};function z_(e){return e.message.metadata.submittedFeedback?.type===`positive`}function B_(e){return e.message.metadata.submittedFeedback?.type===`negative`}var V_=()=>{let e=G(5),t=K(),n=q(m_),r;e[0]===t?r=e[1]:(r=async()=>{t.message.speak()},e[0]=t,e[1]=r);let i=r,a;return e[2]!==n||e[3]!==i?(a={speak:i,disabled:n},e[2]=n,e[3]=i,e[4]=a):a=e[4],a},H_=()=>{let e=G(5),t=K(),n=q(U_),r;e[0]===t?r=e[1]:(r=()=>{t.message.stopSpeaking()},e[0]=t,e[1]=r);let i=r,a;return e[2]!==n||e[3]!==i?(a={stopSpeaking:i,disabled:n},e[2]=n,e[3]=i,e[4]=a):a=e[4],a};function U_(e){return e.message.speech==null}var W_=()=>{let e=G(5),t=K(),n=q(g_),r;e[0]===t?r=e[1]:(r=()=>{t.message.switchToBranch({position:`next`})},e[0]=t,e[1]=r);let i=r,a;return e[2]!==n||e[3]!==i?(a={next:i,disabled:n},e[2]=n,e[3]=i,e[4]=a):a=e[4],a},G_=()=>{let e=G(5),t=K(),n=q(h_),r;e[0]===t?r=e[1]:(r=()=>{t.message.switchToBranch({position:`previous`})},e[0]=t,e[1]=r);let i=r,a;return e[2]!==n||e[3]!==i?(a={previous:i,disabled:n},e[2]=n,e[3]=i,e[4]=a):a=e[4],a},K_=e=>{let t=G(10),{prompt:n,send:r,clearComposer:i}=e,a=i===void 0||i,o=K(),s=r??!1,c;t[0]===s?c=t[1]:(c=e=>v_(e,s),t[0]=s,t[1]=c);let l=q(c),u;t[2]!==o||t[3]!==a||t[4]!==n||t[5]!==s?(u=()=>{if(s){let e=__(o.thread.getState());if(e===`blocked`)return;o.thread.append({content:[{type:`text`,text:n}],runConfig:o.composer.getState().runConfig}),a&&e===`now`&&o.composer.setText(``)}else if(a)o.composer.setText(n);else{let e=o.composer.getState().text;o.composer.setText([e,n].filter(q_).join(` `))}},t[2]=o,t[3]=a,t[4]=n,t[5]=s,t[6]=u):u=t[6];let d=u,f;return t[7]!==l||t[8]!==d?(f={trigger:d,disabled:l},t[7]=l,t[8]=d,t[9]=f):f=t[9],f};function q_(e){return e.trim()}var J_=()=>{let e=G(4),t=K(),n;e[0]===t?n=e[1]:(n=()=>{t.threadListItem.archive()},e[0]=t,e[1]=n);let r=n,i;return e[2]===r?i=e[3]:(i={archive:r},e[2]=r,e[3]=i),i},Y_=()=>{let e=G(4),t=K(),n;e[0]===t?n=e[1]:(n=()=>{t.threadListItem.delete()},e[0]=t,e[1]=n);let r=n,i;return e[2]===r?i=e[3]:(i={delete:r},e[2]=r,e[3]=i),i},X_=()=>{let e=G(5),t=K(),n=q(x_),r;e[0]===t?r=e[1]:(r=()=>{t.threadListItem.unarchive()},e[0]=t,e[1]=r);let i=r,a;return e[2]!==n||e[3]!==i?(a={unarchive:i,disabled:n},e[2]=n,e[3]=i,e[4]=a):a=e[4],a},Z_=()=>{let e=G(4),t=K(),n;e[0]===t?n=e[1]:(n=()=>{t.threadListItem.switchTo()},e[0]=t,e[1]=n);let r=n,i;return e[2]===r?i=e[3]:(i={switchTo:r},e[2]=r,e[3]=i),i},Q_=()=>{let e=G(4),t=K(),n;e[0]===t?n=e[1]:(n=()=>{t.threads.switchToNewThread()},e[0]=t,e[1]=n);let r=n,i;return e[2]===r?i=e[3]:(i={switchToNewThread:r},e[2]=r,e[3]=i),i},$_=()=>{let e=G(5),t=K(),n=q(b_),r;e[0]===t?r=e[1]:(r=()=>{t.threads.loadMore()},e[0]=t,e[1]=r);let i=r,a;return e[2]!==n||e[3]!==i?(a={loadMore:i,disabled:n},e[2]=n,e[3]=i,e[4]=a):a=e[4],a},ev=()=>q(y_),tv=e=>{let{cloud:t,scopeId:n,initialMessages:r,maxSteps:i,adapters:a,unstable_humanToolNames:o,unstable_enableMessageQueue:s,unstable_queueClearOnRewind:c,unstable_queueClearOnCancel:l,...u}=e;return{localRuntimeOptions:{cloud:t,scopeId:n,initialMessages:r,maxSteps:i,adapters:a,unstable_humanToolNames:o,unstable_enableMessageQueue:s,unstable_queueClearOnRewind:c,unstable_queueClearOnCancel:l},otherOptions:u}};function nv(e,t){function n(n){let r=hn(e);if(!n?.optional&&!r)throw Error(`This component must be used within ${t}.`);return r}return n}function rv(e,t){function n(n){let r=e(n);return r?r[t]:null}function r(e){let t=!1,r;typeof e==`function`?r=e:e&&typeof e==`object`&&(t=!!e.optional,r=e.selector);let i=n({optional:t});return i?r?i(r):i():null}return{[t]:r,[`${t}Store`]:n}}var iv=pn(null),{useThreadViewport:av,useThreadViewportStore:ov}=rv(nv(iv,`ThreadPrimitive.Viewport`),`useThreadViewport`),sv,cv=()=>{if(sv)return sv;let e=()=>({apis:new Map,nextId:0,listeners:new Set});if(typeof window>`u`)return sv=e(),sv;let t=window.__ASSISTANT_UI_DEVTOOLS_HOOK__;if(t)return sv=t,t;let n=e();return window.__ASSISTANT_UI_DEVTOOLS_HOOK__=n,sv=n,n},lv=e=>{w(cv().listeners,e,`DevTools`)},uv=class e{static MAX_EVENT_LOGS_PER_API=200;static register(t){let n=cv();for(let e of n.apis.values())if(e.api===t)return()=>{};let r=n.nextId++,i={api:t,logs:[]},a=t.on?.(`*`,t=>{let i=n.apis.get(r);i&&(i.logs.push({time:new Date,event:t.event,data:t.payload}),i.logs.length>e.MAX_EVENT_LOGS_PER_API&&(i.logs=i.logs.slice(-e.MAX_EVENT_LOGS_PER_API)),lv(r))}),o=t.subscribe?.(()=>{lv(r)});return n.apis.set(r,i),lv(r),()=>{let e=cv();e.apis.get(r)&&(a?.(),o?.(),e.apis.delete(r),lv(r))}}},dv=e=>{let t,n=new Set,r=(e,r)=>{let i=typeof e==`function`?e(t):e;if(!Object.is(i,t)){let e=t;t=r??(typeof i!=`object`||!i)?i:Object.assign({},t,i),n.forEach(n=>n(t,e))}},i=()=>t,a={setState:r,getState:i,getInitialState:()=>o,subscribe:e=>(n.add(e),()=>n.delete(e))},o=t=e(r,i,a);return a},fv=(e=>e?dv(e):dv),pv=e=>e;function mv(e,t=pv){let n=f.default.useSyncExternalStore(e.subscribe,f.default.useCallback(()=>t(e.getState()),[e,t]),()=>t(e.getInitialState()));return f.default.useDebugValue(n),n}var hv=e=>{let t=fv(e),n=e=>mv(t,e);return Object.assign(n,t),n},gv=(e=>e?hv(e):hv),_v=e=>{let t=new Map,n=()=>{let n=0;for(let e of t.values())n+=e;e(n)};return{register:()=>{let e=Symbol();return t.set(e,0),{setHeight:r=>{t.get(e)!==r&&(t.set(e,r),n())},unregister:()=>{t.delete(e),n()}}}}},vv=new WeakMap,yv=e=>vv.get(e),bv=(e={})=>{let t=new Set,n=_v(e=>{a.setState({height:{...a.getState().height,viewport:e}})}),r={getOptions:()=>({autoScroll:e.turnAnchor!==`top`,scrollToBottomOnInitialize:!0,scrollToBottomOnRunStart:e.turnAnchor!==`top`,scrollToBottomOnThreadSwitch:!0}),controller:Wa({getOptions:()=>r.getOptions(),onAtBottomChange:e=>a.setState({isAtBottom:e}),onContentInsetChange:e=>{a.setState({height:{...a.getState().height,inset:e}})}})},i=(e,t)=>(a.setState({element:{...a.getState().element,[e]:t}}),()=>{a.getState().element[e]===t&&a.setState({element:{...a.getState().element,[e]:null}})}),a=gv(()=>({isAtBottom:!0,scrollToBottom:({behavior:e=`auto`}={})=>{w(t,()=>({behavior:e}),`Thread viewport`)},onScrollToBottom:e=>(t.add(e),()=>{t.delete(e)}),turnAnchor:e.turnAnchor??`bottom`,topAnchorMessageClamp:{tallerThan:e.topAnchorMessageClamp?.tallerThan??`10em`,visibleHeight:e.topAnchorMessageClamp?.visibleHeight??`6em`},height:{viewport:0,inset:0},element:{viewport:null,anchor:null,target:null},targetConfig:null,topAnchorTurn:null,registerViewport:n.register,registerContentInset:r.controller.registerContentInset,registerViewportElement:e=>i(`viewport`,e),registerAnchorElement:e=>i(`anchor`,e),registerAnchorTargetElement:(e,t)=>(a.setState({element:{...a.getState().element,target:e},targetConfig:e&&t?t:null}),()=>{a.getState().element.target===e&&a.setState({element:{...a.getState().element,target:null},targetConfig:null})}),setTopAnchorTurn:e=>{a.setState({topAnchorTurn:e})}}));return vv.set(a,r),a},xv=e=>e,Sv=e=>{let t=G(11),n;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(n={optional:!0},t[0]=n):n=t[0];let r=ov(n),i;t[1]===e?i=t[2]:(i=()=>bv(e),t[1]=e,t[2]=i);let[a]=H(i),o,s;t[3]!==r||t[4]!==a?(o=()=>r?.getState().onScrollToBottom(e=>{a.getState().scrollToBottom(e)}),s=[r,a],t[3]=r,t[4]=a,t[5]=o,t[6]=s):(o=t[5],s=t[6]),W(o,s);let c,l;return t[7]!==r||t[8]!==a?(c=()=>{if(r)return a.subscribe(e=>{r.getState().isAtBottom!==e.isAtBottom&&xv(r).setState({isAtBottom:e.isAtBottom})})},l=[a,r],t[7]=r,t[8]=a,t[9]=c,t[10]=l):(c=t[9],l=t[10]),W(c,l),a},Cv=e=>{let t=G(7),{children:n,options:r}=e,i;t[0]===r?i=t[1]:(i=r===void 0?{}:r,t[0]=r,t[1]=i);let a=Sv(i),o;t[2]===a?o=t[3]:(o=()=>({useThreadViewport:a}),t[2]=a,t[3]=o);let[s]=H(o),c;return t[4]!==n||t[5]!==s?(c=(0,J.jsx)(iv.Provider,{value:s,children:n}),t[4]=n,t[5]=s,t[6]=c):c=t[6],c},wv=()=>{let e=G(3),t=K(),n,r;return e[0]===t?(n=e[1],r=e[2]):(n=()=>{if(typeof process<`u`&&process.env.NODE_ENV!==`production`)return uv.register(t)},r=[t],e[0]=t,e[1]=n,e[2]=r),W(n,r),null},Tv=rn(e=>{let t=G(8),{children:n,aui:r,config:i,runtime:a}=e,o=r??null,s;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(s=(0,J.jsx)(wv,{}),t[0]=s):s=t[0];let c;t[1]===n?c=t[2]:(c=(0,J.jsx)(Cv,{children:n}),t[1]=n,t[2]=c);let l;return t[3]!==i||t[4]!==a||t[5]!==o||t[6]!==c?(l=(0,J.jsxs)(qu,{runtime:a,aui:o,config:i,children:[s,c]}),t[3]=i,t[4]=a,t[5]=o,t[6]=c,t[7]=l):l=t[7],l}),Ev=globalThis.window===void 0?W:Yt,Dv=()=>{let e=G(3),t=q(Ov),n=q(kv),r=t!==void 0&&t.completedAt===void 0&&n,[i,a]=H(void 0),o,s;if(e[0]===r?(o=e[1],s=e[2]):(o=()=>{if(!r)return;a(Date.now());let e=setInterval(()=>a(Date.now()),1e3);return()=>clearInterval(e)},s=[r],e[0]=r,e[1]=o,e[2]=s),Ev(o,s),t!==void 0){if(t.completedAt!==void 0)return Math.max(0,t.completedAt-t.startedAt);if(r&&i!==void 0)return Math.max(0,i-t.startedAt)}};function Ov(e){let t=e.optional.part;return t?.type===`tool-call`?t.timing:void 0}function kv(e){let t=e.optional.part;return t?.type===`tool-call`&&t.status.type===`running`}var Av=Object.defineProperty,jv=(e,t)=>Av(e,`name`,{value:t,configurable:!0});function Mv(e,t){if(typeof e==`function`)return e(t);e!=null&&(e.current=t)}jv(Mv,`setRef`);function Nv(...e){return t=>{let n=!1,r=e.map(e=>{let r=Mv(e,t);return!n&&typeof r==`function`&&(n=!0),r});if(n)return()=>{for(let t=0;t<r.length;t++){let n=r[t];typeof n==`function`?n():Mv(e[t],null)}}}}jv(Nv,`composeRefs`);function Pv(...e){return f.useCallback(Nv(...e),e)}jv(Pv,`useComposedRefs`);var Fv=Object.defineProperty,Iv=(e,t)=>Fv(e,`name`,{value:t,configurable:!0});function Lv(e){let t=f.forwardRef((t,n)=>{let{children:r,...i}=t,a=null,o=!1,s=[];r=Jv(r),f.Children.forEach(r,e=>{if(Wv(e)){o=!0;let t=e,n=`child`in t.props?t.props.child:t.props.children;for(;Kv(n)&&typeof Qv==`function`;)n=Qv(n._payload);a=Vv(t,n),s.push(a?.props?.children)}else s.push(e)}),a?a=f.cloneElement(a,void 0,s):!o&&f.Children.count(r)===1&&f.isValidElement(r)&&(a=r);let c=a?Uv(a):void 0,l=Pv(n,c);if(!a){if(r||r===0)throw Error(o?Zv(e):Xv(e));return r}let u=Hv(i,a.props??{});return a.type!==f.Fragment&&(u.ref=n?l:c),f.cloneElement(a,u)});return t.displayName=`${e}.Slot`,t}Iv(Lv,`createSlot`);var Rv=Lv(`Slot`),zv=Symbol.for(`radix.slottable`);function Bv(e){let t=Iv(e=>`child`in e?e.children(e.child):e.children,`Slottable`);return t.displayName=`${e}.Slottable`,t.__radixId=zv,t}Iv(Bv,`createSlottable`);var Vv=Iv((e,t)=>`child`in e.props?f.isValidElement(t)?f.cloneElement(t,void 0,e.props.children(t.props.children)):null:f.isValidElement(t)?t:null,`getSlottableElementFromSlottable`);function Hv(e,t){let n={...t};for(let r in t){let i=e[r],a=t[r];/^on[A-Z]/.test(r)?i&&a?n[r]=(...e)=>{let t=a(...e);return i(...e),t}:i&&(n[r]=i):r===`style`?n[r]={...i,...a}:r===`className`?n[r]=[i,a].filter(Boolean).join(` `):r===`aria-describedby`&&(n[r]=Yv(a,i))}return{...e,...n}}Iv(Hv,`mergeProps`);function Uv(e){let t=Object.getOwnPropertyDescriptor(e.props,`ref`)?.get,n=t&&`isReactWarning`in t&&t.isReactWarning;return n?e.ref:(t=Object.getOwnPropertyDescriptor(e,`ref`)?.get,n=t&&`isReactWarning`in t&&t.isReactWarning,n?e.props.ref:e.props.ref||e.ref)}Iv(Uv,`getElementRef`);function Wv(e){return f.isValidElement(e)&&typeof e.type==`function`&&`__radixId`in e.type&&e.type.__radixId===zv}Iv(Wv,`isSlottable`);var Gv=Symbol.for(`react.lazy`);function Kv(e){return typeof e==`object`&&!!e&&`$$typeof`in e&&e.$$typeof===Gv&&`_payload`in e&&qv(e._payload)}Iv(Kv,`isLazyComponent`);function qv(e){return typeof e==`object`&&!!e&&`then`in e}Iv(qv,`isPromiseLike`);function Jv(e){let t=e;for(;Kv(t)&&typeof Qv==`function`;)t=Qv(t._payload);return t}Iv(Jv,`useUnwrappedLazy`);function Yv(...e){let t=new Set;for(let n of e)if(typeof n==`string`)for(let e of String(n).trim().split(/\s+/))e&&t.add(e);return t.size>0?Array.from(t).join(` `):void 0}Iv(Yv,`concatAriaDescribedby`);var Xv=Iv(e=>`${e} failed to slot onto its children. Expected a single React element child or \`Slottable\`.`,`createSlotError`),Zv=Iv(e=>`${e} failed to slot onto its \`Slottable\`. Expected \`Slottable\` to receive a single React element child.`,`createSlottableError`),Qv=f.use,$v=Object.defineProperty,ey=(e,t)=>$v(e,`name`,{value:t,configurable:!0}),ty=[`a`,`button`,`div`,`form`,`h2`,`h3`,`img`,`input`,`label`,`li`,`nav`,`ol`,`p`,`select`,`span`,`svg`,`ul`].reduce((e,t)=>{let n=Lv(`Primitive.${t}`),r=f.forwardRef((e,r)=>{let{asChild:i,...a}=e,o=i?n:t;return typeof window<`u`&&(window[Symbol.for(`radix-ui`)]=!0),(0,J.jsx)(o,{...a,ref:r})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{});function ny(e,t){e&&p.flushSync(()=>e.dispatchEvent(t))}ey(ny,`dispatchDiscreteCustomEvent`);var ry=Object.defineProperty,iy=(e,t)=>ry(e,`name`,{value:t,configurable:!0});function ay(e,t){let n=f.createContext(t);n.displayName=e+`Context`;let r=iy(e=>{let{children:t,...r}=e,i=f.useMemo(()=>r,Object.values(r));return(0,J.jsx)(n.Provider,{value:i,children:t})},`Provider`);r.displayName=e+`Provider`;function i(r,i={}){let{optional:a=!1}=i,o=f.useContext(n);if(o)return o;if(t!==void 0)return t;if(!a)throw Error(`\`${r}\` must be used within \`${e}\``)}return iy(i,`useContext`),[r,i]}iy(ay,`createContext`);function oy(e,t=[]){let n=[];function r(t,r){let i=f.createContext(r);i.displayName=t+`Context`;let a=n.length;n=[...n,r];let o=iy(t=>{let{scope:n,children:r,...o}=t,s=n?.[e]?.[a]||i,c=f.useMemo(()=>o,Object.values(o));return(0,J.jsx)(s.Provider,{value:c,children:r})},`Provider`);o.displayName=t+`Provider`;function s(n,o,s={}){let{optional:c=!1}=s,l=o?.[e]?.[a]||i,u=f.useContext(l);if(u)return u;if(r!==void 0)return r;if(!c)throw Error(`\`${n}\` must be used within \`${t}\``)}return iy(s,`useContext`),[o,s]}iy(r,`createContext`);let i=iy(()=>{let t=n.map(e=>f.createContext(e));return iy(function(n){let r=n?.[e]||t;return f.useMemo(()=>({[`__scope${e}`]:{...n,[e]:r}}),[n,r])},`useScope`)},`createScope`);return i.scopeName=e,[r,sy(i,...t)]}iy(oy,`createContextScope`);function sy(...e){let t=e[0];if(e.length===1)return t;let n=iy(()=>{let n=e.map(e=>({useScope:e(),scopeName:e.scopeName}));return iy(function(e){let r=n.reduce((t,{useScope:n,scopeName:r})=>{let i=n(e)[`__scope${r}`];return{...t,...i}},{});return f.useMemo(()=>({[`__scope${t.scopeName}`]:r}),[r])},`useComposedScopes`)},`createScope`);return n.scopeName=t.scopeName,n}iy(sy,`composeContextScopes`);var cy=globalThis?.document?f.useLayoutEffect:()=>{},ly=Object.defineProperty,uy=(e,t)=>ly(e,`name`,{value:t,configurable:!0});function dy(e){let t=e+`CollectionProvider`,[n,r]=oy(t),[i,a]=n(t,{collectionRef:{current:null},itemMap:new Map}),o=uy(e=>{let{scope:t,children:n}=e,r=f.useRef(null),a=f.useRef(new Map).current;return(0,J.jsx)(i,{scope:t,itemMap:a,collectionRef:r,children:n})},`CollectionProvider`);o.displayName=t;let s=e+`CollectionSlot`,c=Lv(s),l=f.forwardRef((e,t)=>{let{scope:n,children:r}=e,i=Pv(t,a(s,n).collectionRef);return(0,J.jsx)(c,{ref:i,children:r})});l.displayName=s;let u=e+`CollectionItemSlot`,d=`data-radix-collection-item`,p=Lv(u),m=f.forwardRef((e,t)=>{let{scope:n,children:r,...i}=e,o=f.useRef(null),s=Pv(t,o),c=a(u,n);return f.useEffect(()=>(c.itemMap.set(o,{ref:o,...i}),()=>void c.itemMap.delete(o))),(0,J.jsx)(p,{[d]:``,ref:s,children:r})});m.displayName=u;function h(t){let n=a(e+`CollectionConsumer`,t);return f.useCallback(()=>{let e=n.collectionRef.current;if(!e)return[];let t=Array.from(e.querySelectorAll(`[${d}]`));return Array.from(n.itemMap.values()).sort((e,n)=>t.indexOf(e.ref.current)-t.indexOf(n.ref.current))},[n.collectionRef,n.itemMap])}return uy(h,`useCollection`),[{Provider:o,Slot:l,ItemSlot:m},h,r]}uy(dy,`createCollection`);var fy=new WeakMap,py=class e extends Map{static{uy(this,`OrderedDict`)}#e;constructor(e){super(e),this.#e=[...super.keys()],fy.set(this,!0)}set(e,t){return fy.get(this)&&!this.has(e)&&this.#e.push(e),super.set(e,t),this}insert(e,t,n){let r=this.has(t),i=r?this.size:this.size+1,a=gy(e),o=a>=0?Math.min(a,i-1):Math.max(i+a,0);if(r?this.#e.indexOf(t)===o:o===this.size)return this.set(t,n),this;let s=this.#e.filter(e=>e!==t);s.splice(o,0,t);let c=s.map(e=>[e,e===t?n:this.get(e)]);this.clear();for(let[e,t]of c)this.set(e,t);return this}with(t,n,r){let i=new e(this);return i.insert(t,n,r),i}before(e){let t=this.#e.indexOf(e)-1;if(!(t<0))return this.entryAt(t)}setBefore(e,t,n){let r=this.#e.indexOf(e);if(r===-1)return this;let i=this.#e.indexOf(t),a=i!==-1&&i<r?r-1:r;return this.insert(a,t,n)}after(e){let t=this.#e.indexOf(e);if(t=t===-1||t===this.size-1?-1:t+1,t!==-1)return this.entryAt(t)}setAfter(e,t,n){let r=this.#e.indexOf(e);if(r===-1)return this;let i=this.#e.indexOf(t),a=i!==-1&&i<=r?r:r+1;return this.insert(a,t,n)}first(){return this.entryAt(0)}last(){return this.entryAt(-1)}clear(){return this.#e=[],super.clear()}delete(e){let t=super.delete(e);return t&&this.#e.splice(this.#e.indexOf(e),1),t}deleteAt(e){let t=this.keyAt(e);return t!==void 0&&this.delete(t)}at(e){let t=my(this.#e,e);if(t!==void 0)return this.get(t)}entryAt(e){let t=my(this.#e,e);if(t!==void 0)return[t,this.get(t)]}indexOf(e){return this.#e.indexOf(e)}keyAt(e){return my(this.#e,e)}from(e,t){let n=this.indexOf(e);if(n===-1)return;let r=n+t;return r<0&&(r=0),r>=this.size&&(r=this.size-1),this.at(r)}keyFrom(e,t){let n=this.indexOf(e);if(n===-1)return;let r=n+t;return r<0&&(r=0),r>=this.size&&(r=this.size-1),this.keyAt(r)}find(e,t){let n=0;for(let r of this){if(Reflect.apply(e,t,[r,n,this]))return r;n++}}findIndex(e,t){let n=0;for(let r of this){if(Reflect.apply(e,t,[r,n,this]))return n;n++}return-1}filter(t,n){let r=[],i=0;for(let e of this)Reflect.apply(t,n,[e,i,this])&&r.push(e),i++;return new e(r)}map(t,n){let r=[],i=0;for(let e of this)r.push([e[0],Reflect.apply(t,n,[e,i,this])]),i++;return new e(r)}reduce(...e){let[t,n]=e,r=e.length>1;if(!r&&this.size===0)throw TypeError(`Reduce of empty OrderedDict with no initial value`);let i=0,a=n;for(let e of this)a=i===0&&!r?e:Reflect.apply(t,this,[a,e,i,this]),i++;return a}reduceRight(...e){let[t,n]=e,r=e.length>1;if(!r&&this.size===0)throw TypeError(`Reduce of empty OrderedDict with no initial value`);let i=n;for(let e=this.size-1;e>=0;e--){let n=this.entryAt(e);i=e===this.size-1&&!r?n:Reflect.apply(t,this,[i,n,e,this])}return i}sort(e){if(typeof e!=`function`)throw TypeError(`OrderedDict.sort requires a compare function`);let t=[...this.entries()].sort(e);this.clear();for(let[e,n]of t)this.set(e,n);return this}toSorted(t){if(typeof t!=`function`)throw TypeError(`OrderedDict.toSorted requires a compare function`);let n=[...this.entries()].sort(t);return new e(n)}toReversed(){let t=new e;for(let e=this.size-1;e>=0;e--){let n=this.keyAt(e),r=this.get(n);t.set(n,r)}return t}toSpliced(...t){let n=[...this.entries()];return n.splice(...t),new e(n)}slice(t,n){let r=new e;for(let e of this.#e.slice(t,n))r.set(e,this.get(e));return r}every(e,t){let n=0;for(let r of this){if(!Reflect.apply(e,t,[r,n,this]))return!1;n++}return!0}some(e,t){let n=0;for(let r of this){if(Reflect.apply(e,t,[r,n,this]))return!0;n++}return!1}};function my(e,t){if(`at`in Array.prototype)return Array.prototype.at.call(e,t);let n=hy(e,t);return n===-1?void 0:e[n]}uy(my,`at`);function hy(e,t){let n=e.length,r=gy(t),i=r>=0?r:n+r;return i<0||i>=n?-1:i}uy(hy,`toSafeIndex`);function gy(e){return e!==e||e===0?0:Math.trunc(e)}uy(gy,`toSafeInteger`);function _y(e){let t=e+`CollectionProvider`,[n,r]=oy(t),[i,a]=n(t);i.displayName=e+`CollectionStableContextProvider`;let[o,s]=n(t);o.displayName=e+`CollectionStatefulContextProvider`;let c=uy(({state:e,...t})=>e?(0,J.jsx)(u,{...t,state:e}):(0,J.jsx)(l,{...t}),`CollectionProvider`);c.displayName=t;let l=uy(e=>{let t=v();return(0,J.jsx)(u,{...e,state:t})},`CollectionInit`);l.displayName=e+`CollectionInit`;let u=uy(e=>{let{scope:t,children:n,state:r}=e,a=f.useRef(null),[s,c]=f.useState(null),l=Pv(a,c),[u,d]=r,p=f.useRef(new py),m=f.useCallback(()=>{let e=p.current;return by(e)||e.sort(xy),e},[]);return f.useEffect(()=>{if(!s)return;let e=Sy(()=>{d(e=>{let t=e.toSorted(xy);return t.some(([t],n)=>e.keyAt(n)!==t)?t:e})});return e.observe(s,{childList:!0,subtree:!0}),()=>{e.disconnect()}},[s,d]),(0,J.jsx)(i,{scope:t,collectionElementRef:l,collectionElementRefObject:a,getCollection:m,setCollection:d,registryRef:p,children:(0,J.jsx)(o,{scope:t,collectionElement:s,collection:u,children:n})})},`CollectionProviderImpl`);u.displayName=e+`CollectionProviderImpl`;let d=e+`CollectionSlot`,p=Lv(d),m=f.forwardRef((e,t)=>{let{scope:n,children:r}=e,i=Pv(t,a(d,n).collectionElementRef);return(0,J.jsx)(p,{ref:i,children:r})});m.displayName=d;let h=e+`CollectionItemSlot`,g=Lv(h),_=f.forwardRef((e,t)=>{let{scope:n,children:r,...i}=e,o=f.useRef(null),{setCollection:s,registryRef:c}=a(h,n),l=f.useRef(i);vy(l.current,i)||(l.current=i);let u=l.current,d=Pv(t,f.useCallback(e=>{let t=c.current;e?t.set(e,{...l.current,element:e}):o.current&&t.delete(o.current)},[c]),o);cy(()=>{let e=o.current,t=c.current;e&&t.has(e)&&t.set(e,{...u,element:e})},[u,c]);let p=f.useRef(null);return f.useEffect(()=>{let e=o.current,t=p.current;((t?.element??null)!==e||e&&t?.itemData!==u)&&(p.current=e?{element:e,itemData:u}:null,s(n=>{let r=new py(n);return t&&t.element!==e&&r.delete(t.element),e&&r.set(e,{...u,element:e}),r.sort(xy)}))}),f.useEffect(()=>()=>{let e=p.current;p.current=null,e&&s(t=>{if(!t.has(e.element))return t;let n=new py(t);return n.delete(e.element),n})},[s]),(0,J.jsx)(g,{"data-radix-collection-item":``,ref:d,children:r})});_.displayName=h;function v(){return f.useState(new py)}uy(v,`useInitCollection`);function y(t){let{collection:n}=s(e+`CollectionConsumer`,t);return n}uy(y,`useCollection`);function b(t){let{getCollection:n}=a(e+`CollectionConsumer`,t);return n}return uy(b,`useGetCollection`),[{Provider:c,Slot:m,ItemSlot:_},{createCollectionScope:r,useCollection:y,useGetCollection:b,useInitCollection:v}]}uy(_y,`createCollection`);function vy(e,t){if(e===t)return!0;if(typeof e!=`object`||typeof t!=`object`||e==null||t==null)return!1;let n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;for(let r of n)if(!Object.prototype.hasOwnProperty.call(t,r)||e[r]!==t[r])return!1;return!0}uy(vy,`shallowEqual`);function yy(e,t){return!!(t.compareDocumentPosition(e)&Node.DOCUMENT_POSITION_PRECEDING)}uy(yy,`isElementPreceding`);function by(e){let t;for(let n of e.keys()){if(t){let e=t.compareDocumentPosition(n);if(!(e&Node.DOCUMENT_POSITION_DISCONNECTED)&&e&Node.DOCUMENT_POSITION_PRECEDING)return!1}t=n}return!0}uy(by,`isInDocumentOrder`);function xy(e,t){return!e[1].element||!t[1].element?0:yy(e[1].element,t[1].element)?-1:1}uy(xy,`sortByDocumentPosition`);function Sy(e){return new MutationObserver(t=>{for(let n of t)if(n.type===`childList`){e();return}})}uy(Sy,`getChildListObserver`);var Cy=Object.defineProperty,wy=(e,t)=>Cy(e,`name`,{value:t,configurable:!0}),Ty=!!(typeof window<`u`&&window.document&&window.document.createElement);function Ey(e,t,{checkForDefaultPrevented:n=!0}={}){return wy(function(r){if(e?.(r),n===!1||!r||!r.defaultPrevented)return t?.(r)},`handleEvent`)}wy(Ey,`composeEventHandlers`);function Dy(e){if(!Ty)throw Error(`Cannot access window outside of the DOM`);return e?.ownerDocument?.defaultView??window}wy(Dy,`getOwnerWindow`);function Oy(e){if(!Ty)throw Error(`Cannot access document outside of the DOM`);return e?.ownerDocument??document}wy(Oy,`getOwnerDocument`);function ky(e,t=!1){let{activeElement:n}=Oy(e);if(!n?.nodeName)return null;if(Ay(n)&&n.contentDocument)return ky(n.contentDocument.body,t);if(t){let e=n.getAttribute(`aria-activedescendant`);if(e){let t=Oy(n).getElementById(e);if(t)return t}}return n}wy(ky,`getActiveElement`);function Ay(e){return e.tagName===`IFRAME`}wy(Ay,`isFrame`);var jy=Object.defineProperty,My=(e,t)=>jy(e,`name`,{value:t,configurable:!0}),Ny=f.useInsertionEffect;function Py(e){let t=f.useRef(e);return typeof Ny==`function`?Ny(()=>{t.current=e}):cy(()=>{t.current=e}),f.useMemo(()=>((...e)=>t.current?.(...e)),[])}My(Py,`useCallbackRef`);var Fy=Object.defineProperty,Iy=(e,t)=>Fy(e,`name`,{value:t,configurable:!0}),Ly=`dismissableLayer.update`,Ry=`dismissableLayer.pointerDownOutside`,zy=`dismissableLayer.focusOutside`,By,Vy=f.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set,dismissableSurfaces:new Set}),Hy=f.forwardRef(Iy(function(e,t){let{disableOutsidePointerEvents:n=!1,deferPointerDownOutside:r=!1,onEscapeKeyDown:i,onPointerDownOutside:a,onFocusOutside:o,onInteractOutside:s,onDismiss:c,...l}=e,u=f.useContext(Vy),[d,p]=f.useState(null),m=d?.ownerDocument??globalThis?.document,[,h]=f.useState({}),g=Pv(t,p),_=Array.from(u.layers),[v]=[...u.layersWithOutsidePointerEventsDisabled].slice(-1),y=v?_.indexOf(v):-1,b=d?_.indexOf(d):-1,x=u.layersWithOutsidePointerEventsDisabled.size>0,S=b>=y,C=f.useRef(!1),w=Gy(e=>{a?.(e),s?.(e),e.defaultPrevented||c?.()},{ownerDocument:m,deferPointerDownOutside:r,isDeferredPointerDownOutsideRef:C,dismissableSurfaces:u.dismissableSurfaces,shouldHandlePointerDownOutside:f.useCallback(e=>{if(!(e instanceof Node))return!1;let t=[...u.branches].some(t=>t.contains(e));return S&&!t},[u.branches,S])}),T=Ky(e=>{if(r&&C.current)return;let t=e.target;[...u.branches].some(e=>e.contains(t))||(o?.(e),s?.(e),e.defaultPrevented||c?.())},m),E=d?b===_.length-1:!1,D=Py(e=>{e.key===`Escape`&&(i?.(e),!e.defaultPrevented&&c&&(e.preventDefault(),c()))});return f.useEffect(()=>{if(E)return m.addEventListener(`keydown`,D,{capture:!0}),()=>m.removeEventListener(`keydown`,D,{capture:!0})},[m,E,D]),f.useEffect(()=>{if(d)return n&&(u.layersWithOutsidePointerEventsDisabled.size===0&&(By=m.body.style.pointerEvents,m.body.style.pointerEvents=`none`),u.layersWithOutsidePointerEventsDisabled.add(d)),u.layers.add(d),qy(),()=>{n&&(u.layersWithOutsidePointerEventsDisabled.delete(d),u.layersWithOutsidePointerEventsDisabled.size===0&&(m.body.style.pointerEvents=By))}},[d,m,n,u]),f.useEffect(()=>()=>{d&&(u.layers.delete(d),u.layersWithOutsidePointerEventsDisabled.delete(d),qy())},[d,u]),f.useEffect(()=>{let e=Iy(()=>h({}),`handleUpdate`);return document.addEventListener(Ly,e),()=>document.removeEventListener(Ly,e)},[]),(0,J.jsx)(ty.div,{...l,ref:g,style:{pointerEvents:x?S?`auto`:`none`:void 0,...e.style},onFocusCapture:Ey(e.onFocusCapture,T.onFocusCapture),onBlurCapture:Ey(e.onBlurCapture,T.onBlurCapture),onPointerDownCapture:Ey(e.onPointerDownCapture,w.onPointerDownCapture)})},`DismissableLayer`));function Uy(){let e=f.useContext(Vy),[t,n]=f.useState(null);return f.useEffect(()=>{if(t)return e.dismissableSurfaces.add(t),()=>{e.dismissableSurfaces.delete(t)}},[t,e.dismissableSurfaces]),n}Iy(Uy,`useDismissableLayerSurface`);var Wy=Iy(()=>!0,`IS_TRUE`);function Gy(e,t){let{ownerDocument:n=globalThis?.document,deferPointerDownOutside:r=!1,isDeferredPointerDownOutsideRef:i,dismissableSurfaces:a,shouldHandlePointerDownOutside:o=Wy}=t,s=Py(e),c=f.useRef(!1),l=f.useRef(!1),u=f.useRef(new Map),d=f.useRef(()=>{});return f.useEffect(()=>{function e(){l.current=!1,i.current=!1,u.current.clear()}Iy(e,`resetOutsideInteraction`);function t(){return Array.from(u.current.values()).some(Boolean)}Iy(t,`isOutsideInteractionIntercepted`);function f(e){if(!l.current)return;let t=e.target;t instanceof Node&&[...a].some(e=>e.contains(t))||u.current.set(e.type,!0),e.type===`click`&&window.setTimeout(()=>{l.current&&d.current()},0)}Iy(f,`handleInteractionCapture`);function p(e){l.current&&u.current.set(e.type,!1)}Iy(p,`handleInteractionBubble`);let m=Iy(a=>{if(a.target&&!c.current){let f=function(){n.removeEventListener(`click`,d.current);let r=t();e(),r||Jy(Ry,s,p,{discrete:!0})};if(Iy(f,`handleAndDispatchPointerDownOutsideEvent`),!o(a.target)){n.removeEventListener(`click`,d.current),e(),c.current=!1;return}let p={originalEvent:a};l.current=!0,i.current=r&&a.button===0,u.current.clear(),!r||a.button!==0?f():(n.removeEventListener(`click`,d.current),d.current=f,n.addEventListener(`click`,d.current,{once:!0}))}else n.removeEventListener(`click`,d.current),e();c.current=!1},`handlePointerDown`),h=[`pointerup`,`mousedown`,`mouseup`,`touchstart`,`touchend`,`click`];for(let e of h)n.addEventListener(e,f,!0),n.addEventListener(e,p);let g=window.setTimeout(()=>{n.addEventListener(`pointerdown`,m)},0);return()=>{window.clearTimeout(g),n.removeEventListener(`pointerdown`,m),n.removeEventListener(`click`,d.current);for(let e of h)n.removeEventListener(e,f,!0),n.removeEventListener(e,p)}},[n,s,r,i,a,o]),{onPointerDownCapture:Iy(()=>c.current=!0,`onPointerDownCapture`)}}Iy(Gy,`usePointerDownOutside`);function Ky(e,t=globalThis?.document){let n=Py(e),r=f.useRef(!1);return f.useEffect(()=>{let e=Iy(e=>{e.target&&!r.current&&Jy(zy,n,{originalEvent:e},{discrete:!1})},`handleFocus`);return t.addEventListener(`focusin`,e),()=>t.removeEventListener(`focusin`,e)},[t,n]),{onFocusCapture:Iy(()=>r.current=!0,`onFocusCapture`),onBlurCapture:Iy(()=>r.current=!1,`onBlurCapture`)}}Iy(Ky,`useFocusOutside`);function qy(){let e=new CustomEvent(Ly);document.dispatchEvent(e)}Iy(qy,`dispatchUpdate`);function Jy(e,t,n,{discrete:r}){let i=n.originalEvent.target,a=new CustomEvent(e,{bubbles:!1,cancelable:!0,detail:n});t&&i.addEventListener(e,t,{once:!0}),r?ny(i,a):i.dispatchEvent(a)}Iy(Jy,`handleAndDispatchCustomEvent`);var Yy=Object.defineProperty,Xy=(e,t)=>Yy(e,`name`,{value:t,configurable:!0}),Zy=0,Qy=null;function $y(e){return eb(),e.children}Xy($y,`FocusGuards`);function eb(){f.useEffect(()=>{Qy||={start:tb(),end:tb()};let{start:e,end:t}=Qy;return document.body.firstElementChild!==e&&document.body.insertAdjacentElement(`afterbegin`,e),document.body.lastElementChild!==t&&document.body.insertAdjacentElement(`beforeend`,t),Zy++,()=>{Zy===1&&(Qy?.start.remove(),Qy?.end.remove(),Qy=null),Zy=Math.max(0,Zy-1)}},[])}Xy(eb,`useFocusGuards`);function tb(){let e=document.createElement(`span`);return e.setAttribute(`data-radix-focus-guard`,``),e.tabIndex=0,e.style.outline=`none`,e.style.opacity=`0`,e.style.position=`fixed`,e.style.pointerEvents=`none`,e}Xy(tb,`createFocusGuard`);var nb=Object.defineProperty,rb=(e,t)=>nb(e,`name`,{value:t,configurable:!0}),ib=`focusScope.autoFocusOnMount`,ab=`focusScope.autoFocusOnUnmount`,ob={bubbles:!1,cancelable:!0},sb=f.forwardRef(rb(function(e,t){let{loop:n=!1,trapped:r=!1,branches:i,onMountAutoFocus:a,onUnmountAutoFocus:o,...s}=e,[c,l]=f.useState(null),u=Py(a),d=Py(o),p=f.useRef(null),m=Pv(t,l),h=f.useRef(i);f.useEffect(()=>{h.current=i});let g=f.useCallback(e=>e?c?.contains(e)?!0:!!h.current?.some(t=>t.contains(e)):!1,[c]),_=f.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;f.useEffect(()=>{if(r){let e=function(e){if(_.paused||!c)return;let t=e.target;g(t)?p.current=t:vb(p.current,{select:!0})},t=function(e){if(_.paused||!c)return;let t=e.relatedTarget;t!==null&&(g(t)||vb(p.current,{select:!0}))},n=function(e){if(document.activeElement===document.body)for(let t of e)t.removedNodes.length>0&&vb(c)};rb(e,`handleFocusIn`),rb(t,`handleFocusOut`),rb(n,`handleMutations`),document.addEventListener(`focusin`,e),document.addEventListener(`focusout`,t);let r=new MutationObserver(n);return c&&r.observe(c,{childList:!0,subtree:!0}),()=>{document.removeEventListener(`focusin`,e),document.removeEventListener(`focusout`,t),r.disconnect()}}},[r,c,_.paused,g]),f.useEffect(()=>{if(c){yb.add(_);let e=document.activeElement;if(!c.contains(e)){let t=new CustomEvent(ib,ob);c.addEventListener(ib,u),c.dispatchEvent(t),t.defaultPrevented||(fb(Sb(mb(c)),{select:!0}),document.activeElement===e&&vb(c))}return()=>{c.removeEventListener(ib,u);let t=c.ownerDocument,n=CustomEvent;setTimeout(()=>{let r=new n(ab,ob);c.addEventListener(ab,d),c.dispatchEvent(r),r.defaultPrevented||vb(e??t.body,{select:!0}),c.removeEventListener(ab,d),yb.remove(_)},0)}}},[c,u,d,_]);let v=f.useCallback(e=>{if(!n&&!r||_.paused)return;let t=e.key===`Tab`&&!e.altKey&&!e.ctrlKey&&!e.metaKey,i=document.activeElement;if(t&&i){let t=e.currentTarget,[r,a]=pb(t);r&&a?!e.shiftKey&&i===a?(e.preventDefault(),n&&vb(r,{select:!0})):e.shiftKey&&i===r&&(e.preventDefault(),n&&vb(a,{select:!0})):i===t&&e.preventDefault()}},[n,r,_.paused]);return(0,J.jsx)(ty.div,{tabIndex:-1,...s,ref:m,onKeyDown:v})},`FocusScope`)),cb=f.createContext(null);function lb({registry:e,children:t}){return e?(0,J.jsx)(cb.Provider,{value:e,children:t}):t}rb(lb,`FocusScopeBranchProvider`);function ub(){let[e,t]=f.useState([]);return{nodes:e,registry:f.useMemo(()=>({add:rb(e=>t(t=>t.includes(e)?t:[...t,e]),`add`),remove:rb(e=>t(t=>t.filter(t=>t!==e)),`remove`)}),[])}}rb(ub,`useFocusScopeBranchRegistry`);function db(e){let t=f.useContext(cb);f.useEffect(()=>{if(e&&t)return t.add(e),()=>t.remove(e)},[e,t])}rb(db,`useFocusScopeBranch`);function fb(e,{select:t=!1}={}){let n=document.activeElement;for(let r of e)if(vb(r,{select:t}),document.activeElement!==n)return}rb(fb,`focusFirst`);function pb(e){let t=mb(e);return[hb(t,e),hb(t.reverse(),e)]}rb(pb,`getTabbableEdges`);function mb(e){let t=[],n=e.ownerDocument.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:rb(e=>{let t=e.tagName===`INPUT`&&e.type===`hidden`;return e.disabled||e.hidden||t?NodeFilter.FILTER_SKIP:e.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP},`acceptNode`)});for(;n.nextNode();)t.push(n.currentNode);return t}rb(mb,`getTabbableCandidates`);function hb(e,t){let n=typeof t.checkVisibility==`function`&&t.checkVisibility({checkVisibilityCSS:!0});for(let r of e)if(!(n?!r.checkVisibility({checkVisibilityCSS:!0}):gb(r,{upTo:t})))return r}rb(hb,`findVisible`);function gb(e,{upTo:t}){if(getComputedStyle(e).visibility===`hidden`)return!0;for(;e;){if(t!==void 0&&e===t)return!1;if(getComputedStyle(e).display===`none`)return!0;e=e.parentElement}return!1}rb(gb,`isHidden`);function _b(e){return e.tagName===`INPUT`&&typeof e.select==`function`}rb(_b,`isSelectableInput`);function vb(e,{select:t=!1}={}){if(e&&e.focus){let n=(e.ownerDocument??document).activeElement;e.focus({preventScroll:!0}),e!==n&&_b(e)&&t&&e.select()}}rb(vb,`focus`);var yb=bb();function bb(){let e=[];return{add(t){let n=e[0];t!==n&&n?.pause(),e=xb(e,t),e.unshift(t)},remove(t){e=xb(e,t),e[0]?.resume()}}}rb(bb,`createFocusScopesStack`);function xb(e,t){let n=[...e],r=n.indexOf(t);return r!==-1&&n.splice(r,1),n}rb(xb,`arrayRemove`);function Sb(e){return e.filter(e=>e.tagName!==`A`)}rb(Sb,`removeLinks`);var Cb=Object.defineProperty,wb=(e,t)=>Cb(e,`name`,{value:t,configurable:!0}),Tb={LTR:`ltr`,RTL:`rtl`},Eb=f.createContext(void 0);function Db(e){let t=f.useContext(Eb);return e||t||Tb.LTR}wb(Db,`useDirection`);var Ob=Object.defineProperty,kb=(e,t)=>Ob(e,`name`,{value:t,configurable:!0}),Ab=f.useId||(()=>void 0),jb=0;function Mb(e){let[t,n]=f.useState(Ab());return cy(()=>{e||n(e=>e??String(jb++))},[e]),e||(t?`radix-${t}`:``)}kb(Mb,`useId`);var Nb=[`top`,`right`,`bottom`,`left`],Pb=Math.min,Fb=Math.max,Ib=Math.round,Lb=Math.floor,Rb=e=>({x:e,y:e}),zb={left:`right`,right:`left`,bottom:`top`,top:`bottom`};function Bb(e,t,n){return Fb(e,Pb(t,n))}function Vb(e,t){return typeof e==`function`?e(t):e}function Hb(e){return e.split(`-`)[0]}function Ub(e){return e.split(`-`)[1]}function Wb(e){return e===`x`?`y`:`x`}function Gb(e){return e===`y`?`height`:`width`}function Kb(e){let t=e[0];return t===`t`||t===`b`?`y`:`x`}function qb(e){return Wb(Kb(e))}function Jb(e,t,n){n===void 0&&(n=!1);let r=Ub(e),i=qb(e),a=Gb(i),o=i===`x`?r===(n?`end`:`start`)?`right`:`left`:r===`start`?`bottom`:`top`;return t.reference[a]>t.floating[a]&&(o=rx(o)),[o,rx(o)]}function Yb(e){let t=rx(e);return[Xb(e),t,Xb(t)]}function Xb(e){return e.includes(`start`)?e.replace(`start`,`end`):e.replace(`end`,`start`)}var Zb=[`left`,`right`],Qb=[`right`,`left`],$b=[`top`,`bottom`],ex=[`bottom`,`top`];function tx(e,t,n){switch(e){case`top`:case`bottom`:return n?t?Qb:Zb:t?Zb:Qb;case`left`:case`right`:return t?$b:ex;default:return[]}}function nx(e,t,n,r){let i=Ub(e),a=tx(Hb(e),n===`start`,r);return i&&(a=a.map(e=>e+`-`+i),t&&(a=a.concat(a.map(Xb)))),a}function rx(e){let t=Hb(e);return zb[t]+e.slice(t.length)}function ix(e){return{top:e.top??0,right:e.right??0,bottom:e.bottom??0,left:e.left??0}}function ax(e){return typeof e==`number`?{top:e,right:e,bottom:e,left:e}:ix(e)}function ox(e){let{x:t,y:n,width:r,height:i}=e;return{width:r,height:i,top:n,left:t,right:t+r,bottom:n+i,x:t,y:n}}function sx(e,t,n){let{reference:r,floating:i}=e,a=Kb(t),o=qb(t),s=Gb(o),c=Hb(t),l=a===`y`,u=r.x+r.width/2-i.width/2,d=r.y+r.height/2-i.height/2,f=r[s]/2-i[s]/2,p;switch(c){case`top`:p={x:u,y:r.y-i.height};break;case`bottom`:p={x:u,y:r.y+r.height};break;case`right`:p={x:r.x+r.width,y:d};break;case`left`:p={x:r.x-i.width,y:d};break;default:p={x:r.x,y:r.y}}let m=Ub(t);return m&&(p[o]+=f*(m===`end`?1:-1)*(n&&l?-1:1)),p}async function cx(e,t){t===void 0&&(t={});let{x:n,y:r,platform:i,rects:a,elements:o,strategy:s}=e,{boundary:c=`clippingAncestors`,rootBoundary:l=`viewport`,elementContext:u=`floating`,altBoundary:d=!1,padding:f=0}=Vb(t,e),p=ax(f),m=o[d?u===`floating`?`reference`:`floating`:u],h=ox(await i.getClippingRect({element:await(i.isElement==null?void 0:i.isElement(m))??!0?m:m.contextElement||await(i.getDocumentElement==null?void 0:i.getDocumentElement(o.floating)),boundary:c,rootBoundary:l,strategy:s})),g=u===`floating`?{x:n,y:r,width:a.floating.width,height:a.floating.height}:a.reference,_=await(i.getOffsetParent==null?void 0:i.getOffsetParent(o.floating)),v=await(i.isElement==null?void 0:i.isElement(_))&&await(i.getScale==null?void 0:i.getScale(_))||{x:1,y:1},y=ox(i.convertOffsetParentRelativeRectToViewportRelativeRect?await i.convertOffsetParentRelativeRectToViewportRelativeRect({elements:o,rect:g,offsetParent:_,strategy:s}):g);return{top:(h.top-y.top+p.top)/v.y,bottom:(y.bottom-h.bottom+p.bottom)/v.y,left:(h.left-y.left+p.left)/v.x,right:(y.right-h.right+p.right)/v.x}}var lx=50,ux=async(e,t,n)=>{let{placement:r=`bottom`,strategy:i=`absolute`,middleware:a=[],platform:o}=n,s=o.detectOverflow?o:{...o,detectOverflow:cx},c=await(o.isRTL==null?void 0:o.isRTL(t)),l=await o.getElementRects({reference:e,floating:t,strategy:i}),{x:u,y:d}=sx(l,r,c),f=r,p=0,m={};for(let n=0;n<a.length;n++){let h=a[n];if(!h)continue;let{name:g,fn:_}=h,{x:v,y,data:b,reset:x}=await _({x:u,y:d,initialPlacement:r,placement:f,strategy:i,middlewareData:m,rects:l,platform:s,elements:{reference:e,floating:t}});u=v??u,d=y??d,m[g]={...m[g],...b},x&&p<lx&&(p++,typeof x==`object`&&(x.placement&&(f=x.placement),x.rects&&(l=x.rects===!0?await o.getElementRects({reference:e,floating:t,strategy:i}):x.rects),{x:u,y:d}=sx(l,f,c)),n=-1)}return{x:u,y:d,placement:f,strategy:i,middlewareData:m}},dx=e=>({name:`arrow`,options:e,async fn(t){let{x:n,y:r,placement:i,rects:a,platform:o,elements:s,middlewareData:c}=t,{element:l,padding:u=0}=Vb(e,t)||{};if(l==null)return{};let d=ax(u),f={x:n,y:r},p=qb(i),m=Gb(p),h=await o.getDimensions(l),g=p===`y`,_=g?`top`:`left`,v=g?`bottom`:`right`,y=g?`clientHeight`:`clientWidth`,b=a.reference[m]+a.reference[p]-f[p]-a.floating[m],x=f[p]-a.reference[p],S=await(o.getOffsetParent==null?void 0:o.getOffsetParent(l)),C=S?S[y]:0;C&&await(o.isElement==null?void 0:o.isElement(S))||(C=s.floating[y]||a.floating[m]);let w=b/2-x/2,T=C/2-h[m]/2-1,E=Pb(d[_],T),D=Pb(d[v],T),O=C-h[m]-D,k=C/2-h[m]/2+w,A=Bb(E,k,O),j=!c.arrow&&Ub(i)!=null&&k!==A&&a.reference[m]/2-(k<E?E:D)-h[m]/2<0,M=j?k<E?k-E:k-O:0;return{[p]:f[p]+M,data:{[p]:A,centerOffset:k-A-M,...j&&{alignmentOffset:M}},reset:j}}}),fx=function(e){return e===void 0&&(e={}),{name:`flip`,options:e,async fn(t){var n;let{placement:r,middlewareData:i,rects:a,initialPlacement:o,platform:s,elements:c}=t,{mainAxis:l=!0,crossAxis:u=!0,fallbackPlacements:d,fallbackStrategy:f=`bestFit`,fallbackAxisSideDirection:p=`none`,flipAlignment:m=!0,...h}=Vb(e,t);if((n=i.arrow)!=null&&n.alignmentOffset)return{};let g=Hb(r),_=Kb(o),v=Hb(o)===o,y=await(s.isRTL==null?void 0:s.isRTL(c.floating)),b=d||(v||!m?[rx(o)]:Yb(o)),x=p!==`none`;!d&&x&&b.push(...nx(o,m,p,y));let S=[o,...b],C=await s.detectOverflow(t,h),w=[],T=i.flip?.overflows||[];if(l&&w.push(C[g]),u){let e=Jb(r,a,y);w.push(C[e[0]],C[e[1]])}if(T=[...T,{placement:r,overflows:w}],!w.every(e=>e<=0)){let e=(i.flip?.index||0)+1,t=S[e];if(t&&(u!==`alignment`||_===Kb(t)||T.every(e=>Kb(e.placement)!==_||e.overflows[0]>0)))return{data:{index:e,overflows:T},reset:{placement:t}};let n=T.filter(e=>e.overflows[0]<=0).sort((e,t)=>e.overflows[1]-t.overflows[1])[0]?.placement;if(!n)switch(f){case`bestFit`:{let e=T.filter(e=>{if(x){let t=Kb(e.placement);return t===_||t===`y`}return!0}).map(e=>[e.placement,e.overflows.filter(e=>e>0).reduce((e,t)=>e+t,0)]).sort((e,t)=>e[1]-t[1])[0]?.[0];e&&(n=e);break}case`initialPlacement`:n=o}if(r!==n)return{reset:{placement:n}}}return{}}}};function px(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function mx(e){return Nb.some(t=>e[t]>=0)}var hx=function(e){return e===void 0&&(e={}),{name:`hide`,options:e,async fn(t){let{rects:n,platform:r}=t,{strategy:i=`referenceHidden`,...a}=Vb(e,t);switch(i){case`referenceHidden`:{let e=px(await r.detectOverflow(t,{...a,elementContext:`reference`}),n.reference);return{data:{referenceHiddenOffsets:e,referenceHidden:mx(e)}}}case`escaped`:{let e=px(await r.detectOverflow(t,{...a,altBoundary:!0}),n.floating);return{data:{escapedOffsets:e,escaped:mx(e)}}}default:return{}}}}},gx=new Set([`left`,`top`]);async function _x(e,t){let{placement:n,platform:r,elements:i}=e,a=await(r.isRTL==null?void 0:r.isRTL(i.floating)),o=Hb(n),s=Ub(n),c=Kb(n)===`y`,l=gx.has(o)?-1:1,u=a&&c?-1:1,d=Vb(t,e),{mainAxis:f,crossAxis:p,alignmentAxis:m}=typeof d==`number`?{mainAxis:d,crossAxis:0,alignmentAxis:null}:{mainAxis:d.mainAxis||0,crossAxis:d.crossAxis||0,alignmentAxis:d.alignmentAxis};return s&&typeof m==`number`&&(p=s===`end`?m*-1:m),c?{x:p*u,y:f*l}:{x:f*l,y:p*u}}var vx=function(e){return e===void 0&&(e=0),{name:`offset`,options:e,async fn(t){var n;let{x:r,y:i,placement:a,middlewareData:o}=t,s=await _x(t,e);return a===o.offset?.placement&&(n=o.arrow)!=null&&n.alignmentOffset?{}:{x:r+s.x,y:i+s.y,data:{...s,placement:a}}}}},yx=function(e){return e===void 0&&(e={}),{name:`shift`,options:e,async fn(t){let{x:n,y:r,placement:i,platform:a}=t,{mainAxis:o=!0,crossAxis:s=!1,limiter:c={fn:e=>{let{x:t,y:n}=e;return{x:t,y:n}}},...l}=Vb(e,t),u={x:n,y:r},d=await a.detectOverflow(t,l),f=Kb(i),p=Wb(f),m=u[p],h=u[f],g=(e,t)=>Bb(t+d[e===`y`?`top`:`left`],t,t-d[e===`y`?`bottom`:`right`]);o&&(m=g(p,m)),s&&(h=g(f,h));let _=c.fn({...t,[p]:m,[f]:h});return{..._,data:{x:_.x-n,y:_.y-r,enabled:{[p]:o,[f]:s}}}}}},bx=function(e){return e===void 0&&(e={}),{options:e,fn(t){let{x:n,y:r,placement:i,rects:a,middlewareData:o}=t,{offset:s=0,mainAxis:c=!0,crossAxis:l=!0}=Vb(e,t),u={x:n,y:r},d=Kb(i),f=Wb(d),p=u[f],m=u[d],h=Vb(s,t),g=typeof h==`number`?{mainAxis:h,crossAxis:0}:{mainAxis:h.mainAxis??0,crossAxis:h.crossAxis??0};if(c){let e=f===`y`?`height`:`width`,t=a.reference[f]-a.floating[e]+g.mainAxis,n=a.reference[f]+a.reference[e]-g.mainAxis;p<t?p=t:p>n&&(p=n)}if(l){let e=f===`y`?`width`:`height`,t=gx.has(Hb(i)),n=a.reference[d]-a.floating[e]+(t&&o.offset?.[d]||0)+(t?0:g.crossAxis),r=a.reference[d]+a.reference[e]+(t?0:o.offset?.[d]||0)-(t?g.crossAxis:0);m<n?m=n:m>r&&(m=r)}return{[f]:p,[d]:m}}}},xx=function(e){return e===void 0&&(e={}),{name:`size`,options:e,async fn(t){let{placement:n,rects:r,platform:i,elements:a}=t,{apply:o=()=>{},...s}=Vb(e,t),c=await i.detectOverflow(t,s),l=Hb(n),u=Ub(n),d=Kb(n)===`y`,{width:f,height:p}=r.floating,m,h;l===`top`||l===`bottom`?(m=l,h=u===(await(i.isRTL==null?void 0:i.isRTL(a.floating))?`start`:`end`)?`left`:`right`):(h=l,m=u===`end`?`top`:`bottom`);let g=p-c.top-c.bottom,_=f-c.left-c.right,v=Pb(p-c[m],g),y=Pb(f-c[h],_),b=t.middlewareData.shift,x=!b,S=v,C=y;b!=null&&b.enabled.x&&(C=_),b!=null&&b.enabled.y&&(S=g),x&&!u&&(d?C=f-2*Fb(c.left,c.right):S=p-2*Fb(c.top,c.bottom)),await o({...t,availableWidth:C,availableHeight:S});let w=await i.getDimensions(a.floating);return f!==w.width||p!==w.height?{reset:{rects:!0}}:{}}}};function Sx(){return typeof window<`u`}function Cx(e){return Ex(e)?(e.nodeName||``).toLowerCase():`#document`}function wx(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function Tx(e){return((Ex(e)?e.ownerDocument:e.document)||window.document)?.documentElement}function Ex(e){return Sx()?e instanceof Node||e instanceof wx(e).Node:!1}function Dx(e){return Sx()?e instanceof Element||e instanceof wx(e).Element:!1}function Ox(e){return Sx()?e instanceof HTMLElement||e instanceof wx(e).HTMLElement:!1}function kx(e){return!Sx()||typeof ShadowRoot>`u`?!1:e instanceof ShadowRoot||e instanceof wx(e).ShadowRoot}function Ax(e){let{overflow:t,overflowX:n,overflowY:r,display:i}=Vx(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&i!==`inline`&&i!==`contents`}function jx(e){return/^(table|td|th)$/.test(Cx(e))}function Mx(e){try{if(e.matches(`:popover-open`))return!0}catch{}try{return e.matches(`:modal`)}catch{return!1}}var Nx=/transform|translate|scale|rotate|perspective|filter/,Px=/paint|layout|strict|content/,Fx=e=>!!e&&e!==`none`,Ix;function Lx(e){let t=Dx(e)?Vx(e):e;return Fx(t.transform)||Fx(t.translate)||Fx(t.scale)||Fx(t.rotate)||Fx(t.perspective)||!zx()&&(Fx(t.backdropFilter)||Fx(t.filter))||Nx.test(t.willChange||``)||Px.test(t.contain||``)}function Rx(e){let t=Ux(e);for(;Ox(t)&&!Bx(t);){if(Lx(t))return t;if(Mx(t))return null;t=Ux(t)}return null}function zx(){return Ix??=typeof CSS<`u`&&CSS.supports&&CSS.supports(`-webkit-backdrop-filter`,`none`),Ix}function Bx(e){return/^(html|body|#document)$/.test(Cx(e))}function Vx(e){return wx(e).getComputedStyle(e)}function Hx(e){return Dx(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function Ux(e){if(Cx(e)===`html`)return e;let t=e.assignedSlot||e.parentNode||kx(e)&&e.host||Tx(e);return kx(t)?t.host:t}function Wx(e){let t=Ux(e);return Bx(t)?(e.ownerDocument||e).body:Ox(t)&&Ax(t)?t:Wx(t)}function Gx(e,t,n){t===void 0&&(t=[]),n===void 0&&(n=!0);let r=Wx(e),i=r===e.ownerDocument?.body,a=wx(r);if(i){let e=Kx(a);return t.concat(a,a.visualViewport||[],Ax(r)?r:[],e&&n?Gx(e):[])}return t.concat(r,Gx(r,[],n))}function Kx(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function qx(e){let t=Vx(e),n=parseFloat(t.width)||0,r=parseFloat(t.height)||0,i=Ox(e),a=i?e.offsetWidth:n,o=i?e.offsetHeight:r,s=Ib(n)!==a||Ib(r)!==o;return s&&(n=a,r=o),{width:n,height:r,$:s}}function Jx(e){return Dx(e)?e:e.contextElement}function Yx(e){let t=Jx(e);if(!Ox(t))return Rb(1);let n=t.getBoundingClientRect(),{width:r,height:i,$:a}=qx(t),o=(a?Ib(n.width):n.width)/r,s=(a?Ib(n.height):n.height)/i;return o&&Number.isFinite(o)||(o=1),s&&Number.isFinite(s)||(s=1),{x:o,y:s}}var Xx=Rb(0);function Zx(e){let t=wx(e);return!zx()||!t.visualViewport?Xx:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function Qx(e,t,n){return t===void 0&&(t=!1),!!n&&t&&n===wx(e)}function $x(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);let i=e.getBoundingClientRect(),a=Jx(e),o=Rb(1);t&&(r?Dx(r)&&(o=Yx(r)):o=Yx(e));let s=Qx(a,n,r)?Zx(a):Rb(0),c=(i.left+s.x)/o.x,l=(i.top+s.y)/o.y,u=i.width/o.x,d=i.height/o.y;if(a&&r){let e=wx(a),t=Dx(r)?wx(r):r,n=e,i=Kx(n);for(;i&&t!==n;){let e=Yx(i),t=i.getBoundingClientRect(),r=Vx(i),a=t.left+(i.clientLeft+parseFloat(r.paddingLeft))*e.x,o=t.top+(i.clientTop+parseFloat(r.paddingTop))*e.y;c*=e.x,l*=e.y,u*=e.x,d*=e.y,c+=a,l+=o,n=wx(i),i=Kx(n)}}return ox({width:u,height:d,x:c,y:l})}function eS(e,t){let n=Hx(e).scrollLeft;return t?t.left+n:$x(Tx(e)).left+n}function tS(e,t){let n=e.getBoundingClientRect();return{x:n.left+t.scrollLeft-eS(e,n),y:n.top+t.scrollTop}}function nS(e){let{elements:t,rect:n,offsetParent:r,strategy:i}=e,a=i===`fixed`,o=Tx(r),s=t?Mx(t.floating):!1;if(r===o||s&&a)return n;let c={scrollLeft:0,scrollTop:0},l=Rb(1),u=Rb(0),d=Ox(r);if((d||!a)&&((Cx(r)!==`body`||Ax(o))&&(c=Hx(r)),d)){let e=$x(r);l=Yx(r),u.x=e.x+r.clientLeft,u.y=e.y+r.clientTop}let f=o&&!d&&!a?tS(o,c):Rb(0);return{width:n.width*l.x,height:n.height*l.y,x:n.x*l.x-c.scrollLeft*l.x+u.x+f.x,y:n.y*l.y-c.scrollTop*l.y+u.y+f.y}}function rS(e){return e.getClientRects?Array.from(e.getClientRects()):[]}function iS(e){let t=Hx(e),n=e.ownerDocument.body,r=Fb(e.scrollWidth,e.clientWidth,n.scrollWidth,n.clientWidth),i=Fb(e.scrollHeight,e.clientHeight,n.scrollHeight,n.clientHeight),a=-t.scrollLeft+eS(e),o=-t.scrollTop;return Vx(n).direction===`rtl`&&(a+=Fb(e.clientWidth,n.clientWidth)-r),{width:r,height:i,x:a,y:o}}var aS=25;function oS(e,t,n){n===void 0&&(n=`viewport`);let r=n===`layoutViewport`,i=wx(e),a=Tx(e),o=i.visualViewport,s=a.clientWidth,c=a.clientHeight,l=0,u=0;if(o){let e=!zx()||t===`fixed`;r?e||(l=-o.offsetLeft,u=-o.offsetTop):(s=o.width,c=o.height,e&&(l=o.offsetLeft,u=o.offsetTop))}if(eS(a)<=0){let e=a.ownerDocument,t=e.body,n=getComputedStyle(t),r=e.compatMode===`CSS1Compat`&&parseFloat(n.marginLeft)+parseFloat(n.marginRight)||0,i=Math.abs(a.clientWidth-t.clientWidth-r),o=getComputedStyle(a).scrollbarGutter===`stable both-edges`?i/2:i;o<=aS&&(s-=o)}return{width:s,height:c,x:l,y:u}}function sS(e,t){let n=$x(e,!0,t===`fixed`),r=n.top+e.clientTop,i=n.left+e.clientLeft,a=Yx(e);return{width:e.clientWidth*a.x,height:e.clientHeight*a.y,x:i*a.x,y:r*a.y}}function cS(e,t,n){let r;if(t===`viewport`||t===`layoutViewport`)r=oS(e,n,t);else if(t===`document`)r=iS(Tx(e));else if(Dx(t))r=sS(t,n);else{let n=Zx(e);r={x:t.x-n.x,y:t.y-n.y,width:t.width,height:t.height}}return ox(r)}function lS(e,t){let n=t.get(e);if(n)return n;let r=Gx(e,[],!1).filter(e=>Dx(e)&&Cx(e)!==`body`),i=null,a=Vx(e).position===`fixed`,o=a?Ux(e):e;for(;Dx(o)&&!Bx(o);){let e=Vx(o),t=Lx(o),n=i?i.position:a?`fixed`:``;!t&&(n===`fixed`||n===`absolute`&&e.position===`static`)?r=r.filter(e=>e!==o):i=e,o=Ux(o)}return t.set(e,r),r}function uS(e){let{element:t,boundary:n,rootBoundary:r,strategy:i}=e,a=[...n===`clippingAncestors`?Mx(t)?[]:lS(t,this._c):[].concat(n),r],o=cS(t,a[0],i),s=o.top,c=o.right,l=o.bottom,u=o.left;for(let e=1;e<a.length;e++){let n=cS(t,a[e],i);s=Fb(n.top,s),c=Pb(n.right,c),l=Pb(n.bottom,l),u=Fb(n.left,u)}return{width:c-u,height:l-s,x:u,y:s}}function dS(e){let{width:t,height:n}=qx(e);return{width:t,height:n}}function fS(e,t,n){let r=Ox(t),i=Tx(t),a=n===`fixed`,o=$x(e,!0,a,t),s={scrollLeft:0,scrollTop:0},c=Rb(0);if((r||!a)&&((Cx(t)!==`body`||Ax(i))&&(s=Hx(t)),r)){let e=$x(t,!0,a,t);c.x=e.x+t.clientLeft,c.y=e.y+t.clientTop}!r&&i&&(c.x=eS(i));let l=i&&!r&&!a?tS(i,s):Rb(0);return{x:o.left+s.scrollLeft-c.x-l.x,y:o.top+s.scrollTop-c.y-l.y,width:o.width,height:o.height}}function pS(e){return Vx(e).position===`static`}function mS(e,t){if(!Ox(e)||Vx(e).position===`fixed`)return null;if(t)return t(e);let n=e.offsetParent;return Tx(e)===n&&(n=n.ownerDocument.body),n}function hS(e,t){let n=wx(e);if(Mx(e))return n;if(!Ox(e)){let t=Ux(e);for(;t&&!Bx(t);){if(Dx(t)&&!pS(t))return t;t=Ux(t)}return n}let r=mS(e,t);for(;r&&jx(r)&&pS(r);)r=mS(r,t);return r&&Bx(r)&&pS(r)&&!Lx(r)?n:r||Rx(e)||n}var gS=async function(e){let t=this.getOffsetParent||hS,n=this.getDimensions,r=await n(e.floating);return{reference:fS(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function _S(e){return Vx(e).direction===`rtl`}var vS={convertOffsetParentRelativeRectToViewportRelativeRect:nS,getDocumentElement:Tx,getClippingRect:uS,getOffsetParent:hS,getElementRects:gS,getClientRects:rS,getDimensions:dS,getScale:Yx,isElement:Dx,isRTL:_S};function yS(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function bS(e,t,n){let r=null,i,a=Tx(e);function o(){var e;clearTimeout(i),(e=r)==null||e.disconnect(),r=null}function s(n,c){n===void 0&&(n=!1),c===void 0&&(c=1),o();let l=e.getBoundingClientRect(),{left:u,top:d,width:f,height:p}=l;if(n||t(),!f||!p)return;let m=Lb(d),h=Lb(a.clientWidth-(u+f)),g=Lb(a.clientHeight-(d+p)),_=Lb(u),v={rootMargin:-m+`px `+-h+`px `+-g+`px `+-_+`px`,threshold:Fb(0,Pb(1,c))||1},y=!0;function b(t){let n=t[0].intersectionRatio;if(!yS(l,e.getBoundingClientRect()))return s();if(n!==c){if(!y)return s();n?s(!1,n):i=setTimeout(()=>{s(!1,1e-7)},1e3)}y=!1}try{r=new IntersectionObserver(b,{...v,root:a.ownerDocument})}catch{r=new IntersectionObserver(b,v)}r.observe(e)}let c=wx(e),l=()=>s(n);return c.addEventListener(`resize`,l),s(!0),()=>{c.removeEventListener(`resize`,l),o()}}function xS(e,t,n,r){r===void 0&&(r={});let{ancestorScroll:i=!0,ancestorResize:a=!0,elementResize:o=typeof ResizeObserver==`function`,layoutShift:s=typeof IntersectionObserver==`function`,animationFrame:c=!1}=r,l=Jx(e),u=i||a?[...l?Gx(l):[],...t?Gx(t):[]]:[];u.forEach(e=>{i&&e.addEventListener(`scroll`,n),a&&e.addEventListener(`resize`,n)});let d=l&&s?bS(l,n,a):null,f=-1,p=null;o&&(p=new ResizeObserver(e=>{let[r]=e;r&&r.target===l&&p&&t&&(p.unobserve(t),cancelAnimationFrame(f),f=requestAnimationFrame(()=>{var e;(e=p)==null||e.observe(t)})),n()}),l&&!c&&p.observe(l),t&&p.observe(t));let m,h=c?$x(e):null;c&&g();function g(){let t=$x(e);h&&!yS(h,t)&&n(),h=t,m=requestAnimationFrame(g)}return n(),()=>{var e;u.forEach(e=>{i&&e.removeEventListener(`scroll`,n),a&&e.removeEventListener(`resize`,n)}),d?.(),(e=p)==null||e.disconnect(),p=null,c&&cancelAnimationFrame(m)}}var SS=vx,CS=yx,wS=fx,TS=xx,ES=hx,DS=dx,OS=bx,kS=(e,t,n)=>{let r=new Map,i=n??{},a={...vS,...i.platform,_c:r};return ux(e,t,{...i,platform:a})},AS=typeof document<`u`?f.useLayoutEffect:function(){};function jS(e,t){if(e===t)return!0;if(typeof e!=typeof t)return!1;if(typeof e==`function`&&e.toString()===t.toString())return!0;let n,r,i;if(e&&t&&typeof e==`object`){if(Array.isArray(e)){if(n=e.length,n!==t.length)return!1;for(r=n;r--!==0;)if(!jS(e[r],t[r]))return!1;return!0}if(i=Object.keys(e),n=i.length,n!==Object.keys(t).length)return!1;for(r=n;r--!==0;)if(!{}.hasOwnProperty.call(t,i[r]))return!1;for(r=n;r--!==0;){let n=i[r];if(!(n===`_owner`&&e.$$typeof)&&!jS(e[n],t[n]))return!1}return!0}return e!==e&&t!==t}function MS(e){return typeof window>`u`?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function NS(e,t){let n=MS(e);return Math.round(t*n)/n}function PS(e){let t=f.useRef(e);return AS(()=>{t.current=e}),t}function FS(e){e===void 0&&(e={});let{placement:t=`bottom`,strategy:n=`absolute`,middleware:r=[],platform:i,elements:{reference:a,floating:o}={},transform:s=!0,whileElementsMounted:c,open:l}=e,[u,d]=f.useState({x:0,y:0,strategy:n,placement:t,middlewareData:{},isPositioned:!1}),[m,h]=f.useState(r);jS(m,r)||h(r);let[g,_]=f.useState(null),[v,y]=f.useState(null),b=f.useCallback(e=>{e!==w.current&&(w.current=e,_(e))},[]),x=f.useCallback(e=>{e!==T.current&&(T.current=e,y(e))},[]),S=a||g,C=o||v,w=f.useRef(null),T=f.useRef(null),E=f.useRef(u),D=c!=null,O=PS(c),k=PS(i),A=PS(l),j=f.useCallback(()=>{if(!w.current||!T.current)return;let e={placement:t,strategy:n,middleware:m};k.current&&(e.platform=k.current),kS(w.current,T.current,e).then(e=>{let t={...e,isPositioned:A.current!==!1};M.current&&!jS(E.current,t)&&(E.current=t,p.flushSync(()=>{d(t)}))})},[m,t,n,k,A]);AS(()=>{l===!1&&E.current.isPositioned&&(E.current.isPositioned=!1,d(e=>({...e,isPositioned:!1})))},[l]);let M=f.useRef(!1);AS(()=>(M.current=!0,()=>{M.current=!1}),[]),AS(()=>{if(S&&(w.current=S),C&&(T.current=C),S&&C){if(O.current)return O.current(S,C,j);j()}},[S,C,j,O,D]);let N=f.useMemo(()=>({reference:w,floating:T,setReference:b,setFloating:x}),[b,x]),P=f.useMemo(()=>({reference:S,floating:C}),[S,C]),F=f.useMemo(()=>{let e={position:n,left:0,top:0};if(!P.floating)return e;let t=NS(P.floating,u.x),r=NS(P.floating,u.y);return s?{...e,transform:`translate(`+t+`px, `+r+`px)`,...MS(P.floating)>=1.5&&{willChange:`transform`}}:{position:n,left:t,top:r}},[n,s,P.floating,u.x,u.y]);return f.useMemo(()=>({...u,update:j,refs:N,elements:P,floatingStyles:F}),[u,j,N,P,F])}var IS=e=>{function t(e){return{}.hasOwnProperty.call(e,`current`)}return{name:`arrow`,options:e,fn(n){let{element:r,padding:i}=typeof e==`function`?e(n):e;return r&&t(r)?r.current==null?{}:DS({element:r.current,padding:i}).fn(n):r?DS({element:r,padding:i}).fn(n):{}}}},LS=(e,t)=>{let n=SS(e);return{name:n.name,fn:n.fn,options:[e,t]}},RS=(e,t)=>{let n=CS(e);return{name:n.name,fn:n.fn,options:[e,t]}},zS=(e,t)=>({fn:OS(e).fn,options:[e,t]}),BS=(e,t)=>{let n=wS(e);return{name:n.name,fn:n.fn,options:[e,t]}},VS=(e,t)=>{let n=TS(e);return{name:n.name,fn:n.fn,options:[e,t]}},HS=(e,t)=>{let n=ES(e);return{name:n.name,fn:n.fn,options:[e,t]}},US=(e,t)=>{let n=IS(e);return{name:n.name,fn:n.fn,options:[e,t]}},WS=Object.defineProperty,GS=(e,t)=>WS(e,`name`,{value:t,configurable:!0});function KS(e){let[t,n]=f.useState(void 0);return cy(()=>{if(e){n({width:e.offsetWidth,height:e.offsetHeight});let t=0,r=new ResizeObserver(r=>{if(!Array.isArray(r)||!r.length)return;let i=r[0];window.cancelAnimationFrame(t),t=window.requestAnimationFrame(()=>{let t,r;if(`borderBoxSize`in i){let e=i.borderBoxSize,n=Array.isArray(e)?e[0]:e;t=n.inlineSize,r=n.blockSize}else t=e.offsetWidth,r=e.offsetHeight;n({width:t,height:r})})});return r.observe(e,{box:`border-box`}),()=>{window.cancelAnimationFrame(t),r.unobserve(e)}}n(void 0)},[e]),t}GS(KS,`useSize`);var qS=Object.defineProperty,JS=(e,t)=>qS(e,`name`,{value:t,configurable:!0}),YS={Partial:`partial`,Always:`always`},XS={Optimized:`optimized`,Always:`always`},ZS=`Popper`,[QS,$S]=oy(ZS),[eC,tC]=QS(ZS),nC=JS(e=>{let{__scopePopper:t,children:n}=e,[r,i]=f.useState(null),[a,o]=f.useState(void 0);return(0,J.jsx)(eC,{scope:t,anchor:r,onAnchorChange:i,placementState:a,setPlacementState:o,children:n})},`Popper`),rC=`PopperAnchor`,iC=f.forwardRef(JS(function(e,t){let{__scopePopper:n,virtualRef:r,...i}=e,a=tC(rC,n),o=f.useRef(null),s=a.onAnchorChange,c=Pv(t,f.useCallback(e=>{o.current=e,e&&s(e)},[s])),l=f.useRef(null);f.useEffect(()=>{if(!r)return;let e=l.current;l.current=r.current,e!==l.current&&s(l.current)});let u=a.placementState&&dC(a.placementState),d=u?.[0],p=u?.[1];return r?null:(0,J.jsx)(ty.div,{"data-radix-popper-side":d,"data-radix-popper-align":p,...i,ref:c})},`PopperAnchor`)),aC=`PopperContent`,[oC,sC]=QS(aC),cC=f.forwardRef(JS(function(e,t){let{__scopePopper:n,side:r=`bottom`,sideOffset:i=0,align:a=`center`,alignOffset:o=0,arrowPadding:s=0,avoidCollisions:c=!0,collisionBoundary:l=[],collisionPadding:u=0,sticky:d=YS.Partial,hideWhenDetached:p=!1,updatePositionStrategy:m=XS.Optimized,onPlaced:h,...g}=e,_=tC(aC,n),[v,y]=f.useState(null),b=Pv(t,y),[x,S]=f.useState(null),C=KS(x),w=C?.width??0,T=C?.height??0,E=r+(a===`center`?``:`-`+a),D=typeof u==`number`?u:{top:0,right:0,bottom:0,left:0,...u},O=Array.isArray(l)?l:[l],k=O.length>0,A={padding:D,boundary:O.filter(lC),altBoundary:k},{refs:j,floatingStyles:M,placement:N,isPositioned:P,middlewareData:F}=FS({strategy:`fixed`,placement:E,whileElementsMounted:JS((...e)=>xS(...e,{animationFrame:m===XS.Always}),`whileElementsMounted`),elements:{reference:_.anchor},middleware:[LS({mainAxis:i+T,alignmentAxis:o}),c&&RS({mainAxis:!0,crossAxis:!1,...d===YS.Partial?{limiter:zS()}:{},...A}),c&&BS({...A}),VS({...A,apply:JS(({elements:e,rects:t,availableWidth:n,availableHeight:r})=>{let{width:i,height:a}=t.reference,o=e.floating.style;o.setProperty(`--radix-popper-available-width`,`${n}px`),o.setProperty(`--radix-popper-available-height`,`${r}px`),o.setProperty(`--radix-popper-anchor-width`,`${i}px`),o.setProperty(`--radix-popper-anchor-height`,`${a}px`)},`apply`)}),x&&US({element:x,padding:s}),uC({arrowWidth:w,arrowHeight:T}),p&&HS(k?{strategy:`referenceHidden`,...A}:{strategy:`referenceHidden`,padding:A.padding,altBoundary:A.altBoundary})]}),I=_.setPlacementState;cy(()=>(I(N),()=>{I(void 0)}),[N,I]);let[L,R]=dC(N),z=Py(h);cy(()=>{P&&z?.()},[P,z]);let ee=F.arrow?.x,te=F.arrow?.y,ne=F.arrow?.centerOffset!==0,[B,re]=f.useState();return cy(()=>{v&&re(window.getComputedStyle(v).zIndex)},[v]),(0,J.jsx)(`div`,{ref:j.setFloating,"data-radix-popper-content-wrapper":``,style:{...M,transform:P?M.transform:`translate(0, -200%)`,minWidth:`max-content`,zIndex:B,"--radix-popper-transform-origin":[F.transformOrigin?.x,F.transformOrigin?.y].join(` `),...F.hide?.referenceHidden&&{visibility:`hidden`,pointerEvents:`none`}},dir:e.dir,children:(0,J.jsx)(oC,{scope:n,placedSide:L,placedAlign:R,onArrowChange:S,arrowX:ee,arrowY:te,shouldHideArrow:ne,children:(0,J.jsx)(ty.div,{"data-side":L,"data-align":R,...g,ref:b,style:{...g.style,animation:P?g.style?.animation:`none`}})})})},`PopperContent`));function lC(e){return e!==null}JS(lC,`isNotNull`);var uC=JS(e=>({name:`transformOrigin`,options:e,fn(t){let{placement:n,rects:r,middlewareData:i}=t,a=i.arrow?.centerOffset!==0,o=a?0:e.arrowWidth,s=a?0:e.arrowHeight,[c,l]=dC(n),u={start:`0%`,center:`50%`,end:`100%`}[l],d=(i.arrow?.x??0)+o/2,f=(i.arrow?.y??0)+s/2,p=``,m=``;return c===`bottom`?(p=a?u:`${d}px`,m=`${-s}px`):c===`top`?(p=a?u:`${d}px`,m=`${r.floating.height+s}px`):c===`right`?(p=`${-s}px`,m=a?u:`${f}px`):c===`left`&&(p=`${r.floating.width+s}px`,m=a?u:`${f}px`),{data:{x:p,y:m}}}}),`transformOrigin`);function dC(e){let[t,n=`center`]=e.split(`-`);return[t,n]}JS(dC,`getSideAndAlignFromPlacement`);var fC=Object.defineProperty,pC=f.forwardRef(((e,t)=>fC(e,`name`,{value:t,configurable:!0}))(function(e,t){let{container:n,...r}=e,[i,a]=f.useState(!1);cy(()=>a(!0),[]);let o=n||i&&globalThis?.document?.body;return o?p.createPortal((0,J.jsx)(ty.div,{...r,ref:t}),o):null},`Portal`)),mC=Object.defineProperty,hC=(e,t)=>mC(e,`name`,{value:t,configurable:!0});function gC(e,t){return f.useReducer((e,n)=>t[e][n]??e,e)}hC(gC,`useStateMachine`);var _C=hC(e=>{let{present:t,children:n}=e,r=vC(t),i=typeof n==`function`?n({present:r.isPresent}):f.Children.only(n),a=bC(r.ref,SC(i));return typeof n==`function`||r.isPresent?f.cloneElement(i,{ref:a}):null},`Presence`);function vC(e){let[t,n]=f.useState(),r=f.useRef(null),i=f.useRef(e),a=f.useRef(`none`),o=f.useRef(void 0),[s,c]=gC(e?`mounted`:`unmounted`,{mounted:{UNMOUNT:`unmounted`,ANIMATION_OUT:`unmountSuspended`},unmountSuspended:{MOUNT:`mounted`,ANIMATION_END:`unmounted`},unmounted:{MOUNT:`mounted`}});return f.useEffect(()=>{s===`mounted`?(a.current=o.current??xC(r.current),o.current=void 0):a.current=`none`},[s]),cy(()=>{let t=r.current,n=i.current;if(n!==e){let r=a.current,s=xC(t);e?(o.current=s,c(`MOUNT`)):s===`none`||t?.display===`none`?c(`UNMOUNT`):c(n&&r!==s?`ANIMATION_OUT`:`UNMOUNT`),i.current=e}},[e,c]),cy(()=>{if(t){let e,n=t.ownerDocument.defaultView??window,o=hC(a=>{let o=xC(r.current).includes(CSS.escape(a.animationName));if(a.target===t&&o&&(c(`ANIMATION_END`),!i.current)){let r=t.style.animationFillMode;t.style.animationFillMode=`forwards`,e=n.setTimeout(()=>{t.style.animationFillMode===`forwards`&&(t.style.animationFillMode=r)})}},`handleAnimationEnd`),s=hC(e=>{e.target===t&&(a.current=xC(r.current))},`handleAnimationStart`);return t.addEventListener(`animationstart`,s),t.addEventListener(`animationcancel`,o),t.addEventListener(`animationend`,o),()=>{n.clearTimeout(e),t.removeEventListener(`animationstart`,s),t.removeEventListener(`animationcancel`,o),t.removeEventListener(`animationend`,o)}}c(`ANIMATION_END`)},[t,c]),{isPresent:[`mounted`,`unmountSuspended`].includes(s),ref:f.useCallback(e=>{if(e){let t=getComputedStyle(e);r.current=t,o.current=xC(t)}else r.current=null;n(e)},[])}}hC(vC,`usePresence`);function yC(e,t){if(typeof e==`function`)return e(t);e!=null&&(e.current=t)}hC(yC,`setRef`);function bC(...e){let t=f.useRef(e);return t.current=e,f.useCallback(e=>{let n=t.current,r=!1,i=n.map(t=>{let n=yC(t,e);return!r&&typeof n==`function`&&(r=!0),n});if(r)return()=>{for(let e=0;e<i.length;e++){let t=i[e];typeof t==`function`?t():yC(n[e],null)}}},[])}hC(bC,`useStableComposedRefs`);function xC(e){return e?.animationName||`none`}hC(xC,`getAnimationName`);function SC(e){let t=Object.getOwnPropertyDescriptor(e.props,`ref`)?.get,n=t&&`isReactWarning`in t&&t.isReactWarning;return n?e.ref:(t=Object.getOwnPropertyDescriptor(e,`ref`)?.get,n=t&&`isReactWarning`in t&&t.isReactWarning,n?e.props.ref:e.props.ref||e.ref)}hC(SC,`getElementRef`);var CC=Object.defineProperty,wC=(e,t)=>CC(e,`name`,{value:t,configurable:!0}),TC=f.useEffectEvent,EC=f.useInsertionEffect;function DC(e){if(typeof TC==`function`)return TC(e);let t=f.useRef(()=>{throw Error(`Cannot call an event handler while rendering.`)});return typeof EC==`function`?EC(()=>{t.current=e}):cy(()=>{t.current=e}),f.useMemo(()=>((...e)=>t.current?.(...e)),[])}wC(DC,`useEffectEvent`);var OC=Object.defineProperty,kC=(e,t)=>OC(e,`name`,{value:t,configurable:!0}),AC=f.useInsertionEffect||cy;function jC({prop:e,defaultProp:t,onChange:n=kC(()=>{},`onChange`),caller:r}){let[i,a,o]=MC({defaultProp:t,onChange:n}),s=e!==void 0;return[s?e:i,f.useCallback(t=>{if(s){let n=NC(t)?t(e):t;n!==e&&o.current?.(n)}else a(t)},[s,e,a,o])]}kC(jC,`useControllableState`);function MC({defaultProp:e,onChange:t}){let[n,r]=f.useState(e),i=f.useRef(n),a=f.useRef(t);return AC(()=>{a.current=t},[t]),f.useEffect(()=>{i.current!==n&&(a.current?.(n),i.current=n)},[n,i]),[n,r,a]}kC(MC,`useUncontrolledState`);function NC(e){return typeof e==`function`}kC(NC,`isFunction`);var PC=Symbol(`RADIX:SYNC_STATE`);function FC(e,t,n,r){let{prop:i,defaultProp:a,onChange:o,caller:s}=t,c=i!==void 0,l=DC(o),u=[{...n,state:a}];r&&u.push(r);let[d,p]=f.useReducer((t,n)=>{if(n.type===PC)return{...t,state:n.state};let r=e(t,n);return c&&!Object.is(r.state,t.state)&&l(r.state),r},...u),m=d.state,h=f.useRef(m);f.useEffect(()=>{h.current!==m&&(h.current=m,c||l(m))},[m,h,c]);let g=f.useMemo(()=>i===void 0?d:{...d,state:i},[d,i]);return f.useEffect(()=>{c&&!Object.is(i,d.state)&&p({type:PC,state:i})},[i,d.state,c]),[g,p]}kC(FC,`useControllableStateReducer`);var IC=Object.defineProperty,LC=(e,t)=>IC(e,`name`,{value:t,configurable:!0}),RC=!1;function zC(){let[e,t]=f.useState(RC);return f.useEffect(()=>{RC||(RC=!0,t(!0))},[]),e}LC(zC,`useIsHydrated`);var BC=f.useSyncExternalStore;function VC(){return()=>{}}LC(VC,`subscribe`);function HC(){return BC(VC,()=>!0,()=>!1)}LC(HC,`useIsHydratedModern`);var UC=typeof BC==`function`?HC:zC,WC=Object.defineProperty,GC=(e,t)=>WC(e,`name`,{value:t,configurable:!0}),KC=`rovingFocusGroup.onEntryFocus`,qC={bubbles:!1,cancelable:!0},JC=`RovingFocusGroup`,[YC,XC,ZC]=dy(JC),[QC,$C]=oy(JC,[ZC]),ew={Vertical:`vertical`,Horizontal:`horizontal`},tw={LTR:`ltr`,RTL:`rtl`},[nw,rw]=QC(JC),iw=f.forwardRef(GC(function(e,t){return(0,J.jsx)(YC.Provider,{scope:e.__scopeRovingFocusGroup,children:(0,J.jsx)(YC.Slot,{scope:e.__scopeRovingFocusGroup,children:(0,J.jsx)(aw,{...e,ref:t})})})},`RovingFocusGroup`)),aw=f.forwardRef(GC(function(e,t){let{__scopeRovingFocusGroup:n,orientation:r,loop:i=!1,dir:a,currentTabStopId:o,defaultCurrentTabStopId:s,onCurrentTabStopIdChange:c,onEntryFocus:l,preventScrollOnEntryFocus:u=!1,...d}=e,p=f.useRef(null),m=Pv(t,p),h=Db(a),[g,_]=jC({prop:o,defaultProp:s??null,onChange:c,caller:JC}),[v,y]=f.useState(!1),b=Py(l),x=XC(n),S=f.useRef(!1),[C,w]=f.useState(0);return f.useEffect(()=>{let e=p.current;if(e)return e.addEventListener(KC,b),()=>e.removeEventListener(KC,b)},[b]),(0,J.jsx)(nw,{scope:n,orientation:r,dir:h,loop:i,currentTabStopId:g,onItemFocus:f.useCallback(e=>_(e),[_]),onItemShiftTab:f.useCallback(()=>y(!0),[]),onFocusableItemAdd:f.useCallback(()=>w(e=>e+1),[]),onFocusableItemRemove:f.useCallback(()=>w(e=>e-1),[]),children:(0,J.jsx)(ty.div,{tabIndex:v||C===0?-1:0,"data-orientation":r,...d,ref:m,style:{outline:`none`,...e.style},onMouseDown:Ey(e.onMouseDown,()=>{S.current=!0}),onFocus:Ey(e.onFocus,e=>{let t=!S.current;if(e.target===e.currentTarget&&t&&!v){let t=new CustomEvent(KC,qC);if(e.currentTarget.dispatchEvent(t),!t.defaultPrevented){let e=x().filter(e=>e.focusable);dw([e.find(e=>e.active),e.find(e=>e.id===g),...e].filter(Boolean).map(e=>e.ref.current),u)}}S.current=!1}),onBlur:Ey(e.onBlur,()=>y(!1))})})},`RovingFocusGroupImpl`)),ow=`RovingFocusGroupItem`,sw=f.forwardRef(GC(function(e,t){let{__scopeRovingFocusGroup:n,focusable:r=!0,active:i=!1,tabStopId:a,children:o,...s}=e,c=Mb(),l=a||c,u=rw(ow,n),d=u.currentTabStopId===l,p=XC(n),{onFocusableItemAdd:m,onFocusableItemRemove:h,currentTabStopId:g}=u,_=UC();return cy(()=>{if(_&&r)return m(),()=>h()},[_,r,m,h]),f.useEffect(()=>{if(!_&&r)return m(),()=>h()},[_,r,m,h]),(0,J.jsx)(YC.ItemSlot,{scope:n,id:l,focusable:r,active:i,children:(0,J.jsx)(ty.span,{tabIndex:d?0:-1,"data-orientation":u.orientation,...s,ref:t,onMouseDown:Ey(e.onMouseDown,e=>{r?u.onItemFocus(l):e.preventDefault()}),onFocus:Ey(e.onFocus,()=>u.onItemFocus(l)),onKeyDown:Ey(e.onKeyDown,e=>{if(e.key===`Tab`&&e.shiftKey){u.onItemShiftTab();return}if(e.target!==e.currentTarget)return;let t=uw(e,u.orientation,u.dir);if(t!==void 0){if(e.metaKey||e.ctrlKey||e.altKey||e.shiftKey)return;e.preventDefault();let n=p().filter(e=>e.focusable).map(e=>e.ref.current);if(t===`last`)n.reverse();else if(t===`prev`||t===`next`){t===`prev`&&n.reverse();let r=n.indexOf(e.currentTarget);n=u.loop?fw(n,r+1):n.slice(r+1)}setTimeout(()=>dw(n))}}),children:typeof o==`function`?o({isCurrentTabStop:d,hasTabStop:g!=null}):o})})},`RovingFocusGroupItem`)),cw={ArrowLeft:`prev`,ArrowUp:`prev`,ArrowRight:`next`,ArrowDown:`next`,PageUp:`first`,Home:`first`,PageDown:`last`,End:`last`};function lw(e,t){return t===tw.RTL?e===`ArrowLeft`?`ArrowRight`:e===`ArrowRight`?`ArrowLeft`:e:e}GC(lw,`getDirectionAwareKey`);function uw(e,t,n){let r=lw(e.key,n);if(!(t===ew.Vertical&&[`ArrowLeft`,`ArrowRight`].includes(r))&&!(t===ew.Horizontal&&[`ArrowUp`,`ArrowDown`].includes(r)))return cw[r]}GC(uw,`getFocusIntent`);function dw(e,t=!1){let n=document.activeElement;for(let r of e)if(r===n||(r.focus({preventScroll:t}),document.activeElement!==n))return}GC(dw,`focusFirst`);function fw(e,t){return e.map((n,r)=>e[(t+r)%e.length])}GC(fw,`wrapArray`);var pw=function(e){return typeof document>`u`?null:(Array.isArray(e)?e[0]:e).ownerDocument.body},mw=new WeakMap,hw=new WeakMap,gw={},_w=0,vw=function(e){return e&&(e.host||vw(e.parentNode))},yw=function(e,t){return t.map(function(t){if(e.contains(t))return t;var n=vw(t);return n&&e.contains(n)?n:(console.error(`aria-hidden`,t,`in not contained inside`,e,`. Doing nothing`),null)}).filter(function(e){return!!e})},bw=function(e,t,n,r){var i=yw(t,Array.isArray(e)?e:[e]);gw[n]||(gw[n]=new WeakMap);var a=gw[n],o=[],s=new Set,c=new Set(i),l=function(e){e&&!s.has(e)&&(s.add(e),l(e.parentNode))};i.forEach(l);var u=function(e){e&&!c.has(e)&&Array.prototype.forEach.call(e.children,function(e){if(s.has(e))u(e);else try{var t=e.getAttribute(r),i=t!==null&&t!==`false`,c=(mw.get(e)||0)+1,l=(a.get(e)||0)+1;mw.set(e,c),a.set(e,l),o.push(e),c===1&&i&&hw.set(e,!0),l===1&&e.setAttribute(n,`true`),i||e.setAttribute(r,`true`)}catch(t){console.error(`aria-hidden: cannot operate on `,e,t)}})};return u(t),s.clear(),_w++,function(){o.forEach(function(e){var t=mw.get(e)-1,i=a.get(e)-1;mw.set(e,t),a.set(e,i),t||(hw.has(e)||e.removeAttribute(r),hw.delete(e)),i||e.removeAttribute(n)}),_w--,_w||(mw=new WeakMap,mw=new WeakMap,hw=new WeakMap,gw={})}},xw=function(e,t,n){n===void 0&&(n=`data-aria-hidden`);var r=Array.from(Array.isArray(e)?e:[e]),i=t||pw(e);return i?(r.push.apply(r,Array.from(i.querySelectorAll(`[aria-live], script`))),bw(r,i,n,`aria-hidden`)):function(){return null}},Sw=function(){return Sw=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var i in t=arguments[n],t)Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e},Sw.apply(this,arguments)};function Cw(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&typeof Object.getOwnPropertySymbols==`function`)for(var i=0,r=Object.getOwnPropertySymbols(e);i<r.length;i++)t.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(e,r[i])&&(n[r[i]]=e[r[i]]);return n}function ww(e,t,n){if(n||arguments.length===2)for(var r=0,i=t.length,a;r<i;r++)(a||!(r in t))&&(a||=Array.prototype.slice.call(t,0,r),a[r]=t[r]);return e.concat(a||Array.prototype.slice.call(t))}var Tw=`right-scroll-bar-position`,Ew=`width-before-scroll-bar`,Dw=`with-scroll-bars-hidden`,Ow=`--removed-body-scroll-bar-size`;function kw(e,t){return typeof e==`function`?e(t):e&&(e.current=t),e}function Aw(e,t){var n=(0,d.useState)(function(){return{value:e,callback:t,facade:{get current(){return n.value},set current(e){var t=n.value;t!==e&&(n.value=e,n.callback(e,t))}}}})[0];return n.callback=t,n.facade}var jw=typeof window<`u`?d.useLayoutEffect:d.useEffect,Mw=new WeakMap;function Nw(e,t){var n=Aw(t||null,function(t){return e.forEach(function(e){return kw(e,t)})});return jw(function(){var t=Mw.get(n);if(t){var r=new Set(t),i=new Set(e),a=n.current;r.forEach(function(e){i.has(e)||kw(e,null)}),i.forEach(function(e){r.has(e)||kw(e,a)})}Mw.set(n,e)},[e]),n}function Pw(e){return e}function Fw(e,t){t===void 0&&(t=Pw);var n=[],r=!1;return{read:function(){if(r)throw Error("Sidecar: could not `read` from an `assigned` medium. `read` could be used only with `useMedium`.");return n.length?n[n.length-1]:e},useMedium:function(e){var i=t(e,r);return n.push(i),function(){n=n.filter(function(e){return e!==i})}},assignSyncMedium:function(e){for(r=!0;n.length;){var t=n;n=[],t.forEach(e)}n={push:function(t){return e(t)},filter:function(){return n}}},assignMedium:function(e){r=!0;var t=[];if(n.length){var i=n;n=[],i.forEach(e),t=n}var a=function(){var n=t;t=[],n.forEach(e)},o=function(){return Promise.resolve().then(a)};o(),n={push:function(e){t.push(e),o()},filter:function(e){return t=t.filter(e),n}}}}}function Iw(e){e===void 0&&(e={});var t=Fw(null);return t.options=Sw({async:!0,ssr:!1},e),t}var Lw=function(e){var t=e.sideCar,n=Cw(e,[`sideCar`]);if(!t)throw Error("Sidecar: please provide `sideCar` property to import the right car");var r=t.read();if(!r)throw Error(`Sidecar medium not found`);return d.createElement(r,Sw({},n))};Lw.isSideCarExport=!0;function Rw(e,t){return e.useMedium(t),Lw}var zw=Iw(),Bw=function(){},Vw=d.forwardRef(function(e,t){var n=d.useRef(null),r=d.useState({onScrollCapture:Bw,onWheelCapture:Bw,onTouchMoveCapture:Bw}),i=r[0],a=r[1],o=e.forwardProps,s=e.children,c=e.className,l=e.removeScrollBar,u=e.enabled,f=e.shards,p=e.sideCar,m=e.noRelative,h=e.noIsolation,g=e.inert,_=e.allowPinchZoom,v=e.as,y=v===void 0?`div`:v,b=e.gapMode,x=Cw(e,[`forwardProps`,`children`,`className`,`removeScrollBar`,`enabled`,`shards`,`sideCar`,`noRelative`,`noIsolation`,`inert`,`allowPinchZoom`,`as`,`gapMode`]),S=p,C=Nw([n,t]),w=Sw(Sw({},x),i);return d.createElement(d.Fragment,null,u&&d.createElement(S,{sideCar:zw,removeScrollBar:l,shards:f,noRelative:m,noIsolation:h,inert:g,setCallbacks:a,allowPinchZoom:!!_,lockRef:n,gapMode:b}),o?d.cloneElement(d.Children.only(s),Sw(Sw({},w),{ref:C})):d.createElement(y,Sw({},w,{className:c,ref:C}),s))});Vw.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1},Vw.classNames={fullWidth:Ew,zeroRight:Tw};var Hw,Uw=function(){if(Hw)return Hw;if(typeof __webpack_nonce__<`u`)return __webpack_nonce__};function Ww(){if(!document)return null;var e=document.createElement(`style`);e.type=`text/css`;var t=Uw();return t&&e.setAttribute(`nonce`,t),e}function Gw(e,t){e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t))}function Kw(e){(document.head||document.getElementsByTagName(`head`)[0]).appendChild(e)}var qw=function(){var e=0,t=null;return{add:function(n){e==0&&(t=Ww())&&(Gw(t,n),Kw(t)),e++},remove:function(){e--,!e&&t&&(t.parentNode&&t.parentNode.removeChild(t),t=null)}}},Jw=function(){var e=qw();return function(t,n){d.useEffect(function(){return e.add(t),function(){e.remove()}},[t&&n])}},Yw=function(){var e=Jw();return function(t){var n=t.styles,r=t.dynamic;return e(n,r),null}},Xw={left:0,top:0,right:0,gap:0},Zw=function(e){return parseInt(e||``,10)||0},Qw=function(e){var t=window.getComputedStyle(document.body),n=t[e===`padding`?`paddingLeft`:`marginLeft`],r=t[e===`padding`?`paddingTop`:`marginTop`],i=t[e===`padding`?`paddingRight`:`marginRight`];return[Zw(n),Zw(r),Zw(i)]},$w=function(e){if(e===void 0&&(e=`margin`),typeof window>`u`)return Xw;var t=Qw(e),n=document.documentElement.clientWidth,r=window.innerWidth;return{left:t[0],top:t[1],right:t[2],gap:Math.max(0,r-n+t[2]-t[0])}},eT=Yw(),tT=`data-scroll-locked`,nT=function(e,t,n,r){var i=e.left,a=e.top,o=e.right,s=e.gap;return n===void 0&&(n=`margin`),`
|
|
20
|
+
.${Dw} {
|
|
21
|
+
overflow: hidden ${r};
|
|
22
|
+
padding-right: ${s}px ${r};
|
|
23
|
+
}
|
|
24
|
+
body[${tT}] {
|
|
25
|
+
overflow: hidden ${r};
|
|
26
|
+
overscroll-behavior: contain;
|
|
27
|
+
${[t&&`position: relative ${r};`,n===`margin`&&`
|
|
28
|
+
padding-left: ${i}px;
|
|
29
|
+
padding-top: ${a}px;
|
|
30
|
+
padding-right: ${o}px;
|
|
31
|
+
margin-left:0;
|
|
32
|
+
margin-top:0;
|
|
33
|
+
margin-right: ${s}px ${r};
|
|
34
|
+
`,n===`padding`&&`padding-right: ${s}px ${r};`].filter(Boolean).join(``)}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.${Tw} {
|
|
38
|
+
right: ${s}px ${r};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
.${Ew} {
|
|
42
|
+
margin-right: ${s}px ${r};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
.${Tw} .${Tw} {
|
|
46
|
+
right: 0 ${r};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
.${Ew} .${Ew} {
|
|
50
|
+
margin-right: 0 ${r};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
body[${tT}] {
|
|
54
|
+
${Ow}: ${s}px;
|
|
55
|
+
}
|
|
56
|
+
`},rT=function(){var e=parseInt(document.body.getAttribute(`data-scroll-locked`)||`0`,10);return isFinite(e)?e:0},iT=function(){d.useEffect(function(){return document.body.setAttribute(tT,(rT()+1).toString()),function(){var e=rT()-1;e<=0?document.body.removeAttribute(tT):document.body.setAttribute(tT,e.toString())}},[])},aT=function(e){var t=e.noRelative,n=e.noImportant,r=e.gapMode,i=r===void 0?`margin`:r;iT();var a=d.useMemo(function(){return $w(i)},[i]);return d.createElement(eT,{styles:nT(a,!t,i,n?``:`!important`)})},oT=!1;if(typeof window<`u`)try{var sT=Object.defineProperty({},"passive",{get:function(){return oT=!0,!0}});window.addEventListener(`test`,sT,sT),window.removeEventListener(`test`,sT,sT)}catch{oT=!1}var cT=oT?{passive:!1}:!1,lT=function(e){return e.tagName===`TEXTAREA`},uT=function(e,t){if(!(e instanceof Element))return!1;var n=window.getComputedStyle(e);return n[t]!==`hidden`&&!(n.overflowY===n.overflowX&&!lT(e)&&n[t]===`visible`)},dT=function(e){return uT(e,`overflowY`)},fT=function(e){return uT(e,`overflowX`)},pT=function(e,t){var n=t.ownerDocument,r=t;do{if(typeof ShadowRoot<`u`&&r instanceof ShadowRoot&&(r=r.host),gT(e,r)){var i=_T(e,r);if(i[1]>i[2])return!0}r=r.parentNode}while(r&&r!==n.body);return!1},mT=function(e){return[e.scrollTop,e.scrollHeight,e.clientHeight]},hT=function(e){return[e.scrollLeft,e.scrollWidth,e.clientWidth]},gT=function(e,t){return e===`v`?dT(t):fT(t)},_T=function(e,t){return e===`v`?mT(t):hT(t)},vT=function(e,t){return e===`h`&&t===`rtl`?-1:1},yT=function(e,t,n,r,i){var a=vT(e,window.getComputedStyle(t).direction),o=a*r,s=n.target,c=t.contains(s),l=!1,u=o>0,d=0,f=0;do{if(!s)break;var p=_T(e,s),m=p[0],h=p[1]-p[2]-a*m;(m||h)&&gT(e,s)&&(d+=h,f+=m);var g=s.parentNode;s=g&&g.nodeType===Node.DOCUMENT_FRAGMENT_NODE?g.host:g}while(!c&&s!==document.body||c&&(t.contains(s)||t===s));return(u&&(i&&Math.abs(d)<1||!i&&o>d)||!u&&(i&&Math.abs(f)<1||!i&&-o>f))&&(l=!0),l},bT=function(e){return`changedTouches`in e?[e.changedTouches[0].clientX,e.changedTouches[0].clientY]:[0,0]},xT=function(e){return[e.deltaX,e.deltaY]},ST=function(e){return e&&`current`in e?e.current:e},CT=function(e,t){return e[0]===t[0]&&e[1]===t[1]},wT=function(e){return`
|
|
57
|
+
.block-interactivity-${e} {pointer-events: none;}
|
|
58
|
+
.allow-interactivity-${e} {pointer-events: all;}
|
|
59
|
+
`},TT=0,ET=[];function DT(e){var t=d.useRef([]),n=d.useRef([0,0]),r=d.useRef(),i=d.useState(TT++)[0],a=d.useState(Yw)[0],o=d.useRef(e);d.useEffect(function(){o.current=e},[e]),d.useEffect(function(){if(e.inert){document.body.classList.add(`block-interactivity-${i}`);var t=ww([e.lockRef.current],(e.shards||[]).map(ST),!0).filter(Boolean);return t.forEach(function(e){return e.classList.add(`allow-interactivity-${i}`)}),function(){document.body.classList.remove(`block-interactivity-${i}`),t.forEach(function(e){return e.classList.remove(`allow-interactivity-${i}`)})}}},[e.inert,e.lockRef.current,e.shards]);var s=d.useCallback(function(e,t){if(`touches`in e&&e.touches.length===2||e.type===`wheel`&&e.ctrlKey)return!o.current.allowPinchZoom;var i=bT(e),a=n.current,s=`deltaX`in e?e.deltaX:a[0]-i[0],c=`deltaY`in e?e.deltaY:a[1]-i[1],l,u=e.target,d=Math.abs(s)>Math.abs(c)?`h`:`v`;if(`touches`in e&&d===`h`&&u.type===`range`)return!1;var f=window.getSelection(),p=f&&f.anchorNode;if(p&&(p===u||p.contains(u)))return!1;var m=pT(d,u);if(!m)return!0;if(m?l=d:(l=d===`v`?`h`:`v`,m=pT(d,u)),!m)return!1;if(!r.current&&`changedTouches`in e&&(s||c)&&(r.current=l),!l)return!0;var h=r.current||l;return yT(h,t,e,h===`h`?s:c,!0)},[]),c=d.useCallback(function(e){var n=e;if(ET.length&&ET[ET.length-1]===a){var r=`deltaY`in n?xT(n):bT(n),i=t.current.filter(function(e){return e.name===n.type&&(e.target===n.target||n.target===e.shadowParent)&&CT(e.delta,r)})[0];if(i&&i.should)n.cancelable&&n.preventDefault();else if(!i){var c=(o.current.shards||[]).map(ST).filter(Boolean).filter(function(e){return e.contains(n.target)});(c.length>0?s(n,c[0]):!o.current.noIsolation)&&n.cancelable&&n.preventDefault()}}},[]),l=d.useCallback(function(e,n,r,i){var a={name:e,delta:n,target:r,should:i,shadowParent:OT(r)};t.current.push(a),setTimeout(function(){t.current=t.current.filter(function(e){return e!==a})},1)},[]),u=d.useCallback(function(e){n.current=bT(e),r.current=void 0},[]),f=d.useCallback(function(t){l(t.type,xT(t),t.target,s(t,e.lockRef.current))},[]),p=d.useCallback(function(t){l(t.type,bT(t),t.target,s(t,e.lockRef.current))},[]);d.useEffect(function(){return ET.push(a),e.setCallbacks({onScrollCapture:f,onWheelCapture:f,onTouchMoveCapture:p}),document.addEventListener(`wheel`,c,cT),document.addEventListener(`touchmove`,c,cT),document.addEventListener(`touchstart`,u,cT),function(){ET=ET.filter(function(e){return e!==a}),document.removeEventListener(`wheel`,c,cT),document.removeEventListener(`touchmove`,c,cT),document.removeEventListener(`touchstart`,u,cT)}},[]);var m=e.removeScrollBar,h=e.inert;return d.createElement(d.Fragment,null,h?d.createElement(a,{styles:wT(i)}):null,m?d.createElement(aT,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function OT(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}var kT=Rw(zw,DT),AT=d.forwardRef(function(e,t){return d.createElement(Vw,Sw({},e,{ref:t,sideCar:kT}))});AT.classNames=Vw.classNames;var jT=Object.defineProperty,MT=(e,t)=>jT(e,`name`,{value:t,configurable:!0}),NT=[`Enter`,` `],PT=[`ArrowDown`,`PageUp`,`Home`],FT=[`ArrowUp`,`PageDown`,`End`],IT=[...PT,...FT];[...NT],[...NT];var LT=`Menu`,[RT,zT,BT]=dy(LT),[VT,HT]=oy(LT,[BT,$S,$C]),UT=$S(),WT=$C(),[GT,KT]=VT(LT),[qT,JT]=VT(LT),YT=MT(e=>{let{__scopeMenu:t,open:n=!1,children:r,dir:i,onOpenChange:a,modal:o=!0}=e,s=UT(t),[c,l]=f.useState(null),u=f.useRef(!1),d=Py(a),p=Db(i);return f.useEffect(()=>{let e=MT(()=>{u.current=!0,document.addEventListener(`pointerdown`,t,{capture:!0,once:!0}),document.addEventListener(`pointermove`,t,{capture:!0,once:!0})},`handleKeyDown`),t=MT(()=>u.current=!1,`handlePointer`);return document.addEventListener(`keydown`,e,{capture:!0}),()=>{document.removeEventListener(`keydown`,e,{capture:!0}),document.removeEventListener(`pointerdown`,t,{capture:!0}),document.removeEventListener(`pointermove`,t,{capture:!0})}},[]),f.useEffect(()=>{if(!n)return;let e=MT(()=>d(!1),`handleBlur`);return window.addEventListener(`blur`,e),()=>window.removeEventListener(`blur`,e)},[n,d]),(0,J.jsx)(nC,{...s,children:(0,J.jsx)(GT,{scope:t,open:n,onOpenChange:d,content:c,onContentChange:l,children:(0,J.jsx)(qT,{scope:t,onClose:f.useCallback(()=>d(!1),[d]),isUsingKeyboardRef:u,dir:p,modal:o,children:r})})})},`Menu`),XT=f.forwardRef(MT(function(e,t){let{__scopeMenu:n,...r}=e,i=UT(n);return(0,J.jsx)(iC,{...i,...r,ref:t})},`MenuAnchor`)),ZT=`MenuPortal`,[QT,$T]=VT(ZT,{forceMount:void 0}),eE=MT(e=>{let{__scopeMenu:t,forceMount:n,children:r,container:i}=e,a=KT(ZT,t);return(0,J.jsx)(QT,{scope:t,forceMount:n,children:(0,J.jsx)(_C,{present:n||a.open,children:(0,J.jsx)(pC,{asChild:!0,container:i,children:r})})})},`MenuPortal`),tE=`MenuContent`,[nE,rE]=VT(tE),iE=f.forwardRef(MT(function(e,t){let n=$T(tE,e.__scopeMenu),{forceMount:r=n.forceMount,...i}=e,a=KT(tE,e.__scopeMenu),o=JT(tE,e.__scopeMenu);return(0,J.jsx)(RT.Provider,{scope:e.__scopeMenu,children:(0,J.jsx)(_C,{present:r||a.open,children:(0,J.jsx)(RT.Slot,{scope:e.__scopeMenu,children:o.modal?(0,J.jsx)(aE,{...i,ref:t}):(0,J.jsx)(oE,{...i,ref:t})})})})},`MenuContent`)),aE=f.forwardRef(MT(function(e,t){let n=KT(tE,e.__scopeMenu),r=f.useRef(null),i=Pv(t,r);return f.useEffect(()=>{let e=r.current;if(e)return xw(e)},[]),(0,J.jsx)(cE,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:Ey(e.onFocusOutside,e=>e.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})},`MenuRootContentModal`)),oE=f.forwardRef(MT(function(e,t){let n=KT(tE,e.__scopeMenu);return(0,J.jsx)(cE,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})},`MenuRootContentNonModal`)),sE=Lv(`MenuContent.ScrollLock`),cE=f.forwardRef(MT(function(e,t){let{__scopeMenu:n,loop:r=!1,trapFocus:i,onOpenAutoFocus:a,onCloseAutoFocus:o,disableOutsidePointerEvents:s,onEntryFocus:c,onEscapeKeyDown:l,onPointerDownOutside:u,onFocusOutside:d,onInteractOutside:p,onDismiss:m,disableOutsideScroll:h,...g}=e,_=KT(tE,n),v=JT(tE,n),y=UT(n),b=WT(n),x=zT(n),[S,C]=f.useState(null),w=f.useRef(null),[T,E]=f.useState(null);db(T);let{nodes:D,registry:O}=ub(),k=!!(i||h),A=Pv(t,w,_.onContentChange,E),j=f.useRef(0),M=f.useRef(``),N=f.useRef(0),P=f.useRef(null),F=f.useRef(`right`),I=f.useRef(0),L=f.useMemo(()=>h?[w,...D.map(e=>({current:e}))]:[],[w,D,h]),R=h?AT:f.Fragment,z=h?{as:sE,allowPinchZoom:!0,shards:L}:void 0,ee=MT(e=>{let t=M.current+e,n=x().filter(e=>!e.disabled),r=document.activeElement,i=n.find(e=>e.ref.current===r)?.textValue,a=TE(n.map(e=>e.textValue),t,i),o=n.find(e=>e.textValue===a)?.ref.current;function s(e){M.current=e,window.clearTimeout(j.current),e!==``&&(j.current=window.setTimeout(()=>s(``),1e3))}MT(s,`updateSearch`),s(t),o&&setTimeout(()=>o.focus())},`handleTypeaheadSearch`);f.useEffect(()=>()=>window.clearTimeout(j.current),[]),eb();let te=f.useCallback(e=>F.current===P.current?.side&&DE(e,P.current?.area),[]);return(0,J.jsx)(nE,{scope:n,searchRef:M,onItemEnter:f.useCallback(e=>{te(e)&&e.preventDefault()},[te]),onItemLeave:f.useCallback(e=>{te(e)||(w.current?.focus(),C(null))},[te]),onTriggerLeave:f.useCallback(e=>{te(e)&&e.preventDefault()},[te]),pointerGraceTimerRef:N,onPointerGraceIntentChange:f.useCallback(e=>{P.current=e},[]),children:(0,J.jsx)(lb,{registry:k?O:null,children:(0,J.jsx)(R,{...z,children:(0,J.jsx)(sb,{asChild:!0,trapped:i,branches:D,onMountAutoFocus:Ey(a,e=>{e.preventDefault(),w.current?.focus({preventScroll:!0})}),onUnmountAutoFocus:o,children:(0,J.jsx)(Hy,{asChild:!0,disableOutsidePointerEvents:s,onEscapeKeyDown:l,onPointerDownOutside:u,onFocusOutside:d,onInteractOutside:p,onDismiss:m,children:(0,J.jsx)(iw,{asChild:!0,...b,dir:v.dir,orientation:`vertical`,loop:r,currentTabStopId:S,onCurrentTabStopIdChange:C,onEntryFocus:Ey(c,e=>{v.isUsingKeyboardRef.current||e.preventDefault()}),preventScrollOnEntryFocus:!0,children:(0,J.jsx)(cC,{role:`menu`,"aria-orientation":`vertical`,"data-state":bE(_.open),"data-radix-menu-content":``,dir:v.dir,...y,...g,ref:A,style:{outline:`none`,...g.style},onKeyDown:Ey(g.onKeyDown,e=>{let t=e.target.closest(`[data-radix-menu-content]`)===e.currentTarget,n=e.ctrlKey||e.altKey||e.metaKey,r=e.key.length===1;t&&(e.key===`Tab`&&e.preventDefault(),!n&&r&&ee(e.key));let i=w.current;if(e.target!==i||!IT.includes(e.key))return;e.preventDefault();let a=x().filter(e=>!e.disabled).map(e=>e.ref.current);FT.includes(e.key)&&a.reverse(),CE(a)}),onBlur:Ey(e.onBlur,e=>{e.currentTarget.contains(e.target)||(window.clearTimeout(j.current),M.current=``)}),onPointerMove:Ey(e.onPointerMove,OE(e=>{let t=e.target,n=I.current!==e.clientX;if(e.currentTarget.contains(t)&&n){let t=e.clientX>I.current?`right`:`left`;F.current=t,I.current=e.clientX}}))})})})})})})})},`MenuContentImpl`)),lE=`MenuItem`,uE=`menu.itemSelect`,dE=f.forwardRef(MT(function(e,t){let{disabled:n=!1,onSelect:r,...i}=e,a=f.useRef(null),o=JT(lE,e.__scopeMenu),s=rE(lE,e.__scopeMenu),c=Pv(t,a),l=f.useRef(!1),u=MT(()=>{let e=a.current;if(!n&&e){let t=new CustomEvent(uE,{bubbles:!0,cancelable:!0});e.addEventListener(uE,e=>r?.(e),{once:!0}),ny(e,t),t.defaultPrevented?l.current=!1:o.onClose()}},`handleSelect`);return(0,J.jsx)(fE,{...i,ref:c,disabled:n,onClick:Ey(e.onClick,u),onPointerDown:t=>{e.onPointerDown?.(t),l.current=!0},onPointerUp:Ey(e.onPointerUp,e=>{l.current||e.currentTarget?.click()}),onKeyDown:Ey(e.onKeyDown,e=>{n||e.target!==e.currentTarget||(s.searchRef.current===``||e.key!==` `)&&NT.includes(e.key)&&(e.currentTarget.click(),e.preventDefault())})})},`MenuItem`)),fE=f.forwardRef(MT(function(e,t){let{__scopeMenu:n,disabled:r=!1,textValue:i,...a}=e,o=rE(lE,n),s=WT(n),c=f.useRef(null),l=Pv(t,c),[u,d]=f.useState(!1),[p,m]=f.useState(``);return f.useEffect(()=>{let e=c.current;e&&m((e.textContent??``).trim())},[a.children]),(0,J.jsx)(RT.ItemSlot,{scope:n,disabled:r,textValue:i??p,children:(0,J.jsx)(sw,{asChild:!0,...s,focusable:!r,children:(0,J.jsx)(ty.div,{role:`menuitem`,"data-highlighted":u?``:void 0,"aria-disabled":r||void 0,"data-disabled":r?``:void 0,...a,ref:l,onPointerMove:Ey(e.onPointerMove,OE(e=>{r?o.onItemLeave(e):(o.onItemEnter(e),e.defaultPrevented||e.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:Ey(e.onPointerLeave,OE(e=>o.onItemLeave(e))),onFocus:Ey(e.onFocus,()=>d(!0)),onBlur:Ey(e.onBlur,()=>d(!1))})})})},`MenuItemImpl`)),[pE,mE]=VT(`MenuRadioGroup`,{value:void 0,onValueChange:MT(()=>{},`onValueChange`)}),[hE,gE]=VT(`MenuItemIndicator`,{checked:!1}),_E=f.forwardRef(MT(function(e,t){let{__scopeMenu:n,...r}=e;return(0,J.jsx)(ty.div,{role:`separator`,"aria-orientation":`horizontal`,...r,ref:t})},`MenuSeparator`)),[vE,yE]=VT(`MenuSub`);function bE(e){return e?`open`:`closed`}MT(bE,`getOpenState`);function xE(e){return e===`indeterminate`}MT(xE,`isIndeterminate`);function SE(e){return xE(e)?`indeterminate`:e?`checked`:`unchecked`}MT(SE,`getCheckedState`);function CE(e){let t=document.activeElement;for(let n of e)if(n===t||(n.focus(),document.activeElement!==t))return}MT(CE,`focusFirst`);function wE(e,t){return e.map((n,r)=>e[(t+r)%e.length])}MT(wE,`wrapArray`);function TE(e,t,n){let r=t.length>1&&Array.from(t).every(e=>e===t[0])?t[0]:t,i=n?e.indexOf(n):-1,a=wE(e,Math.max(i,0));r.length===1&&(a=a.filter(e=>e!==n));let o=a.find(e=>e.toLowerCase().startsWith(r.toLowerCase()));return o===n?void 0:o}MT(TE,`getNextMatch`);function EE(e,t){let{x:n,y:r}=e,i=!1;for(let e=0,a=t.length-1;e<t.length;a=e++){let o=t[e],s=t[a],c=o.x,l=o.y,u=s.x,d=s.y;l>r!=d>r&&n<(u-c)*(r-l)/(d-l)+c&&(i=!i)}return i}MT(EE,`isPointInPolygon`);function DE(e,t){return t?EE({x:e.clientX,y:e.clientY},t):!1}MT(DE,`isPointerInGraceArea`);function OE(e){return t=>t.pointerType===`mouse`?e(t):void 0}MT(OE,`whenMouse`);var kE=Object.defineProperty,AE=(e,t)=>kE(e,`name`,{value:t,configurable:!0});function jE(e,t=globalThis?.document){let n=Py(e);f.useEffect(()=>{let e=AE(e=>{e.key===`Escape`&&n(e)},`handleKeyDown`);return t.addEventListener(`keydown`,e,{capture:!0}),()=>t.removeEventListener(`keydown`,e,{capture:!0})},[n,t])}AE(jE,`useEscapeKeydown`);var ME=ty;ME.dispatchDiscreteCustomEvent=ny,ME.Root=ty;var NE=Object.defineProperty,PE=(e,t)=>{let n={};for(var r in e)NE(n,r,{get:e[r],enumerable:!0});return t||NE(n,Symbol.toStringTag,{value:`Module`}),n},FE=Object.defineProperty,IE=(e,t)=>FE(e,`name`,{value:t,configurable:!0}),LE=`DropdownMenu`,[RE,zE]=oy(LE,[HT]),BE=HT(),[VE,HE]=RE(LE),UE=IE(e=>{let{__scopeDropdownMenu:t,children:n,dir:r,open:i,defaultOpen:a,onOpenChange:o,modal:s=!0}=e,c=BE(t),l=f.useRef(null),[u,d]=jC({prop:i,defaultProp:a??!1,onChange:o,caller:LE});return(0,J.jsx)(VE,{scope:t,triggerId:Mb(),triggerRef:l,contentId:Mb(),open:u,onOpenChange:d,onOpenToggle:f.useCallback(()=>d(e=>!e),[d]),modal:s,children:(0,J.jsx)(YT,{...c,open:u,onOpenChange:d,dir:r,modal:s,children:n})})},`DropdownMenu`),WE=`DropdownMenuTrigger`,GE=f.forwardRef(IE(function(e,t){let{__scopeDropdownMenu:n,disabled:r=!1,...i}=e,a=HE(WE,n),o=BE(n),s=Pv(t,a.triggerRef);return(0,J.jsx)(XT,{asChild:!0,...o,children:(0,J.jsx)(ty.button,{type:`button`,id:a.triggerId,"aria-haspopup":`menu`,"aria-expanded":a.open,"aria-controls":a.open?a.contentId:void 0,"data-state":a.open?`open`:`closed`,"data-disabled":r?``:void 0,disabled:r,...i,ref:s,onPointerDown:Ey(e.onPointerDown,e=>{!r&&e.button===0&&e.ctrlKey===!1&&(a.onOpenToggle(),a.open||e.preventDefault())}),onKeyDown:Ey(e.onKeyDown,e=>{r||([`Enter`,` `].includes(e.key)&&a.onOpenToggle(),e.key===`ArrowDown`&&a.onOpenChange(!0),[`Enter`,` `,`ArrowDown`].includes(e.key)&&e.preventDefault())})})})},`DropdownMenuTrigger`)),KE=IE(e=>{let{__scopeDropdownMenu:t,...n}=e,r=BE(t);return(0,J.jsx)(eE,{...r,...n})},`DropdownMenuPortal`),qE=`DropdownMenuContent`,JE=f.forwardRef(IE(function(e,t){let{__scopeDropdownMenu:n,...r}=e,i=HE(qE,n),a=BE(n),o=f.useRef(!1);return(0,J.jsx)(iE,{id:i.contentId,"aria-labelledby":i.triggerId,...a,...r,ref:t,onCloseAutoFocus:Ey(e.onCloseAutoFocus,e=>{o.current||i.triggerRef.current?.focus(),o.current=!1,e.preventDefault()}),onInteractOutside:Ey(e.onInteractOutside,e=>{let t=e.detail.originalEvent,n=t.button===0&&t.ctrlKey===!0,r=t.button===2||n;(!i.modal||r)&&(o.current=!0)}),style:{...e.style,"--radix-dropdown-menu-content-transform-origin":`var(--radix-popper-transform-origin)`,"--radix-dropdown-menu-content-available-width":`var(--radix-popper-available-width)`,"--radix-dropdown-menu-content-available-height":`var(--radix-popper-available-height)`,"--radix-dropdown-menu-trigger-width":`var(--radix-popper-anchor-width)`,"--radix-dropdown-menu-trigger-height":`var(--radix-popper-anchor-height)`}})},`DropdownMenuContent`)),YE=f.forwardRef(IE(function(e,t){let{__scopeDropdownMenu:n,...r}=e,i=BE(n);return(0,J.jsx)(dE,{...i,...r,ref:t})},`DropdownMenuItem`)),XE=f.forwardRef(IE(function(e,t){let{__scopeDropdownMenu:n,...r}=e,i=BE(n);return(0,J.jsx)(_E,{...i,...r,ref:t})},`DropdownMenuSeparator`)),ZE=[`a`,`button`,`div`,`form`,`h2`,`h3`,`img`,`input`,`label`,`li`,`nav`,`ol`,`p`,`select`,`span`,`svg`,`ul`];function QE(e,t){return sn(e,void 0,t===void 0?e.props.children:t)}function $E(e,t,n){return(0,J.jsx)(Rv,{...n,children:QE(e,t)})}function eD(e){let t=nn((t,n)=>{let r=G(17),i,a,o,s;r[0]===t?(i=r[1],a=r[2],o=r[3],s=r[4]):({render:o,asChild:i,children:a,...s}=t,r[0]=t,r[1]=i,r[2]=a,r[3]=o,r[4]=s);let c=e;if(o&&cn(o)){let e=s,t;r[5]!==a||r[6]!==o?(t=QE(o,a),r[5]=a,r[6]=o,r[7]=t):t=r[7];let i;return r[8]!==n||r[9]!==e||r[10]!==t?(i=(0,J.jsx)(c,{...e,asChild:!0,ref:n,children:t}),r[8]=n,r[9]=e,r[10]=t,r[11]=i):i=r[11],i}let l=s,u;return r[12]!==i||r[13]!==a||r[14]!==n||r[15]!==l?(u=(0,J.jsx)(c,{...l,asChild:i,ref:n,children:a}),r[12]=i,r[13]=a,r[14]=n,r[15]=l,r[16]=u):u=r[16],u});return t.displayName=typeof e==`string`?e:e.displayName??e.name??`Component`,t}function tD(e){let t=ME[e],n=eD(t);return n.displayName=`Primitive.${e}`,n}var nD=ZE.reduce((e,t)=>(e[t]=tD(t),e),{}),rD={Hidden:`hidden`,Floating:`floating`,Normal:`normal`},iD=e=>{let t=G(5),{hideWhenRunning:n,autohide:r,autohideFloat:i,forceVisible:a}=e,o;return t[0]!==r||t[1]!==i||t[2]!==a||t[3]!==n?(o=e=>{if(n&&e.thread.isRunning)return rD.Hidden;let t=r===`always`||r===`not-last`&&!e.message.isLast,o=a||e.message.isHovering;return t?o?i===`always`||i===`single-branch`&&e.message.branchCount<=1?rD.Floating:rD.Normal:rD.Hidden:rD.Normal},t[0]=r,t[1]=i,t[2]=a,t[3]=n,t[4]=o):o=t[4],q(o)},aD=pn(null),oD=()=>hn(aD),sD=nn((e,t)=>{let n=G(18),r,i,a,o;n[0]===e?(r=n[1],i=n[2],a=n[3],o=n[4]):({hideWhenRunning:a,autohide:r,autohideFloat:i,...o}=e,n[0]=e,n[1]=r,n[2]=i,n[3]=a,n[4]=o);let[s,c]=H(0),l;n[5]===Symbol.for(`react.memo_cache_sentinel`)?(l=()=>{let e=!1;return c(cD),()=>{e||(e=!0,c(lD))}},n[5]=l):l=n[5];let u=l,d;n[6]===Symbol.for(`react.memo_cache_sentinel`)?(d={acquireInteractionLock:u},n[6]=d):d=n[6];let f=d,p=s>0,m;n[7]!==r||n[8]!==i||n[9]!==a||n[10]!==p?(m={hideWhenRunning:a,autohide:r,autohideFloat:i,forceVisible:p},n[7]=r,n[8]=i,n[9]=a,n[10]=p,n[11]=m):m=n[11];let h=iD(m);if(h===rD.Hidden)return null;let g;n[12]===h?g=n[13]:(g=h===rD.Floating?{"data-floating":`true`}:null,n[12]=h,n[13]=g);let _;return n[14]!==t||n[15]!==o||n[16]!==g?(_=(0,J.jsx)(aD.Provider,{value:f,children:(0,J.jsx)(nD.div,{...g,...o,ref:t})}),n[14]=t,n[15]=o,n[16]=g,n[17]=_):_=n[17],_});sD.displayName=`ActionBarPrimitive.Root`;function cD(e){return e+1}function lD(e){return Math.max(0,e-1)}var uD=e=>{let t=G(4),n;t[0]===e?n=t[1]:(n=e===void 0?{}:e,t[0]=e,t[1]=n);let{copiedDuration:r}=n,i=r===void 0?3e3:r,a;t[2]===i?a=t[3]:(a={copiedDuration:i,copyToClipboard:fD},t[2]=i,t[3]=a);let{copy:o,disabled:s}=k_(a);return s?null:o},dD=nn((e,t)=>{let n=G(20),r,i,a,o;n[0]===e?(r=n[1],i=n[2],a=n[3],o=n[4]):({copiedDuration:r,onClick:a,disabled:i,...o}=e,n[0]=e,n[1]=r,n[2]=i,n[3]=a,n[4]=o);let s=q(pD),c;n[5]===r?c=n[6]:(c={copiedDuration:r},n[5]=r,n[6]=c);let l=uD(c),u;n[7]===s?u=n[8]:(u=s?{"data-copied":`true`}:{},n[7]=s,n[8]=u);let d=i||!l,f;n[9]===l?f=n[10]:(f=()=>{l?.()},n[9]=l,n[10]=f);let p;n[11]!==a||n[12]!==f?(p=Ey(a,f),n[11]=a,n[12]=f,n[13]=p):p=n[13];let m;return n[14]!==t||n[15]!==o||n[16]!==u||n[17]!==d||n[18]!==p?(m=(0,J.jsx)(nD.button,{type:`button`,...u,...o,ref:t,disabled:d,onClick:p}),n[14]=t,n[15]=o,n[16]=u,n[17]=d,n[18]=p,n[19]=m):m=n[19],m});dD.displayName=`ActionBarPrimitive.Copy`;function fD(e){return typeof navigator>`u`||!navigator.clipboard?Promise.reject(Error(`Clipboard API is unavailable`)):navigator.clipboard.writeText(e)}function pD(e){return e.message.isCopied}var mD=(e,t,n=[])=>{let r=nn((e,r)=>{let i=G(6),a={},o={};Object.keys(e).forEach(t=>{n.includes(t)?a[t]=e[t]:o[t]=e[t]});let s=t(a)??void 0,c=nD,l=o.disabled||!s,u=Ey(o.onClick,s),d;return i[0]!==r||i[1]!==o||i[2]!==c.button||i[3]!==l||i[4]!==u?(d=(0,J.jsx)(c.button,{type:`button`,...o,ref:r,disabled:l,onClick:u}),i[0]=r,i[1]=o,i[2]=c.button,i[3]=l,i[4]=u,i[5]=d):d=i[5],d});return r.displayName=e,r},hD=mD(`ActionBarPrimitive.Reload`,()=>{let{disabled:e,reload:t}=I_();return e?null:t}),gD=mD(`ActionBarPrimitive.Edit`,()=>{let{disabled:e,edit:t}=F_();return e?null:t}),_D=mD(`ActionBarPrimitive.Speak`,()=>{let{disabled:e,speak:t}=V_();return e?null:t}),vD=()=>{let{disabled:e,stopSpeaking:t}=H_();return e?null:t},yD=nn((e,t)=>{let n=G(10),r=vD(),i=!r,a;n[0]===r?a=n[1]:(a=()=>{r?.()},n[0]=r,n[1]=a);let o;n[2]!==e.onClick||n[3]!==a?(o=Ey(e.onClick,a),n[2]=e.onClick,n[3]=a,n[4]=o):o=n[4];let s;return n[5]!==e||n[6]!==t||n[7]!==i||n[8]!==o?(s=(0,J.jsx)(nD.button,{type:`button`,disabled:i,...e,ref:t,onClick:o}),n[5]=e,n[6]=t,n[7]=i,n[8]=o,n[9]=s):s=n[9],s});yD.displayName=`ActionBarPrimitive.StopSpeaking`;var bD=()=>{let{submit:e}=L_();return e},xD=nn((e,t)=>{let n=G(18),r,i,a;n[0]===e?(r=n[1],i=n[2],a=n[3]):({onClick:i,disabled:r,...a}=e,n[0]=e,n[1]=r,n[2]=i,n[3]=a);let o=q(SD),s=bD(),c;n[4]===o?c=n[5]:(c=o?{"data-submitted":`true`}:{},n[4]=o,n[5]=c);let l=r||!s,u;n[6]===s?u=n[7]:(u=()=>{s?.()},n[6]=s,n[7]=u);let d;n[8]!==i||n[9]!==u?(d=Ey(i,u),n[8]=i,n[9]=u,n[10]=d):d=n[10];let f;return n[11]!==t||n[12]!==o||n[13]!==a||n[14]!==c||n[15]!==l||n[16]!==d?(f=(0,J.jsx)(nD.button,{type:`button`,"aria-pressed":o,...c,...a,ref:t,disabled:l,onClick:d}),n[11]=t,n[12]=o,n[13]=a,n[14]=c,n[15]=l,n[16]=d,n[17]=f):f=n[17],f});xD.displayName=`ActionBarPrimitive.FeedbackPositive`;function SD(e){return e.message.metadata.submittedFeedback?.type===`positive`}var CD=()=>{let{submit:e}=R_();return e},wD=nn((e,t)=>{let n=G(18),r,i,a;n[0]===e?(r=n[1],i=n[2],a=n[3]):({onClick:i,disabled:r,...a}=e,n[0]=e,n[1]=r,n[2]=i,n[3]=a);let o=q(TD),s=CD(),c;n[4]===o?c=n[5]:(c=o?{"data-submitted":`true`}:{},n[4]=o,n[5]=c);let l=r||!s,u;n[6]===s?u=n[7]:(u=()=>{s?.()},n[6]=s,n[7]=u);let d;n[8]!==i||n[9]!==u?(d=Ey(i,u),n[8]=i,n[9]=u,n[10]=d):d=n[10];let f;return n[11]!==t||n[12]!==o||n[13]!==a||n[14]!==c||n[15]!==l||n[16]!==d?(f=(0,J.jsx)(nD.button,{type:`button`,"aria-pressed":o,...c,...a,ref:t,disabled:l,onClick:d}),n[11]=t,n[12]=o,n[13]=a,n[14]=c,n[15]=l,n[16]=d,n[17]=f):f=n[17],f});wD.displayName=`ActionBarPrimitive.FeedbackNegative`;function TD(e){return e.message.metadata.submittedFeedback?.type===`negative`}var ED=e=>{let t=G(6),n;t[0]===e?n=t[1]:(n=e===void 0?{}:e,t[0]=e,t[1]=n);let{filename:r,onExport:i}=n,a=K(),o=q(kD),s;return t[2]!==a.message||t[3]!==r||t[4]!==i?(s=async()=>{let e=a.message.getCopyText();if(!e)return;if(i){await i(e);return}let t=new Blob([e],{type:`text/markdown`}),n=URL.createObjectURL(t),o=document.createElement(`a`);o.href=n,o.download=r??`message-${Date.now()}.md`,o.rel=`noopener`,document.body.appendChild(o),o.click(),document.body.removeChild(o),setTimeout(()=>URL.revokeObjectURL(n),4e4)},t[2]=a.message,t[3]=r,t[4]=i,t[5]=s):s=t[5],o?s:null},DD=nn((e,t)=>{let n=G(19),r,i,a,o,s;n[0]===e?(r=n[1],i=n[2],a=n[3],o=n[4],s=n[5]):({filename:i,onExport:o,onClick:a,disabled:r,...s}=e,n[0]=e,n[1]=r,n[2]=i,n[3]=a,n[4]=o,n[5]=s);let c;n[6]!==i||n[7]!==o?(c={filename:i,onExport:o},n[6]=i,n[7]=o,n[8]=c):c=n[8];let l=ED(c),u=r||!l,d;n[9]===l?d=n[10]:(d=()=>{l?.().catch(AD)},n[9]=l,n[10]=d);let f;n[11]!==a||n[12]!==d?(f=Ey(a,d),n[11]=a,n[12]=d,n[13]=f):f=n[13];let p;return n[14]!==t||n[15]!==s||n[16]!==u||n[17]!==f?(p=(0,J.jsx)(nD.button,{type:`button`,...s,ref:t,disabled:u,onClick:f}),n[14]=t,n[15]=s,n[16]=u,n[17]=f,n[18]=p):p=n[18],p});DD.displayName=`ActionBarPrimitive.ExportMarkdown`;function OD(e){return e.type===`text`&&e.text.length>0}function kD(e){return(e.message.role!==`assistant`||e.message.status?.type!==`running`)&&e.message.parts.some(OD)}function AD(e){console.error(`[assistant-ui] markdown export failed:`,e)}var jD=PE({Copy:()=>dD,Edit:()=>gD,ExportMarkdown:()=>DD,FeedbackNegative:()=>wD,FeedbackPositive:()=>xD,Reload:()=>hD,Root:()=>sD,Speak:()=>_D,StopSpeaking:()=>yD}),MD=zE(),ND=e=>{let t=G(25),n,r,i,a;t[0]===e?(n=t[1],r=t[2],i=t[3],a=t[4]):({__scopeActionBarMore:n,open:i,onOpenChange:r,...a}=e,t[0]=e,t[1]=n,t[2]=r,t[3]=i,t[4]=a);let o=MD(n),s=oD(),c=U(null),l=i!==void 0,u;t[5]===s?u=t[6]:(u=e=>{if(e){if(c.current)return;c.current=s?.acquireInteractionLock()??null}else c.current?.(),c.current=null},t[5]=s,t[6]=u);let d=u,f;t[7]!==l||t[8]!==r||t[9]!==d?(f=e=>{l||d(e),r?.(e)},t[7]=l,t[8]=r,t[9]=d,t[10]=f):f=t[10];let p=f,m,h;t[11]!==l||t[12]!==i||t[13]!==d?(m=()=>{l&&d(!!i)},h=[l,i,d],t[11]=l,t[12]=i,t[13]=d,t[14]=m,t[15]=h):(m=t[14],h=t[15]),W(m,h);let g,_;t[16]===Symbol.for(`react.memo_cache_sentinel`)?(g=()=>()=>{c.current?.(),c.current=null},_=[],t[16]=g,t[17]=_):(g=t[16],_=t[17]),W(g,_);let v;t[18]===i?v=t[19]:(v=i===void 0?null:{open:i},t[18]=i,t[19]=v);let y;return t[20]!==p||t[21]!==a||t[22]!==o||t[23]!==v?(y=(0,J.jsx)(UE,{...o,...a,...v,onOpenChange:p}),t[20]=p,t[21]=a,t[22]=o,t[23]=v,t[24]=y):y=t[24],y};ND.displayName=`ActionBarMorePrimitive.Root`;var PD=eD(GE),FD=eD(JE),ID=eD(YE),LD=eD(XE),RD=nn((e,t)=>{let n=G(7),r,i;n[0]===e?(r=n[1],i=n[2]):({__scopeActionBarMore:r,...i}=e,n[0]=e,n[1]=r,n[2]=i);let a=MD(r),o;return n[3]!==t||n[4]!==i||n[5]!==a?(o=(0,J.jsx)(PD,{...a,...i,ref:t}),n[3]=t,n[4]=i,n[5]=a,n[6]=o):o=n[6],o});RD.displayName=`ActionBarMorePrimitive.Trigger`;var zD=nn((e,t)=>{let n=G(14),r,i,a,o;n[0]===e?(r=n[1],i=n[2],a=n[3],o=n[4]):({__scopeActionBarMore:r,portalProps:i,sideOffset:o,...a}=e,n[0]=e,n[1]=r,n[2]=i,n[3]=a,n[4]=o);let s=o===void 0?4:o,c=MD(r),l;n[5]!==t||n[6]!==a||n[7]!==c||n[8]!==s?(l=(0,J.jsx)(FD,{...c,...a,ref:t,sideOffset:s}),n[5]=t,n[6]=a,n[7]=c,n[8]=s,n[9]=l):l=n[9];let u;return n[10]!==i||n[11]!==c||n[12]!==l?(u=(0,J.jsx)(KE,{...c,...i,children:l}),n[10]=i,n[11]=c,n[12]=l,n[13]=u):u=n[13],u});zD.displayName=`ActionBarMorePrimitive.Content`;var BD=nn((e,t)=>{let n=G(7),r,i;n[0]===e?(r=n[1],i=n[2]):({__scopeActionBarMore:r,...i}=e,n[0]=e,n[1]=r,n[2]=i);let a=MD(r),o;return n[3]!==t||n[4]!==i||n[5]!==a?(o=(0,J.jsx)(ID,{...a,...i,ref:t}),n[3]=t,n[4]=i,n[5]=a,n[6]=o):o=n[6],o});BD.displayName=`ActionBarMorePrimitive.Item`;var VD=nn((e,t)=>{let n=G(7),r,i;n[0]===e?(r=n[1],i=n[2]):({__scopeActionBarMore:r,...i}=e,n[0]=e,n[1]=r,n[2]=i);let a=MD(r),o;return n[3]!==t||n[4]!==i||n[5]!==a?(o=(0,J.jsx)(LD,{...a,...i,ref:t}),n[3]=t,n[4]=i,n[5]=a,n[6]=o):o=n[6],o});VD.displayName=`ActionBarMorePrimitive.Separator`;var HD=PE({Content:()=>zD,Item:()=>BD,Root:()=>ND,Separator:()=>VD,Trigger:()=>RD}),UD=nn((e,t)=>{let n=G(3),r;return n[0]!==e||n[1]!==t?(r=(0,J.jsx)(nD.div,{...e,ref:t}),n[0]=e,n[1]=t,n[2]=r):r=n[2],r});UD.displayName=`AttachmentPrimitive.Root`;var WD=nn((e,t)=>{let n=G(4),r=q(GD),i=e.children??r,a;return n[0]!==e||n[1]!==t||n[2]!==i?(a=(0,J.jsx)(nD.div,{...e,ref:t,children:i}),n[0]=e,n[1]=t,n[2]=i,n[3]=a):a=n[3],a});WD.displayName=`AttachmentPrimitive.unstable_Thumb`;function GD(e){let t=e.attachment.name,n=t.lastIndexOf(`.`);return n>0&&n<t.length-1?`.${t.slice(n+1)}`:e.attachment.type}var KD=()=>{let e=G(2),t=q(qD),n;return e[0]===t?n=e[1]:(n=(0,J.jsx)(J.Fragment,{children:t}),e[0]=t,e[1]=n),n};KD.displayName=`AttachmentPrimitive.Name`;function qD(e){return e.attachment.name}var JD=mD(`AttachmentPrimitive.Remove`,()=>{let e=G(2),t=K(),n;return e[0]===t.attachment?n=e[1]:(n=()=>{t.attachment.remove()},e[0]=t.attachment,e[1]=n),n}),YD=PE({Name:()=>KD,Remove:()=>JD,Root:()=>UD,unstable_Thumb:()=>WD}),XD=mD(`BranchPickerPrimitive.Next`,()=>{let{disabled:e,next:t}=W_();return e?null:t}),ZD=mD(`BranchPickerPrimitive.Previous`,()=>{let{disabled:e,previous:t}=G_();return e?null:t}),QD=()=>q(eO),$D=()=>{let e=G(2),t=QD(),n;return e[0]===t?n=e[1]:(n=(0,J.jsx)(J.Fragment,{children:t}),e[0]=t,e[1]=n),n};$D.displayName=`BranchPickerPrimitive.Count`;function eO(e){return e.message.branchCount}var tO=()=>q(rO),nO=()=>{let e=G(2),t=tO(),n;return e[0]===t?n=e[1]:(n=(0,J.jsx)(J.Fragment,{children:t}),e[0]=t,e[1]=n),n};nO.displayName=`BranchPickerPrimitive.Number`;function rO(e){return e.message.branchNumber}var iO=nn((e,t)=>{let n=G(11),r,i;n[0]===e?(r=n[1],i=n[2]):({hideWhenSingleBranch:r,...i}=e,n[0]=e,n[1]=r,n[2]=i);let a;n[3]===r?a=n[4]:(a=e=>!r||e.message.branchCount>=2,n[3]=r,n[4]=a);let o;n[5]!==t||n[6]!==i?(o=(0,J.jsx)(nD.div,{...i,ref:t}),n[5]=t,n[6]=i,n[7]=o):o=n[7];let s;return n[8]!==a||n[9]!==o?(s=(0,J.jsx)(Pu,{condition:a,children:o}),n[8]=a,n[9]=o,n[10]=s):s=n[10],s});iO.displayName=`BranchPickerPrimitive.Root`;var aO=PE({Count:()=>$D,Next:()=>XD,Number:()=>nO,Previous:()=>ZD,Root:()=>iO}),oO=pn(null),sO=()=>hn(oO),cO=e=>{let t=G(8),{children:n}=e,r;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(r=new Map,t[0]=r):r=t[0];let i=U(r),a;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(a=[],t[1]=a):a=t[1];let o=U(a),s;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(s=()=>{let e=Array.from(i.current.entries());e.sort(lO),o.current=e.map(uO)},t[2]=s):s=t[2];let c=s,l;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(l=(e,t)=>{let n=t?.priority??0;return i.current.set(e,n),c(),()=>{i.current.delete(e),c()}},t[3]=l):l=t[3];let u=l,d;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(d=()=>o.current,t[4]=d):d=t[4];let f=d,p;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(p={register:u,getPlugins:f},t[5]=p):p=t[5];let m=p,h;return t[6]===n?h=t[7]:(h=(0,J.jsx)(oO.Provider,{value:m,children:n}),t[6]=n,t[7]=h),h};function lO(e,t){return t[1]-e[1]}function uO(e){let[t]=e;return t}var dO=pn(null),fO=pn(null),pO=()=>{let e=hn(dO);if(!e)throw Error(`useTriggerPopoverRootContext must be used within ComposerPrimitive.TriggerPopoverRoot`);return e},mO=()=>hn(dO),hO=()=>{let e=hn(fO);if(!e)throw Error(`useTriggerPopoverAriaPublish must be used within ComposerPrimitive.TriggerPopoverRoot`);return e},gO=()=>{let e=pO();return Zt(e.subscribe,e.getTriggers,e.getTriggers)},_O=new Map,vO=()=>()=>{},yO=()=>_O,bO=()=>{let e=mO();return Zt(e?e.subscribe:vO,e?e.getTriggers:yO,e?e.getTriggers:yO)},xO=()=>null,SO=()=>{let e=mO();return Zt(e?e.subscribeAria:vO,e?e.getActiveAria:xO,e?e.getActiveAria:xO)};function CO(){let e=G(4),t;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t=new Set,e[0]=t):t=e[0];let n=U(t),r;e[1]===Symbol.for(`react.memo_cache_sentinel`)?(r=()=>{for(let e of n.current)e()},e[1]=r):r=e[1];let i=r,a;e[2]===Symbol.for(`react.memo_cache_sentinel`)?(a=e=>(n.current.add(e),()=>{n.current.delete(e)}),e[2]=a):a=e[2];let o=a,s;return e[3]===Symbol.for(`react.memo_cache_sentinel`)?(s={notify:i,subscribe:o},e[3]=s):s=e[3],s}var wO=e=>{let t=G(21),{children:n}=e,r;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(r=new Map,t[0]=r):r=t[0];let i=U(r),a;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(a=new Set,t[1]=a):a=t[1];let o=U(a),{notify:s,subscribe:c}=CO(),l;t[2]===s?l=t[3]:(l=e=>{let{char:t}=e;if(i.current.has(t))return process.env.NODE_ENV!==`production`&&console.warn(`[assistant-ui] Duplicate TriggerPopover for char "${t}". Ignoring the second registration.`),EO;if(process.env.NODE_ENV!==`production`)for(let e of i.current.values())(t.startsWith(e.char)||e.char.startsWith(t))&&console.warn(`[assistant-ui] Trigger prefix collision between "${e.char}" and "${t}". One char is a prefix of the other; only one will match reliably.`);let n=new Map(i.current);n.set(t,e),i.current=n,s();for(let t of o.current)t.added(e);return()=>{let e=new Map(i.current);e.delete(t),i.current=e,s();for(let e of o.current)e.removed(t)}},t[2]=s,t[3]=l);let u=l,d;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(d=()=>i.current,t[4]=d):d=t[4];let f=d,p;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(p=e=>(o.current.add(e),()=>{o.current.delete(e)}),t[5]=p):p=t[5];let m=p,h=U(null),g=U(null),{notify:_,subscribe:v}=CO(),y;t[6]===_?y=t[7]:(y=(e,t)=>{if(t===null){if(g.current!==e)return;h.current=null,g.current=null,_();return}let n=h.current;(g.current!==e||n===null||n.popoverId!==t.popoverId||n.highlightedItemId!==t.highlightedItemId)&&(h.current=t,g.current=e,_())},t[6]=_,t[7]=y);let b=y,x;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(x=()=>h.current,t[8]=x):x=t[8];let S=x,C;t[9]!==u||t[10]!==c||t[11]!==v?(C={register:u,getTriggers:f,subscribe:c,subscribeLifecycle:m,getActiveAria:S,subscribeAria:v},t[9]=u,t[10]=c,t[11]=v,t[12]=C):C=t[12];let w=C,T;t[13]===b?T=t[14]:(T={setActiveAria:b},t[13]=b,t[14]=T);let E=T,D;t[15]!==E||t[16]!==n?(D=(0,J.jsx)(fO.Provider,{value:E,children:n}),t[15]=E,t[16]=n,t[17]=D):D=t[17];let O;return t[18]!==D||t[19]!==w?(O=(0,J.jsx)(dO.Provider,{value:w,children:D}),t[18]=D,t[19]=w,t[20]=O):O=t[20],O},TO=e=>{let t=G(4),{children:n}=e;if(sO()){let e;return t[0]===n?e=t[1]:(e=(0,J.jsx)(wO,{children:n}),t[0]=n,t[1]=e),e}let r;return t[2]===n?r=t[3]:(r=(0,J.jsx)(cO,{children:(0,J.jsx)(wO,{children:n})}),t[2]=n,t[3]=r),r};TO.displayName=`ComposerPrimitive.TriggerPopoverRoot`;function EO(){}var DO=/\s/u;function OO(e,t,n,r){if(r===null)return null;let{query:i,offset:a,endOffset:o}=r;return a<0||a+t.length>n||!e.startsWith(t,a)||o<a+t.length||o>e.length?null:{query:i,offset:a,endOffset:o}}function kO(e,t,n,r){if(r)return OO(e,t,n,r(e,t,n));let i=e.slice(0,n);for(let e=i.length-1;e>=0;e--){let r=i[e];if(DO.test(r))return null;if(i.startsWith(t,e)){if(e>0&&!DO.test(i[e-1]))continue;return{query:i.slice(e+t.length),offset:e,endOffset:n}}}return null}var AO=hr(e=>{let t=G(8),{text:n,triggerChar:r,matcher:i}=e,[a,o]=H(n.length),s=Math.min(a,n.length),c;t[0]!==i||t[1]!==s||t[2]!==n||t[3]!==r?(c=kO(n,r,s,i),t[0]=i,t[1]=s,t[2]=n,t[3]=r,t[4]=c):c=t[4];let l=c,u=l?.query??``,d;return t[5]!==u||t[6]!==l?(d={trigger:l,query:u,setCursorPosition:o},t[5]=u,t[6]=l,t[7]=d):d=t[7],d});function jO(e){return`type`in e}var MO=hr(e=>{let t=G(22),{navigableList:n,isSearchMode:r,activeCategoryId:i,query:a,popoverId:o,open:s,selectItem:c,selectCategory:l,goBack:u,close:d}=e,[f,p]=H(0),m;t[0]!==i||t[1]!==r||t[2]!==n?(m={navigableList:n,isSearchMode:r,activeCategoryId:i},t[0]=i,t[1]=r,t[2]=n,t[3]=m):m=t[3];let[h,g]=H(m);(h.navigableList!==n||h.isSearchMode!==r||h.activeCategoryId!==i)&&(g({navigableList:n,isSearchMode:r,activeCategoryId:i}),p(0));let _;t[4]!==f||t[5]!==n.length?(_=e=>{e<0||e>=n.length||e!==f&&p(e)},t[4]=f,t[5]=n.length,t[6]=_):_=t[6];let v=Xt(_),y;t[7]!==i||t[8]!==d||t[9]!==u||t[10]!==f||t[11]!==n||t[12]!==s||t[13]!==a||t[14]!==l||t[15]!==c?(y=e=>{if(!s)return!1;switch(e.key){case`ArrowDown`:return e.preventDefault(),p(e=>{let t=n.length;return t===0?0:e<t-1?e+1:0}),!0;case`ArrowUp`:return e.preventDefault(),p(e=>{let t=n.length;return t===0?0:e>0?e-1:t-1}),!0;case`Enter`:case`Tab`:{if(e.shiftKey)return!1;e.preventDefault();let t=n[f];return t&&(jO(t)?c(t):l(t.id)),!0}case`Escape`:return e.preventDefault(),d(),!0;case`Backspace`:return i&&a===``?(e.preventDefault(),u(),!0):!1;default:return!1}},t[7]=i,t[8]=d,t[9]=u,t[10]=f,t[11]=n,t[12]=s,t[13]=a,t[14]=l,t[15]=c,t[16]=y):y=t[16];let b=Xt(y),x=n[f],S=s&&x?`${o}-option-${x.id}`:void 0,C;return t[17]!==b||t[18]!==v||t[19]!==f||t[20]!==S?(C={highlightedIndex:f,highlightedItemId:S,highlightIndex:v,handleKeyDown:b},t[17]=b,t[18]=v,t[19]=f,t[20]=S,t[21]=C):C=t[21],C});function NO(e,t){return!t||e.id.toLowerCase().includes(t)||e.label.toLowerCase().includes(t)||(e.description?.toLowerCase().includes(t)??!1)}var PO=hr(e=>{let t=G(35),{adapter:n,query:r,open:i}=e,[a,o]=H(null),[s,c]=H(i);s!==i&&(c(i),i||o(null));let l;bb0:{if(!i||!n){let e;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(e=[],t[0]=e):e=t[0],l=e;break bb0}let e;t[1]===n?e=t[2]:(e=n.categories(),t[1]=n,t[2]=e),l=e}let u=l,d=i?a:null,f;bb1:{if(!d||!n){let e;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(e=[],t[3]=e):e=t[3],f=e;break bb1}let e;t[4]!==n||t[5]!==d?(e=n.categoryItems(d),t[4]=n,t[5]=d,t[6]=e):e=t[6],f=e}let p=f,m;bb2:{if(!i||!n||d||!r&&u.length>0){m=null;break bb2}if(n.search){let e;t[7]!==n||t[8]!==r?(e=n.search(r),t[7]=n,t[8]=r,t[9]=e):e=t[9],m=e;break bb2}let e;if(t[10]!==n||t[11]!==u||t[12]!==r){e=[];let i=r.toLowerCase();for(let t of u)for(let r of n.categoryItems(t.id))NO(r,i)&&e.push(r);t[10]=n,t[11]=u,t[12]=r,t[13]=e}else e=t[13];m=e}let h=m,g=h!==null,_;bb3:{if(g){let e;t[14]===Symbol.for(`react.memo_cache_sentinel`)?(e=[],t[14]=e):e=t[14],_=e;break bb3}if(!r){_=u;break bb3}let e;if(t[15]!==u||t[16]!==r){let n=r.toLowerCase();e=u.filter(e=>e.label.toLowerCase().includes(n)),t[15]=u,t[16]=r,t[17]=e}else e=t[17];_=e}let v=_,y;bb4:{if(g){let e;t[18]===h?e=t[19]:(e=h??[],t[18]=h,t[19]=e),y=e;break bb4}if(!r){y=p;break bb4}let e;if(t[20]!==p||t[21]!==r){let n=r.toLowerCase();e=p.filter(e=>NO(e,n)),t[20]=p,t[21]=r,t[22]=e}else e=t[22];y=e}let b=y,x;bb5:{if(g){let e;t[23]===h?e=t[24]:(e=h??[],t[23]=h,t[24]=e),x=e;break bb5}if(d){x=b;break bb5}x=v}let S=x,C;t[25]===Symbol.for(`react.memo_cache_sentinel`)?(C=e=>{o(e)},t[25]=C):C=t[25];let w=Xt(C),T;t[26]===Symbol.for(`react.memo_cache_sentinel`)?(T=()=>{o(null)},t[26]=T):T=t[26];let E=Xt(T),D;return t[27]!==d||t[28]!==v||t[29]!==b||t[30]!==E||t[31]!==g||t[32]!==S||t[33]!==w?(D={categories:v,items:b,isSearchMode:g,activeCategoryId:d,navigableList:S,selectCategory:w,goBack:E},t[27]=d,t[28]=v,t[29]=b,t[30]=E,t[31]=g,t[32]=S,t[33]=w,t[34]=D):D=t[34],D}),FO=hr(e=>{let t=G(15),{behavior:n,trigger:r,aui:i,setCursorPosition:a,onSelected:o}=e,s=U(null),c;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(c=e=>(s.current=e,()=>{s.current===e&&(s.current=null)}),t[0]=c):c=t[0];let l=Xt(c),u;t[1]!==i||t[2]!==n||t[3]!==o||t[4]!==a||t[5]!==r?(u=e=>{if(!r||!n)return;if(s.current?.(e,()=>{n.kind===`directive`&&n.onInserted?.(e)})){o();return}let t=i.composer.getState().text,c=t.slice(0,r.offset),l=t.slice(r.endOffset),u=()=>{let t=n.formatter.serialize(e);i.composer.setText(c+t+(l.startsWith(` `)?l:` ${l}`),{origin:`user`}),a(c.length+t.length+1)};n.kind===`directive`?(u(),n.onInserted?.(e)):(n.removeOnExecute?(i.composer.setText(c+(l.startsWith(` `)?l.slice(1):l),{origin:`user`}),a(c.length)):u(),n.onExecute(e)),o()},t[1]=i,t[2]=n,t[3]=o,t[4]=a,t[5]=r,t[6]=u):u=t[6];let d=Xt(u),f;t[7]!==o||t[8]!==a||t[9]!==r?(f=()=>{o(),r&&a(r.offset)},t[7]=o,t[8]=a,t[9]=r,t[10]=f):f=t[10];let p=Xt(f),m;return t[11]!==p||t[12]!==l||t[13]!==d?(m={selectItem:d,close:p,registerSelectItemOverride:l},t[11]=p,t[12]=l,t[13]=d,t[14]=m):m=t[14],m}),IO=hr(e=>{let t=G(47),{adapter:n,text:r,triggerChar:i,matcher:a,behavior:o,aui:s,popoverId:c,isLoading:l}=e,u;t[0]!==a||t[1]!==r||t[2]!==i?(u=AO({text:r,triggerChar:i,matcher:a}),t[0]=a,t[1]=r,t[2]=i,t[3]=u):u=t[3];let d=vr(u),f=d.trigger!==null&&n!==void 0&&o!==void 0,p;t[4]!==n||t[5]!==d.query||t[6]!==f?(p=PO({adapter:n,query:d.query,open:f}),t[4]=n,t[5]=d.query,t[6]=f,t[7]=p):p=t[7];let m=vr(p),h;t[8]===m?h=t[9]:(h=()=>{m.goBack()},t[8]=m,t[9]=h);let g=Xt(h),_;t[10]!==s||t[11]!==o||t[12]!==d.setCursorPosition||t[13]!==d.trigger||t[14]!==g||t[15]!==i?(_=FO({behavior:o,trigger:d.trigger,aui:s,triggerChar:i,setCursorPosition:d.setCursorPosition,onSelected:g}),t[10]=s,t[11]=o,t[12]=d.setCursorPosition,t[13]=d.trigger,t[14]=g,t[15]=i,t[16]=_):_=t[16];let v=vr(_),y;t[17]!==d.query||t[18]!==m.activeCategoryId||t[19]!==m.goBack||t[20]!==m.isSearchMode||t[21]!==m.navigableList||t[22]!==m.selectCategory||t[23]!==f||t[24]!==c||t[25]!==v.close||t[26]!==v.selectItem?(y=MO({navigableList:m.navigableList,isSearchMode:m.isSearchMode,activeCategoryId:m.activeCategoryId,query:d.query,popoverId:c,open:f,selectItem:v.selectItem,selectCategory:m.selectCategory,goBack:m.goBack,close:v.close}),t[17]=d.query,t[18]=m.activeCategoryId,t[19]=m.goBack,t[20]=m.isSearchMode,t[21]=m.navigableList,t[22]=m.selectCategory,t[23]=f,t[24]=c,t[25]=v.close,t[26]=v.selectItem,t[27]=y):y=t[27];let b=vr(y),x;return t[28]!==d.query||t[29]!==d.setCursorPosition||t[30]!==l||t[31]!==b.handleKeyDown||t[32]!==b.highlightIndex||t[33]!==b.highlightedIndex||t[34]!==b.highlightedItemId||t[35]!==m.activeCategoryId||t[36]!==m.categories||t[37]!==m.goBack||t[38]!==m.isSearchMode||t[39]!==m.items||t[40]!==m.selectCategory||t[41]!==f||t[42]!==c||t[43]!==v.close||t[44]!==v.registerSelectItemOverride||t[45]!==v.selectItem?(x={open:f,query:d.query,activeCategoryId:m.activeCategoryId,categories:m.categories,items:m.items,highlightedIndex:b.highlightedIndex,isSearchMode:m.isSearchMode,isLoading:l,popoverId:c,highlightedItemId:b.highlightedItemId,selectCategory:m.selectCategory,goBack:m.goBack,selectItem:v.selectItem,close:v.close,highlightIndex:b.highlightIndex,handleKeyDown:b.handleKeyDown,setCursorPosition:d.setCursorPosition,registerSelectItemOverride:v.registerSelectItemOverride},t[28]=d.query,t[29]=d.setCursorPosition,t[30]=l,t[31]=b.handleKeyDown,t[32]=b.highlightIndex,t[33]=b.highlightedIndex,t[34]=b.highlightedItemId,t[35]=m.activeCategoryId,t[36]=m.categories,t[37]=m.goBack,t[38]=m.isSearchMode,t[39]=m.items,t[40]=m.selectCategory,t[41]=f,t[42]=c,t[43]=v.close,t[44]=v.registerSelectItemOverride,t[45]=v.selectItem,t[46]=x):x=t[46],x}),LO=pn(null),RO=()=>{let e=hn(LO);if(!e)throw Error(`useTriggerPopoverScopeContext must be used within ComposerPrimitive.TriggerPopover`);return e},zO=()=>hn(LO),BO=pn(null),VO=()=>{let e=hn(BO);if(!e)throw Error(`TriggerPopover.Directive / TriggerPopover.Action must be rendered inside ComposerPrimitive.TriggerPopover`);return e},HO=nn((e,t)=>{let n=G(70),r,i,a,o,s,c,l;n[0]===e?(r=n[1],i=n[2],a=n[3],o=n[4],s=n[5],c=n[6],l=n[7]):({char:a,matcher:s,adapter:r,isLoading:l,"aria-label":i,children:o,...c}=e,n[0]=e,n[1]=r,n[2]=i,n[3]=a,n[4]=o,n[5]=s,n[6]=c,n[7]=l);let u=l!==void 0&&l,d=K(),f=q(UO),p=en(),m=U(s),h;n[8]===s?h=n[9]:(h=()=>{m.current=s},n[8]=s,n[9]=h),W(h);let g;n[10]===Symbol.for(`react.memo_cache_sentinel`)?(g=()=>(e,t,n)=>m.current(e,t,n),n[10]=g):g=n[10];let[_]=H(g),v=s!==void 0,y=U(null),[b,x]=H(null),S=U(0),C;n[11]===a?C=n[12]:(C=e=>(S.current+=1,process.env.NODE_ENV!==`production`&&S.current>1&&console.warn(`[assistant-ui] TriggerPopover "${a}" received more than one behavior child. Exactly one <TriggerPopover.Directive> or <TriggerPopover.Action> is allowed per TriggerPopover; the last registration wins.`),y.current=e,x(e),()=>{S.current=Math.max(0,S.current-1),y.current===e&&(y.current=null,x(null))}),n[11]=a,n[12]=C);let w=C,T;n[13]===w?T=n[14]:(T={register:w},n[13]=w,n[14]=T);let E=T,D=b??void 0,O;n[15]!==r||n[16]!==d||n[17]!==a||n[18]!==u||n[19]!==s||n[20]!==p||n[21]!==D||n[22]!==f?(O=IO({adapter:r,text:f,triggerChar:a,matcher:s,behavior:D,aui:d,popoverId:p,isLoading:u}),n[15]=r,n[16]=d,n[17]=a,n[18]=u,n[19]=s,n[20]=p,n[21]=D,n[22]=f,n[23]=O):O=n[23];let k=vr(O),A;n[24]===k?A=n[25]:(A=()=>k,n[24]=k,n[25]=A);let j=Xt(A),M=pO(),N;n[26]!==b||n[27]!==a||n[28]!==j||n[29]!==v||n[30]!==_||n[31]!==M?(N=()=>M.register({char:a,...v?{matcher:_}:{},...b?{behavior:b}:{},resource:j()}),n[26]=b,n[27]=a,n[28]=j,n[29]=v,n[30]=_,n[31]=M,n[32]=N):N=n[32];let P;n[33]!==b||n[34]!==a||n[35]!==v||n[36]!==_||n[37]!==M?(P=[M,a,v,_,b],n[33]=b,n[34]=a,n[35]=v,n[36]=_,n[37]=M,n[38]=P):P=n[38],W(N,P);let F=sO(),I;n[39]!==j||n[40]!==F?(I=()=>{if(F)return F.register(j())},n[39]=j,n[40]=F,n[41]=I):I=n[41];let L;n[42]===F?L=n[43]:(L=[F],n[42]=F,n[43]=L),W(I,L);let R=b!==null&&k.open,z=hO(),ee,te;n[44]!==z||n[45]!==a||n[46]!==R?(ee=()=>{if(R)return()=>{z.setActiveAria(a,null)}},te=[z,a,R],n[44]=z,n[45]=a,n[46]=R,n[47]=ee,n[48]=te):(ee=n[47],te=n[48]),W(ee,te);let ne,B;n[49]!==z||n[50]!==a||n[51]!==R||n[52]!==p||n[53]!==k.highlightedItemId?(ne=()=>{R&&z.setActiveAria(a,{popoverId:p,highlightedItemId:k.highlightedItemId})},B=[z,a,p,R,k.highlightedItemId],n[49]=z,n[50]=a,n[51]=R,n[52]=p,n[53]=k.highlightedItemId,n[54]=ne,n[55]=B):(ne=n[54],B=n[55]),W(ne,B);let re;n[56]!==i||n[57]!==o||n[58]!==t||n[59]!==R||n[60]!==p||n[61]!==c||n[62]!==k.highlightedItemId?(re=R?(0,J.jsx)(nD.div,{role:`listbox`,id:p,"aria-label":i??`Suggestions`,"aria-activedescendant":k.highlightedItemId,"data-state":`open`,...c,ref:t,children:o}):o,n[56]=i,n[57]=o,n[58]=t,n[59]=R,n[60]=p,n[61]=c,n[62]=k.highlightedItemId,n[63]=re):re=n[63];let ie;n[64]!==k||n[65]!==re?(ie=(0,J.jsx)(LO.Provider,{value:k,children:re}),n[64]=k,n[65]=re,n[66]=ie):ie=n[66];let V;return n[67]!==E||n[68]!==ie?(V=(0,J.jsx)(BO.Provider,{value:E,children:ie}),n[67]=E,n[68]=ie,n[69]=V):V=n[69],V});HO.displayName=`ComposerPrimitive.TriggerPopover`;function UO(e){return e.composer.text}var WO=()=>{let e=G(2),{disabled:t,send:n}=S_(),r;return e[0]===n?r=e[1]:(r=()=>n(),e[0]=n,e[1]=r),t?null:r},GO=mD(`ComposerPrimitive.Send`,WO),KO=pn(null),qO=()=>hn(KO),JO=`[contenteditable]:not([contenteditable='false'])`,YO=`textarea:not(:disabled), ${JO}`,XO=[`a`,`audio[controls]`,`button`,`details`,`embed`,`iframe`,`input`,`label`,`select`,`summary`,`textarea`,`video[controls]`,JO,`[tabindex]`].join(`, `),ZO=Ut.version.startsWith(`18.`),QO=nn((e,t)=>{let n=G(27),r,i,a,o,s;n[0]===e?(r=n[1],i=n[2],a=n[3],o=n[4],s=n[5]):({onSubmit:o,onMouseDown:a,compact:r,inert:i,...s}=e,n[0]=e,n[1]=r,n[2]=i,n[3]=a,n[4]=o,n[5]=s);let c=WO(),l=q($O),[u,d]=H(!1),f;n[6]===Symbol.for(`react.memo_cache_sentinel`)?(f={setMultiline:d},n[6]=f):f=n[6];let p=f,m;n[7]===r?m=n[8]:(m=e=>r?e.composer.attachments.length===0&&e.composer.quote==null&&e.composer.queue.length===0&&e.composer.dictation==null&&!e.composer.text.includes(`
|
|
60
|
+
`):!1,n[7]=r,n[8]=m);let h=q(m)&&!u,g=ZO&&typeof i==`boolean`?i?``:void 0:i,_;n[9]===c?_=n[10]:(_=e=>{e.preventDefault(),c&&c()},n[9]=c,n[10]=_);let v=_,y=ek,b=r?p:null,x=g,S=h?``:void 0,C;n[11]!==v||n[12]!==o?(C=Ey(o,v),n[11]=v,n[12]=o,n[13]=C):C=n[13];let w;n[14]===a?w=n[15]:(w=Ey(a,y),n[14]=a,n[15]=w);let T;n[16]!==l||n[17]!==t||n[18]!==s||n[19]!==x||n[20]!==S||n[21]!==C||n[22]!==w?(T=(0,J.jsx)(nD.form,{...s,inert:x,"data-aui-composer-type":l,"data-compact":S,ref:t,onSubmit:C,onMouseDown:w}),n[16]=l,n[17]=t,n[18]=s,n[19]=x,n[20]=S,n[21]=C,n[22]=w,n[23]=T):T=n[23];let E;return n[24]!==b||n[25]!==T?(E=(0,J.jsx)(KO.Provider,{value:b,children:T}),n[24]=b,n[25]=T,n[26]=E):E=n[26],E});QO.displayName=`ComposerPrimitive.Root`;function $O(e){return e.composer.type}function ek(e){if(e.button!==0)return;let t=e.target;if(!(t instanceof Element)||!e.currentTarget.contains(t))return;let n=t.closest(XO);if(n&&e.currentTarget.contains(n))return;let r=e.currentTarget.querySelector(YO);r&&(e.preventDefault(),r.focus())}var tk=e=>{let t=G(4),n=Py(e),r=av(nk),i,a;t[0]!==n||t[1]!==r?(i=()=>r(n),a=[r,n],t[0]=n,t[1]=r,t[2]=i,t[3]=a):(i=t[2],a=t[3]),W(i,a)};function nk(e){return e.onScrollToBottom}var rk=()=>!1,ik=()=>{},ak=e=>{let t=G(4),n;t[0]===e?n=t[1]:(n=t=>{if(typeof window>`u`||e===null||!window.matchMedia)return ik;let n=window.matchMedia(e);return n.addEventListener(`change`,t),()=>n.removeEventListener(`change`,t)},t[0]=e,t[1]=n);let r=n,i;return t[2]===e?i=t[3]:(i=()=>typeof window>`u`||e===null||!window.matchMedia?!1:window.matchMedia(e).matches,t[2]=e,t[3]=i),Zt(r,i,rk)},ok=e=>e.isComposing||e.keyCode===229,sk=pn(void 0),ck=()=>hn(sk),lk=`[data-aui-composer-type]`,uk=`[data-aui-thread-root]`,dk=e=>{let t=G(4),n=K(),r=ck(),i;return t[0]!==n.composer||t[1]!==e||t[2]!==r?(i=t=>{let i=r?.current,a=t?.ownerDocument,o=a?.activeElement,s=t?.closest(lk),c=n.composer.getState().type===`edit`&&i&&o&&s?.getAttribute(`data-aui-composer-type`)===`edit`&&s.contains(o)&&s.closest(uk)===i,l=c?Array.from(i.querySelectorAll(YO)).filter(e=>e.closest(uk)===i&&e.closest(lk)?.getAttribute(`data-aui-composer-type`)===`thread`):[];if(e(),a&&o&&c&&(a.activeElement===o||a.activeElement===a.body)){for(let e of l)if(e.isConnected&&!e.closest(`[hidden], [inert]`)&&(e.focus({preventScroll:!0}),a.activeElement!==o&&a.activeElement!==a.body))break}},t[0]=n.composer,t[1]=e,t[2]=r,t[3]=i):i=t[3],i};function fk(){return q(pk)}function pk(e){return e.composer.isEditing?e.composer.text:``}function mk(e){return!!q(hk)||!!e}function hk(e){return e.thread.isDisabled||e.composer.dictation?.inputDisabled}function gk(){let e=G(4),t=SO();if(!t){let t;return e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t={},e[0]=t):t=e[0],t}let n;return e[1]!==t.highlightedItemId||e[2]!==t.popoverId?(n={"aria-controls":t.popoverId,"aria-expanded":!0,"aria-haspopup":`listbox`,"aria-activedescendant":t.highlightedItemId},e[1]=t.highlightedItemId,e[2]=t.popoverId,e[3]=n):n=e[3],n}function _k(){return _k=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},_k.apply(null,arguments)}function vk(e,t){if(e==null)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.indexOf(r)!==-1)continue;n[r]=e[r]}return n}var yk=d.useLayoutEffect,bk=function(e){var t=d.default.useRef(e);return yk(function(){t.current=e}),t},xk=function(e,t){typeof e==`function`?e(t):e.current=t},Sk=function(e,t){var n=d.default.useRef();return d.default.useCallback(function(r){e.current=r,n.current&&xk(n.current,null),n.current=t,t&&xk(t,r)},[t])},Ck={"min-height":`0`,"max-height":`none`,height:`0`,visibility:`hidden`,overflow:`hidden`,position:`absolute`,"z-index":`-1000`,top:`0`,right:`0`,display:`block`},wk=function(e){Object.keys(Ck).forEach(function(t){e.style.setProperty(t,Ck[t],`important`)})},Tk=null,Ek=function(e,t){var n=e.scrollHeight;return t.sizingStyle.boxSizing===`border-box`?n+t.borderSize:n-t.paddingSize};function Dk(e,t,n,r){n===void 0&&(n=1),r===void 0&&(r=1/0),Tk||(Tk=document.createElement(`textarea`),Tk.setAttribute(`tabindex`,`-1`),Tk.setAttribute(`aria-hidden`,`true`),wk(Tk)),Tk.parentNode===null&&document.body.appendChild(Tk);var i=e.paddingSize,a=e.borderSize,o=e.sizingStyle,s=o.boxSizing;Object.keys(o).forEach(function(e){var t=e;Tk.style[t]=o[t]}),wk(Tk),Tk.value=t;var c=Ek(Tk,e);Tk.value=t,c=Ek(Tk,e),Tk.value=`x`;var l=Tk.scrollHeight-i,u=l*n;s===`border-box`&&(u=u+i+a),c=Math.max(u,c);var d=l*r;return s===`border-box`&&(d=d+i+a),c=Math.min(d,c),[c,l]}var Ok=function(){},kk=function(e,t){return e.reduce(function(e,n){return e[n]=t[n],e},{})},Ak=[`borderBottomWidth`,`borderLeftWidth`,`borderRightWidth`,`borderTopWidth`,`boxSizing`,`fontFamily`,`fontSize`,`fontStyle`,`fontWeight`,`letterSpacing`,`lineHeight`,`paddingBottom`,`paddingLeft`,`paddingRight`,`paddingTop`,`tabSize`,`textIndent`,`textRendering`,`textTransform`,`width`,`wordBreak`,`wordSpacing`,`scrollbarGutter`],jk=!!document.documentElement.currentStyle,Mk=function(e){var t=window.getComputedStyle(e);if(t===null)return null;var n=kk(Ak,t),r=n.boxSizing;return r===``?null:(jk&&r===`border-box`&&(n.width=parseFloat(n.width)+parseFloat(n.borderRightWidth)+parseFloat(n.borderLeftWidth)+parseFloat(n.paddingRight)+parseFloat(n.paddingLeft)+`px`),{sizingStyle:n,paddingSize:parseFloat(n.paddingBottom)+parseFloat(n.paddingTop),borderSize:parseFloat(n.borderBottomWidth)+parseFloat(n.borderTopWidth)})};function Nk(e,t,n){var r=bk(n);d.useLayoutEffect(function(){var n=function(e){return r.current(e)};if(e)return e.addEventListener(t,n),function(){return e.removeEventListener(t,n)}},[])}var Pk=function(e,t){Nk(document.body,`reset`,function(n){e.current.form===n.target&&t(n)})},Fk=function(e){Nk(window,`resize`,e)},Ik=function(e){Nk(document.fonts,`loadingdone`,e)},Lk=[`cacheMeasurements`,`maxRows`,`minRows`,`onChange`,`onHeightChange`],Rk=d.forwardRef(function(e,t){var n=e.cacheMeasurements,r=e.maxRows,i=e.minRows,a=e.onChange,o=a===void 0?Ok:a,s=e.onHeightChange,c=s===void 0?Ok:s,l=vk(e,Lk),u=l.value!==void 0,f=d.useRef(null),p=Sk(f,t),m=d.useRef(0),h=d.useRef(),g=function(){var e=f.current,t=n&&h.current?h.current:Mk(e);if(t){h.current=t;var a=Dk(t,e.value||e.placeholder||`x`,i,r),o=a[0],s=a[1];m.current!==o&&(m.current=o,e.style.setProperty(`height`,o+`px`,`important`),c(o,{rowHeight:s}))}};return d.useLayoutEffect(g),Pk(f,function(){if(!u){var e=f.current.value;requestAnimationFrame(function(){var t=f.current;t&&e!==t.value&&g()})}}),Fk(g),Ik(g),d.createElement(`textarea`,_k({},l,{onChange:function(e){u||g(),o(e)},ref:p}))}),zk=`(pointer: coarse) and (not (any-pointer: fine))`,Bk=nn(({autoFocus:e=!1,asChild:t,render:n,disabled:r,onChange:i,onKeyDown:a,onPaste:o,onSelect:s,submitOnEnter:c,submitMode:l,cancelOnEscape:u=!0,unstable_focusOnRunStart:d=!0,unstable_focusOnScrollToBottom:f=!0,unstable_focusOnThreadSwitched:p=!0,unstable_insertNewlineOnTouchEnter:m=!1,addAttachmentOnPaste:h=!0,onHeightChange:g,..._},v)=>{let y=K(),b=ck(),x=sO(),S=qO(),C=l??(c===!1?`none`:`enter`),w=ak(m?zk:null),T=m&&w&&C===`enter`?`none`:C,E=fk(),D=mk(r),O=U(null),k=dk(Jt(()=>y.composer.cancel(),[y])),A=Pv(v,O),j=U(!1);jE(e=>{if(O.current?.contains(e.target)&&!ok(e)){if(x){for(let t of x.getPlugins())if(t.handleKeyDown(e))return}u&&y.composer.getState().canCancel&&(k(O.current),e.preventDefault())}});let M=e=>{if(!D&&!ok(e.nativeEvent)){if(x){for(let t of x.getPlugins())if(t.handleKeyDown(e))return}if(e.key===`Enter`){let t=y.thread.getState(),n=t.capabilities.queue;if(e.shiftKey&&(e.ctrlKey||e.metaKey)&&n&&C!==`none`&&y.composer.getState().canSend){e.preventDefault(),y.composer.send({steer:!0});return}if(e.shiftKey||t.isRunning&&!n&&t.voice===void 0)return;let r=!1;T===`ctrlEnter`?r=e.ctrlKey||e.metaKey:T===`enter`&&(r=!0),r&&(e.preventDefault(),O.current?.closest(`form`)?.requestSubmit())}}},N=async e=>{if(!h)return;let t=y.thread.getState().capabilities,n=Array.from(e.clipboardData?.files||[]);t.attachments&&n.length>0&&(e.preventDefault(),await Promise.all(n.map(async e=>{try{await y.composer.addAttachment(e)}catch{}})))},P=(e,t)=>{if(g?.(e,t),!S)return;let n=O.current;if(!n||n.value===``)return;let r=getComputedStyle(n),i=r.boxSizing===`border-box`?e-parseFloat(r.paddingTop)-parseFloat(r.paddingBottom)-parseFloat(r.borderTopWidth)-parseFloat(r.borderBottomWidth):e;Math.round(i/t.rowHeight)>1&&S.setMultiline(!0)},F=e&&!D,I=Jt(()=>{let e=O.current;e&&F&&(e.focus({preventScroll:!0}),e.setSelectionRange(e.value.length,e.value.length))},[F]),L=Jt(()=>{let e=O.current;if(!e)return;let t=e.ownerDocument,n=t.activeElement;if(n===e)return;let r=b?.current,i=e.closest(`[data-aui-composer-type]`);(!n||n===t.body||i?.contains(n)||r?.contains(n)&&n.closest(`[data-aui-thread-root]`)===r)&&I()},[I,b]);W(()=>I(),[I]),tk(()=>{y.composer.getState().type===`thread`&&f&&I()}),W(()=>{if(y.composer.getState().type===`thread`&&d)return y.on(`thread.runStart`,L)},[d,L,y]),W(()=>{if(y.composer.getState().type===`thread`&&p&&y.optional.threads)return y.on(`threads.selectionChanged`,I)},[p,I,y]),W(()=>{E===``&&S?.setMultiline(!1)},[E,S]);let R=gk(),z={name:`input`,value:E,..._,...R,ref:A,disabled:D,onChange:Ey(i,e=>{if(!y.composer.getState().isEditing)return;let t=e.nativeEvent.isComposing===!0;j.current&&!t&&(j.current=!1);let n=t||j.current;if(Mn(()=>{y.composer.setText(e.target.value,{origin:`user`})}),n)return;let r=e.target.selectionStart??e.target.value.length;if(x)for(let e of x.getPlugins())e.setCursorPosition(r)}),onKeyDown:Ey(a,M),onCompositionStart:Ey(_.onCompositionStart,()=>{j.current=!0}),onCompositionEnd:Ey(_.onCompositionEnd,e=>{if(j.current=!1,!y.composer.getState().isEditing)return;let t=e.target;Mn(()=>{y.composer.setText(t.value,{origin:`user`})});let n=t.selectionStart??t.value.length;if(x)for(let e of x.getPlugins())e.setCursorPosition(n)}),onSelect:Ey(s,e=>{if(j.current)return;let t=e.target,n=t.selectionStart??t.value.length;if(x)for(let e of x.getPlugins())e.setCursorPosition(n)}),onPaste:Ey(o,N),...S?{onHeightChange:P}:g===void 0?{}:{onHeightChange:g}};if(n&&cn(n))return $E(n,_.children,z);let ee=t?Rv:Rk;return(0,J.jsx)(ee,{...z})});Bk.displayName=`ComposerPrimitive.Input`;var Vk=mD(`ComposerPrimitive.Resume`,()=>{let e=G(2),{disabled:t,resume:n}=C_(),r;return e[0]===n?r=e[1]:(r=()=>n(),e[0]=n,e[1]=r),t?null:r}),Hk=mD(`ComposerPrimitive.Cancel`,()=>{let e=G(2),{disabled:t,cancel:n}=w_(),r=dk(n);if(t)return null;let i;return e[0]===r?i=e[1]:(i=e=>r(e.detail===0?e.currentTarget:null),e[0]=r,e[1]=i),i}),Uk=mD(`ComposerPrimitive.AddAttachment`,e=>{let t=G(10),n;t[0]===e?n=t[1]:(n=e===void 0?{}:e,t[0]=e,t[1]=n);let{multiple:r}=n,i=r===void 0||r,{disabled:a,addAttachment:o}=D_(),s=K(),c=U(0),l;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(l=()=>()=>{c.current+=1},t[2]=l):l=t[2];let u;t[3]!==s.composer||t[4]!==s.optional.threadListItem?(u=[s.composer,s.optional.threadListItem],t[3]=s.composer,t[4]=s.optional.threadListItem,t[5]=u):u=t[5],$t(l,u);let d;return t[6]!==o||t[7]!==s.composer||t[8]!==i?(d=()=>{let e=c.current,t=document.createElement(`input`);t.type=`file`,t.multiple=i,t.hidden=!0;let n=s.composer.getState().attachmentAccept;n!==`*`&&(t.accept=n),document.body.appendChild(t),t.onchange=async n=>{let r=n.target.files;if(!r)return;let i=Array.from(r,async t=>{try{if(c.current!==e)return;await o(t)}catch{}});document.body.removeChild(t),await Promise.all(i)},t.oncancel=()=>{t.files&&t.files.length!==0||document.body.removeChild(t)},t.click()},t[6]=o,t[7]=s.composer,t[8]=i,t[9]=d):d=t[9],a?null:d},[`multiple`]),Wk=nn(({disabled:e,asChild:t=!1,render:n,children:r,...i},a)=>{let[o,s]=H(!1),c=K(),l=q(e=>e.thread.isDisabled),u=e||l;W(()=>{u&&s(!1)},[u]);let d=Jt(e=>{e.dataTransfer.types.includes(`Files`)&&(e.preventDefault(),u||!c.thread.getState().capabilities.attachments?e.dataTransfer.dropEffect=`none`:s(!0))},[u,c]),f=Jt(e=>{e.dataTransfer.types.includes(`Files`)&&(e.preventDefault(),u||!c.thread.getState().capabilities.attachments?e.dataTransfer.dropEffect=`none`:o||s(!0))},[u,o,c]),p=Jt(e=>{if(u)return;e.preventDefault();let t=e.relatedTarget;t&&e.currentTarget.contains(t)||s(!1)},[u]),m=Jt(async e=>{if(s(!1),!e.dataTransfer.types.includes(`Files`)||(e.preventDefault(),u))return;let t=Array.from(e.dataTransfer.files);c.thread.getState().capabilities.attachments&&t.length!==0&&await Promise.all(t.map(async e=>{try{await c.composer.addAttachment(e)}catch{}}))},[u,c]),h={...o&&!u?{"data-dragging":`true`}:null,...i,onDragEnterCapture:Ey(i.onDragEnterCapture,d),onDragOverCapture:Ey(i.onDragOverCapture,f),onDragLeaveCapture:Ey(i.onDragLeaveCapture,p),onDropCapture:Ey(i.onDropCapture,m),ref:a};if(n&&cn(n))return $E(n,r,h);let g=t?Rv:`div`;return(0,J.jsx)(g,{...h,children:r})});Wk.displayName=`ComposerPrimitive.AttachmentDropzone`;var Gk=mD(`ComposerPrimitive.Dictate`,()=>{let{disabled:e,startDictation:t}=T_();return e?null:t}),Kk=mD(`ComposerPrimitive.StopDictation`,()=>{let e=G(2),t=K(),n=q(qk),r;return e[0]===t.composer?r=e[1]:(r=()=>{t.composer.stopDictation()},e[0]=t.composer,e[1]=r),n?r:null});function qk(e){return e.composer.dictation!=null}var Jk=nn((e,t)=>{let n=G(7),r,i;n[0]===e?(r=n[1],i=n[2]):({children:r,...i}=e,n[0]=e,n[1]=r,n[2]=i);let a=q(Yk);if(!a)return null;let o=r??a,s;return n[3]!==t||n[4]!==i||n[5]!==o?(s=(0,J.jsx)(nD.span,{...i,ref:t,children:o}),n[3]=t,n[4]=i,n[5]=o,n[6]=s):s=n[6],s});Jk.displayName=`ComposerPrimitive.DictationTranscript`;function Yk(e){return e.composer.dictation?.transcript}var Xk=nn((e,t)=>{let n=G(3);if(!q($k))return null;let r;return n[0]!==t||n[1]!==e?(r=(0,J.jsx)(nD.div,{...e,ref:t}),n[0]=t,n[1]=e,n[2]=r):r=n[2],r});Xk.displayName=`ComposerPrimitive.Quote`;var Zk=nn((e,t)=>{let n=G(7),r,i;n[0]===e?(r=n[1],i=n[2]):({children:r,...i}=e,n[0]=e,n[1]=r,n[2]=i);let a=q(eA);if(!a)return null;let o=r??a,s;return n[3]!==t||n[4]!==i||n[5]!==o?(s=(0,J.jsx)(nD.span,{...i,ref:t,children:o}),n[3]=t,n[4]=i,n[5]=o,n[6]=s):s=n[6],s});Zk.displayName=`ComposerPrimitive.QuoteText`;var Qk=nn((e,t)=>{let n=G(12),r,i;n[0]===e?(r=n[1],i=n[2]):({onClick:r,...i}=e,n[0]=e,n[1]=r,n[2]=i);let a=K(),o;n[3]===a?o=n[4]:(o=()=>{a.composer.setQuote(void 0)},n[3]=a,n[4]=o);let s=o,c;n[5]!==s||n[6]!==r?(c=Ey(r,s),n[5]=s,n[6]=r,n[7]=c):c=n[7];let l;return n[8]!==t||n[9]!==i||n[10]!==c?(l=(0,J.jsx)(nD.button,{type:`button`,...i,ref:t,onClick:c}),n[8]=t,n[9]=i,n[10]=c,n[11]=l):l=n[11],l});Qk.displayName=`ComposerPrimitive.QuoteDismiss`;function $k(e){return e.composer.quote}function eA(e){return e.composer.quote?.text}var tA=nn((e,t)=>{let n=G(12),r,i,a;n[0]===e?(r=n[1],i=n[2],a=n[3]):({children:i,"aria-label":r,...a}=e,n[0]=e,n[1]=r,n[2]=i,n[3]=a);let{categories:o,activeCategoryId:s,isSearchMode:c,open:l}=RO();if(!l||s||c)return null;let u=r??`Categories`,d;n[4]!==o||n[5]!==i?(d=i(o),n[4]=o,n[5]=i,n[6]=d):d=n[6];let f;return n[7]!==t||n[8]!==a||n[9]!==u||n[10]!==d?(f=(0,J.jsx)(nD.div,{role:`group`,"aria-label":u,...a,ref:t,children:d}),n[7]=t,n[8]=a,n[9]=u,n[10]=d,n[11]=f):f=n[11],f});tA.displayName=`ComposerPrimitive.TriggerPopoverCategories`;var nA=nn((e,t)=>{let n=G(30),r,i,a,o;n[0]===e?(r=n[1],i=n[2],a=n[3],o=n[4]):({categoryId:r,onClick:i,onMouseMove:a,...o}=e,n[0]=e,n[1]=r,n[2]=i,n[3]=a,n[4]=o);let{selectCategory:s,highlightIndex:c,categories:l,highlightedIndex:u,activeCategoryId:d,isSearchMode:f,popoverId:p}=RO(),m;n[5]!==r||n[6]!==s?(m=()=>{s(r)},n[5]=r,n[6]=s,n[7]=m):m=n[7];let h=m,g;if(n[8]!==l||n[9]!==r){let e;n[11]===r?e=n[12]:(e=e=>e.id===r,n[11]=r,n[12]=e),g=l.findIndex(e),n[8]=l,n[9]=r,n[10]=g}else g=n[10];let _=g,v=!d&&!f&&_===u,y;n[13]!==_||n[14]!==c?(y=()=>{c(_)},n[13]=_,n[14]=c,n[15]=y):y=n[15];let b=y,x=`${p}-option-${r}`,S=v?``:void 0,C;n[16]!==h||n[17]!==i?(C=Ey(i,h),n[16]=h,n[17]=i,n[18]=C):C=n[18];let w;n[19]!==b||n[20]!==a?(w=Ey(a,b),n[19]=b,n[20]=a,n[21]=w):w=n[21];let T;return n[22]!==t||n[23]!==v||n[24]!==o||n[25]!==x||n[26]!==S||n[27]!==C||n[28]!==w?(T=(0,J.jsx)(nD.button,{type:`button`,role:`option`,id:x,"aria-selected":v,"data-highlighted":S,...o,ref:t,onClick:C,onMouseMove:w}),n[22]=t,n[23]=v,n[24]=o,n[25]=x,n[26]=S,n[27]=C,n[28]=w,n[29]=T):T=n[29],T});nA.displayName=`ComposerPrimitive.TriggerPopoverCategoryItem`;var rA=nn((e,t)=>{let n=G(12),r,i,a;n[0]===e?(r=n[1],i=n[2],a=n[3]):({children:i,"aria-label":r,...a}=e,n[0]=e,n[1]=r,n[2]=i,n[3]=a);let{items:o,activeCategoryId:s,isSearchMode:c,open:l}=RO();if(!l||!s&&!c)return null;let u=r??`Items`,d;n[4]!==i||n[5]!==o?(d=i(o),n[4]=i,n[5]=o,n[6]=d):d=n[6];let f;return n[7]!==t||n[8]!==a||n[9]!==u||n[10]!==d?(f=(0,J.jsx)(nD.div,{role:`group`,"aria-label":u,...a,ref:t,children:d}),n[7]=t,n[8]=a,n[9]=u,n[10]=d,n[11]=f):f=n[11],f});rA.displayName=`ComposerPrimitive.TriggerPopoverItems`;var iA=nn((e,t)=>{let n=G(30),r,i,a,o,s;n[0]===e?(r=n[1],i=n[2],a=n[3],o=n[4],s=n[5]):({item:i,index:r,onClick:a,onMouseMove:o,...s}=e,n[0]=e,n[1]=r,n[2]=i,n[3]=a,n[4]=o,n[5]=s);let{selectItem:c,highlightIndex:l,items:u,highlightedIndex:d,activeCategoryId:f,isSearchMode:p,popoverId:m}=RO(),h;n[6]!==i||n[7]!==c?(h=()=>{c(i)},n[6]=i,n[7]=c,n[8]=h):h=n[8];let g=h,_;n[9]!==r||n[10]!==i.id||n[11]!==u?(_=r??u.findIndex(e=>e.id===i.id),n[9]=r,n[10]=i.id,n[11]=u,n[12]=_):_=n[12];let v=_,y=(p||f!==null)&&v===d,b;n[13]!==l||n[14]!==v?(b=()=>{l(v)},n[13]=l,n[14]=v,n[15]=b):b=n[15];let x=b,S=`${m}-option-${i.id}`,C=y?``:void 0,w;n[16]!==g||n[17]!==a?(w=Ey(a,g),n[16]=g,n[17]=a,n[18]=w):w=n[18];let T;n[19]!==x||n[20]!==o?(T=Ey(o,x),n[19]=x,n[20]=o,n[21]=T):T=n[21];let E;return n[22]!==t||n[23]!==y||n[24]!==s||n[25]!==S||n[26]!==C||n[27]!==w||n[28]!==T?(E=(0,J.jsx)(nD.button,{type:`button`,role:`option`,id:S,"aria-selected":y,"data-highlighted":C,...s,ref:t,onClick:w,onMouseMove:T}),n[22]=t,n[23]=y,n[24]=s,n[25]=S,n[26]=C,n[27]=w,n[28]=T,n[29]=E):E=n[29],E});iA.displayName=`ComposerPrimitive.TriggerPopoverItem`;var aA=nn((e,t)=>{let n=G(10),r,i;n[0]===e?(r=n[1],i=n[2]):({onClick:r,...i}=e,n[0]=e,n[1]=r,n[2]=i);let{activeCategoryId:a,isSearchMode:o,goBack:s,open:c}=RO();if(!c||!a||o)return null;let l;n[3]!==s||n[4]!==r?(l=Ey(r,s),n[3]=s,n[4]=r,n[5]=l):l=n[5];let u;return n[6]!==t||n[7]!==i||n[8]!==l?(u=(0,J.jsx)(nD.button,{type:`button`,...i,ref:t,onClick:l}),n[6]=t,n[7]=i,n[8]=l,n[9]=u):u=n[9],u});aA.displayName=`ComposerPrimitive.TriggerPopoverBack`;var oA=e=>{let t=G(8),{formatter:n,onExecute:r,removeOnExecute:i}=e,{register:a}=VO(),o=U(r),s,c;t[0]===r?(s=t[1],c=t[2]):(s=()=>{o.current=r},c=[r],t[0]=r,t[1]=s,t[2]=c),$t(s,c);let l,u;return t[3]!==n||t[4]!==a||t[5]!==i?(l=()=>{let e={kind:`action`,formatter:n??C,onExecute:e=>o.current(e),...i===void 0?{}:{removeOnExecute:i}};return a(e)},u=[a,n,i],t[3]=n,t[4]=a,t[5]=i,t[6]=l,t[7]=u):(l=t[6],u=t[7]),W(l,u),null};oA.displayName=`ComposerPrimitive.TriggerPopoverAction`;var sA=e=>{let t=G(7),{formatter:n,onInserted:r}=e,{register:i}=VO(),a=U(r),o,s;t[0]===r?(o=t[1],s=t[2]):(o=()=>{a.current=r},s=[r],t[0]=r,t[1]=o,t[2]=s),$t(o,s);let c,l;return t[3]!==n||t[4]!==i?(c=()=>i({kind:`directive`,formatter:n??C,onInserted:e=>a.current?.(e)}),l=[i,n],t[3]=n,t[4]=i,t[5]=c,t[6]=l):(c=t[5],l=t[6]),W(c,l),null};sA.displayName=`ComposerPrimitive.TriggerPopoverDirective`;var cA=Object.assign(HO,{Directive:sA,Action:oA}),lA=PE({AddAttachment:()=>Uk,AttachmentByIndex:()=>Vg,AttachmentDropzone:()=>Wk,Attachments:()=>Ug,Cancel:()=>Hk,Dictate:()=>Gk,DictationTranscript:()=>Jk,If:()=>o_,Input:()=>Bk,Queue:()=>Gg,Quote:()=>Xk,QuoteDismiss:()=>Qk,QuoteText:()=>Zk,Resume:()=>Vk,Root:()=>QO,Send:()=>GO,StopDictation:()=>Kk,TriggerPopover:()=>cA,TriggerPopoverBack:()=>aA,TriggerPopoverCategories:()=>tA,TriggerPopoverCategoryItem:()=>nA,TriggerPopoverItem:()=>iA,TriggerPopoverItems:()=>rA,TriggerPopoverRoot:()=>TO,Unstable_TriggerPopover:()=>cA,Unstable_TriggerPopoverBack:()=>aA,Unstable_TriggerPopoverCategories:()=>tA,Unstable_TriggerPopoverCategoryItem:()=>nA,Unstable_TriggerPopoverItem:()=>iA,Unstable_TriggerPopoverItems:()=>rA,Unstable_TriggerPopoverRoot:()=>TO,unstable_useTriggerPopoverRootContext:()=>pO,unstable_useTriggerPopoverRootContextOptional:()=>mO,unstable_useTriggerPopoverScopeContext:()=>RO,unstable_useTriggerPopoverScopeContextOptional:()=>zO,unstable_useTriggerPopoverTriggers:()=>gO,unstable_useTriggerPopoverTriggersOptional:()=>bO}),uA=Object.freeze({type:`complete`}),dA=Object.freeze({type:`text`,text:``,status:uA}),fA=()=>q(pA);function pA(e){return e.part.type!==`text`&&e.part.type!==`reasoning`?dA:e.part}var mA=pn(null),hA=e=>({useSmoothStatus:gv(()=>e)}),gA=e=>{let t=G(6),{children:n}=e,r;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(r={optional:!0},t[0]=r):r=t[0];let i=vA(r),a=K(),o;t[1]===a.part?o=t[2]:(o=()=>hA(a.part.getState().status),t[1]=a.part,t[2]=o);let[s]=H(o);if(i)return n;let c;return t[3]!==n||t[4]!==s?(c=(0,J.jsx)(mA.Provider,{value:s,children:n}),t[3]=n,t[4]=s,t[5]=c):c=t[5],c},_A=e=>{let t=nn((t,n)=>{let r=G(3),i=t,a;return r[0]!==n||r[1]!==i?(a=(0,J.jsx)(gA,{children:(0,J.jsx)(e,{...i,ref:n})}),r[0]=n,r[1]=i,r[2]=a):a=r[2],a});return t.displayName=e.displayName,t};function vA(e){let t=hn(mA);if(!e?.optional&&!t)throw Error(`This component must be used within a SmoothContextProvider.`);return t}var{useSmoothStatus:yA,useSmoothStatusStore:bA}=rv(vA,`useSmoothStatus`),xA=250,SA=5,CA=class{animationFrameId=null;lastUpdateTime=0;lastCommitTime=-1/0;targetText=``;drainMs=xA;maxCharIntervalMs=SA;maxCharsPerFrame=1/0;minCommitMs=0;currentText;setText;constructor(e,t){this.currentText=e,this.setText=t}start(){this.animationFrameId===null&&(this.lastUpdateTime=performance.now(),this.animate())}stop(){this.animationFrameId!==null&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=null)}animate=()=>{let e=performance.now(),t=e-this.lastUpdateTime,n=this.targetText.length-this.currentText.length,r=Math.min(this.maxCharIntervalMs,this.drainMs/n),i=Math.min(n,this.maxCharsPerFrame),a=0;for(;t>=r&&a<i;)a++,t-=r;a===i&&i===this.maxCharsPerFrame&&(t=0),this.animationFrameId=a===n?null:requestAnimationFrame(this.animate),a!==0&&(this.currentText=this.targetText.slice(0,this.currentText.length+a),this.lastUpdateTime=e-t,(a===n||e-this.lastCommitTime>=this.minCommitMs)&&(this.lastCommitTime=e,this.setText(this.currentText)))}},wA=Object.freeze({type:`running`}),TA=(e,t)=>e!==void 0&&e>0?e:t,EA=(e,t=!1)=>{let{text:n}=e,r=ak(`(prefers-reduced-motion: reduce)`),i=typeof t==`object`&&t?t:void 0,a=t!==!1&&t!==null&&!r,o=TA(i?.drainMs,xA),s=TA(i?.maxCharIntervalMs,SA),c=TA(i?.maxCharsPerFrame,1/0),l=TA(i?.minCommitMs,0),[u,d]=H(e.status.type===`running`?``:n),f=K(),p=q(()=>f.part),[m,h]=H(p);p===m&&n.startsWith(u)||(h(p),d(e.status.type===`running`?``:n));let g=bA({optional:!0}),_=Py(t=>{if(d(t),g){let n=u!==t||e.status.type===`running`?wA:e.status;xv(g).setState(n,!0)}});W(()=>{if(g){let t=a&&(u!==n||e.status.type===`running`)?wA:e.status;xv(g).setState(t,!0)}},[g,a,n,u,e.status]);let[v]=H(()=>new CA(u,_)),[y,b]=H(a);a!==y&&(b(a),a&&p===m&&n.startsWith(v.currentText)&&d(v.currentText)),W(()=>{v.drainMs=o,v.maxCharIntervalMs=s,v.maxCharsPerFrame=c,v.minCommitMs=l},[v,o,s,c,l]);let x=U(p);return W(()=>{let t=x.current!==p;if(x.current=p,!a)v.stop(),v.currentText=n,v.targetText=n,v.lastCommitTime=-1/0;else if(t||!n.startsWith(v.targetText))e.status.type===`running`?(v.currentText=``,v.targetText=n,v.lastCommitTime=-1/0,v.start()):(v.currentText=n,v.targetText=n,v.stop(),_(n));else if(v.targetText=n,e.status.type!==`running`){if(v.currentText===``){v.currentText=n,v.stop(),_(n);return}v.start()}else v.start()},[v,a,n,e.status.type,p,_]),W(()=>()=>{v.stop()},[v]),qt(()=>a?{...e,text:u,status:n===u?e.status:wA}:e,[a,u,e,n])},DA=Object.freeze({type:`complete`}),OA=Object.freeze({type:`image`,image:``,status:DA}),kA=()=>q(AA);function AA(e){return e.part.type===`image`?e.part:OA}var jA=nn(({smooth:e=!0,component:t=nD.span,render:n,...r},i)=>{let{text:a,status:o}=EA(fA(),e),s={"data-status":o.type,...r,ref:i};return n&&cn(n)?$E(n,a,s):(0,J.jsx)(t,{...s,children:a})});jA.displayName=`MessagePartPrimitive.Text`;var MA=nn((e,t)=>{let n=G(4),{image:r}=kA(),i;return n[0]!==t||n[1]!==r||n[2]!==e?(i=(0,J.jsx)(nD.img,{src:r,...e,ref:t}),n[0]=t,n[1]=r,n[2]=e,n[3]=i):i=n[3],i});MA.displayName=`MessagePartPrimitive.Image`;var NA=nn((e,t)=>{let n=G(3),r;return n[0]!==t||n[1]!==e?(r=(0,J.jsx)(nD.div,{role:`alert`,...e,ref:t}),n[0]=t,n[1]=e,n[2]=r):r=n[2],r});NA.displayName=`ErrorPrimitive.Root`;var PA=nn((e,t)=>{let n=G(7),r,i;n[0]===e?(r=n[1],i=n[2]):({children:r,...i}=e,n[0]=e,n[1]=r,n[2]=i);let a=ev();if(a===void 0)return null;let o=r??String(a),s;return n[3]!==t||n[4]!==i||n[5]!==o?(s=(0,J.jsx)(nD.span,{...i,ref:t,children:o}),n[3]=t,n[4]=i,n[5]=o,n[6]=s):s=n[6],s});PA.displayName=`ErrorPrimitive.Message`;var FA=PE({Message:()=>PA,Root:()=>NA}),IA=e=>{let t=G(2),n=U(void 0),r;return t[0]===e?r=t[1]:(r=t=>{n.current&&=(n.current(),void 0),t&&(n.current=e(t))},t[0]=e,t[1]=r),r},LA=(e,t)=>{let n=e.trim().match(/^(\d+(?:\.\d+)?|\.\d+)(em|px|rem)$/);if(!n)return 1/0;let r=Number(n[1]),i=n[2];return i===`px`?r:i===`em`?r*(parseFloat(getComputedStyle(t).fontSize)||16):i===`rem`?r*(parseFloat(getComputedStyle(document.documentElement).fontSize)||16):1/0},RA=e=>e.dataset.messageId,zA=()=>{let e=document.createElement(`div`);return e.dataset.auiTopAnchorReserve=``,e.style.height=`0px`,e.style.flexShrink=`0`,e.style.pointerEvents=`none`,e.setAttribute(`aria-hidden`,`true`),e},BA=(e,t)=>{let n=`${t}px`;return e.style.height!==n&&(e.style.height=n,!0)},VA=e=>{let t=window.devicePixelRatio||1;return Math.round(e*t)/t},HA=()=>{let e=G(4),t=K(),n;e[0]===t.message?n=e[1]:(n=()=>t.message,e[0]=t.message,e[1]=n);let r=q(n),i;return e[2]===r?i=e[3]:(i=e=>{let t=!0,n=()=>{r.setIsHovering(!0)},i=()=>{r.setIsHovering(!1)};return e.addEventListener(`mouseenter`,n),e.addEventListener(`mouseleave`,i),e.matches(`:hover`)&&queueMicrotask(()=>{t&&r.setIsHovering(!0)}),()=>{t=!1,e.removeEventListener(`mouseenter`,n),e.removeEventListener(`mouseleave`,i),r.setIsHovering(!1)}},e[2]=r,e[3]=i),IA(i)},UA=()=>{let e=G(2),t=av(XA),n;return e[0]===t?n=e[1]:(n=e=>e.message.role===`user`&&e.message.index>0&&e.message.index===e.thread.messages.length-2&&e.thread.messages.at(-1)?.role===`assistant`&&(e.message.id===t||e.thread.isRunning),e[0]=t,e[1]=n),q(n)},WA=()=>{let e=G(2),t=av(ZA),n;return e[0]===t?n=e[1]:(n=e=>e.message.isLast&&e.message.role===`assistant`&&e.message.index>=1&&e.thread.messages.at(e.message.index-1)?.role===`user`&&(e.message.id===t||e.thread.isRunning),e[0]=t,e[1]=n),q(n)},GA=(e,t)=>{let n=G(3),r;return n[0]!==e||n[1]!==t?(r=n=>{if(e)return t.getState().registerAnchorElement(n)},n[0]=e,n[1]=t,n[2]=r):r=n[2],IA(r)},KA=e=>{let t=G(3),{active:n,threadViewportStore:r}=e,i;return t[0]!==n||t[1]!==r?(i=e=>{if(!n)return;let t=r.getState(),i=t.topAnchorMessageClamp;return t.registerAnchorTargetElement(e,{tallerThan:LA(i.tallerThan,e),visibleHeight:LA(i.visibleHeight,e)})},t[0]=n,t[1]=r,t[2]=i):i=t[2],IA(i)},qA=e=>{let t=G(7),n,r;t[0]===e?(n=t[1],r=t[2]):({forwardedRef:n,...r}=e,t[0]=e,t[1]=n,t[2]=r);let i=HA(),a=Pv(n,i),o=q(QA),s;return t[3]!==o||t[4]!==r||t[5]!==a?(s=(0,J.jsx)(nD.div,{...r,ref:a,"data-message-id":o}),t[3]=o,t[4]=r,t[5]=a,t[6]=s):s=t[6],s},JA=e=>{let t=G(13),n,r,i;t[0]===e?(n=t[1],r=t[2],i=t[3]):({forwardedRef:n,threadViewportStore:i,...r}=e,t[0]=e,t[1]=n,t[2]=r,t[3]=i);let a=HA(),o=UA(),s=WA(),c=GA(o,i),l;t[4]!==s||t[5]!==i?(l={active:s,threadViewportStore:i},t[4]=s,t[5]=i,t[6]=l):l=t[6];let u=KA(l),d=Pv(n,a,c,u),f=q($A),p=o?``:void 0,m=s?``:void 0,h;return t[7]!==f||t[8]!==r||t[9]!==d||t[10]!==p||t[11]!==m?(h=(0,J.jsx)(nD.div,{...r,ref:d,"data-message-id":f,"data-aui-top-anchor-user":p,"data-aui-top-anchor-target":m}),t[7]=f,t[8]=r,t[9]=d,t[10]=p,t[11]=m,t[12]=h):h=t[12],h},YA=nn((e,t)=>{let n=G(7),r=ov();if(r.getState().turnAnchor===`top`){let i;return n[0]!==t||n[1]!==e||n[2]!==r?(i=(0,J.jsx)(JA,{...e,forwardedRef:t,threadViewportStore:r}),n[0]=t,n[1]=e,n[2]=r,n[3]=i):i=n[3],i}let i;return n[4]!==t||n[5]!==e?(i=(0,J.jsx)(qA,{...e,forwardedRef:t}),n[4]=t,n[5]=e,n[6]=i):i=n[6],i});YA.displayName=`MessagePrimitive.Root`;function XA(e){return e.topAnchorTurn?.anchorId}function ZA(e){return e.topAnchorTurn?.targetId}function QA(e){return e.message.id}function $A(e){return e.message.id}var ej={...Rh,Text:()=>(0,J.jsxs)(`p`,{style:{whiteSpace:`pre-line`},children:[(0,J.jsx)(jA,{}),(0,J.jsx)(Yg,{children:(0,J.jsx)(`span`,{style:{fontFamily:`revert`},children:` ●`})})]}),Image:()=>(0,J.jsx)(MA,{})},tj=e=>{let t=G(10);if(`children`in e){let n;return t[0]===e.children?n=t[1]:(n=(0,J.jsx)(eg,{children:e.children}),t[0]=e.children,t[1]=n),n}let n,r;t[2]===e?(n=t[3],r=t[4]):({components:n,...r}=e,t[2]=e,t[3]=n,t[4]=r);let i;t[5]===n?i=t[6]:(i=n?{...n,Text:n.Text??ej.Text,Image:n.Image??ej.Image}:ej,t[5]=n,t[6]=i);let a=i,o;return t[7]!==r||t[8]!==a?(o=(0,J.jsx)(eg,{components:a,...r}),t[7]=r,t[8]=a,t[9]=o):o=t[9],o};tj.displayName=`MessagePrimitive.Parts`;var nj=e=>{let t=G(12),n;return t[0]!==e.assistant||t[1]!==e.copied||t[2]!==e.hasAttachments||t[3]!==e.hasBranches||t[4]!==e.hasContent||t[5]!==e.last||t[6]!==e.lastOrHover||t[7]!==e.speaking||t[8]!==e.submittedFeedback||t[9]!==e.system||t[10]!==e.user?(n=t=>{let{role:n,attachments:r,parts:i,branchCount:a,isLast:o,speech:s,isCopied:c,isHovering:l}=t.message;return!(e.hasBranches===!0&&a<2||e.user===!0&&n!==`user`||e.user===!1&&n===`user`||e.assistant===!0&&n!==`assistant`||e.assistant===!1&&n===`assistant`||e.system===!0&&n!==`system`||e.system===!1&&n===`system`||e.lastOrHover===!0&&!l&&!o||e.last!==void 0&&e.last!==o||e.copied===!0&&!c||e.copied===!1&&c||e.speaking===!0&&s==null||e.speaking===!1&&s!=null||e.hasAttachments===!0&&(n!==`user`||!r?.length)||e.hasAttachments===!1&&n===`user`&&r?.length||e.hasContent===!0&&i.length===0||e.hasContent===!1&&i.length>0||e.submittedFeedback!==void 0&&(t.message.metadata.submittedFeedback?.type??null)!==e.submittedFeedback)},t[0]=e.assistant,t[1]=e.copied,t[2]=e.hasAttachments,t[3]=e.hasBranches,t[4]=e.hasContent,t[5]=e.last,t[6]=e.lastOrHover,t[7]=e.speaking,t[8]=e.submittedFeedback,t[9]=e.system,t[10]=e.user,t[11]=n):n=t[11],q(n)},rj=e=>{let t=G(3),n,r;return t[0]===e?(n=t[1],r=t[2]):({children:n,...r}=e,t[0]=e,t[1]=n,t[2]=r),nj(r)?n:null};rj.displayName=`MessagePrimitive.If`;var ij=e=>{let{children:t}=e;return ev()===void 0?null:t};ij.displayName=`MessagePrimitive.Error`;var aj=e=>{let t=new Map;for(let n=0;n<e.length;n++){let r=e[n]?.parentId??n,i=t.get(r)??[];i.push(n),t.set(r,i)}let n=[];for(let[e,r]of t){let t=typeof e==`string`?e:void 0;n.push({groupKey:t,indices:r})}return n},oj=e=>{let t=G(9),n=q(mj),r;bb0:{if(n.length===0){let e;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(e=[],t[0]=e):e=t[0],r=e;break bb0}let i;t[1]!==e||t[2]!==n?(i=e(n),t[1]=e,t[2]=n,t[3]=i):i=t[3],r=i}let i=r,a;t[4]===n?a=t[5]:(a=Tl(n),t[4]=n,t[5]=a);let o;return t[6]!==i||t[7]!==a?(o={groups:i,partKeys:a},t[6]=i,t[7]=a,t[8]=o):o=t[8],o},sj={Text:()=>(0,J.jsxs)(`p`,{style:{whiteSpace:`pre-line`},children:[(0,J.jsx)(jA,{}),(0,J.jsx)(Yg,{children:(0,J.jsx)(`span`,{style:{fontFamily:`revert`},children:` ●`})})]}),Reasoning:()=>null,Source:()=>null,Image:()=>(0,J.jsx)(MA,{}),File:()=>null,Unstable_Audio:()=>null,Group:({children:e})=>e},cj=rn(e=>{let t=G(5),{partIndex:n,components:r}=e,i;t[0]===r?i=t[1]:(i=(0,J.jsx)(zh,{components:r}),t[0]=r,t[1]=i);let a;return t[2]!==n||t[3]!==i?(a=(0,J.jsx)(ad,{index:n,children:i}),t[2]=n,t[3]=i,t[4]=a):a=t[4],a},(e,t)=>e.partIndex===t.partIndex&&e.components?.Text===t.components?.Text&&e.components?.Reasoning===t.components?.Reasoning&&e.components?.Source===t.components?.Source&&e.components?.Image===t.components?.Image&&e.components?.File===t.components?.File&&e.components?.Unstable_Audio===t.components?.Unstable_Audio&&e.components?.tools===t.components?.tools&&e.components?.data===t.components?.data),lj=e=>{let t=G(6),{status:n,component:r}=e,i=n.type===`running`,a;t[0]!==r||t[1]!==n?(a=(0,J.jsx)(r,{type:`text`,text:``,status:n}),t[0]=r,t[1]=n,t[2]=a):a=t[2];let o;return t[3]!==i||t[4]!==a?(o=(0,J.jsx)(sd,{text:``,isRunning:i,children:a}),t[3]=i,t[4]=a,t[5]=o):o=t[5],o},uj=Object.freeze({type:`complete`}),dj=rn(e=>{let t=G(6),{components:n}=e,r=q(hj);if(n?.Empty){let e;return t[0]!==n.Empty||t[1]!==r?(e=(0,J.jsx)(n.Empty,{status:r}),t[0]=n.Empty,t[1]=r,t[2]=e):e=t[2],e}let i=n?.Text??sj.Text,a;return t[3]!==r||t[4]!==i?(a=(0,J.jsx)(lj,{status:r,component:i}),t[3]=r,t[4]=i,t[5]=a):a=t[5],a},(e,t)=>e.components?.Empty===t.components?.Empty&&e.components?.Text===t.components?.Text),fj=e=>{let t=G(21),{groupingFunction:n,components:r}=e,i=q(gj),{groups:a,partKeys:o}=oj(n),s;bb0:{if(i===0){let e;t[0]===r?e=t[1]:(e=(0,J.jsx)(dj,{components:r}),t[0]=r,t[1]=e),s=e;break bb0}let e=r?.Text??sj.Text,n=r?.Reasoning??sj.Reasoning,c=r?.Image??sj.Image,l=r?.Source??sj.Source,u=r?.File??sj.File,d=r?.Unstable_Audio??sj.Unstable_Audio,f;t[2]!==r||t[3]!==e||t[4]!==n||t[5]!==c||t[6]!==l||t[7]!==u||t[8]!==d?(f={...r,Text:e,Reasoning:n,Image:c,Source:l,File:u,Unstable_Audio:d},t[2]=r,t[3]=e,t[4]=n,t[5]=c,t[6]=l,t[7]=u,t[8]=d,t[9]=f):f=t[9];let p=f,m;if(t[10]!==r?.Group||t[11]!==p||t[12]!==a||t[13]!==o){let e;t[15]!==r?.Group||t[16]!==p||t[17]!==o?(e=(e,t)=>{let n=r?.Group??sj.Group,i=o[e.indices[0]];return(0,J.jsx)(n,{groupKey:e.groupKey,indices:e.indices,children:e.indices.map(e=>(0,J.jsx)(cj,{partIndex:e,components:p},o[e]))},JSON.stringify([`group`,e.groupKey??null,i?.includes(`:`)?`id:${i}`:t]))},t[15]=r?.Group,t[16]=p,t[17]=o,t[18]=e):e=t[18],m=a.map(e),t[10]=r?.Group,t[11]=p,t[12]=a,t[13]=o,t[14]=m}else m=t[14];s=m}let c=s,l;return t[19]===c?l=t[20]:(l=(0,J.jsx)(J.Fragment,{children:c}),t[19]=c,t[20]=l),l};fj.displayName=`MessagePrimitive.Unstable_PartsGrouped`;var pj=e=>{let t=G(6),n,r;t[0]===e?(n=t[1],r=t[2]):({components:n,...r}=e,t[0]=e,t[1]=n,t[2]=r);let i;return t[3]!==n||t[4]!==r?(i=(0,J.jsx)(fj,{...r,components:n,groupingFunction:aj}),t[3]=n,t[4]=r,t[5]=i):i=t[5],i};pj.displayName=`MessagePrimitive.Unstable_PartsGroupedByParentId`;function mj(e){return e.message.parts}function hj(e){return e.message.status??uj}function gj(e){return e.message.parts.length}var _j=PE({AttachmentByIndex:()=>Fg,Attachments:()=>Lg,Content:()=>tj,Error:()=>ij,GenerativeUI:()=>kh,GroupedParts:()=>Cg,If:()=>rj,PartByIndex:()=>Bh,Parts:()=>tj,Quote:()=>Mg,Root:()=>YA,Unstable_PartsGrouped:()=>fj,Unstable_PartsGroupedByParentId:()=>pj}),vj=({autoScroll:e,scrollToBottomOnRunStart:t=!0,scrollToBottomOnInitialize:n=!0,scrollToBottomOnThreadSwitch:r=!0})=>{let i=K(),a=U(null),o=q(e=>e.thread.messages.length>0),s=q(e=>e.thread.messages[0]?.id),c=q(e=>e.optional.threadListItem?.id),l=q(e=>e.thread.isRunning),u=ov(),d=yv(u),{controller:f}=d;$t(()=>{d.getOptions=()=>{let i=u.getState();return{autoScroll:e??i.turnAnchor!==`top`,holdFollow:l&&i.turnAnchor===`top`&&i.element.viewport===a.current&&i.element.anchor!==null,scrollToBottomOnInitialize:n,scrollToBottomOnRunStart:t&&i.turnAnchor!==`top`,scrollToBottomOnThreadSwitch:r}}});let p=U({threadId:c,firstMessageId:s});return Ev(()=>{let e=p.current;if(p.current={threadId:c,firstMessageId:s},e.threadId!==c)return;let t=e.firstMessageId;t!==void 0&&t!==s&&i.thread.getState().messages.some((e,n)=>n>0&&e.id===t)&&f.messagesPrepended(t)},[i,f,s,c]),Ev(()=>{f.setHasMessages(o)},[f,o,n]),tk(({behavior:e})=>f.scrollToBottom(e)),Wu(`thread.runStart`,()=>f.runStarted()),W(()=>{if(i.optional.threads)return i.on(`threads.selectionChanged`,()=>f.threadSwitched())},[i,f]),IA(Jt(e=>{a.current=e;let t=f.attach(e);return()=>{t(),a.current=null}},[f]))},yj=new WeakMap,bj=nn((e,t)=>{let n=G(9),r=K(),i=U(null),a=Pv(t,i),o;n[0]===e?o=n[1]:(o=t=>{t.key===`Escape`&&i.current&&yj.set(t.nativeEvent,i.current),e.onKeyDown?.(t)},n[0]=e,n[1]=o);let s=o,c,l;n[2]===r?(c=n[3],l=n[4]):(c=()=>{let e=e=>{if(e.key!==`Escape`||ok(e)||e.defaultPrevented||r.thread.source===null)return;let t=yj.get(e)??e.composedPath().find(xj);if(!(t&&t!==i.current)&&r.thread.getState().speech!=null){e.preventDefault();try{r.thread.stopSpeaking()}catch(e){let t=e;if(!(t instanceof Error)||t.message!==`No message is being spoken`)throw t}}};return document.addEventListener(`keydown`,e),()=>{document.removeEventListener(`keydown`,e)}},l=[r],n[2]=r,n[3]=c,n[4]=l),W(c,l);let u;return n[5]!==a||n[6]!==s||n[7]!==e?(u=(0,J.jsx)(sk.Provider,{value:i,children:(0,J.jsx)(nD.div,{...e,"data-aui-thread-root":``,ref:a,onKeyDown:s})}),n[5]=a,n[6]=s,n[7]=e,n[8]=u):u=n[8],u});bj.displayName=`ThreadPrimitive.Root`;function xj(e){return e instanceof Element&&e.hasAttribute(`data-aui-thread-root`)}var Sj=e=>{let{children:t}=e;return q(Cj)?t:null};Sj.displayName=`ThreadPrimitive.Empty`;function Cj(e){return e.thread.isEmpty}var wj=e=>{let t=G(4),n;return t[0]!==e.disabled||t[1]!==e.empty||t[2]!==e.running?(n=t=>!(e.empty===!0&&!t.thread.isEmpty||e.empty===!1&&t.thread.isEmpty||e.running===!0&&!t.thread.isRunning||e.running===!1&&t.thread.isRunning||e.disabled===!0&&!t.thread.isDisabled||e.disabled===!1&&t.thread.isDisabled),t[0]=e.disabled,t[1]=e.empty,t[2]=e.running,t[3]=n):n=t[3],q(n)},Tj=e=>{let t=G(3),n,r;return t[0]===e?(n=t[1],r=t[2]):({children:n,...r}=e,t[0]=e,t[1]=n,t[2]=r),wj(r)?n:null};Tj.displayName=`ThreadPrimitive.If`;var Ej=(e,t)=>{let n=G(3),r;return n[0]!==t||n[1]!==e?(r=n=>{if(!e)return;let r=e(),i=()=>{let e=t?t(n):n.offsetHeight;r.setHeight(e)},a=new ResizeObserver(i);return a.observe(n),i(),()=>{a.disconnect(),r.unregister()}},n[0]=t,n[1]=e,n[2]=r):r=n[2],IA(r)},Dj=e=>{let t=0,n=e;for(;n;)t+=n.offsetTop,n=n.offsetParent;return t},Oj=(e,t)=>{let n=0,r=e;for(;r&&r!==t;)n+=r.offsetTop,r=r.offsetParent;return r===t?n:Dj(e)-Dj(t)},kj=({viewport:e,anchor:t,tallerThan:n,visibleHeight:r})=>{let i=Oj(t,e),a=t.offsetHeight;return i+Math.max(0,a-(a<=n?a:r))},Aj=({scrollHeight:e,...t})=>{let{viewport:n}=t,r=kj(t)+n.clientHeight;return Math.max(0,r-e)},jj=({viewport:e,reserve:t,...n})=>Aj({viewport:e,...n,scrollHeight:e.scrollHeight-t.offsetHeight}),Mj=e=>{let t=new ResizeObserver(e),n=new MutationObserver(e),r=null,i=null,a=null,o=()=>{t.disconnect(),n.disconnect(),r=null,i=null,a=null};return{target:(e,s,c)=>{(r!==e||i!==s||a!==c)&&(o(),t.observe(e),t.observe(s),t.observe(c),n.observe(c,{childList:!0,subtree:!0,characterData:!0}),r=e,i=s,a=c)},disconnect:o}},Nj=e=>{let t=null;return{schedule:()=>{t===null&&(t=requestAnimationFrame(()=>{t=null,e()}))},cancel:()=>{t!==null&&(cancelAnimationFrame(t),t=null)}}},Pj=e=>{let t=null,n,r=null,i=0,a=null,o=!1,s=null,c=()=>{a=null,s=null},l=()=>s!==null&&Math.abs(i-s)<=1,u=()=>{let e=r;if(!e)return;let t=e.scrollTop,n=Math.max(0,e.scrollHeight-e.clientHeight);t<i&&i>n+1&&Math.abs(t-n)<=1&&l()&&!o&&(a??=i,p.schedule()),i=t},d=e=>{r!==e&&(r&&r.removeEventListener(`scroll`,u),r=e,o=!1,c(),e&&(e.addEventListener(`scroll`,u,{passive:!0}),i=e.scrollTop))};function f(){let r=e.getState(),{viewport:i,anchor:l,target:u}=r.element,f=r.targetConfig;if(d(r.turnAnchor===`top`?i:null),r.turnAnchor!==`top`||!i){m.disconnect(),c(),t&&(BA(t,0),t.remove());return}if(!l&&!u&&!f&&r.topAnchorTurn){m.disconnect(),c(),t?.parentElement&&t.parentElement.lastElementChild!==t&&t.parentElement.append(t);return}if(!l||!u||!f){m.disconnect(),c(),t&&(BA(t,0),t.remove());return}if(t??=zA(),(t.parentElement!==u.parentElement||t.previousElementSibling!==u)&&u.after(t),m.target(i,l,u),BA(t,jj({viewport:i,anchor:l,reserve:t,...f}))){p.schedule();return}let h=RA(l),g=VA(kj({viewport:i,anchor:l,...f}));if(h===void 0||h!==n)a=null,o=!1,Math.abs(i.scrollTop-g)>1&&i.scrollTo({top:g,behavior:`smooth`}),h!==void 0&&(n=h);else if(a!==null&&s!==null){let e=VA(a+(g-s));a=null,o=!0,Math.abs(i.scrollTop-e)>1&&i.scrollTo({top:e,behavior:`instant`})}s=g}let p=Nj(f),m=Mj(p.schedule);p.schedule();let h=e.subscribe(p.schedule);return()=>{p.cancel(),h(),m.disconnect(),d(null),t?.remove()}},Fj=e=>{let t=G(4),n=ov(),r,i;t[0]!==e||t[1]!==n?(r=()=>{if(e)return Pj(n)},i=[e,n],t[0]=e,t[1]=n,t[2]=r,t[3]=i):(r=t[2],i=t[3]),Ev(r,i)},Ij=(e,t)=>{if(!e)return!1;let n=t.findIndex(t=>t.id===e.targetId);return n<1?!1:t[n-1]?.id===e.anchorId&&t.slice(n+1).every(e=>e.role===`user`)},Lj=({isRunning:e,messages:t})=>{if(!e)return null;let n=t.at(-1),r=t.at(-2);return r?.role!==`user`||n?.role!==`assistant`?null:{anchorId:r.id,targetId:n.id}},Rj=e=>Lj(e)?.anchorId,zj=e=>Lj(e)?.targetId,Bj=()=>Ej(av(Gj),Kj),Vj=()=>IA(av(qj)),Hj=e=>{let t=G(19),n=ov(),r;t[0]===e?r=t[1]:(r=t=>{if(e)return Rj(t.thread)},t[0]=e,t[1]=r);let i=q(r),a;t[2]===e?a=t[3]:(a=t=>{if(e)return zj(t.thread)},t[2]=e,t[3]=a);let o=q(a),s=av(Jj),c;bb0:{if(!i||!o){c=null;break bb0}let e;t[4]!==i||t[5]!==o?(e={anchorId:i,targetId:o},t[4]=i,t[5]=o,t[6]=e):e=t[6],c=e}let l=c,u;t[7]!==e||t[8]!==s?(u=t=>e&&!!s&&Ij(s,t.thread.messages),t[7]=e,t[8]=s,t[9]=u):u=t[9];let d=q(u),f,p;t[10]!==n||t[11]!==s||t[12]!==d?(f=()=>{s&&!d&&n.getState().setTopAnchorTurn(null)},p=[n,s,d],t[10]=n,t[11]=s,t[12]=d,t[13]=f,t[14]=p):(f=t[13],p=t[14]),Ev(f,p);let m,h;t[15]!==l||t[16]!==n?(m=()=>{if(!l)return;let e=n.getState(),t=e.topAnchorTurn;(t?.anchorId!==l.anchorId||t.targetId!==l.targetId)&&e.setTopAnchorTurn(l)},h=[l,n],t[15]=l,t[16]=n,t[17]=m,t[18]=h):(m=t[17],h=t[18]),Ev(m,h)},Uj=nn((e,t)=>{let n=G(18),r,i,a,o,s,c;n[0]===e?(r=n[1],i=n[2],a=n[3],o=n[4],s=n[5],c=n[6]):({autoScroll:r,scrollToBottomOnRunStart:s,scrollToBottomOnInitialize:o,scrollToBottomOnThreadSwitch:c,children:i,...a}=e,n[0]=e,n[1]=r,n[2]=i,n[3]=a,n[4]=o,n[5]=s,n[6]=c);let l;n[7]!==r||n[8]!==o||n[9]!==s||n[10]!==c?(l={autoScroll:r,scrollToBottomOnRunStart:s,scrollToBottomOnInitialize:o,scrollToBottomOnThreadSwitch:c},n[7]=r,n[8]=o,n[9]=s,n[10]=c,n[11]=l):l=n[11];let u=vj(l),d=Bj(),f=Vj(),p=ov(),m;n[12]===p?m=n[13]:(m=p.getState(),n[12]=p,n[13]=m);let h=m.turnAnchor===`top`;Hj(h),Fj(h);let g=Pv(t,u,d,f),_;return n[14]!==i||n[15]!==g||n[16]!==a?(_=(0,J.jsx)(nD.div,{...a,ref:g,children:i}),n[14]=i,n[15]=g,n[16]=a,n[17]=_):_=n[17],_});Uj.displayName=`ThreadPrimitive.ViewportScrollable`;var Wj=nn((e,t)=>{let n=G(13),r,i,a;n[0]===e?(r=n[1],i=n[2],a=n[3]):({turnAnchor:a,topAnchorMessageClamp:i,...r}=e,n[0]=e,n[1]=r,n[2]=i,n[3]=a);let o;n[4]!==i||n[5]!==a?(o={turnAnchor:a,topAnchorMessageClamp:i},n[4]=i,n[5]=a,n[6]=o):o=n[6];let s;n[7]!==r||n[8]!==t?(s=(0,J.jsx)(Uj,{...r,ref:t}),n[7]=r,n[8]=t,n[9]=s):s=n[9];let c;return n[10]!==o||n[11]!==s?(c=(0,J.jsx)(Cv,{options:o,children:s}),n[10]=o,n[11]=s,n[12]=c):c=n[12],c});Wj.displayName=`ThreadPrimitive.Viewport`;function Gj(e){return e.registerViewport}function Kj(e){return e.clientHeight}function qj(e){return e.registerViewportElement}function Jj(e){return e.topAnchorTurn}var Yj=nn((e,t)=>{let n=G(3),r=Pv(t,Ej(av(Xj),Zj)),i;return n[0]!==e||n[1]!==r?(i=(0,J.jsx)(nD.div,{...e,ref:r}),n[0]=e,n[1]=r,n[2]=i):i=n[2],i});Yj.displayName=`ThreadPrimitive.ViewportFooter`;function Xj(e){return e.registerContentInset}function Zj(e){let t=parseFloat(getComputedStyle(e).marginTop)||0;return e.offsetHeight+t}var Qj=mD(`ThreadPrimitive.ScrollToBottom`,e=>{let t=G(5),n;t[0]===e?n=t[1]:(n=e===void 0?{}:e,t[0]=e,t[1]=n);let{behavior:r}=n,i=av($j),a=ov(),o;return t[2]!==r||t[3]!==a?(o=()=>{a.getState().scrollToBottom({behavior:r})},t[2]=r,t[3]=a,t[4]=o):o=t[4],i?null:o},[`behavior`]);function $j(e){return e.isAtBottom}var eM=mD(`ThreadPrimitive.LoadEarlier`,()=>{let e=G(2),t=K(),n=q(tM),r;return e[0]===t.thread?r=e[1]:(r=()=>{t.thread.loadEarlier()},e[0]=t.thread,e[1]=r),n?r:null});function tM(e){return e.thread.hasEarlier}var nM=mD(`ThreadPrimitive.Suggestion`,e=>{let t=G(4),{prompt:n,send:r,clearComposer:i,autoSend:a}=e,o=r??a??!1,s;t[0]!==i||t[1]!==n||t[2]!==o?(s={prompt:n,send:o,clearComposer:i},t[0]=i,t[1]=n,t[2]=o,t[3]=s):s=t[3];let{disabled:c,trigger:l}=K_(s);return c?null:l},[`prompt`,`send`,`clearComposer`,`autoSend`,`method`]),rM=PE({Empty:()=>Sj,If:()=>Tj,LoadEarlier:()=>eM,MessageByIndex:()=>mh,Messages:()=>vh,Root:()=>bj,Row:()=>Ag,ScrollToBottom:()=>Qj,Suggestion:()=>nM,SuggestionByIndex:()=>t_,Suggestions:()=>i_,Unstable_MessageById:()=>hh,Viewport:()=>Wj,ViewportFooter:()=>Yj,ViewportProvider:()=>Cv}),iM=nn((e,t)=>{let n=G(4),r=q(aM),i=e.children??r,a;return n[0]!==e||n[1]!==t||n[2]!==i?(a=(0,J.jsx)(nD.span,{...e,ref:t,children:i}),n[0]=e,n[1]=t,n[2]=i,n[3]=a):a=n[3],a});iM.displayName=`SuggestionPrimitive.Title`;function aM(e){return e.suggestion.title}var oM=nn((e,t)=>{let n=G(4),r=q(sM),i=e.children??r,a;return n[0]!==e||n[1]!==t||n[2]!==i?(a=(0,J.jsx)(nD.span,{...e,ref:t,children:i}),n[0]=e,n[1]=t,n[2]=i,n[3]=a):a=n[3],a});oM.displayName=`SuggestionPrimitive.Description`;function sM(e){return e.suggestion.label}var cM=mD(`SuggestionPrimitive.Trigger`,e=>{let t=G(4),{send:n,clearComposer:r}=e,i=q(lM),a;t[0]!==r||t[1]!==i||t[2]!==n?(a={prompt:i,send:n,clearComposer:r},t[0]=r,t[1]=i,t[2]=n,t[3]=a):a=t[3];let{trigger:o,disabled:s}=K_(a);return s?null:o},[`send`,`clearComposer`]);function lM(e){return e.suggestion.prompt}var uM=PE({Description:()=>oM,Title:()=>iM,Trigger:()=>cM}),dM=nn((e,t)=>{let n=G(15),r,i,a;n[0]===e?(r=n[1],i=n[2],a=n[3]):({onClick:i,disabled:r,...a}=e,n[0]=e,n[1]=r,n[2]=i,n[3]=a);let o=q(fM),{switchToNewThread:s}=Q_(),c;n[4]===o?c=n[5]:(c=o?{"data-active":`true`,"aria-current":`true`}:null,n[4]=o,n[5]=c);let l;n[6]!==i||n[7]!==s?(l=Ey(i,s),n[6]=i,n[7]=s,n[8]=l):l=n[8];let u;return n[9]!==r||n[10]!==t||n[11]!==a||n[12]!==c||n[13]!==l?(u=(0,J.jsx)(nD.button,{type:`button`,...c,...a,ref:t,disabled:r,onClick:l}),n[9]=r,n[10]=t,n[11]=a,n[12]=c,n[13]=l,n[14]=u):u=n[14],u});dM.displayName=`ThreadListPrimitive.New`;function fM(e){return e.threads.newThreadId===e.threads.mainThreadId}var pM=mD(`ThreadListPrimitive.LoadMore`,()=>{let{loadMore:e,disabled:t}=$_();return t?null:e}),[mM,hM]=dy(`ThreadList`),gM=mM,_M=pn(null),vM=_M.Provider,yM=()=>hn(_M),bM=nn((e,t)=>{let n=G(3),r;return n[0]!==e||n[1]!==t?(r=(0,J.jsx)(gM.Provider,{scope:void 0,children:(0,J.jsx)(gM.Slot,{scope:void 0,children:(0,J.jsx)(nD.div,{...e,ref:t})})}),n[0]=e,n[1]=t,n[2]=r):r=n[2],r});bM.displayName=`ThreadListPrimitive.Root`;var xM=PE({ItemByIndex:()=>Kg,Items:()=>Jg,LoadMore:()=>pM,New:()=>dM,Root:()=>bM}),SM=nn((e,t)=>{let n=q(e=>e.threads.mainThreadId===e.threadListItem.id),r=U(null),i=U(null),a=qt(()=>({triggerRef:r,moreRef:i}),[]),o=hM(void 0),s=Db(),c=e=>{if(e.altKey||e.ctrlKey||e.metaKey||e.shiftKey)return;let t=s===`rtl`?`ArrowLeft`:`ArrowRight`,n=s===`rtl`?`ArrowRight`:`ArrowLeft`,a=r.current,c=i.current;if(a&&e.target===a){if(e.key===`ArrowDown`||e.key===`ArrowUp`){let t=o().map(e=>e.ref.current).filter(e=>e!==null&&!e.disabled),n=t[t.indexOf(a)+(e.key===`ArrowDown`?1:-1)];n&&(n.focus(),e.preventDefault())}else e.key===t&&c&&(c.focus(),e.preventDefault())}else c&&e.target===c&&e.key===n&&(a?.focus(),e.preventDefault())};return(0,J.jsx)(vM,{value:a,children:(0,J.jsx)(nD.div,{...n?{"data-active":`true`,"aria-current":`true`}:null,...e,onKeyDown:Ey(e.onKeyDown,c),ref:t})})});SM.displayName=`ThreadListItemPrimitive.Root`;var CM=mD(`ThreadListItemPrimitive.Archive`,()=>{let{archive:e}=J_();return e}),wM=mD(`ThreadListItemPrimitive.Unarchive`,()=>{let{unarchive:e,disabled:t}=X_();return t?null:e}),TM=mD(`ThreadListItemPrimitive.Delete`,()=>{let{delete:e}=Y_();return e}),EM=mD(`ThreadListItemPrimitive.Trigger`,()=>{let{switchTo:e}=Z_();return e}),DM=nn((e,t)=>{let n=G(3),r=Pv(t,yM()?.triggerRef),i;return n[0]!==e||n[1]!==r?(i=(0,J.jsx)(gM.ItemSlot,{scope:void 0,children:(0,J.jsx)(EM,{...e,ref:r})}),n[0]=e,n[1]=r,n[2]=i):i=n[2],i});DM.displayName=`ThreadListItemPrimitive.Trigger`;var OM=PE({Archive:()=>CM,Delete:()=>TM,Root:()=>SM,Title:()=>Zg,Trigger:()=>DM,Unarchive:()=>wM}),kM=e=>{let t=e;for(;t;){let{overflowY:e}=getComputedStyle(t);if(e===`scroll`||e===`auto`)return t;t=t.parentElement}return null},AM=new WeakMap,jM=e=>{let t=AM.get(e);if(t)return t.count++,t;let n=e.scrollTop,r=e.style.scrollbarWidth,i=getComputedStyle(e),a=i.direction===`rtl`?`paddingLeft`:`paddingRight`,o=e.style[a],s=e.offsetWidth-e.clientWidth-parseFloat(i.borderLeftWidth)-parseFloat(i.borderRightWidth),c=e.ownerDocument,l=(e===c.documentElement||e===c.body)&&s<=0?(c.defaultView?.innerWidth??0)-c.documentElement.clientWidth:s;e.style.scrollbarWidth=`none`,l>0&&(e.style[a]=`${parseFloat(i[a])+l}px`);let u=()=>{e.style.scrollbarWidth=r,e.style[a]=o},d=()=>e.scrollTop=n;e.addEventListener(`scroll`,d);let f={count:1,restore:()=>{e.removeEventListener(`scroll`,d),u()}};return AM.set(e,f),f},MM=(e,t)=>{let n=G(5),r=U(null),i,a;n[0]===Symbol.for(`react.memo_cache_sentinel`)?(i=()=>()=>{r.current?.()},a=[],n[0]=i,n[1]=a):(i=n[0],a=n[1]),W(i,a);let o;return n[2]!==e||n[3]!==t?(o=()=>{r.current?.();let n=kM(e.current);if(!n){r.current=null;return}let i=jM(n),a=setTimeout(()=>r.current?.(),t);r.current=()=>{clearTimeout(a),--i.count===0&&(i.restore(),AM.delete(n)),r.current=null}},n[2]=e,n[3]=t,n[4]=o):o=n[4],o},NM=PE({AssistantRuntimeImpl:()=>pf,BaseAssistantRuntimeCore:()=>mf,CompositeContextProvider:()=>ro,DefaultThreadComposerRuntimeCore:()=>Pf,MessageRepository:()=>Bc,ThreadRuntimeImpl:()=>Kd,getAutoStatus:()=>Nc,splitLocalRuntimeOptions:()=>tv,useComposerInputPluginRegistryOptional:()=>sO,useSmooth:()=>EA,useSmoothStatus:()=>yA,withSmoothContextProvider:()=>_A}),PM=`http://localhost:3000/api/agent/chat`;function FM(e){let t=e.split(/\r?\n/);for(let e of t){if(!e.startsWith(`data:`))continue;let t=e.startsWith(`data: `)?e.slice(6):e.slice(5);if(t)try{return JSON.parse(t)}catch{return null}}return null}async function*IM(e){let t=new TextDecoder,n=``;for(;;){let{done:r,value:i}=await e.read();if(r)break;n+=t.decode(i,{stream:!0});let a;for(;(a=n.search(/\r?\n\r?\n/))!==-1;){let e=n.match(/\r?\n\r?\n/);if(!e)break;let t=n.slice(0,a);n=n.slice(a+e[0].length);let r=FM(t);r&&(yield r)}}if(n+=t.decode(),n){let e=FM(n);e&&(yield e)}}async function*LM({userMessage:e,abortSignal:t,token:n,getConversationId:r,onConversationCreated:i,onCustomEvent:a,onEvent:o}){let s={id:e.id,role:`user`,parts:e.content.filter(e=>e.type===`text`).map(e=>({type:`text`,text:e.text??``})),metadata:{files:[],sentAt:new Date().toISOString()}},c=r(),l=await fetch(PM,{method:`POST`,headers:{"Content-Type":`application/json`,Accept:`text/event-stream`,Token:n},credentials:`include`,signal:t,body:JSON.stringify({message:s,conversationId:c||``})});if(!l.ok){let e=await l.text();throw Error(`请求失败 (${l.status}): ${e}`)}if(!l.body)throw Error(`服务端没有返回数据流`);let u=l.body.getReader(),d=[],f=new Map,p=new Map,m=new Map,h=()=>[...d];try{for await(let e of IM(u)){if(t.aborted)return;let n=e.payload;switch(e.type){case`data-conversation-created`:{let t=e.data?.id;t&&i(t);break}case`text-delta`:{let e=n?.id??`default`,t=n?.text;if(!t)break;let r=f.get(e);r===void 0&&(r=d.length,f.set(e,r),d.push({type:`text`,text:``}));let i=d[r];i.type===`text`&&(d[r]={...i,text:i.text+t}),yield h();break}case`reasoning-start`:{let e=n?.id??`default`,t=Date.now(),r=d.length;p.set(e,r),m.set(e,t),d.push({type:`reasoning`,text:``,timing:{startedAt:t}}),yield h();break}case`reasoning-delta`:{let e=n?.id??`default`;if(!p.has(e)){let t=Date.now(),n=d.length;p.set(e,n),m.set(e,t),d.push({type:`reasoning`,text:``,timing:{startedAt:t}}),yield h()}break}case`reasoning-end`:{let e=n?.id??`default`,t=p.get(e);if(t===void 0)break;let r=d[t];if(r.type!==`reasoning`)break;let i=m.get(e)??r.timing?.startedAt??Date.now();d[t]={...r,timing:{startedAt:i,completedAt:Date.now()}},p.delete(e),m.delete(e),yield h();break}case`tool-call`:case`tool-result`:case`tool-error`:break;case`error`:throw Error(n?.error??`AI 服务执行失败`);default:e.type.startsWith(`data-`)?a?.(e):o?.(e)}}}finally{try{await u.cancel()}catch{}finally{u.releaseLock()}}}var RM=`http://localhost:3000/api/conversations`,zM=new Map,BM=new Set,VM=`currentConversationId`;function HM(){return localStorage.getItem(VM)}function UM(e=``){localStorage.setItem(VM,e)}function WM(){localStorage.removeItem(VM)}function GM(e,t){zM.set(e,t)}var KM=``;function qM(e){KM=e}async function JM(e,t={}){let n=await fetch(`${RM}${e}`,{...t,credentials:`include`,headers:{"Content-Type":`application/json`,Token:KM,...t.headers}}),r=await n.json();if(!n.ok||r.success===!1)throw Error(r.message||`请求失败`);return r}function YM(e){return{remoteId:e.id,status:`regular`,title:e.title||`新会话`}}function XM(e){let t={id:e.id,content:[{type:`text`,text:e.content}],createdAt:new Date(e.createdAt)};return e.role===`user`?{...t,role:`user`,attachments:[],metadata:{custom:{}}}:{...t,role:`assistant`,status:{type:`complete`,reason:`stop`},metadata:{unstable_state:{},unstable_annotations:[],unstable_data:[],steps:[],custom:{}}}}function ZM(e){let t=e.custom?.conversationId;if(typeof t==`string`&&t)return t;let n=zM.get(e.id);if(n)return n;if(!BM.has(e.id))return e.remoteId||void 0}function QM(e){return BM.has(e)}async function $M(e,t,n=20){return JM(`/${encodeURIComponent(e)}/messages?page=${t}&perPage=${n}`)}var eN={async list(){return{threads:(await JM(`/`)).data.map(YM)}},async initialize(e){return BM.add(e),{remoteId:e}},async fetch(e){return YM((await JM(`/${encodeURIComponent(e)}`)).data)},async delete(e){let t=zM.get(e)??(BM.has(e)?void 0:e);t?(await JM(`/${encodeURIComponent(t)}`,{method:`DELETE`}),zM.delete(e),BM.delete(e)):(BM.delete(e),zM.delete(e))},async rename(){},async archive(){},async updateCustom(){},async generateTitle(e,t){return Ss(async e=>{let n=t.find(e=>e.role===`user`)?.content.filter(e=>e.type===`text`).map(e=>e.text).join(``).slice(0,30)||`新会话`;e.appendText(n)})}},tN=`mineScript`,X={"color-white":`#ffffff`,"color-black":`#000000`,"color-transparent":`#00000000`,"color-cold-gray-50":`#F8F9FD`,"color-cold-gray-100":`#F0F3FA`,"color-cold-gray-150":`#E0E3EB`,"color-cold-gray-200":`#D1D4DC`,"color-cold-gray-250":`#C1C4CD`,"color-cold-gray-300":`#B2B5BE`,"color-cold-gray-350":`#A3A6AF`,"color-cold-gray-400":`#9598A1`,"color-cold-gray-450":`#868993`,"color-cold-gray-500":`#787B86`,"color-cold-gray-550":`#6A6D78`,"color-cold-gray-600":`#5D606B`,"color-cold-gray-650":`#50535E`,"color-cold-gray-700":`#434651`,"color-cold-gray-750":`#363A45`,"color-cold-gray-800":`#2A2E39`,"color-cold-gray-850":`#1E222D`,"color-cold-gray-900":`#131722`,"color-cold-gray-950":`#0C0E15`,"color-ripe-red-50":`#FFEBEC`,"color-ripe-red-100":`#FCCBCD`,"color-ripe-red-200":`#FAA1A4`,"color-ripe-red-300":`#F77C80`,"color-ripe-red-400":`#F7525F`,"color-ripe-red-500":`#F23645`,"color-ripe-red-600":`#CC2F3C`,"color-ripe-red-700":`#B22833`,"color-ripe-red-800":`#991F29`,"color-ripe-red-900":`#801922`,"color-ripe-red-a100":`#FF8080`,"color-ripe-red-a200":`#FF5252`,"color-ripe-red-a400":`#FF3333`,"color-ripe-red-a600":`#CC2929`,"color-ripe-red-a700":`#802028`,"color-ripe-red-a800":`#4D191D`,"color-ripe-red-a900":`#331F20`,"color-tan-orange-50":`#FFF3E0`,"color-tan-orange-100":`#FFE0B2`,"color-tan-orange-200":`#FFCC80`,"color-tan-orange-300":`#ffb74d`,"color-tan-orange-400":`#FFA726`,"color-tan-orange-500":`#FF9800`,"color-tan-orange-600":`#FB8C00`,"color-tan-orange-700":`#F57C00`,"color-tan-orange-800":`#EF6C00`,"color-tan-orange-900":`#e65100`,"color-tan-orange-a200":`#ffab40`,"color-tan-orange-a400":`#FF9100`,"color-tan-orange-a600":`#CC7014`,"color-tan-orange-a700":`#8C541C`,"color-tan-orange-a800":`#593A1B`,"color-tan-orange-a900":`#33261A`,"color-iguana-green-100":`#C8E6C9`,"color-iguana-green-200":`#A5D6A7`,"color-iguana-green-300":`#81c784`,"color-iguana-green-400":`#66BB6A`,"color-iguana-green-500":`#4caf50`,"color-iguana-green-600":`#43a047`,"color-iguana-green-700":`#388e3c`,"color-iguana-green-800":`#2E7D32`,"color-iguana-green-900":`#1B5E20`,"color-iguana-green-a700":`#00c853`,"color-banana-yellow-100":`#FFF9C4`,"color-banana-yellow-200":`#FFF59D`,"color-banana-yellow-300":`#FFF176`,"color-banana-yellow-400":`#ffee58`,"color-banana-yellow-500":`#ffeb3b`,"color-banana-yellow-600":`#fdd835`,"color-banana-yellow-700":`#fbc02d`,"color-banana-yellow-800":`#f9a825`,"color-banana-yellow-900":`#F57F17`,"color-banana-yellow-a400":`#ffea00`,"color-banana-yellow-a700":`#EEDA01`,"color-tv-blue-50":`#E3EFFD`,"color-tv-blue-100":`#BBD9FB`,"color-tv-blue-200":`#90BFF9`,"color-tv-blue-300":`#5B9CF6`,"color-tv-blue-400":`#3179F5`,"color-tv-blue-500":`#2962FF`,"color-tv-blue-600":`#1E53E5`,"color-tv-blue-700":`#1848CC`,"color-tv-blue-800":`#143EB3`,"color-tv-blue-900":`#0C3299`,"color-tv-blue-a100":`#82b1ff`,"color-tv-blue-a200":`#448aff`,"color-tv-blue-a400":`#2979ff`,"color-tv-blue-a600":`#2962FF`,"color-tv-blue-a700":`#143A87`,"color-tv-blue-a800":`#142E61`,"color-tv-blue-a900":`#132042`,"color-deep-blue-50":`#EDE7F6`,"color-deep-blue-100":`#D1C4E9`,"color-deep-blue-200":`#B39DDB`,"color-deep-blue-300":`#9575cd`,"color-deep-blue-400":`#7e57c2`,"color-deep-blue-500":`#673ab7`,"color-deep-blue-700":`#512da8`,"color-deep-blue-800":`#4527A0`,"color-deep-blue-900":`#311B92`,"color-deep-blue-a100":`#b388ff`,"color-deep-blue-a200":`#7C4DFF`,"color-deep-blue-a400":`#651FFF`,"color-deep-blue-a700":`#6200EA`,"color-minty-green-50":`#DAF2EE`,"color-minty-green-100":`#ACE5DC`,"color-minty-green-200":`#70CCBD`,"color-minty-green-300":`#42BDA8`,"color-minty-green-400":`#22AB94`,"color-minty-green-500":`#089981`,"color-minty-green-600":`#06806B`,"color-minty-green-700":`#056656`,"color-minty-green-800":`#004D40`,"color-minty-green-900":`#00332A`,"color-minty-green-a400":`#2BD9BC`,"color-minty-green-a600":`#24B29B`,"color-minty-green-a700":`#1B7667`,"color-minty-green-a800":`#10443B`,"color-minty-green-a900":`#082621`,"color-grapes-purple-50":`#F3E5F5`,"color-grapes-purple-100":`#E1BEE7`,"color-grapes-purple-200":`#CE93D8`,"color-grapes-purple-300":`#ba68c8`,"color-grapes-purple-400":`#ab47bc`,"color-grapes-purple-500":`#9c27b0`,"color-grapes-purple-600":`#8e24aa`,"color-grapes-purple-700":`#7b1fa2`,"color-grapes-purple-800":`#6A1B9A`,"color-grapes-purple-900":`#4A148C`,"color-grapes-purple-a100":`#EA80FC`,"color-grapes-purple-a200":`#E040FB`,"color-grapes-purple-a400":`#D500F9`,"color-grapes-purple-a700":`#aa00ff`,"color-berry-pink-100":`#F8BBD0`,"color-berry-pink-200":`#f48fb1`,"color-berry-pink-300":`#f06292`,"color-berry-pink-400":`#ec407a`,"color-berry-pink-500":`#e91e63`,"color-berry-pink-600":`#D81B60`,"color-berry-pink-700":`#C2185B`,"color-berry-pink-800":`#AD1457`,"color-berry-pink-900":`#880E4F`,"color-berry-pink-a100":`#ff80ab`,"color-berry-pink-a200":`#ff4081`,"color-berry-pink-a400":`#f50057`,"color-sky-blue-100":`#B2EBF2`,"color-sky-blue-200":`#80DEEA`,"color-sky-blue-300":`#4dd0e1`,"color-sky-blue-400":`#26c6da`,"color-sky-blue-500":`#00bcd4`,"color-sky-blue-600":`#00acc1`,"color-sky-blue-700":`#0097A7`,"color-sky-blue-800":`#00838F`,"color-sky-blue-900":`#006064`,"color-sky-blue-a400":`#00e5ff`,"color-sky-blue-a700":`#00B8D4`,"color-deep-blue-600":`#5E35B1`,"color-forest-green-50":`#DAF2E6`,"color-forest-green-100":`#ACE5C9`,"color-forest-green-200":`#70CC9E`,"color-forest-green-300":`#42BD7F`,"color-forest-green-400":`#22AB67`,"color-forest-green-500":`#089950`,"color-forest-green-600":`#068043`,"color-forest-green-700":`#056636`,"color-forest-green-800":`#004D27`,"color-forest-green-900":`#1A3326`,"color-facebook":`#1877F2`,"color-deep-facebook":`#1564CA`,"color-twitter":`#1DA1F2`,"color-deep-twitter":`#188CD3`,"color-youtube":`#FF0000`,"color-linkedin":`#007BB5`,"color-seeking-alpha-brand":`#ff7200`};function nN(e,t=1){return e+Math.round(255*Math.min(Math.max(t,0),1)).toString(16).toUpperCase().padStart(2,`0`)}var rN={base:`vs`,inherit:!0,rules:[{token:`comment`,foreground:X[`color-cold-gray-400`]},{token:`comment.annotation`,fontStyle:`bold`},{token:`text`,foreground:X[`color-cold-gray-900`]},{token:`string`,foreground:X[`color-iguana-green-700`]},{token:`constant.numeric`,foreground:X[`color-banana-yellow-900`]},{token:`constant.language`,foreground:X[`color-ripe-red-a600`]},{token:`constant.other.color`,foreground:X[`color-ripe-red-a600`]},{token:`constant.other`,foreground:X[`color-ripe-red-a600`]},{token:`support.variable`,foreground:X[`color-ripe-red-a600`]},{token:`support.function`,foreground:X[`color-tv-blue-a600`]},{token:`support.type`,foreground:X[`color-minty-green-400`],fontStyle:`bold`},{token:`entity.name.type`,foreground:X[`color-minty-green-400`],fontStyle:`bold`},{token:`support.method`,foreground:X[`color-tv-blue-a600`]},{token:`keyword.equals`,foreground:X[`color-minty-green-400`]},{token:`keyword.operator`,foreground:X[`color-minty-green-400`]},{token:`keyword.other`,foreground:X[`color-minty-green-400`]},{token:`keyword`,foreground:X[`color-minty-green-400`]},{token:`variable.other`,foreground:X[`color-cold-gray-800`]},{token:`variable.other.property`,foreground:X[`color-cold-gray-800`]},{token:`paren`,foreground:X[`color-black`]},{token:`entity.name.function`,foreground:X[`color-tv-blue-900`]},{token:`entity.name.method`,foreground:X[`color-tv-blue-900`]},{token:`meta.function-call`,foreground:X[`color-grapes-purple-600`]},{token:`entity.name.module.name`,foreground:X[`color-grapes-purple-600`]},{token:`entity.name.module`,foreground:X[`color-tv-blue-a600`]},{token:``,background:X[`color-white`]}],colors:{"editor.foreground":X[`color-cold-gray-900`],"editor.background":`#00000000`,"editorLineNumber.foreground":X[`color-cold-gray-400`],"editorLineNumber.activeForeground":X[`color-cold-gray-700`],"editorHoverWidget.background":X[`color-white`],"editorHoverWidget.statusBarBackground":X[`color-cold-gray-150`],"editorHoverWidget.foreground":X[`color-cold-gray-900`],"editorWidget.background":X[`color-white`],"editorWidget.foreground":X[`color-cold-gray-900`],"editorGutter.background":`#00000000`,"editor.foldBackground":nN(X[`color-cold-gray-200`],.5),"editor.lineHighlightBackground":X[`color-tv-blue-50`],"editor.lineHighlightBorder":X[`color-tv-blue-50`],"editor.rangeHighlightBackground":X[`color-tv-blue-100`],"editorBracketMatch.background":X[`color-cold-gray-150`],"editor.selectionBackground":X[`color-tv-blue-100`],"editor.selectionHighlightBackground":X[`color-tv-blue-50`],"editor.findMatchBackground":X[`color-tan-orange-100`],"editor.findMatchHighlightBackground":X[`color-tan-orange-100`],"editor.findMatchBorder":X[`color-tan-orange-500`],"list.foreground":X[`color-cold-gray-900`],"list.hoverForeground":X[`color-cold-gray-900`],"list.activeSelectionBackground":X[`color-tv-blue-500`],"list.hoverBackground":X[`color-tv-blue-50`],"list.focusHighlightForeground":X[`color-tv-blue-100`],"list.inactiveSelectionBackground":X[`color-tv-blue-500`],"keybindingLabel.background":X[`color-white`],"keybindingLabel.foreground":X[`color-cold-gray-900`],"keybindingLabel.border":X[`color-cold-gray-150`],"input.foreground":X[`color-cold-gray-900`],"textLink.foreground":X[`color-tv-blue-500`],"textLink.activeForeground":X[`color-tv-blue-600`],"peekViewEditor.matchHighlightBackground":X[`color-tan-orange-100`],"peekViewResult.lineForeground":X[`color-cold-gray-900`],"editorMarkerNavigationWarning.background":X[`color-banana-yellow-800`],"inputValidation.warningBackground":X[`color-banana-yellow-800`],"diffEditor.insertedTextBackground":nN(X[`color-forest-green-500`],.3),"diffEditor.insertedLineBackground":nN(X[`color-forest-green-500`],.15),"diffEditor.removedTextBackground":nN(X[`color-ripe-red-500`],.3),"diffEditor.removedLineBackground":nN(X[`color-ripe-red-500`],.15),"editorInlayHint.background":X[`color-cold-gray-150`],"editorInlayHint.foreground":X[`color-cold-gray-550`],"editorError.foreground":X[`color-ripe-red-500`],"editorWarning.foreground":X[`color-tan-orange-500`]}},iN={base:`vs-dark`,inherit:!0,rules:[{token:`comment`,foreground:X[`color-cold-gray-500`]},{token:`comment.annotation`,fontStyle:`bold`},{token:`text`,foreground:X[`color-white`]},{token:`string`,foreground:X[`color-iguana-green-700`]},{token:`constant.numeric`,foreground:X[`color-banana-yellow-900`]},{token:`constant.language`,foreground:X[`color-ripe-red-300`]},{token:`constant.other.color`,foreground:X[`color-ripe-red-300`]},{token:`constant.other`,foreground:X[`color-ripe-red-300`]},{token:`support.variable`,foreground:X[`color-ripe-red-300`]},{token:`support.function`,foreground:X[`color-tv-blue-300`]},{token:`support.method`,foreground:X[`color-tv-blue-300`]},{token:`support.type`,foreground:X[`color-minty-green-300`],fontStyle:`bold`},{token:`entity.name.type`,foreground:X[`color-minty-green-300`],fontStyle:`bold`},{token:`keyword.equals`,foreground:X[`color-minty-green-300`]},{token:`keyword.operator`,foreground:X[`color-minty-green-300`]},{token:`keyword.other`,foreground:X[`color-minty-green-300`]},{token:`keyword`,foreground:X[`color-minty-green-300`]},{token:`variable.other`,foreground:X[`color-cold-gray-200`]},{token:`variable.other.property`,foreground:X[`color-cold-gray-200`]},{token:`paren`,foreground:X[`color-white`]},{token:`entity.name.function`,foreground:X[`color-tv-blue-400`]},{token:`entity.name.method`,foreground:X[`color-tv-blue-400`]},{token:`meta.function-call`,foreground:X[`color-grapes-purple-300`]},{token:`entity.name.module.name`,foreground:X[`color-grapes-purple-300`]},{token:`entity.name.module`,foreground:X[`color-tv-blue-300`]},{token:``,background:X[`color-cold-gray-900`]}],colors:{"editor.foreground":X[`color-white`],"editor.background":X[`color-cold-gray-900`],"editorLineNumber.foreground":X[`color-cold-gray-500`],"editorLineNumber.activeForeground":X[`color-cold-gray-300`],"editorWidget.background":X[`color-cold-gray-850`],"editorHoverWidget.background":X[`color-cold-gray-850`],"editorHoverWidget.foreground":X[`color-cold-gray-300`],"editorHoverWidget.statusBarBackground":X[`color-cold-gray-900`],"editorWidget.foreground":X[`color-cold-gray-300`],"editorGutter.background":X[`color-cold-gray-900`],"editor.foldBackground":nN(X[`color-cold-gray-700`],.5),"editor.lineHighlightBackground":X[`color-tv-blue-a900`],"editor.lineHighlightBorder":X[`color-tv-blue-a900`],"editor.rangeHighlightBackground":X[`color-tv-blue-a800`],"editorBracketMatch.background":X[`color-cold-gray-750`],"editor.selectionBackground":X[`color-tv-blue-a800`],"editor.selectionHighlightBackground":X[`color-cold-gray-800`],"list.foreground":X[`color-cold-gray-350`],"list.hoverForeground":X[`color-cold-gray-350`],"list.activeSelectionBackground":X[`color-tv-blue-500`],"list.hoverBackground":X[`color-tv-blue-900`],"list.focusHighlightForeground":X[`color-tv-blue-300`],"list.inactiveSelectionBackground":X[`color-tv-blue-500`],"keybindingLabel.background":X[`color-cold-gray-800`],"keybindingLabel.foreground":X[`color-cold-gray-300`],"keybindingLabel.border":X[`color-cold-gray-700`],"input.foreground":X[`color-cold-gray-350`],"textLink.foreground":X[`color-tv-blue-500`],"textLink.activeForeground":X[`color-tv-blue-600`],"peekViewEditor.matchHighlightBackground":X[`color-tan-orange-a800`],"peekViewResult.lineForeground":X[`color-cold-gray-350`],"diffEditor.insertedTextBackground":nN(X[`color-iguana-green-a700`],.3),"diffEditor.insertedLineBackground":nN(X[`color-iguana-green-a700`],.15),"diffEditor.removedTextBackground":nN(X[`color-ripe-red-a400`],.3),"diffEditor.removedLineBackground":nN(X[`color-ripe-red-a400`],.15),"editorInlayHint.background":X[`color-cold-gray-800`],"editorInlayHint.foreground":X[`color-cold-gray-400`],"editorError.foreground":X[`color-ripe-red-500`],"editorWarning.foreground":X[`color-tan-orange-700`]}},aN={builtinFunctions:/strategy\.closedtrades\.max_drawdown_percent|strategy\.opentrades\.max_drawdown_percent|strategy\.risk\.max_intraday_filled_orders|strategy\.closedtrades\.max_runup_percent|array\.percentile_linear_interpolation|strategy\.closedtrades\.entry_bar_index|strategy\.opentrades\.max_runup_percent|strategy\.closedtrades\.exit_bar_index|strategy\.closedtrades\.profit_percent|strategy\.closedtrades\.entry_comment|strategy\.opentrades\.entry_bar_index|strategy\.closedtrades\.exit_comment|strategy\.closedtrades\.max_drawdown|strategy\.opentrades\.profit_percent|ta\.percentile_linear_interpolation|strategy\.closedtrades\.entry_price|strategy\.opentrades\.entry_comment|strategy\.closedtrades\.commission|strategy\.closedtrades\.entry_time|strategy\.closedtrades\.exit_price|strategy\.opentrades\.max_drawdown|strategy\.risk\.max_cons_loss_days|strategy\.closedtrades\.exit_time|strategy\.closedtrades\.max_runup|strategy\.opentrades\.entry_price|strategy\.risk\.max_intraday_loss|strategy\.risk\.max_position_size|table\.cell_set_text_font_family|strategy\.closedtrades\.entry_id|strategy\.opentrades\.commission|strategy\.opentrades\.entry_time|table\.cell_set_text_formatting|array\.binary_search_rightmost|array\.percentile_nearest_rank|strategy\.closedtrades\.exit_id|strategy\.opentrades\.direction|strategy\.opentrades\.max_runup|array\.binary_search_leftmost|strategy\.closedtrades\.profit|strategy\.opentrades\.entry_id|strategy\.risk\.allow_entry_in|strategy\.convert_to_account|box\.set_bottom_right_point|label\.set_text_font_family|strategy\.closedtrades\.size|strategy\.convert_to_symbol|strategy\.default_entry_qty|strategy\.opentrades\.profit|strategy\.risk\.max_drawdown|ta\.percentile_nearest_rank|table\.cell_set_text_halign|table\.cell_set_text_valign|label\.set_text_formatting|request\.security_lower_tf|table\.cell_set_text_color|box\.set_text_font_family|strategy\.close_all_short|strategy\.opentrades\.size|table\.cell_set_text_size|box\.set_text_formatting|matrix\.is_antisymmetric|strategy\.close_all_long|box\.set_top_left_point|chart\.point\.from_index|matrix\.is_antidiagonal|table\.cell_set_bgcolor|table\.cell_set_tooltip|table\.set_border_color|table\.set_border_width|timeframe\.from_seconds|chart\.point\.from_time|line\.set_second_point|math\.round_to_mintick|matrix\.elements_count|ta\.pivot_point_levels|table\.cell_set_height|table\.set_frame_color|table\.set_frame_width|box\.set_border_color|box\.set_border_style|box\.set_border_width|line\.set_first_point|matrix\.is_stochastic|matrix\.is_triangular|table\.cell_set_width|timeframe\.in_seconds|array\.binary_search|box\.set_rightbottom|box\.set_text_halign|box\.set_text_valign|color\.from_gradient|label\.set_textalign|label\.set_textcolor|matrix\.eigenvectors|matrix\.is_symmetric|matrix\.swap_columns|strategy\.cancel_all|table\.cell_set_text|array\.new_linefill|array\.sort_indices|box\.set_text_color|linefill\.get_line1|linefill\.get_line2|linefill\.set_color|map\.new|matrix\.eigenvalues|matrix\.is_diagonal|matrix\.is_identity|strategy\.close_all|table\.set_position|array\.lastindexof|array\.percentrank|array\.standardize|box\.set_text_size|box\.set_text_wrap|label\.set_tooltip|matrix\.remove_col|matrix\.remove_row|table\.merge_cells|table\.set_bgcolor|array\.covariance|array\.new_string|chart\.point\.copy|matrix\.is_binary|matrix\.is_square|matrix\.new|matrix\.submatrix|matrix\.swap_rows|matrix\.transpose|request\.security|timeframe\.change|array\.new|array\.new_color|array\.new_float|array\.new_label|array\.new_table|box\.set_bgcolor|box\.set_lefttop|chart\.point\.new|chart\.point\.now|input\.text_area|input\.timeframe|label\.set_color|label\.set_point|label\.set_style|line\.set_extend|linefill\.delete|polyline\.delete|str\.format_time|str\.replace_all|strategy\.cancel|alertcondition|array\.includes|array\.new_bool|array\.new_line|array\.variance|box\.get_bottom|box\.set_bottom|box\.set_extend|label\.get_text|label\.set_size|label\.set_text|label\.set_xloc|label\.set_yloc|line\.get_price|line\.set_color|line\.set_style|line\.set_width|math\.todegrees|math\.toradians|matrix\.add_col|matrix\.add_row|matrix\.columns|matrix\.is_zero|matrix\.reshape|matrix\.reverse|str\.startswith|strategy\.close|strategy\.entry|strategy\.order|syminfo\.prefix|syminfo\.ticker|ta\.correlation|ta\.highestbars|ta\.percentrank|array\.indexof|array\.new_box|array\.new_int|array\.reverse|array\.unshift|box\.get_right|box\.set_right|input\.session|line\.set_xloc|matrix\.concat|matrix\.median|max_bars_back|runtime\.error|str\.substring|strategy\.exit|ta\.crossunder|ta\.lowestbars|ta\.supertrend|array\.concat|array\.insert|array\.median|array\.remove|box\.get_left|box\.set_left|box\.set_text|box\.set_xloc|input\.source|input\.string|input\.symbol|label\.delete|label\.set_xy|line\.set_xy1|line\.set_xy2|linefill\.new|map\.contains|matrix\.trace|polyline\.new|str\.contains|str\.endswith|str\.tonumber|str\.tostring|ta\.barssince|ta\.crossover|ta\.pivothigh|ta\.valuewhen|table\.delete|array\.clear|array\.every|array\.first|array\.range|array\.shift|array\.slice|array\.stdev|box\.get_top|box\.set_top|input\.color|input\.float|input\.price|label\.get_x|label\.get_y|label\.set_x|label\.set_y|line\.delete|line\.get_x1|line\.get_x2|line\.get_y1|line\.get_y2|line\.set_x1|line\.set_x2|line\.set_y1|line\.set_y2|log\.warning|map\.put_all|math\.random|matrix\.copy|matrix\.diff|matrix\.fill|matrix\.kron|matrix\.mode|matrix\.mult|matrix\.pinv|matrix\.rank|matrix\.rows|matrix\.sort|str\.replace|ta\.pivotlow|ta\.variance|table\.clear|array\.copy|array\.fill|array\.from|array\.join|array\.last|array\.mode|array\.push|array\.size|array\.some|array\.sort|box\.delete|dayofmonth|input\.bool|input\.enum|input\.time|label\.copy|map\.remove|map\.values|math\.floor|math\.log10|math\.round|matrix\.avg|matrix\.col|matrix\.det|matrix\.get|matrix\.inv|matrix\.max|matrix\.min|matrix\.pow|matrix\.row|matrix\.set|matrix\.sum|plotcandle|str\.format|str\.length|str\.repeat|ta\.falling|ta\.highest|table\.cell|time_close|weekofyear|array\.abs|array\.avg|array\.get|array\.max|array\.min|array\.pop|array\.set|array\.sum|color\.new|color\.rgb|dayofweek|indicator|input\.int|label\.new|line\.copy|log\.error|map\.clear|math\.acos|math\.asin|math\.atan|math\.ceil|math\.sign|math\.sqrt|plotarrow|plotshape|str\.lower|str\.match|str\.split|str\.upper|ta\.change|ta\.linreg|ta\.lowest|ta\.median|ta\.rising|table\.new|timestamp|barcolor|box\.copy|line\.new|linefill|log\.info|map\.copy|map\.keys|map\.size|math\.abs|math\.avg|math\.cos|math\.exp|math\.log|math\.max|math\.min|math\.pow|math\.sin|math\.sum|math\.tan|plotchar|str\.trim|strategy|ta\.cross|ta\.range|ta\.stdev|ta\.stoch|bgcolor|box\.new|color\.b|color\.g|color\.r|color\.t|library|map\.get|map\.put|plotbar|str\.pos|ta\.alma|ta\.macd|ta\.mode|ta\.swma|ta\.vwap|ta\.vwma|fixnan|minute|second|string|ta\.atr|ta\.bbw|ta\.cci|ta\.cmo|ta\.cog|ta\.cum|ta\.dev|ta\.dmi|ta\.ema|ta\.hma|ta\.kcw|ta\.max|ta\.mfi|ta\.min|ta\.mom|ta\.rci|ta\.rma|ta\.roc|ta\.rsi|ta\.sar|ta\.sma|ta\.tsi|ta\.wma|ta\.wpr|alert|color|float|hline|input|label|month|ta\.bb|ta\.kc|ta\.tr|table|bool|fill|hour|line|plot|time|year|box|int|na|nz/,keywords:/continue|for\.\.\.in|export|import|method|switch|break|varip|while|else|enum|type|and|for|not|var|as|by|if|in|or|to/,tokenizer:{root:[[/\/\/\s*(?=@)/,`comment`,`@comments`],[/\/\/.*(?!@).*/,`comment`],[/\'([^\'\\]|\\.)*$/,`string.invalid`],[/'([^'\\]|\\.)*$/,`string.invalid`],[/\"/,{token:`string`,bracket:`@open`,next:`@stringDouble`}],[/(type|enum)\s+[a-zA-Z]\w*/,`entity.name.type`],[/'/,{token:`string`,bracket:`@open`,next:`@stringSingle`}],[/(@builtinFunctions)(?=\s*\(|\s*<.*>)/,{token:`support.function`,next:`@template`}],[/@punctuation/,{token:`punctuation.operator`,next:`@property`}],[/(varip|var)\b(\s+)((?!(?:chart\.point|linefill|polyline|matrix|series|simple|string|array|color|const|float|label|table|bool|line|box|int|map|continue|for\.\.\.in|export|import|method|switch|break|varip|while|else|type|enum|and|for|not|var|as|by|if|in|or|to)\b)[\w.\d_$]+)(\[\]|)(\s+)((?!(?:continue|for\.\.\.in|export|import|method|switch|break|varip|while|else|type|enum|and|for|not|var|as|by|if|in|or|to)\b)[\w\d_$]+)/,[{token:`keyword`},{token:`source`},{token:`entity.name.type`},{token:`paren`},{token:`source`},{token:`variable.other`}]],[/\b(?:@builtinTypes)(?=(\s*)[\[|<|(]|(?=\s+(?=[^.=][\w\(]*))|\s*$)/,{token:`support.type`,next:`@template`}],[/^(\s*)\b(?!(?:chart\.point|linefill|polyline|matrix|series|simple|string|array|color|const|float|label|table|bool|line|box|int|map|continue|for\.\.\.in|export|import|method|switch|break|varip|while|else|type|enum|and|for|not|var|as|by|if|in|or|to)\b)([\w.\d_$]+)(\[\]|)(\s+)((?!(?:continue|for\.\.\.in|export|import|method|switch|break|varip|while|else|type|enum|and|for|not|var|as|by|if|in|or|to)\b)[\w\d_$]+)(\s+)(\=)/,[{token:`source`},{token:`entity.name.type`},{token:`paren`},{token:`source`},{token:`variable.other`},{token:`source`},{token:`keyword.equals`}]],[/(\((?:\s+))?((?!(?:chart\.point|linefill|polyline|continue|for\.\.\.in|matrix|series|simple|string|export|import|method|switch|array|color|const|float|label|table|break|varip|while|bool|line|else|type|enum|box|int|map|and|for|not|var|as|by|if|in|or|to)\b)\b[\w.\d_$]+(?=[\[\]]*(?:\s+)(?:[\w\d_$]+\s*(?:\,|\))+\s*).+(?:\=\>|\→)))/,`entity.name.type`],[/import(?=\s+@importName)/,{token:`keyword`,next:`@import`}],[/import(?=\s+[a-zA-Z\d\$_\-\.\u00a1-\uffff\/]+)/,`keyword`],[/[+-]?\d+\.\d*([eE][\-+]?\d+)?(?!\w+)/,`constant.numeric.float`],[/[+-]?\.\d+([eE][\-+]?\d+)?(?!\w+)/,`constant.numeric.float`],[/([+-]?(\d+))(?!\w+)(?!\w+)/,`constant.numeric.integer`],[/(?:true|false)\b/,`constant.other.boolean`],[/#[0-9a-fA-F]{6,8}\b/,`constant.other.color`],[/\+=|\-=|\*=|\/=|%=|[\/%*+\-]|==|!=|<=|>=|=>|<|>|\?|\:=|\:|\,/,`keyword.operator`],[/\b(?:continue|for\.\.\.in|export|import|method|switch|break|varip|while|else|type|enum|and|for|not|var|as|by|if|in|or|to)\b/,`keyword`],[/^[a-zA-Z_][a-zA-Z_0-9]+(?=\s*\()/,`entity.name.function`],[/[0-9]+\b/,`constant.numeric.integer`],[/=/,`keyword.equals`],[/\b(?:@builtinVariables)\b(?!\s*=\s*\w+)/,`support.variable`],[/[(|)|\[|\]]/,`paren`],[/[a-zA-Z_][a-zA-Z_0-9]*(?=\s*\()/,{token:`entity.name.method`}],[/\w+\b/,`variable.other`]],comments:[[/@[A-Za-z]+(\s*=\s*)?$/,{token:`comment.annotation`,next:`@pop`}],[/@[A-Za-z]+(\s*=\s*)?/,{token:`comment.annotation`}],[/(?!\s*@[A-Za-z]+).+$/,{token:`comment`,next:`@pop`}]],stringDouble:[[/[^\\\"]+/,`string`],[/\\./,`string.invalid`],[/\"/,{token:`string.quote`,bracket:`@close`,next:`@pop`}]],stringSingle:[[/[^\\']+/,`string`],[/\\./,`string.invalid`],[/'/,{token:`string`,bracket:`@close`,next:`@pop`}]],template:[[/(@builtinTypes)/,{token:`support.type`}],[/(\((?:\s+))?((?!(?:chart\.point|linefill|polyline|continue|for\.\.\.in|matrix|series|simple|string|export|import|method|switch|array|color|const|float|label|table|break|varip|while|bool|line|else|type|enum|box|int|map|and|for|not|var|as|by|if|in|or|to)\b)\b[\w.\d_$]+(?=[\[\]]*(?:\s+)(?:[\w\d_$]+\s*(?:\,|\))+\s*).+(?:\=\>|\→)))/,`entity.name.type`],[/\(|\)|\[|\]|\=|\>/,{token:`paren`,next:`@pop`}],[/(\,)(\s+)/,[`keyword.operator`,`source`]],[/(\,)/,{token:`keyword.operator`}],[/([\w.\d$]+)/,{token:`entity.name.type`}],[/(<|>)/,{token:`paren`}],[/\s(?=\w)|$/,{token:`source`,next:`@pop`}]],property:[[/@punctuation/,{token:`punctuation.operator`}],[/(@builtinTypes)(?=\s*[(])/,{token:`support.method`,next:`@pop`}],[/[a-zA-Z_][a-zA-Z_0-9]+(?=\s*\()/,{token:`entity.name.method`,next:`@pop`}],[/[a-zA-Z0-9_]+/,{token:`variable.other.property`,next:`@pop`}],[/@empty/,{token:`source`,next:`@pop`}]],import:[[/\s+/,{token:`source`}],[/(@importName)(\s+)(as\b)(\s+)(@importAlias)/,[{token:`entity.name.module`},{token:`source`},{token:`keyword`},{token:`source`},{token:`entity.name.module.name`,next:`@pop`}]],[/@importName/,{token:`entity.name.module`,next:`@pop`}]]},builtinVariables:/strategy\.commission\.cash_per_contract|syminfo\.recommendations_sell_strong|strategy\.commission\.cash_per_order|strategy\.avg_winning_trade_percent|syminfo\.recommendations_buy_strong|strategy\.avg_losing_trade_percent|strategy\.closedtrades\.first_index|strategy\.margin_liquidation_price|strategy\.max_contracts_held_short|strategy\.max_contracts_held_long|strategy\.opentrades\.capital_held|syminfo\.shares_outstanding_float|syminfo\.shares_outstanding_total|barstate\.islastconfirmedhistory|earnings\.future_period_end_time|strategy\.max_contracts_held_all|syminfo\.target_price_estimates|alert\.freq_once_per_bar_close|label\.style_label_lower_right|label\.style_label_upper_right|strategy\.max_drawdown_percent|syminfo\.recommendations_total|label\.style_label_lower_left|label\.style_label_upper_left|chart\.right_visible_bar_time|strategy\.grossprofit_percent|strategy\.position_entry_name|strategy\.position_size_short|strategy\.position_size_total|strategy\.price_highest_short|syminfo\.recommendations_date|syminfo\.recommendations_hold|syminfo\.recommendations_sell|syminfo\.target_price_average|plot\.style_stepline_diamond|strategy\.commission\.percent|chart\.left_visible_bar_time|strategy\.openprofit_percent|strategy\.position_avg_price|strategy\.position_size_long|strategy\.price_highest_long|strategy\.price_lowest_short|syminfo\.recommendations_buy|syminfo\.target_price_median|strategy\.percent_of_equity|session\.isfirstbar_regular|strategy\.avg_trade_percent|strategy\.avg_winning_trade|strategy\.grossloss_percent|strategy\.max_runup_percent|strategy\.netprofit_percent|strategy\.price_first_short|strategy\.price_lowest_long|dividends\.future_pay_date|session\.islastbar_regular|strategy\.account_currency|strategy\.avg_losing_trade|strategy\.openprofit_short|strategy\.opentrades_short|strategy\.price_first_long|strategy\.price_last_short|syminfo\.target_price_date|syminfo\.target_price_high|label\.style_label_center|label\.style_text_outline|label\.style_triangledown|strategy\.direction\.short|dividends\.future_ex_date|strategy\.avg_price_short|strategy\.initial_capital|strategy\.openprofit_long|strategy\.opentrades_long|strategy\.price_last_long|syminfo\.current_contract|syminfo\.target_price_low|alert\.freq_once_per_bar|label\.style_label_right|strategy\.direction\.long|dividends\.future_amount|earnings\.future_revenue|strategy\.avg_price_long|syminfo\.expiration_date|barmerge\.lookahead_off|label\.style_label_down|label\.style_label_left|label\.style_triangleup|line\.style_arrow_right|position\.bottom_center|position\.middle_center|strategy\.direction\.all|strategy\.position_size|barmerge\.lookahead_on|earnings\.standardized|font\.family_monospace|label\.style_arrowdown|line\.style_arrow_both|line\.style_arrow_left|plot\.style_steplinebr|position\.bottom_right|position\.middle_right|strategy\.closedtrades|strategy\.max_drawdown|syminfo\.main_tickerid|timeframe\.main_period|label\.style_label_up|plot\.style_histogram|position\.bottom_left|position\.middle_left|barstate\.isconfirmed|earnings\.future_time|session\.ispostmarket|strategy\.grossprofit|syminfo\.basecurrency|syminfo\.shareholders|timeframe\.isintraday|timeframe\.multiplier|dayofweek\.wednesday|display\.data_window|display\.price_scale|display\.status_line|font\.family_default|label\.style_arrowup|label\.style_diamond|plot\.style_stepline|position\.top_center|strategy\.oca\.cancel|strategy\.oca\.reduce|barstate\.isrealtime|chart\.is_heikinashi|earnings\.future_eps|session\.ispremarket|strategy\.eventrades|strategy\.losstrades|strategy\.openprofit|strategy\.opentrades|syminfo\.description|syminfo\.mincontract|timeframe\.isminutes|timeframe\.ismonthly|timeframe\.isseconds|dayofweek\.saturday|dayofweek\.thursday|hline\.style_dashed|hline\.style_dotted|label\.style_circle|label\.style_square|label\.style_xcross|plot\.style_circles|plot\.style_columns|position\.top_right|shape\.triangledown|splits\.denominator|text\.format_italic|barstate\.ishistory|chart\.is_linebreak|session\.isfirstbar|strategy\.avg_trade|strategy\.grossloss|strategy\.max_runup|strategy\.netprofit|strategy\.wintrades|syminfo\.pointvalue|syminfo\.pricescale|syminfo\.volumetype|timeframe\.isweekly|barmerge\.gaps_off|dayofweek\.tuesday|earnings\.estimate|hline\.style_solid|label\.style_cross|line\.style_dashed|line\.style_dotted|location\.abovebar|location\.absolute|location\.belowbar|plot\.style_areabr|plot\.style_linebr|position\.top_left|strategy\.oca\.none|text\.align_bottom|text\.align_center|chart\.is_standard|session\.islastbar|syminfo\.employees|timeframe\.isdaily|barmerge\.gaps_on|dayofweek\.friday|dayofweek\.monday|dayofweek\.sunday|label\.style_flag|label\.style_none|line\.style_solid|order\.descending|plot\.style_cross|session\.extended|shape\.triangleup|splits\.numerator|text\.align_right|text\.format_bold|text\.format_none|barstate\.isfirst|session\.ismarket|syminfo\.currency|syminfo\.industry|syminfo\.tickerid|syminfo\.timezone|timeframe\.period|dividends\.gross|earnings\.actual|location\.bottom|order\.ascending|plot\.style_area|plot\.style_line|session\.regular|shape\.arrowdown|shape\.labeldown|text\.align_left|barstate\.islast|strategy\.equity|syminfo\.country|syminfo\.minmove|syminfo\.mintick|syminfo\.session|time_tradingday|timeframe\.isdwm|alert\.freq_all|format\.inherit|format\.mintick|format\.percent|strategy\.fixed|strategy\.short|text\.align_top|text\.wrap_auto|text\.wrap_none|xloc\.bar_index|barstate\.isnew|chart\.bg_color|chart\.fg_color|chart\.is_range|chart\.is_renko|last_bar_index|syminfo\.prefix|syminfo\.sector|syminfo\.ticker|color\.fuchsia|currency\.NONE|currency\.USDT|dividends\.net|format\.volume|shape\.arrowup|shape\.diamond|shape\.labelup|strategy\.cash|strategy\.long|xloc\.bar_time|yloc\.abovebar|yloc\.belowbar|chart\.is_kagi|last_bar_time|color\.maroon|color\.orange|color\.purple|color\.silver|color\.yellow|currency\.AUD|currency\.BTC|currency\.CAD|currency\.CHF|currency\.EGP|currency\.ETH|currency\.EUR|currency\.GBP|currency\.HKD|currency\.INR|currency\.JPY|currency\.KRW|currency\.MYR|currency\.NOK|currency\.NZD|currency\.PKR|currency\.PLN|currency\.RUB|currency\.SEK|currency\.SGD|currency\.TRY|currency\.USD|currency\.ZAR|display\.none|display\.pane|extend\.right|format\.price|location\.top|shape\.circle|shape\.square|shape\.xcross|chart\.is_pnf|linefill\.all|polyline\.all|syminfo\.root|syminfo\.type|color\.black|color\.green|color\.olive|color\.white|display\.all|extend\.both|extend\.left|extend\.none|scale\.right|shape\.cross|size\.normal|color\.aqua|color\.blue|color\.gray|color\.lime|color\.navy|color\.teal|scale\.left|scale\.none|shape\.flag|size\.large|size\.small|yloc\.price|dayofmonth|ta\.accdist|time_close|weekofyear|color\.red|math\.rphi|size\.auto|size\.huge|size\.tiny|bar_index|dayofweek|label\.all|table\.all|math\.phi|line\.all|math\.pi|box\.all|ta\.vwap|ta\.wvad|timenow|math\.e|minute|second|ta\.iii|ta\.nvi|ta\.obv|ta\.pvi|ta\.pvt|ta\.wad|volume|false|close|hlcc4|month|ohlc4|ta\.tr|true|high|hlc3|hour|open|time|year|ask|bid|hl2|low|na/,builtinTypes:/chart\.point|linefill|polyline|matrix|series|simple|string|array|color|const|float|label|table|bool|line|box|int|map/,punctuation:/[.](?![.])/,importName:/[a-zA-Z\d\$_\-\.\u00a1-\uffff\/]+/,importAlias:/[a-zA-Z\d\_\u00a1\uffff\/]+/,empty:/^$/},oN={None:0,Indent:1,IndentOutdent:2,Outdent:3},sN={wordPattern:/(-?\d*\.\d\w*)|([^\`\~\!\@\#\%\^\&\*\(\)\-\=\+\[\{\]\}\\\|\;\:\'\"\,\.\<\>\/\?\s]+)/g,comments:{lineComment:`//`,blockComment:[`/*`,`*/`]},brackets:[[`(`,`)`],[`[`,`]`]],folding:{markers:{start:/(\/\/#region)|(\/\/.*{($|\s))/,end:/(\/\/#endregion)|(\/\/.*}($|\s))/}},autoClosingPairs:[{open:`{`,close:`}`},{open:`[`,close:`]`},{open:`(`,close:`)`},{open:`"`,close:`"`},{open:`'`,close:`'`}],surroundingPairs:[{open:`{`,close:`}`},{open:`[`,close:`]`},{open:`(`,close:`)`},{open:`"`,close:`"`},{open:`'`,close:`'`},{open:`<`,close:`>`}],onEnterRules:[{beforeText:/\)\s*=>\s*$/,action:{indentAction:oN.Indent}},{beforeText:/if\s+.*\s*$/,action:{indentAction:oN.Indent}},{beforeText:/else/,action:{indentAction:oN.Indent}},{beforeText:/for\s+\S+\s*=\s*\S+\s+to\s+\S+(?:\s+by\s+\S+)?\s*$/,action:{indentAction:oN.Indent}},{beforeText:/for\s+(?:\[\S+\s+\S+]|\S+)\s+in\s+\S+\s*$/,action:{indentAction:oN.Indent}},{beforeText:/switch\s+.*\s*$/,action:{indentAction:oN.Indent}},{beforeText:/while\s+.*\s*$/,action:{indentAction:oN.Indent}},{beforeText:/type\s+\w+/,action:{indentAction:oN.Indent}},{beforeText:/enum\s+\w+/,action:{indentAction:oN.Indent}},{beforeText:/^\s*$/,action:{indentAction:oN.Outdent}}]},Z={"color-white":`#ffffff`,"color-black":`#000000`,"color-transparent":`#00000000`,"color-cold-gray-50":`#F8F9FD`,"color-cold-gray-100":`#F0F3FA`,"color-cold-gray-150":`#E0E3EB`,"color-cold-gray-200":`#D1D4DC`,"color-cold-gray-250":`#C1C4CD`,"color-cold-gray-300":`#B2B5BE`,"color-cold-gray-350":`#A3A6AF`,"color-cold-gray-400":`#9598A1`,"color-cold-gray-450":`#868993`,"color-cold-gray-500":`#787B86`,"color-cold-gray-550":`#6A6D78`,"color-cold-gray-600":`#5D606B`,"color-cold-gray-650":`#50535E`,"color-cold-gray-700":`#434651`,"color-cold-gray-750":`#363A45`,"color-cold-gray-800":`#2A2E39`,"color-cold-gray-850":`#1E222D`,"color-cold-gray-900":`#131722`,"color-cold-gray-950":`#0C0E15`,"color-ripe-red-50":`#FFEBEC`,"color-ripe-red-100":`#FCCBCD`,"color-ripe-red-200":`#FAA1A4`,"color-ripe-red-300":`#F77C80`,"color-ripe-red-400":`#F7525F`,"color-ripe-red-500":`#F23645`,"color-ripe-red-600":`#CC2F3C`,"color-ripe-red-700":`#B22833`,"color-ripe-red-800":`#991F29`,"color-ripe-red-900":`#801922`,"color-ripe-red-a100":`#FF8080`,"color-ripe-red-a200":`#FF5252`,"color-ripe-red-a400":`#FF3333`,"color-ripe-red-a600":`#CC2929`,"color-ripe-red-a700":`#802028`,"color-ripe-red-a800":`#4D191D`,"color-ripe-red-a900":`#331F20`,"color-tan-orange-50":`#FFF3E0`,"color-tan-orange-100":`#FFE0B2`,"color-tan-orange-200":`#FFCC80`,"color-tan-orange-300":`#ffb74d`,"color-tan-orange-400":`#FFA726`,"color-tan-orange-500":`#FF9800`,"color-tan-orange-600":`#FB8C00`,"color-tan-orange-700":`#F57C00`,"color-tan-orange-800":`#EF6C00`,"color-tan-orange-900":`#e65100`,"color-tan-orange-a200":`#ffab40`,"color-tan-orange-a400":`#FF9100`,"color-tan-orange-a600":`#CC7014`,"color-tan-orange-a700":`#8C541C`,"color-tan-orange-a800":`#593A1B`,"color-tan-orange-a900":`#33261A`,"color-iguana-green-100":`#C8E6C9`,"color-iguana-green-200":`#A5D6A7`,"color-iguana-green-300":`#81c784`,"color-iguana-green-400":`#66BB6A`,"color-iguana-green-500":`#4caf50`,"color-iguana-green-600":`#43a047`,"color-iguana-green-700":`#388e3c`,"color-iguana-green-800":`#2E7D32`,"color-iguana-green-900":`#1B5E20`,"color-iguana-green-a700":`#00c853`,"color-banana-yellow-100":`#FFF9C4`,"color-banana-yellow-200":`#FFF59D`,"color-banana-yellow-300":`#FFF176`,"color-banana-yellow-400":`#ffee58`,"color-banana-yellow-500":`#ffeb3b`,"color-banana-yellow-600":`#fdd835`,"color-banana-yellow-700":`#fbc02d`,"color-banana-yellow-800":`#f9a825`,"color-banana-yellow-900":`#F57F17`,"color-banana-yellow-a400":`#ffea00`,"color-banana-yellow-a700":`#EEDA01`,"color-tv-blue-50":`#E3EFFD`,"color-tv-blue-100":`#BBD9FB`,"color-tv-blue-200":`#90BFF9`,"color-tv-blue-300":`#5B9CF6`,"color-tv-blue-400":`#3179F5`,"color-tv-blue-500":`#2962FF`,"color-tv-blue-600":`#1E53E5`,"color-tv-blue-700":`#1848CC`,"color-tv-blue-800":`#143EB3`,"color-tv-blue-900":`#0C3299`,"color-tv-blue-a100":`#82b1ff`,"color-tv-blue-a200":`#448aff`,"color-tv-blue-a400":`#2979ff`,"color-tv-blue-a600":`#2962FF`,"color-tv-blue-a700":`#143A87`,"color-tv-blue-a800":`#142E61`,"color-tv-blue-a900":`#132042`,"color-deep-blue-50":`#EDE7F6`,"color-deep-blue-100":`#D1C4E9`,"color-deep-blue-200":`#B39DDB`,"color-deep-blue-300":`#9575cd`,"color-deep-blue-400":`#7e57c2`,"color-deep-blue-500":`#673ab7`,"color-deep-blue-700":`#512da8`,"color-deep-blue-800":`#4527A0`,"color-deep-blue-900":`#311B92`,"color-deep-blue-a100":`#b388ff`,"color-deep-blue-a200":`#7C4DFF`,"color-deep-blue-a400":`#651FFF`,"color-deep-blue-a700":`#6200EA`,"color-minty-green-50":`#DAF2EE`,"color-minty-green-100":`#ACE5DC`,"color-minty-green-200":`#70CCBD`,"color-minty-green-300":`#42BDA8`,"color-minty-green-400":`#22AB94`,"color-minty-green-500":`#089981`,"color-minty-green-600":`#06806B`,"color-minty-green-700":`#056656`,"color-minty-green-800":`#004D40`,"color-minty-green-900":`#00332A`,"color-minty-green-a400":`#2BD9BC`,"color-minty-green-a600":`#24B29B`,"color-minty-green-a700":`#1B7667`,"color-minty-green-a800":`#10443B`,"color-minty-green-a900":`#082621`,"color-grapes-purple-50":`#F3E5F5`,"color-grapes-purple-100":`#E1BEE7`,"color-grapes-purple-200":`#CE93D8`,"color-grapes-purple-300":`#ba68c8`,"color-grapes-purple-400":`#ab47bc`,"color-grapes-purple-500":`#9c27b0`,"color-grapes-purple-600":`#8e24aa`,"color-grapes-purple-700":`#7b1fa2`,"color-grapes-purple-800":`#6A1B9A`,"color-grapes-purple-900":`#4A148C`,"color-grapes-purple-a100":`#EA80FC`,"color-grapes-purple-a200":`#E040FB`,"color-grapes-purple-a400":`#D500F9`,"color-grapes-purple-a700":`#aa00ff`,"color-berry-pink-100":`#F8BBD0`,"color-berry-pink-200":`#f48fb1`,"color-berry-pink-300":`#f06292`,"color-berry-pink-400":`#ec407a`,"color-berry-pink-500":`#e91e63`,"color-berry-pink-600":`#D81B60`,"color-berry-pink-700":`#C2185B`,"color-berry-pink-800":`#AD1457`,"color-berry-pink-900":`#880E4F`,"color-berry-pink-a100":`#ff80ab`,"color-berry-pink-a200":`#ff4081`,"color-berry-pink-a400":`#f50057`,"color-sky-blue-100":`#B2EBF2`,"color-sky-blue-200":`#80DEEA`,"color-sky-blue-300":`#4dd0e1`,"color-sky-blue-400":`#26c6da`,"color-sky-blue-500":`#00bcd4`,"color-sky-blue-600":`#00acc1`,"color-sky-blue-700":`#0097A7`,"color-sky-blue-800":`#00838F`,"color-sky-blue-900":`#006064`,"color-sky-blue-a400":`#00e5ff`,"color-sky-blue-a700":`#00B8D4`,"color-deep-blue-600":`#5E35B1`,"color-forest-green-50":`#DAF2E6`,"color-forest-green-100":`#ACE5C9`,"color-forest-green-200":`#70CC9E`,"color-forest-green-300":`#42BD7F`,"color-forest-green-400":`#22AB67`,"color-forest-green-500":`#089950`,"color-forest-green-600":`#068043`,"color-forest-green-700":`#056636`,"color-forest-green-800":`#004D27`,"color-forest-green-900":`#1A3326`,"color-facebook":`#1877F2`,"color-deep-facebook":`#1564CA`,"color-twitter":`#1DA1F2`,"color-deep-twitter":`#188CD3`,"color-youtube":`#FF0000`,"color-linkedin":`#007BB5`,"color-seeking-alpha-brand":`#ff7200`};function cN(e,t=1){return e+Math.round(255*Math.min(Math.max(t,0),1)).toString(16).toUpperCase().padStart(2,`0`)}Z[`color-cold-gray-400`],Z[`color-cold-gray-900`],Z[`color-iguana-green-700`],Z[`color-banana-yellow-900`],Z[`color-ripe-red-a600`],Z[`color-ripe-red-a600`],Z[`color-ripe-red-a600`],Z[`color-ripe-red-a600`],Z[`color-tv-blue-a600`],Z[`color-minty-green-400`],Z[`color-minty-green-400`],Z[`color-tv-blue-a600`],Z[`color-minty-green-400`],Z[`color-minty-green-400`],Z[`color-minty-green-400`],Z[`color-minty-green-400`],Z[`color-cold-gray-800`],Z[`color-cold-gray-800`],Z[`color-black`],Z[`color-tv-blue-900`],Z[`color-tv-blue-900`],Z[`color-grapes-purple-600`],Z[`color-grapes-purple-600`],Z[`color-tv-blue-a600`],Z[`color-white`],Z[`color-cold-gray-900`],Z[`color-cold-gray-400`],Z[`color-cold-gray-700`],Z[`color-white`],Z[`color-cold-gray-150`],Z[`color-cold-gray-900`],Z[`color-white`],Z[`color-cold-gray-900`],cN(Z[`color-cold-gray-200`],.5),Z[`color-tv-blue-50`],Z[`color-tv-blue-50`],Z[`color-tv-blue-100`],Z[`color-cold-gray-150`],Z[`color-tv-blue-100`],Z[`color-tv-blue-50`],Z[`color-tan-orange-100`],Z[`color-tan-orange-100`],Z[`color-tan-orange-500`],Z[`color-cold-gray-900`],Z[`color-cold-gray-900`],Z[`color-tv-blue-500`],Z[`color-tv-blue-50`],Z[`color-tv-blue-100`],Z[`color-tv-blue-500`],Z[`color-white`],Z[`color-cold-gray-900`],Z[`color-cold-gray-150`],Z[`color-cold-gray-900`],Z[`color-tv-blue-500`],Z[`color-tv-blue-600`],Z[`color-tan-orange-100`],Z[`color-cold-gray-900`],Z[`color-banana-yellow-800`],Z[`color-banana-yellow-800`],cN(Z[`color-forest-green-500`],.3),cN(Z[`color-forest-green-500`],.15),cN(Z[`color-ripe-red-500`],.3),cN(Z[`color-ripe-red-500`],.15),Z[`color-cold-gray-150`],Z[`color-cold-gray-550`],Z[`color-ripe-red-500`],Z[`color-tan-orange-500`],Z[`color-cold-gray-500`],Z[`color-white`],Z[`color-iguana-green-700`],Z[`color-banana-yellow-900`],Z[`color-ripe-red-300`],Z[`color-ripe-red-300`],Z[`color-ripe-red-300`],Z[`color-ripe-red-300`],Z[`color-tv-blue-300`],Z[`color-tv-blue-300`],Z[`color-minty-green-300`],Z[`color-minty-green-300`],Z[`color-minty-green-300`],Z[`color-minty-green-300`],Z[`color-minty-green-300`],Z[`color-minty-green-300`],Z[`color-cold-gray-200`],Z[`color-cold-gray-200`],Z[`color-white`],Z[`color-tv-blue-400`],Z[`color-tv-blue-400`],Z[`color-grapes-purple-300`],Z[`color-grapes-purple-300`],Z[`color-tv-blue-300`],Z[`color-cold-gray-900`],Z[`color-white`],Z[`color-cold-gray-900`],Z[`color-cold-gray-500`],Z[`color-cold-gray-300`],Z[`color-cold-gray-850`],Z[`color-cold-gray-850`],Z[`color-cold-gray-300`],Z[`color-cold-gray-900`],Z[`color-cold-gray-300`],Z[`color-cold-gray-900`],cN(Z[`color-cold-gray-700`],.5),Z[`color-tv-blue-a900`],Z[`color-tv-blue-a900`],Z[`color-tv-blue-a800`],Z[`color-cold-gray-750`],Z[`color-tv-blue-a800`],Z[`color-cold-gray-800`],Z[`color-cold-gray-350`],Z[`color-cold-gray-350`],Z[`color-tv-blue-500`],Z[`color-tv-blue-900`],Z[`color-tv-blue-300`],Z[`color-tv-blue-500`],Z[`color-cold-gray-800`],Z[`color-cold-gray-300`],Z[`color-cold-gray-700`],Z[`color-cold-gray-350`],Z[`color-tv-blue-500`],Z[`color-tv-blue-600`],Z[`color-tan-orange-a800`],Z[`color-cold-gray-350`],cN(Z[`color-iguana-green-a700`],.3),cN(Z[`color-iguana-green-a700`],.15),cN(Z[`color-ripe-red-a400`],.3),cN(Z[`color-ripe-red-a400`],.15),Z[`color-cold-gray-800`],Z[`color-cold-gray-400`],Z[`color-ripe-red-500`],Z[`color-tan-orange-700`];function lN(){m.languages.register({id:tN}),m.editor.defineTheme(`vs-dark`,iN),m.editor.defineTheme(`vs`,rN),m.languages.setMonarchTokensProvider(tN,aN),m.languages.setLanguageConfiguration(tN,sN)}async function uN(e,t){return t&&m.editor.setTheme(t.includes(`dark`)?`vs-dark`:`light`),await m.editor.colorize(e,tN,{tabSize:4})}function dN(e=`light`){m.editor.setTheme(e.includes(`dark`)?`vs-dark`:`light`)}var fN=20;function pN(e,t,n){let r=K(),i=q(e=>e.threadListItem),[a,o]=(0,f.useState)([]),s=(0,f.useCallback)(e=>{o([...e])},[]),[c,l]=(0,f.useState)(!1),[u,d]=(0,f.useState)(!0),[p,m]=(0,f.useState)(!1),[h,g]=(0,f.useState)(0),_=ZM(i)??``,v=(0,f.useRef)(null),y=(0,f.useRef)(!1);(0,f.useEffect)(()=>{let e=!1;async function t(){if(o([]),g(0),m(!1),d(!0),!_)d(!1);else try{let t=await $M(_,0,fN);if(e)return;o([...t.messages].reverse().map(XM)),g(0),m(t.pagination.hasMore)}catch(t){e||console.error(`加载会话历史失败:`,t)}finally{e||d(!1)}}return t(),()=>{e=!0}},[i.id]);let b=(0,f.useCallback)(async(i,a=!1)=>{let s=crypto.randomUUID(),c=crypto.randomUUID(),u=new AbortController;v.current=u;let d=i.content.flatMap(e=>e.type===`text`?[{type:`text`,text:e.text}]:[]),f={id:s,role:`user`,content:d,attachments:i.attachments??[],createdAt:new Date,metadata:{custom:{}}},p={id:c,role:`assistant`,content:[],createdAt:new Date,status:{type:`running`},metadata:{unstable_state:{},unstable_annotations:[],unstable_data:[],steps:[],custom:{}}};o(e=>{let t=e;if(a){let n=e.findIndex(e=>e.id===i.parentId);t=n===-1?[]:e.slice(0,n+1)}return[...t,f,p]}),l(!0);try{for await(let i of LM({token:e.current||``,userMessage:{id:s,content:d},abortSignal:u.signal,getConversationId:()=>ZM(r.threadListItem.getState())??``,onConversationCreated:e=>{let t=r.threadListItem.getState();GM(t.id,e),r.threadListItem.updateCustom({...t.custom,conversationId:e}),n.current?.(e),g(0),m(!1)},onCustomEvent:e=>{t.current?.(e)}}))o(e=>e.map(e=>e.id!==c||e.role!==`assistant`?e:{...e,content:i}));if(u.signal.aborted){o(e=>e.filter(e=>e.id!==c));return}o(e=>e.map(e=>e.id!==c||e.role!==`assistant`?e:{...e,status:{type:`complete`,reason:`stop`}}))}catch(e){if(o(e=>e.filter(e=>e.id!==c)),!u.signal.aborted)throw e}finally{v.current===u&&(v.current=null),l(!1)}},[r]);return op({messages:a,setMessages:s,isRunning:c,isLoading:u,onNew:(0,f.useCallback)(e=>b(e),[b]),onEdit:(0,f.useCallback)(e=>b(e,!0),[b]),onCancel:(0,f.useCallback)(async()=>{v.current?.abort()},[]),hasEarlier:p,onLoadEarlier:(0,f.useCallback)(async()=>{if(_&&p&&!y.current){y.current=!0;try{let e=h+1,t=await $M(_,e,fN),n=[...t.messages].reverse().map(XM);o(e=>{let t=new Set(e.map(e=>e.id));return[...n.filter(e=>!t.has(e.id)),...e]}),g(e),m(t.pagination.hasMore)}finally{y.current=!1}}},[_,h,p])})}lN();function mN({children:e,token:t,onCustomEvent:n}){let[r,i]=(0,f.useState)(),a=(0,f.useRef)(!1),o=(0,f.useRef)(t),s=(0,f.useRef)(n);(0,f.useEffect)(()=>{s.current=n},[n]),qM(t),(0,f.useEffect)(()=>{o.current=t},[t]);let c=(0,f.useRef)(()=>{}),l=(0,f.useCallback)(e=>{a.current&&(i(e),!e||QM(e)?WM():UM(e))},[]),u=(0,f.useCallback)(function(){return pN(o,s,c)},[]);(0,f.useEffect)(()=>{let e=!1;async function t(){let t=HM();if(t)try{let n=await eN.fetch(t);if(e)return;i(n.remoteId)}catch{if(e)return;WM(),i(void 0)}finally{e||(a.current=!0)}else{if(e)return;i(void 0),a.current=!0}}return t(),c.current=e=>{UM(e)},()=>{e=!0}},[]);let d=oh({runtimeHook:u,adapter:eN,threadId:r,onThreadIdChange:l});return(0,J.jsx)(Tv,{runtime:d,children:e})}var hN=e=>e?.replace(/([a-z0-9])([A-Z])/g,`$1-$2`).toLowerCase();function gN(e,t,n=[]){if(t==null)throw Error(`[lucide]: iconNode is required when icon name is used`);return{name:hN(e),size:24,node:t,...n.length>0?{aliases:n}:{}}}var _N=e=>{let t=``,n=!1;for(let r of e)r===`-`||r===`_`||r<=` `?n=t.length>0:(t.length===0?t+=r.toLowerCase():t+=n?r.toUpperCase():r,n=!1);return t},vN=e=>{let t=_N(e);return t.charAt(0).toUpperCase()+t.slice(1)},yN=(...e)=>e.filter((e,t,n)=>!!e&&e.trim()!==``&&n.indexOf(e)===t).join(` `).trim(),bN={xmlns:`http://www.w3.org/2000/svg`,width:24,height:24,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,"stroke-width":2,"stroke-linecap":`round`,"stroke-linejoin":`round`};function xN(e){return e!=null}function SN(e,t={}){let n=t.attributeNames??{},r=e=>n[e]??e,i=e.size??e.width??bN.width,a=e.size??e.height??bN.height,o=e.aliases?.filter(e=>typeof e==`string`&&e.trim()!==``).map(e=>`lucide-${e}`)??[],s=[...e.name?[`lucide-${e.name}`]:[],...o],c=t.className?.split(` `).filter(Boolean)??[],l=t.includeDefaultClasses===!1?yN(...c):yN(`lucide`,...s,...c),u=t.absoluteStrokeWidth?Number(t.strokeWidth??bN[`stroke-width`])*Number(e.size??e.width??bN.width)/Number(t.size??t.width??bN.width):t.strokeWidth??bN[`stroke-width`];return[`svg`,{...Object.entries(bN).reduce((e,[t,n])=>(e[r(t)]=n,e),{}),...`color`in t&&t.color&&{[r(`stroke`)]:t.color},...`size`in t&&xN(t.size)&&{[r(`width`)]:t.size,[r(`height`)]:t.size},...`width`in t&&xN(t.width)&&{[r(`width`)]:t.width},...`height`in t&&xN(t.height)&&{[r(`height`)]:t.height},[r(`stroke-width`)]:u,...l&&{[r(`class`)]:l},[r(`viewBox`)]:`0 0 ${i} ${a}`,...t.hasA11yProp===!1?{[r(`aria-hidden`)]:`true`}:{},...`attributes`in t&&t.attributes},e.node.map(e=>{let[n,i,a]=e,o=t.nonScalingStroke?{[r(`vector-effect`)]:`non-scaling-stroke`,...i}:i;return a?[n,o,a]:[n,o]})]}function CN(e,t={}){return SN(e,{...t,attributeNames:{...t.attributeNames,class:`className`,"stroke-width":`strokeWidth`,"stroke-linecap":`strokeLinecap`,"stroke-linejoin":`strokeLinejoin`,"vector-effect":`vectorEffect`}})}var wN=e=>{for(let t in e)if(t.startsWith(`aria-`)||t===`role`||t===`title`)return!0;return!1},TN=(0,f.createContext)({}),EN=()=>(0,f.useContext)(TN),DN=(0,f.forwardRef)(({color:e,size:t,width:n,height:r,strokeWidth:i,absoluteStrokeWidth:a,nonScalingStroke:o,className:s=``,children:c,iconNode:l=[],icon:u={node:l,aliases:[],size:24},...d},p)=>{let{size:m=24,strokeWidth:h=2,absoluteStrokeWidth:g=!1,nonScalingStroke:_=!1,color:v=`currentColor`,className:y=``}=EN()??{},b=!!c||wN(d),[x,S,C=[]]=CN(u,{color:e??v,width:n??t??m,height:r??t??m,strokeWidth:i??h,absoluteStrokeWidth:a??g,nonScalingStroke:o??_,className:yN(y,s),hasA11yProp:b,attributes:d});return(0,f.createElement)(x,{ref:p,...S},[...C.map(([e,t])=>(0,f.createElement)(e,t)),...Array.isArray(c)?c:[c]])});function ON(e,t=[],n=[]){let r=typeof e==`string`?gN(e,t,n):e,i=(0,f.forwardRef)(({className:e,...t},n)=>(0,f.createElement)(DN,{ref:n,icon:r,className:e,...t}));return r.name&&(i.displayName=vN(r.name)),i}var kN={name:`arrow-down`,size:24,node:[[`path`,{d:`M12 5v14`,key:`s699le`}],[`path`,{d:`m19 12-7 7-7-7`,key:`1idqje`}]]};kN.node;var AN=ON(kN),jN={name:`arrow-up`,size:24,node:[[`path`,{d:`m5 12 7-7 7 7`,key:`hav0vg`}],[`path`,{d:`M12 19V5`,key:`x0mq9r`}]]};jN.node;var MN=ON(jN),NN={name:`audio-lines`,size:24,node:[[`path`,{d:`M2 10v3`,key:`1fnikh`}],[`path`,{d:`M6 6v11`,key:`11sgs0`}],[`path`,{d:`M10 3v18`,key:`yhl04a`}],[`path`,{d:`M14 8v7`,key:`3a1oy3`}],[`path`,{d:`M18 5v13`,key:`123xd1`}],[`path`,{d:`M22 10v3`,key:`154ddg`}]]};NN.node;var PN=ON(NN),FN={name:`braces`,size:24,node:[[`path`,{d:`M8 3H7a2 2 0 0 0-2 2v5a2 2 0 0 1-2 2 2 2 0 0 1 2 2v5c0 1.1.9 2 2 2h1`,key:`ezmyqa`}],[`path`,{d:`M16 21h1a2 2 0 0 0 2-2v-5c0-1.1.9-2 2-2a2 2 0 0 1-2-2V5a2 2 0 0 0-2-2h-1`,key:`e1hn23`}]],aliases:[`curly-braces`]};FN.node;var IN=ON(FN),LN={name:`brain`,size:24,node:[[`path`,{d:`M12 18V5`,key:`adv99a`}],[`path`,{d:`M15 13a4.17 4.17 0 01-3-4 4.17 4.17 0 01-3 4`,key:`5nuw1p`}],[`path`,{d:`M17.707 6.294A3 3 0 1012 5a3 3 0 10-5.707 1.294`,key:`18ldcf`}],[`path`,{d:`M17.996 5.125a4 4 0 012.526 5.77`,key:`1sdu8q`}],[`path`,{d:`M18 18a4 4 0 002-7.465`,key:`7xqqvr`}],[`path`,{d:`M19.967 17.482a4 4 0 11-7.967.517 4 4 0 11-7.967-.517`,key:`t46ysz`}],[`path`,{d:`M6 18a4 4 0 01-2-7.465`,key:`1y2m15`}],[`path`,{d:`M6.004 5.125a4 4 0 00-2.526 5.77`,key:`3cw1ss`}]]};LN.node;var RN=ON(LN),zN={name:`check`,size:24,node:[[`path`,{d:`M20 6 9 17l-5-5`,key:`1gmf2c`}]]};zN.node;var BN=ON(zN),VN={name:`chevron-down`,size:24,node:[[`path`,{d:`m6 9 6 6 6-6`,key:`qrunsl`}]]};VN.node;var HN=ON(VN),UN={name:`chevron-left`,size:24,node:[[`path`,{d:`m15 18-6-6 6-6`,key:`1wnfg3`}]]};UN.node;var WN=ON(UN),GN={name:`chevron-right`,size:24,node:[[`path`,{d:`m9 18 6-6-6-6`,key:`mthhwq`}]]};GN.node;var KN=ON(GN),qN={name:`circle-exclamation-point`,size:24,node:[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`line`,{x1:`12`,x2:`12`,y1:`8`,y2:`12`,key:`1pkeuh`}],[`line`,{x1:`12`,x2:`12.01`,y1:`16`,y2:`16`,key:`4dfq90`}]],aliases:[`alert-circle`,`circle-alert`]};qN.node;var JN=ON(qN),YN={name:`circle-minus`,size:24,node:[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M8 12h8`,key:`1wcyev`}]],aliases:[`minus-circle`]};YN.node;var XN=ON(YN),ZN={name:`circle-x`,size:24,node:[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`m15 9-6 6`,key:`1uzhvr`}],[`path`,{d:`m9 9 6 6`,key:`z0biqf`}]],aliases:[`x-circle`]};ZN.node;var QN=ON(ZN),$N={name:`copy`,size:24,node:[[`rect`,{width:`14`,height:`14`,x:`8`,y:`8`,rx:`2`,ry:`2`,key:`17jyea`}],[`path`,{d:`M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2`,key:`zix9uf`}]]};$N.node;var eP=ON($N),tP={name:`download`,size:24,node:[[`path`,{d:`M12 15V3`,key:`m9g1x1`}],[`path`,{d:`M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4`,key:`ih7n3h`}],[`path`,{d:`m7 10 5 5 5-5`,key:`brsn70`}]]};tP.node;var nP=ON(tP),rP={name:`eighth-notes`,size:24,node:[[`path`,{d:`M21 16V3a1 1 0 0 0-1.28-.96l-10 2.917a1 1 0 0 0-.72.96V19`,key:`uy6ho8`}],[`circle`,{cx:`18`,cy:`16`,r:`3`,key:`1hluhg`}],[`circle`,{cx:`6`,cy:`19`,r:`3`,key:`1kj8tv`}]],aliases:[`music`]};rP.node;var iP=ON(rP),aP={name:`ellipsis`,size:24,node:[[`circle`,{cx:`12`,cy:`12`,r:`1`,key:`41hilf`}],[`circle`,{cx:`19`,cy:`12`,r:`1`,key:`1wjl8i`}],[`circle`,{cx:`5`,cy:`12`,r:`1`,key:`1pcz8c`}]],aliases:[`more-horizontal`]};aP.node;var oP=ON(aP),sP={name:`file-text`,size:24,node:[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`path`,{d:`M10 9H8`,key:`b1mrlr`}],[`path`,{d:`M16 13H8`,key:`t4e002`}],[`path`,{d:`M16 17H8`,key:`z1uh3a`}]]};sP.node;var cP=ON(sP),lP={name:`file`,size:24,node:[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}]]};lP.node;var uP=ON(lP),dP={name:`image-off`,size:24,node:[[`line`,{x1:`2`,x2:`22`,y1:`2`,y2:`22`,key:`a6p6uj`}],[`path`,{d:`M10.41 10.41a2 2 0 1 1-2.83-2.83`,key:`1bzlo9`}],[`line`,{x1:`13.5`,x2:`6`,y1:`13.5`,y2:`21`,key:`1q0aeu`}],[`line`,{x1:`18`,x2:`21`,y1:`12`,y2:`15`,key:`5mozeu`}],[`path`,{d:`M3.59 3.59A1.99 1.99 0 0 0 3 5v14a2 2 0 0 0 2 2h14c.55 0 1.052-.22 1.41-.59`,key:`mmje98`}],[`path`,{d:`M21 15V5a2 2 0 0 0-2-2H9`,key:`43el77`}]]};dP.node;var fP=ON(dP),pP={name:`image`,size:24,node:[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,ry:`2`,key:`1m3agn`}],[`circle`,{cx:`9`,cy:`9`,r:`2`,key:`af1f0g`}],[`path`,{d:`m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21`,key:`1xmnt7`}]]};pP.node;var mP=ON(pP),hP={name:`loader-circle`,size:24,node:[[`path`,{d:`M21 12a9 9 0 1 1-6.219-8.56`,key:`13zald`}]],aliases:[`loader-2`]};hP.node;var gP=ON(hP),_P={name:`loader`,size:24,node:[[`path`,{d:`M12 2v4`,key:`3427ic`}],[`path`,{d:`m16.2 7.8 2.9-2.9`,key:`r700ao`}],[`path`,{d:`M18 12h4`,key:`wj9ykh`}],[`path`,{d:`m16.2 16.2 2.9 2.9`,key:`1bxg5t`}],[`path`,{d:`M12 18v4`,key:`jadmvz`}],[`path`,{d:`m4.9 19.1 2.9-2.9`,key:`bwix9q`}],[`path`,{d:`M2 12h4`,key:`j09sii`}],[`path`,{d:`m4.9 4.9 2.9 2.9`,key:`giyufr`}]]};_P.node;var vP=ON(_P),yP={name:`message-square`,size:24,node:[[`path`,{d:`M22 17a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 21.286V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2z`,key:`18887p`}]]};yP.node;var bP=ON(yP),xP={name:`messages-square`,size:24,node:[[`path`,{d:`M16 10a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 14.286V4a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2z`,key:`1n2ejm`}],[`path`,{d:`M20 9a2 2 0 0 1 2 2v10.286a.71.71 0 0 1-1.212.502l-2.202-2.202A2 2 0 0 0 17.172 19H10a2 2 0 0 1-2-2v-1`,key:`1qfcsi`}]]};xP.node;var SP=ON(xP),CP={name:`mic`,size:24,node:[[`path`,{d:`M12 19v3`,key:`npa21l`}],[`path`,{d:`M19 10v2a7 7 0 0 1-14 0v-2`,key:`1vc78b`}],[`rect`,{x:`9`,y:`2`,width:`6`,height:`13`,rx:`3`,key:`s6n7sd`}]]};CP.node;var wP=ON(CP),TP={name:`pause`,size:24,node:[[`rect`,{x:`14`,y:`3`,width:`5`,height:`18`,rx:`1`,key:`kaeet6`}],[`rect`,{x:`5`,y:`3`,width:`5`,height:`18`,rx:`1`,key:`1wsw3u`}]]};TP.node;var EP=ON(TP),DP={name:`pencil`,size:24,node:[[`path`,{d:`M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z`,key:`1a8usu`}],[`path`,{d:`m15 5 4 4`,key:`1mk7zo`}]]};DP.node;var OP=ON(DP),kP={name:`phone`,size:24,node:[[`path`,{d:`M13.832 16.568a1 1 0 0 0 1.213-.303l.355-.465A2 2 0 0 1 17 15h3a2 2 0 0 1 2 2v3a2 2 0 0 1-2 2A18 18 0 0 1 2 4a2 2 0 0 1 2-2h3a2 2 0 0 1 2 2v3a2 2 0 0 1-.8 1.6l-.468.351a1 1 0 0 0-.292 1.233 14 14 0 0 0 6.392 6.384`,key:`9njp5v`}]]};kP.node;var AP=ON(kP),jP={name:`play`,size:24,node:[[`path`,{d:`M5 5a2 2 0 0 1 3.008-1.728l11.997 6.998a2 2 0 0 1 .003 3.458l-12 7A2 2 0 0 1 5 19z`,key:`10ikf1`}]]};jP.node;var MP=ON(jP),NP={name:`plus`,size:24,node:[[`path`,{d:`M5 12h14`,key:`1ays0h`}],[`path`,{d:`M12 5v14`,key:`s699le`}]]};NP.node;var PP=ON(NP),FP={name:`refresh-cw`,size:24,node:[[`path`,{d:`M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8`,key:`v9h5vc`}],[`path`,{d:`M21 3v5h-5`,key:`1q7to0`}],[`path`,{d:`M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16`,key:`3uifl3`}],[`path`,{d:`M8 16H3v5`,key:`1cv678`}]]};FP.node;var IP=ON(FP),LP={name:`shield-exclamation-point`,size:24,node:[[`path`,{d:`M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z`,key:`oel41y`}],[`path`,{d:`M12 8v4`,key:`1got3b`}],[`path`,{d:`M12 16h.01`,key:`1drbdi`}]],aliases:[`shield-alert`]};LP.node;var RP=ON(LP),zP={name:`square`,size:24,node:[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}]]};zP.node;var BP=ON(zP),VP={name:`thumbs-up`,size:24,node:[[`path`,{d:`M15 5.88 14 10h5.83a2 2 0 0 1 1.92 2.56l-2.33 8A2 2 0 0 1 17.5 22H4a2 2 0 0 1-2-2v-8a2 2 0 0 1 2-2h2.76a2 2 0 0 0 1.79-1.11L12 2a3.13 3.13 0 0 1 3 3.88Z`,key:`emmmcr`}],[`path`,{d:`M7 10v12`,key:`1qc93n`}]]};VP.node;var HP=ON(VP),UP={name:`thumbs-down`,size:24,node:[[`path`,{d:`M9 18.12 10 14H4.17a2 2 0 0 1-1.92-2.56l2.33-8A2 2 0 0 1 6.5 2H20a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2h-2.76a2 2 0 0 0-1.79 1.11L12 22a3.13 3.13 0 0 1-3-3.88Z`,key:`m61m77`}],[`path`,{d:`M17 14V2`,key:`8ymqnk`}]]};UP.node;var WP=ON(UP),GP={name:`trash`,size:24,node:[[`path`,{d:`M10 11v6`,key:`nco0om`}],[`path`,{d:`M14 11v6`,key:`outv1u`}],[`path`,{d:`M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6`,key:`miytrc`}],[`path`,{d:`M3 6h18`,key:`d0wm0j`}],[`path`,{d:`M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2`,key:`e791ji`}]],aliases:[`trash-2`]};GP.node;var KP=ON(GP),qP={name:`video`,size:24,node:[[`path`,{d:`m16 13 5.223 3.482a.5.5 0 0 0 .777-.416V7.87a.5.5 0 0 0-.752-.432L16 10.5`,key:`ftymec`}],[`rect`,{x:`2`,y:`6`,width:`14`,height:`12`,rx:`2`,key:`158x01`}]]};qP.node;var JP=ON(qP),YP={name:`x`,size:24,node:[[`path`,{d:`M18 6 6 18`,key:`1bl5f8`}],[`path`,{d:`m6 6 12 12`,key:`d8bk6v`}]]};YP.node;var XP=ON(YP),ZP={};function QP(e,t){let n=f.useRef(ZP);return n.current===ZP&&(n.current=e(t)),n}var $P=[],eF=void 0;function tF(){return eF}function nF(e){$P.push(e)}function rF(e){let t=(t,n)=>{let r=QP(aF).current,i;try{eF=r;for(let e of $P)e.before(r);i=e(t,n);for(let e of $P)e.after(r);r.didInitialize=!0}finally{eF=void 0}return i};return t.displayName=e.displayName||e.name,t}function iF(e){return f.forwardRef(rF(e))}function aF(){return{didInitialize:!1}}function oF(){}var sF=Object.freeze([]),cF=Object.freeze({}),lF=typeof document<`u`?f.useLayoutEffect:()=>{};function uF(e,t){return function(n,...r){let i=new URL(e);return i.searchParams.set(`code`,n.toString()),r.forEach(e=>i.searchParams.append(`args[]`,e)),`${t} error #${n}; visit ${i} for the full message.`}}var dF=uF(`https://base-ui.com/production-error`,`Base UI`),fF=f.createContext(void 0);process.env.NODE_ENV!==`production`&&(fF.displayName=`TooltipRootContext`);function pF(e){let t=f.useContext(fF);if(t===void 0&&!e)throw Error(process.env.NODE_ENV===`production`?dF(72):`Base UI: TooltipRootContext is missing. Tooltip parts must be placed within <Tooltip.Root>.`);return t}function mF(e){f.useEffect(e,sF)}var hF=0,gF=class e{static create(){return new e}currentId=hF;start(e,t){this.clear(),this.currentId=setTimeout(()=>{this.currentId=hF,t()},e)}isStarted(){return this.currentId!==hF}clear=()=>{this.currentId!==hF&&(clearTimeout(this.currentId),this.currentId=hF)};disposeEffect=()=>this.clear};function _F(){let e=QP(gF.create).current;return mF(e.disposeEffect),e}function vF(){if(typeof navigator>`u`)return{userAgent:``,platform:``,maxTouchPoints:0};if(process.env.NODE_ENV!==`production`){let e=navigator.userAgentData;if(e&&Array.isArray(e.brands))return{userAgent:e.brands.map(({brand:e,version:t})=>`${e}/${t}`).join(` `),platform:e.platform??navigator.platform??``,maxTouchPoints:navigator.maxTouchPoints??0}}return{userAgent:navigator.userAgent,platform:navigator.platform??``,maxTouchPoints:navigator.maxTouchPoints??0}}var{userAgent:yF,platform:bF,maxTouchPoints:xF}=vF(),SF=yF.toLowerCase(),CF=bF.toLowerCase(),wF=/^i(os$|p)/.test(CF)||CF===`macintel`&&xF>1,TF=`android`,EF=CF===TF||SF.includes(TF),DF=!wF&&CF.startsWith(`mac`);CF.startsWith(`win`),!EF&&/^(linux|chrome os)/.test(CF);var OF=DF||wF,kF=typeof CSS<`u`&&!!CSS.supports?.(`-webkit-backdrop-filter:none`);!kF&&SF.includes(`firefox`),!kF&&SF.includes(`chrom`);var AF=OF,jF=/jsdom|happydom/.test(SF);function MF(e){e.preventDefault(),e.stopPropagation()}function NF(e){return`nativeEvent`in e}function PF(e){return e.pointerType===``&&e.isTrusted?!0:EF&&e.pointerType?e.type===`click`&&e.buttons===1:e.detail===0&&!e.pointerType}function FF(e){return jF?!1:!EF&&e.width===0&&e.height===0||e.type===`pointerdown`&&e.width===1&&e.height===1&&e.pressure===0&&e.detail===0&&e.pointerType===`mouse`&&(EF||e.buttons===0)||e.width<1&&e.height<1&&e.pressure===0&&e.detail===0&&e.pointerType===`touch`}function IF(e,t){let n=[`mouse`,`pen`];return t||n.push(``,void 0),n.includes(e)}function LF(e){let t=e.type;return t===`click`||t===`mousedown`||t===`keydown`||t===`keyup`}function RF(e){let t=e.activeElement;for(;t?.shadowRoot?.activeElement!=null;)t=t.shadowRoot.activeElement;return t}function zF(e,t){if(!e||!t)return!1;let n=t.getRootNode?.();if(e.contains(t))return!0;if(n&&kx(n)){let n=t;for(;n;){if(e===n)return!0;n=n.parentNode||n.host}}return!1}function BF(e,t){let n=e;for(;n;){if(Dx(n)&&n.matches(t))return n;n=n.assignedSlot??n.parentNode??(kx(n)?n.host:null)}return null}function VF(e){return`composedPath`in e?e.composedPath()[0]??e.target:e.target}var HF=`data-base-ui-focusable`,UF=`input:not([type='hidden']):not([disabled]),[contenteditable]:not([contenteditable='false']),textarea:not([disabled])`,WF=`data-starting-style`,GF=`data-ending-style`,KF={[WF]:``},qF={[GF]:``},JF={transitionStatus(e){return e===`starting`?KF:e===`ending`?qF:null}},YF=`data-open`,XF=`data-closed`,ZF=`data-anchor-hidden`,QF={"data-popup-open":``},$F={[YF]:``},eI={[XF]:``},tI={[ZF]:``},nI={open(e){return e?QF:null}},rI={open(e){return e?$F:eI},anchorHidden(e){return e?tI:null}},iI={...rI,...JF},aI=`data-trigger-disabled`;function oI(e,t){if(!Dx(e))return!1;let n=e;if(t.hasElement(n))return!n.hasAttribute(aI);for(let[,e]of t.entries())if(zF(e,n))return!e.hasAttribute(aI);return!1}function sI(e,t){if(t==null)return!1;if(`composedPath`in e)return e.composedPath().includes(t);let n=e;return n.target!=null&&t.contains(n.target)}function cI(e){return e.matches(`html,body`)}function lI(e){return Ox(e)&&e.matches(`input:not([type='hidden']):not([disabled]),[contenteditable]:not([contenteditable='false']),textarea:not([disabled])`)}function uI(e){return BF(e,`button,a[href],[role="button"],select,[tabindex]:not([tabindex="-1"]),${UF}`)!=null}function dI(e){return e?e.getAttribute(`role`)===`combobox`&&lI(e):!1}function fI(e){if(!e||jF)return!0;try{return e.matches(`:focus-visible`)}catch{return!0}}function pI(e){return e?e.hasAttribute(`data-base-ui-focusable`)?e:e.querySelector(`[data-base-ui-focusable]`)||e:null}function mI(e,t){return t!=null&&!IF(t)?0:typeof e==`function`?e():e}function hI(e,t,n){let r=mI(e,n);return typeof r==`number`?r:r?.[t]}function gI(e){return typeof e==`function`?e():e}function _I(e,t){return t||e===`click`||e===`mousedown`}function vI(e){return e?.includes(`mouse`)&&e!==`mousedown`}function yI(e,t,n,r){let i=!1,a=!1,o=r??cF;return{reason:e,event:t??new Event(`base-ui`),cancel(){i=!0},allowPropagation(){a=!0},get isCanceled(){return i},get isPropagationAllowed(){return a},trigger:n,...o}}var bI=`none`,xI=`trigger-press`,SI=`trigger-hover`,CI=`trigger-focus`,wI=`outside-press`,TI=`close-press`,EI=`focus-out`,DI=`escape-key`,OI=`disabled`,kI=`imperative-action`,AI=f.createContext({hasProvider:!1,timeoutMs:0,delayRef:{current:0},initialDelayRef:{current:0},timeout:new gF,currentIdRef:{current:null},currentContextRef:{current:null}});process.env.NODE_ENV!==`production`&&(AI.displayName=`FloatingDelayGroupContext`);function jI(e,t){e.current=t.current}function MI(e){let{children:t,delay:n,timeoutMs:r=0}=e,i=f.useRef(n),a=f.useRef(n),o=f.useRef(null),s=f.useRef(null),c=_F();return lF(()=>{a.current=n,o.current?i.current={open:hI(i.current,`open`),close:hI(n,`close`)}:i.current=n},[n,o,i,a]),(0,J.jsx)(AI.Provider,{value:f.useMemo(()=>({hasProvider:!0,delayRef:i,initialDelayRef:a,currentIdRef:o,timeoutMs:r,currentContextRef:s,timeout:c}),[r,c]),children:t})}function NI(e,t={open:!1}){let{open:n}=t,r=e.useState(`floatingId`),{currentIdRef:i,delayRef:a,timeoutMs:o,initialDelayRef:s,currentContextRef:c,hasProvider:l,timeout:u}=f.useContext(AI),[d,p]=f.useState(!1),m=f.useRef(n);return lF(()=>{m.current=n},[n]),lF(()=>{function t(){c.current?.setIsInstantPhase(!1),i.current=null,c.current=null,a.current=s.current,u.clear()}if(i.current&&!n&&i.current===r){if(p(!1),o){let n=r;return u.start(o,()=>{e.select(`open`)||i.current&&i.current!==n||t()}),()=>{(m.current||i.current!==n)&&u.clear()}}t()}},[n,r,i,a,o,s,c,u,e]),lF(()=>{if(!n)return;let t=c.current,o=i.current;u.clear(),c.current={onOpenChange:e.setOpen,setIsInstantPhase:p},i.current=r,a.current={open:0,close:hI(s.current,`close`)},o!==null&&o!==r?(p(!0),t?.setIsInstantPhase(!0),t?.onOpenChange(!1,yI(bI))):(p(!1),t?.setIsInstantPhase(!1))},[n,r,e,i,a,s,c,u]),lF(()=>()=>{if(i.current===r){if(c.current=null,!m.current)return;i.current=null,jI(a,s),u.clear()}},[c,i,a,r,s,u]),f.useMemo(()=>({activeIdRef:i,hasProvider:l,delayRef:a,isInstantPhase:d}),[i,l,a,d])}function PI(e,t,n,r){return e.addEventListener(t,n,r),()=>{e.removeEventListener(t,n,r)}}function FI(...e){return()=>{for(let t=0;t<e.length;t+=1){let n=e[t];n&&n()}}}function II(e,t,n,r){let i=QP(RI).current;return zI(i,e,t,n,r)&&VI(i,[e,t,n,r]),i.callback}function LI(e){let t=QP(RI).current;return BI(t,e)&&VI(t,e),t.callback}function RI(){return{callback:null,cleanup:null,refs:[]}}function zI(e,t,n,r,i){return e.refs[0]!==t||e.refs[1]!==n||e.refs[2]!==r||e.refs[3]!==i}function BI(e,t){return e.refs.length!==t.length||e.refs.some((e,n)=>e!==t[n])}function VI(e,t){e.refs=t,e.callback=t.every(e=>e==null)?null:n=>{if(e.cleanup&&=(e.cleanup(),null),n!=null){let r=Array(t.length).fill(null);for(let e=0;e<t.length;e+=1){let i=t[e];if(i!=null)switch(typeof i){case`function`:{let t=i(n);typeof t==`function`&&(r[e]=t);break}case`object`:i.current=n}}e.cleanup=()=>{for(let e=0;e<t.length;e+=1){let n=t[e];if(n!=null)switch(typeof n){case`function`:{let t=r[e];typeof t==`function`?t():n(null);break}case`object`:n.current=null}}}}}}function HI(e){let t=QP(UI,e).current;return t.next=e,lF(t.effect),t}function UI(e){let t={current:e,next:e,effect:()=>{t.current=t.next}};return t}var WI={...f},GI=WI.useInsertionEffect,KI=GI&&GI!==WI.useLayoutEffect?GI:e=>e();function qI(e){let t=QP(JI).current;return t.next=e,KI(t.effect),t.trampoline}function JI(){let e={next:void 0,callback:YI,trampoline:(...t)=>e.callback?.(...t),effect:()=>{e.callback=e.next}};return e}function YI(){if(process.env.NODE_ENV!==`production`)throw Error(`Base UI: Cannot call an event handler while rendering.`)}var XI=null,ZI=globalThis.requestAnimationFrame,QI=new class{callbacks=[];callbacksCount=0;nextId=1;startId=1;isScheduled=!1;tick=e=>{this.isScheduled=!1;let t=this.callbacks,n=this.callbacksCount;if(this.callbacks=[],this.callbacksCount=0,this.startId=this.nextId,n>0)for(let n=0;n<t.length;n+=1)t[n]?.(e)};request(e){let t=this.nextId;this.nextId+=1,this.callbacks.push(e),this.callbacksCount+=1;let n=process.env.NODE_ENV!==`production`&&ZI!==requestAnimationFrame&&(ZI=requestAnimationFrame,!0);return(!this.isScheduled||n)&&(requestAnimationFrame(this.tick),this.isScheduled=!0),t}cancel(e){let t=e-this.startId;t<0||t>=this.callbacks.length||this.callbacks[t]!==null&&(this.callbacks[t]=null,--this.callbacksCount)}},$I=class e{static create(){return new e}static request(e){return QI.request(e)}static cancel(e){return QI.cancel(e)}currentId=XI;request(e){this.cancel(),this.currentId=QI.request(()=>{this.currentId=XI,e()})}cancel=()=>{this.currentId!==XI&&(QI.cancel(this.currentId),this.currentId=XI)};disposeEffect=()=>this.cancel};function eL(){let e=QP($I.create).current;return mF(e.disposeEffect),e}function tL(e){return e?.ownerDocument||document}var nL={clipPath:`inset(50%)`,overflow:`hidden`,whiteSpace:`nowrap`,border:0,padding:0,width:1,height:1,margin:-1},rL={...nL,position:`fixed`,margin:0,top:0,left:0};({...nL});var iL=f.forwardRef(function(e,t){let[n,r]=f.useState();lF(()=>{AF&&kF&&r(`button`)},[]);let i={tabIndex:0,role:n};return(0,J.jsx)(`span`,{...e,ref:t,style:rL,"aria-hidden":!n||void 0,...i,"data-base-ui-focus-guard":``})});process.env.NODE_ENV!==`production`&&(iL.displayName=`FocusGuard`);function aL(e){return e.visibility===`hidden`||e.visibility===`collapse`}function oL(e,t=e?Vx(e):null){return!e||!e.isConnected||!t||aL(t)?!1:typeof e.checkVisibility==`function`?e.checkVisibility():t.display!==`none`&&t.display!==`contents`}var sL=`a[href],button,input,select,textarea,summary,details,iframe,object,embed,[tabindex],[contenteditable]:not([contenteditable="false"]),audio[controls],video[controls]`;function cL(e){let t=e.assignedSlot;if(t)return t;if(e.parentElement)return e.parentElement;let n=e.getRootNode();return kx(n)?n.host:null}function lL(e){for(let t of Array.from(e.children))if(Cx(t)===`summary`)return t;return null}function uL(e,t){let n=lL(t);return!!n&&(e===n||zF(n,e))}function dL(e){let t=e?Cx(e):``;return e!=null&&e.matches(sL)&&(t!==`summary`||e.parentElement!=null&&Cx(e.parentElement)===`details`&&lL(e.parentElement)===e)&&(t!==`details`||lL(e)==null)&&(t!==`input`||e.type!==`hidden`)}function fL(e){if(!dL(e)||!e.isConnected||e.matches(`:disabled`))return!1;for(let t=e;t;t=cL(t)){let n=t!==e,r=Cx(t)===`slot`;if(t.hasAttribute(`inert`)||n&&Cx(t)===`details`&&!t.open&&!uL(e,t)||t.hasAttribute(`hidden`)||!r&&!pL(t,n))return!1}return!0}function pL(e,t){let n=Vx(e);return t?n.display!==`none`:oL(e,n)}function mL(e){let t=e.tabIndex;if(t<0){let t=Cx(e);if(t===`details`||t===`audio`||t===`video`||Ox(e)&&e.isContentEditable)return 0}return t}function hL(e){if(Cx(e)!==`input`)return null;let t=e;return t.type===`radio`&&t.name!==``?t:null}function gL(e,t){let n=hL(e);if(!n)return!0;let r=t.find(e=>{let t=hL(e);return t?.name===n.name&&t.form===n.form&&t.checked});return r?r===n:t.find(e=>{let t=hL(e);return t?.name===n.name&&t.form===n.form})===n}function _L(e){if(Ox(e)&&Cx(e)===`slot`){let t=e.assignedElements({flatten:!0});if(t.length>0)return t}return Ox(e)&&e.shadowRoot?Array.from(e.shadowRoot.children):Array.from(e.children)}function vL(e,t){_L(e).forEach(e=>{dL(e)&&t.push(e),vL(e,t)})}function yL(e,t,n){_L(e).forEach(e=>{Ox(e)&&e.matches(t)&&n.push(e),yL(e,t,n)})}function bL(e){return fL(e)&&mL(e)>=0}function xL(e){let t=[];return vL(e,t),t.filter(fL)}function SL(e){let t=xL(e);return t.filter(e=>mL(e)>=0&&gL(e,t))}function CL(e,t){let n=SL(e),r=n.length;if(r===0)return;let i=RF(tL(e)),a=n.indexOf(i);return n[a===-1?t===1?0:r-1:a+t]}function wL(e){return CL(tL(e).body,1)||e}function TL(e){return CL(tL(e).body,-1)||e}function EL(e,t){let n=t||e.currentTarget,r=e.relatedTarget;return!r||!zF(n,r)}function DL(e){SL(e).forEach(e=>{e.dataset.tabindex=e.getAttribute(`tabindex`)||``,e.setAttribute(`tabindex`,`-1`)})}function OL(e){let t=[];yL(e,`[data-tabindex]`,t),t.forEach(e=>{let t=e.dataset.tabindex;delete e.dataset.tabindex,t?e.setAttribute(`tabindex`,t):e.removeAttribute(`tabindex`)})}function kL(e,t,n=!0){return e.filter(e=>e.parentId===t).flatMap(t=>[...!n||t.context?.open?[t]:[],...kL(e,t.id,n)])}function AL(e,t){let n=[],r=e.find(e=>e.id===t)?.parentId;for(;r;){let t=e.find(e=>e.id===r);r=t?.parentId,t&&(n=n.concat(t))}return n}function jL(e){return`data-base-ui-${e}`}var ML=0;function NL(e,t={}){let{preventScroll:n=!1,sync:r=!1,shouldFocus:i}=t;cancelAnimationFrame(ML);function a(){(!i||i())&&e?.focus({preventScroll:n})}if(r)return a(),oF;let o=requestAnimationFrame(a);return ML=o,()=>{ML===o&&(cancelAnimationFrame(o),ML=0)}}var PL=`data-base-ui-inert`,FL=new WeakMap,IL=new WeakSet,LL=new WeakMap,RL=0;function zL(e){return e?kx(e)?e.host:zL(e.parentNode):null}var BL=(e,t)=>t.map(t=>{if(e.contains(t))return t;let n=zL(t);return e.contains(n)?n:null}).filter(e=>e!=null),VL=e=>{let t=new Set;return e.forEach(e=>{let n=e;for(;n&&!t.has(n);)t.add(n),n=n.parentNode}),t},HL=(e,t,n)=>{let r=[],i=e=>{e&&!n.has(e)&&Array.from(e.children).forEach(e=>{Cx(e)!==`script`&&(t.has(e)?i(e):r.push(e))})};return i(e),r};function UL(e,t,n,{mark:r=!0}){let i=BL(t,e),a=r?HL(t,VL(i),new Set(i)):[],o=[],s=[];if(n){let e=BL(t,Array.from(t.querySelectorAll(`[aria-live]`))),n=i.concat(e);HL(t,VL(n),new Set(n)).forEach(e=>{let t=e.getAttribute(`aria-hidden`),n=t!==null&&t!==`false`,r=(FL.get(e)||0)+1;FL.set(e,r),o.push(e),r===1&&n&&IL.add(e),n||e.setAttribute(`aria-hidden`,`true`)})}return r&&a.forEach(e=>{let t=(LL.get(e)||0)+1;LL.set(e,t),s.push(e),t===1&&e.setAttribute(PL,``)}),RL+=1,()=>{o.forEach(e=>{let t=(FL.get(e)||0)-1;FL.set(e,t),t||(IL.has(e)||e.removeAttribute(`aria-hidden`),IL.delete(e))}),r&&s.forEach(e=>{let t=(LL.get(e)||0)-1;LL.set(e,t),t||e.removeAttribute(PL)}),--RL,RL||(FL=new WeakMap,IL=new WeakSet,LL=new WeakMap)}}function WL(e,t={}){let{ariaHidden:n=!1,mark:r=!0}=t,i=tL(e[0]).body;return UL(e,i,n,{mark:r})}function GL(){let[,e]=f.useState({});return f.useCallback(()=>{e({})},[])}var KL=0;function qL(e,t=`mui`){let n=f.useRef(void 0),r=GL(),i=e??n.current;return f.useEffect(()=>{n.current??(KL+=1,n.current=`${t}-${KL}`,e??r())},[e,t,r]),i}var JL=WI.useId;function YL(e,t){if(JL!==void 0){let n=JL();return e??(t?`${t}-${n}`:n)}return qL(e,t)}var XL=parseInt(f.version,10);function ZL(e){return XL>=e}function QL(e){if(!f.isValidElement(e))return null;let t=e,n=t.props;return(ZL(19)?n?.ref:t.ref)??null}function $L(e,t){if(e&&!t)return e;if(!e&&t)return t;if(e||t)return{...e,...t}}var eR;process.env.NODE_ENV!==`production`&&(eR=new Set);function tR(e,t){return function(...n){if(process.env.NODE_ENV!==`production`){let r=n.join(` `),i=t?`${t}: ${r}`:r,a=`${e}:${i}`;eR.has(a)||(eR.add(a),e===`warn`?console.warn(i):console.error(i))}}}var nR=tR(`warn`,`Base UI`);function rR(e,t){let n={};for(let r in e){let i=e[r];if(t?.hasOwnProperty(r)){let e=t[r](i);e!=null&&Object.assign(n,e)}else i===!0?n[`data-${r.toLowerCase()}`]=``:i&&(n[`data-${r.toLowerCase()}`]=i.toString())}return n}function iR(e,t){return typeof e==`function`?e(t):e}function aR(e,t){return typeof e==`function`?e(t):e}var oR={};function sR(e,t,n,r,i){if(!n&&!r&&!i&&!e)return lR(t);let a=lR(e);return t&&(a=uR(a,t)),n&&(a=uR(a,n)),r&&(a=uR(a,r)),i&&(a=uR(a,i)),a}function cR(e){if(e.length===0)return oR;if(e.length===1)return lR(e[0]);let t=lR(e[0]);for(let n=1;n<e.length;n+=1)t=uR(t,e[n]);return t}function lR(e){return mR(e)?{...e(oR)}:dR(e)}function uR(e,t){return mR(t)?t(e):fR(e,t)}function dR(e){let t={...e};for(let e in t){let n=t[e];pR(e,n)&&(t[e]=gR(n))}return t}function fR(e,t){if(!t)return e;for(let n in t){let r=t[n];switch(n){case`style`:e[n]=$L(e.style,r);break;case`className`:e[n]=vR(e.className,r);break;default:e[n]=pR(n,r)?hR(e[n],r):r}}return e}function pR(e,t){let n=e.charCodeAt(0),r=e.charCodeAt(1),i=e.charCodeAt(2);return n===111&&r===110&&i>=65&&i<=90&&(typeof t==`function`||t===void 0)}function mR(e){return typeof e==`function`}function hR(e,t){return t?e?(...n)=>{let r=n[0];if(yR(r)){let i=r;_R(i);let a=t(...n);return i.baseUIHandlerPrevented||e?.(...n),a}let i=t(...n);return e?.(...n),i}:gR(t):e}function gR(e){return e&&((...t)=>{let n=t[0];return yR(n)&&_R(n),e(...t)})}function _R(e){return e.preventBaseUIHandler=()=>{e.baseUIHandlerPrevented=!0},e}function vR(e,t){return t?e?t+` `+e:t:e}function yR(e){return typeof e==`object`&&!!e&&`nativeEvent`in e}function bR(e,t,n={}){let r=t.render;n.enabled!==!1&&(r=ER(r));let i=xR(t,n,r);if(n.enabled===!1)return null;let a=n.state??cF;return DR(e,r,i,a)}function xR(e,t,n){let{className:r,style:i}=e,{state:a=cF,ref:o,props:s,stateAttributesMapping:c,enabled:l=!0}=t,u=l?iR(r,a):void 0,d=l?aR(i,a):void 0,f=l?rR(a,c):cF,p=l&&s?SR(s):void 0,m=l?$L(f,p)??{}:cF;return typeof document<`u`&&(l?m.ref=Array.isArray(o)?LI([m.ref,QL(n),...o]):II(m.ref,QL(n),o):II(null,null)),l?(u!==void 0&&(m.className=vR(m.className,u)),d!==void 0&&(m.style=$L(m.style,d)),m):cF}function SR(e){return Array.isArray(e)?cR(e):sR(void 0,e)}var CR=Symbol.for(`react.lazy`),wR=/^[A-Z][A-Za-z0-9$]*$/,TR=/[a-z]/;function ER(e){if(e?.$$typeof!==CR)return e;let t=f.Children.toArray(e)[0];return f.isValidElement(t)?t:e}function DR(e,t,n,r){if(t){if(typeof t==`function`)return process.env.NODE_ENV!==`production`&&OR(t),t(n,r);let e=sR(n,t.props);if(e.ref=n.ref,process.env.NODE_ENV!==`production`&&!f.isValidElement(t))throw Error("Base UI: The `render` prop was provided an invalid React element as `React.isValidElement(render)` is `false`.\nA valid React element must be provided to the `render` prop because it is cloned with props to replace the default element.\nhttps://base-ui.com/r/invalid-render-prop");return f.cloneElement(t,e)}return kR(e,n)}function OR(e){let t=e.name;t.length!==0&&wR.test(t)&&TR.test(t)&&nR(`The \`render\` prop received a function named \`${t}\` that starts with an uppercase letter.`,"This usually means a React component was passed directly as `render={Component}`.","Base UI calls `render` as a plain function, which can break the Rules of Hooks during reconciliation.",`If this is an intentional render callback, rename it to start with a lowercase letter.`,"Use `render={<Component />}` or `render={(props) => <Component {...props} />}` instead.",`https://base-ui.com/r/invalid-render-prop`)}function kR(e,t){return e===`button`?(0,f.createElement)(`button`,{type:`button`,...t,key:t.key}):e===`img`?(0,f.createElement)(`img`,{alt:``,...t,key:t.key}):f.createElement(e,t)}var AR={style:{transition:`none`}},jR=`data-base-ui-click-trigger`,MR={fallbackAxisSide:`end`},NR={clipPath:`inset(50%)`,position:`fixed`,top:0,left:0},PR=f.createContext(null);process.env.NODE_ENV!==`production`&&(PR.displayName=`PortalContext`);var FR=()=>f.useContext(PR),IR=jL(`portal`);function LR(e={}){let{ref:t,container:n,componentProps:r=cF,elementProps:i}=e,a=YL(),o=FR()?.portalNode,[s,c]=f.useState(null),[l,u]=f.useState(null),d=qI(e=>{e!==null&&u(e)}),m=f.useRef(null);lF(()=>{if(n===null){m.current&&(m.current=null,u(null),c(null));return}let e=(n&&(Ex(n)?n:n.current))??o??document.body;e==null?m.current&&(m.current=null,u(null),c(null)):m.current!==e&&(m.current=e,u(null),c(e))},[n,o]);let h=bR(`div`,r,{ref:[t,d],props:[{id:a,[IR]:``},i]}),g=s&&h?p.createPortal(h,s):null;return{node:l,nodeId:f.isValidElement(h)?h.props.id:void 0,subtree:g}}var RR=f.forwardRef(function(e,t){let{render:n,className:r,style:i,children:a,container:o,portalOwnerRole:s,...c}=e,{node:l,nodeId:u,subtree:d}=LR({container:o,ref:t,componentProps:e,elementProps:c}),m=f.useRef(null),h=f.useRef(null),g=f.useRef(null),_=f.useRef(null),[v,y]=f.useState(null),b=f.useRef(!1),x=v?.modal,S=v?.open,C=!!v&&!v.modal&&v.open&&!!l;f.useEffect(()=>{if(!l||x)return;function e(e){l&&e.relatedTarget&&EL(e)&&(e.type===`focusin`?b.current&&=(OL(l),!1):(DL(l),b.current=!0))}return FI(PI(l,`focusin`,e,!0),PI(l,`focusout`,e,!0))},[l,x]),lF(()=>{l&&S===!0&&b.current&&(OL(l),b.current=!1)},[S,l]);let w=f.useMemo(()=>({beforeOutsideRef:m,afterOutsideRef:h,beforeInsideRef:g,afterInsideRef:_,portalNode:l,setFocusManagerState:y}),[l]);return(0,J.jsxs)(f.Fragment,{children:[d,(0,J.jsxs)(PR.Provider,{value:w,children:[C&&l&&(0,J.jsx)(iL,{"data-type":`outside`,ref:m,onFocus:e=>{EL(e,l)?g.current?.focus():TL(v?v.domReference:null)?.focus()}}),C&&l&&(0,J.jsx)(`span`,{role:s,"aria-owns":u,style:NR}),l&&p.createPortal(a,l),C&&l&&(0,J.jsx)(iL,{"data-type":`outside`,ref:h,onFocus:e=>{EL(e,l)?_.current?.focus():(wL(v?v.domReference:null)?.focus(),v?.closeOnFocusOut&&v?.onOpenChange(!1,yI(`focus-out`,e.nativeEvent)))}})]})]})});process.env.NODE_ENV!==`production`&&(RR.displayName=`FloatingPortal`);function zR(){let e=new Map;return{emit(t,n){e.get(t)?.forEach(e=>e(n))},on(t,n){e.has(t)||e.set(t,new Set),e.get(t).add(n)},off(t,n){e.get(t)?.delete(n)}}}var BR=f.createContext(null);process.env.NODE_ENV!==`production`&&(BR.displayName=`FloatingNodeContext`);var VR=f.createContext(null);process.env.NODE_ENV!==`production`&&(VR.displayName=`FloatingTreeContext`);var HR=()=>f.useContext(BR)?.id||null,UR=e=>{let t=f.useContext(VR);return e??t};function WR(e){return e==null?e:`current`in e?e.current:e}function GR(e,t){let n=wx(VF(e));return e instanceof n.KeyboardEvent?`keyboard`:e instanceof n.FocusEvent?t||`keyboard`:`pointerType`in e?e.pointerType||(PF(e)?`keyboard`:t||`mouse`):`touches`in e?`touch`:e instanceof n.MouseEvent?t||(e.detail===0?`keyboard`:`mouse`):``}var KR=20,qR=[];function JR(){qR=qR.filter(e=>e.deref()?.isConnected)}function YR(e){JR(),e&&Cx(e)!==`body`&&(qR.push(new WeakRef(e)),qR.length>KR&&(qR=qR.slice(-20)))}function XR(){return JR(),qR[qR.length-1]?.deref()}function ZR(e){return e?bL(e)?e:SL(e)[0]||e:null}function QR(e){if(e.hasAttribute(`tabindex`)&&!e.hasAttribute(`data-tabindex`)||!e.getAttribute(`role`)?.includes(`dialog`))return;let t=xL(e).filter(e=>{let t=e.getAttribute(`data-tabindex`)||``;return bL(e)||e.hasAttribute(`data-tabindex`)&&!t.startsWith(`-`)}),n=e.getAttribute(`tabindex`);t.length===0?n!==`0`&&(e.setAttribute(`tabindex`,`0`),e.setAttribute(`data-tabindex`,`0`)):(n!==`-1`||e.hasAttribute(`data-tabindex`)&&e.getAttribute(`data-tabindex`)!==`-1`)&&(e.setAttribute(`tabindex`,`-1`),e.setAttribute(`data-tabindex`,`-1`))}function $R(e){let{context:t,children:n,disabled:r=!1,initialFocus:i=!0,returnFocus:a=!0,explicitReturnFocus:o,restoreFocus:s=!1,modal:c=!0,closeOnFocusOut:l=!0,openInteractionType:u=``,nextFocusableElement:d,previousFocusableElement:p,beforeContentFocusGuardRef:m,externalTree:h,getInsideElements:g}=e,_=t.useState(`open`),v=t.useState(`domReferenceElement`),y=t.useState(`floatingElement`),{events:b,dataRef:x}=t.context,S=qI(()=>x.current.floatingContext?.nodeId),C=i===!1,w=dI(v)&&C,T=HI(i),E=HI(a),D=HI(o),O=HI(u),k=HI(_),A=UR(h),j=FR(),M=f.useRef(!1),N=f.useRef(!1),P=f.useRef(!1),F=f.useRef(null),I=f.useRef(``),L=f.useRef(``),R=f.useRef(null),z=f.useRef(null),ee=II(R,m,j?.beforeInsideRef),te=II(z,j?.afterInsideRef),ne=_F(),B=_F(),re=eL(),ie=j!=null,V=pI(y),ae=qI((e=V)=>e?SL(e):[]),oe=qI(()=>g?.().filter(e=>e!=null)??[]);f.useEffect(()=>{if(r||!c)return;function e(e){e.key===`Tab`&&zF(V,RF(tL(V)))&&ae().length===0&&!w&&MF(e)}return PI(tL(V),`keydown`,e)},[r,V,c,w,ae]),f.useEffect(()=>{if(r||!_)return;let e=tL(V);function t(){P.current=!1}function n(e){let t=VF(e),n=oe(),r=zF(y,t)||zF(v,t)||zF(j?.portalNode,t)||n.some(e=>e===t||zF(e,t));P.current=!r,L.current=e.pointerType||`keyboard`,BF(t,`[data-base-ui-click-trigger]`)&&(N.current=!0,B.start(0,()=>{N.current=!1}))}function i(){L.current=`keyboard`}return FI(PI(e,`pointerdown`,n,!0),PI(e,`pointerup`,t,!0),PI(e,`pointercancel`,t,!0),PI(e,`keydown`,i,!0),t)},[r,y,v,V,_,j,B,oe]),f.useEffect(()=>{if(r||!l)return;let e=tL(V);function n(){N.current=!0,B.start(0,()=>{N.current=!1})}function i(e){let t=VF(e);bL(t)&&(F.current=t)}function a(n){let r=n.relatedTarget,i=n.currentTarget,a=VF(n);c&&r==null&&a!=null&&zF(y,a)&&YR(a),queueMicrotask(()=>{let o=S(),l=t.context.triggerElements,u=oe(),f=r?.hasAttribute(jL(`focus-guard`))&&[R.current,z.current,j?.beforeInsideRef.current,j?.afterInsideRef.current,j?.beforeOutsideRef.current,j?.afterOutsideRef.current,WR(p),WR(d)].includes(r),m=!(zF(v,r)||zF(y,r)||zF(r,y)||zF(j?.portalNode,r)||u.some(e=>e===r||zF(e,r))||l.hasMatchingElement(e=>zF(e,r))||f||A&&(kL(A.nodesRef.current,o).find(e=>zF(e.context?.elements.floating,r)||zF(e.context?.elements.domReference,r))||AL(A.nodesRef.current,o).find(e=>[e.context?.elements.floating,pI(e.context?.elements.floating)].includes(r)||e.context?.elements.domReference===r)));if(i===v&&V&&QR(V),s&&i!==v&&!oL(a)&&RF(e)===e.body){if(Ox(V)&&(V.focus(),s===`popup`)){re.request(()=>{V.focus()});return}let e=ae(),t=F.current,n=(t&&e.includes(t)?t:null)||e[e.length-1]||V;Ox(n)&&n.focus()}x.current.insideReactTree?x.current.insideReactTree=!1:(w||!c)&&r&&m&&!N.current&&(w||r!==XR())&&(M.current=!0,t.setOpen(!1,yI(EI,n)))})}function o(){P.current||(x.current.insideReactTree=!0,ne.start(0,()=>{x.current.insideReactTree=!1}))}let u=Ox(v)?v:null;if(y||u)return FI(u&&PI(u,`focusout`,a),u&&PI(u,`pointerdown`,n),y&&PI(y,`focusin`,i),y&&PI(y,`focusout`,a),y&&j&&PI(y,`focusout`,o,!0))},[r,v,y,V,c,A,j,t,l,s,ae,w,S,x,ne,B,re,d,p,oe]),f.useEffect(()=>{if(r||!y||!_)return;let e=Array.from(j?.portalNode?.querySelectorAll(`[${jL(`portal`)}]`)||[]),t=(A?AL(A.nodesRef.current,S()):[]).find(e=>dI(e.context?.elements.domReference||null))?.context?.elements.domReference,n=WL([y,...e,R.current,z.current,j?.beforeOutsideRef.current,j?.afterOutsideRef.current,...oe(),t,WR(p),WR(d),w?v:null].filter(e=>e!=null),{ariaHidden:c||w,mark:!1}),i=WL([y,...e].filter(e=>e!=null));return()=>{i(),n()}},[_,r,v,y,c,j,w,A,S,d,p,oe]),lF(()=>{if(!_||r||!Ox(V))return;I.current=``,L.current=``;let e=tL(V),t=RF(e);queueMicrotask(()=>{let n=T.current,r=typeof n==`function`?n(O.current||``):n;if(r===void 0||r===!1||zF(V,t))return;let i=null,a=()=>(i??=ae(V),i[0]||V),o;o=r===!0||r===null?a():WR(r),o||=a();let s=zF(V,RF(e)),c=x.current.openEvent,l=c?.type===`mousedown`&&PF(c);NL(o,{sync:l,preventScroll:o===V,shouldFocus(){if(!k.current)return!1;if(s)return!0;let t=RF(e);return!(t!==o&&zF(V,t))}})})},[r,_,V,ae,T,O,k,x]);let se=f.useRef(null);lF(()=>{if(r||!V){se.current=null;return}se.current&&=(se.current.cancelled=!0,null);let e=tL(V),t=RF(e),n=O.current==null;YR(t);function i(e){if(e.open||(I.current=GR(e.nativeEvent,L.current)),(e.reason===`focus-out`&&e.triggerElement?.hasAttribute(jL(`focus-guard`))||e.reason===`trigger-hover`&&e.nativeEvent.type===`mouseleave`)&&(M.current=!0),e.reason===`outside-press`){if(e.nested)M.current=!1;else if(PF(e.nativeEvent)||FF(e.nativeEvent))M.current=!1;else{let e=!1;tL(V).createElement(`div`).focus({get preventScroll(){return e=!0,!1}}),e?M.current=!1:M.current=!0}}}b.on(`openchange`,i);function a(e){let r=E.current,i=typeof r==`function`?r(e):r;if(i===void 0||i===!1)return null;i===null&&(i=!0);let a=v?.isConnected?v:null,o=t?.isConnected&&Cx(t)!==`body`?t:null,s=n?o||a:a||o;return s||=XR()||null,typeof i==`boolean`?s:WR(i)||s||null}return()=>{b.off(`openchange`,i);let t=RF(e),n=oe(),r=zF(y,t)||n.some(e=>e===t||zF(e,t))||A&&kL(A.nodesRef.current,S(),!1).some(e=>zF(e.context?.elements.floating,t)),o=E.current,s=I.current,c=a(s),l={cancelled:!1};se.current=l,queueMicrotask(()=>{se.current===l&&(se.current=null);let n=ZR(c),i=D.current??typeof o!=`boolean`;if(!l.cancelled&&o&&!M.current&&Ox(n)&&(i||n===t||t===e.body||r)){let e={preventScroll:!0};s===`keyboard`&&(e.focusVisible=!0),n.focus(e)}M.current=!1})}},[r,y,V,E,D,O,b,A,v,S,oe]),lF(()=>{if(!kF||_||!y)return;let e=RF(tL(y));Ox(e)&&lI(e)&&zF(y,e)&&e.blur()},[_,y]),lF(()=>{if(!r&&j)return j.setFocusManagerState({modal:c,closeOnFocusOut:l,open:_,onOpenChange:t.setOpen,domReference:v}),()=>{j.setFocusManagerState(null)}},[r,j,c,_,t,l,v]),lF(()=>{if(!r&&V)return QR(V),()=>{queueMicrotask(JR)}},[r,V]);let ce=!r&&(!c||!w)&&(ie||c);return(0,J.jsxs)(f.Fragment,{children:[ce&&(0,J.jsx)(iL,{"data-type":`inside`,ref:ee,onFocus:e=>{if(c){let e=ae();NL(e[e.length-1])}else j?.portalNode&&(M.current=!1,EL(e,j.portalNode)?wL(v)?.focus():WR(p??j.beforeOutsideRef)?.focus())}}),n,ce&&(0,J.jsx)(iL,{"data-type":`inside`,ref:te,onFocus:e=>{c?NL(ae()[0]):j?.portalNode&&(l&&(M.current=!0),EL(e,j.portalNode)?TL(v)?.focus():WR(d??j.afterOutsideRef)?.focus())}})]})}function ez(e,t={}){let{enabled:n=!0,event:r=`click`,toggle:i=!0,ignoreMouse:a=!1,stickIfOpen:o=!0,touchOpenDelay:s=0,reason:c=xI}=t,l=e.context.dataRef,u=f.useRef(void 0),d=eL(),p=_F(),m=f.useMemo(()=>{function t(t,n,r,i){let a=yI(c,n,r);t&&i===`touch`&&s>0?p.start(s,()=>{e.setOpen(!0,a)}):e.setOpen(t,a)}function n(t,n,r){let a=l.current.openEvent,s=e.select(`domReferenceElement`)!==n;return t&&s||!t||!i?!0:a&&(typeof o==`function`?o():o)?!r(a.type):!1}return{onPointerDown(e){u.current=IF(e.pointerType,!0)&&FF(e.nativeEvent)?`virtual`:e.pointerType},onMouseDown(i){let o=u.current,s=i.nativeEvent,c=e.select(`open`);if(i.button!==0||r===`click`||IF(o,!0)&&a)return;let l=n(c,i.currentTarget,e=>e===`click`||e===`mousedown`),f=VF(s),p=lI(f);if(p||o===`virtual`){t(l,s,p?f:i.currentTarget,o);return}let m=i.currentTarget;d.request(()=>{t(l,s,m,o)})},onClick(i){if(r===`mousedown-only`)return;let o=u.current;r===`mousedown`&&o?u.current=void 0:IF(o,!0)&&a||t(n(e.select(`open`),i.currentTarget,e=>e===`click`||e===`mousedown`||e===`keydown`||e===`keyup`),i.nativeEvent,i.currentTarget,o)},onKeyDown(){u.current=void 0}}},[l,r,a,c,e,o,i,d,p,s]);return f.useMemo(()=>n?{reference:m}:cF,[n,m])}function tz(e,t){let n=null,r=null,i=!1;return{contextElement:e||void 0,getBoundingClientRect(){let a=e?.getBoundingClientRect()||{width:0,height:0,x:0,y:0},o=t.axis===`x`||t.axis===`both`,s=t.axis===`y`||t.axis===`both`,c=[`mouseenter`,`mousemove`].includes(t.dataRef.current.openEvent?.type||``)&&t.pointerType!==`touch`,l=t.axis===`y`?a.width:0,u=t.axis===`x`?a.height:0,d=a.x,f=a.y;return n==null&&t.x&&o&&(n=a.x-t.x),r==null&&t.y&&s&&(r=a.y-t.y),d-=n||0,f-=r||0,(!i||c)&&(d=o&&t.x!=null?t.x:d,f=s&&t.y!=null?t.y:f),i=!0,{width:l,height:u,x:d,y:f,top:f,right:d+l,bottom:f+u,left:d}}}}function nz(e){return e!=null&&e.clientX!=null}function rz(e,t={}){let{enabled:n=!0,axis:r=`both`}=t,i=e.useState(`open`),a=e.useState(`floatingElement`),o=e.useState(`domReferenceElement`),s=e.context.dataRef,c=f.useRef(!1),l=f.useRef(null),[u,d]=f.useState(),[p,m]=f.useState([]),h=qI(t=>{e.set(`positionReference`,t)}),g=qI((t,n,i)=>{c.current||(!s.current.openEvent||nz(s.current.openEvent))&&e.set(`positionReference`,tz(i??o,{x:t,y:n,axis:r,dataRef:s,pointerType:u}))}),_=qI(e=>{i?l.current||(g(e.clientX,e.clientY,e.currentTarget),m([])):g(e.clientX,e.clientY,e.currentTarget)}),v=IF(u)?a:i;f.useEffect(()=>{if(!n){h(o);return}if(!v)return;function e(){l.current?.(),l.current=null}let t=wx(a);function r(t){let n=VF(t);zF(a,n)?e():g(t.clientX,t.clientY)}return!s.current.openEvent||nz(s.current.openEvent)?l.current=PI(t,`mousemove`,r):h(o),e},[v,n,a,s,o,e,g,h,p]),f.useEffect(()=>()=>{e.set(`positionReference`,null)},[e]),f.useEffect(()=>{n&&!a&&(c.current=!1)},[n,a]),f.useEffect(()=>{!n&&i&&(c.current=!0)},[n,i]);let y=f.useMemo(()=>{function e(e){d(e.pointerType)}return{onPointerDown:e,onPointerEnter:e,onMouseMove:_,onMouseEnter:_}},[_]);return f.useMemo(()=>n?{reference:y,trigger:y}:{},[n,y])}function iz(){return!1}function az(e){return{escapeKey:typeof e==`boolean`?e:e?.escapeKey??!1,outsidePress:typeof e==`boolean`?e:e?.outsidePress??!0}}function oz(e,t={}){let{enabled:n=!0,escapeKey:r=!0,outsidePress:i=!0,outsidePressEvent:a=`sloppy`,referencePress:o=iz,bubbles:s,externalTree:c}=t,l=e.useState(`open`),u=e.useState(`floatingElement`),{dataRef:d,events:p}=e.context,m=UR(c),h=qI(typeof i==`function`?i:()=>!1),g=typeof i==`function`?h:i,_=g!==!1,v=qI(()=>a),{escapeKey:y,outsidePress:b}=az(s),x=f.useRef(!1),S=f.useRef(!1),C=f.useRef(!1),w=f.useRef(!1),T=f.useRef(!1),E=f.useRef(``),D=f.useRef(null),O=_F(),k=_F(),A=_F(),j=qI(()=>{k.clear(),d.current.insideReactTree=!1}),M=qI(e=>{let t=d.current.floatingContext?.nodeId;return(m?kL(m.nodesRef.current,t):[]).some(t=>t.context?.open&&!t.context.dataRef.current[e])}),N=qI(t=>sI(t,e.select(`floatingElement`))||sI(t,e.select(`domReferenceElement`))),P=qI(t=>{o()&&e.setOpen(!1,yI(xI,t.nativeEvent))}),F=qI(t=>{if(!l||!n||!r||t.key!==`Escape`)return;let i=NF(t)?t.nativeEvent:t;if(T.current||i.isComposing||!y&&M(`__escapeKeyBubbles`))return;let a=yI(DI,i);e.setOpen(!1,a),a.isCanceled||t.preventDefault(),!y&&!a.isPropagationAllowed&&t.stopPropagation()}),I=qI(()=>{d.current.insideReactTree=!0,k.start(0,j)}),L=qI(t=>{if(!l||!n||t.button!==0)return;let r=VF(t.nativeEvent);zF(e.select(`floatingElement`),r)&&(x.current||(x.current=!0,S.current=!1))}),R=qI(e=>{l&&n&&(e.defaultPrevented||e.nativeEvent.defaultPrevented)&&x.current&&(S.current=!0)});f.useEffect(()=>{function e(e){e.open||(w.current=!1)}return p.on(`openchange`,e),()=>{p.off(`openchange`,e)}},[p]),f.useEffect(()=>j,[j]),f.useEffect(()=>{if(!l||!n)return l||(w.current=!1,T.current=!1,E.current=``,D.current=null),j;d.current.__escapeKeyBubbles=y,d.current.__outsidePressBubbles=b;let t=new gF,i=tL(u);function a(){A.clear(),T.current=!0}function o(){T.current=!0,A.start(kF?5:0,()=>{T.current=!1})}function s(){C.current=!0,t.start(0,()=>{C.current=!1})}function c(){x.current=!1,S.current=!1}function f(){let e=E.current,t=e===`pen`||!e?`mouse`:e,n=v(),r=typeof n==`function`?n():n;return typeof r==`string`?r:r[t]}function p(e){let t=f();return t===`intentional`&&e.type!==`click`||t===`sloppy`&&e.type===`click`}function h(e){let t=d.current.floatingContext?.nodeId,n=m&&kL(m.nodesRef.current,t).some(t=>sI(e,t.context?.elements.floating));return N(e)||n}function k(n){if(p(n)){n.type!==`click`&&!N(n)&&(t.clear(),C.current=!1),j();return}if(d.current.insideReactTree){j();return}let r=VF(n),i=`[${jL(`inert`)}]`,a=Dx(r)?r.getRootNode():null,o=Array.from((kx(a)?a:tL(e.select(`floatingElement`))).querySelectorAll(i)),s=e.context.triggerElements;if(r&&(s.hasElement(r)||s.hasMatchingElement(e=>zF(e,r))))return;let c=Dx(r)?r:null;for(;c&&!Bx(c);){let e=Ux(c);if(Bx(e)||!Dx(e))break;c=e}if(!(o.length&&Dx(r)&&!cI(r)&&!zF(r,e.select(`floatingElement`))&&o.every(e=>!zF(c,e)))){if(Ox(r)&&!(`touches`in n)){let e=Bx(r),t=Vx(r),i=/auto|scroll/,a=e||i.test(t.overflowX),o=e||i.test(t.overflowY),s=a&&r.clientWidth>0&&r.scrollWidth>r.clientWidth,c=o&&r.clientHeight>0&&r.scrollHeight>r.clientHeight,l=t.direction===`rtl`,u=c&&(l?n.offsetX<=r.offsetWidth-r.clientWidth:n.offsetX>r.clientWidth),d=s&&n.offsetY>r.clientHeight;if(u||d)return}if(!h(n)){if(f()===`intentional`){if(n.detail!==0&&!PF(n)&&!w.current)return;if(C.current){t.clear(),C.current=!1;return}}typeof g==`function`&&!g(n)||M(`__outsidePressBubbles`)||(e.setOpen(!1,yI(wI,n)),j())}}}function P(t){f()===`sloppy`&&t.pointerType!==`touch`&&e.select(`open`)&&n&&!N(t)&&k(t)}function I(t){if(f()!==`sloppy`||!e.select(`open`)||!n||N(t))return;let r=t.touches[0];r&&(D.current={startTime:Date.now(),startX:r.clientX,startY:r.clientY,dismissOnTouchEnd:!1,dismissOnMouseDown:!0},O.start(1e3,()=>{D.current&&(D.current.dismissOnTouchEnd=!1,D.current.dismissOnMouseDown=!1)}))}function L(e,t){let n=VF(e);if(!n)return;let r=PI(n,e.type,()=>{t(e),r()})}function R(e){E.current=`touch`,L(e,I)}function z(e){O.clear(),e.type===`pointerdown`&&(e.button===0&&(w.current=!0),E.current=e.pointerType),(e.type!==`mousedown`||!D.current||D.current.dismissOnMouseDown)&&L(e,e=>{e.type===`pointerdown`?P(e):k(e)})}function ee(e){if(e.type===`pointercancel`&&(w.current=!1),!x.current)return;let n=S.current;c(),f()===`intentional`&&(e.type===`pointercancel`?n&&s():h(e)||(n?s():(typeof g!=`function`||g(e))&&(t.clear(),C.current=!0,j())))}function te(e){if(f()!==`sloppy`||!D.current||N(e))return;let t=e.touches[0];if(!t)return;let n=Math.abs(t.clientX-D.current.startX),r=Math.abs(t.clientY-D.current.startY),i=Math.sqrt(n*n+r*r);i>5&&(D.current.dismissOnTouchEnd=!0),i>10&&(k(e),O.clear(),D.current=null)}function ne(e){L(e,te)}function B(e){f()===`sloppy`&&D.current&&!N(e)&&(D.current.dismissOnTouchEnd&&k(e),O.clear(),D.current=null)}function re(e){L(e,B)}let ie=FI(r&&FI(PI(i,`keydown`,F),PI(i,`compositionstart`,a),PI(i,`compositionend`,o)),_&&FI(PI(i,`click`,z,!0),PI(i,`pointerdown`,z,!0),PI(i,`pointerup`,ee,!0),PI(i,`pointercancel`,ee,!0),PI(i,`mousedown`,z,!0),PI(i,`mouseup`,ee,!0),PI(i,`touchstart`,R,{capture:!0,passive:!0}),PI(i,`touchmove`,ne,{capture:!0,passive:!0}),PI(i,`touchend`,re,{capture:!0,passive:!0})));return()=>{ie(),t.clear(),c(),C.current=!1}},[d,u,r,_,g,l,n,y,b,F,j,v,M,N,m,e,O,A]);let z=f.useMemo(()=>({onKeyDown:F,onPointerDown:P,onClick:P}),[F,P]),ee=f.useMemo(()=>({onKeyDown:F,onPointerDown:R,onMouseDown:R,onClickCapture:I,onMouseDownCapture(e){I(),L(e)},onPointerDownCapture(e){I(),L(e)},onMouseUpCapture:I,onTouchEndCapture:I,onTouchMoveCapture:I}),[F,I,L,R]);return f.useMemo(()=>n?{reference:z,floating:ee,trigger:z}:{},[n,z,ee])}function sz(e){let{popupStore:t,treatPopupAsFloatingElement:n=!1,floatingRootContext:r,floatingId:i,nested:a,onOpenChange:o}=e,s=t.useState(`open`),c=t.useState(`activeTriggerElement`),l=t.useState(n?`popupElement`:`positionerElement`),u=o;return t.useSyncedValue(`floatingId`,i),lF(()=>{let e={open:s,floatingId:i,referenceElement:c,floatingElement:l};Dx(c)&&(e.domReferenceElement=c),r.state.positionReference===r.state.referenceElement&&(e.positionReference=c),r.update(e)},[s,i,c,l,r]),r.context.onOpenChange=u,r.context.nested=a,r}function cz(e,t=!1,n=!1,r=!1){let[i,a]=f.useState(e&&t?`idle`:void 0),[o,s]=f.useState(e&&!r);return e&&!o&&(s(!0),a(`starting`)),!e&&o&&i!==`ending`&&!n&&a(`ending`),!e&&!o&&i===`ending`&&a(void 0),lF(()=>{if(!e&&o&&i!==`ending`&&n){let e=$I.request(()=>{a(`ending`)});return()=>{$I.cancel(e)}}},[e,o,i,n]),lF(()=>{if(!e||t||i===void 0)return;let n=$I.request(()=>{a(void 0)});return()=>{$I.cancel(n)}},[t,e,i]),lF(()=>{if(!e||!t)return;e&&o&&i!==`idle`&&a(`starting`);let n=$I.request(()=>{a(`idle`)});return()=>{$I.cancel(n)}},[t,e,o,i]),{mounted:o,setMounted:s,transitionStatus:i}}function lz(e,t){return e.getAnimations(t).filter(e=>{let t=e.effect?.getTiming();return t?.duration!==1/0&&t?.iterations!==1/0})}var uz=null;function dz(e){if(!uz){let e=[];uz=e,queueMicrotask(()=>{uz=null,p.flushSync(()=>{for(let t of e)t()})})}uz.push(e)}function fz(e,t=!1,n=!1){let r=eL();return qI((i,a=null)=>{r.cancel();let o=WR(e);if(o==null)return;let s=o,c=()=>{n?dz(()=>{a?.aborted||i()}):p.flushSync(i)};if(typeof s.getAnimations!=`function`||globalThis.BASE_UI_ANIMATIONS_DISABLED){i();return}function l(){Promise.all(lz(s).map(e=>e.finished.then(oF))).then(()=>{a?.aborted||c()},()=>{a?.aborted||(lz(s).some(e=>e.pending||e.playState!==`finished`)?l():c())})}if(t){let e=WF;if(!s.hasAttribute(e)){r.request(l);return}let t=new MutationObserver(()=>{s.hasAttribute(e)||(t.disconnect(),l())});t.observe(s,{attributes:!0,attributeFilter:[e]}),a?.addEventListener(`abort`,()=>t.disconnect(),{once:!0})}else r.request(l)})}function pz(e){let{enabled:t=!0,open:n,ref:r,batch:i=!1,onComplete:a}=e,o=qI(a),s=fz(r,n,i);f.useEffect(()=>{if(!t)return;let e=new AbortController;return s(o,e.signal),()=>{e.abort()}},[t,n,o,s])}function mz(e){let{open:t,ref:n,preventUnmountOnClose:r,setPreventUnmountOnClose:i,onUnmount:a,animateInitialOpen:o}=e,s=qI(i),{mounted:c,setMounted:l,transitionStatus:u}=cz(t,!1,!1,o),d=!t&&r;lF(()=>{t&&s(!1)},[t,s]);let p=f.useRef(c),m=f.useRef(!1),h=GL(),g=()=>{p.current=!1,l(!1),a()};lF(()=>{p.current=c,m.current&&(m.current=!1,!t&&c&&g())});let _=qI(()=>{p.current&&(t?(m.current=!0,h()):g())});return pz({enabled:c&&!t&&!d,open:t,ref:n,onComplete(){t||_()}}),{mounted:c,transitionStatus:u,preventUnmountingOnClose:d,forceUnmount:_}}var hz={tabIndex:-1,[HF]:``};function gz(e){return t=>t!==`touch`||e.current}function _z(e,t=!1){let n=YL(),r=HR()!=null,i=QP(()=>e(n,r)).current;return sz({popupStore:i,treatPopupAsFloatingElement:t,floatingRootContext:i.state.floatingRootContext,floatingId:n,nested:r,onOpenChange:i.setOpen}),i}function vz({handle:e,store:t}){return lF(()=>e.attachStore(t),[e,t]),null}function yz(e){let t=e.context.triggerElements.size;e.select(`open`)&&e.state.triggerCount!==t&&e.set(`triggerCount`,t)}function bz(e,t){let n=f.useRef(null);return qI(r=>{let i=n.current;if(i!==null){if(i.element===r&&i.store===t&&i.id===e)return;n.current=null;let a=i.store;a.context.triggerElements.getById(i.id)===i.element&&(a.context.triggerElements.delete(i.id),yz(a))}r!==null&&e!==void 0&&(n.current={store:t,id:e,element:r},t.context.triggerElements.add(e,r),yz(t))})}function xz(e,t,n,r=!1){let i=e.preventUnmountingOnClose;t?i=!1:r&&(i=!0);let a=n?.id??null,o=e.activeTriggerId,s=e.activeTriggerElement;return(a||t)&&(o=a,s=n??null),{open:t,preventUnmountingOnClose:i,activeTriggerId:o,activeTriggerElement:s,openedWithoutTrigger:t?n==null:e.openedWithoutTrigger}}function Sz(e){let t=!1;return e.preventUnmountOnClose=()=>{t=!0},()=>t}function Cz(e,t,n,r={}){let i=n.reason,a=i===SI,o=t&&i===`trigger-focus`,s=!t&&(i===`trigger-press`||i===`escape-key`),c=Sz(n);if(e.context.onOpenChange?.(t,n),n.isCanceled)return;r.onBeforeDispatch?.(),e.state.floatingRootContext.dispatchOpenChange(t,n);let l=()=>{let i=xz(e.state,t,n.trigger,c()),l={...r.extraState,...i};o?l.instantType=`focus`:s?l.instantType=`dismiss`:a&&(l.instantType=void 0),e.update(l)};a?p.flushSync(l):l()}function wz(e,t,n,r){let i=n.useState(`isMountedByTrigger`,e),a=bz(e,n),o=qI(t=>{let i=n.select(`open`),a=n.select(`activeTriggerId`);if(a===e){let e={activeTriggerElement:t,...i?r:null};n.update(e)}else if(a==null&&i&&!n.state.openedWithoutTrigger){let i={activeTriggerId:e??null,activeTriggerElement:t,...r};n.update(i)}}),s=qI(e=>{a(e),e&&o(e)});return lF(()=>(s(t.current),()=>s(null)),[s,t,n,e]),lF(()=>{if(i){let e={activeTriggerElement:t.current,...r};n.update(e)}},[i,n,t,...Object.values(r)]),{registerTrigger:s,isMountedByThisTrigger:i}}function Tz(e,t={}){let{closeOnActiveTriggerUnmount:n=!1}=t,r=f.useRef(null),i=e.useState(`open`);lF(()=>{if(!i){r.current=null,e.state.triggerCount!==0&&e.set(`triggerCount`,0),e.state.openedWithoutTrigger&&e.set(`openedWithoutTrigger`,!1);return}let t=e.context.triggerElements.size,a={};e.state.triggerCount!==t&&(a.triggerCount=t);let o=e.select(`activeTriggerId`),s=null;if(o){let t=e.context.triggerElements.getById(o);if(t)r.current=o,t!==e.state.activeTriggerElement&&(a.activeTriggerElement=t);else{for(let[t,n]of e.context.triggerElements.entries())if(n===e.state.activeTriggerElement){a.activeTriggerId=t,a.activeTriggerElement=n,r.current=t;break}a.activeTriggerId===void 0&&(r.current===o?s=o:r.current=null)}}else r.current=null;if(!s&&!o&&!e.state.openedWithoutTrigger&&t===1){let t=e.context.triggerElements.entries().next();if(!t.done){let[e,n]=t.value;a.activeTriggerId=e,a.activeTriggerElement=n,r.current=e}}(a.triggerCount!==void 0||a.activeTriggerId!==void 0||a.activeTriggerElement!==void 0)&&e.update(a),s&&n&&queueMicrotask(()=>{if(e.select(`open`)&&e.select(`activeTriggerId`)===s&&!e.context.triggerElements.getById(s)){let t=yI(bI);e.setOpen(!1,t),t.isCanceled||e.update({activeTriggerId:null,activeTriggerElement:null})}})},[i,e,e.useState(`triggerCount`),e.useState(`activeTriggerId`),e.useState(`activeTriggerElement`),n])}function Ez(e,t,n,r){let{mounted:i,transitionStatus:a,forceUnmount:o}=mz({open:e,ref:t.context.popupRef,preventUnmountOnClose:t.useState(`preventUnmountingOnClose`),setPreventUnmountOnClose:e=>t.set(`preventUnmountingOnClose`,e),animateInitialOpen:r,onUnmount(){t.update({activeTriggerId:null,activeTriggerElement:null,mounted:!1,preventUnmountingOnClose:!1}),n?.(),t.context.onOpenChangeComplete?.(!1)}});return QP(()=>(t.set(`mounted`,i),null)),t.useSyncedValues({mounted:i,transitionStatus:a}),{forceUnmount:o,transitionStatus:a}}function Dz(e,t){e.useSyncedValues(t),lF(()=>()=>{e.update({activeTriggerProps:cF,inactiveTriggerProps:cF,popupProps:cF})},[e])}function Oz(e,t){lF(()=>{!t&&e.state.openMethod!==null&&e.set(`openMethod`,null)},[t,e]),lF(()=>()=>{e.state.openMethod!==null&&e.set(`openMethod`,null)},[e])}var kz;function Az(e){kz??=new WeakMap;let t=kz.get(e);return t||(t=new WeakMap,kz.set(e,t)),t}var jz=class{idMap=new Map;add(e,t){if(process.env.NODE_ENV!==`production`){let n=Az(this),r=n.get(t);if(r!==void 0&&r!==e)throw Error(`Base UI: A trigger element cannot be registered under multiple IDs in PopupTriggerMap.`);let i=this.idMap.get(e);i!==void 0&&i!==t&&n.delete(i),n.set(t,e)}this.idMap.set(e,t)}delete(e){if(process.env.NODE_ENV!==`production`){let t=this.idMap.get(e);t!==void 0&&kz?.get(this)?.delete(t)}this.idMap.delete(e)}hasElement(e){for(let t of this.idMap.values())if(t===e)return!0;return!1}hasMatchingElement(e){for(let t of this.idMap.values())if(e(t))return!0;return!1}getById(e){return this.idMap.get(e)}entries(){return this.idMap.entries()}elements(){return this.idMap.values()}get size(){return this.idMap.size}},Mz=o((e=>{var t=require("react");function n(e,t){return e===t&&(e!==0||1/e==1/t)||e!==e&&t!==t}var r=typeof Object.is==`function`?Object.is:n,i=t.useState,a=t.useEffect,o=t.useLayoutEffect,s=t.useDebugValue;function c(e,t){var n=t(),r=i({inst:{value:n,getSnapshot:t}}),c=r[0].inst,u=r[1];return o(function(){c.value=n,c.getSnapshot=t,l(c)&&u({inst:c})},[e,n,t]),a(function(){return l(c)&&u({inst:c}),e(function(){l(c)&&u({inst:c})})},[e]),s(n),n}function l(e){var t=e.getSnapshot;e=e.value;try{var n=t();return!r(e,n)}catch{return!0}}function u(e,t){return t()}var d=typeof window>`u`||window.document===void 0||window.document.createElement===void 0?u:c;e.useSyncExternalStore=t.useSyncExternalStore===void 0?d:t.useSyncExternalStore})),Nz=o((e=>{process.env.NODE_ENV!==`production`&&(function(){function t(e,t){return e===t&&(e!==0||1/e==1/t)||e!==e&&t!==t}function n(e,t){d||a.startTransition===void 0||(d=!0,console.error(`You are using an outdated, pre-release alpha of React 18 that does not support useSyncExternalStore. The use-sync-external-store shim will not work correctly. Upgrade to a newer pre-release.`));var n=t();if(!f){var i=t();o(n,i)||(console.error(`The result of getSnapshot should be cached to avoid an infinite loop`),f=!0)}i=s({inst:{value:n,getSnapshot:t}});var p=i[0].inst,m=i[1];return l(function(){p.value=n,p.getSnapshot=t,r(p)&&m({inst:p})},[e,n,t]),c(function(){return r(p)&&m({inst:p}),e(function(){r(p)&&m({inst:p})})},[e]),u(n),n}function r(e){var t=e.getSnapshot;e=e.value;try{var n=t();return!o(e,n)}catch{return!0}}function i(e,t){return t()}typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<`u`&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart==`function`&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());var a=require("react"),o=typeof Object.is==`function`?Object.is:t,s=a.useState,c=a.useEffect,l=a.useLayoutEffect,u=a.useDebugValue,d=!1,f=!1,p=typeof window>`u`||window.document===void 0||window.document.createElement===void 0?i:n;e.useSyncExternalStore=a.useSyncExternalStore===void 0?p:a.useSyncExternalStore,typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<`u`&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop==`function`&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error())})()})),Pz=o(((e,t)=>{t.exports=process.env.NODE_ENV===`production`?Mz():Nz()})),Fz=o((e=>{var t=require("react"),n=Pz();function r(e,t){return e===t&&(e!==0||1/e==1/t)||e!==e&&t!==t}var i=typeof Object.is==`function`?Object.is:r,a=n.useSyncExternalStore,o=t.useRef,s=t.useEffect,c=t.useMemo,l=t.useDebugValue;e.useSyncExternalStoreWithSelector=function(e,t,n,r,u){var d=o(null);if(d.current===null){var f={hasValue:!1,value:null};d.current=f}else f=d.current;d=c(function(){function e(e){if(!a){if(a=!0,o=e,e=r(e),u!==void 0&&f.hasValue){var t=f.value;if(u(t,e))return s=t}return s=e}if(t=s,i(o,e))return t;var n=r(e);return u!==void 0&&u(t,n)?(o=e,t):(o=e,s=n)}var a=!1,o,s,c=n===void 0?null:n;return[function(){return e(t())},c===null?void 0:function(){return e(c())}]},[t,n,r,u]);var p=a(e,d[0],d[1]);return s(function(){f.hasValue=!0,f.value=p},[p]),l(p),p}})),Iz=o((e=>{process.env.NODE_ENV!==`production`&&(function(){function t(e,t){return e===t&&(e!==0||1/e==1/t)||e!==e&&t!==t}typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<`u`&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart==`function`&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());var n=require("react"),r=Pz(),i=typeof Object.is==`function`?Object.is:t,a=r.useSyncExternalStore,o=n.useRef,s=n.useEffect,c=n.useMemo,l=n.useDebugValue;e.useSyncExternalStoreWithSelector=function(e,t,n,r,u){var d=o(null);if(d.current===null){var f={hasValue:!1,value:null};d.current=f}else f=d.current;d=c(function(){function e(e){if(!a){if(a=!0,o=e,e=r(e),u!==void 0&&f.hasValue){var t=f.value;if(u(t,e))return s=t}return s=e}if(t=s,i(o,e))return t;var n=r(e);return u!==void 0&&u(t,n)?(o=e,t):(o=e,s=n)}var a=!1,o,s,c=n===void 0?null:n;return[function(){return e(t())},c===null?void 0:function(){return e(c())}]},[t,n,r,u]);var p=a(e,d[0],d[1]);return s(function(){f.hasValue=!0,f.value=p},[p]),l(p),p},typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<`u`&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop==`function`&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error())})()})),Lz=o(((e,t)=>{t.exports=process.env.NODE_ENV===`production`?Fz():Iz()})),Rz=Pz(),zz=Lz(),Bz=ZL(19)?Uz:Wz;function Vz(e,t,n,r,i){return Bz(e,t,n,r,i)}function Hz(e,t,n,r,i){let a=f.useCallback(()=>t(e.getSnapshot(),n,r,i),[e,t,n,r,i]);return(0,Rz.useSyncExternalStore)(e.subscribe,a,a)}nF({before(e){e.syncIndex=0,e.didInitialize||(e.syncTick=1,e.syncHooks=[],e.didChangeStore=!0,e.getSnapshot=()=>{let t=!1;for(let n=0;n<e.syncHooks.length;n+=1){let r=e.syncHooks[n],i=r.selector(r.store.state,r.a1,r.a2,r.a3);Object.is(r.value,i)||(t=!0,r.value=i)}return t&&(e.syncTick+=1),e.syncTick})},after(e){e.syncHooks.length>0&&(e.didChangeStore&&(e.didChangeStore=!1,e.subscribe=t=>{let n=new Set;for(let t of e.syncHooks)n.add(t.store);let r=[];for(let e of n)r.push(e.subscribe(t));return()=>{for(let e of r)e()}}),(0,Rz.useSyncExternalStore)(e.subscribe,e.getSnapshot,e.getSnapshot))}});function Uz(e,t,n,r,i){let a=tF();if(!a)return Hz(e,t,n,r,i);let o=a.syncIndex;a.syncIndex+=1;let s;return a.didInitialize?(s=a.syncHooks[o],s.store===e&&s.selector===t&&Object.is(s.a1,n)&&Object.is(s.a2,r)&&Object.is(s.a3,i)||(s.store!==e&&(a.didChangeStore=!0),s.store=e,s.selector=t,s.a1=n,s.a2=r,s.a3=i,s.value=t(e.getSnapshot(),n,r,i))):(s={store:e,selector:t,a1:n,a2:r,a3:i,value:t(e.getSnapshot(),n,r,i)},a.syncHooks.push(s)),s.value}function Wz(e,t,n,r,i){return(0,zz.useSyncExternalStoreWithSelector)(e.subscribe,e.getSnapshot,e.getSnapshot,e=>t(e,n,r,i))}var Gz=class{static create(e){return new this(e)}constructor(e){this.state=e,this.listeners=new Set,this.updateTick=0}subscribe=e=>(this.listeners.add(e),()=>{this.listeners.delete(e)});getSnapshot=()=>this.state;setState(e){if(this.state===e)return;this.state=e,this.updateTick+=1;let t=this.updateTick;for(let n of this.listeners){if(t!==this.updateTick)return;n(e)}}update(e){for(let t in e)if(!Object.is(this.state[t],e[t])){this.setState({...this.state,...e});return}}set(e,t){Object.is(this.state[e],t)||this.setState({...this.state,[e]:t})}notifyAll(){let e={...this.state};this.setState(e)}use(e,t,n,r){return Vz(this,e,t,n,r)}},Kz=class extends Gz{constructor(e,t={},n){super(e),this.context=t,this.selectors=n}useSyncedValue(e,t){f.useDebugValue(e);let n=this;lF(()=>{n.state[e]!==t&&n.set(e,t)},[n,e,t])}useSyncedValueWithCleanup(e,t){let n=this;lF(()=>(n.state[e]!==t&&n.set(e,t),()=>{n.set(e,void 0)}),[n,e,t])}useSyncedValues(e){let t=this;if(process.env.NODE_ENV!==`production`){f.useDebugValue(e,e=>Object.keys(e));let t=f.useRef(Object.keys(e)).current,n=Object.keys(e);(t.length!==n.length||t.some((e,t)=>e!==n[t]))&&console.error(`ReactStore.useSyncedValues expects the same prop keys on every render. Keys should be stable.`)}lF(()=>{t.update(e)},[t,...Object.values(e)])}useControlledProp(e,t){f.useDebugValue(e);let n=this,r=t!==void 0;if(lF(()=>{r&&!Object.is(n.state[e],t)&&n.setState({...n.state,[e]:t})},[n,e,t,r]),process.env.NODE_ENV!==`production`){let t=this.controlledValues??=new Map;t.has(e)||t.set(e,r);let n=t.get(e);n!==void 0&&n!==r&&console.error(`A component is changing the ${n?``:`un`}controlled state of ${e.toString()} to be ${n?`un`:``}controlled. Elements should not switch from uncontrolled to controlled (or vice versa).`)}}select(e,t,n,r){let i=this.selectors[e];return i(this.state,t,n,r)}useState(e,t,n,r){return f.useDebugValue(e),Vz(this,this.selectors[e],t,n,r)}useContextCallback(e,t){f.useDebugValue(e);let n=qI(t??oF);this.context[e]=n}useStateSetter(e){let t=f.useRef(void 0);return t.current===void 0&&(t.current=t=>{this.set(e,t)}),t.current}observe(e,t){let n;n=typeof e==`function`?e:this.selectors[e];let r=n(this.state);return t(r,r,this),this.subscribe(e=>{let i=n(e);if(!Object.is(r,i)){let e=r;r=i,t(i,e,this)}})}},qz={open:e=>e.open,transitionStatus:e=>e.transitionStatus,domReferenceElement:e=>e.domReferenceElement,referenceElement:e=>e.positionReference??e.referenceElement,floatingElement:e=>e.floatingElement,floatingId:e=>e.floatingId},Jz=class extends Kz{constructor(e){let{syncOnly:t,nested:n,onOpenChange:r,triggerElements:i,...a}=e;super({...a,positionReference:a.referenceElement,domReferenceElement:a.referenceElement},{onOpenChange:r,dataRef:{current:{}},events:zR(),nested:n,triggerElements:i},qz),this.syncOnly=t}syncOpenEvent=(e,t)=>{(!e||!this.state.open||t!=null&&LF(t))&&(this.context.dataRef.current.openEvent=e?t:void 0)};dispatchOpenChange=(e,t)=>{this.syncOpenEvent(e,t.event);let n={open:e,reason:t.reason,nativeEvent:t.event,nested:this.context.nested,triggerElement:t.trigger};this.context.events.emit(`openchange`,n)};setOpen=(e,t)=>{this.syncOnly||this.dispatchOpenChange(e,t),this.context.onOpenChange?.(e,t)}};function Yz(e,t,n=!1){return{open:!1,openProp:void 0,mounted:!1,transitionStatus:void 0,floatingRootContext:new Jz({open:!1,transitionStatus:void 0,floatingElement:null,referenceElement:null,triggerElements:e,floatingId:t,syncOnly:!0,nested:n,onOpenChange:void 0}),floatingId:t,triggerCount:0,preventUnmountingOnClose:!1,payload:void 0,activeTriggerId:null,activeTriggerElement:null,openedWithoutTrigger:!1,triggerIdProp:void 0,popupElement:null,positionerElement:null,activeTriggerProps:cF,inactiveTriggerProps:cF,popupProps:cF}}var Xz=e=>e.triggerIdProp??e.activeTriggerId,Zz=e=>e.openProp??e.open,Qz=e=>(e.popupElement?.id??e.floatingId)||void 0;function $z(e,t){return t!==void 0&&Zz(e)&&Xz(e)===t}function eB(e,t){return $z(e,t)?!0:t!==void 0&&Zz(e)&&Xz(e)==null&&!e.openedWithoutTrigger&&e.triggerCount===1}var tB={open:Zz,mounted:e=>e.mounted,transitionStatus:e=>Zz(e)&&!e.mounted?`starting`:e.transitionStatus,floatingRootContext:e=>e.floatingRootContext,triggerCount:e=>e.triggerCount,preventUnmountingOnClose:e=>e.preventUnmountingOnClose,payload:e=>e.payload,activeTriggerId:Xz,activeTriggerElement:e=>e.mounted?e.activeTriggerElement:null,popupId:Qz,isTriggerActive:(e,t)=>t!==void 0&&Xz(e)===t,isOpenedByTrigger:(e,t)=>$z(e,t),isMountedByTrigger:(e,t)=>t!==void 0&&Xz(e)===t&&e.mounted,triggerProps:(e,t)=>t?e.activeTriggerProps:e.inactiveTriggerProps,triggerPopupId:(e,t)=>eB(e,t)?Qz(e):void 0,popupProps:e=>e.popupProps,popupElement:e=>e.popupElement,positionerElement:e=>e.positionerElement};function nB(e){let t=f.useCallback(t=>e===void 0?oF:e.subscribeStore(t),[e]),n=f.useCallback(()=>e===void 0?void 0:e.store,[e]);return(0,Rz.useSyncExternalStore)(t,n,()=>e?.serverStore)}var rB=DF&&kF;function iB(e,t={}){let{enabled:n=!0,delay:r}=t,{events:i,dataRef:a}=e.context,o=f.useRef(!1),s=f.useRef(null),c=f.useRef(!0),l=_F();f.useEffect(()=>{let t=e.select(`domReferenceElement`);if(!n)return;let r=wx(t);function i(){let t=e.select(`domReferenceElement`);!e.select(`open`)&&Ox(t)&&t===RF(tL(t))&&(o.current=!0,s.current=t)}function a(){c.current=!0}function l(){c.current=!1}return FI(PI(r,`blur`,i),rB&&PI(r,`keydown`,a,!0),rB&&PI(r,`pointerdown`,l,!0))},[e,n]),f.useEffect(()=>{if(!n)return;function t(t){if(t.reason===`trigger-press`||t.reason===`escape-key`){let t=e.select(`domReferenceElement`);Dx(t)&&(s.current=t,o.current=!0)}}return i.on(`openchange`,t),()=>{i.off(`openchange`,t)}},[i,n,e]);let u=f.useMemo(()=>{function t(){o.current=!1,s.current=null}return{onMouseLeave(){t()},onFocus(n){let i=n.currentTarget;if(o.current){if(s.current===i)return;t()}let a=VF(n.nativeEvent);if(Dx(a)){if(rB&&!n.relatedTarget){if(!c.current&&!lI(a))return}else if(!fI(a))return}let u=oI(n.relatedTarget,e.context.triggerElements),{nativeEvent:d,currentTarget:f}=n;e.select(`open`)&&u||!r?e.setOpen(!0,yI(CI,d,f)):l.start(r,()=>{o.current||e.setOpen(!0,yI(CI,d,f))})},onBlur(n){t();let r=n.relatedTarget,i=n.nativeEvent,o=Dx(r)&&r.hasAttribute(jL(`focus-guard`))&&r.getAttribute(`data-type`)===`outside`;l.start(0,()=>{let t=e.select(`domReferenceElement`),n=RF(tL(t));!r&&n===t||zF(a.current.floatingContext?.refs.floating.current,n)||zF(t,n)||o||oI(r??n,e.context.triggerElements)||e.setOpen(!1,yI(CI,i))})}}},[a,r,e,l]);return f.useMemo(()=>n?{reference:u,trigger:u}:{},[n,u])}var aB=class e{pointerType=void 0;interactedInside=!1;handler=void 0;blockMouseMove=!0;performedPointerEventsMutation=!1;pointerEventsScopeElement=null;pointerEventsReferenceElement=null;pointerEventsFloatingElement=null;restTimeoutPending=!1;openChangeTimeout=new gF;restTimeout=new gF;handleCloseOptions=void 0;static create(){return new e}dispose=()=>{this.openChangeTimeout.clear(),this.restTimeout.clear()};disposeEffect=()=>this.dispose},oB=new WeakMap;function sB(e){if(!e.performedPointerEventsMutation)return;let t=e.pointerEventsScopeElement;t&&oB.get(t)===e&&(e.pointerEventsScopeElement?.style.removeProperty(`pointer-events`),e.pointerEventsReferenceElement?.style.removeProperty(`pointer-events`),e.pointerEventsFloatingElement?.style.removeProperty(`pointer-events`),oB.delete(t)),e.performedPointerEventsMutation=!1,e.pointerEventsScopeElement=null,e.pointerEventsReferenceElement=null,e.pointerEventsFloatingElement=null}function cB(e,t){let{scopeElement:n,referenceElement:r,floatingElement:i}=t,a=oB.get(n);a&&a!==e&&sB(a),sB(e),e.performedPointerEventsMutation=!0,e.pointerEventsScopeElement=n,e.pointerEventsReferenceElement=r,e.pointerEventsFloatingElement=i,oB.set(n,e),n.style.pointerEvents=`none`,r.style.pointerEvents=`auto`,i.style.pointerEvents=`auto`}function lB(e){let t=e.context.dataRef.current,n=QP(()=>t.hoverInteractionState??aB.create()).current;return t.hoverInteractionState||=n,mF(t.hoverInteractionState.disposeEffect),t.hoverInteractionState}function uB(e,t={}){let{enabled:n=!0,closeDelay:r=0,nodeId:i}=t,a=e.useState(`open`),o=e.useState(`floatingElement`),s=e.useState(`domReferenceElement`),{dataRef:c}=e.context,l=UR(),u=HR(),d=lB(e),p=_F(),m=qI(()=>_I(c.current.openEvent?.type,d.interactedInside)),h=qI(()=>vI(c.current.openEvent?.type)),g=qI(()=>{sB(d)});lF(()=>{a||(d.pointerType=void 0,d.restTimeoutPending=!1,d.interactedInside=!1,g())},[a,d,g]),f.useEffect(()=>g,[g]),lF(()=>{if(n&&a&&d.handleCloseOptions?.blockPointerEvents&&h()&&Dx(s)&&o){let e=s,t=o,n=tL(o),r=l?.nodesRef.current.find(e=>e.id===u)?.context?.elements.floating;r&&(r.style.pointerEvents=``);let i=d.pointerEventsScopeElement===t?null:d.pointerEventsScopeElement,a=r===t?null:r,c=d.handleCloseOptions?.getScope?.()??i??a??BF(e,`[data-rootownerid]`)??n.body;return cB(d,{scopeElement:c,referenceElement:e,floatingElement:t}),()=>{g()}}},[n,a,s,o,d,h,l,u,g]),f.useEffect(()=>{if(!n)return;function t(){return!!(l&&u&&kL(l.nodesRef.current,u).length>0)}function a(t){let n=hI(r,`close`,d.pointerType),i=()=>{e.setOpen(!1,yI(SI,t)),l?.events.emit(`floating.closed`,t)};n?d.openChangeTimeout.start(n,i):(d.openChangeTimeout.clear(),i())}function s(e){let t=VF(e);uI(t)?d.interactedInside=BF(t,`[aria-haspopup]`)!=null:d.interactedInside=!1}function f(){d.openChangeTimeout.clear(),p.clear(),l?.events.off(`floating.closed`,v),g()}function _(n){if(t()&&l){l.events.on(`floating.closed`,v);return}if(oI(n.relatedTarget,e.context.triggerElements))return;let r=c.current.floatingContext?.nodeId??i,o=n.relatedTarget;l&&r&&Dx(o)&&kL(l.nodesRef.current,r,!1).some(e=>zF(e.context?.elements.floating,o))||(d.handler?d.handler(n):(g(),h()&&!m()&&a(n)))}function v(n){l&&u&&!t()&&p.start(0,()=>{l.events.off(`floating.closed`,v),e.setOpen(!1,yI(SI,n)),l.events.emit(`floating.closed`,n)})}let y=o;return FI(y&&PI(y,`mouseenter`,f),y&&PI(y,`mouseleave`,_),y&&PI(y,`pointerdown`,s,!0),()=>{l?.events.off(`floating.closed`,v)})},[n,o,e,c,r,i,h,m,g,d,l,u,p])}var dB={current:null};function fB(e,t={}){let{enabled:n=!0,delay:r=0,handleClose:i=null,mouseOnly:a=!1,restMs:o=0,move:s=!0,triggerElementRef:c=dB,externalTree:l,isActiveTrigger:u=!0,getHandleCloseContext:d,isClosing:m,shouldOpen:h,guardStaleOpen:g=!1}=t,{dataRef:_,events:v}=e.context,y=UR(l),b=lB(e),x=f.useRef(!1),S=HI(i),C=HI(r),w=HI(o),T=HI(n),E=HI(h),D=HI(m),O=qI(()=>_I(_.current.openEvent?.type,b.interactedInside)),k=qI(()=>E.current?.()!==!1),A=qI((t,n,r)=>{let i=e.context.triggerElements;if(i.hasElement(n))return!t||!zF(t,n);if(!Dx(r))return!1;let a=r;return i.hasMatchingElement(e=>zF(e,a))&&(!t||!zF(t,a))}),j=qI(()=>{b.handler&&=(tL(e.select(`domReferenceElement`)).removeEventListener(`mousemove`,b.handler),void 0)}),M=qI(()=>{sB(b)});return u&&(b.handleCloseOptions=i?.__options),f.useEffect(()=>j,[j]),f.useEffect(()=>{if(!n)return;function e(e){e.open?x.current=!1:(x.current=e.reason===SI,j(),b.openChangeTimeout.clear(),b.restTimeout.clear(),b.blockMouseMove=!0,b.restTimeoutPending=!1)}return v.on(`openchange`,e),()=>{v.off(`openchange`,e)}},[n,v,b,j]),f.useEffect(()=>{if(!n)return;function t(t,n=!0){let r=hI(C.current,`close`,b.pointerType);r?b.openChangeTimeout.start(r,()=>{e.setOpen(!1,yI(SI,t)),y?.events.emit(`floating.closed`,t)}):n&&(b.openChangeTimeout.clear(),e.setOpen(!1,yI(SI,t)),y?.events.emit(`floating.closed`,t))}let r=c.current??(u?e.select(`domReferenceElement`):null);if(!Dx(r))return;function i(t){if(b.openChangeTimeout.clear(),b.blockMouseMove=!1,a&&!IF(b.pointerType))return;let n=gI(w.current),r=hI(C.current,`open`,b.pointerType),i=VF(t),o=t.currentTarget??null,s=e.select(`domReferenceElement`),c=o;if(Dx(i)&&!e.context.triggerElements.hasElement(i)){for(let t of e.context.triggerElements.elements())if(zF(t,i)){c=t;break}}Dx(o)&&Dx(s)&&!e.context.triggerElements.hasElement(o)&&zF(o,s)&&(c=s);let l=c!=null&&A(s,c,i),u=e.select(`open`),d=D.current?.()??e.select(`transitionStatus`)===`ending`,f=!u&&d&&x.current,p=!l&&Dx(c)&&Dx(s)&&zF(s,c)&&f,m=n>0&&!r,h=l&&(u||f)||p,g=!u||l;h?k()&&e.setOpen(!0,yI(SI,t,c)):m||(r?b.openChangeTimeout.start(r,()=>{g&&k()&&e.setOpen(!0,yI(SI,t,c))}):g&&k()&&e.setOpen(!0,yI(SI,t,c)))}function o(n){if(O()){M();return}j();let r=tL(e.select(`domReferenceElement`));b.restTimeout.clear(),b.restTimeoutPending=!1;let i=_.current.floatingContext??d?.();if(!oI(n.relatedTarget,e.context.triggerElements)){if(S.current&&i){e.select(`open`)||b.openChangeTimeout.clear();let a=c.current;b.handler=S.current({...i,tree:y,x:n.clientX,y:n.clientY,onClose(){M(),j(),T.current&&!O()&&a===e.select(`domReferenceElement`)&&t(n,!0)}}),r.addEventListener(`mousemove`,b.handler),b.handler(n)}else b.pointerType===`touch`&&zF(e.select(`floatingElement`),n.relatedTarget)||t(n)}}function l(e){zF(r,e.relatedTarget)||(b.openChangeTimeout.clear(),b.restTimeout.clear(),b.restTimeoutPending=!1)}let f=g?PI(r,`mouseout`,l):void 0;return s?FI(PI(r,`mousemove`,i,{once:!0}),PI(r,`mouseenter`,i),PI(r,`mouseleave`,o),f):FI(PI(r,`mouseenter`,i),PI(r,`mouseleave`,o),f)},[j,M,_,C,e,n,S,b,u,A,O,a,s,w,c,y,T,d,D,k,g]),f.useMemo(()=>{if(!n)return;function t(e){b.pointerType=e.pointerType}return{onPointerDown:t,onPointerEnter:t,onMouseMove(t){let{nativeEvent:n}=t,r=t.currentTarget,i=e.select(`domReferenceElement`),o=e.select(`open`),s=A(i,r,t.target);if(a&&!IF(b.pointerType))return;if(o&&s&&b.handleCloseOptions?.blockPointerEvents){let t=e.select(`floatingElement`);if(t){let e=b.handleCloseOptions?.getScope?.()??r.ownerDocument.body;cB(b,{scopeElement:e,referenceElement:r,floatingElement:t})}}let c=gI(w.current);if(o&&!s||c===0||!s&&b.restTimeoutPending&&t.movementX**2+t.movementY**2<2)return;b.restTimeout.clear();function l(){if(b.restTimeoutPending=!1,O())return;let t=e.select(`open`);!b.blockMouseMove&&(!t||s)&&k()&&e.setOpen(!0,yI(SI,n,r))}b.pointerType===`touch`?p.flushSync(()=>{l()}):s&&o?l():(b.restTimeoutPending=!0,b.restTimeout.start(c,l))}}},[n,b,O,A,a,e,w,k])}var pB=.1,mB=pB*pB,hB=.5;function gB(e,t,n,r,i,a){return r>=t!=a>=t&&e<=(i-n)*(t-r)/(a-r)+n}function _B(e,t,n,r,i,a,o,s,c,l){let u=!1;return gB(e,t,n,r,i,a)&&(u=!u),gB(e,t,i,a,o,s)&&(u=!u),gB(e,t,o,s,c,l)&&(u=!u),gB(e,t,c,l,n,r)&&(u=!u),u}function vB(e,t,n){return e>=n.x&&e<=n.x+n.width&&t>=n.y&&t<=n.y+n.height}function yB(e,t,n,r,i,a){return e>=Math.min(n,i)&&e<=Math.max(n,i)&&t>=Math.min(r,a)&&t<=Math.max(r,a)}function bB(e={}){let{blockPointerEvents:t=!1}=e,n=new gF,r=({x:e,y:t,placement:r,elements:i,onClose:a,nodeId:o,tree:s})=>{let c=r?.split(`-`)[0],l=!1,u=null,d=null,f=typeof performance<`u`?performance.now():0;function p(e,t){let n=performance.now(),r=n-f;if(u===null||d===null||r===0)return u=e,d=t,f=n,!1;let i=e-u,a=t-d,o=i*i+a*a,s=r*r*mB;return u=e,d=t,f=n,o<s}function m(){n.clear(),a()}return function(r){n.clear();let a=i.domReference,u=i.floating;if(!a||!u||c==null||e==null||t==null)return;let{clientX:d,clientY:f}=r,h=VF(r),g=r.type===`mouseleave`,_=zF(u,h),v=zF(a,h);if(_&&(l=!0,!g))return;if(v&&(l=!1,!g)){l=!0;return}if(g&&Dx(r.relatedTarget)&&zF(u,r.relatedTarget))return;function y(){return!!(s&&kL(s.nodesRef.current,o).length>0)}function b(){y()||m()}if(y())return;let x=a.getBoundingClientRect(),S=u.getBoundingClientRect(),C=e>S.right-S.width/2,w=t>S.bottom-S.height/2,T=S.width>x.width,E=S.height>x.height,D=(T?x:S).left,O=(T?x:S).right,k=(E?x:S).top,A=(E?x:S).bottom;if(c===`top`&&t>=x.bottom-1||c===`bottom`&&t<=x.top+1||c===`left`&&e>=x.right-1||c===`right`&&e<=x.left+1){b();return}let j=!1;switch(c){case`top`:j=yB(d,f,D,x.top+1,O,S.bottom-1);break;case`bottom`:j=yB(d,f,D,S.top+1,O,x.bottom-1);break;case`left`:j=yB(d,f,S.right-1,A,x.left+1,k);break;case`right`:j=yB(d,f,x.right-1,A,S.left+1,k)}if(j)return;if(l&&!vB(d,f,x)||!g&&p(d,f)){b();return}let M=!1;switch(c){case`top`:{let n=T?hB/2:hB*4,r=T||C?e+n:e-n,i=T?e-n:C?e+n:e-n,a=t+hB+1,o=C||T?S.bottom-hB:S.top,s=C?T?S.bottom-hB:S.top:S.bottom-hB;M=_B(d,f,r,a,i,a,S.left,o,S.right,s);break}case`bottom`:{let n=T?hB/2:hB*4,r=T||C?e+n:e-n,i=T?e-n:C?e+n:e-n,a=t-hB,o=C||T?S.top+hB:S.bottom,s=C?T?S.top+hB:S.bottom:S.top+hB;M=_B(d,f,r,a,i,a,S.left,o,S.right,s);break}case`left`:{let n=E?hB/2:hB*4,r=E||w?t+n:t-n,i=E?t-n:w?t+n:t-n,a=e+hB+1,o=w||E?S.right-hB:S.left,s=w?E?S.right-hB:S.left:S.right-hB;M=_B(d,f,o,S.top,s,S.bottom,a,r,a,i);break}case`right`:{let n=E?hB/2:hB*4,r=E||w?t+n:t-n,i=E?t-n:w?t+n:t-n,a=e-hB,o=w||E?S.left+hB:S.right,s=w?E?S.left+hB:S.right:S.left+hB;M=_B(d,f,a,r,a,i,o,S.top,s,S.bottom);break}}M?l||n.start(40,b):b()}};return r.__options={...e,blockPointerEvents:t},r}var xB={...tB,disabled:e=>e.disabled,instantType:e=>e.instantType,isInstantPhase:e=>e.isInstantPhase,trackCursorAxis:e=>e.trackCursorAxis,disableHoverablePopup:e=>e.disableHoverablePopup,lastOpenChangeReason:e=>e.openChangeReason,closeOnClick:e=>e.closeOnClick,appliedTriggerProps:(e,t)=>t?e.activeTriggerProps:void 0,closeDelay:e=>e.closeDelay,adaptiveOrigin:e=>e.adaptiveOrigin},SB=class extends Kz{constructor(e,t,n){let r=new jz;super(CB(e,r,t,n),wB(r),xB)}setOpen=(e,t)=>{Cz(this,e,t,{extraState:{openChangeReason:t.reason}})};cancelPendingOpen(e){this.state.floatingRootContext.dispatchOpenChange(!1,yI(xI,e))}};function CB(e,t,n,r=!1){return{...Yz(t,n,r),disabled:!1,instantType:void 0,isInstantPhase:!1,trackCursorAxis:`none`,disableHoverablePopup:!1,openChangeReason:null,closeOnClick:!0,closeDelay:0,adaptiveOrigin:void 0,...e}}function wB(e){return{popupRef:f.createRef(),onOpenChange:void 0,onOpenChangeComplete:void 0,triggerElements:e}}var TB=rF(function(e){let{disabled:t=!1,defaultOpen:n=!1,open:r,disableHoverablePopup:i=!1,trackCursorAxis:a=`none`,actionsRef:o,onOpenChange:s,onOpenChangeComplete:c,handle:l,triggerId:u,defaultTriggerId:d=null,children:p}=e,m=_z((e,t)=>new SB({open:n,openProp:r,activeTriggerId:d,triggerIdProp:u},e,t));m.useControlledProp(`openProp`,r),m.useControlledProp(`triggerIdProp`,u),m.useContextCallback(`onOpenChange`,s),m.useContextCallback(`onOpenChangeComplete`,c);let h=m.useState(`open`),g=!t&&h,_=m.useState(`activeTriggerId`),v=m.useState(`mounted`),y=m.useState(`payload`);m.useSyncedValues({trackCursorAxis:a,disableHoverablePopup:i,disabled:t}),Tz(m,{closeOnActiveTriggerUnmount:!0});let{forceUnmount:b,transitionStatus:x}=Ez(g,m),S=m.useState(`isInstantPhase`),C=m.useState(`instantType`),w=m.useState(`lastOpenChangeReason`),T=f.useRef(null);lF(()=>{h&&t&&m.setOpen(!1,yI(OI))},[h,t,m]),lF(()=>{x===`ending`&&w===`none`||x!==`ending`&&S?(C!==`delay`&&(T.current=C),m.set(`instantType`,`delay`)):T.current!==null&&(m.set(`instantType`,T.current),T.current=null)},[x,S,w,C,m]),lF(()=>{g&&(_??m.set(`payload`,void 0))},[m,_,g]),f.useImperativeHandle(o,()=>({unmount:b,close:()=>m.setOpen(!1,yI(kI))}),[b,m]);let E=g||v||!t&&a!==`none`;return(0,J.jsxs)(fF.Provider,{value:m,children:[l&&(0,J.jsx)(vz,{handle:l,store:m}),E&&(0,J.jsx)(EB,{store:m,disabled:t,trackCursorAxis:a}),typeof p==`function`?p({payload:y}):p]})});process.env.NODE_ENV!==`production`&&(TB.displayName=`TooltipRoot`);function EB({store:e,disabled:t,trackCursorAxis:n}){let r=e.useState(`floatingRootContext`),i=oz(r,{enabled:!t,referencePress:()=>e.select(`closeOnClick`)}),a=rz(r,{enabled:!t&&n!==`none`,axis:n===`none`?void 0:n}),o=f.useMemo(()=>sR(a.reference,i.reference),[a.reference,i.reference]);return Dz(e,{activeTriggerProps:o,inactiveTriggerProps:o,popupProps:i.floating??cF}),null}function DB(e){return YL(e,`base-ui`)}var OB=f.createContext(void 0);process.env.NODE_ENV!==`production`&&(OB.displayName=`TooltipProviderContext`);function kB(){return f.useContext(OB)}var AB=`data-base-ui-tooltip-trigger`;function jB(e){let t=VF(e);return Dx(t)?t:null}var MB=iF(function(e,t){let{render:n,className:r,style:i,handle:a,payload:o,disabled:s,delay:c,closeOnClick:l=!0,closeDelay:u,id:d,...p}=e,m=pF(!0),h=nB(a)??m;if(!h)throw Error(process.env.NODE_ENV===`production`?dF(82):`Base UI: <Tooltip.Trigger> must be either used within a <Tooltip.Root> component or provided with a handle.`);let g=DB(d),_=h.useState(`isTriggerActive`,g),v=h.useState(`isOpenedByTrigger`,g),y=h.useState(`floatingRootContext`),b=f.useRef(null),x=u??0,{registerTrigger:S,isMountedByThisTrigger:C}=wz(g,b,h,{payload:o,closeOnClick:l,closeDelay:x}),w=kB(),{activeIdRef:T,delayRef:E,isInstantPhase:D,hasProvider:O}=NI(y,{open:v}),k=lB(y);h.useSyncedValue(`isInstantPhase`,D);let A=h.useState(`disabled`),j=s??A,M=HI(j),N=h.useState(`trackCursorAxis`),P=h.useState(`disableHoverablePopup`),F=f.useRef(!1),I=_F(),L=f.useRef(void 0);function R(){return O&&T.current!=null?0:c??w??600}function z(e){let t=b.current;if(!t||!e)return!1;let n=BF(e,`[${AB}]`);return n!==null&&n!==t&&zF(t,n)}function ee(e){let t=z(e);return F.current=t,t&&(k.openChangeTimeout.clear(),k.restTimeout.clear(),k.restTimeoutPending=!1,I.clear()),t}let te=fB(y,{enabled:!j,mouseOnly:!0,move:!1,handleClose:!P&&N!==`both`?bB():null,restMs:R,delay(){return u==null&&O?{close:hI(E.current,`close`)}:{close:x}},triggerElementRef:b,isActiveTrigger:_,isClosing:()=>h.select(`transitionStatus`)===`ending`,shouldOpen(){return!F.current}}),ne=iB(y,{enabled:!j}).reference,B=e=>{let t=F.current,n=jB(e),r=ee(n),i=b.current,a=i&&n&&zF(i,n);if(r&&h.select(`open`)&&h.select(`lastOpenChangeReason`)===`trigger-hover`)h.setOpen(!1,yI(SI,e));else if(t&&!r&&a&&!M.current&&!h.select(`open`)&&i&&IF(L.current)){let t=()=>{F.current||M.current||h.select(`open`)||h.setOpen(!0,yI(SI,e,i))},n=R();n===0?(I.clear(),t()):I.start(n,t)}},re=h.useState(`appliedTriggerProps`,C||N!==`none`);return bR(`button`,e,{state:{open:v},ref:[t,S,b],props:[te,ne,re,{onMouseOver(e){B(e.nativeEvent)},onFocus(e){z(jB(e.nativeEvent))&&e.preventBaseUIHandler()},onMouseLeave(){F.current=!1,I.clear(),L.current=void 0},onPointerEnter(e){L.current=e.pointerType},onPointerDown(e){L.current=e.pointerType,h.set(`closeOnClick`,l),l&&!h.select(`open`)&&h.cancelPendingOpen(e.nativeEvent)},onClick(e){l&&!h.select(`open`)&&h.cancelPendingOpen(e.nativeEvent)},id:g,[aI]:j?``:void 0,[AB]:j?void 0:``},p],stateAttributesMapping:nI})});process.env.NODE_ENV!==`production`&&(MB.displayName=`TooltipTrigger`);var NB=f.createContext(void 0);process.env.NODE_ENV!==`production`&&(NB.displayName=`TooltipPortalContext`);function PB(){let e=f.useContext(NB);if(e===void 0)throw Error(process.env.NODE_ENV===`production`?dF(70):`Base UI: <Tooltip.Portal> is missing.`);return e}var FB=f.forwardRef(function(e,t){let{children:n,container:r,className:i,render:a,style:o,...s}=e,{node:c,subtree:l}=LR({container:r,ref:t,componentProps:e,elementProps:s});return!l&&!c?null:(0,J.jsxs)(f.Fragment,{children:[l,c&&p.createPortal(n,c)]})});process.env.NODE_ENV!==`production`&&(FB.displayName=`FloatingPortalLite`);var IB=f.forwardRef(function(e,t){let{keepMounted:n=!1,...r}=e;return pF().useState(`mounted`)||n?(0,J.jsx)(NB.Provider,{value:n,children:(0,J.jsx)(FB,{ref:t,...r})}):null});process.env.NODE_ENV!==`production`&&(IB.displayName=`TooltipPortal`);var LB=f.createContext(void 0);process.env.NODE_ENV!==`production`&&(LB.displayName=`TooltipPositionerContext`);function RB(){let e=f.useContext(LB);if(e===void 0)throw Error(process.env.NODE_ENV===`production`?dF(71):`Base UI: TooltipPositionerContext is missing. TooltipPositioner parts must be placed within <Tooltip.Positioner>.`);return e}function zB(e){let{nodeId:t,externalTree:n,rootContext:r}=e,i=r.useState(`referenceElement`),a=r.useState(`floatingElement`),o=r.useState(`domReferenceElement`),s=r.useState(`open`),c=r.useState(`floatingId`),[l,u]=f.useState(null),d=f.useRef(null),p=UR(n),m=f.useMemo(()=>({reference:i,floating:a,domReference:o}),[i,a,o]),h=FS({...e,elements:{...m,...l&&{reference:l}}}),g=f.useCallback(e=>{let t=Dx(e)?{getBoundingClientRect:()=>e.getBoundingClientRect(),getClientRects:()=>e.getClientRects(),contextElement:e}:e;u(t),h.refs.setReference(t)},[h.refs]),_=f.useMemo(()=>({...h.refs,setPositionReference:g,domReference:d}),[h.refs,g]),v=f.useMemo(()=>({...h.elements,domReference:o}),[h.elements,o]),y=f.useMemo(()=>({...h,dataRef:r.context.dataRef,open:s,onOpenChange:r.setOpen,events:r.context.events,floatingId:c,refs:_,elements:v,nodeId:t,rootStore:r}),[h,_,v,t,r,s,c]);return lF(()=>{o&&(d.current=o)},[o]),lF(()=>{r.context.dataRef.current.floatingContext=y;let e=p?.nodesRef.current.find(e=>e.id===t);e&&(e.context=y)}),f.useMemo(()=>({...h,context:y,refs:_,elements:v,rootStore:r}),[h,_,v,y,r])}var BB=f.createContext(void 0);process.env.NODE_ENV!==`production`&&(BB.displayName=`DirectionContext`);function VB(){return f.useContext(BB)?.direction??`ltr`}var HB=e=>({name:`arrow`,options:e,async fn(t){let{x:n,y:r,placement:i,rects:a,platform:o,elements:s,middlewareData:c}=t,{element:l,padding:u=0}=Vb(e,t)||{};if(l==null)return{};let d=ax(u),f={x:n,y:r},p=qb(i),m=Gb(p),h=await o.getDimensions(l),g=p===`y`,_=g?`top`:`left`,v=g?`bottom`:`right`,y=g?`clientHeight`:`clientWidth`,b=a.reference[m]+a.reference[p]-f[p]-a.floating[m],x=f[p]-a.reference[p],S=s.floating[y]||a.floating[m],C=b/2-x/2,w=S/2-h[m]/2-1,T=Math.min(d[_],w),E=Math.min(d[v],w),D=T,O=S-h[m]-E,k=S/2-h[m]/2+C,A=Bb(D,k,O),j=!c.arrow&&Ub(i)!=null&&k!==A&&a.reference[m]/2-(k<D?T:E)-h[m]/2<0,M=j?k<D?k-D:k-O:0;return{[p]:f[p]+M,data:{[p]:A,centerOffset:k-A-M,...j&&{alignmentOffset:M}},reset:j}}}),UB=(e,t)=>{let{name:n,fn:r}=HB(e);return{name:n,fn:r,options:[e,t]}},WB={name:`hide`,async fn(e){let{width:t,height:n,x:r,y:i}=e.rects.reference,a=t===0&&n===0&&r===0&&i===0,o=await e.platform.detectOverflow(e,{elementContext:`reference`});return{data:{referenceHidden:o.top-n>=0||o.right-t>=0||o.bottom-n>=0||o.left-t>=0||a}}}},GB={sideX:`left`,sideY:`top`},KB=`--available-width`,qB=`--available-height`,JB=`--anchor-width`,YB=`--anchor-height`,XB=`--transform-origin`,ZB=KB,QB=qB;function $B(e,t,n){let r=e===`inline-start`||e===`inline-end`;return{top:`top`,right:r?n?`inline-start`:`inline-end`:`right`,bottom:`bottom`,left:r?n?`inline-end`:`inline-start`:`left`}[t]}function eV(e,t,n){let{rects:r,placement:i}=e;return{side:$B(t,Hb(i),n),align:Ub(i)||`center`,anchor:{width:r.reference.width,height:r.reference.height},positioner:{width:r.floating.width,height:r.floating.height}}}function tV(e){return nV(e,zB)}function nV(e,t){let{anchor:n,positionMethod:r=`absolute`,side:i=`bottom`,sideOffset:a=0,align:o=`center`,alignOffset:s=0,collisionBoundary:c,collisionPadding:l=5,sticky:u=!1,arrowPadding:d=5,disableAnchorTracking:p=!1,inline:m,keepMounted:h=!1,floatingRootContext:g,mounted:_,collisionAvoidance:v,shift:y,nodeId:b,adaptiveOrigin:x,lazyFlip:S=!1,externalTree:C}=e,w=v.side||`flip`,T=v.align||`flip`,E=v.fallbackAxisSide||`end`,D=y?.crossAxis??!1,O=y?.rootBoundary,k=typeof n==`function`?n:void 0,A=qI(k),j=k?A:n,M=HI(n),N=HI(_),P=VB()===`rtl`,[F,I]=f.useState(null);!_&&F!==null&&I(null);let L=S===`placement`,R=F?Hb(F):null,z=F&&L?Ub(F)||`center`:null,ee=R||{top:`top`,right:`right`,bottom:`bottom`,left:`left`,"inline-end":P?`left`:`right`,"inline-start":P?`right`:`left`}[i],te=z||o,ne=te===`center`?ee:`${ee}-${te}`,B=l;typeof B==`number`?B={top:B,right:B,bottom:B,left:B}:B&&={top:B.top||0,right:B.right||0,bottom:B.bottom||0,left:B.left||0};let re=+(i===`bottom`),ie=+(i===`top`),V=+(i===`right`),ae=+(i===`left`),oe={boundary:c===`clipping-ancestors`?`clippingAncestors`:c,padding:B},se=f.useRef(null),ce=HI(a),le=HI(s),ue=typeof a==`function`?0:a,de=typeof s==`function`?0:s,fe=[];m&&fe.push(m),fe.push(LS(e=>{let t=eV(e,i,P),n=typeof ce.current==`function`?ce.current(t):ce.current,r=typeof le.current==`function`?le.current(t):le.current;return{mainAxis:n,crossAxis:r,alignmentAxis:r}},[ue,de,P,i]));let pe=T===`none`&&w!==`shift`,me=!pe&&(u||D||w===`shift`),he=w===`none`?null:BS({...oe,padding:{top:B.top+1+re,right:B.right+1+ae,bottom:B.bottom+1+ie,left:B.left+1+V},mainAxis:!D&&w===`flip`,crossAxis:T===`flip`&&`alignment`,fallbackAxisSideDirection:E}),ge=pe?null:RS({...oe,rootBoundary:O,mainAxis:T!==`none`,crossAxis:me,limiter:u||D?void 0:zS(e=>{if(!se.current)return{};let{width:t,height:n}=se.current.getBoundingClientRect(),r=Kb(Hb(e.placement)),i=r===`y`?t:n,a=r===`y`?B.left+B.right:B.top+B.bottom;return{offset:i/2+a/2}})},[oe,u,D,O,B,T]);w===`shift`||T===`shift`||te===`center`?fe.push(ge,he):fe.push(he,ge),fe.push(VS({...oe,apply({elements:{floating:e},availableWidth:t,availableHeight:n,rects:r}){if(!N.current)return;let i=e.style;i.setProperty(ZB,`${t}px`),i.setProperty(QB,`${n}px`);let a=wx(e).devicePixelRatio||1,{x:o,y:s,width:c,height:l}=r.reference,u=(Math.round((o+c)*a)-Math.round(o*a))/a,d=(Math.round((s+l)*a)-Math.round(s*a))/a;i.setProperty(JB,`${u}px`),i.setProperty(YB,`${d}px`)}}),UB(e=>({element:se.current||tL(e.elements.floating).createElement(`div`),padding:se.current?d:0}),[d]),{name:`transformOrigin`,fn(e){let{elements:{floating:t},middlewareData:n,placement:r,platform:o,rects:s,y:c}=e,l=Hb(r),u=Ub(r),d=Kb(l)===`y`,f=se.current,p=typeof a==`function`?a(eV(e,i,P)):a,m;m=!f&&u&&Math.abs(d?n.shift?.x||0:n.shift?.y||0)<=1?u===`start`===(d&&o.isRTL?.(t)===!0)?`100%`:`0%`:`${(d?n.arrow?.x||0:n.arrow?.y||0)+(d?f?.clientWidth||0:f?.clientHeight||0)/2}px`;let h=l===`top`||l===`left`?`calc(100% + ${p}px)`:`${-p}px`;return me&&d&&Math.abs(n.shift?.y||0)>p&&(h=`${s.reference.y+s.reference.height/2-c}px`),t.style.setProperty(XB,d?`${m} ${h}`:`${h} ${m}`),{}}},WB,x),lF(()=>{!_&&g&&g.update({referenceElement:null,floatingElement:null,domReferenceElement:null,positionReference:null})},[_,g]);let _e=f.useMemo(()=>({ancestorScroll:!p,elementResize:!p&&typeof ResizeObserver<`u`,layoutShift:!p&&typeof IntersectionObserver<`u`}),[p]),{refs:ve,elements:ye,x:be,y:xe,middlewareData:Se,update:Ce,placement:we,context:Te,isPositioned:Ee,floatingStyles:De}=t({rootContext:g,open:h?_:void 0,placement:ne,middleware:fe,strategy:r,whileElementsMounted:h?void 0:(...e)=>xS(...e,_e),nodeId:b,externalTree:C}),{sideX:Oe,sideY:ke}=Se.adaptiveOrigin||GB,Ae=Ee?r:`fixed`,je=f.useMemo(()=>{let e;return e=Ee?x?{position:Ae,[Oe]:be,[ke]:xe}:{...De,position:Ae}:{position:Ae,top:0,left:0},e[ZB]=`100vw`,e[QB]=`100vh`,Ee||(e.opacity=0),e},[x,Ae,Oe,be,ke,xe,De,Ee]),Me=f.useRef(null);lF(()=>{if(!_)return;let e=M.current,t=typeof e==`function`?e():e,n=(rV(t)?t.current:t)||null;n!==Me.current&&(ve.setPositionReference(n),Me.current=n)},[_,ve,j,M]),f.useEffect(()=>{if(!_)return;let e=M.current;typeof e!=`function`&&rV(e)&&e.current!==Me.current&&(ve.setPositionReference(e.current),Me.current=e.current)},[_,ve,j,M]),f.useEffect(()=>{if(h&&_&&ye.reference&&ye.floating)return xS(ye.reference,ye.floating,Ce,_e)},[h,_,ye,Ce,_e]);let Ne=Hb(we),Pe=$B(i,Ne,P),Fe=Ub(we)||`center`,Ie=!!Se.hide?.referenceHidden;lF(()=>{S&&_&&Ee&&(Ne!==ee||L&&Fe!==te)&&I(we)},[S,L,_,Ee,we,Ne,Fe,ee,te]);let Le=f.useMemo(()=>({position:`absolute`,top:Se.arrow?.y,left:Se.arrow?.x}),[Se.arrow]),Re=Se.arrow?.centerOffset!==0;return f.useMemo(()=>({positionerStyles:je,arrowStyles:Le,arrowRef:se,arrowUncentered:Re,side:Pe,align:Fe,physicalSide:Ne,anchorHidden:Ie,refs:ve,context:Te,isPositioned:Ee,update:Ce}),[je,Le,se,Re,Pe,Fe,Ne,Ie,ve,Te,Ee,Ce])}function rV(e){return e!=null&&`current`in e}function iV(e){return e===`starting`?AR:cF}function aV(e,t,{styles:n,transitionStatus:r,props:i,refs:a,hidden:o,inert:s=!1}){let c={...n};return s&&(c.pointerEvents=`none`),bR(`div`,e,{state:t,ref:a,props:[{role:`presentation`,hidden:o,style:c},iV(r),i],stateAttributesMapping:rI})}var oV=f.forwardRef(function(e,t){let{render:n,className:r,anchor:i,positionMethod:a=`absolute`,side:o=`top`,align:s=`center`,sideOffset:c=0,alignOffset:l=0,collisionBoundary:u=`clipping-ancestors`,collisionPadding:d=5,arrowPadding:p=5,sticky:m=!1,disableAnchorTracking:h=!1,collisionAvoidance:g=MR,style:_,...v}=e,y=pF(),b=PB(),x=y.useState(`open`),S=y.useState(`mounted`),C=y.useState(`trackCursorAxis`),w=y.useState(`disableHoverablePopup`),T=y.useState(`floatingRootContext`),E=y.useState(`instantType`),D=y.useState(`transitionStatus`),O=tV({anchor:i,positionMethod:a,floatingRootContext:T,mounted:S,side:o,sideOffset:c,align:s,alignOffset:l,collisionBoundary:u,collisionPadding:d,sticky:m,arrowPadding:p,disableAnchorTracking:h,keepMounted:b,collisionAvoidance:g,adaptiveOrigin:y.useState(`adaptiveOrigin`)}),k=aV(e,f.useMemo(()=>({open:x,side:O.side,align:O.align,anchorHidden:O.anchorHidden,instant:C===`none`?E:`tracking-cursor`}),[x,O.side,O.align,O.anchorHidden,C,E]),{styles:O.positionerStyles,transitionStatus:D,props:v,refs:[t,y.useStateSetter(`positionerElement`)],hidden:!S,inert:!x||C===`both`||w});return(0,J.jsx)(LB.Provider,{value:O,children:k})});process.env.NODE_ENV!==`production`&&(oV.displayName=`TooltipPositioner`);var sV=f.forwardRef(function(e,t){let{render:n,className:r,style:i,...a}=e,o=pF(),{side:s,align:c}=RB(),l=o.useState(`open`),u=o.useState(`instantType`),d=o.useState(`transitionStatus`),f=o.useState(`popupProps`),p=o.useState(`floatingRootContext`),m=o.useState(`disabled`),h=o.useState(`closeDelay`);pz({open:l,ref:o.context.popupRef,onComplete(){l&&o.context.onOpenChangeComplete?.(!0)}}),uB(p,{enabled:!m,closeDelay:h});let g=o.useStateSetter(`popupElement`);return bR(`div`,e,{state:{open:l,side:s,align:c,instant:u,transitionStatus:d},ref:[t,o.context.popupRef,g],props:[hz,f,iV(d),a],stateAttributesMapping:iI})});process.env.NODE_ENV!==`production`&&(sV.displayName=`TooltipPopup`);var cV=f.forwardRef(function(e,t){let{render:n,className:r,style:i,...a}=e,o=pF(),{arrowRef:s,side:c,align:l,arrowUncentered:u,arrowStyles:d}=RB();return bR(`div`,e,{state:{open:o.useState(`open`),side:c,align:l,uncentered:u,instant:o.useState(`instantType`)},ref:[t,s],props:[{style:d,"aria-hidden":!0},a],stateAttributesMapping:rI})});process.env.NODE_ENV!==`production`&&(cV.displayName=`TooltipArrow`);var lV=function(e){let{delay:t,closeDelay:n,timeout:r=400}=e,i=f.useMemo(()=>({open:t,close:n}),[t,n]);return(0,J.jsx)(OB.Provider,{value:t,children:(0,J.jsx)(MI,{delay:i,timeoutMs:r,children:e.children})})};process.env.NODE_ENV!==`production`&&(lV.displayName=`TooltipProvider`);function uV(e){return ZL(19)?e:e?`true`:void 0}var dV=48,fV=(e,t=0)=>{let n=new Int32Array(e.length);for(let r=0;r<e.length;r++)n[r]=e.charCodeAt(r)-dV-t;return n},pV=e=>{let t=new Int32Array(e.length+1);for(let n=0;n<e.length;n++)t[n+1]=t[n]+e[n];return t},mV=e=>{let t=new Int32Array(e.length),n=0;for(let r=0;r<e.length;r++){let i=e.charCodeAt(r)-dV;n+=i>>>1^-(i&1),t[r]=n}return t},hV=384,gV=[],_V=pV(fV(`E0500002005282000000002000150000020021820000011200000003022202000300004200120000200420001200021200301200010400162000010000220021010:2192001200220012000220012000200200200400010200040000000000400200108200110100000022010313000162002000020020012020080213000228200000000082000000000120002000120020020040101020300130001001010`)),vV=pV(fV(`:11111111211111119311546544411119731869:671397415686432441111111111161114151214313433415:78311132233313187211117221449443411141111151152226611131111112212518142224214215421421542142424242516171151615616347111111111197911327451111111111111111111113134714133513411111311111111111111111111112444411111342312715245411117:3`)),yV=`@containerabcdefghinlmoprstunderlineviawzccentlignnimatespectuto-colsrowsaglorightnessckdrop-sisbcontrastfiltergrayscalehue-rotateinvertopacityslurrightnessaturateepia-coniclinearpositionradialsizeockurrderttom-belrstxyespacing-xyaretoursorlnt-umnsendspantartainentrasteividerop-shadowurationcorationlay-xyasendillexontromlter-featuresstretchapr-xyayscaleidow-colsrowsue-rotatedentlinesetvert-beringsxyeshadoweiadingftnest-clamp-imageabein-lrstxyskx--b-coniclpositionrsizet-x-y-fromto-fromto-inearfromto-fromto-adialfromto-fromtofromtofromtofromtoblockhinlinew-screenesblockhinlinewbjectpacityrutlinederigin-offsetbelrstxyesrspective-originaceholderioghtng-offsettateundedw-xyz-belrstlreseslr-endspantartaturatecepiahizekewpace-taleroll-xyz-barmpbelrstxyesbelrstxyes-thumbrackadowrink-xyxyartrokeabextora-shadowpckingnsformitionlate-xyz-offsetill-changeoom`,bV=(()=>{let e=_V.length-1,t=new Int32Array(e);for(let n=e-1;n>=0;n--){let e=1,r=n+1;for(let i=_V[n];i<_V[n+1];i++)e+=t[r],r+=t[r];t[n]=e}let n=new Int32Array(_V[e]),r=0;for(let i=0;i<e;i++){let e=i+1;for(let a=_V[i];a<_V[i+1];a++)n[r++]=e,e+=t[e]}return n})(),xV=fV(`02000000000000900<=0?000B000F00F00ŏI0J0LNPRTVX0000]_a00000000000000000000000rst0000000zŏ00000000000
ŏ0000000ŏ00000000000000000000000000000000000000000000000000000000000000Ë000000000000000000000Þ000000000000000000ð0000000ø0ùúûüýþÿĀāĂ㥹Ć000000000000000000000000000000000000000000ħ0ĨĪ00000000000000000000ļĽ00000Ŭ000000`,1),SV=pV(fV(`123333359346463635126536711576`)),CV=fV(`93203242332583253248325D>E?F@03263243255B:032523853:0325B:8GA032542H<C=12727B:0328432553;D>E?3257D>032585:0325B:;0328B:032`),wV=fV(`012113445661666666789111:5;;;;;;;;444;;;:62999<1161=62>>?61:21@ABCD4446996:64E:::;:?::64:F114GHHIHHHHIHH1HH1HH1HHHHHH::EEJ4444::EE4444441691;644444114244444:;K6666555555555555555999666664444444444444444444444226?6:66644L9M?D:111::::6DE199`),TV=mV(`020200202020020020020020020020200200200200200200200002020202001003040106000200200200200200200200200200200200200200200200200200200200200200200200200200200200020020020020020020002020200202002002002002002002002002002020002002020020200220200200200200200200200200200200020020020000200020002000200200200020020020002000200200200020020202002020202000200200020022000200200020020002002000200220002002000200W0Z00020020002002020002002000200g0j0002002000200200020020002002000200200020020002000200002000002002002002002000200020000200002002002002002002002020020020200200200200200200200200202020020020020020020020020002002002020020020020020020020020020020020020020020020020020020020020020020020020020020020020020020020020020020020020020020020020020020020020020020020020020020020020020020020020020002002002002002002000200200200200200200200200200020202020002000200020002002002002000020200200`),EV=(()=>{let e=new Int32Array(319).fill(-1),t=mV(`02422242:222222242224222242442222222422222244442242226224222426222422442462222422622222222626222462242622422622422424242422222222422222222242422222222222222222622442224222222222222224424442262222222222222222222226224222424242422224422422422222`),n=mV(`02222222222222222222202222222222222222222222221422222222222222222222222222222222222Y\\222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222221422222222222222222222222222222222222222Ŀł222222222222222222`);for(let r=0;r<t.length;r++)e[t[r]]=n[r];return e})(),DV=`container |break-after- all auto avoid avoid-page column left page right|break-before- all auto avoid avoid-page column left page right|break-inside-a uto void void-column void-page|box-decoration- clone slice|box- border content| contents flow-root hidden table table-caption table-cell table-column table-column-group table-footer-group table-header-group table-row table-row-group| not-sr-only sr-only|float- end left none right start|clear- both end left none right start|isolat e ion-auto|overflow- auto clip hidden scroll visible|overflow-x- auto clip hidden scroll visible|overflow-y- auto clip hidden scroll visible|overscroll- auto contain none|overscroll-x- auto contain none|overscroll-y- auto contain none| absolute fixed relative static sticky| collapse invisible visible|justify- around baseline between center center-safe end end-safe evenly normal start stretch|justify-items- center center-safe end end-safe normal start stretch|justify-self- auto center center-safe end end-safe start stretch|items- baseline baseline-last center center-safe end end-safe start stretch|self- auto baseline baseline-last center center-safe end end-safe start stretch|place-content- around baseline between center center-safe end end-safe evenly start stretch|place-items- baseline center center-safe end end-safe start stretch|place-self- auto center center-safe end end-safe start stretch| antialiased subpixel-antialiased| italic not-italic|normal-nums |ordinal |slashed-zero | lining-nums oldstyle-nums| proportional-nums tabular-nums| diagonal-fractions stacked-fractions| no-underline overline| capitalize lowercase normal-case uppercase|truncate |whitespace- break-spaces normal nowrap pre pre-line pre-wrap|break- all keep normal words|wrap- anywhere break-word normal|hyphens- auto manual none|mix-blend- color color-burn color-dodge darken difference exclusion hard-light hue lighten luminosity multiply normal overlay plus-darker plus-lighter saturation screen soft-light|table- auto fixed|caption- bottom top|backface- hidden visible|appearance- auto none|scheme- dark light light-dark normal only-dark only-light|field-sizing- content fixed|pointer-events- auto none|resize -none -x -y|snap- align-none center end start|snap- always normal|snap- both none x y|snap- mandatory proximity|touch- auto manipulation none|touch-pan- left right x|touch-pan- down up y|touch-pinch-zoom |select- all auto none text|forced-color-adjust- auto none| normal size| baseline bottom middle sub super text-bottom text-top top| bounce none ping pulse spin| auto square video| auto fr max min px|none | auto full px| fixed local scroll|clip- border content padding text|origin- border content padding| bottom bottom-left bottom-right center left left-bottom left-top right right-bottom right-top top top-left top-right| no-repeat repeat repeat-round repeat-space repeat-x repeat-y| auto contain cover|blend- color color-burn color-dodge darken difference exclusion hard-light hue lighten luminosity multiply normal overlay saturation screen soft-light|to- b bl br l r t tl tr| auto dvh fit full lh lvh max min px screen svh| dashed dotted double hidden none solid| collapse separate|px |auto |full | content none strict| inline-size size|layout |paint |style | around baseline between center center-safe end end-safe evenly normal start stretch| alias all-scroll auto cell col-resize context-menu copy crosshair default e-resize ew-resize grab grabbing help move n-resize ne-resize nesw-resize no-drop none not-allowed ns-resize nw-resize nwse-resize pointer progress row-resize s-resize se-resize sw-resize text vertical-text w-resize wait zoom-in zoom-out| dashed dotted double solid wavy| auto from-font|reverse |initial | in in-out initial linear out| col col-reverse row row-reverse| nowrap wrap wrap-reverse| auto initial none| black bold extrabold extralight light medium normal semibold thin| condensed expanded extra-condensed extra-expanded normal semi-condensed semi-expanded ultra-condensed ultra-expanded|flow- col col-dense dense row row-dense| none subgrid| auto dvh dvw fit full lh lvh lvw max min px screen svh svw| block flex grid table| auto dvw fit full lvw max min px screen svw| loose none normal px relaxed snug tight|through |item | inside outside| decimal disc none| auto px| clip-border clip-content clip-fill clip-padding clip-stroke clip-view no-clip| add exclude intersect subtract| alpha luminance match|origin- border content fill padding stroke view|type- alpha luminance| circle ellipse| closest-corner closest-side farthest-corner farthest-side|at- bottom bottom-left bottom-right center left left-bottom left-top right right-bottom right-top top top-left top-right| dvh fit full lh lvh max min none px screen svh| auto dvh dvw fit full lh lvh lvw max min none px screen svh svw| dvw fit full lvw max min none px screen svw| auto dvh dvw fit full lvh lvw max min none prose px svh svw| auto dvh dvw fit full lvh lvw max min none px screen svh svw| contain cover fill none scale-down| first last none| distant dramatic midrange near none normal|inset | full none|3d | auto smooth|gutter- auto both stable| auto none thin| inner none| auto dvh dvw fit full lvh lvw max min px svh svw|base | center end justify left right start| clip ellipsis| balance nowrap pretty wrap| normal tight tighter wide wider widest| cpu gpu none| 3d flat| all colors none opacity shadow transform| discrete normal| full px| auto dvh dvw fit full lvh lvw max min px screen svh svw| auto contents scroll transform`.split(`|`).map(e=>{let t=e.split(` `),n=t.shift();for(let e=0;e<t.length;e++)t[e]=n+t[e];return t}),OV=mV(`0000000000000000000000000000000000000000000000000000000000000262242:6@200000006:240B428:4422400002046044222426220026642642462026224222824220022400000000\\00N222422242222222224062242222222422226264222422222222222222442804222422222222222222222222220<4<0204260002444020204224422`),kV=mV(`ɠ222222222222222222222222222222222222222222222222222222222222˕4222226>6ʰ22ʷʺʷʺʷ42ʴ2ʓ22>621422ɶ222ɹɼɷɺɷɺ22ɱ42222ɨ2ɧ26622ɘɓ244ƸƵ222]d24242ǖǓƚÄȫ2263ȨȥȨ2222222ǣ222222222222222222ǂƽ2ƾƵ2222222422222ƜƑ22222222222222222222144Ŧţ22Ţş222222222222222222222ĸ2ı68ĦģĦɡŰ4Ġ«®ĝ822ĔđĔ2ē2222622`),AV=mV(`02222222222222222222222222222222222222222222222222222222222222222202021422222222CF2200GJ021042222WZ222IL0ad2c10h2222U00X202[^2w0000120zy|}22
:22z22222222222G000qOVI00000{2<40000@00000G¦§000ª00000000000000021K¬«00®000000000000000000000222HGH_1¸222½2¾2222ÇÊ000°2±`),jV=new Int32Array(987),MV=new Int32Array(987),NV=new Int32Array(987),PV=``,FV=new Int32Array(1022);{let e=new Map,t=0,n=0;for(let r=0;r<OV.length;r++)for(let i of DV[AV[r]]){let a=e.get(i);a===void 0&&(a=t++,e.set(i,a),FV[a*2]=PV.length,FV[a*2+1]=i.length,PV+=i),jV[n]=OV[r],MV[n]=kV[r],NV[n]=a,n++}}var IV=mV(`0b2N:222@R>F@286¦2@H2D266226FB22B2>BD\\6N22222Z222D222p`),LV=pV(fV(`1::24444432:442:44:44>222222:44:4421322511111311111114`)),RV=mV(`24A;33N=C@H4A;33N=C@<27;83:;8393NQ:3NQʰ222ˉºŴŽ2R2=18cƴÅŇ=cĞÛC1ƈǝȈ:ħ25=11D3A@4=<1;1DEr25;11B3?<6;:371BCn9@7=<8192>2E121@9@EHE@9>2T25511<398454131<=V25511<398454131<=ƧNž2Đå242L222290000f22500ɛ000ǘ222`),zV=fV(`ij`),BV=fV(``),VV=fV(`1`),HV={GROUP_COUNT:hV,customValidatorNames:gV,edgeStart:_V,labelStart:vV,labelText:yV,edgeTarget:bV,nodeGroup:xV,nodeVlist:EV,vlistPat:SV,vlistOps:CV,vlistRef:wV,vlistGroup:TV,litAnchor:jV,litGroup:MV,litPool:NV,poolOffsets:FV,poolText:PV,adjGid:IV,adjStart:LV,adjTgt:RV,patGid:zV,patTgt:BV,postfixLookupGroups:VV,orderSensitiveModifiers:`* ** after backdrop before details-content file first-letter first-line marker placeholder selection`},UV=`line`in Error(),WV=-1,GV=-1,KV=(e,t,n)=>{let r=2166136261;for(let i=t;i<n;i++)r=Math.imul(r^e.charCodeAt(i),16777619);return r},qV=(e,t,n)=>{let r=n-t,i=Math.imul(r,2654435761)^e.charCodeAt(t);if(r>3){let a=r>>2,o=r>>1;i=Math.imul(i^e.charCodeAt(t+1)<<8^e.charCodeAt(t+2)<<16^e.charCodeAt(t+a),2246822507),i=Math.imul(i^e.charCodeAt(t+o)<<8^e.charCodeAt(t+o+a)<<16^e.charCodeAt(n-3),3266489909),i^=e.charCodeAt(n-2)<<8^e.charCodeAt(n-1)<<16;for(let r=t+3,a=n-4;r<t+8&&r<a;r++,a--)i=Math.imul(i^e.charCodeAt(r)^e.charCodeAt(a)<<8,16777619)}return i^i>>>15},JV=(e,t,n={})=>{let{GROUP_COUNT:r,edgeStart:i,labelStart:a,labelText:o,edgeTarget:s,nodeGroup:c,nodeVlist:l,vlistPat:u,vlistOps:d,vlistRef:f,vlistGroup:p,litAnchor:m,litGroup:h,litPool:g,poolOffsets:_,poolText:v,adjGid:y,adjStart:b,adjTgt:x,patGid:S,patTgt:C,postfixLookupGroups:w,customValidatorNames:T,orderSensitiveModifiers:E}=e,D=new Int32Array(r).fill(-1);for(let e=0;e<y.length;e++)D[y[e]]=e;let O=0;for(let e=0;e+1<b.length;e++){let t=b[e+1]-b[e];t>O&&(O=t)}let k=32;for(;k<2*(1+O+S.length);)k<<=1;let A=new Int32Array(f.length+1);for(let e=0;e<f.length;e++)A[e+1]=A[e]+u[f[e]+1]-u[f[e]];let j=new Uint8Array(r);for(let e=0;e<w.length;e++)j[w[e]]=1;let M=i.length-1,N=new Uint8Array(M),P=0,F=!0;for(let e=0;e<m.length;e++){N[m[e]]=1;let t=_[g[e]*2+1];t>P&&(P=t);let n=v.charCodeAt(_[g[e]*2]);(n===91||n===40)&&(F=!1)}let I=1;for(;I<m.length*2;)I<<=1;let L=new Int32Array(I).fill(-1);for(let e=0;e<m.length;e++){let t=_[g[e]*2],n=(KV(v,t,t+_[g[e]*2+1])^Math.imul(m[e],2654435761)|0)&I-1;for(;L[n]!==-1;)n=n+1&I-1;L[n]=e}let R=(e,t,n,r)=>{let i=(KV(t,n,r)^Math.imul(e,2654435761)|0)&I-1,a=r-n;for(;;){let r=L[i];if(r===-1)return-1;if(m[r]===e&&_[g[r]*2+1]===a){let e=_[g[r]*2],i=!0;for(let r=0;r<a;r++)if(v.charCodeAt(e+r)!==t.charCodeAt(n+r)){i=!1;break}if(i)return h[r]}i=i+1&I-1}},z=n.cacheSize??8192,ee=n.prefix??e.prefix??``,te=ee===``?``:ee+`:`,ne=te.length,B=(T??[]).map(e=>{let n=t&&t[e];if(!n)throw Error(`cn: missing validator `+e);return n}),re=/\d+(%|px|r?em|[sdl]?v([hwib]|min|max)|pt|pc|in|cm|mm|cap|ch|ex|r?lh|cq(w|h|i|b|min|max))|\b(calc|min|max|clamp)\(.+\)|^0$/,ie=/^(rgba?|hsla?|hwb|(ok)?(lab|lch)|color-mix)\(.+\)$/,V=/^(inset_)?-?((\d+)?\.?(\d+)[a-z]+|0)_-?((\d+)?\.?(\d+)[a-z]+|0)/,ae=/^(url|image|image-set|cross-fade|element|(repeating-)?(linear|radial|conic)-gradient)\(.+\)$/,oe=0,se=-1,ce=-1,le=-1,ue=-1,de=e=>e>=97&&e<=122||e>=65&&e<=90||e>=48&&e<=57||e===95,fe=e=>/\s/.test(String.fromCharCode(e)),pe=(e,t,n)=>{if(oe=0,se=-1,n-t<3)return;let r=e.charCodeAt(t),i=e.charCodeAt(n-1);if(r===91&&i===93)oe=1;else if(r===40&&i===41)oe=2;else return;le=t+1,ue=n-1;let a=t+1;if(de(e.charCodeAt(a))){for(a++;a<n-1;){let t=e.charCodeAt(a);if(!de(t)&&t!==45)break;a++}a<n-2&&e.charCodeAt(a)===58&&(se=t+1,ce=a,le=a+1)}},me=(e,t,n,r)=>{if(n-t!==r.length)return!1;for(let n=0;n<r.length;n++)if(e.charCodeAt(t+n)!==r.charCodeAt(n))return!1;return!0},he=/^\d+(?:\.\d+)?\/\d+(?:\.\d+)?$/,ge=/^(\d+(\.\d+)?)?(xs|sm|md|lg|xl)$/,_e=e=>!!e&&!Number.isNaN(Number(e)),ve=(e,t,n)=>{if(n-t<11||!me(e,t,t+10,`@container`))return!1;if(e.charCodeAt(t+10)===47)return n-t>=12;let r=e.charCodeAt(t+11);return r===115&&n-t>=17&&me(e,t+10,t+16,`-size/`)||r===110&&n-t>=19&&me(e,t+10,t+18,`-normal/`)},ye=[1,1,1,1,1,1,1,1,2,2,2,2,2,2,2],be=`length|number|number weight|family-name|position percentage|length size bg-size|image url|shadow|length|family-name|position percentage|length size bg-size|image url|shadow|number weight`.split(`|`).map(e=>e.split(` `)),xe=[2,3,1,0,0,0,4,5,0,0,0,0,0,1,1],Se=(e,t,n,r)=>{if(e>=10){if(e>=25)return B[e-25](t.slice(n,r));let i=e-10;if(oe!==ye[i])return!1;if(se>=0){for(let e of be[i])if(me(t,se,ce,e))return!0;return!1}switch(xe[i]){case 0:return!1;case 1:return!0;case 2:{let e=t.slice(le,ue);return re.test(e)&&!ie.test(e)}case 3:return _e(t.slice(le,ue));case 4:return ae.test(t.slice(le,ue));default:return V.test(t.slice(le,ue))}}switch(e){case 0:return!0;case 1:return oe===0;case 2:return oe===1;case 3:return oe===2;case 4:return he.test(t.slice(n,r));case 5:return _e(t.slice(n,r));case 6:{let e=t.slice(n,r);return!!e&&Number.isInteger(Number(e))}case 7:return r>n&&t.charCodeAt(r-1)===37&&_e(t.slice(n,r-1));case 8:return ge.test(t.slice(n,r));default:return ve(t,n,r)}},Ce=new Set(typeof E==`string`?E.split(` `):E),we=(e,t,n,r,i,a)=>{let o=KV(t,n,r)^(i?2654435769:0),s=e.get(o);if(s!==void 0)outer:for(let e=0;e<s.length;e++){let a=s[e];if(a.imp===i&&a.k.length===r-n){for(let e=0;e<a.k.length;e++)if(a.k.charCodeAt(e)!==t.charCodeAt(n+e))continue outer;return a.id}}else e.set(o,s=[]);let c=t.slice(n,r),l=a(c);return s.push({k:c,imp:i,id:l}),l},Te=new Map,Ee=new Map,De=2,Oe=4096,ke=(e,t)=>{let n=[],r=0,i=0,a=0;for(let t=0;t<e.length;t++){let o=e.charCodeAt(t);r===0&&i===0&&o===58?(n.push(e.slice(a,t)),a=t+1):o===91?r++:o===93?r--:o===40?i++:o===41&&i--}n.push(e.slice(a));let o=n[0];if(n.length>1){let e=[],t=[];for(let r of n)r.charCodeAt(0)===91||Ce.has(r)?(t.length&&(e.push(...t.sort()),t=[]),e.push(r)):t.push(r);t.length&&e.push(...t.sort()),o=e.join(`:`)}let s=t?o+` !`:o,c=Ee.get(s);return c===void 0&&Ee.set(s,c=De++),c},Ae=new Map,je=r,Me=r+4096,Ne=()=>je++,Pe=2097152,Fe=8192,Ie=new Int32Array(Fe),Le=Array(Fe).fill(null),Re=new Int32Array(Fe),ze=new Int32Array(Fe),Be=new Uint8Array(Fe),Ve=0,He=(e,t,n,r,i,a,o,s)=>{let c=e;if(Le[e]!==null){if(Le[e|1]===null)c=e|1;else if(!(Ve++&3))c=e|Ve>>2&1;else return}Le[c]=t.slice(n,r),Ie[c]=i,Re[c]=a,ze[c]=o,Be[c]=s},Ue=()=>Le.fill(null),We=256,Ge=[new Int32Array(We),new Int32Array(We),new Int32Array(We),new Int32Array(We)],[Ke,qe,Je,Ye]=Ge,Xe=new Uint8Array(We),Ze=new Uint8Array(We),Qe=()=>{We*=2,Ge=Ge.map(e=>{let t=new Int32Array(We);return t.set(e),t}),[Ke,qe,Je,Ye]=Ge;let e=new Uint8Array(We);e.set(Xe),Xe=e,Ze=new Uint8Array(We)},$e=64,et=new Int32Array($e),tt=new Int32Array($e),nt=new Int32Array(r),rt=2048,it=21,at=new Float64Array(rt),ot=new Int32Array(rt),st=0,ct=(e,t)=>{if(e===0&&t<r)return nt[t]===st?1:(nt[t]=st,0);let n=e*2097152+t+1,i=Math.imul(n,2654435761)>>>it;for(;ot[i]===st;){if(at[i]===n)return 1;i=i+1&rt-1}return at[i]=n,ot[i]=st,0},lt=(e,t,n,r,i)=>{if(n-t>=2&&e.charCodeAt(t)===91&&e.charCodeAt(n-1)===93){let r=-1;for(let i=t+1;i<n-1;i++)if(e.charCodeAt(i)===58){r=i;break}return r===-1||r===t+1?WV:we(Ae,e,t+1,r,0,Ne)}if(r>=0&&c[r]>=0)return c[r];for(let t=i-1;t>=0;t--){let r=tt[t];if(r>n)continue;let i=et[t],a=n-r;if(N[i]===1&&a>0&&a<=P){let t=e.charCodeAt(r);if(F===!1||t!==91&&t!==40){let t=R(i,e,r,n);if(t>=0)return t}}let o=l[i];if(o<0)continue;let s=f[o],c=u[s],m=u[s+1];if(c===m)continue;pe(e,r,n);let h=A[o]-c;for(let t=c;t<m;t++)if(Se(d[t],e,r,n))return p[h+t]}return WV},ut=e=>{let t=e.length,n=0,c=0,u=!1;(De>Oe||Te.size>Oe)&&(Te=new Map,Ee=new Map,De=2,Ue()),je>Me&&(Ae=new Map,je=r,Ue());let d=0;for(;d<t;){let f=e.charCodeAt(d);if(f===32||f>=9&&f<=13||f>=160&&fe(f)){f!==32&&(u=!0),d++;continue}let p=d,m=0;for(;d<t;){if(f=e.charCodeAt(d),f<=32){if(f===32)break;if(f>=9&&f<=13){u=!0;break}}else if(f>=160&&fe(f)){u=!0;break}m=Math.imul(m^f,16777619),d++}let h=d,g=h-p;n===We&&Qe();let _=n++;Ke[_]=p,qe[_]=h,c+=g,m^=Math.imul(g,2654435761);let v=m^m>>>15,y=v&8190;{let t=-1;if(Ie[y]===v&&Le[y]!==null&&Le[y].length===g?t=y:Ie[y|1]===v&&Le[y|1]!==null&&Le[y|1].length===g&&(t=y|1),t>=0){let n=Le[t],r=!0;for(let t=0;t<g;t++)if(n.charCodeAt(t)!==e.charCodeAt(p+t)){r=!1;break}if(r){Je[_]=Re[t],Ye[_]=ze[t],Xe[_]=Be[t];continue}}}let b=p;if(ne!==0){if(h-p<=ne||!e.startsWith(te,p)){Je[_]=WV,He(y,e,p,h,v,WV,0,0);continue}b=p+ne}let x=0,S=0,C=-1,w=-1;for(let t=b;t<h;t++){let n=e.charCodeAt(t);if(x===0&&S===0){if(n===58){C=t;continue}if(n===47){w=t;continue}}n===91?x++:n===93?x--:n===40?S++:n===41&&S--}let T=C>=b?C+1:b,E=T,D=h,O=!1,k=0;D>E&&e.charCodeAt(D-1)===33?(O=!0,D--):D>E&&e.charCodeAt(E)===33&&(O=!0,E++,k=1);let A=-1;w>T&&(A=w+k,A>=D&&(A=-1));let M=E;D-E>1&&e.charCodeAt(E)===45&&(M=E+1);let P=0,F=0,I=0,L=-1,R=0;(l[0]>=0||N[0]===1)&&(et[0]=0,tt[0]=M,R=1);let z=GV,ee=0;for(let t=M;t<D;t++)if(t===A&&(z=F<I?GV:P,ee=R),P!==GV){let n=e.charCodeAt(t),r=-1;if(F<I)o.charCodeAt(F)===n?(F++,F===I&&(r=P=L)):P=GV;else{let e=i[P],t=i[P+1],c=GV;for(let i=e;i<t;i++){let e=a[i];if(o.charCodeAt(e)===n){a[i+1]-e===1?r=c=s[i]:(F=e+1,I=a[i+1],L=s[i],c=P);break}}P=c}if(r>=0&&(l[r]>=0||N[r]===1)&&t+1<D&&e.charCodeAt(t+1)===45){if(R===$e){$e*=2;let e=new Int32Array($e);e.set(et),et=e;let t=new Int32Array($e);t.set(tt),tt=t}et[R]=r,tt[R]=t+2,R++}}A===D&&(z=F<I?GV:P,ee=R);let B=F<I?GV:P,re,ie=!1;if(A>=0){if(ie=!0,re=lt(e,E,A,z,ee),re!==WV&&re<r&&j[re]){let t=lt(e,E,D,B,R);t!==WV&&t!==re&&(re=t,ie=!1)}else re===WV&&(re=lt(e,E,D,B,R),ie=!1)}else re=lt(e,E,D,B,R);let V=0,ae=0;re===WV?Je[_]=WV:(ae=+!!ie,V=b>=C?+!!O:we(Te,e,b,C,+!!O,e=>ke(e,O)),Je[_]=re,Xe[_]=ae,Ye[_]=V),He(y,e,p,h,v,re,V,ae)}if(n===0)return``;if(n===1)return Ke[0]===0&&qe[0]===t?e:e.slice(Ke[0],qe[0]);if(n*k>rt){for(;n*k>rt;)rt<<=1,it--;at=new Float64Array(rt),ot=new Int32Array(rt)}if(De>=Pe||je>=Pe)throw Error(`cn: too many distinct classes in one merge`);st=st+1|0,st===0&&(nt.fill(0),ot.fill(0),st=1);let f=!1;for(let e=n-1;e>=0;e--){let t=Je[e];if(t===WV){Ze[e]=1;continue}let n=Ye[e];if(ct(n,t)===1)Ze[e]=0,f=!0;else if(Ze[e]=1,t<r){let r=D[t];if(r>=0)for(let e=b[r];e<b[r+1];e++)ct(n,x[e]);if(Xe[e]&1)for(let e=0;e<S.length;e++)S[e]===t&&ct(n,C[e])}}if(!f&&!u&&t===c+n-1)return e;let p=``,m=0;for(;m<n;){if(!Ze[m]){m++;continue}let t=Ke[m],r=qe[m],i=m+1;for(;i<n&&Ze[i]&&Ke[i]===r+1&&e.charCodeAt(r)===32;)r=qe[i],i++;p.length>0&&(p+=` `),p+=e.slice(t,r),m=i}return p},dt=16384,ft=new Int32Array(dt*2),pt=0,mt=1,ht=Object.create(null),gt=Object.create(null),_t=new Map,vt=new Map,yt=0,bt=0,xt=()=>{pt^=dt,mt=mt+1|0,bt=0},St=e=>{let t=ht[e];if(t!==void 0)return t;let n=qV(e,0,e.length),r=(n&16383)+pt,i=ft[r]===(n^mt)||ft[r^dt]===(n^mt-1);return i&&(t=gt[e],t!==void 0)?(ht[e]=t,t):(t=ut(e),i?(ht[e]=t,++yt>z&&(yt=0,gt=ht,ht=Object.create(null),xt())):(ft[r]=n^mt,++bt>dt&&xt()),t)},Ct=e=>{let t=_t.get(e);if(t!==void 0)return t;let n=qV(e,0,e.length),r=(n&16383)+pt,i=ft[r]===(n^mt)||ft[r^dt]===(n^mt-1);return i&&(t=vt.get(e),t!==void 0)?(_t.set(e,t),t):(t=ut(e),i?(_t.set(e,t),++yt>z&&(yt=0,vt=_t,_t=new Map,xt())):(ft[r]=n^mt,++bt>dt&&xt()),t)},wt=e=>{let t=qV(e,0,e.length),n=(t&16383)+pt;return ft[n]===(t^mt)||ft[n^dt]===(t^mt-1)||(ft[n]=t^mt,++bt>dt&&xt(),!1)},Tt=z===0?ut:UV?e=>{let t=_t.get(e);return t===void 0?Ct(e):t}:St;return{merge:function(){return arguments.length===1&&typeof arguments[0]==`string`?Tt(arguments[0]):Tt(ZV.apply(null,arguments))},mergeString:Tt,seenBefore:z===0?()=>!1:wt,mergeUncached:ut}},YV=(e,t)=>{if(!e)return``;if(typeof e==`string`)return e;let n=``;if(typeof e.length==`number`&&(!t||Array.isArray(e))){let r=e;for(let e=0;e<r.length;e++){let i=r[e];if(!i)continue;let a=typeof i==`string`?i:YV(i,t);a&&(n&&(n+=` `),n+=a)}return n}if(t){if(typeof e==`number`)return``+e;if(typeof e==`object`)for(let t in e)e[t]&&(n&&(n+=` `),n+=t)}return n},XV=(e,t)=>{let n=``;for(let r=0;r<e.length;r++){let i=e[r];if(!i)continue;let a=typeof i==`string`?i:YV(i,t);a&&(n&&(n+=` `),n+=a)}return n},ZV=function(){return XV(arguments,!1)},QV=256,$V=16,eH=1024,tH=4096,nH=(e,t)=>{let n=t===void 0?()=>!0:t.seenBefore,r=t===void 0?e:t.mergeUncached,i=new Map,a=new Map,o=0,s=null,c=null,l=[],u=[],d=0,f=(t,n,r)=>{c===null&&(c=Array(tH).fill(``),l=Array(tH).fill(``),u=Array(tH).fill(``));let i=qV(t,0,t.length)&4094;if(c[i]===t&&l[i]===n)return u[i];if(c[i|1]===t&&l[i|1]===n)return u[i|1];let a=e(r?n+` `+t:t),o=c[i]===``?i:i|(c[i|1]===``?1:d++&1);return c[o]=t,l[o]=n,u[o]=a,a},p=(e,t,n,r)=>{let i=0;if(t){if(t!==e.a0)return!1;i=1}if(n){if(n!==(i===0?e.a0:e.a1))return!1;i++}if(r){if(r!==(i===0?e.a0:i===1?e.a1:e.a2))return!1;i++}return i===e.t},m=(e,t)=>{let n=e.a,r=0;for(let e=0;e<t.length;e++){let i=t[e];if(i){if(i!==n[r])return!1;r++}}return r===e.t},h=(t,c)=>{let l=t.length,u=s===null?null:s.n;if(!c){if(u!==null&&m(u,t))return s=u,u.r;if(s!==null&&s!==u&&m(s,t))return s.r}let d=``,p=-1,h=0,g=!1;for(let e=0;e<l;e++){let n=t[e];if(n){if(typeof n!=`string`){if(n=t[e]=YV(n,!0),!n)continue;g=!0}p<0&&(d=n,p=e),h++}}if(h===0)return``;if(h===1)return e(d);if(g){if(u!==null&&m(u,t))return s=u,u.r;if(s!==null&&s!==u&&m(s,t))return s.r}let _=i.get(d);_===void 0&&(_=a.get(d),_!==void 0&&i.set(d,_));let v=null;if(_!==void 0){if(_.skip>0){_.skip--,s=null;let e=d;for(let n=p+1;n<l;n++){let r=t[n];r&&(e+=` `+r)}return f(e,``,!1)}let e=_.e;outer:for(let n=0;n<e.length;n++){let r=e[n];if(r.t!==h)continue;let i=r.a,a=1;for(let e=p+1;e<l;e++){let n=t[e];if(n&&n!==i[a++])continue outer}v=r;break}v!==null&&(_.miss=0)}if(v===null){let s=d,c=[d];for(let e=p+1;e<l;e++){let n=t[e];n&&(s+=` `+n,c.push(n))}if(!n(s))return r(s);v={r:e(s),t:c.length,a0:c[0],a1:c[1],a2:c[2]??``,a:c,n:null},_===void 0?i.set(d,_={e:[],miss:0,skip:0,at:0}):++_.miss>$V&&(_.miss=$V,_.skip=eH,_.e.length=0,_.at=0);let u=_.e;u.length<QV?u.push(v):(u[_.at]=v,_.at=_.at+1&255),++o>1e3&&(o=0,a=i,i=new Map)}return s!==null&&s!==v&&(s.n=v),s=v,v.r},g=t=>Array.isArray(t)?h(t.slice(),!1):e(YV(t,!0));return function(t,n,r){let a=arguments.length;if((a|1)==3){let e=s;if(e!==null){let i=e.n;if(i!==null&&p(i,t,n,r))return s=i,i.r;if(e!==i&&p(e,t,n,r))return e.r}if(a===2&&typeof n==`string`&&n!==``){let e=i.get(t);if(e!==void 0&&e.skip>0)return e.skip--,s=null,f(n,t,!0)}return h([t,n,r],!0)}if(a===1)return typeof t==`string`?e(t):g(t);let o=s;if(o!==null){let e=o.n;if(e!==null){let t=e.a,n=0,r=!0;for(let e=0;e<a;e++){let i=arguments[e];if(i){if(i!==t[n]){r=!1;break}n++}}if(r&&n===e.t)return s=e,e.r}if(o!==e){let e=o.a,t=0,n=!0;for(let r=0;r<a;r++){let i=arguments[r];if(i){if(i!==e[t]){n=!1;break}t++}}if(n&&t===o.t)return o.r}}let c=[];for(let e=0;e<a;e++)c.push(arguments[e]);return h(c,!0)}},rH=JV(HV),Q=nH(rH.mergeString,rH);rH.merge;function iH({delay:e=0,...t}){return(0,J.jsx)(lV,{"data-slot":`tooltip-provider`,delay:e,...t})}function aH({...e}){return(0,J.jsx)(TB,{"data-slot":`tooltip`,...e})}function oH({...e}){return(0,J.jsx)(MB,{"data-slot":`tooltip-trigger`,...e})}function sH({className:e,side:t=`top`,sideOffset:n=4,align:r=`center`,alignOffset:i=0,children:a,...o}){return(0,J.jsx)(IB,{children:(0,J.jsx)(oV,{align:r,alignOffset:i,side:t,sideOffset:n,className:`isolate z-50`,children:(0,J.jsxs)(sV,{"data-slot":`tooltip-content`,className:Q(`z-50 inline-flex w-fit max-w-xs origin-(--transform-origin) items-center gap-1.5 rounded-md bg-foreground px-3 py-1.5 text-xs text-background has-data-[slot=kbd]:pr-1.5 data-[side=bottom]:slide-in-from-top-2 data-[side=inline-end]:slide-in-from-left-2 data-[side=inline-start]:slide-in-from-right-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 **:data-[slot=kbd]:relative **:data-[slot=kbd]:isolate **:data-[slot=kbd]:z-50 **:data-[slot=kbd]:rounded-sm data-[state=delayed-open]:animate-in data-[state=delayed-open]:fade-in-0 data-[state=delayed-open]:zoom-in-95 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95`,e),...o,children:[a,(0,J.jsx)(cV,{className:`z-50 size-2.5 translate-y-[calc(-50%-2px)] rotate-45 rounded-[2px] bg-foreground fill-foreground data-[side=bottom]:top-1 data-[side=inline-end]:top-1/2! data-[side=inline-end]:-left-1 data-[side=inline-end]:-translate-y-1/2 data-[side=inline-start]:top-1/2! data-[side=inline-start]:-right-1 data-[side=inline-start]:-translate-y-1/2 data-[side=left]:top-1/2! data-[side=left]:-right-1 data-[side=left]:-translate-y-1/2 data-[side=right]:top-1/2! data-[side=right]:-left-1 data-[side=right]:-translate-y-1/2 data-[side=top]:-bottom-2.5`})]})})})}var cH=f.createContext(void 0);process.env.NODE_ENV!==`production`&&(cH.displayName=`DialogRootContext`);function lH(e){let t=f.useContext(cH);if(!e&&t===void 0)throw Error(process.env.NODE_ENV===`production`?dF(27):`Base UI: DialogRootContext is missing. Dialog parts must be placed within <Dialog.Root>.`);return t}var uH=f.forwardRef(function(e,t){let{render:n,className:r,style:i,forceRender:a=!1,...o}=e,s=lH(),c=s.useState(`open`),l=s.useState(`nested`),u=s.useState(`mounted`);return bR(`div`,e,{state:{open:c,transitionStatus:s.useState(`transitionStatus`)},ref:[s.context.backdropRef,t],stateAttributesMapping:iI,props:[{role:`presentation`,hidden:!u,style:{userSelect:`none`,WebkitUserSelect:`none`}},o],enabled:a||!l})});process.env.NODE_ENV!==`production`&&(uH.displayName=`DialogBackdrop`);var dH=tR(`error`,`Base UI`),fH=f.createContext(void 0);process.env.NODE_ENV!==`production`&&(fH.displayName=`CompositeRootContext`);function pH(e=!1){let t=f.useContext(fH);if(t===void 0&&!e)throw Error(process.env.NODE_ENV===`production`?dF(16):`Base UI: CompositeRootContext is missing. Composite parts must be placed within <Composite.Root>.`);return t}function mH(e){let{focusableWhenDisabled:t,disabled:n,composite:r=!1,tabIndex:i=0,isNativeButton:a}=e,o=r&&t!==!1,s=r&&t===!1;return{props:f.useMemo(()=>{let e={onKeyDown(e){n&&t&&e.key!==`Tab`&&e.preventDefault()}};return r||(e.tabIndex=i,!a&&n&&(e.tabIndex=t?i:-1)),(a&&(t||o)||!a&&n)&&(e[`aria-disabled`]=n),a&&(!t||s)&&(e.disabled=n),e},[r,n,t,o,s,a,i])}}function hH(e,t,{detail:n=0,pointerType:r=``}={}){e.dispatchEvent(new(wx(e)).PointerEvent(`click`,{bubbles:!0,cancelable:!0,composed:!0,detail:n,pointerType:r,shiftKey:t.shiftKey,ctrlKey:t.ctrlKey,altKey:t.altKey,metaKey:t.metaKey}))}function gH(e={}){let{disabled:t=!1,focusableWhenDisabled:n,tabIndex:r=0,native:i=!0,composite:a}=e,o=f.useRef(null),s=pH(!0),c=a??s!==void 0,{props:l}=mH({focusableWhenDisabled:n,disabled:t,composite:c,tabIndex:r,isNativeButton:i});process.env.NODE_ENV!==`production`&&f.useEffect(()=>{if(!o.current)return;let e=_H(o.current);i?e||dH(`A component that acts as a button expected a native <button> because the \`nativeButton\` prop is true. Rendering a non-<button> removes native button semantics, which can impact forms and accessibility. Use a real <button> in the \`render\` prop, or set \`nativeButton\` to \`false\`.${WI.captureOwnerStack?.()||``}`):e&&dH(`A component that acts as a button expected a non-<button> because the \`nativeButton\` prop is false. Rendering a <button> keeps native behavior while Base UI applies non-native attributes and handlers, which can add unintended extra attributes (such as \`role\` or \`aria-disabled\`). Use a non-<button> in the \`render\` prop, or set \`nativeButton\` to \`true\`.${WI.captureOwnerStack?.()||``}`)},[i]);let u=f.useCallback(()=>{let e=o.current;_H(e)&&c&&t&&l.disabled===void 0&&e.disabled&&(e.disabled=!1)},[t,l.disabled,c]);return lF(u,[u]),{getButtonProps:f.useCallback((e={})=>{let{onClick:n,onMouseDown:r,onKeyUp:a,onKeyDown:o,onPointerDown:s,...u}=e;return sR({onClick(e){t?e.preventDefault():n?.(e)},onMouseDown(e){t||r?.(e)},onKeyDown(e){if(t||(_R(e),o?.(e),e.baseUIHandlerPrevented))return;let n=e.target===e.currentTarget,r=e.currentTarget,a=_H(r),s=!i&&vH(r),l=n&&(i?a:!s),u=e.key===`Enter`,d=e.key===` `,f=r.getAttribute(`role`),p=f?.startsWith(`menuitem`)||f===`option`||f===`gridcell`;if(n&&c&&d){if(e.defaultPrevented&&p)return;e.preventDefault(),(!i||a)&&(e.preventBaseUIHandler(),hH(r,e))}else!l||i||!d&&!u?n&&s&&d&&e.preventDefault():e.defaultPrevented||(e.preventDefault(),u&&(e.preventBaseUIHandler(),hH(r,e)))},onKeyUp(e){t||(_R(e),a?.(e),e.target===e.currentTarget&&i&&c&&_H(e.currentTarget)&&e.key===` `?e.preventDefault():e.baseUIHandlerPrevented||e.target!==e.currentTarget||i||c||e.defaultPrevented||e.key!==` `||(e.preventBaseUIHandler(),hH(e.currentTarget,e)))},onPointerDown(e){t?e.preventDefault():s?.(e)}},i?{type:`button`}:{role:`button`},l,u)},[t,l,c,i]),buttonRef:qI(e=>{o.current=e,u()})}}function _H(e){return Ox(e)&&e.tagName===`BUTTON`}function vH(e){return Ox(e)&&e.tagName===`A`&&!!e.href}var yH=f.forwardRef(function(e,t){let{render:n,className:r,style:i,disabled:a=!1,nativeButton:o=!0,...s}=e,c=lH(),l=c.useState(`open`),{getButtonProps:u,buttonRef:d}=gH({disabled:a,native:o}),f={disabled:a};function p(e){l&&c.setOpen(!1,yI(TI,e.nativeEvent))}return bR(`button`,e,{state:f,ref:[t,d],props:[{onClick:p},s,u]})});process.env.NODE_ENV!==`production`&&(yH.displayName=`DialogClose`);var bH=f.createContext(void 0);process.env.NODE_ENV!==`production`&&(bH.displayName=`DialogPortalContext`);function xH(){let e=f.useContext(bH);if(e===void 0)throw Error(process.env.NODE_ENV===`production`?dF(26):`Base UI: <Dialog.Portal> is missing.`);return e}var SH=new Set([`ArrowUp`,`ArrowDown`,`ArrowLeft`,`ArrowRight`,`Home`,`End`]),CH=`--nested-dialogs`,wH=`data-nested-dialog-open`,TH={...rI,...JF,nestedDialogOpen(e){return e?{[wH]:``}:null}},EH=f.forwardRef(function(e,t){let{render:n,className:r,style:i,finalFocus:a,initialFocus:o,...s}=e,c=lH(),l=c.useState(`descriptionElementId`),u=c.useState(`disablePointerDismissal`),d=c.useState(`floatingRootContext`),f=c.useState(`popupProps`),p=c.useState(`modal`),m=c.useState(`mounted`),h=c.useState(`nested`),g=c.useState(`nestedOpenDialogCount`),_=c.useState(`open`),v=c.useState(`openMethod`),y=c.useState(`titleElementId`),b=c.useState(`transitionStatus`),x=c.useState(`role`),S=d.useState(`floatingId`);xH(),pz({open:_,ref:c.context.popupRef,onComplete(){_&&c.context.onOpenChangeComplete?.(!0)}});let C=o===void 0?gz(c.context.popupRef):o,w=g>0,T=c.useStateSetter(`popupElement`),E=bR(`div`,e,{state:{open:_,nested:h,transitionStatus:b,nestedDialogOpen:w},props:[f,{id:S,"aria-labelledby":y,"aria-describedby":l,role:x,...hz,hidden:!m,onKeyDown(e){SH.has(e.key)&&e.stopPropagation()},style:{[CH]:g}},s],ref:[t,c.context.popupRef,T],stateAttributesMapping:TH});return(0,J.jsx)($R,{context:d,openInteractionType:v,disabled:!m,closeOnFocusOut:!u,initialFocus:C,returnFocus:a,modal:p!==!1,restoreFocus:`popup`,children:E})});process.env.NODE_ENV!==`production`&&(EH.displayName=`DialogPopup`);var DH=f.forwardRef(function(e,t){let{cutout:n,...r}=e,i;if(n){let e=n.getBoundingClientRect();i=`polygon(0% 0%,100% 0%,100% 100%,0% 100%,0% 0%,${e.left}px ${e.top}px,${e.left}px ${e.bottom}px,${e.right}px ${e.bottom}px,${e.right}px ${e.top}px,${e.left}px ${e.top}px)`}return(0,J.jsx)(`div`,{ref:t,role:`presentation`,"data-base-ui-inert":``,...r,style:{position:`fixed`,inset:0,userSelect:`none`,WebkitUserSelect:`none`,clipPath:i}})});process.env.NODE_ENV!==`production`&&(DH.displayName=`InternalBackdrop`);var OH=f.forwardRef(function(e,t){let{keepMounted:n=!1,...r}=e,i=lH(),a=i.useState(`mounted`),o=i.useState(`modal`),s=i.useState(`open`);return a||n?(0,J.jsx)(bH.Provider,{value:n,children:(0,J.jsxs)(RR,{ref:t,...r,children:[a&&o===!0&&(0,J.jsx)(DH,{ref:i.context.internalBackdropRef,inert:uV(!s)}),e.children]})}):null});process.env.NODE_ENV!==`production`&&(OH.displayName=`DialogPortal`);var kH={},AH={},jH=``;function MH(e,t){return Ax(e)?e:t}function NH(e,t,n){return/hidden|clip/.test(e.getComputedStyle(MH(t,n)).overflowY)}function PH(e){if(typeof document>`u`)return!1;let t=tL(e);return wx(t).innerWidth-t.documentElement.clientWidth>0}function FH(e){if(!(typeof CSS<`u`&&CSS.supports&&CSS.supports(`scrollbar-gutter`,`stable`))||typeof document>`u`)return!1;let t=tL(e),n=t.documentElement,r=t.body,i=MH(n,r),a=i.style.overflowY,o=n.style.scrollbarGutter;n.style.scrollbarGutter=`stable`,i.style.overflowY=`scroll`;let s=i.offsetWidth;i.style.overflowY=`hidden`;let c=i.offsetWidth;return i.style.overflowY=a,n.style.scrollbarGutter=o,s===c}function IH(e){let t=tL(e),n=t.documentElement,r=t.body,i=MH(n,r),a={overflowY:i.style.overflowY,overflowX:i.style.overflowX};return Object.assign(i.style,{overflowY:`hidden`,overflowX:`hidden`}),()=>{Object.assign(i.style,a)}}function LH(e){let t=tL(e),n=t.documentElement,r=t.body,i=wx(n),a=0,o=0,s=!1,c=$I.create();if(kF&&(i.visualViewport?.scale??1)!==1)return()=>{};function l(){let t=i.getComputedStyle(n),c=i.getComputedStyle(r),l=(t.scrollbarGutter||``).includes(`both-edges`)?`stable both-edges`:`stable`;a=n.scrollTop,o=n.scrollLeft,kH={scrollbarGutter:n.style.scrollbarGutter,overflowY:n.style.overflowY,overflowX:n.style.overflowX},jH=n.style.scrollBehavior,AH={position:r.style.position,height:r.style.height,width:r.style.width,boxSizing:r.style.boxSizing,overflowY:r.style.overflowY,overflowX:r.style.overflowX,scrollBehavior:r.style.scrollBehavior};let u=n.scrollHeight>n.clientHeight,d=n.scrollWidth>n.clientWidth,f=t.overflowY===`scroll`||c.overflowY===`scroll`,p=t.overflowX===`scroll`||c.overflowX===`scroll`,m=Math.max(0,i.innerWidth-r.clientWidth),h=Math.max(0,i.innerHeight-r.clientHeight),g=parseFloat(c.marginTop)+parseFloat(c.marginBottom),_=parseFloat(c.marginLeft)+parseFloat(c.marginRight),v=MH(n,r);s=FH(e),s?(n.style.scrollbarGutter=l,v.style.overflowY=`hidden`,v.style.overflowX=`hidden`):(Object.assign(n.style,{scrollbarGutter:l,overflowY:`hidden`,overflowX:`hidden`}),(u||f)&&(n.style.overflowY=`scroll`),(d||p)&&(n.style.overflowX=`scroll`),Object.assign(r.style,{position:`relative`,height:g||h?`calc(100dvh - ${g+h}px)`:`100dvh`,width:_||m?`calc(100vw - ${_+m}px)`:`100vw`,boxSizing:`border-box`,overflowY:`hidden`,overflowX:`hidden`,scrollBehavior:`unset`}),r.scrollTop=a,r.scrollLeft=o,n.setAttribute(`data-base-ui-scroll-locked`,``),n.style.scrollBehavior=`unset`)}function u(){Object.assign(n.style,kH),Object.assign(r.style,AH),s||(n.scrollTop=a,n.scrollLeft=o,n.removeAttribute(`data-base-ui-scroll-locked`),n.style.scrollBehavior=jH)}function d(){u(),c.request(l)}l();let f=PI(i,`resize`,d);return()=>{c.cancel(),u(),typeof i.removeEventListener==`function`&&f()}}var RH=new class{lockCount=0;restore=null;timeoutLock=gF.create();timeoutUnlock=gF.create();acquire(e){return this.lockCount+=1,this.lockCount===1&&this.restore===null&&this.timeoutLock.start(0,()=>this.lock(e)),this.release}release=()=>{--this.lockCount,this.lockCount===0&&this.restore&&this.timeoutUnlock.start(0,this.unlock)};unlock=()=>{this.lockCount===0&&this.restore&&(this.restore?.(),this.restore=null)};lock(e){if(this.lockCount===0||this.restore!==null)return;let t=tL(e),n=t.documentElement,r=t.body,i=wx(n);if(NH(i,n,r)){let t=new i.MutationObserver(()=>{NH(i,n,r)||(t.disconnect(),this.restore=null,this.lock(e))}),a={attributes:!0};t.observe(n,a),t.observe(r,a),this.restore=()=>t.disconnect();return}let a=wF||!PH(e);this.restore=a?IH(e):LH(e)}};function zH(e=!0,t=null){lF(()=>{if(e)return RH.acquire(t)},[e,t])}function BH({store:e,parentContext:t,isDrawer:n}){let r=e.useState(`open`),i=e.useState(`mounted`),a=e.useState(`disablePointerDismissal`),o=e.useState(`modal`),s=e.useState(`popupElement`),c=e.useState(`floatingRootContext`),[l,u]=f.useState(0),[d,p]=f.useState(0),m=l===0,h=oz(c,{outsidePressEvent(){return e.context.internalBackdropRef.current||e.context.backdropRef.current?`intentional`:{mouse:o===`trap-focus`?`sloppy`:`intentional`,touch:`sloppy`}},outsidePress(t){if(!e.context.outsidePressEnabledRef.current||`button`in t&&t.button!==0)return!1;if(`touches`in t){if(t.type===`touchend`){if(t.changedTouches.length!==1||t.touches.length!==0)return!1}else if(t.touches.length!==1)return!1}let n=VF(t);if(m&&!a){if(o){let t=e.context.internalBackdropRef.current,r=e.context.backdropRef.current;return t||r?t===n||r===n||zF(n,s)&&!n?.hasAttribute(`data-base-ui-portal`):!0}return!0}return!1},escapeKey:m});return zH(r&&o===!0,s),e.useContextCallback(`onNestedDialogOpen`,(t,n)=>{(e.select(`open`)||e.select(`mounted`))&&(u(t),p(n))}),lF(()=>{!r&&!i&&(u(0),p(0))},[r,i]),lF(()=>(t?.onNestedDialogOpen&&r&&t.onNestedDialogOpen(l+1,d+ +!!n),()=>{t?.onNestedDialogOpen&&r&&t.onNestedDialogOpen(0,0)}),[n,r,l,d,t]),Dz(e,{activeTriggerProps:h.reference,inactiveTriggerProps:h.trigger,popupProps:h.floating,nestedOpenDialogCount:l,nestedOpenDrawerCount:d}),null}var VH={...tB,modal:e=>e.modal,nested:e=>e.nested,nestedOpenDialogCount:e=>e.nestedOpenDialogCount,nestedOpenDrawerCount:e=>e.nestedOpenDrawerCount,disablePointerDismissal:e=>e.disablePointerDismissal,openMethod:e=>e.openMethod,descriptionElementId:e=>e.descriptionElementId,titleElementId:e=>e.titleElementId,viewportElement:e=>e.viewportElement,role:e=>e.role},HH=class extends Kz{constructor(e,t,n){let r=new jz,i=UH(e,r,t,n);super(i,WH(r),VH)}setOpen=(e,t)=>{t.preventUnmountOnClose=()=>{this.set(`preventUnmountingOnClose`,!0)},!e&&t.trigger==null&&this.state.activeTriggerId!=null&&(t.trigger=this.state.activeTriggerElement??void 0),this.context.onOpenChange?.(e,t),t.isCanceled||(this.state.floatingRootContext.dispatchOpenChange(e,t),this.update(xz(this.state,e,t.trigger)))}};function UH(e,t,n,r=!1){return{...Yz(t,n,r),modal:!0,disablePointerDismissal:!1,viewportElement:null,descriptionElementId:void 0,titleElementId:void 0,openMethod:null,nested:!1,nestedOpenDialogCount:0,nestedOpenDrawerCount:0,role:`dialog`,...e}}function WH(e){return{popupRef:f.createRef(),backdropRef:f.createRef(),internalBackdropRef:f.createRef(),outsidePressEnabledRef:{current:!0},triggerElements:e,onOpenChange:void 0,onOpenChangeComplete:void 0}}function GH(e,t){let{children:n,open:r,defaultOpen:i=!1,onOpenChange:a,onOpenChangeComplete:o,disablePointerDismissal:s=!1,modal:c=!0,actionsRef:l,handle:u,triggerId:d,defaultTriggerId:p=null}=t,m=e===`drawer`,h=e===`alert-dialog`,g=h?!0:c,_=h||s,v=h?`alertdialog`:`dialog`,y=lH(!0),b={modal:g,disablePointerDismissal:_,nested:y!=null,role:v},x=_z((e,t)=>new HH({open:i,openProp:r,activeTriggerId:p,triggerIdProp:d,...b},e,t),!0);x.useControlledProp(`openProp`,r),x.useControlledProp(`triggerIdProp`,d),x.useSyncedValues(b),x.useContextCallback(`onOpenChange`,a),x.useContextCallback(`onOpenChangeComplete`,o);let S=x.useState(`open`),C=x.useState(`mounted`),w=x.useState(`payload`);Oz(x,S),Tz(x);let{forceUnmount:T}=Ez(S,x);f.useImperativeHandle(l,()=>({unmount:T,close:()=>x.setOpen(!1,yI(kI))}),[T,x]);let E=S||C||u!=null;return(0,J.jsxs)(cH.Provider,{value:x,children:[u&&(0,J.jsx)(vz,{handle:u,store:x}),E&&(0,J.jsx)(BH,{store:x,parentContext:y?.context,isDrawer:m}),typeof n==`function`?n({payload:w}):n]})}var KH=rF(function(e){return GH(`dialog`,e)});process.env.NODE_ENV!==`production`&&(KH.displayName=`DialogRoot`);var qH=f.forwardRef(function(e,t){let{render:n,className:r,style:i,id:a,...o}=e,s=lH(),c=DB(a);return s.useSyncedValueWithCleanup(`titleElementId`,c),bR(`h2`,e,{ref:t,props:[{id:c},o]})});process.env.NODE_ENV!==`production`&&(qH.displayName=`DialogTitle`);function JH(e){let t=f.useRef(``),n=f.useCallback(n=>{n.defaultPrevented||(t.current=n.pointerType,e(n,n.pointerType))},[e]);return{onClick:f.useCallback(n=>{n.detail===0?e(n,`keyboard`):(`pointerType`in n?e(n,n.pointerType):e(n,t.current),t.current=``)},[e]),onPointerDown:n}}function YH(e,t){let{onClick:n,onPointerDown:r}=JH(qI((n,r)=>{(typeof e==`function`?e():e)||t(r||(wF?`touch`:``))}));return f.useMemo(()=>({onClick:n,onPointerDown:r}),[n,r])}var XH=iF(function(e,t){let{render:n,className:r,style:i,disabled:a=!1,nativeButton:o=!0,id:s,payload:c,handle:l,...u}=e,d=lH(!0),p=nB(l)??d;if(!p)throw Error(process.env.NODE_ENV===`production`?dF(79):`Base UI: <Dialog.Trigger> must be used within <Dialog.Root> or provided with a handle.`);let m=DB(s),h=p.useState(`floatingRootContext`),g=p.useState(`isOpenedByTrigger`,m),_=p.useState(`triggerPopupId`,m),v=f.useRef(null),{registerTrigger:y,isMountedByThisTrigger:b}=wz(m,v,p,{payload:c}),{getButtonProps:x,buttonRef:S}=gH({disabled:a,native:o}),C=ez(h),w=YH(()=>p.select(`open`),e=>{p.set(`openMethod`,e)}),T={disabled:a,open:g},E=p.useState(`triggerProps`,b);return bR(`button`,e,{state:T,ref:[S,t,y,v],props:[C.reference,E,w,{[jR]:``,id:m,"aria-haspopup":`dialog`,"aria-expanded":g,"aria-controls":_},u,x],stateAttributesMapping:nI})});process.env.NODE_ENV!==`production`&&(XH.displayName=`DialogTrigger`);var ZH=f.forwardRef(function(e,t){let{render:n,className:r,disabled:i=!1,focusableWhenDisabled:a=!1,nativeButton:o=!0,style:s,...c}=e,{getButtonProps:l,buttonRef:u}=gH({disabled:i,focusableWhenDisabled:a,native:o});return bR(`button`,e,{state:{disabled:i},ref:[t,u],props:[c,l]})});process.env.NODE_ENV!==`production`&&(ZH.displayName=`Button`);function QH(e){var t,n,r=``;if(typeof e==`string`||typeof e==`number`)r+=e;else if(typeof e==`object`){if(Array.isArray(e)){var i=e.length;for(t=0;t<i;t++)e[t]&&(n=QH(e[t]))&&(r&&(r+=` `),r+=n)}else for(n in e)e[n]&&(r&&(r+=` `),r+=n)}return r}function $H(){for(var e,t,n=0,r=``,i=arguments.length;n<i;n++)(e=arguments[n])&&(t=QH(e))&&(r&&(r+=` `),r+=t);return r}var eU=e=>typeof e==`boolean`?`${e}`:e===0?`0`:e,tU=$H,nU=(e,t)=>n=>{if(t?.variants==null)return tU(e,n?.class,n?.className);let{variants:r,defaultVariants:i}=t,a=Object.keys(r).map(e=>{let t=n?.[e],a=i?.[e];if(t===null)return null;let o=eU(t)||eU(a);return r[e][o]}),o=n&&Object.entries(n).reduce((e,t)=>{let[n,r]=t;return r===void 0||(e[n]=r),e},{});return tU(e,a,t?.compoundVariants?.reduce((e,t)=>{let{class:n,className:r,...a}=t;return Object.entries(a).every(e=>{let[t,n]=e;return Array.isArray(n)?n.includes({...i,...o}[t]):{...i,...o}[t]===n})?[...e,n,r]:e},[]),n?.class,n?.className)},rU=nU(`group/button inline-flex shrink-0 items-center justify-center rounded-lg border border-transparent bg-clip-padding text-sm font-medium whitespace-nowrap transition-all outline-none select-none focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 active:not-aria-[haspopup]:translate-y-px disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4`,{variants:{variant:{default:`bg-primary text-primary-foreground hover:bg-primary/80`,outline:`border-border bg-background hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:border-input dark:bg-input/30 dark:hover:bg-input/50`,secondary:`bg-secondary text-secondary-foreground hover:bg-[color-mix(in_oklch,var(--secondary),var(--foreground)_5%)] aria-expanded:bg-secondary aria-expanded:text-secondary-foreground`,ghost:`hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:hover:bg-muted/50`,destructive:`bg-destructive/10 text-destructive hover:bg-destructive/20 focus-visible:border-destructive/40 focus-visible:ring-destructive/20 dark:bg-destructive/20 dark:hover:bg-destructive/30 dark:focus-visible:ring-destructive/40`,link:`text-primary underline-offset-4 hover:underline`},size:{default:`h-8 gap-1.5 px-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2`,xs:`h-6 gap-1 rounded-[min(var(--radius-md),10px)] px-2 text-xs in-data-[slot=button-group]:rounded-lg has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&_svg:not([class*='size-'])]:size-3`,sm:`h-7 gap-1 rounded-[min(var(--radius-md),12px)] px-2.5 text-[0.8rem] in-data-[slot=button-group]:rounded-lg has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&_svg:not([class*='size-'])]:size-3.5`,lg:`h-9 gap-1.5 px-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2`,icon:`size-8`,"icon-xs":`size-6 rounded-[min(var(--radius-md),10px)] in-data-[slot=button-group]:rounded-lg [&_svg:not([class*='size-'])]:size-3`,"icon-sm":`size-7 rounded-[min(var(--radius-md),12px)] in-data-[slot=button-group]:rounded-lg`,"icon-lg":`size-9`}},defaultVariants:{variant:`default`,size:`default`}}),iU=f.forwardRef(({className:e,variant:t=`default`,size:n=`default`,...r},i)=>(0,J.jsx)(ZH,{ref:i,"data-slot":`button`,className:Q(rU({variant:t,size:n,className:e})),...r}));iU.displayName=`Button`;function aU({...e}){return(0,J.jsx)(KH,{"data-slot":`dialog`,...e})}function oU({...e}){return(0,J.jsx)(XH,{"data-slot":`dialog-trigger`,...e})}function sU({...e}){return(0,J.jsx)(OH,{"data-slot":`dialog-portal`,...e})}function cU({className:e,...t}){return(0,J.jsx)(uH,{"data-slot":`dialog-overlay`,className:Q(`fixed inset-0 isolate z-50 bg-black/10 duration-100 supports-backdrop-filter:backdrop-blur-xs data-open:animate-in data-open:fade-in-0 data-closed:animate-out data-closed:fade-out-0`,e),...t})}function lU({className:e,children:t,showCloseButton:n=!0,...r}){return(0,J.jsxs)(sU,{children:[(0,J.jsx)(cU,{}),(0,J.jsxs)(EH,{"data-slot":`dialog-content`,className:Q(`fixed top-1/2 left-1/2 z-50 grid w-full max-w-[calc(100%-2rem)] -translate-x-1/2 -translate-y-1/2 gap-4 rounded-xl bg-popover p-4 text-sm text-popover-foreground ring-1 ring-foreground/10 duration-100 outline-none sm:max-w-sm data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95`,e),...r,children:[t,n&&(0,J.jsxs)(yH,{"data-slot":`dialog-close`,render:(0,J.jsx)(iU,{variant:`ghost`,className:`absolute top-2 right-2`,size:`icon-sm`}),children:[(0,J.jsx)(XP,{}),(0,J.jsx)(`span`,{className:`sr-only`,children:`Close`})]})]})]})}function uU({className:e,...t}){return(0,J.jsx)(qH,{"data-slot":`dialog-title`,className:Q(`font-heading text-base leading-none font-medium`,e),...t})}var dU=f.createContext(void 0);process.env.NODE_ENV!==`production`&&(dU.displayName=`AvatarRootContext`);function fU(){let e=f.useContext(dU);if(e===void 0)throw Error(process.env.NODE_ENV===`production`?dF(13):`Base UI: AvatarRootContext is missing. Avatar parts must be placed within <Avatar.Root>.`);return e}var pU={imageLoadingStatus:()=>null},mU=f.forwardRef(function(e,t){let{className:n,render:r,style:i,...a}=e,[o,s]=f.useState(`idle`),c={imageLoadingStatus:o},l=f.useMemo(()=>({imageLoadingStatus:o,setImageLoadingStatus:s}),[o,s]),u=bR(`span`,e,{state:c,ref:t,props:a,stateAttributesMapping:pU});return(0,J.jsx)(dU.Provider,{value:l,children:u})});process.env.NODE_ENV!==`production`&&(mU.displayName=`AvatarRoot`);function hU(e,{referrerPolicy:t,crossOrigin:n,sizes:r,srcSet:i},a){let o=f.useState(`idle`),s=o[1];return lF(()=>{if(!a)return oF;if(!e&&!i)return s(`error`),oF;let o=!0,c=new window.Image,l=e=>()=>{o&&s(e)};return s(`loading`),c.onload=l(`loaded`),c.onerror=l(`error`),t&&(c.referrerPolicy=t),c.crossOrigin=n??null,r&&(c.sizes=r),i&&(c.srcset=i),e&&(c.src=e),c.complete&&s(c.naturalWidth>0?`loaded`:`error`),()=>{o=!1}},[a,e,i,r,n,t,s]),o}var gU={...pU,...JF},_U=f.forwardRef(function(e,t){let{className:n,render:r,onLoadingStatusChange:i,keepMounted:a=!1,style:o,sizes:s,srcSet:c,src:l,...u}=e,{setImageLoadingStatus:d}=fU(),[p,m]=hU(l,e,!a),h=p===`loaded`,{mounted:g,transitionStatus:_,setMounted:v}=cz(h),y=f.useRef(null),b=f.useRef(!0);lF(()=>{if(!a)return;let e=b.current;b.current=!1;let t=y.current;if(!t)return;if(!t.complete){m(`loading`);return}let n=t.naturalWidth>0?`loaded`:`error`;m(n),n===`loaded`&&e&&v(!0)},[a,l,c,s,u.crossOrigin,u.referrerPolicy,r,m,v]);let x=a?{"data-loading":p===`loading`?``:void 0,"data-error":p===`error`?``:void 0,"aria-hidden":p!==`loaded`||void 0,onLoad(){m(`loaded`)},onError(){m(`error`)}}:void 0,S=qI(e=>{i?.(e),d(e)});lF(()=>{p!==`idle`&&S(p)},[p,S]),lF(()=>()=>d(`idle`),[d]),pz({enabled:!h,open:h,ref:y,onComplete(){h||v(!1)}});let C={imageLoadingStatus:p,transitionStatus:a&&_===`ending`?void 0:_},w=a||g,T={};s!==void 0&&(T.sizes=s),c!==void 0&&(T.srcSet=c),l!==void 0&&(T.src=l);let E=bR(`img`,e,{state:C,ref:[t,y],props:[x,u,T],stateAttributesMapping:gU,enabled:w});return w?E:null});process.env.NODE_ENV!==`production`&&(_U.displayName=`AvatarImage`);var vU=f.forwardRef(function(e,t){let{className:n,render:r,delay:i=0,style:a,...o}=e,{imageLoadingStatus:s}=fU(),[c,l]=f.useState(i===0),u=_F();return f.useEffect(()=>(i>0?u.start(i,()=>l(!0)):l(!0),u.clear),[u,i]),bR(`span`,e,{state:{imageLoadingStatus:s},ref:t,props:o,stateAttributesMapping:pU,enabled:s!==`loaded`&&(i===0||c)})});process.env.NODE_ENV!==`production`&&(vU.displayName=`AvatarFallback`);function yU({className:e,size:t=`default`,...n}){return(0,J.jsx)(mU,{"data-slot":`avatar`,"data-size":t,className:Q(`group/avatar relative flex size-8 shrink-0 rounded-full select-none after:absolute after:inset-0 after:rounded-full after:border after:border-border after:mix-blend-darken data-[size=lg]:size-10 data-[size=sm]:size-6 dark:after:mix-blend-lighten`,e),...n})}function bU({className:e,...t}){return(0,J.jsx)(_U,{"data-slot":`avatar-image`,className:Q(`aspect-square size-full rounded-full object-cover`,e),...t})}function xU({className:e,...t}){return(0,J.jsx)(vU,{"data-slot":`avatar-fallback`,className:Q(`flex size-full items-center justify-center rounded-full bg-muted text-sm text-muted-foreground group-data-[size=sm]/avatar:text-xs`,e),...t})}var SU=(0,f.forwardRef)(({children:e,tooltip:t,side:n=`bottom`,className:r,...i},a)=>(0,J.jsx)(iH,{children:(0,J.jsxs)(aH,{children:[(0,J.jsxs)(oH,{render:(0,J.jsx)(iU,{variant:`ghost`,size:`icon`,...i,className:Q(`aui-button-icon size-6 p-1 active:scale-90`,r),ref:a}),children:[e,(0,J.jsx)(`span`,{className:`aui-sr-only sr-only`,children:t})]}),(0,J.jsx)(sH,{side:n,children:t})]})}));SU.displayName=`TooltipIconButton`;var CU=e=>Symbol.iterator in e,wU=e=>`entries`in e,TU=(e,t)=>{let n=e instanceof Map?e:new Map(e.entries()),r=t instanceof Map?t:new Map(t.entries());if(n.size!==r.size)return!1;for(let[e,t]of n)if(!r.has(e)||!Object.is(t,r.get(e)))return!1;return!0},EU=(e,t)=>{let n=e[Symbol.iterator](),r=t[Symbol.iterator](),i=n.next(),a=r.next();for(;!i.done&&!a.done;){if(!Object.is(i.value,a.value))return!1;i=n.next(),a=r.next()}return!!i.done&&!!a.done};function DU(e,t){return Object.is(e,t)?!0:typeof e!=`object`||!e||typeof t!=`object`||!t||Object.getPrototypeOf(e)!==Object.getPrototypeOf(t)?!1:CU(e)&&CU(t)?wU(e)&&wU(t)?TU(e,t):EU(e,t):TU({entries:()=>Object.entries(e)},{entries:()=>Object.entries(t)})}function OU(e){let t=f.default.useRef(void 0);return n=>{let r=e(n);return DU(t.current,r)?t.current:t.current=r}}var kU=e=>{let[t,n]=(0,f.useState)(void 0);return(0,f.useEffect)(()=>{if(!e){n(void 0);return}let t=URL.createObjectURL(e);return n({file:e,url:t}),()=>{URL.revokeObjectURL(t)}},[e]),t!==void 0&&t.file===e?t.url:void 0},AU=()=>{let{file:e,src:t}=q(OU(e=>{if(e.attachment.type!==`image`)return{};if(e.attachment.file)return{file:e.attachment.file};let t=e.attachment.content?.filter(e=>e.type===`image`)[0]?.image;return t?{src:t}:{}}));return kU(e)??t};function jU(){let e=K().attachment.source!==`message`,t=AU(),n=q(e=>e.attachment.type===`image`),r=q(e=>e.attachment.name),i=q(e=>{let t=e.attachment.type;switch(t){case`image`:return`Image`;case`document`:return`Document`;case`file`:return`File`;default:return t}}),a=q(e=>e.attachment.status.type===`incomplete`&&e.attachment.status.reason===`error`?`error`:e.attachment.status.type===`running`||e.optional.message?.submission!==void 0&&e.attachment.status.type!==`complete`?`uploading`:void 0);return{isComposer:e,src:t,isImage:n,name:r,typeLabel:i,isUploading:a===`uploading`,isError:a===`error`,errorMessage:q(e=>e.attachment.status.type===`incomplete`&&e.attachment.status.reason===`error`?e.attachment.status.message??`Upload failed`:void 0)}}var MU=({src:e,name:t})=>{let[n,r]=(0,f.useState)(!1);return(0,J.jsx)(`img`,{src:e,alt:`Preview of ${t}`,className:Q(`block h-auto max-h-[80vh] w-auto max-w-full rounded-sm object-contain transition-opacity duration-300 motion-reduce:transition-none`,n?`aui-attachment-preview-image-loaded opacity-100`:`aui-attachment-preview-image-loading opacity-0`),onLoad:()=>r(!0)})},NU=({children:e,src:t,name:n})=>t?(0,J.jsxs)(aU,{children:[(0,J.jsx)(oU,{nativeButton:!1,className:`aui-attachment-preview-trigger cursor-zoom-in`,render:(0,f.isValidElement)(e)?e:(0,J.jsx)(`button`,{type:`button`,children:e})}),(0,J.jsxs)(lU,{className:`aui-attachment-preview-dialog-content [&>button]:bg-foreground/60 [&>button]:hover:bg-foreground/80 [&_svg]:text-background p-2 sm:max-w-3xl [&>button]:rounded-full [&>button]:p-1 [&>button]:opacity-100 [&>button]:ring-0!`,children:[(0,J.jsxs)(uU,{className:`aui-sr-only sr-only`,children:[`Preview `,n]}),(0,J.jsx)(`div`,{className:`aui-attachment-preview bg-background relative mx-auto flex max-h-[80dvh] w-full items-center justify-center overflow-hidden rounded-sm`,children:(0,J.jsx)(MU,{src:t,name:n})})]})]}):e,PU=({src:e})=>(0,J.jsxs)(yU,{className:`aui-attachment-tile-avatar h-full w-full rounded-none after:hidden`,children:[(0,J.jsx)(bU,{src:e,alt:``,className:`aui-attachment-tile-image rounded-none object-cover`}),(0,J.jsx)(xU,{children:(0,J.jsx)(cP,{className:`aui-attachment-tile-fallback-icon text-muted-foreground/80 size-6 stroke-[1.5]`})})]}),FU=()=>{let{isComposer:e,src:t,isImage:n,name:r,typeLabel:i,isUploading:a,isError:o,errorMessage:s}=jU();return(0,J.jsx)(iH,{children:(0,J.jsxs)(aH,{children:[(0,J.jsxs)(YD.Root,{className:Q(`aui-attachment-root relative`,e&&`animate-in fade-in-0 zoom-in-95 duration-200 motion-reduce:animate-none`,n&&!e&&`aui-attachment-root-message only:*:first:size-24`),children:[(0,J.jsx)(NU,{src:t,name:r,children:(0,J.jsxs)(oH,{render:(0,J.jsx)(`div`,{className:Q(`aui-attachment-tile bg-muted hover:after:bg-foreground/10 focus-visible:ring-ring/50 relative size-14 overflow-hidden rounded-[calc(var(--composer-radius,1rem)-var(--composer-padding,8px))] transition-transform outline-none after:pointer-events-none after:absolute after:inset-0 after:rounded-[inherit] after:ring-1 after:ring-black/10 after:transition-colors after:ring-inset focus-visible:ring-1 motion-reduce:transition-none dark:after:ring-white/10`,t?`cursor-zoom-in active:scale-[0.96]`:`cursor-default`,o&&`after:ring-destructive/60 dark:after:ring-destructive/60`),role:t?`button`:`group`,tabIndex:0,"aria-label":`${t?`Preview ${r}`:`${i} attachment ${r}`}${o?`, upload failed`:a?`, uploading`:``}`}),children:[(0,J.jsx)(PU,{src:t}),a&&(0,J.jsx)(`div`,{"aria-hidden":`true`,className:`aui-attachment-tile-uploading bg-background/60 animate-in fade-in-0 absolute inset-0 flex items-center justify-center backdrop-blur-[2px] motion-reduce:animate-none`,children:(0,J.jsx)(gP,{className:`text-muted-foreground size-4 animate-spin`})}),o&&(0,J.jsx)(`div`,{"aria-hidden":`true`,className:`aui-attachment-tile-error bg-background/70 animate-in fade-in-0 absolute inset-0 flex items-center justify-center backdrop-blur-[2px] motion-reduce:animate-none`,children:(0,J.jsx)(JN,{className:`text-destructive size-4`})})]})}),e&&(0,J.jsx)(IU,{name:r})]}),(0,J.jsxs)(sH,{side:`top`,children:[(0,J.jsx)(YD.Name,{}),s&&(0,J.jsx)(`p`,{className:`aui-attachment-error-message`,children:s})]})]})})},IU=({name:e})=>(0,J.jsx)(YD.Remove,{render:(0,J.jsx)(SU,{tooltip:`Remove ${e}`,className:`aui-attachment-tile-remove absolute end-1 top-1 size-5 rounded-full bg-black/50! text-white after:absolute after:-inset-1.5 hover:bg-black/70! hover:text-white! active:scale-[0.96] motion-reduce:transition-none`,side:`top`}),children:(0,J.jsx)(XP,{className:`aui-attachment-remove-icon size-3 stroke-[2.5]`})}),LU=()=>(0,J.jsx)(`div`,{className:`aui-user-message-attachments-end col-span-full col-start-1 row-start-1 flex w-full flex-row justify-end gap-2 empty:hidden`,children:(0,J.jsx)(_j.Attachments,{children:()=>(0,J.jsx)(FU,{})})}),RU=()=>(0,J.jsx)(`div`,{className:`aui-composer-attachments flex w-full flex-row items-center gap-2 overflow-x-auto empty:hidden`,children:(0,J.jsx)(lA.Attachments,{children:()=>(0,J.jsx)(FU,{})})}),zU=()=>(0,J.jsx)(lA.AddAttachment,{render:(0,J.jsx)(SU,{tooltip:`Add Attachment`,side:`bottom`,variant:`ghost`,size:`icon`,className:`aui-composer-add-attachment text-muted-foreground hover:text-foreground hover:bg-muted-foreground/15 dark:border-muted-foreground/15 dark:hover:bg-muted-foreground/30 size-7 rounded-full active:scale-[0.96] motion-reduce:transition-none`,"aria-label":`Add Attachment`}),children:(0,J.jsx)(PP,{className:`aui-attachment-add-icon size-4`})}),BU=globalThis.window===void 0?f.useEffect:f.useLayoutEffect,VU=`bg-background border border-border/60 dark:bg-popover`,HU=`bg-foreground/[0.04] forced-colors:border dark:bg-foreground/[0.06]`,UU=`bg-foreground text-background transition-[opacity,scale] duration-150 ease-[cubic-bezier(0.23,1,0.32,1)] hover:opacity-90 active:scale-[0.96] motion-reduce:transition-none forced-colors:border`,WU=`font-mono text-[11px] tracking-tight`;function GU(e){let t=Math.max(0,Math.floor(e));return`${Math.floor(t/60)}:${(t%60).toString().padStart(2,`0`)}`}function KU(e,t,n){let[r,i]=(0,f.useState)({src:t});(0,f.useEffect)(()=>{let n=e.current;!n||n.readyState<HTMLMediaElement.HAVE_METADATA||Number.isFinite(n.duration)&&n.duration>=0&&i({src:t,duration:n.duration})},[e,t]);let a=n!==void 0&&Number.isFinite(n)?Math.max(0,n/1e3):void 0;return{duration:r.src===t?r.duration??a:a,setDurationFromMetadata:e=>{Number.isFinite(e)&&e>=0&&i({src:t,duration:e})}}}function qU({src:e,title:t,artwork:n,durationMs:r,className:i,...a}){let o=(0,f.useRef)(null),[s,c]=(0,f.useState)({src:e,currentTime:0,playing:!1,hasError:!1}),{duration:l,setDurationFromMetadata:u}=KU(o,e,r),{currentTime:d,playing:p,hasError:m}=s.src===e?s:{src:e,currentTime:0,playing:!1,hasError:!1},h=t=>c(n=>({...n.src===e?n:{src:e,currentTime:0,playing:!1,hasError:!1},...t})),g=t??`Audio`,_=t?` ${t}`:` audio`,v=l===void 0?`--:--`:GU(l);(0,f.useEffect)(()=>{o.current?.error&&c({src:e,currentTime:0,playing:!1,hasError:!0})},[e]);let y=()=>{let e=o.current;e&&!m&&(p?(e.pause(),h({playing:!1})):e.play().then(()=>h({playing:!0}),()=>h(e.error?{hasError:!0,playing:!1}:{playing:!1})))};return(0,J.jsxs)(`div`,{"data-slot":`audio-player`,className:Q(VU,`flex w-full max-w-md items-center gap-3 rounded-2xl p-3`,i),...a,children:[n?(0,J.jsx)(`img`,{src:n,alt:``,className:`size-10 shrink-0 rounded-lg object-cover`}):null,(0,J.jsx)(`button`,{type:`button`,"aria-label":`${p?`Pause`:`Play`}${_}`,disabled:m,onClick:y,className:Q(UU,`flex size-9 shrink-0 items-center justify-center rounded-full disabled:cursor-default disabled:opacity-40`),children:p?(0,J.jsx)(EP,{"aria-hidden":!0,className:`size-4`}):(0,J.jsx)(MP,{"aria-hidden":!0,className:`ml-0.5 size-4`})}),(0,J.jsxs)(`div`,{className:`flex min-w-0 grow basis-16 flex-col gap-1.5`,children:[(0,J.jsx)(`span`,{className:`truncate text-[13.5px] font-medium`,children:g}),(0,J.jsx)(`input`,{type:`range`,min:0,max:l??0,step:.1,value:Math.min(d,l??0),"aria-label":`Seek`,"aria-valuetext":`${GU(d)} of ${v}`,disabled:m,onChange:e=>{let t=Number(e.currentTarget.value);if(!Number.isFinite(t))return;let n=Math.min(t,l??t);o.current&&(o.current.currentTime=n),h({currentTime:n})},className:`accent-foreground w-full`})]}),(0,J.jsxs)(`span`,{className:Q(WU,`text-muted-foreground tabular-nums`),children:[GU(d),`\xA0/ `,v]}),(0,J.jsx)(`audio`,{ref:o,src:e,preload:`metadata`,className:`hidden`,onLoadedMetadata:e=>{u(e.currentTarget.duration)},onTimeUpdate:e=>h({currentTime:e.currentTarget.currentTime}),onPlay:()=>h({playing:!0}),onPause:()=>h({playing:!1}),onError:()=>h({hasError:!0,playing:!1})}),m?(0,J.jsx)(`span`,{role:`alert`,className:`text-muted-foreground text-xs`,children:`Can't play this audio`}):null]})}function JU({src:e,poster:t,title:n,ratio:r=`16:9`,durationMs:i,className:a,...o}){let s=(0,f.useRef)(null),{duration:c,setDurationFromMetadata:l}=KU(s,e,i),u=r===`1:1`?`aspect-square`:r===`4:3`?`aspect-[4/3]`:r===`16:9`?`aspect-video`:r===`9:16`?`aspect-[9/16]`:void 0;return(0,J.jsxs)(`div`,{"data-slot":`video-player`,className:Q(`flex w-full max-w-xl flex-col gap-2`,a),...o,children:[(0,J.jsx)(`div`,{className:Q(HU,`overflow-hidden rounded-xl`,u),children:(0,J.jsx)(`video`,{ref:s,src:e,poster:t,controls:!0,playsInline:!0,preload:`metadata`,"aria-label":n??`Video`,className:Q(`block max-w-full`,r!==`auto`&&`h-full w-full object-contain`),onLoadedMetadata:e=>{l(e.currentTarget.duration)}})}),(n||c!==void 0)&&(0,J.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2 px-1`,children:[n?(0,J.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[13.5px] font-medium`,children:n}):null,c===void 0?null:(0,J.jsx)(`span`,{className:Q(`font-mono text-[11px] tracking-tight`,`text-muted-foreground shrink-0 tabular-nums`),children:GU(c)})]})]})}var YU=nU(`aui-file-root inline-flex items-center gap-3 rounded-lg transition-colors`,{variants:{variant:{outline:`border-border hover:bg-muted/50 border`,ghost:`hover:bg-muted/50`,muted:`bg-muted/50 hover:bg-muted/70`},size:{sm:`px-2.5 py-1.5 text-xs`,default:`px-3 py-2 text-sm`,lg:`px-4 py-3 text-base`}},defaultVariants:{variant:`outline`,size:`default`}});function XU(e){let t=e.toLowerCase();return t.startsWith(`image/`)?mP:t===`application/pdf`?cP:t===`application/json`?IN:t.startsWith(`text/`)?cP:t.startsWith(`audio/`)?iP:t.startsWith(`video/`)?JP:uP}function ZU(e,t){return t===`url`&&/^data:/i.test(e)?`data-uri`:t||(/^data:/i.test(e)?`data-uri`:/^(https?:\/\/|blob:)/i.test(e)?`url`:`base64`)}function QU(e){return/^[a-z][a-z\d+.-]*:/i.test(e)&&!/^(data:|https?:\/\/|blob:)/i.test(e)}function $U(e,t,n){if(QU(e))return null;let r=ZU(e,n);return r===`id`?null:r===`data-uri`?/^data:[^,]*,/i.test(e)?e:null:r===`url`?/^(https?:\/\/|blob:)/i.test(e)?e:null:`data:${t};base64,${e}`}function eW(e){let t=e.endsWith(`==`)?2:+!!e.endsWith(`=`),n=e.search(/[^A-Za-z\d+/]/);return n!==-1&&n!==e.length-t||e.length%4==1||t>0&&e.length%4!=0?0:Math.floor(e.length*3/4)-t}function tW(e){return eW(/[\t\n\f\r ]/.test(e)?e.replace(/[\t\n\f\r ]/g,``):e)}function nW(e){let t=e.indexOf(`#`),n=t<0?e.length:t,r=e.indexOf(`,`);if(r<0||r>=n)return 0;let i=e.slice(r+1,n);return/;base64$/i.test(e.slice(0,r))?(/[%\t\n\f\r ]/.test(i)&&(i=i.replace(/%([\da-f]{2})/gi,(e,t)=>String.fromCharCode(Number.parseInt(t,16))).replace(/[\t\n\f\r ]/g,``)),eW(i)):new TextEncoder().encode(i.replace(/%[\da-f]{2}/gi,`_`)).byteLength}function rW(e){let t=/^[^/;]+\/(?:x-)?(?:[^;+]*\.)?([^;+.\s]+)/.exec(e.toLowerCase())?.[1];return!t||t===`octet-stream`?`文件`:t===`plain`?`文本文件`:`${t.toUpperCase()} 文件`}function iW(e){return e<1024?`${e} B`:e<1048576?`${(e/1024).toFixed(1)} KB`:`${(e/1048576).toFixed(1)} MB`}function aW({className:e,variant:t,size:n,children:r,...i}){return(0,J.jsx)(`div`,{"data-slot":`file-root`,"data-variant":t,"data-size":n,className:Q(YU({variant:t,size:n,className:e})),...i,children:r})}function oW({mimeType:e,className:t,children:n,...r}){let i=e?XU(e):uP;return(0,J.jsx)(`span`,{"data-slot":`file-icon`,className:Q(`text-muted-foreground shrink-0`,t),...r,children:n??(0,J.jsx)(i,{className:`size-5`})})}function sW({className:e,children:t,...n}){return(0,J.jsx)(`span`,{"data-slot":`file-name`,className:Q(`min-w-0 flex-1 truncate font-medium`,e),...n,children:t||`未命名文件`})}function cW({bytes:e,className:t,...n}){return(0,J.jsx)(`span`,{"data-slot":`file-size`,className:Q(`text-muted-foreground shrink-0`,t),...n,children:iW(e)})}function lW({data:e,mimeType:t,filename:n,sourceType:r,className:i,children:a,...o}){if(typeof e!=`string`)return null;let s=ZU(e,r),c=$U(e,t,r);return c?(0,J.jsx)(`a`,{"data-slot":`file-download`,href:c,download:n||`download`,...s===`url`&&{target:`_blank`,rel:`noopener noreferrer`},className:Q(`text-muted-foreground hover:bg-accent hover:text-accent-foreground shrink-0 rounded-md p-1 transition-colors`,i),"aria-label":a?void 0:`下载 ${n||`文件`}`,...o,children:a||(0,J.jsx)(nP,{className:`size-4`})}):null}function uW({data:e,mimeType:t,filename:n,sourceType:r,className:i,...a}){let o=$U(e,t,r),s=t.toLowerCase();return!o||!s.startsWith(`audio/`)&&!s.startsWith(`video/`)?null:(0,J.jsx)(`div`,{"data-slot":`file-player`,className:Q(`w-full`,i),...a,children:s.startsWith(`audio/`)?(0,J.jsx)(qU,{src:o,title:n}):(0,J.jsx)(JU,{src:o,title:n})})}var dW=(0,f.memo)(({filename:e,data:t,mimeType:n,sourceType:r})=>{let i=ZU(t,r),a=typeof t==`string`&&(i===`base64`||i===`data-uri`),o=$U(t,n,r),s=n.toLowerCase().startsWith(`audio/`)||n.toLowerCase().startsWith(`video/`);return o&&s?(0,J.jsxs)(`div`,{className:`flex w-full max-w-xl flex-col gap-2`,children:[(0,J.jsx)(uW,{data:t,mimeType:n,...e!==void 0&&{filename:e},...r!==void 0&&{sourceType:r}}),(0,J.jsxs)(`div`,{className:`flex min-w-0 items-center justify-end gap-2 px-1`,children:[a&&(0,J.jsx)(cW,{bytes:i===`data-uri`?nW(t):tW(t),className:`text-muted-foreground text-[11px]`}),(0,J.jsx)(lW,{data:t,mimeType:n,...e!==void 0&&{filename:e},...r!==void 0&&{sourceType:r}})]})]}):(0,J.jsxs)(aW,{children:[(0,J.jsx)(oW,{mimeType:n}),(0,J.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col gap-0.5`,children:[(0,J.jsx)(sW,{children:e||rW(n)}),a&&(0,J.jsx)(cW,{bytes:i===`data-uri`?nW(t):tW(t),className:`text-xs`})]}),(0,J.jsx)(lW,{data:t,mimeType:n,...e!==void 0&&{filename:e},...r!==void 0&&{sourceType:r}})]})});dW.displayName=`File`,dW.Root=aW,dW.Icon=oW,dW.Name=sW,dW.Size=cW,dW.Download=lW,dW.Player=uW;var fW=()=>{let e=q(e=>e.thread.suggestions),t=(0,f.useRef)(null),n=(0,f.useRef)(null),[r,i]=(0,f.useState)({left:!1,right:!1}),a=(0,f.useCallback)(()=>{let e=t.current;if(!e)return;let r=e.scrollWidth-e.clientWidth,a=Math.abs(e.scrollLeft),[o,s]=(n.current??=getComputedStyle(e).direction===`rtl`)?[r-a,a]:[a,r-a];i(e=>{let t={left:o>1,right:s>1};return e.left===t.left&&e.right===t.right?e:t})},[]);(0,f.useEffect)(()=>{a();let e=t.current;if(!e?.firstElementChild)return;let n=new ResizeObserver(a);return n.observe(e),n.observe(e.firstElementChild),()=>n.disconnect()},[a]);let o=`linear-gradient(to right, ${r.left?`transparent, black 2rem`:`black`}, ${r.right?`black calc(100% - 2rem), transparent`:`black`})`;return(0,J.jsx)(`div`,{ref:t,onScroll:a,role:`group`,"aria-label":`后续问题建议`,className:`aui-thread-followup-suggestions -my-1 w-full [scrollbar-width:none] overflow-x-auto py-1 [-ms-overflow-style:none] [&::-webkit-scrollbar]:hidden`,style:{maskImage:o,WebkitMaskImage:o},children:(0,J.jsx)(`div`,{className:`mx-auto flex min-h-8 w-max items-center gap-2 px-0.5`,children:e.map((e,t)=>(0,J.jsxs)(rM.Suggestion,{className:`aui-thread-followup-suggestion border-foreground/10 hover:bg-foreground/[0.03] hover:border-foreground/25 rounded-md border px-2.5 py-1 text-sm whitespace-nowrap transition-colors ease-in motion-reduce:transition-none`,prompt:e.prompt,send:!0,children:[e.title??e.prompt,e.label&&(0,J.jsx)(`span`,{className:`aui-thread-followup-suggestion-label text-muted-foreground ms-1`,children:e.label})]},t))})})},pW=()=>(0,J.jsx)(Pu,{condition:e=>!e.thread.isEmpty&&!e.thread.isRunning&&e.thread.suggestions.length>0,children:(0,J.jsx)(fW,{})}),mW=/^(?:[/?#]|\.{1,2}\/)/,hW=new Set([`http:`,`https:`,`mailto:`]),gW=e=>{try{return new URL(e)}catch{return}};function _W(e){if(typeof e!=`string`)return;let t=e.trim();if(t===``)return;let n=gW(t);return n?hW.has(n.protocol)?t:void 0:mW.test(t)?t:void 0}function vW(e){let t=_W(e);return(t===void 0?``:gW(t)?.hostname??``).replace(/^www\./,``)||void 0}var yW=e=>{switch(e){case`image/png`:return`png`;case`image/jpeg`:case`image/jpg`:return`jpg`;case`image/webp`:return`webp`;case`image/gif`:return`gif`;case`image/svg+xml`:return`svg`;default:return`png`}},bW=e=>{let t=e.indexOf(`,`),n=t>=0?e.slice(0,t):e,r=t>=0?e.slice(t+1):``,i=n.match(/data:([^;]+)/i)?.[1]?.toLowerCase()??`application/octet-stream`;if(!/;base64/i.test(n)){let e=[],t=0;for(let n of r.matchAll(/(?:%[\da-f]{2})+/gi)){n.index>t&&e.push(r.slice(t,n.index));let i=n[0],a=new Uint8Array(i.length/3);for(let e=0;e<a.length;e++)a[e]=Number.parseInt(i.slice(e*3+1,e*3+3),16);e.push(a),t=n.index+i.length}return e.push(r.slice(t)),new Blob(e,{type:i})}let a;try{let e=r.replace(/%([\da-f]{2})/gi,(e,t)=>String.fromCharCode(Number.parseInt(t,16)));a=atob(e)}catch{return null}let o=new Uint8Array(a.length);for(let e=0;e<a.length;e++)o[e]=a.charCodeAt(e);return new Blob([o],{type:i})},xW=e=>e.match(/^data:([^;,]+)/i)?.[1]?.toLowerCase(),SW=e=>{let t=xW(e);if(t)return`image.${yW(t)}`;try{let t=new URL(e,document.baseURI).pathname.split(`/`).pop()??``,n=t;try{n=decodeURIComponent(t)}catch{}if(/\.(png|jpe?g|webp|gif|svg)$/i.test(n))return n}catch{}return`image.png`},CW=e=>{try{let t=new URL(e,document.baseURI);return t.protocol===`http:`||t.protocol===`https:`||t.protocol===`blob:`?e:null}catch{return null}},wW=e=>{if(typeof document>`u`)return;let t=e.filename??SW(e.image),n=/^data:/i.test(e.image),r=n?bW(e.image):null;if(n&&!r)return;let i=r?URL.createObjectURL(r):null,a=i??CW(e.image);if(!a)return;let o=document.createElement(`a`);o.href=a,o.download=t,o.rel=`noopener`,document.body.appendChild(o),o.click(),document.body.removeChild(o),i&&setTimeout(()=>URL.revokeObjectURL(i),4e4)},TW=async e=>{if(typeof navigator>`u`||!navigator.clipboard||typeof ClipboardItem>`u`)throw Error(`Clipboard API is not available in this environment.`);let t=/^data:/i.test(e.image)?bW(e.image):await fetch(e.image).then(e=>e.blob());if(!t)return;let n=xW(e.image)??t.type??`image/png`;await navigator.clipboard.write([new ClipboardItem({[n]:t})])},EW=nU(`aui-image-root relative overflow-hidden rounded-lg`,{variants:{variant:{outline:`border-border border`,ghost:``,muted:`bg-muted/50`},size:{sm:`max-w-64`,default:`max-w-96`,lg:`max-w-[512px]`,full:`w-full`}},defaultVariants:{variant:`outline`,size:`default`}});function DW({className:e,variant:t,size:n,children:r,...i}){return(0,J.jsx)(`div`,{"data-slot":`image-root`,"data-variant":t,"data-size":n,className:Q(EW({variant:t,size:n,className:e})),...i,children:r})}function OW({className:e,containerClassName:t,ratio:n=`auto`,fit:r=`contain`,onLoad:i,onError:a,alt:o=`Image content`,src:s,...c}){let l=(0,f.useRef)(null),[u,d]=(0,f.useState)(void 0),[p,m]=(0,f.useState)(void 0),h=u===s,g=p===s,_=n!==`auto`,v=n===`1:1`?`aspect-square`:n===`4:3`?`aspect-[4/3]`:n===`16:9`?`aspect-video`:n===`9:16`?`aspect-[9/16]`:void 0;return(0,f.useEffect)(()=>{let e=l.current;typeof s==`string`&&e?.complete&&(e.naturalWidth>0?d(s):m(s))},[s]),(0,J.jsxs)(`div`,{"data-slot":`image-preview`,className:Q(`relative`,_?v:`min-h-32`,t),children:[!h&&!g&&(0,J.jsx)(`div`,{"data-slot":`image-preview-loading`,className:`bg-muted/50 absolute inset-0 flex items-center justify-center`,children:(0,J.jsx)(mP,{className:`text-muted-foreground size-8 animate-pulse`})}),g?(0,J.jsx)(`div`,{"data-slot":`image-preview-error`,className:Q(`bg-muted/50 flex min-h-32 items-center justify-center p-4`,_&&`absolute inset-0`),children:(0,J.jsx)(fP,{className:`text-muted-foreground size-8`})}):(0,J.jsx)(`img`,{ref:l,src:s,alt:o,className:Q(_?Q(`block h-full w-full`,{"object-cover":r===`cover`,"object-contain":r===`contain`}):`block h-auto w-full object-contain`,!h&&`invisible`,e),onLoad:e=>{typeof s==`string`&&d(s),i?.(e)},onError:e=>{typeof s==`string`&&m(s),a?.(e)},...c})]})}function kW({className:e,label:t,url:n,iconUrl:r,...i}){let a=_W(n),o=vW(n),s=t||o,[c,l]=(0,f.useState)();if(!s)return null;let u=r!==void 0&&c!==r;return(0,J.jsxs)(`div`,{"data-slot":`image-source`,className:Q(`text-muted-foreground flex items-center gap-2 border-t px-2 py-1.5 text-xs`,e),...i,children:[u?(0,J.jsx)(`img`,{"data-slot":`image-source-icon`,src:r,alt:``,className:`size-4 shrink-0 rounded-sm`,onError:()=>l(r)}):(0,J.jsx)(`span`,{"data-slot":`image-source-icon-fallback`,"aria-hidden":`true`,className:`bg-muted flex size-4 shrink-0 items-center justify-center rounded-sm text-[10px] font-medium`,children:s.charAt(0).toUpperCase()}),a?(0,J.jsxs)(`a`,{"data-slot":`image-source-label`,href:a,target:`_blank`,rel:`noopener noreferrer`,className:`hover:text-foreground truncate`,children:[s,(0,J.jsx)(`span`,{className:`sr-only`,children:` (opens in a new tab)`})]}):(0,J.jsx)(`span`,{"data-slot":`image-source-label`,className:`truncate`,children:s})]})}function AW({className:e,children:t,...n}){return t?(0,J.jsx)(`span`,{"data-slot":`image-filename`,className:Q(`text-muted-foreground block truncate px-2 py-1.5 text-xs`,e),...n,children:t}):null}function jW({src:e,alt:t=`Image preview`,children:n}){let[r,i]=(0,f.useState)(!1),a=(0,f.useRef)(null),o=(0,f.useRef)(null),s=(0,f.useRef)(null),c=(0,f.useCallback)(()=>i(!0),[]),l=(0,f.useCallback)(()=>{i(!1),a.current?.focus()},[]);return(0,f.useEffect)(()=>{if(!r)return;let e=e=>{if(e.key===`Escape`){l();return}if(e.key!==`Tab`)return;let t=s.current?.querySelectorAll(`a[href], button:not([disabled]), [tabindex]:not([tabindex="-1"])`),n=t?.[0],r=t?.[t.length-1];n&&r&&(e.shiftKey&&document.activeElement===n?(e.preventDefault(),r.focus()):!e.shiftKey&&document.activeElement===r&&(e.preventDefault(),n.focus()))};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[r,l]),(0,f.useEffect)(()=>{if(!r)return;let e=document.body.style.overflow;return document.body.style.overflow=`hidden`,()=>{document.body.style.overflow=e}},[r]),(0,f.useEffect)(()=>{r&&o.current?.focus()},[r]),(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`div`,{ref:a,onClick:c,onKeyDown:e=>{e.key===`Enter`?(e.preventDefault(),e.currentTarget.click()):e.key===` `&&e.preventDefault()},onKeyUp:e=>{e.key===` `&&e.currentTarget.click()},role:`button`,tabIndex:0,className:`aui-image-zoom-trigger cursor-zoom-in`,"aria-label":`Click to zoom image`,children:n}),r&&(0,p.createPortal)((0,J.jsxs)(`div`,{ref:s,"data-slot":`image-zoom-overlay`,role:`dialog`,"aria-modal":`true`,className:`aui-image-zoom-overlay fade-in animate-in fixed inset-0 z-50 flex items-center justify-center bg-black/80 duration-200`,onClick:l,"aria-label":`Zoomed image`,children:[(0,J.jsx)(`img`,{"data-slot":`image-zoom-content`,src:e,alt:t,className:`aui-image-zoom-content fade-in zoom-in-95 animate-in max-h-[90%] max-w-[90%] cursor-zoom-out object-contain duration-200`,onClick:e=>{e.stopPropagation(),l()}}),(0,J.jsx)(`button`,{ref:o,type:`button`,"aria-label":`Close zoomed image`,onClick:e=>{e.stopPropagation(),l()},className:`text-muted-foreground hover:text-foreground bg-background/80 absolute end-4 top-4 rounded-md p-2`,children:(0,J.jsx)(XP,{className:`size-5`})})]}),document.body)]})}function MW({className:e}){return(0,J.jsxs)(`div`,{"data-slot":`image-generating`,className:Q(`bg-muted/50 flex min-h-32 items-center justify-center p-4`,e),children:[(0,J.jsx)(gP,{className:`text-muted-foreground size-8 animate-spin`}),(0,J.jsx)(`span`,{className:`sr-only`,children:`Generating image…`})]})}function NW({className:e,reason:t}){return(0,J.jsxs)(`div`,{"data-slot":`image-content-filter-error`,className:Q(`bg-muted/50 flex min-h-32 flex-col items-center justify-center gap-2 p-4 text-center`,e),children:[(0,J.jsx)(RP,{className:`text-muted-foreground size-8`}),(0,J.jsx)(`p`,{className:`text-sm font-medium`,children:`Image could not be generated`}),t&&(0,J.jsx)(`p`,{className:`text-muted-foreground text-xs`,children:t})]})}function PW({onRegenerate:e}){let[t,n]=(0,f.useState)(!1);return(0,J.jsx)(`button`,{type:`button`,onClick:async()=>{n(!0);try{await e()}catch{}finally{n(!1)}},disabled:t,"data-slot":`image-regenerate`,"aria-label":`Regenerate image`,className:`hover:bg-muted inline-flex size-7 items-center justify-center rounded disabled:opacity-50`,children:(0,J.jsx)(IP,{className:Q(`size-4`,t&&`animate-spin`)})})}function FW({part:e,onRegenerate:t,className:n}){return(0,J.jsxs)(`div`,{"data-slot":`image-actions`,className:Q(`flex items-center gap-1 p-1`,n),children:[(0,J.jsx)(`button`,{type:`button`,onClick:()=>wW(e),"data-slot":`image-download`,"aria-label":`Download image`,className:`hover:bg-muted inline-flex size-7 items-center justify-center rounded`,children:(0,J.jsx)(nP,{className:`size-4`})}),(0,J.jsx)(`button`,{type:`button`,onClick:()=>{TW(e).catch(()=>{})},"data-slot":`image-copy`,"aria-label":`Copy image`,className:`hover:bg-muted inline-flex size-7 items-center justify-center rounded`,children:(0,J.jsx)(eP,{className:`size-4`})}),t&&(0,J.jsx)(PW,{onRegenerate:t})]})}var IW=(0,f.memo)(e=>{let{image:t,filename:n,status:r}=e;return r?.type===`running`?(0,J.jsxs)(DW,{children:[(0,J.jsx)(MW,{}),(0,J.jsx)(AW,{children:n})]}):r?.type===`incomplete`&&r.reason===`content-filter`?(0,J.jsx)(DW,{children:(0,J.jsx)(NW,{reason:`The provider blocked this image.`})}):(0,J.jsxs)(DW,{children:[(0,J.jsx)(jW,{src:t,alt:n||`Image content`,children:(0,J.jsx)(OW,{src:t,alt:n||`Image content`})}),(0,J.jsx)(AW,{children:n})]})});IW.displayName=`Image`,IW.Root=DW,IW.Preview=OW,IW.Source=kW,IW.Filename=AW,IW.Zoom=jW,IW.Actions=FW,IW.Generating=MW,IW.ContentFilterError=NW;var LW=(e,t,n=0,r=!1)=>{if(Object.is(e,t))return!0;if(n>=100||typeof e!=`object`||!e||typeof t!=`object`||!t)return!1;if(Array.isArray(e)){if(!Array.isArray(t)||e.length!==t.length)return!1;for(let r=0;r<e.length;r++)if(!LW(e[r],t[r],n+1))return!1;return!0}if(Array.isArray(t))return!1;let i=Object.getPrototypeOf(e),a=Object.getPrototypeOf(t);if(i!==Object.prototype&&i!==null||a!==Object.prototype&&a!==null)return!1;let o=e,s=t,c=0;for(let e in o)if(Object.hasOwn(o,e)&&(!r||e!==`position`&&e!==`data`)){if(!Object.prototype.propertyIsEnumerable.call(s,e)||!LW(o[e],s[e],n+1))return!1;c++}let l=0;for(let e in s)Object.hasOwn(s,e)&&(!r||e!==`position`&&e!==`data`)&&l++;return c===l},RW=(e,t)=>!e||!t?!1:e===t||LW(e.properties,t.properties,0,!0)&&LW(e.children,t.children),zW=(e,t)=>RW(e.node,t.node),BW=(e={})=>Object.fromEntries(Object.entries(e??{}).map(([e,t])=>{if(!t)return[e,t];let n=t;return[e,(0,f.memo)(({node:e,...t})=>(0,J.jsx)(n,{...t}),zW)]})),VW=(0,f.createContext)(null),HW=()=>(0,f.useContext)(VW)!==null,UW=(0,f.memo)(({children:e,fallbackPre:t,...n})=>n.node?.children.some(e=>e.type===`element`&&e.tagName===`code`)??!0?(0,J.jsx)(VW.Provider,{value:n,children:e}):(0,J.jsx)(t,{...n,children:e}),(e,t)=>e.fallbackPre===t.fallbackPre&&zW(e,t)),WW=({node:e,...t})=>(0,J.jsx)(`pre`,{...t}),GW=({node:e,...t})=>(0,J.jsx)(`code`,{...t}),KW=({node:e,components:{Pre:t,Code:n},code:r})=>(0,J.jsx)(t,{children:(0,J.jsx)(n,{node:e,children:r})}),qW=()=>null,JW=e=>/language-([^\s]+)/.exec(e??``)?.[1]??``,YW=({node:e,components:{Pre:t,Code:n,SyntaxHighlighter:r,CodeHeader:i},language:a,code:o})=>{let s=(0,f.useMemo)(()=>({Pre:t,Code:n}),[t,n]);return(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(i,{node:e,language:a,code:o}),(0,J.jsx)(r,{node:e,components:s,language:a,code:o})]})},XW=u(o(((e,t)=>{(function(){"use strict";var e={}.hasOwnProperty;function n(){for(var e=``,t=0;t<arguments.length;t++){var n=arguments[t];n&&(e=i(e,r(n)))}return e}function r(t){if(typeof t==`string`||typeof t==`number`)return t;if(typeof t!=`object`)return``;if(Array.isArray(t))return n.apply(null,t);if(t.toString!==Object.prototype.toString&&!t.toString.toString().includes(`[native code]`))return t.toString();var r=``;for(var a in t)e.call(t,a)&&t[a]&&(r=i(r,a));return r}function i(e,t){return t?e?e+` `+t:e+t:e}t!==void 0&&t.exports?(n.default=n,t.exports=n):typeof define==`function`&&typeof define.amd==`object`&&define.amd?define(`classnames`,[],function(){return n}):window.classNames=n})()}))(),1),ZW=({className:e,...t})=>({className:n,...r})=>({className:(0,XW.default)(e,n),...t,...r}),QW=(0,f.createContext)(null);function $W(e){let{Pre:t,preProps:n}=(0,f.useContext)(QW);return(0,J.jsx)(t,{...ZW(n)(e)})}function eG(e){let{Code:t,codeProps:n}=(0,f.useContext)(QW);return(0,J.jsx)(t,{...ZW(n)(e)})}function tG(e){if(typeof e==`string`)return e;if(Array.isArray(e)){let t=``;for(let n of e)t+=tG(n);return t}return(0,f.isValidElement)(e)?tG(e.props.children):``}var nG=({node:e,components:{Pre:t,Code:n,SyntaxHighlighter:r,CodeHeader:i},componentsByLanguage:a={},children:o,...s})=>{let c={Pre:t,Code:n,preProps:(0,f.useContext)(VW),codeProps:s},l=JW(s.className),u=a[l]?.SyntaxHighlighter??r,d=a[l]?.CodeHeader??i;return o!=null&&typeof o!=`string`?(0,J.jsxs)(QW.Provider,{value:c,children:[(0,J.jsx)(d,{node:e,language:l,code:tG(o)}),(0,J.jsx)(KW,{node:e,components:{Pre:$W,Code:eG},code:o})]}):(0,J.jsx)(QW.Provider,{value:c,children:(0,J.jsx)(YW,{node:e,components:{Pre:$W,Code:eG,SyntaxHighlighter:u,CodeHeader:d},language:l,code:o??``})})},rG=({node:e,components:t,componentsByLanguage:n,...r})=>HW()?(0,J.jsx)(nG,{node:e,components:t,componentsByLanguage:n,...r}):(0,J.jsx)(t.Code,{...r}),iG=(e,t)=>{if(e===t)return!0;if(!e||!t)return!1;let n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(let r of n){if(!Object.hasOwn(t,r))return!1;let n=e[r],i=t[r];if(n!==i&&(!n||!i||n.SyntaxHighlighter!==i.SyntaxHighlighter||n.CodeHeader!==i.CodeHeader))return!1}return!0},aG=(0,f.memo)(rG,(e,t)=>e.components===t.components&&iG(e.componentsByLanguage,t.componentsByLanguage)&&zW(e,t));function oG(e,t){let n=t||{};return(e[e.length-1]===``?[...e,``]:e).join((n.padRight?` `:``)+`,`+(n.padLeft===!1?``:` `)).trim()}var sG=/^[$_\p{ID_Start}][$_\u{200C}\u{200D}\p{ID_Continue}]*$/u,cG=/^[$_\p{ID_Start}][-$_\u{200C}\u{200D}\p{ID_Continue}]*$/u,lG={};function uG(e,t){return((t||lG).jsx?cG:sG).test(e)}var dG=/[ \t\n\f\r]/g;function fG(e){return typeof e==`object`?e.type===`text`&&pG(e.value):pG(e)}function pG(e){return e.replace(dG,``)===``}var mG=class{constructor(e,t,n){this.normal=t,this.property=e,n&&(this.space=n)}};mG.prototype.normal={},mG.prototype.property={},mG.prototype.space=void 0;function hG(e,t){let n={},r={};for(let t of e)Object.assign(n,t.property),Object.assign(r,t.normal);return new mG(n,r,t)}function gG(e){return e.toLowerCase()}var _G=class{constructor(e,t){this.attribute=t,this.property=e}};_G.prototype.attribute=``,_G.prototype.booleanish=!1,_G.prototype.boolean=!1,_G.prototype.commaOrSpaceSeparated=!1,_G.prototype.commaSeparated=!1,_G.prototype.defined=!1,_G.prototype.mustUseProperty=!1,_G.prototype.number=!1,_G.prototype.overloadedBoolean=!1,_G.prototype.property=``,_G.prototype.spaceSeparated=!1,_G.prototype.space=void 0;var vG=s({boolean:()=>bG,booleanish:()=>xG,commaOrSpaceSeparated:()=>TG,commaSeparated:()=>wG,number:()=>$,overloadedBoolean:()=>SG,spaceSeparated:()=>CG}),yG=0,bG=EG(),xG=EG(),SG=EG(),$=EG(),CG=EG(),wG=EG(),TG=EG();function EG(){return 2**++yG}var DG=Object.keys(vG),OG=class extends _G{constructor(e,t,n,r){let i=-1;if(super(e,t),kG(this,`space`,r),typeof n==`number`)for(;++i<DG.length;){let e=DG[i];kG(this,DG[i],(n&vG[e])===vG[e])}}};OG.prototype.defined=!0;function kG(e,t,n){n&&(e[t]=n)}function AG(e){let t={},n={};for(let[r,i]of Object.entries(e.properties)){let a=new OG(r,e.transform(e.attributes||{},r),i,e.space);e.mustUseProperty&&e.mustUseProperty.includes(r)&&(a.mustUseProperty=!0),t[r]=a,n[gG(r)]=r,n[gG(a.attribute)]=r}return new mG(t,n,e.space)}var jG=AG({properties:{ariaActiveDescendant:null,ariaAtomic:xG,ariaAutoComplete:null,ariaBusy:xG,ariaChecked:xG,ariaColCount:$,ariaColIndex:$,ariaColSpan:$,ariaControls:CG,ariaCurrent:null,ariaDescribedBy:CG,ariaDetails:null,ariaDisabled:xG,ariaDropEffect:CG,ariaErrorMessage:null,ariaExpanded:xG,ariaFlowTo:CG,ariaGrabbed:xG,ariaHasPopup:null,ariaHidden:xG,ariaInvalid:null,ariaKeyShortcuts:null,ariaLabel:null,ariaLabelledBy:CG,ariaLevel:$,ariaLive:null,ariaModal:xG,ariaMultiLine:xG,ariaMultiSelectable:xG,ariaOrientation:null,ariaOwns:CG,ariaPlaceholder:null,ariaPosInSet:$,ariaPressed:xG,ariaReadOnly:xG,ariaRelevant:null,ariaRequired:xG,ariaRoleDescription:CG,ariaRowCount:$,ariaRowIndex:$,ariaRowSpan:$,ariaSelected:xG,ariaSetSize:$,ariaSort:null,ariaValueMax:$,ariaValueMin:$,ariaValueNow:$,ariaValueText:null,role:null},transform(e,t){return t===`role`?t:`aria-`+t.slice(4).toLowerCase()}});function MG(e,t){return t in e?e[t]:t}function NG(e,t){return MG(e,t.toLowerCase())}var PG=AG({attributes:{acceptcharset:`accept-charset`,classname:`class`,htmlfor:`for`,httpequiv:`http-equiv`},mustUseProperty:[`checked`,`multiple`,`muted`,`selected`],properties:{abbr:null,accept:wG,acceptCharset:CG,accessKey:CG,action:null,allow:null,allowFullScreen:bG,allowPaymentRequest:bG,allowUserMedia:bG,alpha:bG,alt:null,as:null,async:bG,autoCapitalize:null,autoComplete:CG,autoFocus:bG,autoPlay:bG,blocking:CG,capture:null,charSet:null,checked:bG,cite:null,className:CG,closedBy:null,colorSpace:null,cols:$,colSpan:$,command:null,commandFor:null,content:null,contentEditable:xG,controls:bG,controlsList:CG,coords:$|wG,crossOrigin:null,data:null,dateTime:null,decoding:null,default:bG,defer:bG,dir:null,dirName:null,disabled:bG,download:SG,draggable:xG,encType:null,enterKeyHint:null,fetchPriority:null,form:null,formAction:null,formEncType:null,formMethod:null,formNoValidate:bG,formTarget:null,headers:CG,height:$,hidden:SG,high:$,href:null,hrefLang:null,htmlFor:CG,httpEquiv:CG,id:null,imageSizes:null,imageSrcSet:null,inert:bG,inputMode:null,integrity:null,is:null,isMap:bG,itemId:null,itemProp:CG,itemRef:CG,itemScope:bG,itemType:CG,kind:null,label:null,lang:null,language:null,list:null,loading:null,loop:bG,low:$,manifest:null,max:null,maxLength:$,media:null,method:null,min:null,minLength:$,multiple:bG,muted:bG,name:null,nonce:null,noModule:bG,noValidate:bG,onAbort:null,onAfterPrint:null,onAuxClick:null,onBeforeMatch:null,onBeforePrint:null,onBeforeToggle:null,onBeforeUnload:null,onBlur:null,onCancel:null,onCanPlay:null,onCanPlayThrough:null,onChange:null,onClick:null,onClose:null,onContextLost:null,onContextMenu:null,onContextRestored:null,onCopy:null,onCueChange:null,onCut:null,onDblClick:null,onDrag:null,onDragEnd:null,onDragEnter:null,onDragExit:null,onDragLeave:null,onDragOver:null,onDragStart:null,onDrop:null,onDurationChange:null,onEmptied:null,onEnded:null,onError:null,onFocus:null,onFormData:null,onHashChange:null,onInput:null,onInvalid:null,onKeyDown:null,onKeyPress:null,onKeyUp:null,onLanguageChange:null,onLoad:null,onLoadedData:null,onLoadedMetadata:null,onLoadEnd:null,onLoadStart:null,onMessage:null,onMessageError:null,onMouseDown:null,onMouseEnter:null,onMouseLeave:null,onMouseMove:null,onMouseOut:null,onMouseOver:null,onMouseUp:null,onOffline:null,onOnline:null,onPageHide:null,onPageShow:null,onPaste:null,onPause:null,onPlay:null,onPlaying:null,onPopState:null,onProgress:null,onRateChange:null,onRejectionHandled:null,onReset:null,onResize:null,onScroll:null,onScrollEnd:null,onSecurityPolicyViolation:null,onSeeked:null,onSeeking:null,onSelect:null,onSlotChange:null,onStalled:null,onStorage:null,onSubmit:null,onSuspend:null,onTimeUpdate:null,onToggle:null,onUnhandledRejection:null,onUnload:null,onVolumeChange:null,onWaiting:null,onWheel:null,open:bG,optimum:$,pattern:null,ping:CG,placeholder:null,playsInline:bG,popover:null,popoverTarget:null,popoverTargetAction:null,poster:null,preload:null,readOnly:bG,referrerPolicy:null,rel:CG,required:bG,reversed:bG,rows:$,rowSpan:$,sandbox:CG,scope:null,scoped:bG,seamless:bG,selected:bG,shadowRootClonable:bG,shadowRootCustomElementRegistry:bG,shadowRootDelegatesFocus:bG,shadowRootMode:null,shadowRootSerializable:bG,shape:null,size:$,sizes:null,slot:null,span:$,spellCheck:xG,src:null,srcDoc:null,srcLang:null,srcSet:null,start:$,step:null,style:null,tabIndex:$,target:null,title:null,translate:null,type:null,typeMustMatch:bG,useMap:null,value:xG,width:$,wrap:null,writingSuggestions:null,align:null,aLink:null,archive:CG,axis:null,background:null,bgColor:null,border:$,borderColor:null,bottomMargin:$,cellPadding:null,cellSpacing:null,char:null,charOff:null,classId:null,clear:null,code:null,codeBase:null,codeType:null,color:null,compact:bG,declare:bG,event:null,face:null,frame:null,frameBorder:null,hSpace:$,leftMargin:$,link:null,longDesc:null,lowSrc:null,marginHeight:$,marginWidth:$,noResize:bG,noHref:bG,noShade:bG,noWrap:bG,object:null,profile:null,prompt:null,rev:null,rightMargin:$,rules:null,scheme:null,scrolling:xG,standby:null,summary:null,text:null,topMargin:$,valueType:null,version:null,vAlign:null,vLink:null,vSpace:$,allowTransparency:null,autoCorrect:null,autoSave:null,credentialless:bG,disablePictureInPicture:bG,disableRemotePlayback:bG,exportParts:wG,part:CG,prefix:null,property:null,results:$,security:null,unselectable:null},space:`html`,transform:NG}),FG=AG({attributes:{accentHeight:`accent-height`,alignmentBaseline:`alignment-baseline`,arabicForm:`arabic-form`,baselineShift:`baseline-shift`,capHeight:`cap-height`,className:`class`,clipPath:`clip-path`,clipRule:`clip-rule`,colorInterpolation:`color-interpolation`,colorInterpolationFilters:`color-interpolation-filters`,colorProfile:`color-profile`,colorRendering:`color-rendering`,crossOrigin:`crossorigin`,dataType:`datatype`,dominantBaseline:`dominant-baseline`,enableBackground:`enable-background`,fillOpacity:`fill-opacity`,fillRule:`fill-rule`,floodColor:`flood-color`,floodOpacity:`flood-opacity`,fontFamily:`font-family`,fontSize:`font-size`,fontSizeAdjust:`font-size-adjust`,fontStretch:`font-stretch`,fontStyle:`font-style`,fontVariant:`font-variant`,fontWeight:`font-weight`,glyphName:`glyph-name`,glyphOrientationHorizontal:`glyph-orientation-horizontal`,glyphOrientationVertical:`glyph-orientation-vertical`,hrefLang:`hreflang`,horizAdvX:`horiz-adv-x`,horizOriginX:`horiz-origin-x`,horizOriginY:`horiz-origin-y`,imageRendering:`image-rendering`,letterSpacing:`letter-spacing`,lightingColor:`lighting-color`,markerEnd:`marker-end`,markerMid:`marker-mid`,markerStart:`marker-start`,maskType:`mask-type`,navDown:`nav-down`,navDownLeft:`nav-down-left`,navDownRight:`nav-down-right`,navLeft:`nav-left`,navNext:`nav-next`,navPrev:`nav-prev`,navRight:`nav-right`,navUp:`nav-up`,navUpLeft:`nav-up-left`,navUpRight:`nav-up-right`,onAbort:`onabort`,onActivate:`onactivate`,onAfterPrint:`onafterprint`,onBeforePrint:`onbeforeprint`,onBegin:`onbegin`,onCancel:`oncancel`,onCanPlay:`oncanplay`,onCanPlayThrough:`oncanplaythrough`,onChange:`onchange`,onClick:`onclick`,onClose:`onclose`,onCopy:`oncopy`,onCueChange:`oncuechange`,onCut:`oncut`,onDblClick:`ondblclick`,onDrag:`ondrag`,onDragEnd:`ondragend`,onDragEnter:`ondragenter`,onDragExit:`ondragexit`,onDragLeave:`ondragleave`,onDragOver:`ondragover`,onDragStart:`ondragstart`,onDrop:`ondrop`,onDurationChange:`ondurationchange`,onEmptied:`onemptied`,onEnd:`onend`,onEnded:`onended`,onError:`onerror`,onFocus:`onfocus`,onFocusIn:`onfocusin`,onFocusOut:`onfocusout`,onHashChange:`onhashchange`,onInput:`oninput`,onInvalid:`oninvalid`,onKeyDown:`onkeydown`,onKeyPress:`onkeypress`,onKeyUp:`onkeyup`,onLoad:`onload`,onLoadedData:`onloadeddata`,onLoadedMetadata:`onloadedmetadata`,onLoadStart:`onloadstart`,onMessage:`onmessage`,onMouseDown:`onmousedown`,onMouseEnter:`onmouseenter`,onMouseLeave:`onmouseleave`,onMouseMove:`onmousemove`,onMouseOut:`onmouseout`,onMouseOver:`onmouseover`,onMouseUp:`onmouseup`,onMouseWheel:`onmousewheel`,onOffline:`onoffline`,onOnline:`ononline`,onPageHide:`onpagehide`,onPageShow:`onpageshow`,onPaste:`onpaste`,onPause:`onpause`,onPlay:`onplay`,onPlaying:`onplaying`,onPopState:`onpopstate`,onProgress:`onprogress`,onRateChange:`onratechange`,onRepeat:`onrepeat`,onReset:`onreset`,onResize:`onresize`,onScroll:`onscroll`,onSeeked:`onseeked`,onSeeking:`onseeking`,onSelect:`onselect`,onShow:`onshow`,onStalled:`onstalled`,onStorage:`onstorage`,onSubmit:`onsubmit`,onSuspend:`onsuspend`,onTimeUpdate:`ontimeupdate`,onToggle:`ontoggle`,onUnload:`onunload`,onVolumeChange:`onvolumechange`,onWaiting:`onwaiting`,onZoom:`onzoom`,overlinePosition:`overline-position`,overlineThickness:`overline-thickness`,paintOrder:`paint-order`,panose1:`panose-1`,pointerEvents:`pointer-events`,referrerPolicy:`referrerpolicy`,renderingIntent:`rendering-intent`,shapeRendering:`shape-rendering`,stopColor:`stop-color`,stopOpacity:`stop-opacity`,strikethroughPosition:`strikethrough-position`,strikethroughThickness:`strikethrough-thickness`,strokeDashArray:`stroke-dasharray`,strokeDashOffset:`stroke-dashoffset`,strokeLineCap:`stroke-linecap`,strokeLineJoin:`stroke-linejoin`,strokeMiterLimit:`stroke-miterlimit`,strokeOpacity:`stroke-opacity`,strokeWidth:`stroke-width`,tabIndex:`tabindex`,textAnchor:`text-anchor`,textDecoration:`text-decoration`,textRendering:`text-rendering`,transformOrigin:`transform-origin`,typeOf:`typeof`,underlinePosition:`underline-position`,underlineThickness:`underline-thickness`,unicodeBidi:`unicode-bidi`,unicodeRange:`unicode-range`,unitsPerEm:`units-per-em`,vAlphabetic:`v-alphabetic`,vHanging:`v-hanging`,vIdeographic:`v-ideographic`,vMathematical:`v-mathematical`,vectorEffect:`vector-effect`,vertAdvY:`vert-adv-y`,vertOriginX:`vert-origin-x`,vertOriginY:`vert-origin-y`,wordSpacing:`word-spacing`,writingMode:`writing-mode`,xHeight:`x-height`,playbackOrder:`playbackorder`,timelineBegin:`timelinebegin`},properties:{about:TG,accentHeight:$,accumulate:null,additive:null,alignmentBaseline:null,alphabetic:$,amplitude:$,arabicForm:null,ascent:$,attributeName:null,attributeType:null,azimuth:$,bandwidth:null,baselineShift:null,baseFrequency:null,baseProfile:null,bbox:null,begin:null,bias:$,by:null,calcMode:null,capHeight:$,className:CG,clip:null,clipPath:null,clipPathUnits:null,clipRule:null,color:null,colorInterpolation:null,colorInterpolationFilters:null,colorProfile:null,colorRendering:null,content:null,contentScriptType:null,contentStyleType:null,crossOrigin:null,cursor:null,cx:null,cy:null,d:null,dataType:null,defaultAction:null,descent:$,diffuseConstant:$,direction:null,display:null,dur:null,divisor:$,dominantBaseline:null,download:bG,dx:null,dy:null,edgeMode:null,editable:null,elevation:$,enableBackground:null,end:null,event:null,exponent:$,externalResourcesRequired:null,fill:null,fillOpacity:$,fillRule:null,filter:null,filterRes:null,filterUnits:null,floodColor:null,floodOpacity:null,focusable:null,focusHighlight:null,fontFamily:null,fontSize:null,fontSizeAdjust:null,fontStretch:null,fontStyle:null,fontVariant:null,fontWeight:null,format:null,fr:null,from:null,fx:null,fy:null,g1:wG,g2:wG,glyphName:wG,glyphOrientationHorizontal:null,glyphOrientationVertical:null,glyphRef:null,gradientTransform:null,gradientUnits:null,handler:null,hanging:$,hatchContentUnits:null,hatchUnits:null,height:null,href:null,hrefLang:null,horizAdvX:$,horizOriginX:$,horizOriginY:$,id:null,ideographic:$,imageRendering:null,initialVisibility:null,in:null,in2:null,intercept:$,k:$,k1:$,k2:$,k3:$,k4:$,kernelMatrix:TG,kernelUnitLength:null,keyPoints:null,keySplines:null,keyTimes:null,kerning:null,lang:null,lengthAdjust:null,letterSpacing:null,lightingColor:null,limitingConeAngle:$,local:null,markerEnd:null,markerMid:null,markerStart:null,markerHeight:null,markerUnits:null,markerWidth:null,mask:null,maskContentUnits:null,maskType:null,maskUnits:null,mathematical:null,max:null,media:null,mediaCharacterEncoding:null,mediaContentEncodings:null,mediaSize:$,mediaTime:null,method:null,min:null,mode:null,name:null,navDown:null,navDownLeft:null,navDownRight:null,navLeft:null,navNext:null,navPrev:null,navRight:null,navUp:null,navUpLeft:null,navUpRight:null,numOctaves:null,observer:null,offset:null,onAbort:null,onActivate:null,onAfterPrint:null,onBeforePrint:null,onBegin:null,onCancel:null,onCanPlay:null,onCanPlayThrough:null,onChange:null,onClick:null,onClose:null,onCopy:null,onCueChange:null,onCut:null,onDblClick:null,onDrag:null,onDragEnd:null,onDragEnter:null,onDragExit:null,onDragLeave:null,onDragOver:null,onDragStart:null,onDrop:null,onDurationChange:null,onEmptied:null,onEnd:null,onEnded:null,onError:null,onFocus:null,onFocusIn:null,onFocusOut:null,onHashChange:null,onInput:null,onInvalid:null,onKeyDown:null,onKeyPress:null,onKeyUp:null,onLoad:null,onLoadedData:null,onLoadedMetadata:null,onLoadStart:null,onMessage:null,onMouseDown:null,onMouseEnter:null,onMouseLeave:null,onMouseMove:null,onMouseOut:null,onMouseOver:null,onMouseUp:null,onMouseWheel:null,onOffline:null,onOnline:null,onPageHide:null,onPageShow:null,onPaste:null,onPause:null,onPlay:null,onPlaying:null,onPopState:null,onProgress:null,onRateChange:null,onRepeat:null,onReset:null,onResize:null,onScroll:null,onSeeked:null,onSeeking:null,onSelect:null,onShow:null,onStalled:null,onStorage:null,onSubmit:null,onSuspend:null,onTimeUpdate:null,onToggle:null,onUnload:null,onVolumeChange:null,onWaiting:null,onZoom:null,opacity:null,operator:null,order:null,orient:null,orientation:null,origin:null,overflow:null,overlay:null,overlinePosition:$,overlineThickness:$,paintOrder:null,panose1:null,path:null,pathLength:$,patternContentUnits:null,patternTransform:null,patternUnits:null,phase:null,ping:CG,pitch:null,playbackOrder:null,pointerEvents:null,points:null,pointsAtX:$,pointsAtY:$,pointsAtZ:$,preserveAlpha:null,preserveAspectRatio:null,primitiveUnits:null,propagate:null,property:TG,r:null,radius:null,referrerPolicy:null,refX:null,refY:null,rel:TG,rev:TG,renderingIntent:null,repeatCount:null,repeatDur:null,requiredExtensions:TG,requiredFeatures:TG,requiredFonts:TG,requiredFormats:TG,resource:null,restart:null,result:null,rotate:null,rx:null,ry:null,scale:null,seed:null,shapeRendering:null,side:null,slope:null,snapshotTime:null,specularConstant:$,specularExponent:$,spreadMethod:null,spacing:null,startOffset:null,stdDeviation:null,stemh:null,stemv:null,stitchTiles:null,stopColor:null,stopOpacity:null,strikethroughPosition:$,strikethroughThickness:$,string:null,stroke:null,strokeDashArray:TG,strokeDashOffset:null,strokeLineCap:null,strokeLineJoin:null,strokeMiterLimit:$,strokeOpacity:$,strokeWidth:null,style:null,surfaceScale:$,syncBehavior:null,syncBehaviorDefault:null,syncMaster:null,syncTolerance:null,syncToleranceDefault:null,systemLanguage:TG,tabIndex:$,tableValues:null,target:null,targetX:$,targetY:$,textAnchor:null,textDecoration:null,textRendering:null,textLength:null,timelineBegin:null,title:null,transformBehavior:null,type:null,typeOf:TG,to:null,transform:null,transformOrigin:null,u1:null,u2:null,underlinePosition:$,underlineThickness:$,unicode:null,unicodeBidi:null,unicodeRange:null,unitsPerEm:$,values:null,vAlphabetic:$,vMathematical:$,vectorEffect:null,vHanging:$,vIdeographic:$,version:null,vertAdvY:$,vertOriginX:$,vertOriginY:$,viewBox:null,viewTarget:null,visibility:null,width:null,widths:null,wordSpacing:null,writingMode:null,x:null,x1:null,x2:null,xChannelSelector:null,xHeight:$,y:null,y1:null,y2:null,yChannelSelector:null,z:null,zoomAndPan:null},space:`svg`,transform:MG}),IG=AG({properties:{xLinkActuate:null,xLinkArcRole:null,xLinkHref:null,xLinkRole:null,xLinkShow:null,xLinkTitle:null,xLinkType:null},space:`xlink`,transform(e,t){return`xlink:`+t.slice(5).toLowerCase()}}),LG=AG({attributes:{xmlnsxlink:`xmlns:xlink`},properties:{xmlnsXLink:null,xmlns:null},space:`xmlns`,transform:NG}),RG=AG({properties:{xmlBase:null,xmlLang:null,xmlSpace:null},space:`xml`,transform(e,t){return`xml:`+t.slice(3).toLowerCase()}}),zG={classId:`classID`,dataType:`datatype`,itemId:`itemID`,strokeDashArray:`strokeDasharray`,strokeDashOffset:`strokeDashoffset`,strokeLineCap:`strokeLinecap`,strokeLineJoin:`strokeLinejoin`,strokeMiterLimit:`strokeMiterlimit`,typeOf:`typeof`,xLinkActuate:`xlinkActuate`,xLinkArcRole:`xlinkArcrole`,xLinkHref:`xlinkHref`,xLinkRole:`xlinkRole`,xLinkShow:`xlinkShow`,xLinkTitle:`xlinkTitle`,xLinkType:`xlinkType`,xmlnsXLink:`xmlnsXlink`},BG=/[A-Z]/g,VG=/-[a-z]/g,HG=/^data[-\w.:]+$/i;function UG(e,t){let n=gG(t),r=t,i=_G;if(n in e.normal)return e.property[e.normal[n]];if(n.length>4&&n.slice(0,4)===`data`&&HG.test(t)){if(t.charAt(4)===`-`){let e=t.slice(5).replace(VG,GG);r=`data`+e.charAt(0).toUpperCase()+e.slice(1)}else{let e=t.slice(4);if(!VG.test(e)){let n=e.replace(BG,WG);n.charAt(0)!==`-`&&(n=`-`+n),t=`data`+n}}i=OG}return new i(r,t)}function WG(e){return`-`+e.toLowerCase()}function GG(e){return e.charAt(1).toUpperCase()}var KG=hG([jG,PG,IG,LG,RG],`html`),qG=hG([jG,FG,IG,LG,RG],`svg`);function JG(e){return e.join(` `).trim()}var YG=/\/\*(?:[^*]|\*(?!\/))*\*\//g,XG=/\n/g,ZG=/^\s*/,QG=/^(\*?[-#/*\\\w]+(\[[0-9a-z_-]+\])?)\s*/,$G=/^:\s*/,eK=/^((?:'(?:\\.|[^'\\])*'|"(?:\\.|[^"\\])*"|url\((?:'(?:\\.|[^'\\])*'|"(?:\\.|[^"\\])*"|[^)]*)\)|[^};])+)/,tK=/^[;\s]*/,nK=`
|
|
61
|
+
`,rK=`/`,iK=`*`,aK=``,oK=`comment`,sK=`declaration`;function cK(e,t){if(typeof e!=`string`)throw TypeError(`First argument must be a string`);if(!e)return[];t||={};var n=1,r=1;function i(e){var t=e.match(XG);t&&(n+=t.length);var i=e.lastIndexOf(nK);r=~i?e.length-i:r+e.length}function a(){var e={line:n,column:r};return function(t){return t.position=new o(e),l(),t}}function o(e){this.start=e,this.end={line:n,column:r},this.source=t.source}o.prototype.content=e;function s(i){var a=Error(t.source+`:`+n+`:`+r+`: `+i);if(a.reason=i,a.filename=t.source,a.line=n,a.column=r,a.source=e,!t.silent)throw a}function c(t){var n=t.exec(e);if(n){var r=n[0];return i(r),e=e.slice(r.length),n}}function l(){c(ZG)}function u(e){for(var t;t=d();)e.push(t);return e}function d(){var t=a();if(rK==e.charAt(0)&&iK==e.charAt(1)){for(var n=2;aK!=e.charAt(n)&&(iK!=e.charAt(n)||rK!=e.charAt(n+1));)++n;if(n+=2,aK===e.charAt(n-1))return s(`End of comment missing`);var o=e.slice(2,n-2);return r+=2,i(o),e=e.slice(n),r+=2,t({type:oK,comment:o})}}function f(){var e=a(),t=c(QG);if(t){if(d(),!c($G))return s(`property missing ':'`);var n=c(eK),r=e({type:sK,property:t[0].replace(YG,aK).trim(),value:n?n[0].replace(YG,aK).trim():aK});return c(tK),r}}function p(){var e=[];u(e);for(var t;t=f();)e.push(t),u(e);return e}return l(),p()}function lK(e,t){let n=null;if(!e||typeof e!=`string`)return n;let r=cK(e),i=typeof t==`function`;return r.forEach(e=>{if(e.type!==`declaration`)return;let{property:r,value:a}=e;i?t(r,a,e):a&&(n??={},n[r]=a)}),n}var uK=fK(`end`),dK=fK(`start`);function fK(e){return t;function t(t){let n=t&&t.position&&t.position[e]||{};if(typeof n.line==`number`&&n.line>0&&typeof n.column==`number`&&n.column>0)return{line:n.line,column:n.column,offset:typeof n.offset==`number`&&n.offset>-1?n.offset:void 0}}}function pK(e){let t=dK(e),n=uK(e);if(t&&n)return{start:t,end:n}}function mK(e){return!e||typeof e!=`object`?``:`position`in e||`type`in e?gK(e.position):`start`in e||`end`in e?gK(e):`line`in e||`column`in e?hK(e):``}function hK(e){return _K(e&&e.line)+`:`+_K(e&&e.column)}function gK(e){return hK(e&&e.start)+`-`+hK(e&&e.end)}function _K(e){return e&&typeof e==`number`?e:1}var vK=class extends Error{constructor(e,t,n){super(),typeof t==`string`&&(n=t,t=void 0);let r=``,i={},a=!1;if(t&&(i=`line`in t&&`column`in t||`start`in t&&`end`in t?{place:t}:`type`in t?{ancestors:[t],place:t.position}:{...t}),typeof e==`string`?r=e:!i.cause&&e&&(a=!0,r=e.message,i.cause=e),!i.ruleId&&!i.source&&typeof n==`string`){let e=n.indexOf(`:`);e===-1?i.ruleId=n:(i.source=n.slice(0,e),i.ruleId=n.slice(e+1))}if(!i.place&&i.ancestors&&i.ancestors){let e=i.ancestors[i.ancestors.length-1];e&&(i.place=e.position)}let o=i.place&&`start`in i.place?i.place.start:i.place;this.ancestors=i.ancestors||void 0,this.cause=i.cause||void 0,this.column=o?o.column:void 0,this.fatal=void 0,this.file=``,this.message=r,this.line=o?o.line:void 0,this.name=mK(i.place)||`1:1`,this.place=i.place||void 0,this.reason=this.message,this.ruleId=i.ruleId||void 0,this.source=i.source||void 0,this.stack=a&&i.cause&&typeof i.cause.stack==`string`?i.cause.stack:``,this.actual=void 0,this.expected=void 0,this.note=void 0,this.url=void 0}};vK.prototype.file=``,vK.prototype.name=``,vK.prototype.reason=``,vK.prototype.message=``,vK.prototype.stack=``,vK.prototype.column=void 0,vK.prototype.line=void 0,vK.prototype.ancestors=void 0,vK.prototype.cause=void 0,vK.prototype.fatal=void 0,vK.prototype.place=void 0,vK.prototype.ruleId=void 0,vK.prototype.source=void 0;var yK={}.hasOwnProperty,bK=new Map,xK=/[A-Z]/g,SK=/-([a-z])/g,CK=new Set([`table`,`tbody`,`thead`,`tfoot`,`tr`]),wK=new Set([`td`,`th`]),TK=`https://github.com/syntax-tree/hast-util-to-jsx-runtime`;function EK(e,t){if(!t||t.Fragment===void 0)throw TypeError("Expected `Fragment` in options");let n=t.filePath||void 0,r;if(t.development){if(typeof t.jsxDEV!=`function`)throw TypeError("Expected `jsxDEV` in options when `development: true`");r=LK(n,t.jsxDEV)}else{if(typeof t.jsx!=`function`)throw TypeError("Expected `jsx` in production options");if(typeof t.jsxs!=`function`)throw TypeError("Expected `jsxs` in production options");r=IK(n,t.jsx,t.jsxs)}let i={Fragment:t.Fragment,ancestors:[],components:t.components||{},create:r,elementAttributeNameCase:t.elementAttributeNameCase||`react`,evaluater:t.createEvaluater?t.createEvaluater():void 0,filePath:n,ignoreInvalidStyle:t.ignoreInvalidStyle||!1,passKeys:t.passKeys!==!1,passNode:t.passNode||!1,schema:t.space===`svg`?qG:KG,stylePropertyNameCase:t.stylePropertyNameCase||`dom`,tableCellAlignToStyle:t.tableCellAlignToStyle!==!1},a=DK(i,e,void 0);return a&&typeof a!=`string`?a:i.create(e,i.Fragment,{children:a||void 0},void 0)}function DK(e,t,n){if(t.type===`element`)return OK(e,t,n);if(t.type===`mdxFlowExpression`||t.type===`mdxTextExpression`)return kK(e,t);if(t.type===`mdxJsxFlowElement`||t.type===`mdxJsxTextElement`)return jK(e,t,n);if(t.type===`mdxjsEsm`)return AK(e,t);if(t.type===`root`)return MK(e,t,n);if(t.type===`text`)return NK(e,t)}function OK(e,t,n){let r=e.schema,i=r;t.tagName.toLowerCase()===`svg`&&r.space===`html`&&(i=qG,e.schema=i),e.ancestors.push(t);let a=UK(e,t.tagName,!1),o=RK(e,t),s=BK(e,t);return CK.has(t.tagName)&&(s=s.filter(function(e){return typeof e!=`string`||!fG(e)})),PK(e,o,a,t),FK(o,s),e.ancestors.pop(),e.schema=r,e.create(t,a,o,n)}function kK(e,t){if(t.data&&t.data.estree&&e.evaluater){let n=t.data.estree.body[0];return n.type,e.evaluater.evaluateExpression(n.expression)}WK(e,t.position)}function AK(e,t){if(t.data&&t.data.estree&&e.evaluater)return e.evaluater.evaluateProgram(t.data.estree);WK(e,t.position)}function jK(e,t,n){let r=e.schema,i=r;t.name===`svg`&&r.space===`html`&&(i=qG,e.schema=i),e.ancestors.push(t);let a=t.name===null?e.Fragment:UK(e,t.name,!0),o=zK(e,t),s=BK(e,t);return PK(e,o,a,t),FK(o,s),e.ancestors.pop(),e.schema=r,e.create(t,a,o,n)}function MK(e,t,n){let r={};return FK(r,BK(e,t)),e.create(t,e.Fragment,r,n)}function NK(e,t){return t.value}function PK(e,t,n,r){typeof n!=`string`&&n!==e.Fragment&&e.passNode&&(t.node=r)}function FK(e,t){if(t.length>0){let n=t.length>1?t:t[0];n&&(e.children=n)}}function IK(e,t,n){return r;function r(e,r,i,a){let o=Array.isArray(i.children)?n:t;return a?o(r,i,a):o(r,i)}}function LK(e,t){return n;function n(n,r,i,a){let o=Array.isArray(i.children),s=dK(n);return t(r,i,a,o,{columnNumber:s?s.column-1:void 0,fileName:e,lineNumber:s?s.line:void 0},void 0)}}function RK(e,t){let n={},r,i;for(i in t.properties)if(i!==`children`&&yK.call(t.properties,i)){let a=VK(e,i,t.properties[i]);if(a){let[i,o]=a;e.tableCellAlignToStyle&&i===`align`&&typeof o==`string`&&wK.has(t.tagName)?r=o:n[i]=o}}if(r){let t=n.style||={};t[e.stylePropertyNameCase===`css`?`text-align`:`textAlign`]=r}return n}function zK(e,t){let n={};for(let r of t.attributes)if(r.type===`mdxJsxExpressionAttribute`){if(r.data&&r.data.estree&&e.evaluater){let t=r.data.estree.body[0];t.type;let i=t.expression;i.type;let a=i.properties[0];a.type,Object.assign(n,e.evaluater.evaluateExpression(a.argument))}else WK(e,t.position)}else{let{name:i}=r,a;if(r.value&&typeof r.value==`object`){if(r.value.data&&r.value.data.estree&&e.evaluater){let t=r.value.data.estree.body[0];t.type,a=e.evaluater.evaluateExpression(t.expression)}else WK(e,t.position)}else a=r.value===null||r.value;n[i]=a}return n}function BK(e,t){let n=[],r=-1,i=e.passKeys?new Map:bK;for(;++r<t.children.length;){let a=t.children[r],o;if(e.passKeys){let e=a.type===`element`?a.tagName:a.type===`mdxJsxFlowElement`||a.type===`mdxJsxTextElement`?a.name:void 0;if(e){let t=i.get(e)||0;o=e+`-`+t,i.set(e,t+1)}}let s=DK(e,a,o);s!==void 0&&n.push(s)}return n}function VK(e,t,n){if(n==null||typeof n==`number`&&Number.isNaN(n))return;let r=UG(e.schema,t);return Array.isArray(n)&&(n=r.commaSeparated?oG(n):JG(n)),r.property===`style`?[`style`,typeof n==`object`?e.stylePropertyNameCase===`dom`?n:GK(n):HK(e,String(n))]:[e.elementAttributeNameCase===`react`&&r.space?zG[r.property]||r.property:r.attribute,n]}function HK(e,t){let n={};try{lK(t,function(t,r){if(t&&r){let i=t;i.slice(0,2)!==`--`&&(i=i.toLowerCase(),e.stylePropertyNameCase===`dom`&&(i.slice(0,4)===`-ms-`&&(i=i.slice(1)),i=i.replace(SK,JK))),n[i]=r}})}catch(t){if(e.ignoreInvalidStyle)return{};let n=t,r=new vK("Cannot parse `style` attribute",{ancestors:e.ancestors,cause:n,ruleId:`style`,source:`hast-util-to-jsx-runtime`});throw r.file=e.filePath||void 0,r.url=TK+`#cannot-parse-style-attribute`,r}return n}function UK(e,t,n){let r;if(!n)r={type:`Literal`,value:t};else if(t.includes(`.`)){let e=t.split(`.`),n=-1,i;for(;++n<e.length;){let t=uG(e[n])?{type:`Identifier`,name:e[n]}:{type:`Literal`,value:e[n]};i=i?{type:`MemberExpression`,object:i,property:t,computed:!!(n&&t.type===`Literal`),optional:!1}:t}r=i}else r=uG(t)&&!/^[a-z]/.test(t)?{type:`Identifier`,name:t}:{type:`Literal`,value:t};if(r.type===`Literal`){let t=r.value;return yK.call(e.components,t)?e.components[t]:t}if(e.evaluater)return e.evaluater.evaluateExpression(r);WK(e)}function WK(e,t){let n=new vK("Cannot handle MDX estrees without `createEvaluater`",{ancestors:e.ancestors,place:t,ruleId:`mdx-estree`,source:`hast-util-to-jsx-runtime`});throw n.file=e.filePath||void 0,n.url=TK+`#cannot-handle-mdx-estrees-without-createevaluater`,n}function GK(e){let t={},n;for(n in e)yK.call(e,n)&&(t[KK(n)]=e[n]);return t}function KK(e){if(e.slice(0,2)===`--`)return e;let t=e.replace(xK,qK);return t.slice(0,3)===`ms-`&&(t=`-`+t),t}function qK(e){return`-`+e.toLowerCase()}function JK(e,t){return t.toUpperCase()}var YK={action:[`form`],cite:[`blockquote`,`del`,`ins`,`q`],data:[`object`],formAction:[`button`,`input`],href:[`a`,`area`,`base`,`link`],icon:[`menuitem`],itemId:null,manifest:[`html`],ping:[`a`,`area`],poster:[`video`],src:[`audio`,`embed`,`iframe`,`img`,`input`,`script`,`source`,`track`,`video`]},XK={};function ZK(e,t){let n=t||XK;return QK(e,typeof n.includeImageAlt!=`boolean`||n.includeImageAlt,typeof n.includeHtml!=`boolean`||n.includeHtml)}function QK(e,t,n){if(eq(e)){if(`value`in e)return e.type===`html`&&!n?``:e.value;if(t&&`alt`in e&&e.alt)return e.alt;if(`children`in e)return $K(e.children,t,n)}return Array.isArray(e)?$K(e,t,n):``}function $K(e,t,n){let r=[],i=-1;for(;++i<e.length;)r[i]=QK(e[i],t,n);return r.join(``)}function eq(e){return!!(e&&typeof e==`object`)}var tq=document.createElement(`i`);function nq(e){let t=`&`+e+`;`;tq.innerHTML=t;let n=tq.textContent;return n.charCodeAt(n.length-1)===59&&e!==`semi`?!1:n!==t&&n}function rq(e,t,n,r){let i=e.length,a=0,o;if(t=t<0?-t>i?0:i+t:t>i?i:t,n=n>0?n:0,r.length<1e4)o=Array.from(r),o.unshift(t,n),e.splice(...o);else for(n&&e.splice(t,n);a<r.length;)o=r.slice(a,a+1e4),o.unshift(t,0),e.splice(...o),a+=1e4,t+=1e4}function iq(e,t){return e.length>0?(rq(e,e.length,0,t),e):t}var aq={}.hasOwnProperty;function oq(e){let t={},n=-1;for(;++n<e.length;)sq(t,e[n]);return t}function sq(e,t){let n;for(n in t){let r=(aq.call(e,n)?e[n]:void 0)||(e[n]={}),i=t[n],a;if(i)for(a in i){aq.call(r,a)||(r[a]=[]);let e=i[a];cq(r[a],Array.isArray(e)?e:e?[e]:[])}}}function cq(e,t){let n=-1,r=[];for(;++n<t.length;)(t[n].add===`after`?e:r).push(t[n]);rq(e,0,0,r)}function lq(e,t){let n=Number.parseInt(e,t);return n<9||n===11||n>13&&n<32||n>126&&n<160||n>55295&&n<57344||n>64975&&n<65008||(n&65535)==65535||(n&65535)==65534||n>1114111?`�`:String.fromCodePoint(n)}function uq(e){return e.replace(/[\t\n\r ]+/g,` `).replace(/^ | $/g,``).toLowerCase().toUpperCase()}var dq=Cq(/[A-Za-z]/),fq=Cq(/[\dA-Za-z]/),pq=Cq(/[#-'*+\--9=?A-Z^-~]/);function mq(e){return e!==null&&(e<32||e===127)}var hq=Cq(/\d/),gq=Cq(/[\dA-Fa-f]/),_q=Cq(/[!-/:-@[-`{-~]/);function vq(e){return e!==null&&e<-2}function yq(e){return e!==null&&(e<0||e===32)}function bq(e){return e===-2||e===-1||e===32}var xq=Cq(/\p{P}|\p{S}/u),Sq=Cq(/\s/);function Cq(e){return t;function t(t){return t!==null&&t>-1&&e.test(String.fromCharCode(t))}}function wq(e){let t=[],n=-1,r=0,i=0;for(;++n<e.length;){let a=e.charCodeAt(n),o=``;if(a===37&&fq(e.charCodeAt(n+1))&&fq(e.charCodeAt(n+2)))i=2;else if(a<128)/[!#$&-;=?-Z_a-z~]/.test(String.fromCharCode(a))||(o=String.fromCharCode(a));else if(a>55295&&a<57344){let t=e.charCodeAt(n+1);a<56320&&t>56319&&t<57344?(o=String.fromCharCode(a,t),i=1):o=`�`}else o=String.fromCharCode(a);o&&=(t.push(e.slice(r,n),encodeURIComponent(o)),r=n+i+1,``),i&&=(n+=i,0)}return t.join(``)+e.slice(r)}function Tq(e,t,n,r){let i=r?r-1:1/0,a=0;return o;function o(r){return bq(r)?(e.enter(n),s(r)):t(r)}function s(r){return bq(r)&&a++<i?(e.consume(r),s):(e.exit(n),t(r))}}function Eq(e,t,n,r,i,a){let o=0;return s;function s(t){return a>0&&bq(t)?(e.enter(r),c(t)):l(t)}function c(t){return bq(t)&&o<a?(e.consume(t),o++,c):(e.exit(r),l(t))}function l(e){return o>=i?t(e):n(e)}}var Dq={tokenize:Oq};function Oq(e){let t=e.attempt(this.parser.constructs.contentInitial,r,i),n;return t;function r(n){if(n===null)e.consume(n);else return e.enter(`lineEnding`),e.consume(n),e.exit(`lineEnding`),Tq(e,t,`linePrefix`)}function i(t){return e.enter(`paragraph`),a(t)}function a(t){let r=e.enter(`chunkText`,{contentType:`text`,previous:n});return n&&(n.next=r),n=r,o(t)}function o(t){if(t===null)e.exit(`chunkText`),e.exit(`paragraph`),e.consume(t);else return vq(t)?(e.consume(t),e.exit(`chunkText`),a):(e.consume(t),o)}}var kq=class{constructor(){this.index=new Map,this.map=[]}add(e,t,n){Aq(this,e,t,n,!1)}addBefore(e,t,n){Aq(this,e,t,n,!0)}consume(e){if(this.map.sort(function(e,t){return e[0]-t[0]}),this.map.length===0)return;let t=this.map.length,n=[];for(;t>0;)--t,n.push(e.slice(this.map[t][0]+this.map[t][1]),this.map[t][2]),e.length=this.map[t][0];n.push(e.slice()),e.length=0;let r=n.pop();for(;r;){for(let t of r)e.push(t);r=n.pop()}this.map.length=0,this.index.clear()}};function Aq(e,t,n,r,i){if(n===0&&r.length===0)return;let a=e.index.get(t);if(a){a[1]+=n,i?(r.push(...a[2]),a[2]=r):a[2].push(...r);return}let o=[t,n,r];e.map.push(o),e.index.set(t,o)}var jq={tokenize:Nq},Mq={tokenize:Pq};function Nq(e){let t=this,n=[],r=0,i,a,o;return s;function s(i){if(r<n.length){let a=n[r];return t.containerState=a[1],e.attempt(a[0].continuation,c,l)(i)}return l(i)}function c(e){if(r++,t.containerState._closeFlow){t.containerState._closeFlow=void 0,i&&v();let n=t.events.length,a=n,o;for(;a--;)if(t.events[a][0]===`exit`&&t.events[a][1].type===`chunkFlow`){o=t.events[a][1].end;break}_(r);let s=n;for(;s<t.events.length;)t.events[s][1].end={...o},s++;let c=new kq;return c.add(a+1,0,t.events.slice(n)),c.add(n,s-n,[]),c.consume(t.events),l(e)}return s(e)}function l(a){if(r===n.length){if(!i)return f(a);if(i.currentConstruct&&i.currentConstruct.concrete)return m(a);t.interrupt=!(!i.currentConstruct||i._gfmTableDynamicInterruptHack)}return t.containerState={},e.check(Mq,u,d)(a)}function u(e){return i&&v(),_(r),f(e)}function d(e){return t.parser.lazy[t.now().line]=r!==n.length,o=t.now().offset,m(e)}function f(n){return t.containerState={},e.attempt(Mq,p,m)(n)}function p(e){return r++,n.push([t.currentConstruct,t.containerState]),f(e)}function m(n){if(n===null)i&&v(),_(0),e.consume(n);else return i||=t.parser.flow(t.now()),e.enter(`chunkFlow`,{_tokenizer:i,contentType:`flow`,previous:a}),h(n)}function h(n){if(n===null)g(e.exit(`chunkFlow`),!0),_(0),e.consume(n);else return vq(n)?(e.consume(n),g(e.exit(`chunkFlow`)),r=0,t.interrupt=void 0,s):(e.consume(n),h)}function g(e,n){let s=t.sliceStream(e);if(n&&s.push(null),e.previous=a,a&&(a.next=e),a=e,i.defineSkip(e.start),i.write(s),t.parser.lazy[e.start.line]){let e=i.events.length;for(;e--;)if(i.events[e][1].start.offset<o&&(!i.events[e][1].end||i.events[e][1].end.offset>o))return;let n=t.events.length,a=n,s,c;for(;a--;)if(t.events[a][0]===`exit`&&t.events[a][1].type===`chunkFlow`){if(s){c=t.events[a][1].end;break}s=!0}for(_(r),e=n;e<t.events.length;)t.events[e][1].end={...c},e++;let l=new kq;l.add(a+1,0,t.events.slice(n)),l.add(n,e-n,[]),l.consume(t.events)}}function _(r){let i=n.length;for(;i-->r;){let r=n[i];t.containerState=r[1],r[0].exit.call(t,e)}n.length=r}function v(){i.write([null]),a=void 0,i=void 0,t.containerState._closeFlow=void 0}}function Pq(e,t,n){return Tq(e,e.attempt(this.parser.constructs.document,t,n),`linePrefix`,this.parser.constructs.disable.null.includes(`codeIndented`)?void 0:4)}function Fq(e){if(e===null||yq(e)||Sq(e))return 1;if(xq(e))return 2}function Iq(e,t,n){let r=[],i=-1;for(;++i<e.length;){let a=e[i].resolveAll;a&&!r.includes(a)&&(t=a(t,n),r.push(a))}return t}var Lq={name:`attention`,resolveAll:Rq,tokenize:zq};function Rq(e,t){let n=-1,r;for(;++n<e.length;)if(e[n][0]===`enter`&&e[n][1].type===`attentionSequence`&&e[n][1]._close){let i=n;for(;i--;)if(e[i][0]===`exit`&&e[i][1].type===`attentionSequence`&&e[i][1]._open&&t.sliceSerialize(e[i][1]).charCodeAt(0)===t.sliceSerialize(e[n][1]).charCodeAt(0)){if((e[i][1]._close||e[n][1]._open)&&(e[n][1].end.offset-e[n][1].start.offset)%3&&!((e[i][1].end.offset-e[i][1].start.offset+e[n][1].end.offset-e[n][1].start.offset)%3))continue;let a=e[i][1].end.offset-e[i][1].start.offset>1&&e[n][1].end.offset-e[n][1].start.offset>1?2:1,o={...e[i][1].end},s={...e[n][1].start};Bq(o,-a),Bq(s,a);let c={type:a>1?`strongSequence`:`emphasisSequence`,start:o,end:{...e[i][1].end}},l={type:a>1?`strongSequence`:`emphasisSequence`,start:{...e[n][1].start},end:s},u={type:a>1?`strongText`:`emphasisText`,start:{...e[i][1].end},end:{...e[n][1].start}},d={type:a>1?`strong`:`emphasis`,start:{...c.start},end:{...l.end}};e[i][1].end={...c.start},e[n][1].start={...l.end},r=[],e[i][1].end.offset-e[i][1].start.offset&&(r=iq(r,[[`enter`,e[i][1],t],[`exit`,e[i][1],t]])),r=iq(r,[[`enter`,d,t],[`enter`,c,t],[`exit`,c,t],[`enter`,u,t]]),r=iq(r,Iq(t.parser.constructs.insideSpan.null,e.slice(i+1,n),t)),r=iq(r,[[`exit`,u,t],[`enter`,l,t],[`exit`,l,t],[`exit`,d,t]]);let f=0;e[n][1].end.offset-e[n][1].start.offset&&(f=2,r=iq(r,[[`enter`,e[n][1],t],[`exit`,e[n][1],t]])),rq(e,i-1,n-i+3,r),n=i+r.length-f-2;break}}for(n=-1;++n<e.length;)e[n][1].type===`attentionSequence`&&(e[n][1].type=`data`);return e}function zq(e,t){let n=this.parser.constructs.attentionMarkers.null,r=this.previous,i=Fq(r),a;return o;function o(t){return a=t,e.enter(`attentionSequence`),s(t)}function s(o){if(o===a)return e.consume(o),s;let c=e.exit(`attentionSequence`),l=Fq(o),u=!l||l===2&&i||n.includes(o)&&o!==42&&o!==95,d=!i||i===2&&l||n.includes(r)&&r!==42&&r!==95;return c._open=!!(a===42?u:u&&(i||!d)),c._close=!!(a===42?d:d&&(l||!u)),t(o)}}function Bq(e,t){e.column+=t,e.offset+=t,e._bufferIndex+=t}var Vq={name:`autolink`,tokenize:Hq};function Hq(e,t,n){let r=0;return i;function i(t){return e.enter(`autolink`),e.enter(`autolinkMarker`),e.consume(t),e.exit(`autolinkMarker`),e.enter(`autolinkProtocol`),a}function a(t){return dq(t)?(e.consume(t),o):t===64?n(t):l(t)}function o(e){return e===43||e===45||e===46||fq(e)?(r=1,s(e)):l(e)}function s(t){return t===58?(e.consume(t),r=0,c):(t===43||t===45||t===46||fq(t))&&r++<32?(e.consume(t),s):(r=0,l(t))}function c(r){return r===62?(e.exit(`autolinkProtocol`),e.enter(`autolinkMarker`),e.consume(r),e.exit(`autolinkMarker`),e.exit(`autolink`),t):r===null||r===32||r===60||mq(r)?n(r):(e.consume(r),c)}function l(t){return t===64?(e.consume(t),u):pq(t)?(e.consume(t),l):n(t)}function u(e){return fq(e)?d(e):n(e)}function d(n){return n===46?(e.consume(n),r=0,u):n===62?(e.exit(`autolinkProtocol`).type=`autolinkEmail`,e.enter(`autolinkMarker`),e.consume(n),e.exit(`autolinkMarker`),e.exit(`autolink`),t):f(n)}function f(t){if((t===45||fq(t))&&r++<63){let n=t===45?f:d;return e.consume(t),n}return n(t)}}var Uq={partial:!0,tokenize:Wq};function Wq(e,t,n){return r;function r(t){return bq(t)?Tq(e,i,`linePrefix`)(t):i(t)}function i(e){return e===null||vq(e)?t(e):n(e)}}var Gq={continuation:{tokenize:qq},exit:Jq,name:`blockQuote`,tokenize:Kq};function Kq(e,t,n){let r=this;return i;function i(t){if(t===62){let n=r.containerState;return n.open||=(e.enter(`blockQuote`,{_container:!0}),!0),e.enter(`blockQuotePrefix`),e.enter(`blockQuoteMarker`),e.consume(t),e.exit(`blockQuoteMarker`),a}return n(t)}function a(n){return bq(n)?(e.enter(`blockQuotePrefixWhitespace`),e.consume(n),e.exit(`blockQuotePrefixWhitespace`),e.exit(`blockQuotePrefix`),t):(e.exit(`blockQuotePrefix`),t(n))}}function qq(e,t,n){let r=this;return i;function i(t){return bq(t)?Tq(e,a,`linePrefix`,r.parser.constructs.disable.null.includes(`codeIndented`)?void 0:4)(t):a(t)}function a(r){return e.attempt(Gq,t,n)(r)}}function Jq(e){e.exit(`blockQuote`)}var Yq={name:`characterEscape`,tokenize:Xq};function Xq(e,t,n){return r;function r(t){return e.enter(`characterEscape`),e.enter(`escapeMarker`),e.consume(t),e.exit(`escapeMarker`),i}function i(r){return _q(r)?(e.enter(`characterEscapeValue`),e.consume(r),e.exit(`characterEscapeValue`),e.exit(`characterEscape`),t):n(r)}}var Zq={name:`characterReference`,tokenize:Qq};function Qq(e,t,n){let r=this,i=0,a,o;return s;function s(t){return e.enter(`characterReference`),e.enter(`characterReferenceMarker`),e.consume(t),e.exit(`characterReferenceMarker`),c}function c(t){return t===35?(e.enter(`characterReferenceMarkerNumeric`),e.consume(t),e.exit(`characterReferenceMarkerNumeric`),l):(e.enter(`characterReferenceValue`),a=31,o=fq,u(t))}function l(t){return t===88||t===120?(e.enter(`characterReferenceMarkerHexadecimal`),e.consume(t),e.exit(`characterReferenceMarkerHexadecimal`),e.enter(`characterReferenceValue`),a=6,o=gq,u):(e.enter(`characterReferenceValue`),a=7,o=hq,u(t))}function u(s){if(s===59&&i){let i=e.exit(`characterReferenceValue`);return o===fq&&!nq(r.sliceSerialize(i))?n(s):(e.enter(`characterReferenceMarker`),e.consume(s),e.exit(`characterReferenceMarker`),e.exit(`characterReference`),t)}return o(s)&&i++<a?(e.consume(s),u):n(s)}}var $q={partial:!0,tokenize:eJ};function eJ(e,t,n){let r=this;return i;function i(t){return t===null?n(t):(e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),a)}function a(e){return r.parser.lazy[r.now().line]?n(e):t(e)}}var tJ={concrete:!0,name:`codeFenced`,tokenize:nJ};function nJ(e,t,n){let r=this,i={partial:!0,tokenize:x},a=0,o=0,s;return c;function c(e){return l(e)}function l(t){let n=r.events[r.events.length-1];return a=n&&n[1].type===`linePrefix`?n[2].sliceSerialize(n[1],!0).length:0,s=t,e.enter(`codeFenced`),e.enter(`codeFencedFence`),e.enter(`codeFencedFenceSequence`),u(t)}function u(t){return t===s?(o++,e.consume(t),u):o<3?n(t):(e.exit(`codeFencedFenceSequence`),bq(t)?Tq(e,d,`whitespace`)(t):d(t))}function d(n){return n===null||vq(n)?(e.exit(`codeFencedFence`),r.interrupt?t(n):e.check($q,h,b)(n)):(e.enter(`codeFencedFenceInfo`),e.enter(`chunkString`,{contentType:`string`}),f(n))}function f(t){return t===null||vq(t)?(e.exit(`chunkString`),e.exit(`codeFencedFenceInfo`),d(t)):bq(t)?(e.exit(`chunkString`),e.exit(`codeFencedFenceInfo`),Tq(e,p,`whitespace`)(t)):t===96&&t===s?n(t):(e.consume(t),f)}function p(t){return t===null||vq(t)?d(t):(e.enter(`codeFencedFenceMeta`),e.enter(`chunkString`,{contentType:`string`}),m(t))}function m(t){return t===null||vq(t)?(e.exit(`chunkString`),e.exit(`codeFencedFenceMeta`),d(t)):t===96&&t===s?n(t):(e.consume(t),m)}function h(t){return e.attempt(i,b,g)(t)}function g(t){return e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),_}function _(t){return a>0&&bq(t)?Tq(e,v,`linePrefix`,a+1)(t):v(t)}function v(t){return t===null||vq(t)?e.check($q,h,b)(t):(e.enter(`codeFlowValue`),y(t))}function y(t){return t===null||vq(t)?(e.exit(`codeFlowValue`),v(t)):(e.consume(t),y)}function b(n){return e.exit(`codeFenced`),t(n)}function x(e,t,n){let i=0;return a;function a(t){return e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),c}function c(t){return e.enter(`codeFencedFence`),bq(t)?Tq(e,l,`linePrefix`,r.parser.constructs.disable.null.includes(`codeIndented`)?void 0:4)(t):l(t)}function l(t){return t===s?(e.enter(`codeFencedFenceSequence`),u(t)):n(t)}function u(t){return t===s?(i++,e.consume(t),u):i>=o?(e.exit(`codeFencedFenceSequence`),bq(t)?Tq(e,d,`whitespace`)(t):d(t)):n(t)}function d(r){return r===null||vq(r)?(e.exit(`codeFencedFence`),t(r)):n(r)}}}var rJ={name:`codeIndented`,tokenize:aJ},iJ={partial:!0,tokenize:oJ};function aJ(e,t,n){return r;function r(t){return e.enter(`codeIndented`),Eq(e,i,n,`linePrefix`,4,4)(t)}function i(t){return t===null?o(t):vq(t)?e.attempt(iJ,i,o)(t):(e.enter(`codeFlowValue`),a(t))}function a(t){return t===null||vq(t)?(e.exit(`codeFlowValue`),i(t)):(e.consume(t),a)}function o(n){return e.exit(`codeIndented`),t(n)}}function oJ(e,t,n){let r=this;return i;function i(o){return r.parser.lazy[r.now().line]?n(o):vq(o)?(e.enter(`lineEnding`),e.consume(o),e.exit(`lineEnding`),i):Eq(e,t,a,`linePrefix`,4,4)(o)}function a(e){return vq(e)?i(e):n(e)}}var sJ={name:`codeText`,previous:lJ,resolve:cJ,tokenize:uJ};function cJ(e){let t=e.length-4,n=3,r,i;if((e[n][1].type===`lineEnding`||e[n][1].type===`space`)&&(e[t][1].type===`lineEnding`||e[t][1].type===`space`)){for(r=n;++r<t;)if(e[r][1].type===`codeTextData`){e[n][1].type=`codeTextPadding`,e[t][1].type=`codeTextPadding`,n+=2,t-=2;break}}for(r=n-1,t++;++r<=t;)i===void 0?r!==t&&e[r][1].type!==`lineEnding`&&(i=r):(r===t||e[r][1].type===`lineEnding`)&&(e[i][1].type=`codeTextData`,r!==i+2&&(e[i][1].end=e[r-1][1].end,e.splice(i+2,r-i-2),t-=r-i-2,r=i+2),i=void 0);return e}function lJ(e){return e!==96||this.events[this.events.length-1][1].type===`characterEscape`}function uJ(e,t,n){let r=0,i,a;return o;function o(t){return e.enter(`codeText`),e.enter(`codeTextSequence`),s(t)}function s(t){return t===96?(e.consume(t),r++,s):(e.exit(`codeTextSequence`),c(t))}function c(t){return t===null?n(t):t===32?(e.enter(`space`),e.consume(t),e.exit(`space`),c):t===96?(a=e.enter(`codeTextSequence`),i=0,u(t)):vq(t)?(e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),c):(e.enter(`codeTextData`),l(t))}function l(t){return t===null||t===32||t===96||vq(t)?(e.exit(`codeTextData`),c(t)):(e.consume(t),l)}function u(n){return n===96?(e.consume(n),i++,u):i===r?(e.exit(`codeTextSequence`),e.exit(`codeText`),t(n)):(a.type=`codeTextData`,l(n))}}var dJ=class{constructor(e){this.left=e?[...e]:[],this.right=[]}get(e){if(e<0||e>=this.left.length+this.right.length)throw RangeError("Cannot access index `"+e+"` in a splice buffer of size `"+(this.left.length+this.right.length)+"`");return e<this.left.length?this.left[e]:this.right[this.right.length-e+this.left.length-1]}get length(){return this.left.length+this.right.length}shift(){return this.setCursor(0),this.right.pop()}slice(e,t){let n=t??1/0;return n<this.left.length?this.left.slice(e,n):e>this.left.length?this.right.slice(this.right.length-n+this.left.length,this.right.length-e+this.left.length).reverse():this.left.slice(e).concat(this.right.slice(this.right.length-n+this.left.length).reverse())}splice(e,t,n){let r=t||0;this.setCursor(Math.trunc(e));let i=this.right.splice(this.right.length-r,1/0);return n&&fJ(this.left,n),i.reverse()}pop(){return this.setCursor(1/0),this.left.pop()}push(e){this.setCursor(1/0),this.left.push(e)}pushMany(e){this.setCursor(1/0),fJ(this.left,e)}unshift(e){this.setCursor(0),this.right.push(e)}unshiftMany(e){this.setCursor(0),fJ(this.right,e.reverse())}setCursor(e){if(!(e===this.left.length||e>this.left.length&&this.right.length===0||e<0&&this.left.length===0)){if(e<this.left.length){let t=this.left.splice(e,1/0);fJ(this.right,t.reverse())}else{let t=this.right.splice(this.left.length+this.right.length-e,1/0);fJ(this.left,t.reverse())}}}};function fJ(e,t){let n=0;if(t.length<1e4)e.push(...t);else for(;n<t.length;)e.push(...t.slice(n,n+1e4)),n+=1e4}function pJ(e){let t={},n=-1,r,i,a,o,s,c,l,u=new dJ(e);for(;++n<u.length;){for(;n in t;)n=t[n];if(r=u.get(n),n&&r[1].type===`chunkFlow`&&u.get(n-1)[1].type===`listItemPrefix`&&(c=r[1]._tokenizer.events,a=0,a<c.length&&c[a][1].type===`lineEndingBlank`&&(a+=2),a<c.length&&c[a][1].type===`content`))for(;++a<c.length&&c[a][1].type!==`content`;)c[a][1].type===`chunkText`&&(c[a][1]._isInFirstContentOfListItem=!0,a++);if(r[0]===`enter`)r[1].contentType&&(Object.assign(t,mJ(u,n)),n=t[n],l=!0);else if(r[1]._container){for(a=n,i=void 0;a--;)if(o=u.get(a),o[1].type===`lineEnding`||o[1].type===`lineEndingBlank`)o[0]===`enter`&&(i&&(u.get(i)[1].type=`lineEndingBlank`),o[1].type=`lineEnding`,i=a);else if(o[1].type!==`linePrefix`&&o[1].type!==`listItemIndent`)break;i&&(r[1].end={...u.get(i)[1].start},s=u.slice(i,n),s.unshift(r),u.splice(i,n-i+1,s))}}return rq(e,0,1/0,u.slice(0)),!l}function mJ(e,t){let n=e.get(t)[1],r=e.get(t)[2],i=t-1,a=[],o=n._tokenizer;o||(o=r.parser[n.contentType](n.start),n._contentTypeTextTrailing&&(o._contentTypeTextTrailing=!0));let s=o.events,c=[],l={},u,d,f=-1,p=n,m=0,h=0,g=[h];for(;p;){for(;e.get(++i)[1]!==p;);a.push(i),p._tokenizer||(u=r.sliceStream(p),p.next||u.push(null),d&&o.defineSkip(p.start),p._isInFirstContentOfListItem&&(o._gfmTasklistFirstContentOfListItem=!0),o.write(u),p._isInFirstContentOfListItem&&(o._gfmTasklistFirstContentOfListItem=void 0)),d=p,p=p.next}for(p=n;++f<s.length;)s[f][0]===`exit`&&s[f-1][0]===`enter`&&s[f][1].type===s[f-1][1].type&&s[f][1].start.line!==s[f][1].end.line&&(h=f+1,g.push(h),p._tokenizer=void 0,p.previous=void 0,p=p.next);for(o.events=[],p?(p._tokenizer=void 0,p.previous=void 0):g.pop(),f=g.length;f--;){let t=s.slice(g[f],g[f+1]),n=a.pop();c.push([n,n+t.length-1]),e.splice(n,2,t)}for(c.reverse(),f=-1;++f<c.length;)l[m+c[f][0]]=m+c[f][1],m+=c[f][1]-c[f][0]-1;return l}var hJ={resolve:_J,tokenize:vJ},gJ={partial:!0,tokenize:yJ};function _J(e){return pJ(e),e}function vJ(e,t){let n;return r;function r(t){return e.enter(`content`),n=e.enter(`chunkContent`,{contentType:`content`}),i(t)}function i(t){return t===null?a(t):vq(t)?e.check(gJ,o,a)(t):(e.consume(t),i)}function a(n){return e.exit(`chunkContent`),e.exit(`content`),t(n)}function o(t){return e.consume(t),e.exit(`chunkContent`),n.next=e.enter(`chunkContent`,{contentType:`content`,previous:n}),n=n.next,i}}function yJ(e,t,n){let r=this;return i;function i(t){return e.exit(`chunkContent`),e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),Tq(e,a,`linePrefix`)}function a(i){if(i===null||vq(i))return n(i);let a=r.events[r.events.length-1];return!r.parser.constructs.disable.null.includes(`codeIndented`)&&a&&a[1].type===`linePrefix`&&a[2].sliceSerialize(a[1],!0).length>=4?t(i):e.interrupt(r.parser.constructs.flow,n,t)(i)}}function bJ(e,t,n,r,i,a,o,s,c){let l=c||1/0,u=0;return d;function d(t){return t===60?(e.enter(r),e.enter(i),e.enter(a),e.consume(t),e.exit(a),f):t===null||t===32||t===41||mq(t)?n(t):(e.enter(r),e.enter(o),e.enter(s),e.enter(`chunkString`,{contentType:`string`}),h(t))}function f(n){return n===62?(e.enter(a),e.consume(n),e.exit(a),e.exit(i),e.exit(r),t):(e.enter(s),e.enter(`chunkString`,{contentType:`string`}),p(n))}function p(t){return t===62?(e.exit(`chunkString`),e.exit(s),f(t)):t===null||t===60||vq(t)?n(t):(e.consume(t),t===92?m:p)}function m(t){return t===60||t===62||t===92?(e.consume(t),p):p(t)}function h(i){return!u&&(i===null||i===41||yq(i))?(e.exit(`chunkString`),e.exit(s),e.exit(o),e.exit(r),t(i)):u<l&&i===40?(e.consume(i),u++,h):i===41?(e.consume(i),u--,h):i===null||i===32||i===40||mq(i)?n(i):(e.consume(i),i===92?g:h)}function g(t){return t===40||t===41||t===92?(e.consume(t),h):h(t)}}function xJ(e,t,n,r,i,a){let o=this,s=0,c;return l;function l(t){return e.enter(r),e.enter(i),e.consume(t),e.exit(i),e.enter(a),u}function u(l){return s>999||l===null||l===91||l===93&&!c||l===94&&!s&&`_hiddenFootnoteSupport`in o.parser.constructs?n(l):l===93?(e.exit(a),e.enter(i),e.consume(l),e.exit(i),e.exit(r),t):vq(l)?(e.enter(`lineEnding`),e.consume(l),e.exit(`lineEnding`),u):(e.enter(`chunkString`,{contentType:`string`}),d(l))}function d(t){return t===null||t===91||t===93||vq(t)||s++>999?(e.exit(`chunkString`),u(t)):(e.consume(t),c||=!bq(t),t===92?f:d)}function f(t){return t===91||t===92||t===93?(e.consume(t),s++,d):d(t)}}function SJ(e,t,n,r,i,a){let o;return s;function s(t){return t===34||t===39||t===40?(e.enter(r),e.enter(i),e.consume(t),e.exit(i),o=t===40?41:t,c):n(t)}function c(n){return n===o?(e.enter(i),e.consume(n),e.exit(i),e.exit(r),t):(e.enter(a),l(n))}function l(t){return t===o?(e.exit(a),c(o)):t===null?n(t):vq(t)?(e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),Tq(e,l,`linePrefix`)):(e.enter(`chunkString`,{contentType:`string`}),u(t))}function u(t){return t===o||t===null||vq(t)?(e.exit(`chunkString`),l(t)):(e.consume(t),t===92?d:u)}function d(t){return t===o||t===92?(e.consume(t),u):u(t)}}function CJ(e,t){let n;return r;function r(i){return vq(i)?(e.enter(`lineEnding`),e.consume(i),e.exit(`lineEnding`),n=!0,r):bq(i)?Tq(e,r,n?`linePrefix`:`lineSuffix`)(i):t(i)}}var wJ={name:`definition`,tokenize:EJ},TJ={partial:!0,tokenize:DJ};function EJ(e,t,n){let r=this,i;return a;function a(t){return e.enter(`definition`),o(t)}function o(t){return xJ.call(r,e,s,n,`definitionLabel`,`definitionLabelMarker`,`definitionLabelString`)(t)}function s(t){return i=uq(r.sliceSerialize(r.events[r.events.length-1][1]).slice(1,-1)),t===58?(e.enter(`definitionMarker`),e.consume(t),e.exit(`definitionMarker`),c):n(t)}function c(t){return yq(t)?CJ(e,l)(t):l(t)}function l(t){return bJ(e,u,n,`definitionDestination`,`definitionDestinationLiteral`,`definitionDestinationLiteralMarker`,`definitionDestinationRaw`,`definitionDestinationString`)(t)}function u(t){return e.attempt(TJ,d,d)(t)}function d(t){return bq(t)?Tq(e,f,`whitespace`)(t):f(t)}function f(a){return a===null||vq(a)?(e.exit(`definition`),r.parser.defined.push(i),t(a)):n(a)}}function DJ(e,t,n){return r;function r(t){return yq(t)?CJ(e,i)(t):n(t)}function i(t){return SJ(e,a,n,`definitionTitle`,`definitionTitleMarker`,`definitionTitleString`)(t)}function a(t){return bq(t)?Tq(e,o,`whitespace`)(t):o(t)}function o(e){return e===null||vq(e)?t(e):n(e)}}var OJ={name:`hardBreakEscape`,tokenize:kJ};function kJ(e,t,n){return r;function r(t){return e.enter(`hardBreakEscape`),e.consume(t),i}function i(r){return vq(r)?(e.exit(`hardBreakEscape`),t(r)):n(r)}}var AJ={name:`headingAtx`,resolve:jJ,tokenize:MJ};function jJ(e,t){let n=e.length-2,r=3;if(e[r][1].type===`whitespace`&&(r+=2),n-2>r&&e[n][1].type===`whitespace`&&(n-=2),e[n][1].type===`atxHeadingSequence`&&(r===n-1||n-4>r&&e[n-2][1].type===`whitespace`)&&(n-=r+1===n?2:4),n>r){let i={type:`atxHeadingText`,start:e[r][1].start,end:e[n][1].end},a={type:`chunkText`,start:e[r][1].start,end:e[n][1].end,contentType:`text`};rq(e,r,n-r+1,[[`enter`,i,t],[`enter`,a,t],[`exit`,a,t],[`exit`,i,t]])}return e}function MJ(e,t,n){let r=0;return i;function i(t){return e.enter(`atxHeading`),a(t)}function a(t){return e.enter(`atxHeadingSequence`),o(t)}function o(t){return t===35&&r++<6?(e.consume(t),o):t===null||yq(t)?(e.exit(`atxHeadingSequence`),s(t)):n(t)}function s(n){return n===35?(e.enter(`atxHeadingSequence`),c(n)):n===null||vq(n)?(e.exit(`atxHeading`),t(n)):bq(n)?Tq(e,s,`whitespace`)(n):(e.enter(`atxHeadingText`),l(n))}function c(t){return t===35?(e.consume(t),c):(e.exit(`atxHeadingSequence`),s(t))}function l(t){return t===null||t===35||yq(t)?(e.exit(`atxHeadingText`),s(t)):(e.consume(t),l)}}var NJ=`address.article.aside.base.basefont.blockquote.body.caption.center.col.colgroup.dd.details.dialog.dir.div.dl.dt.fieldset.figcaption.figure.footer.form.frame.frameset.h1.h2.h3.h4.h5.h6.head.header.hr.html.iframe.legend.li.link.main.menu.menuitem.nav.noframes.ol.optgroup.option.p.param.search.section.summary.table.tbody.td.tfoot.th.thead.title.tr.track.ul`.split(`.`),PJ=[`pre`,`script`,`style`,`textarea`],FJ={concrete:!0,name:`htmlFlow`,resolveTo:LJ,tokenize:RJ},IJ={partial:!0,tokenize:zJ};function LJ(e){let t=e.length;for(;t--&&(e[t][0]!==`enter`||e[t][1].type!==`htmlFlow`););return t>1&&e[t-2][1].type===`linePrefix`&&(e[t][1].start=e[t-2][1].start,e[t+1][1].start=e[t-2][1].start,e.splice(t-2,2)),e}function RJ(e,t,n){let r=this,i,a,o,s,c;return l;function l(e){return u(e)}function u(t){return e.enter(`htmlFlow`),e.enter(`htmlFlowData`),e.consume(t),d}function d(s){return s===33?(e.consume(s),f):s===47?(e.consume(s),a=!0,h):s===63?(e.consume(s),i=3,r.interrupt?t:I):dq(s)?(e.consume(s),o=String.fromCharCode(s),g):n(s)}function f(a){return a===45?(e.consume(a),i=2,p):a===91?(e.consume(a),i=5,s=0,m):dq(a)?(e.consume(a),i=4,r.interrupt?t:I):n(a)}function p(i){return i===45?(e.consume(i),r.interrupt?t:I):n(i)}function m(i){return i===`CDATA[`.charCodeAt(s++)?(e.consume(i),s===6?r.interrupt?t:O:m):n(i)}function h(t){return dq(t)?(e.consume(t),o=String.fromCharCode(t),g):n(t)}function g(s){if(s===null||s===47||s===62||yq(s)){let c=s===47,l=o.toLowerCase();return!c&&!a&&PJ.includes(l)?(i=1,r.interrupt?t(s):O(s)):NJ.includes(o.toLowerCase())?(i=6,c?(e.consume(s),_):r.interrupt?t(s):O(s)):(i=7,r.interrupt&&!r.parser.lazy[r.now().line]?n(s):a?v(s):y(s))}return s===45||fq(s)?(e.consume(s),o+=String.fromCharCode(s),g):n(s)}function _(i){return i===62?(e.consume(i),r.interrupt?t:O):n(i)}function v(t){return bq(t)?(e.consume(t),v):E(t)}function y(t){return t===47?(e.consume(t),E):t===58||t===95||dq(t)?(e.consume(t),b):bq(t)?(e.consume(t),y):E(t)}function b(t){return t===45||t===46||t===58||t===95||fq(t)?(e.consume(t),b):x(t)}function x(t){return t===61?(e.consume(t),S):bq(t)?(e.consume(t),x):y(t)}function S(t){return t===null||t===60||t===61||t===62||t===96?n(t):t===34||t===39?(e.consume(t),c=t,C):bq(t)?(e.consume(t),S):w(t)}function C(t){return t===c?(e.consume(t),c=null,T):t===null||vq(t)?n(t):(e.consume(t),C)}function w(t){return t===null||t===34||t===39||t===47||t===60||t===61||t===62||t===96||yq(t)?x(t):(e.consume(t),w)}function T(e){return e===47||e===62||bq(e)?y(e):n(e)}function E(t){return t===62?(e.consume(t),D):n(t)}function D(t){return t===null||vq(t)?O(t):bq(t)?(e.consume(t),D):n(t)}function O(t){return t===45&&i===2?(e.consume(t),M):t===60&&i===1?(e.consume(t),N):t===62&&i===4?(e.consume(t),L):t===63&&i===3?(e.consume(t),I):t===93&&i===5?(e.consume(t),F):vq(t)&&(i===6||i===7)?(e.exit(`htmlFlowData`),e.check(IJ,R,k)(t)):t===null||vq(t)?(e.exit(`htmlFlowData`),k(t)):(e.consume(t),O)}function k(t){return e.check($q,A,R)(t)}function A(t){return e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),j}function j(t){return t===null||vq(t)?k(t):(e.enter(`htmlFlowData`),O(t))}function M(t){return t===45?(e.consume(t),I):O(t)}function N(t){return t===47?(e.consume(t),o=``,P):O(t)}function P(t){if(t===62){let n=o.toLowerCase();return PJ.includes(n)?(e.consume(t),L):O(t)}return dq(t)&&o.length<8?(e.consume(t),o+=String.fromCharCode(t),P):O(t)}function F(t){return t===93?(e.consume(t),I):O(t)}function I(t){return t===62?(e.consume(t),L):t===45&&i===2?(e.consume(t),I):O(t)}function L(t){return t===null||vq(t)?(e.exit(`htmlFlowData`),R(t)):(e.consume(t),L)}function R(n){return e.exit(`htmlFlow`),t(n)}}function zJ(e,t,n){return r;function r(r){return e.enter(`lineEnding`),e.consume(r),e.exit(`lineEnding`),e.attempt(Uq,t,n)}}var BJ={name:`htmlText`,tokenize:VJ};function VJ(e,t,n){let r=this,i,a,o;return s;function s(t){return e.enter(`htmlText`),e.enter(`htmlTextData`),e.consume(t),c}function c(t){return t===33?(e.consume(t),l):t===47?(e.consume(t),x):t===63?(e.consume(t),y):dq(t)?(e.consume(t),w):n(t)}function l(t){return t===45?(e.consume(t),u):t===91?(e.consume(t),a=0,m):dq(t)?(e.consume(t),v):n(t)}function u(t){return t===45?(e.consume(t),p):n(t)}function d(t){return t===null?n(t):t===45?(e.consume(t),f):vq(t)?(o=d,N(t)):(e.consume(t),d)}function f(t){return t===45?(e.consume(t),p):d(t)}function p(e){return e===62?M(e):e===45?f(e):d(e)}function m(t){return t===`CDATA[`.charCodeAt(a++)?(e.consume(t),a===6?h:m):n(t)}function h(t){return t===null?n(t):t===93?(e.consume(t),g):vq(t)?(o=h,N(t)):(e.consume(t),h)}function g(t){return t===93?(e.consume(t),_):h(t)}function _(t){return t===62?M(t):t===93?(e.consume(t),_):h(t)}function v(t){return t===null||t===62?M(t):vq(t)?(o=v,N(t)):(e.consume(t),v)}function y(t){return t===null?n(t):t===63?(e.consume(t),b):vq(t)?(o=y,N(t)):(e.consume(t),y)}function b(e){return e===62?M(e):y(e)}function x(t){return dq(t)?(e.consume(t),S):n(t)}function S(t){return t===45||fq(t)?(e.consume(t),S):C(t)}function C(t){return vq(t)?(o=C,N(t)):bq(t)?(e.consume(t),C):M(t)}function w(t){return t===45||fq(t)?(e.consume(t),w):t===47||t===62||yq(t)?T(t):n(t)}function T(t){return t===47?(e.consume(t),M):t===58||t===95||dq(t)?(e.consume(t),E):vq(t)?(o=T,N(t)):bq(t)?(e.consume(t),T):M(t)}function E(t){return t===45||t===46||t===58||t===95||fq(t)?(e.consume(t),E):D(t)}function D(t){return t===61?(e.consume(t),O):vq(t)?(o=D,N(t)):bq(t)?(e.consume(t),D):T(t)}function O(t){return t===null||t===60||t===61||t===62||t===96?n(t):t===34||t===39?(e.consume(t),i=t,k):vq(t)?(o=O,N(t)):bq(t)?(e.consume(t),O):(e.consume(t),A)}function k(t){return t===i?(e.consume(t),i=void 0,j):t===null?n(t):vq(t)?(o=k,N(t)):(e.consume(t),k)}function A(t){return t===null||t===34||t===39||t===60||t===61||t===96?n(t):t===47||t===62||yq(t)?T(t):(e.consume(t),A)}function j(e){return e===47||e===62||yq(e)?T(e):n(e)}function M(r){return r===62?(e.consume(r),e.exit(`htmlTextData`),e.exit(`htmlText`),t):n(r)}function N(t){return e.exit(`htmlTextData`),e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),P}function P(t){return bq(t)?Tq(e,F,`linePrefix`,r.parser.constructs.disable.null.includes(`codeIndented`)?void 0:4)(t):F(t)}function F(t){return e.enter(`htmlTextData`),o(t)}}var HJ={name:`labelEnd`,resolveAll:KJ,resolveTo:qJ,tokenize:JJ},UJ={tokenize:YJ},WJ={tokenize:XJ},GJ={tokenize:ZJ};function KJ(e){let t=-1,n=[];for(;++t<e.length;){let r=e[t][1];if(n.push(e[t]),r.type===`labelImage`||r.type===`labelLink`||r.type===`labelEnd`){let e=r.type===`labelImage`?4:2;r.type=`data`,t+=e}}return e.length!==n.length&&rq(e,0,e.length,n),e}function qJ(e,t){let n=e.length,r=0,i,a,o;for(;n--;){let t=e[n][1];if(i){if(t.type===`link`||t.type===`labelLink`&&t._inactive)break;e[n][0]===`enter`&&t.type===`labelLink`&&(t._inactive=!0)}else if(a){if(e[n][0]===`enter`&&(t.type===`labelImage`||t.type===`labelLink`)&&!t._balanced&&(i=n,t.type!==`labelLink`)){r=2;break}}else t.type===`labelEnd`&&(a=n)}let s={type:e[i][1].type===`labelLink`?`link`:`image`,start:{...e[i][1].start},end:{...e[e.length-1][1].end}},c={type:`label`,start:{...e[i][1].start},end:{...e[a][1].end}},l={type:`labelText`,start:{...e[i+r+2][1].end},end:{...e[a-2][1].start}};return o=[[`enter`,s,t],[`enter`,c,t]],o=iq(o,e.slice(i+1,i+r+3)),o=iq(o,[[`enter`,l,t]]),o=iq(o,Iq(t.parser.constructs.insideSpan.null,e.slice(i+r+4,a-3),t)),o=iq(o,[[`exit`,l,t],e[a-2],e[a-1],[`exit`,c,t]]),o=iq(o,e.slice(a+1)),o=iq(o,[[`exit`,s,t]]),rq(e,i,e.length,o),e}function JJ(e,t,n){let r=this,i=r._labelStarts,a,o;if(i){for(;i.length>0&&i[i.length-1]._balanced;)i.pop();a=i[i.length-1]}return s;function s(t){return a?a._inactive?d(t):(o=r.parser.defined.includes(uq(r.sliceSerialize({start:a.end,end:r.now()}))),e.enter(`labelEnd`),e.enter(`labelMarker`),e.consume(t),e.exit(`labelMarker`),e.exit(`labelEnd`),c):n(t)}function c(t){return t===40?e.attempt(UJ,u,o?u:d)(t):t===91?e.attempt(WJ,u,o?l:d)(t):o?u(t):d(t)}function l(t){return e.attempt(GJ,u,d)(t)}function u(e){return i.pop(),t(e)}function d(e){return a._balanced=!0,n(e)}}function YJ(e,t,n){return r;function r(t){return e.enter(`resource`),e.enter(`resourceMarker`),e.consume(t),e.exit(`resourceMarker`),i}function i(t){return yq(t)?CJ(e,a)(t):a(t)}function a(t){return t===41?u(t):bJ(e,o,s,`resourceDestination`,`resourceDestinationLiteral`,`resourceDestinationLiteralMarker`,`resourceDestinationRaw`,`resourceDestinationString`,32)(t)}function o(t){return yq(t)?CJ(e,c)(t):u(t)}function s(e){return n(e)}function c(t){return t===34||t===39||t===40?SJ(e,l,n,`resourceTitle`,`resourceTitleMarker`,`resourceTitleString`)(t):u(t)}function l(t){return yq(t)?CJ(e,u)(t):u(t)}function u(r){return r===41?(e.enter(`resourceMarker`),e.consume(r),e.exit(`resourceMarker`),e.exit(`resource`),t):n(r)}}function XJ(e,t,n){let r=this;return i;function i(t){return xJ.call(r,e,a,o,`reference`,`referenceMarker`,`referenceString`)(t)}function a(e){return r.parser.defined.includes(uq(r.sliceSerialize(r.events[r.events.length-1][1]).slice(1,-1)))?t(e):n(e)}function o(e){return n(e)}}function ZJ(e,t,n){return r;function r(t){return e.enter(`reference`),e.enter(`referenceMarker`),e.consume(t),e.exit(`referenceMarker`),i}function i(r){return r===93?(e.enter(`referenceMarker`),e.consume(r),e.exit(`referenceMarker`),e.exit(`reference`),t):n(r)}}var QJ={name:`labelStartImage`,resolveAll:HJ.resolveAll,tokenize:$J};function $J(e,t,n){let r=this,i;return a;function a(t){return e.enter(`labelImage`),e.enter(`labelImageMarker`),e.consume(t),e.exit(`labelImageMarker`),o}function o(t){return t===91?(e.enter(`labelMarker`),e.consume(t),e.exit(`labelMarker`),i=e.exit(`labelImage`),s):n(t)}function s(e){return e===94&&`_hiddenFootnoteSupport`in r.parser.constructs?n(e):(r._labelStarts=r._labelStarts||[],r._labelStarts.push(i),t(e))}}var eY={name:`labelStartLink`,resolveAll:HJ.resolveAll,tokenize:tY};function tY(e,t,n){let r=this,i;return a;function a(t){return e.enter(`labelLink`),e.enter(`labelMarker`),e.consume(t),e.exit(`labelMarker`),i=e.exit(`labelLink`),o}function o(e){return e===94&&`_hiddenFootnoteSupport`in r.parser.constructs?n(e):(r._labelStarts=r._labelStarts||[],r._labelStarts.push(i),t(e))}}var nY={name:`lineEnding`,tokenize:rY};function rY(e,t){return n;function n(n){return e.enter(`lineEnding`),e.consume(n),e.exit(`lineEnding`),Tq(e,t,`linePrefix`)}}var iY={name:`thematicBreak`,tokenize:aY};function aY(e,t,n){let r=0,i;return a;function a(t){return e.enter(`thematicBreak`),o(t)}function o(e){return i=e,s(e)}function s(a){return a===i?(e.enter(`thematicBreakSequence`),c(a)):r>=3&&(a===null||vq(a))?(e.exit(`thematicBreak`),t(a)):n(a)}function c(t){return t===i?(e.consume(t),r++,c):(e.exit(`thematicBreakSequence`),bq(t)?Tq(e,s,`whitespace`)(t):s(t))}}var oY={continuation:{tokenize:uY},exit:fY,name:`list`,tokenize:lY},sY={partial:!0,tokenize:pY},cY={partial:!0,tokenize:dY};function lY(e,t,n){let r=this,i=r.events[r.events.length-1],a=i&&i[1].type===`linePrefix`?i[2].sliceSerialize(i[1],!0).length:0,o=0;return s;function s(t){let i=r.containerState.type||(t===42||t===43||t===45?`listUnordered`:`listOrdered`);if(i===`listUnordered`?!r.containerState.marker||t===r.containerState.marker:hq(t)){if(r.containerState.type||(r.containerState.type=i,e.enter(i,{_container:!0})),i===`listUnordered`)return e.enter(`listItemPrefix`),t===42||t===45?e.check(iY,n,l)(t):l(t);if(!r.interrupt||t===49)return e.enter(`listItemPrefix`),e.enter(`listItemValue`),c(t)}return n(t)}function c(t){return hq(t)&&++o<10?(e.consume(t),c):(!r.interrupt||o<2)&&(r.containerState.marker?t===r.containerState.marker:t===41||t===46)?(e.exit(`listItemValue`),l(t)):n(t)}function l(t){return e.enter(`listItemMarker`),e.consume(t),e.exit(`listItemMarker`),r.containerState.marker=r.containerState.marker||t,e.check(Uq,r.interrupt?n:u,e.attempt(sY,f,d))}function u(e){return r.containerState.initialBlankLine=!0,a++,f(e)}function d(t){return bq(t)?(e.enter(`listItemPrefixWhitespace`),e.consume(t),e.exit(`listItemPrefixWhitespace`),f):n(t)}function f(n){return r.containerState.size=a+r.sliceSerialize(e.exit(`listItemPrefix`),!0).length,t(n)}}function uY(e,t,n){let r=this;return r.containerState._closeFlow=void 0,e.check(Uq,i,a);function i(n){return r.containerState.furtherBlankLines=r.containerState.furtherBlankLines||r.containerState.initialBlankLine,Tq(e,t,`listItemIndent`,r.containerState.size+1)(n)}function a(n){return r.containerState.furtherBlankLines||!bq(n)?(r.containerState.furtherBlankLines=void 0,r.containerState.initialBlankLine=void 0,o(n)):(r.containerState.furtherBlankLines=void 0,r.containerState.initialBlankLine=void 0,e.attempt(cY,t,o)(n))}function o(i){return r.containerState._closeFlow=!0,r.interrupt=void 0,Tq(e,e.attempt(oY,t,n),`linePrefix`,r.parser.constructs.disable.null.includes(`codeIndented`)?void 0:4)(i)}}function dY(e,t,n){let r=this;return Tq(e,i,`listItemIndent`,r.containerState.size+1);function i(e){let i=r.events[r.events.length-1];return i&&i[1].type===`listItemIndent`&&i[2].sliceSerialize(i[1],!0).length===r.containerState.size?t(e):n(e)}}function fY(e){e.exit(this.containerState.type)}function pY(e,t,n){let r=this;return Tq(e,i,`listItemPrefixWhitespace`,r.parser.constructs.disable.null.includes(`codeIndented`)?void 0:5);function i(e){let i=r.events[r.events.length-1];return!bq(e)&&i&&i[1].type===`listItemPrefixWhitespace`?t(e):n(e)}}var mY={name:`setextUnderline`,resolveTo:hY,tokenize:gY};function hY(e,t){let n=new kq,r=e.length,i,a,o;for(;r--;)if(e[r][0]===`enter`){if(e[r][1].type===`content`){i=r;break}e[r][1].type===`paragraph`&&(a=r)}else e[r][1].type===`content`&&n.add(r,1,[]),!o&&e[r][1].type===`definition`&&(o=r);let s={type:`setextHeading`,start:{...e[i][1].start},end:{...e[e.length-1][1].end}};return e[a][1].type=`setextHeadingText`,o?(n.add(a,0,[[`enter`,s,t]]),n.add(o+1,0,[[`exit`,e[i][1],t]]),e[i][1].end={...e[o][1].end}):e[i][1]=s,n.add(e.length,0,[[`exit`,s,t]]),n.consume(e),e}function gY(e,t,n){let r=this,i;return a;function a(t){let a=r.events.length,s;for(;a--;)if(r.events[a][1].type!==`lineEnding`&&r.events[a][1].type!==`linePrefix`&&r.events[a][1].type!==`content`){s=r.events[a][1].type===`paragraph`;break}return!r.parser.lazy[r.now().line]&&(r.interrupt||s)?(e.enter(`setextHeadingLine`),i=t,o(t)):n(t)}function o(t){return e.enter(`setextHeadingLineSequence`),s(t)}function s(t){return t===i?(e.consume(t),s):(e.exit(`setextHeadingLineSequence`),bq(t)?Tq(e,c,`lineSuffix`)(t):c(t))}function c(r){return r===null||vq(r)?(e.exit(`setextHeadingLine`),t(r)):n(r)}}var _Y={tokenize:vY};function vY(e){let t=this,n=e.attempt(Uq,r,e.attempt(this.parser.constructs.flowInitial,i,Tq(e,e.attempt(this.parser.constructs.flow,i,e.attempt(hJ,i)),`linePrefix`)));return n;function r(r){if(r===null)e.consume(r);else return e.enter(`lineEndingBlank`),e.consume(r),e.exit(`lineEndingBlank`),t.currentConstruct=void 0,n}function i(r){if(r===null)e.consume(r);else return e.enter(`lineEnding`),e.consume(r),e.exit(`lineEnding`),t.currentConstruct=void 0,n}}var yY={resolveAll:CY()},bY=SY(`string`),xY=SY(`text`);function SY(e){return{resolveAll:CY(e===`text`?wY:void 0),tokenize:t};function t(t){let n=this,r=this.parser.constructs[e],i=t.attempt(r,a,o);return a;function a(e){return c(e)?i(e):o(e)}function o(e){if(e===null)t.consume(e);else return t.enter(`data`),t.consume(e),s}function s(e){return c(e)?(t.exit(`data`),i(e)):(t.consume(e),s)}function c(e){if(e===null)return!0;let t=r[e],i=-1;if(t)for(;++i<t.length;){let e=t[i];if(!e.previous||e.previous.call(n,n.previous))return!0}return!1}}}function CY(e){return t;function t(t,n){let r=-1,i;for(;++r<=t.length;)i===void 0?t[r]&&t[r][1].type===`data`&&(i=r,r++):t[r]&&t[r][1].type===`data`||(r!==i+2&&(t[i][1].end=t[r-1][1].end,t.splice(i+2,r-i-2),r=i+2),i=void 0);return e?e(t,n):t}}function wY(e,t){let n=new kq,r=0;for(;++r<=e.length;)if((r===e.length||e[r][1].type===`lineEnding`)&&e[r-1][1].type===`data`){let i=e[r-1][1],a=t.sliceStream(i),o=a.length,s=-1,c=0,l;for(;o--;){let e=a[o];if(typeof e==`string`){for(s=e.length;e.charCodeAt(s-1)===32;)c++,s--;if(s)break;s=-1}else if(e===-2)l=!0,c++;else if(e!==-1){o++;break}}if(t._contentTypeTextTrailing&&r===e.length&&(c=0),c){let a={type:r===e.length||l||c<2?`lineSuffix`:`hardBreakTrailing`,start:{_bufferIndex:o?s:i.start._bufferIndex+s,_index:i.start._index+o,line:i.end.line,column:i.end.column-c,offset:i.end.offset-c},end:{...i.end}};i.end={...a.start},i.start.offset===i.end.offset?Object.assign(i,a):n.add(r,0,[[`enter`,a,t],[`exit`,a,t]])}r++}return n.consume(e),e}var TY=s({attentionMarkers:()=>NY,contentInitial:()=>DY,disable:()=>PY,document:()=>EY,flow:()=>kY,flowInitial:()=>OY,insideSpan:()=>MY,string:()=>AY,text:()=>jY}),EY={42:oY,43:oY,45:oY,48:oY,49:oY,50:oY,51:oY,52:oY,53:oY,54:oY,55:oY,56:oY,57:oY,62:Gq},DY={91:wJ},OY={[-2]:rJ,[-1]:rJ,32:rJ},kY={35:AJ,42:iY,45:[mY,iY],60:FJ,61:mY,95:iY,96:tJ,126:tJ},AY={38:Zq,92:Yq},jY={[-5]:nY,[-4]:nY,[-3]:nY,33:QJ,38:Zq,42:Lq,60:[Vq,BJ],91:eY,92:[OJ,Yq],93:HJ,95:Lq,96:sJ},MY={null:[Lq,yY]},NY={null:[42,95]},PY={null:[]};function FY(e,t,n){let r={_bufferIndex:-1,_index:0,line:n&&n.line||1,column:n&&n.column||1,offset:n&&n.offset||0},i={},a=[],o=[],s=[],c={attempt:C(x),check:C(S),consume:v,enter:y,exit:b,interrupt:C(S,{interrupt:!0})},l={code:null,containerState:{},defineSkip:h,events:[],now:m,parser:e,previous:null,sliceSerialize:f,sliceStream:p,write:d},u=t.tokenize.call(l,c);return t.resolveAll&&a.push(t),l;function d(e){return o=iq(o,e),g(),o[o.length-1]===null?(w(t,0),l.events=Iq(a,l.events,l),l.events):[]}function f(e,t){return LY(p(e),t)}function p(e){return IY(o,e)}function m(){let{_bufferIndex:e,_index:t,line:n,column:i,offset:a}=r;return{_bufferIndex:e,_index:t,line:n,column:i,offset:a}}function h(e){i[e.line]=e.column,E()}function g(){for(;r._index<o.length;){let e=o[r._index];if(typeof e==`string`){let t=r._index;for(r._bufferIndex<0&&(r._bufferIndex=0);r._index===t&&r._bufferIndex<e.length;)_(e.charCodeAt(r._bufferIndex))}else _(e)}}function _(e){u=u(e)}function v(e){vq(e)?(r.line++,r.column=1,r.offset+=e===-3?2:1,E()):e!==-1&&(r.column++,r.offset++),r._bufferIndex<0?r._index++:(r._bufferIndex++,r._bufferIndex===o[r._index].length&&(r._bufferIndex=-1,r._index++)),l.previous=e}function y(e,t){let n=t||{};return n.type=e,n.start=m(),l.events.push([`enter`,n,l]),s.push(n),n}function b(e){let t=s.pop();return t.end=m(),l.events.push([`exit`,t,l]),t}function x(e,t){w(e,t.from)}function S(e,t){t.restore()}function C(e,t){return n;function n(n,r,i){let a,o,s,u;return Array.isArray(n)?f(n):`tokenize`in n?f([n]):d(n);function d(e){return t;function t(t){let n=t!==null&&e[t],r=t!==null&&e.null;return f([...Array.isArray(n)?n:n?[n]:[],...Array.isArray(r)?r:r?[r]:[]])(t)}}function f(e){return a=e,o=0,e.length===0?i:p(e[o])}function p(e){return n;function n(n){return u=T(),s=e,e.partial||(l.currentConstruct=e),e.name&&l.parser.constructs.disable.null.includes(e.name)?h(n):e.tokenize.call(t?Object.assign(Object.create(l),t):l,c,m,h)(n)}}function m(t){return e(s,u),r}function h(e){return u.restore(),++o<a.length?p(a[o]):i}}}function w(e,t){e.resolveAll&&!a.includes(e)&&a.push(e),e.resolve&&rq(l.events,t,l.events.length-t,e.resolve(l.events.slice(t),l)),e.resolveTo&&(l.events=e.resolveTo(l.events,l))}function T(){let e=m(),t=l.previous,n=l.currentConstruct,i=l.events.length,a=Array.from(s);return{from:i,restore:o};function o(){r=e,l.previous=t,l.currentConstruct=n,l.events.length=i,s=a,E()}}function E(){r.line in i&&r.column<2&&(r.column=i[r.line],r.offset+=i[r.line]-1)}}function IY(e,t){let n=t.start._index,r=t.start._bufferIndex,i=t.end._index,a=t.end._bufferIndex,o;if(n===i)o=[e[n].slice(r,a)];else{if(o=e.slice(n,i),r>-1){let e=o[0];typeof e==`string`?o[0]=e.slice(r):o.shift()}a>0&&o.push(e[i].slice(0,a))}return o}function LY(e,t){let n=-1,r=[],i;for(;++n<e.length;){let a=e[n],o;if(typeof a==`string`)o=a;else switch(a){case-5:o=`\r`;break;case-4:o=`
|
|
62
|
+
`;break;case-3:o=`\r
|
|
63
|
+
`;break;case-2:o=t?` `:` `;break;case-1:if(!t&&i)continue;o=` `;break;default:o=String.fromCharCode(a)}i=a===-2,r.push(o)}return r.join(``)}function RY(e){let t={constructs:oq([TY,...(e||{}).extensions||[]]),content:n(Dq),defined:[],document:n(jq),flow:n(_Y),lazy:{},string:n(bY),text:n(xY)};return t;function n(e){return n;function n(n){return FY(t,e,n)}}}function zY(e){for(;!pJ(e););return e}var BY=/[\0\t\n\r]/g;function VY(){let e=1,t=``,n=!0,r;return i;function i(i,a,o){i=t+(typeof i==`string`?i.toString():new TextDecoder(a||void 0).decode(i));let s=[],c=0;for(t=``,n&&=(i.charCodeAt(0)===65279&&c++,void 0);c<i.length;){BY.lastIndex=c;let n=BY.exec(i),a=n&&n.index!==void 0?n.index:i.length,o=i.charCodeAt(a);if(!n){t=i.slice(c);break}if(o===10&&c===a&&r)s.push(-3),r=void 0;else switch(r&&=(s.push(-5),void 0),c<a&&(s.push(i.slice(c,a)),e+=a-c),o){case 0:s.push(65533),e++;break;case 9:{let t=Math.ceil(e/4)*4;for(s.push(-2);e++<t;)s.push(-1);break}case 10:s.push(-4),e=1;break;default:r=!0,e=1}c=a+1}return o&&(r&&s.push(-5),t&&s.push(t),s.push(null)),s}}var HY=/\\([!-/:-@[-`{-~])|&(#(?:\d{1,7}|x[\da-f]{1,6})|[\da-z]{1,31});/gi;function UY(e){return e.replace(HY,WY)}function WY(e,t,n){if(t)return t;if(n.charCodeAt(0)===35){let e=n.charCodeAt(1),t=e===120||e===88;return lq(n.slice(t?2:1),t?16:10)}return nq(n)||e}var GY={}.hasOwnProperty;function KY(e,t,n){return t&&typeof t==`object`&&(n=t,t=void 0),qY(n)(zY(RY(n).document().write(VY()(e,t,!0))))}function qY(e){let t={afterExit:[],beforeEnter:[],transforms:[],canContainEols:[`emphasis`,`fragment`,`heading`,`paragraph`,`strong`],enter:{autolink:o(me),autolinkProtocol:E,autolinkEmail:E,atxHeading:o(ue),blockQuote:o(ae),characterEscape:E,characterReference:E,codeFenced:o(oe),codeFencedFenceInfo:s,codeFencedFenceMeta:s,codeIndented:o(oe,s),codeText:o(se,s),codeTextData:E,data:E,codeFlowValue:E,definition:o(ce),definitionDestinationString:s,definitionLabelString:s,definitionTitleString:s,emphasis:o(le),hardBreakEscape:o(de),hardBreakTrailing:o(de),htmlFlow:o(fe,s),htmlFlowData:E,htmlText:o(fe,s),htmlTextData:E,image:o(pe),label:s,link:o(me),listItem:o(ge),listItemValue:p,listOrdered:o(he,f),listUnordered:o(he),paragraph:o(_e),reference:ee,referenceString:s,resourceDestinationString:s,resourceTitleString:s,setextHeading:o(ue),strong:o(ve),thematicBreak:o(be)},exit:{atxHeading:l(),atxHeadingSequence:S,autolink:l(),autolinkEmail:V,autolinkProtocol:ie,blockQuote:l(),characterEscapeValue:D,characterReferenceMarkerHexadecimal:ne,characterReferenceMarkerNumeric:ne,characterReferenceValue:B,characterReference:re,codeFenced:l(_),codeFencedFence:g,codeFencedFenceInfo:m,codeFencedFenceMeta:h,codeFlowValue:D,codeIndented:l(v),codeText:l(M),codeTextData:D,data:D,definition:l(),definitionDestinationString:x,definitionLabelString:y,definitionTitleString:b,emphasis:l(),hardBreakEscape:l(k),hardBreakTrailing:l(k),htmlFlow:l(A),htmlFlowData:D,htmlText:l(j),htmlTextData:D,image:l(P),label:I,labelText:F,lineEnding:O,link:l(N),listItem:l(),listOrdered:l(),listUnordered:l(),paragraph:l(),referenceString:te,resourceDestinationString:L,resourceTitleString:R,resource:z,setextHeading:l(T),setextHeadingLineSequence:w,setextHeadingText:C,strong:l(),thematicBreak:l()}};YY(t,(e||{}).mdastExtensions||[]);let n={};return r;function r(e){let r={type:`root`,children:[],position:void 0},o={stack:[r],tokenStack:[],config:t,enter:c,exit:u,buffer:s,resume:d,data:n},l=[],f=[],p=-1;for(;++p<e.length;)f.push(e[p]),(e[p][1].type===`listOrdered`||e[p][1].type===`listUnordered`)&&(e[p][0]===`enter`?l.push(f.length-1):a(f,l.pop()));for(e=f,p=-1;++p<e.length;){let n=t[e[p][0]];e[p][0]===`enter`&&t.beforeEnter.length>0&&i(t.beforeEnter,{...o,sliceSerialize:e[p][2].sliceSerialize},e[p][1]),GY.call(n,e[p][1].type)&&n[e[p][1].type].call({...o,sliceSerialize:e[p][2].sliceSerialize},e[p][1]),e[p][0]===`exit`&&t.afterExit.length>0&&i(t.afterExit,{...o,sliceSerialize:e[p][2].sliceSerialize},e[p][1])}if(o.tokenStack.length>0){let e=o.tokenStack[o.tokenStack.length-1];(e[1]||ZY).call(o,void 0,e[0])}for(r.position={start:JY(e.length>0?e[0][1].start:{line:1,column:1,offset:0}),end:JY(e.length>0?e[e.length-2][1].end:{line:1,column:1,offset:0})},p=-1;++p<t.transforms.length;)r=t.transforms[p](r)||r;return r}function i(e,t,n){let r=-1;for(;++r<e.length;)e[r].call(t,n)}function a(e,t){let n=e.length-1,r=t-1,i=-1,a=!1,o,s,c,l,u=[];for(;++r<=n;){let t=e[r];switch(t[1].type){case`listUnordered`:case`listOrdered`:case`blockQuote`:t[0]===`enter`?i++:i--,l=void 0;break;case`lineEndingBlank`:t[0]===`enter`&&(o&&!l&&!i&&!c&&(c=r),l=void 0);break;case`linePrefix`:case`listItemValue`:case`listItemMarker`:case`listItemPrefix`:case`listItemPrefixWhitespace`:break;default:l=void 0}if(!i&&t[0]===`enter`&&t[1].type===`listItemPrefix`||i===-1&&t[0]===`exit`&&(t[1].type===`listUnordered`||t[1].type===`listOrdered`)){if(o){let n=r;for(s=void 0;n--;){let t=e[n];if(t[1].type===`lineEnding`||t[1].type===`lineEndingBlank`){if(t[0]===`exit`)continue;s&&(e[s][1].type=`lineEndingBlank`,a=!0),t[1].type=`lineEnding`,s=n}else if(t[1].type!==`linePrefix`&&t[1].type!==`blockQuotePrefix`&&t[1].type!==`blockQuotePrefixWhitespace`&&t[1].type!==`blockQuoteMarker`&&t[1].type!==`listItemIndent`)break}c&&(!s||c<s)&&(o._spread=!0),o.end=Object.assign({},s?e[s][1].start:t[1].end),u.push({at:s||r,event:[`exit`,o,t[2]]})}if(t[1].type===`listItemPrefix`){let e={type:`listItem`,_spread:!1,start:Object.assign({},t[1].start),end:void 0};o=e,u.push({at:r,event:[`enter`,e,t[2]]}),c=void 0,l=!0}}}let d=e.splice(t),f=0;for(r=-1;++r<d.length;){for(;f<u.length&&u[f].at===t+r;)e.push(u[f++].event);e.push(d[r])}e[t][1]._spread=a}function o(e,t){return n;function n(n){c.call(this,e(n),n),t&&t.call(this,n)}}function s(){this.stack.push({type:`fragment`,children:[]})}function c(e,t,n){this.stack[this.stack.length-1].children.push(e),this.stack.push(e),this.tokenStack.push([t,n||void 0]),e.position={start:JY(t.start),end:void 0}}function l(e){return t;function t(t){e&&e.call(this,t),u.call(this,t)}}function u(e,t){let n=this.stack.pop(),r=this.tokenStack.pop();if(!r)throw Error("Cannot close `"+e.type+"` ("+mK({start:e.start,end:e.end})+`): it’s not open`);r[0].type!==e.type&&(t?t.call(this,e,r[0]):(r[1]||ZY).call(this,e,r[0])),n.position.end=JY(e.end)}function d(){return ZK(this.stack.pop())}function f(){this.data.expectingFirstListItemValue=!0}function p(e){if(this.data.expectingFirstListItemValue){let t=this.stack[this.stack.length-2];t.start=Number.parseInt(this.sliceSerialize(e),10),this.data.expectingFirstListItemValue=void 0}}function m(){let e=this.resume(),t=this.stack[this.stack.length-1];t.lang=e}function h(){let e=this.resume(),t=this.stack[this.stack.length-1];t.meta=e}function g(){this.data.flowCodeInside||(this.buffer(),this.data.flowCodeInside=!0)}function _(){let e=this.resume(),t=this.stack[this.stack.length-1];t.value=e.replace(/^(\r?\n|\r)|(\r?\n|\r)$/g,``),this.data.flowCodeInside=void 0}function v(){let e=this.resume(),t=this.stack[this.stack.length-1];t.value=e.replace(/(\r?\n|\r)$/g,``)}function y(e){let t=this.resume(),n=this.stack[this.stack.length-1];n.label=t,n.identifier=uq(this.sliceSerialize(e)).toLowerCase()}function b(){let e=this.resume(),t=this.stack[this.stack.length-1];t.title=e}function x(){let e=this.resume(),t=this.stack[this.stack.length-1];t.url=e}function S(e){let t=this.stack[this.stack.length-1];t.depth||=this.sliceSerialize(e).length}function C(){this.data.setextHeadingSlurpLineEnding=!0}function w(e){let t=this.stack[this.stack.length-1];t.depth=this.sliceSerialize(e).codePointAt(0)===61?1:2}function T(){this.data.setextHeadingSlurpLineEnding=void 0}function E(e){let t=this.stack[this.stack.length-1].children,n=t[t.length-1];n&&n.type===`text`||(n=ye(),n.position={start:JY(e.start),end:void 0},t.push(n)),this.stack.push(n)}function D(e){let t=this.stack.pop();t.value+=this.sliceSerialize(e),t.position.end=JY(e.end)}function O(e){let n=this.stack[this.stack.length-1];if(this.data.atHardBreak){let t=n.children[n.children.length-1];t.position.end=JY(e.end),this.data.atHardBreak=void 0}else!this.data.setextHeadingSlurpLineEnding&&t.canContainEols.includes(n.type)&&(E.call(this,e),D.call(this,e))}function k(){this.data.atHardBreak=!0}function A(){let e=this.resume(),t=this.stack[this.stack.length-1];t.value=e}function j(){let e=this.resume(),t=this.stack[this.stack.length-1];t.value=e}function M(){let e=this.resume(),t=this.stack[this.stack.length-1];t.value=e}function N(){let e=this.stack[this.stack.length-1];if(this.data.inReference){let t=this.data.referenceType||`shortcut`;e.type+=`Reference`,e.referenceType=t,delete e.url,delete e.title}else delete e.identifier,delete e.label;this.data.referenceType=void 0}function P(){let e=this.stack[this.stack.length-1];if(this.data.inReference){let t=this.data.referenceType||`shortcut`;e.type+=`Reference`,e.referenceType=t,delete e.url,delete e.title}else delete e.identifier,delete e.label;this.data.referenceType=void 0}function F(e){let t=this.sliceSerialize(e),n=this.stack[this.stack.length-2];n.label=UY(t),n.identifier=uq(t).toLowerCase()}function I(){let e=this.stack[this.stack.length-1],t=this.resume(),n=this.stack[this.stack.length-1];this.data.inReference=!0,n.type===`link`?n.children=e.children:n.alt=t}function L(){let e=this.resume(),t=this.stack[this.stack.length-1];t.url=e}function R(){let e=this.resume(),t=this.stack[this.stack.length-1];t.title=e}function z(){this.data.inReference=void 0}function ee(){this.data.referenceType=`collapsed`}function te(e){let t=this.resume(),n=this.stack[this.stack.length-1];n.label=t,n.identifier=uq(this.sliceSerialize(e)).toLowerCase(),this.data.referenceType=`full`}function ne(e){this.data.characterReferenceType=e.type}function B(e){let t=this.sliceSerialize(e),n=this.data.characterReferenceType,r;n?(r=lq(t,n===`characterReferenceMarkerNumeric`?10:16),this.data.characterReferenceType=void 0):r=nq(t);let i=this.stack[this.stack.length-1];i.value+=r}function re(e){let t=this.stack.pop();t.position.end=JY(e.end)}function ie(e){D.call(this,e);let t=this.stack[this.stack.length-1];t.url=this.sliceSerialize(e)}function V(e){D.call(this,e);let t=this.stack[this.stack.length-1];t.url=`mailto:`+this.sliceSerialize(e)}function ae(){return{type:`blockquote`,children:[],position:void 0}}function oe(){return{type:`code`,lang:null,meta:null,value:``,position:void 0}}function se(){return{type:`inlineCode`,value:``,position:void 0}}function ce(){return{type:`definition`,identifier:``,label:null,title:null,url:``,position:void 0}}function le(){return{type:`emphasis`,children:[],position:void 0}}function ue(){return{type:`heading`,depth:0,children:[],position:void 0}}function de(){return{type:`break`,position:void 0}}function fe(){return{type:`html`,value:``,position:void 0}}function pe(){return{type:`image`,title:null,url:``,alt:null,position:void 0}}function me(){return{type:`link`,title:null,url:``,children:[],position:void 0}}function he(e){return{type:`list`,ordered:e.type===`listOrdered`,start:null,spread:e._spread,children:[],position:void 0}}function ge(e){return{type:`listItem`,spread:e._spread,checked:null,children:[],position:void 0}}function _e(){return{type:`paragraph`,children:[],position:void 0}}function ve(){return{type:`strong`,children:[],position:void 0}}function ye(){return{type:`text`,value:``,position:void 0}}function be(){return{type:`thematicBreak`,position:void 0}}}function JY(e){return{line:e.line,column:e.column,offset:e.offset}}function YY(e,t){let n=-1;for(;++n<t.length;){let r=t[n];Array.isArray(r)?YY(e,r):XY(e,r)}}function XY(e,t){let n;for(n in t)if(GY.call(t,n))switch(n){case`canContainEols`:{let r=t[n];r&&e[n].push(...r);break}case`transforms`:{let r=t[n];r&&e[n].push(...r);break}case`afterExit`:case`beforeEnter`:{let r=t[n];r&&e[n].push(r);break}case`enter`:case`exit`:{let r=t[n];r&&Object.assign(e[n],r);break}}}function ZY(e,t){throw Error(e?"Cannot close `"+e.type+"` ("+mK({start:e.start,end:e.end})+"): a different token (`"+t.type+"`, "+mK({start:t.start,end:t.end})+`) is open`:"Cannot close document, a token (`"+t.type+"`, "+mK({start:t.start,end:t.end})+`) is still open`)}function QY(e){let t=this;t.parser=n;function n(n){return KY(n,{...t.data(`settings`),...e,extensions:t.data(`micromarkExtensions`)||[],mdastExtensions:t.data(`fromMarkdownExtensions`)||[]})}}function $Y(e,t){let n={type:`element`,tagName:`blockquote`,properties:{},children:e.wrap(e.all(t),!0)};return e.patch(t,n),e.applyData(t,n)}function eX(e,t){let n={type:`element`,tagName:`br`,properties:{},children:[]};return e.patch(t,n),[e.applyData(t,n),{type:`text`,value:`
|
|
64
|
+
`}]}function tX(e,t){let n=t.value?t.value+`
|
|
65
|
+
`:``,r={},i=t.lang?t.lang.split(/\s+/):[];i.length>0&&(r.className=[`language-`+i[0]]);let a={type:`element`,tagName:`code`,properties:r,children:[{type:`text`,value:n}]};return t.meta&&(a.data={meta:t.meta}),e.patch(t,a),a=e.applyData(t,a),a={type:`element`,tagName:`pre`,properties:{},children:[a]},e.patch(t,a),a}function nX(e,t){let n={type:`element`,tagName:`del`,properties:{},children:e.all(t)};return e.patch(t,n),e.applyData(t,n)}function rX(e,t){let n={type:`element`,tagName:`em`,properties:{},children:e.all(t)};return e.patch(t,n),e.applyData(t,n)}function iX(e,t){let n=typeof e.options.clobberPrefix==`string`?e.options.clobberPrefix:`user-content-`,r=String(t.identifier).toUpperCase(),i=wq(r.toLowerCase()),a=e.footnoteOrder.indexOf(r),o,s=e.footnoteCounts.get(r);s===void 0?(s=0,e.footnoteOrder.push(r),o=e.footnoteOrder.length):o=a+1,s+=1,e.footnoteCounts.set(r,s);let c={type:`element`,tagName:`a`,properties:{href:`#`+n+`fn-`+i,id:n+`fnref-`+i+(s>1?`-`+s:``),dataFootnoteRef:!0,ariaDescribedBy:[`footnote-label`]},children:[{type:`text`,value:String(o)}]};e.patch(t,c);let l={type:`element`,tagName:`sup`,properties:{},children:[c]};return e.patch(t,l),e.applyData(t,l)}function aX(e,t){let n={type:`element`,tagName:`h`+t.depth,properties:{},children:e.all(t)};return e.patch(t,n),e.applyData(t,n)}function oX(e,t){if(e.options.allowDangerousHtml){let n={type:`raw`,value:t.value};return e.patch(t,n),e.applyData(t,n)}}function sX(e,t){let n=t.referenceType,r=`]`;if(n===`collapsed`?r+=`[]`:n===`full`&&(r+=`[`+(t.label||t.identifier)+`]`),t.type===`imageReference`)return[{type:`text`,value:`![`+t.alt+r}];let i=e.all(t),a=i[0];a&&a.type===`text`?a.value=`[`+a.value:i.unshift({type:`text`,value:`[`});let o=i[i.length-1];return o&&o.type===`text`?o.value+=r:i.push({type:`text`,value:r}),i}function cX(e,t){let n=String(t.identifier).toUpperCase(),r=e.definitionById.get(n);if(!r)return sX(e,t);let i={src:wq(r.url||``),alt:t.alt};r.title!==null&&r.title!==void 0&&(i.title=r.title);let a={type:`element`,tagName:`img`,properties:i,children:[]};return e.patch(t,a),e.applyData(t,a)}function lX(e,t){let n={src:wq(t.url)};t.alt!==null&&t.alt!==void 0&&(n.alt=t.alt),t.title!==null&&t.title!==void 0&&(n.title=t.title);let r={type:`element`,tagName:`img`,properties:n,children:[]};return e.patch(t,r),e.applyData(t,r)}function uX(e,t){let n={type:`text`,value:t.value.replace(/\r?\n|\r/g,` `)};e.patch(t,n);let r={type:`element`,tagName:`code`,properties:{},children:[n]};return e.patch(t,r),e.applyData(t,r)}function dX(e,t){let n=String(t.identifier).toUpperCase(),r=e.definitionById.get(n);if(!r)return sX(e,t);let i={href:wq(r.url||``)};r.title!==null&&r.title!==void 0&&(i.title=r.title);let a={type:`element`,tagName:`a`,properties:i,children:e.all(t)};return e.patch(t,a),e.applyData(t,a)}function fX(e,t){let n={href:wq(t.url)};t.title!==null&&t.title!==void 0&&(n.title=t.title);let r={type:`element`,tagName:`a`,properties:n,children:e.all(t)};return e.patch(t,r),e.applyData(t,r)}function pX(e,t,n){let r=e.all(t),i=n?mX(n):hX(t),a={},o=[];if(typeof t.checked==`boolean`){let e=r[0],n;e&&e.type===`element`&&e.tagName===`p`?n=e:(n={type:`element`,tagName:`p`,properties:{},children:[]},r.unshift(n)),n.children.length>0&&n.children.unshift({type:`text`,value:` `}),n.children.unshift({type:`element`,tagName:`input`,properties:{type:`checkbox`,checked:t.checked,disabled:!0},children:[]}),a.className=[`task-list-item`]}let s=-1;for(;++s<r.length;){let e=r[s];(i||s!==0||e.type!==`element`||e.tagName!==`p`)&&o.push({type:`text`,value:`
|
|
66
|
+
`}),e.type===`element`&&e.tagName===`p`&&!i?o.push(...e.children):o.push(e)}let c=r[r.length-1];c&&(i||c.type!==`element`||c.tagName!==`p`)&&o.push({type:`text`,value:`
|
|
67
|
+
`});let l={type:`element`,tagName:`li`,properties:a,children:o};return e.patch(t,l),e.applyData(t,l)}function mX(e){let t=!1;if(e.type===`list`){t=e.spread||!1;let n=e.children,r=-1;for(;!t&&++r<n.length;)t=hX(n[r])}return t}function hX(e){return e.spread??e.children.length>1}function gX(e,t){let n={},r=e.all(t),i=-1;for(typeof t.start==`number`&&t.start!==1&&(n.start=t.start);++i<r.length;){let e=r[i];if(e.type===`element`&&e.tagName===`li`&&e.properties&&Array.isArray(e.properties.className)&&e.properties.className.includes(`task-list-item`)){n.className=[`contains-task-list`];break}}let a={type:`element`,tagName:t.ordered?`ol`:`ul`,properties:n,children:e.wrap(r,!0)};return e.patch(t,a),e.applyData(t,a)}function _X(e,t){let n={type:`element`,tagName:`p`,properties:{},children:e.all(t)};return e.patch(t,n),e.applyData(t,n)}function vX(e,t){let n={type:`root`,children:e.wrap(e.all(t))};return e.patch(t,n),e.applyData(t,n)}function yX(e,t){let n={type:`element`,tagName:`strong`,properties:{},children:e.all(t)};return e.patch(t,n),e.applyData(t,n)}function bX(e,t){let n=e.all(t),r=n.shift(),i=[];if(r){let n={type:`element`,tagName:`thead`,properties:{},children:e.wrap([r],!0)};e.patch(t.children[0],n),i.push(n)}if(n.length>0){let r={type:`element`,tagName:`tbody`,properties:{},children:e.wrap(n,!0)},a=dK(t.children[1]),o=uK(t.children[t.children.length-1]);a&&o&&(r.position={start:a,end:o}),i.push(r)}let a={type:`element`,tagName:`table`,properties:{},children:e.wrap(i,!0)};return e.patch(t,a),e.applyData(t,a)}function xX(e,t,n){let r=n?n.children:void 0,i=(r?r.indexOf(t):1)===0?`th`:`td`,a=n&&n.type===`table`?n.align:void 0,o=a?a.length:t.children.length,s=-1,c=[];for(;++s<o;){let n=t.children[s],r={},o=a?a[s]:void 0;o&&(r.align=o);let l={type:`element`,tagName:i,properties:r,children:[]};n&&(l.children=e.all(n),e.patch(n,l),l=e.applyData(n,l)),c.push(l)}let l={type:`element`,tagName:`tr`,properties:{},children:e.wrap(c,!0)};return e.patch(t,l),e.applyData(t,l)}function SX(e,t){let n={type:`element`,tagName:`td`,properties:{},children:e.all(t)};return e.patch(t,n),e.applyData(t,n)}var CX=9,wX=32;function TX(e){let t=String(e),n=/\r?\n|\r/g,r=n.exec(t),i=0,a=[];for(;r;)a.push(EX(t.slice(i,r.index),i>0,!0),r[0]),i=r.index+r[0].length,r=n.exec(t);return a.push(EX(t.slice(i),i>0,!1)),a.join(``)}function EX(e,t,n){let r=0,i=e.length;if(t){let t=e.codePointAt(r);for(;t===CX||t===wX;)r++,t=e.codePointAt(r)}if(n){let t=e.codePointAt(i-1);for(;t===CX||t===wX;)i--,t=e.codePointAt(i-1)}return i>r?e.slice(r,i):``}function DX(e,t){let n={type:`text`,value:TX(String(t.value))};return e.patch(t,n),e.applyData(t,n)}function OX(e,t){let n={type:`element`,tagName:`hr`,properties:{},children:[]};return e.patch(t,n),e.applyData(t,n)}var kX={blockquote:$Y,break:eX,code:tX,delete:nX,emphasis:rX,footnoteReference:iX,heading:aX,html:oX,imageReference:cX,image:lX,inlineCode:uX,linkReference:dX,link:fX,listItem:pX,list:gX,paragraph:_X,root:vX,strong:yX,table:bX,tableCell:SX,tableRow:xX,text:DX,thematicBreak:OX,toml:AX,yaml:AX,definition:AX,footnoteDefinition:AX};function AX(){}var{defineProperty:jX}=Object,MX=typeof self==`object`?self:globalThis,NX=(e,t)=>{switch(e){case`Function`:case`SharedWorker`:case`Worker`:case`eval`:case`setInterval`:case`setTimeout`:throw TypeError(`unable to deserialize `+e)}return new MX[e](t)},PX=(e,t)=>{let n=(t,n)=>(e.set(n,t),t),r=i=>{if(e.has(i))return e.get(i);let[a,o]=t[i];switch(a){case 0:case-1:return n(o,i);case 1:{let e=n([],i);for(let t of o)e.push(r(t));return e}case 2:{let e=n({},i);for(let[t,n]of o){let i=r(t),a=r(n);i===`__proto__`?jX(e,i,{value:a,configurable:!0,enumerable:!0,writable:!0}):e[i]=a}return e}case 3:return n(new Date(o),i);case 4:{let{source:e,flags:t}=o;return n(new RegExp(e,t),i)}case 5:{let e=n(new Map,i);for(let[t,n]of o)e.set(r(t),r(n));return e}case 6:{let e=n(new Set,i);for(let t of o)e.add(r(t));return e}case 7:{let{name:e,message:t}=o;return n(typeof MX[e]==`function`?NX(e,t):Error(t),i)}case 8:return n(BigInt(o),i);case`BigInt`:return n(Object(BigInt(o)),i);case`ArrayBuffer`:return n(new Uint8Array(o).buffer,o);case`DataView`:{let{buffer:e}=new Uint8Array(o);return n(new DataView(e),o)}case`-0`:return-0}return n(NX(a,o),i)};return r},FX=e=>PX(new Map,e)(0),IX=``,{toString:LX}={},{keys:RX,is:zX}=Object,BX=e=>{let t=typeof e;if(t!==`object`||!e)return[0,t];let n=LX.call(e).slice(8,-1);switch(n){case`Array`:return[1,IX];case`Object`:return[2,IX];case`Date`:return[3,IX];case`RegExp`:return[4,IX];case`Map`:return[5,IX];case`Set`:return[6,IX];case`DataView`:return[1,n]}return n.includes(`Array`)?[1,n]:e instanceof Error?[7,e.name||`Error`]:[2,n]},VX=([e,t])=>e===0&&(t===`function`||t===`symbol`),HX=(e,t,n,r)=>{let i=(e,t)=>{let i=r.push(e)-1;return n.set(t,i),i},a=o=>{if(n.has(o))return n.get(o);let[s,c]=BX(o);switch(s){case 0:{let t=o;switch(c){case`bigint`:s=8,t=o.toString();break;case`number`:if(!o&&zX(o,-0))return r.push([`-0`])-1;break;case`function`:case`symbol`:if(e)throw TypeError(`unable to serialize `+c);t=null;break;case`undefined`:return i([-1],o)}return i([s,t],o)}case 1:{if(c){let e=o;return c===`DataView`?e=new Uint8Array(o.buffer):c===`ArrayBuffer`&&(e=new Uint8Array(o)),i([c,[...e]],o)}let e=[],t=i([s,e],o);for(let t of o)e.push(a(t));return t}case 2:{if(c)switch(c){case`BigInt`:return i([c,o.toString()],o);case`Boolean`:case`Number`:case`String`:return i([c,o.valueOf()],o)}if(t&&`toJSON`in o)return a(o.toJSON());let n=[],r=i([s,n],o);for(let t of RX(o))(e||!VX(BX(o[t])))&&n.push([a(t),a(o[t])]);return r}case 3:return i([s,isNaN(o.getTime())?IX:o.toISOString()],o);case 4:{let{source:e,flags:t}=o;return i([s,{source:e,flags:t}],o)}case 5:{let t=[],n=i([s,t],o);for(let[n,r]of o)(e||!(VX(BX(n))||VX(BX(r))))&&t.push([a(n),a(r)]);return n}case 6:{let t=[],n=i([s,t],o);for(let n of o)(e||!VX(BX(n)))&&t.push(a(n));return n}}let{message:l}=o;return i([s,{name:c,message:l}],o)};return a},UX=(e,{json:t,lossy:n}={})=>{let r=[];return HX(!(t||n),!!t,new Map,r)(e),r},WX=typeof structuredClone==`function`?(e,t)=>t&&(`json`in t||`lossy`in t)?FX(UX(e,t)):structuredClone(e):(e,t)=>FX(UX(e,t));function GX(e,t){let n=[{type:`text`,value:`↩`}];return t>1&&n.push({type:`element`,tagName:`sup`,properties:{},children:[{type:`text`,value:String(t)}]}),n}function KX(e,t){return`Back to reference `+(e+1)+(t>1?`-`+t:``)}function qX(e){let t=typeof e.options.clobberPrefix==`string`?e.options.clobberPrefix:`user-content-`,n=e.options.footnoteBackContent||GX,r=e.options.footnoteBackLabel||KX,i=e.options.footnoteLabel||`Footnotes`,a=e.options.footnoteLabelTagName||`h2`,o=e.options.footnoteLabelProperties||{className:[`sr-only`]},s=[],c=-1;for(;++c<e.footnoteOrder.length;){let i=e.footnoteById.get(e.footnoteOrder[c]);if(!i)continue;let a=e.all(i),o=String(i.identifier).toUpperCase(),l=wq(o.toLowerCase()),u=0,d=[],f=e.footnoteCounts.get(o);for(;f!==void 0&&++u<=f;){d.length>0&&d.push({type:`text`,value:` `});let e=typeof n==`string`?n:n(c,u);typeof e==`string`&&(e={type:`text`,value:e}),d.push({type:`element`,tagName:`a`,properties:{href:`#`+t+`fnref-`+l+(u>1?`-`+u:``),dataFootnoteBackref:``,ariaLabel:typeof r==`string`?r:r(c,u),className:[`data-footnote-backref`]},children:Array.isArray(e)?e:[e]})}let p=a[a.length-1];if(p&&p.type===`element`&&p.tagName===`p`){let e=p.children[p.children.length-1];e&&e.type===`text`?e.value+=` `:p.children.push({type:`text`,value:` `}),p.children.push(...d)}else a.push(...d);let m={type:`element`,tagName:`li`,properties:{id:t+`fn-`+l},children:e.wrap(a,!0)};e.patch(i,m),s.push(m)}if(s.length!==0)return{type:`element`,tagName:`section`,properties:{dataFootnotes:!0,className:[`footnotes`]},children:[{type:`element`,tagName:a,properties:{...WX(o),id:`footnote-label`},children:[{type:`text`,value:i}]},{type:`text`,value:`
|
|
68
|
+
`},{type:`element`,tagName:`ol`,properties:{},children:e.wrap(s,!0)},{type:`text`,value:`
|
|
69
|
+
`}]}}var JX=(function(e){if(e==null)return $X;if(typeof e==`function`)return QX(e);if(typeof e==`object`)return Array.isArray(e)?YX(e):XX(e);if(typeof e==`string`)return ZX(e);throw Error(`Expected function, string, or object as test`)});function YX(e){let t=[],n=-1;for(;++n<e.length;)t[n]=JX(e[n]);return QX(r);function r(...e){let n=-1;for(;++n<t.length;)if(t[n].apply(this,e))return!0;return!1}}function XX(e){let t=e;return QX(n);function n(n){let r=n,i;for(i in e)if(r[i]!==t[i])return!1;return!0}}function ZX(e){return QX(t);function t(t){return t&&t.type===e}}function QX(e){return t;function t(t,n,r){return!!(eZ(t)&&e.call(this,t,typeof n==`number`?n:void 0,r||void 0))}}function $X(){return!0}function eZ(e){return typeof e==`object`&&!!e&&`type`in e}function tZ(e){return e}var nZ=[],rZ=`skip`;function iZ(e,t,n,r){if(!e||typeof e!=`object`)throw Error("Unexpected value `"+e+"` for `tree`, expected node");let i=!0,a,o,s,c;if(typeof n==`function`||n&&typeof n==`object`?(a=t,o=n,r&&(i=!1)):(o=t,n&&(i=!1)),typeof o==`function`)s=o;else if(o&&typeof o==`object`){if(o.enter!==null&&o.enter!==void 0){if(typeof o.enter==`function`)s=o.enter;else throw Error("Unexpected value `"+o.enter+"` for `visitors.enter`, expected optional visitor")}if(typeof o.exit==`function`)c=o.exit;else throw Error("Unexpected value `"+o.exit+"` for `visitors.exit`, expected visitor (pass a visitor directly if you only want an enter visitor)")}else throw Error("Unexpected value `"+o+"` for `enter` or `visitors`, expected visitor or object with visitors");let l=JX(a),u=i?1:-1;d(e,void 0,[])();function d(e,t,n){let r=e&&typeof e==`object`?e:{};if(typeof r.type==`string`){let t=typeof r.tagName==`string`?r.tagName:typeof r.name==`string`?r.name:void 0;Object.defineProperty(o,"name",{value:`node (`+tZ(e.type+(t?`<`+t+`>`:``))+`)`})}return o;function o(){let r=!a||l(e,t,n[n.length-1]||void 0),o=nZ;if(s&&r&&(o=aZ(s(e,n,t)),o[0]===!1))return o;if(`children`in e&&e.children){let t=e;if(t.children&&o[0]!==`skip`){let e=(i?-1:t.children.length)+u,r=[...n,t];for(;e>-1&&e<t.children.length;){let n=t.children[e],i=d(n,e,r)();if(i[0]===!1)return i;e=typeof i[1]==`number`?i[1]:e+u}}}if(c&&r){let r=aZ(c(e,n,t));if(r[0]===`skip`)throw Error("Unexpected value `"+r[0]+"` from `exit`, expected `CONTINUE`, `EXIT`, index, or nothing");if(r[0]===!1||typeof r[1]==`number`)return r}return o}}}function aZ(e){return Array.isArray(e)?e:typeof e==`number`?[!0,e]:e==null?nZ:[e]}function oZ(e,t,n,r){let i,a,o;typeof n==`function`||n&&typeof n==`object`?(i=t,a=n,o=r):(a=t,o=n),typeof a==`function`?iZ(e,i,cZ(a),o):iZ(e,i,sZ(a),o)}function sZ(e){return!e||typeof e!=`object`?e:{enter:typeof e.enter==`function`?cZ(e.enter):e.enter,exit:typeof e.exit==`function`?cZ(e.exit):e.exit}}function cZ(e){return t;function t(t,n,r){return e(t,r,n[n.length-1])}}var lZ={}.hasOwnProperty,uZ={};function dZ(e,t){let n=t||uZ,r=new Map,i=new Map,a={all:s,applyData:pZ,definitionById:r,footnoteById:i,footnoteCounts:new Map,footnoteOrder:[],handlers:{...kX,...n.handlers},one:o,options:n,patch:fZ,wrap:hZ};return oZ(e,function(e){if(e.type===`definition`||e.type===`footnoteDefinition`){let t=e.type===`definition`?r:i,n=String(e.identifier).toUpperCase();t.has(n)||t.set(n,e)}}),a;function o(e,t){let n=e.type,r=a.handlers[n];if(lZ.call(a.handlers,n)&&r)return r(a,e,t);if(a.options.passThrough&&a.options.passThrough.includes(n)){if(`children`in e){let{children:t,...n}=e,r=WX(n);return r.children=a.all(e),r}return WX(e)}return(a.options.unknownHandler||mZ)(a,e,t)}function s(e){let t=[];if(`children`in e){let n=e.children,r=-1;for(;++r<n.length;){let i=a.one(n[r],e);if(i){if(r&&n[r-1].type===`break`&&(!Array.isArray(i)&&i.type===`text`&&(i.value=gZ(i.value)),!Array.isArray(i)&&i.type===`element`)){let e=i.children[0];e&&e.type===`text`&&(e.value=gZ(e.value))}Array.isArray(i)?t.push(...i):t.push(i)}}}return t}}function fZ(e,t){e.position&&(t.position=pK(e))}function pZ(e,t){let n=t;if(e&&e.data){let t=e.data.hName,r=e.data.hChildren,i=e.data.hProperties;typeof t==`string`&&(n.type===`element`?n.tagName=t:n={type:`element`,tagName:t,properties:{},children:`children`in n?n.children:[n]}),n.type===`element`&&i&&Object.assign(n.properties,WX(i)),`children`in n&&n.children&&r!=null&&(n.children=r)}return n}function mZ(e,t){let n=t.data||{},r=`value`in t&&!(lZ.call(n,`hProperties`)||lZ.call(n,`hChildren`))?{type:`text`,value:t.value}:{type:`element`,tagName:`div`,properties:{},children:e.all(t)};return e.patch(t,r),e.applyData(t,r)}function hZ(e,t){let n=[],r=-1;for(t&&n.push({type:`text`,value:`
|
|
70
|
+
`});++r<e.length;)r&&n.push({type:`text`,value:`
|
|
71
|
+
`}),n.push(e[r]);return t&&e.length>0&&n.push({type:`text`,value:`
|
|
72
|
+
`}),n}function gZ(e){let t=0,n=e.charCodeAt(t);for(;n===9||n===32;)t++,n=e.charCodeAt(t);return e.slice(t)}function _Z(e,t){let n=dZ(e,t),r=n.one(e,void 0),i=qX(n),a=Array.isArray(r)?{type:`root`,children:r}:r||{type:`root`,children:[]};return i&&(`children`in a,a.children.push({type:`text`,value:`
|
|
73
|
+
`},i)),a}function vZ(e,t){return e&&`run`in e?async function(n,r){let i=_Z(n,{file:r,...t});await e.run(i,r)}:function(n,r){return _Z(n,{file:r,...e||t})}}function yZ(e){if(e)throw e}var bZ=o(((e,t)=>{var n=Object.prototype.hasOwnProperty,r=Object.prototype.toString,i=Object.defineProperty,a=Object.getOwnPropertyDescriptor,o=function(e){return typeof Array.isArray==`function`?Array.isArray(e):r.call(e)===`[object Array]`},s=function(e){if(!e||r.call(e)!==`[object Object]`)return!1;var t=n.call(e,`constructor`),i=e.constructor&&e.constructor.prototype&&n.call(e.constructor.prototype,`isPrototypeOf`);if(e.constructor&&!t&&!i)return!1;for(var a in e);return a===void 0||n.call(e,a)},c=function(e,t){i&&t.name===`__proto__`?i(e,t.name,{enumerable:!0,configurable:!0,value:t.newValue,writable:!0}):e[t.name]=t.newValue},l=function(e,t){if(t===`__proto__`){if(!n.call(e,t))return;if(a)return a(e,t).value}return e[t]};t.exports=function e(){var t,n,r,i,a,u,d=arguments[0],f=1,p=arguments.length,m=!1;for(typeof d==`boolean`&&(m=d,d=arguments[1]||{},f=2),(d==null||typeof d!=`object`&&typeof d!=`function`)&&(d={});f<p;++f)if(t=arguments[f],t!=null)for(n in t)r=l(d,n),i=l(t,n),d!==i&&(m&&i&&(s(i)||(a=o(i)))?(a?(a=!1,u=r&&o(r)?r:[]):u=r&&s(r)?r:{},c(d,{name:n,newValue:e(m,u,i)})):i!==void 0&&c(d,{name:n,newValue:i}));return d}}));function xZ(e){if(typeof e!=`object`||!e)return!1;let t=Object.getPrototypeOf(e);return(t===null||t===Object.prototype||Object.getPrototypeOf(t)===null)&&!(Symbol.toStringTag in e)&&!(Symbol.iterator in e)}function SZ(){let e=[],t={run:n,use:r};return t;function n(...t){let n=-1,r=t.pop();if(typeof r!=`function`)throw TypeError(`Expected function as last argument, not `+r);i(null,...t);function i(a,...o){let s=e[++n],c=-1;if(a)r(a);else{for(;++c<t.length;)(o[c]===null||o[c]===void 0)&&(o[c]=t[c]);t=o,s?CZ(s,i)(...o):r(null,...o)}}}function r(n){if(typeof n!=`function`)throw TypeError("Expected `middelware` to be a function, not "+n);return e.push(n),t}}function CZ(e,t){let n;return r;function r(...t){let r=e.length>t.length,o;r&&t.push(i);try{o=e.apply(this,t)}catch(e){let t=e;if(r&&n)throw t;return i(t)}r||(o&&o.then&&typeof o.then==`function`?o.then(a,i):o instanceof Error?i(o):a(o))}function i(e,...r){n||(n=!0,t(e,...r))}function a(e){i(null,e)}}var wZ={basename:TZ,dirname:EZ,extname:DZ,join:OZ,sep:`/`};function TZ(e,t){if(t!==void 0&&typeof t!=`string`)throw TypeError(`"ext" argument must be a string`);jZ(e);let n=0,r=-1,i=e.length,a;if(t===void 0||t.length===0||t.length>e.length){for(;i--;)if(e.codePointAt(i)===47){if(a){n=i+1;break}}else r<0&&(a=!0,r=i+1);return r<0?``:e.slice(n,r)}if(t===e)return``;let o=-1,s=t.length-1;for(;i--;)if(e.codePointAt(i)===47){if(a){n=i+1;break}}else o<0&&(a=!0,o=i+1),s>-1&&(e.codePointAt(i)===t.codePointAt(s--)?s<0&&(r=i):(s=-1,r=o));return n===r?r=o:r<0&&(r=e.length),e.slice(n,r)}function EZ(e){if(jZ(e),e.length===0)return`.`;let t=-1,n=e.length,r;for(;--n;)if(e.codePointAt(n)===47){if(r){t=n;break}}else r||=!0;return t<0?e.codePointAt(0)===47?`/`:`.`:t===1&&e.codePointAt(0)===47?`//`:e.slice(0,t)}function DZ(e){jZ(e);let t=e.length,n=-1,r=0,i=-1,a=0,o;for(;t--;){let s=e.codePointAt(t);if(s===47){if(o){r=t+1;break}}else n<0&&(o=!0,n=t+1),s===46?i<0?i=t:a!==1&&(a=1):i>-1&&(a=-1)}return i<0||n<0||a===0||a===1&&i===n-1&&i===r+1?``:e.slice(i,n)}function OZ(...e){let t=-1,n;for(;++t<e.length;)jZ(e[t]),e[t]&&(n=n===void 0?e[t]:n+`/`+e[t]);return n===void 0?`.`:kZ(n)}function kZ(e){jZ(e);let t=e.codePointAt(0)===47,n=AZ(e,!t);return n.length===0&&!t&&(n=`.`),n.length>0&&e.codePointAt(e.length-1)===47&&(n+=`/`),t?`/`+n:n}function AZ(e,t){let n=``,r=0,i=-1,a=0,o=-1,s,c;for(;++o<=e.length;){if(o<e.length)s=e.codePointAt(o);else if(s===47)break;else s=47;if(s===47){if(i!==o-1&&a!==1){if(i!==o-1&&a===2){if(n.length<2||r!==2||n.codePointAt(n.length-1)!==46||n.codePointAt(n.length-2)!==46){if(n.length>2){if(c=n.lastIndexOf(`/`),c!==n.length-1){c<0?(n=``,r=0):(n=n.slice(0,c),r=n.length-1-n.lastIndexOf(`/`)),i=o,a=0;continue}}else if(n.length>0){n=``,r=0,i=o,a=0;continue}}t&&(n=n.length>0?n+`/..`:`..`,r=2)}else n.length>0?n+=`/`+e.slice(i+1,o):n=e.slice(i+1,o),r=o-i-1}i=o,a=0}else s===46&&a>-1?a++:a=-1}return n}function jZ(e){if(typeof e!=`string`)throw TypeError(`Path must be a string. Received `+JSON.stringify(e))}var MZ={cwd:NZ};function NZ(){return`/`}function PZ(e){return!!(typeof e==`object`&&e&&`href`in e&&e.href&&`protocol`in e&&e.protocol&&e.auth===void 0)}function FZ(e){if(typeof e==`string`)e=new URL(e);else if(!PZ(e)){let t=TypeError('The "path" argument must be of type string or an instance of URL. Received `'+e+"`");throw t.code=`ERR_INVALID_ARG_TYPE`,t}if(e.protocol!==`file:`){let e=TypeError(`The URL must be of scheme file`);throw e.code=`ERR_INVALID_URL_SCHEME`,e}return IZ(e)}function IZ(e){if(e.hostname!==``){let e=TypeError(`File URL host must be "localhost" or empty on darwin`);throw e.code=`ERR_INVALID_FILE_URL_HOST`,e}let t=e.pathname,n=-1;for(;++n<t.length;)if(t.codePointAt(n)===37&&t.codePointAt(n+1)===50){let e=t.codePointAt(n+2);if(e===70||e===102){let e=TypeError(`File URL path must not include encoded / characters`);throw e.code=`ERR_INVALID_FILE_URL_PATH`,e}}return decodeURIComponent(t)}var LZ=[`history`,`path`,`basename`,`stem`,`extname`,`dirname`],RZ=class{constructor(e){let t;t=e?PZ(e)?{path:e}:typeof e==`string`||HZ(e)?{value:e}:e:{},this.cwd=`cwd`in t?``:MZ.cwd(),this.data={},this.history=[],this.messages=[],this.value,this.map,this.result,this.stored;let n=-1;for(;++n<LZ.length;){let e=LZ[n];e in t&&t[e]!==void 0&&t[e]!==null&&(this[e]=e===`history`?[...t[e]]:t[e])}let r;for(r in t)LZ.includes(r)||(this[r]=t[r])}get basename(){return typeof this.path==`string`?wZ.basename(this.path):void 0}set basename(e){BZ(e,`basename`),zZ(e,`basename`),this.path=wZ.join(this.dirname||``,e)}get dirname(){return typeof this.path==`string`?wZ.dirname(this.path):void 0}set dirname(e){VZ(this.basename,`dirname`),this.path=wZ.join(e||``,this.basename)}get extname(){return typeof this.path==`string`?wZ.extname(this.path):void 0}set extname(e){if(zZ(e,`extname`),VZ(this.dirname,`extname`),e){if(e.codePointAt(0)!==46)throw Error("`extname` must start with `.`");if(e.includes(`.`,1))throw Error("`extname` cannot contain multiple dots")}this.path=wZ.join(this.dirname,this.stem+(e||``))}get path(){return this.history[this.history.length-1]}set path(e){PZ(e)&&(e=FZ(e)),BZ(e,`path`),this.path!==e&&this.history.push(e)}get stem(){return typeof this.path==`string`?wZ.basename(this.path,this.extname):void 0}set stem(e){BZ(e,`stem`),zZ(e,`stem`),this.path=wZ.join(this.dirname||``,e+(this.extname||``))}fail(e,t,n){let r=this.message(e,t,n);throw r.fatal=!0,r}info(e,t,n){let r=this.message(e,t,n);return r.fatal=void 0,r}message(e,t,n){let r=new vK(e,t,n);return this.path&&(r.name=this.path+`:`+r.name,r.file=this.path),r.fatal=!1,this.messages.push(r),r}toString(e){return this.value===void 0?``:typeof this.value==`string`?this.value:new TextDecoder(e||void 0).decode(this.value)}};function zZ(e,t){if(e&&e.includes(wZ.sep))throw Error("`"+t+"` cannot be a path: did not expect `"+wZ.sep+"`")}function BZ(e,t){if(!e)throw Error("`"+t+"` cannot be empty")}function VZ(e,t){if(!e)throw Error("Setting `"+t+"` requires `path` to be set too")}function HZ(e){return!!(e&&typeof e==`object`&&`byteLength`in e&&`byteOffset`in e)}var UZ=(function(e){let t=this.constructor.prototype,n=t[e],r=function(){return n.apply(r,arguments)};return Object.setPrototypeOf(r,t),r}),WZ=u(bZ(),1),GZ={}.hasOwnProperty,KZ=new class e extends UZ{constructor(){super(`copy`),this.Compiler=void 0,this.Parser=void 0,this.attachers=[],this.compiler=void 0,this.freezeIndex=-1,this.frozen=void 0,this.namespace={},this.parser=void 0,this.transformers=SZ()}copy(){let t=new e,n=-1;for(;++n<this.attachers.length;){let e=this.attachers[n];t.use(...e)}return t.data((0,WZ.default)(!0,{},this.namespace)),t}data(e,t){return typeof e==`string`?arguments.length===2?(YZ(`data`,this.frozen),this.namespace[e]=t,this):GZ.call(this.namespace,e)&&this.namespace[e]||void 0:e?(YZ(`data`,this.frozen),this.namespace=e,this):this.namespace}freeze(){if(this.frozen)return this;let e=this;for(;++this.freezeIndex<this.attachers.length;){let[t,...n]=this.attachers[this.freezeIndex];if(n[0]===!1)continue;n[0]===!0&&(n[0]=void 0);let r=t.call(e,...n);typeof r==`function`&&this.transformers.use(r)}return this.frozen=!0,this.freezeIndex=1/0,this}parse(e){this.freeze();let t=QZ(e),n=this.parser||this.Parser;return qZ(`parse`,n),n(String(t),t)}process(e,t){let n=this;return this.freeze(),qZ(`process`,this.parser||this.Parser),JZ(`process`,this.compiler||this.Compiler),t?r(void 0,t):new Promise(r);function r(r,i){let a=QZ(e),o=n.parse(a);n.run(o,a,function(e,t,r){if(e||!t||!r)return s(e);let i=t,a=n.stringify(i,r);eQ(a)?r.value=a:r.result=a,s(e,r)});function s(e,n){e||!n?i(e):r?r(n):t(void 0,n)}}}processSync(e){let t=!1,n;return this.freeze(),qZ(`processSync`,this.parser||this.Parser),JZ(`processSync`,this.compiler||this.Compiler),this.process(e,r),ZZ(`processSync`,`process`,t),n;function r(e,r){t=!0,yZ(e),n=r}}run(e,t,n){XZ(e),this.freeze();let r=this.transformers;return!n&&typeof t==`function`&&(n=t,t=void 0),n?i(void 0,n):new Promise(i);function i(i,a){let o=QZ(t);r.run(e,o,s);function s(t,r,o){let s=r||e;t?a(t):i?i(s):n(void 0,s,o)}}}runSync(e,t){let n=!1,r;return this.run(e,t,i),ZZ(`runSync`,`run`,n),r;function i(e,t){yZ(e),r=t,n=!0}}stringify(e,t){this.freeze();let n=QZ(t),r=this.compiler||this.Compiler;return JZ(`stringify`,r),XZ(e),r(e,n)}use(e,...t){let n=this.attachers,r=this.namespace;if(YZ(`use`,this.frozen),e!=null){if(typeof e==`function`)s(e,t);else if(typeof e==`object`)Array.isArray(e)?o(e):a(e);else throw TypeError("Expected usable value, not `"+e+"`")}return this;function i(e){if(typeof e==`function`)s(e,[]);else if(typeof e==`object`){if(Array.isArray(e)){let[t,...n]=e;s(t,n)}else a(e)}else throw TypeError("Expected usable value, not `"+e+"`")}function a(e){if(!(`plugins`in e)&&!(`settings`in e))throw Error("Expected usable value but received an empty preset, which is probably a mistake: presets typically come with `plugins` and sometimes with `settings`, but this has neither");o(e.plugins),e.settings&&(r.settings=(0,WZ.default)(!0,r.settings,e.settings))}function o(e){let t=-1;if(e!=null){if(Array.isArray(e))for(;++t<e.length;){let n=e[t];i(n)}else throw TypeError("Expected a list of plugins, not `"+e+"`")}}function s(e,t){let r=-1,i=-1;for(;++r<n.length;)if(n[r][0]===e){i=r;break}if(i===-1)n.push([e,...t]);else if(t.length>0){let[r,...a]=t,o=n[i][1];xZ(o)&&xZ(r)&&(r=(0,WZ.default)(!0,o,r)),n[i]=[e,r,...a]}}}}().freeze();function qZ(e,t){if(typeof t!=`function`)throw TypeError("Cannot `"+e+"` without `parser`")}function JZ(e,t){if(typeof t!=`function`)throw TypeError("Cannot `"+e+"` without `compiler`")}function YZ(e,t){if(t)throw Error("Cannot call `"+e+"` on a frozen processor.\nCreate a new processor first, by calling it: use `processor()` instead of `processor`.")}function XZ(e){if(!xZ(e)||typeof e.type!=`string`)throw TypeError("Expected node, got `"+e+"`")}function ZZ(e,t,n){if(!n)throw Error("`"+e+"` finished async. Use `"+t+"` instead")}function QZ(e){return $Z(e)?e:new RZ(e)}function $Z(e){return!!(e&&typeof e==`object`&&`message`in e&&`messages`in e)}function eQ(e){return typeof e==`string`||tQ(e)}function tQ(e){return!!(e&&typeof e==`object`&&`byteLength`in e&&`byteOffset`in e)}var nQ=[],rQ={allowDangerousHtml:!0},iQ=/^(https?|ircs?|mailto|xmpp)$/i,aQ=[{from:`astPlugins`,id:`remove-buggy-html-in-markdown-parser`},{from:`allowDangerousHtml`,id:`remove-buggy-html-in-markdown-parser`},{from:`allowNode`,id:`replace-allownode-allowedtypes-and-disallowedtypes`,to:`allowElement`},{from:`allowedTypes`,id:`replace-allownode-allowedtypes-and-disallowedtypes`,to:`allowedElements`},{from:`className`,id:`remove-classname`},{from:`disallowedTypes`,id:`replace-allownode-allowedtypes-and-disallowedtypes`,to:`disallowedElements`},{from:`escapeHtml`,id:`remove-buggy-html-in-markdown-parser`},{from:`includeElementIndex`,id:`#remove-includeelementindex`},{from:`includeNodeIndex`,id:`change-includenodeindex-to-includeelementindex`},{from:`linkTarget`,id:`remove-linktarget`},{from:`plugins`,id:`change-plugins-to-remarkplugins`,to:`remarkPlugins`},{from:`rawSourcePos`,id:`#remove-rawsourcepos`},{from:`renderers`,id:`change-renderers-to-components`,to:`components`},{from:`source`,id:`change-source-to-children`,to:`children`},{from:`sourcePos`,id:`#remove-sourcepos`},{from:`transformImageUri`,id:`#add-urltransform`,to:`urlTransform`},{from:`transformLinkUri`,id:`#add-urltransform`,to:`urlTransform`}];function oQ(e){let t=sQ(e),n=cQ(e);return lQ(t.runSync(t.parse(n),n),e)}function sQ(e){let t=e.rehypePlugins||nQ,n=e.remarkPlugins||nQ,r=e.remarkRehypeOptions?{...e.remarkRehypeOptions,...rQ}:rQ;return KZ().use(QY).use(n).use(vZ,r).use(t)}function cQ(e){let t=e.children||``,n=new RZ;return typeof t==`string`?n.value=t:``+t,n}function lQ(e,t){let n=t.allowedElements,r=t.allowElement,i=t.components,a=t.disallowedElements,o=t.skipHtml,s=t.unwrapDisallowed,c=t.urlTransform||uQ;for(let e of aQ)Object.hasOwn(t,e.from)&&``+e.from+(e.to?"use `"+e.to+"` instead":`remove it`)+e.id;return oZ(e,l),EK(e,{Fragment:J.Fragment,components:i,ignoreInvalidStyle:!0,jsx:J.jsx,jsxs:J.jsxs,passKeys:!0,passNode:!0});function l(e,t,i){if(e.type===`raw`&&i&&typeof t==`number`)return o?i.children.splice(t,1):i.children[t]={type:`text`,value:e.value},t;if(e.type===`element`){let t;for(t in YK)if(Object.hasOwn(YK,t)&&Object.hasOwn(e.properties,t)){let n=e.properties[t],r=YK[t];(r===null||r.includes(e.tagName))&&(e.properties[t]=c(String(n||``),t,e))}}if(e.type===`element`){let o=n?!n.includes(e.tagName):a?a.includes(e.tagName):!1;if(!o&&r&&typeof t==`number`&&(o=!r(e,t,i)),o&&i&&typeof t==`number`)return s&&e.children?i.children.splice(t,1,...e.children):i.children.splice(t,1),t}}}function uQ(e){let t=e.indexOf(`:`),n=e.indexOf(`?`),r=e.indexOf(`#`),i=e.indexOf(`/`);return t===-1||i!==-1&&t>i||n!==-1&&t>n||r!==-1&&t>r||iQ.test(e.slice(0,t))?e:``}var{useSmooth:dQ,useSmoothStatus:fQ,withSmoothContextProvider:pQ}=NM,mQ=(0,f.createContext)(null),hQ=e=>{let t=(0,f.useContext)(mQ);return(0,J.jsx)(aG,{...t,...e})},gQ=e=>{let{components:t}=(0,f.useContext)(mQ);return(0,J.jsx)(UW,{...e,fallbackPre:t.Pre})},_Q=(0,f.memo)(({text:e,...t})=>(0,J.jsx)(oQ,{...t,children:e}));_Q.displayName=`MarkdownRenderer`;var vQ=({text:e,...t})=>{let n=(0,f.useDeferredValue)(e);return(0,J.jsx)(_Q,{text:n,...t})},yQ=e=>typeof e==`object`&&!!e&&!Array.isArray(e),bQ=(e,t,n=1)=>{if(Object.is(e,t))return!0;if(n<=0)return!1;if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return!1;for(let r=0;r<e.length;r++)if(!bQ(e[r],t[r],n-1))return!1;return!0}if(yQ(e)&&yQ(t)){let r=Object.keys(e);return r.length===Object.keys(t).length&&r.every(r=>Object.hasOwn(t,r)&&bQ(e[r],t[r],n-1))}return!1};function xQ(e,t){let n=(0,f.useRef)(e);return bQ(e,n.current,t)||(n.current=e),n.current}function SQ(e){let t=(0,f.useRef)(e),n=(e,t)=>e[t],r=Object.keys(e),i=Object.keys(t.current);return r.length===i.length&&r.every(r=>Object.hasOwn(t.current,r)&&bQ(n(e,r),n(t.current,r)))||(t.current=e),t.current}var CQ=({components:e,componentsByLanguage:t,smooth:n=!0,defer:r=!1,preprocess:i,...a})=>{let{text:o}=dQ(fA(),n),s=(0,f.useMemo)(()=>i?i(o):o,[i,o]),{pre:c=WW,code:l=GW,SyntaxHighlighter:u=KW,CodeHeader:d=qW}=e??{},p=(0,f.useMemo)(()=>({Pre:c,Code:l,SyntaxHighlighter:u,CodeHeader:d}),[c,l,u,d]),m=xQ((0,f.useMemo)(()=>({components:p,componentsByLanguage:t}),[p,t]),3),h=SQ((0,f.useMemo)(()=>{let{pre:t,code:n,SyntaxHighlighter:r,CodeHeader:i,...a}=e??{};return{...a,pre:gQ,code:hQ}},[e])),g=r?vQ:_Q,_=SQ(a);return(0,J.jsx)(mQ.Provider,{value:m,children:(0,J.jsx)(g,{text:s,components:h,..._})})},wQ=(0,f.forwardRef)(({className:e,containerProps:t,containerComponent:n=`div`,...r},i)=>{let a=fQ();return(0,J.jsx)(n,{"data-status":a.type,...t,className:(0,XW.default)(e,t?.className),ref:i,children:(0,J.jsx)(CQ,{...r})})});wQ.displayName=`MarkdownTextPrimitive`;var TQ=pQ(wQ);function EQ(e,t){let n=String(e);if(typeof t!=`string`)throw TypeError(`Expected character`);let r=0,i=n.indexOf(t);for(;i!==-1;)r++,i=n.indexOf(t,i+t.length);return r}function DQ(e){if(typeof e!=`string`)throw TypeError(`Expected a string`);return e.replace(/[|\\{}()[\]^$+*?.]/g,`\\$&`).replace(/-/g,`\\x2d`)}function OQ(e,t,n){let r=JX((n||{}).ignore||[]),i=kQ(t),a=-1;for(;++a<i.length;)iZ(e,o);function o(e,t,n){if(e.type===`text`&&typeof n==`number`)return s(e,t,n);if(r(e,n,t[t.length-1]))return rZ}function s(e,t,n){let r=t[t.length-1],o=i[a][0],s=i[a][1],c=0,l=!1,u=[];o.lastIndex=0;let d=o.exec(e.value);for(;d;){let n=d.index,r={index:d.index,input:d.input,stack:[...t,e]},i=s(...d,r);if(typeof i==`string`&&(i=i.length>0?{type:`text`,value:i}:void 0),i===!1)o.lastIndex=n+1;else{if(c!==n&&f({type:`text`,value:e.value.slice(c,n)}),Array.isArray(i))for(let e of i)f(e);else i&&f(i);c=n+d[0].length,l=!0}if(!o.global)break;d=o.exec(e.value)}return l?(c<e.value.length&&f({type:`text`,value:e.value.slice(c)}),r.children.splice(n,1,...u)):u=[e],n+u.length;function f(e){let t=u[u.length-1];t&&t.type===`text`&&e.type===`text`?t.value+=e.value:u.push(e)}}}function kQ(e){if(!Array.isArray(e))throw TypeError(`Expected find and replace tuple or list of tuples`);let t=[],n=!e[0]||Array.isArray(e[0])?e:[e],r=-1;for(;++r<n.length;){let e=n[r];t.push([AQ(e[0]),jQ(e[1])])}return t}function AQ(e){return typeof e==`string`?new RegExp(DQ(e),`g`):e}function jQ(e){return typeof e==`function`?e:function(){return e}}var MQ=`phrasing`,NQ=[`autolink`,`link`,`image`,`label`];function PQ(){return{transforms:[HQ],enter:{literalAutolink:IQ,literalAutolinkEmail:LQ,literalAutolinkHttp:LQ,literalAutolinkWww:LQ},exit:{literalAutolink:VQ,literalAutolinkEmail:BQ,literalAutolinkHttp:RQ,literalAutolinkWww:zQ}}}function FQ(){return{unsafe:[{character:`@`,before:`[+\\-.\\w]`,after:`[\\-.\\w]`,inConstruct:MQ,notInConstruct:NQ},{character:`.`,before:`[Ww]`,after:`[\\-.\\w]`,inConstruct:MQ,notInConstruct:NQ},{character:`:`,before:`[ps]`,after:`\\/`,inConstruct:MQ,notInConstruct:NQ}]}}function IQ(e){this.enter({type:`link`,title:null,url:``,children:[]},e)}function LQ(e){this.config.enter.autolinkProtocol.call(this,e)}function RQ(e){this.config.exit.autolinkProtocol.call(this,e)}function zQ(e){this.config.exit.data.call(this,e);let t=this.stack[this.stack.length-1];t.type,t.url=`http://`+this.sliceSerialize(e)}function BQ(e){this.config.exit.autolinkEmail.call(this,e)}function VQ(e){this.exit(e)}function HQ(e){OQ(e,[[/(https?:\/\/|www(?=\.))([-.\w]+)([^ \t\r\n]*)/gi,UQ],[/(?<=^|\s|\p{P}|\p{S})([-.\w+]+)@([-\w]+(?:\.[-\w]+)+)/gu,WQ]],{ignore:[`link`,`linkReference`]})}function UQ(e,t,n,r,i){let a=``;if(!qQ(i)||(/^w/i.test(t)&&(n=t+n,t=``,a=`http://`),!GQ(n)))return!1;let o=KQ(n+r);if(!o[0])return!1;let s={type:`link`,title:null,url:a+t+o[0],children:[{type:`text`,value:t+o[0]}]};return o[1]?[s,{type:`text`,value:o[1]}]:s}function WQ(e,t,n,r){return!qQ(r,!0)||/[-\d_]$/.test(n)?!1:{type:`link`,title:null,url:`mailto:`+t+`@`+n,children:[{type:`text`,value:t+`@`+n}]}}function GQ(e){let t=e.split(`.`);return!(t.length<2||t[t.length-1]&&(/_/.test(t[t.length-1])||!/[a-zA-Z\d]/.test(t[t.length-1]))||t[t.length-2]&&(/_/.test(t[t.length-2])||!/[a-zA-Z\d]/.test(t[t.length-2])))}function KQ(e){let t=/[!"&'),.:;<>?\]}]+$/.exec(e);if(!t)return[e,void 0];e=e.slice(0,t.index);let n=t[0],r=n.indexOf(`)`),i=EQ(e,`(`),a=EQ(e,`)`);for(;r!==-1&&i>a;)e+=n.slice(0,r+1),n=n.slice(r+1),r=n.indexOf(`)`),a++;return[e,n]}function qQ(e,t){let n=e.input.charCodeAt(e.index-1);return(e.index===0||Sq(n)||xq(n))&&(!t||n!==47)}r$.peek=n$;function JQ(){this.buffer()}function YQ(e){this.enter({type:`footnoteReference`,identifier:``,label:``},e)}function XQ(){this.buffer()}function ZQ(e){this.enter({type:`footnoteDefinition`,identifier:``,label:``,children:[]},e)}function QQ(e){let t=this.resume(),n=this.stack[this.stack.length-1];n.type,n.identifier=uq(this.sliceSerialize(e)).toLowerCase(),n.label=t}function $Q(e){this.exit(e)}function e$(e){let t=this.resume(),n=this.stack[this.stack.length-1];n.type,n.identifier=uq(this.sliceSerialize(e)).toLowerCase(),n.label=t}function t$(e){this.exit(e)}function n$(){return`[`}function r$(e,t,n,r){let i=n.createTracker(r),a=i.move(`[^`),o=n.enter(`footnoteReference`),s=n.enter(`reference`);return a+=i.move(n.safe(n.associationId(e),{after:`]`,before:a})),s(),o(),a+=i.move(`]`),a}function i$(){return{enter:{gfmFootnoteCallString:JQ,gfmFootnoteCall:YQ,gfmFootnoteDefinitionLabelString:XQ,gfmFootnoteDefinition:ZQ},exit:{gfmFootnoteCallString:QQ,gfmFootnoteCall:$Q,gfmFootnoteDefinitionLabelString:e$,gfmFootnoteDefinition:t$}}}function a$(e){let t=!1;return e&&e.firstLineBlank&&(t=!0),{handlers:{footnoteDefinition:n,footnoteReference:r$},unsafe:[{character:`[`,inConstruct:[`label`,`phrasing`,`reference`]}]};function n(e,n,r,i){let a=r.createTracker(i),o=a.move(`[^`),s=r.enter(`footnoteDefinition`),c=r.enter(`label`);return o+=a.move(r.safe(r.associationId(e),{before:o,after:`]`})),c(),o+=a.move(`]:`),e.children&&e.children.length>0&&(a.shift(4),o+=a.move((t?`
|
|
74
|
+
`:` `)+r.indentLines(r.containerFlow(e,a.current()),t?s$:o$))),s(),o}}function o$(e,t,n){return t===0?e:s$(e,t,n)}function s$(e,t,n){return(n?``:` `)+e}var c$=[`autolink`,`destinationLiteral`,`destinationRaw`,`reference`,`titleQuote`,`titleApostrophe`];p$.attention=m$,p$.peek=h$;function l$(){return{canContainEols:[`delete`],enter:{strikethrough:d$},exit:{strikethrough:f$}}}function u$(){return{handlers:{delete:p$},unsafe:[{character:`~`,inConstruct:`phrasing`,notInConstruct:c$}]}}function d$(e){this.enter({type:`delete`,children:[],position:void 0},e)}function f$(e){this.exit(e)}function p$(e,t,n,r){let i=n.createTracker(r),a=n.stack.includes(`strikethrough`)?`~`:`~~`,o=n.enter(`strikethrough`),s=i.move(a);return s+=n.containerPhrasing(e,{...i.current(),before:s,after:`~`}),s+=i.move(a),o(),s}function m$(){return{construct:`strikethrough`,markers:[`~`],sizes:[2,1]}}function h$(){return`~`}function g$(e){return e.length}function _$(e,t){let n=t||{},r=(n.align||[]).concat(),i=n.stringLength||g$,a=[],o=[],s=[],c=[],l=0,u=-1;for(;++u<e.length;){let t=[],r=[],a=-1;for(e[u].length>l&&(l=e[u].length);++a<e[u].length;){let o=v$(e[u][a]);if(n.alignDelimiters!==!1){let e=i(o);r[a]=e,(c[a]===void 0||e>c[a])&&(c[a]=e)}t.push(o)}o[u]=t,s[u]=r}let d=-1;if(typeof r==`object`&&`length`in r)for(;++d<l;)a[d]=y$(r[d]);else{let e=y$(r);for(;++d<l;)a[d]=e}d=-1;let f=[],p=[];for(;++d<l;){let e=a[d],t=``,r=``;e===99?(t=`:`,r=`:`):e===108?t=`:`:e===114&&(r=`:`);let i=n.alignDelimiters===!1?1:Math.max(1,c[d]-t.length-r.length),o=t+`-`.repeat(i)+r;n.alignDelimiters!==!1&&(i=t.length+i+r.length,i>c[d]&&(c[d]=i),p[d]=i),f[d]=o}o.splice(1,0,f),s.splice(1,0,p),u=-1;let m=[];for(;++u<o.length;){let e=o[u],t=s[u],r=n.fillRows===!1?Math.max(1,o[u===1?0:u].length):l;d=-1;let i=[];for(;++d<r;){let o=e[d]||``,s=``,l=``;if(n.alignDelimiters!==!1){let e=c[d]-(t[d]||0),n=a[d];if(n===114)s=` `.repeat(e);else if(n===99){let t=e/2;e%2?(s=` `.repeat(t+.5),l=` `.repeat(t-.5)):(s=` `.repeat(t),l=s)}else l=` `.repeat(e)}n.delimiterStart!==!1&&!d&&i.push(`|`),n.padding===!1||n.alignDelimiters===!1&&o===``||n.delimiterStart===!1&&!d||i.push(` `),n.alignDelimiters!==!1&&i.push(s),i.push(o),n.alignDelimiters!==!1&&i.push(l),n.padding!==!1&&i.push(` `),(n.delimiterEnd!==!1||d!==r-1)&&i.push(`|`)}m.push(n.delimiterEnd===!1?i.join(``).replace(/ +$/,``):i.join(``))}return m.join(`
|
|
75
|
+
`)}function v$(e){return e==null?``:String(e)}function y$(e){let t=typeof e==`string`?e.codePointAt(0):0;return t===67||t===99?99:t===76||t===108?108:t===82||t===114?114:0}var b$=JX([`break`,`delete`,`emphasis`,`footnote`,`footnoteReference`,`image`,`imageReference`,`inlineCode`,`inlineMath`,`link`,`linkReference`,`mdxJsxTextElement`,`mdxTextExpression`,`strong`,`text`,`textDirective`]);function x$(e,t,n,r){let i=n.enter(`blockquote`),a=n.createTracker(r);a.move(`> `),a.shift(2);let o=n.indentLines(n.containerFlow(e,a.current()),S$);return i(),o}function S$(e,t,n){return`>`+(n?``:` `)+e}function C$(e,t){return w$(e,t.inConstruct,!0)&&!w$(e,t.notInConstruct,!1)}function w$(e,t,n){if(typeof t==`string`&&(t=[t]),!t||t.length===0)return n;let r=-1;for(;++r<t.length;)if(e.includes(t[r]))return!0;return!1}function T$(e,t,n,r){let i=-1;for(;++i<n.unsafe.length;){let e=n.unsafe[i];if(e.character===`
|
|
76
|
+
`&&!e.before&&!e.after&&C$(n.stack,e))return/[\t ]/.test(r.before)?``:` `}return`\\
|
|
77
|
+
`}function E$(e,t){let n=String(e),r=n.indexOf(t),i=r,a=0,o=0;if(typeof t!=`string`)throw TypeError(`Expected substring`);for(;r!==-1;)r===i?++a>o&&(o=a):a=1,i=r+t.length,r=n.indexOf(t,i);return o}function D$(e,t){return!(t.options.fences!==!1||!e.value||e.lang||!/[^\n\r ]/.test(e.value)||/^[\t ]*(?:[\n\r]|$)|(?:^|[\n\r])[\t ]*$/.test(e.value))}function O$(e){let t=e.options.fence||"`";if(t!=="`"&&t!==`~`)throw Error("Cannot serialize code with `"+t+"` for `options.fence`, expected `` ` `` or `~`");return t}function k$(e,t,n,r){let i=O$(n),a=e.value||``;if(D$(e,n)){let e=n.enter(`codeIndented`),t=n.indentLines(a,A$);return e(),t}let o=n.createTracker(r),s=i.repeat(Math.max(E$(a,i)+1,3)),c=n.enter(`codeFenced`),l=i==="`"?`GraveAccent`:`Tilde`,u=o.move(s);if(e.lang){let t=n.enter(`codeFencedLang${l}`);u+=o.move(n.safe(e.lang,{before:u,after:` `,encode:["`"],...o.current()})),t()}if(e.lang&&e.meta){let t=n.enter(`codeFencedMeta${l}`);u+=o.move(` `),u+=o.move(n.safe(e.meta,{before:u,after:`
|
|
78
|
+
`,encode:["`"],...o.current()})),t()}return u+=o.move(`
|
|
79
|
+
`),a&&(u+=o.move(a+`
|
|
80
|
+
`)),u+=o.move(s),c(),u}function A$(e,t,n){return(n?``:` `)+e}function j$(e){let t=e.options.quote||`"`;if(t!==`"`&&t!==`'`)throw Error("Cannot serialize title with `"+t+"` for `options.quote`, expected `\"`, or `'`");return t}function M$(e,t,n,r){let i=j$(n),a=i===`"`?`Quote`:`Apostrophe`,o=n.enter(`definition`),s=n.enter(`label`),c=n.createTracker(r),l=c.move(`[`);return l+=c.move(n.safe(n.associationId(e),{before:l,after:`]`,...c.current()})),l+=c.move(`]: `),s(),!e.url||/[\0- \u007F]/.test(e.url)?(s=n.enter(`destinationLiteral`),l+=c.move(`<`),l+=c.move(n.safe(e.url,{before:l,after:`>`,...c.current()})),l+=c.move(`>`)):(s=n.enter(`destinationRaw`),l+=c.move(n.safe(e.url,{before:l,after:e.title?` `:`
|
|
81
|
+
`,...c.current()}))),s(),e.title&&(s=n.enter(`title${a}`),l+=c.move(` `+i),l+=c.move(n.safe(e.title,{before:l,after:i,...c.current()})),l+=c.move(i),s()),o(),l}function N$(e){let t=e.options.emphasis||`*`;if(t!==`*`&&t!==`_`)throw Error("Cannot serialize emphasis with `"+t+"` for `options.emphasis`, expected `*`, or `_`");return t}function P$(e){let t=e.codePointAt(0);return t===void 0?``:String.fromCodePoint(t)}function F$(e){let t=e.codePointAt(e.length-2);return t!==void 0&&t>65535?e.slice(-2):e.slice(-1)}function I$(e){return`&#x`+e.toString(16).toUpperCase()+`;`}function L$(e,t,n){let r=Fq(e),i=Fq(t);return r===void 0?i===void 0?n===`_`?{inside:!0,outside:!0}:{inside:!1,outside:!1}:i===1?{inside:!0,outside:!0}:{inside:!1,outside:!0}:r===1?i===void 0?{inside:!1,outside:!1}:i===1?{inside:!0,outside:!0}:{inside:!1,outside:!1}:i===void 0?{inside:!1,outside:!1}:i===1?{inside:!0,outside:!1}:{inside:!1,outside:!1}}function R$(e){if(e.charCodeAt(0)!==60)return;let t=e.charCodeAt(1);if(t===33){let t=e.charCodeAt(2);return t===45?2:t===91?5:dq(t)?4:void 0}if(t===63)return 3;let n=t===47,r=n?2:1,i=r,a=e.charCodeAt(i);if(!dq(a))return;for(;a===45||fq(a);)a=e.charCodeAt(++i);let o=e.slice(r,i).toLowerCase();return!n&&a!==47&&PJ.includes(o)?1:NJ.includes(o)?6:7}var z$=new Map([[`*`,!1],[`_`,!0]]);function B$(e,t,n){let r=new Set;for(let i of e){let e=n.get(i);if(e&&i.attention&&t.some(e=>e.attention===i.attention))for(let t of e.tokens)r.add(t.attention)}let i=[];for(let t of e)t.attention&&r.delete(t.attention)&&i.push(t.attention);return i.reverse(),i}function V$(e,t,n){let r=[],i=new Map,a=new Map,o=0;for(;o<e.length;){if(!e[o].attention){o++;continue}let s=e[o].value.charAt(0),c=z$.get(s),l=o+1;for(;l<e.length&&e[l].attention&&e[l].value.charAt(0)===s;)l++;let u=o?e[o-1].value:t,d=Fq(u.charCodeAt(u.length-1)),f=Fq((l<e.length?e[l].value:n).charCodeAt(0)),p=!f||f===2&&!!d,m=!d||d===2&&!!f,h={tokens:e.slice(o,l),markers:[],start:0,end:0,open:c?p&&(!!d||!m):p,close:c?m&&(!!f||!p):m,split:c!==void 0};for(let e of h.tokens){i.set(e,[...h.tokens]),a.set(e,h);let t=e.value.length;for(;t--;)h.markers.push(e)}h.end=h.markers.length,r.push(h),o=l}for(W$(r,i),o=-1;++o<e.length;){let t=i.get(e[o]);if(t)return{attention:B$(e,t,a),index:o}}}function H$(e,t){let n=e[t?0:e.length-1];if(!n||n.attention)return;let r=t?P$(n.value):F$(n.value),i=I$(r.codePointAt(0));if(t)n.value=i+n.value.slice(r.length);else{let e=n.value.slice(0,n.value.length-r.length),t=0;for(;e.charCodeAt(e.length-1-t)===92;)t++;t%2&&(e+=`\\`),n.value=e+i}}function U$(e,t,n,r,i){for(let a of n.attention){let o=t.get(a)||a.sequences[0];for(let s of a.sequences){if(s===o)continue;let c=new Map(t);c.set(a,s);let l=J$(e,c,r,i),u=V$(l,r,i);if(!u||u.index>n.index)return{chosen:c,mistake:u,tokens:l}}}}function W$(e,t){let n=new Map;for(let r of e){let e=r.tokens[0].value.charAt(0),i=n.get(e);i||(i=[],n.set(e,i));let a=r.close?i.length:0;for(;a--&&r.start<r.end;){let e=i[a],n=e.end-e.start,o=r.end-r.start;if(r.split?(e.close||r.open)&&o%3&&!((n+o)%3):n!==e.markers.length||n!==o)continue;let s=r.split?n>1&&o>1?2:1:o,c=e.markers.slice(e.end-s,e.end),l=r.markers.slice(r.start,r.start+s),u=c[0],d=l[0];if(u===c[s-1]&&u.value.length===s&&d===l[s-1]&&d.value.length===s&&u.attention===d.attention)t.delete(u),t.delete(d);else{let e=[...new Set([...c,...l])];for(let n of e){let r=t.get(n);r&&r.push(...e)}}e.end-=s,r.start+=s,e.start===e.end&&i.splice(a,1),a=i.length}r.open&&r.start<r.end&&i.push(r)}}function G$(e,t,n){if(t.length===0)throw Error("Cannot serialize `"+e+"` as attention without markers, expected one or more markers");if(n.length===0)throw Error("Cannot serialize `"+e+"` as attention without sizes, expected one or more sizes");for(let t of n)if(!Number.isSafeInteger(t)||t<1)throw Error("Cannot serialize `"+e+"` as attention with `"+t+"` as size, expected positive integer");let r=[];for(let i of t){if(i.length!==1)throw Error("Cannot serialize `"+e+"` as attention with `"+i+"` as marker, expected a single ascii character");if(!_q(i.charCodeAt(0)))throw Error("Cannot serialize `"+e+"` as attention with `"+i+"` as marker, expected ascii punctuation");for(let e of n)r.push(i.repeat(e))}return r}function K$(e,t,n){let r=t.indexStack,i=e.children||[],a=[],o=-1,s=n.before;r.push(-1);let c=t.createTracker(n);for(;++o<i.length;){let l=i[o],u;if(r[r.length-1]=o,o+1<i.length){let n=t.handle.handlers[i[o+1].type];n&&n.peek&&(n=n.peek),u=n?P$(n(i[o+1],e,t,{before:``,after:``,...c.current()})):``}else u=n.after;let d=a[a.length-1];typeof d==`string`&&(s===`\r`||s===`
|
|
82
|
+
`)&&l.type===`html`&&R$(l.value)!==7&&(a[a.length-1]=d.replace(/(\r?\n|\r)$/,` `),s=` `,c=t.createTracker(n),c.move(Y$(a,n.before,n.after)));let f=t.handle.handlers[l.type];if(f&&f.attention){let e=q$(l,f.attention,t,c);a.push(e),s=F$(e.sequences[0])}else{let n=t.handle(l,e,t,{...c.current(),after:u,before:s});if(!n)continue;c.move(n),a.push(n),s=F$(n)}}return r.pop(),a}function q$(e,t,n,r){let{construct:i,markers:a,sizes:o}=t(e,n),s=G$(e.type,a,o),c=s[0],l=n.enter(i);r.move(c);let u=K$(e,n,{...r.current(),before:c,after:c});return r.move(Y$(u,c,c)),r.move(c),l(),{children:u,sequences:s}}function J$(e,t,n,r){let i=[],a,o=F$(n),s=-1;for(;++s<e.length;){let n=e[s];if(typeof n==`string`){let e={value:n,attention:void 0};a&&a===P$(n)&&H$([e],!0),a=void 0,i.push(e),e.value&&(o=F$(e.value));continue}let c=t.get(n)||n.sequences[0],l=c.charAt(0),u=e[s+1],d=o,f=P$(u===void 0?r:typeof u==`string`?u:t.get(u)||u.sequences[0]),p=J$(n.children,t,c,c),m=p.length>0?p[0].value:``,h=L$(d.charCodeAt(d.length-1),m.charCodeAt(0),l);h.inside&&H$(p,!0);let g=p.length>0?F$(p[p.length-1].value):``,_=L$(f.charCodeAt(0),g.charCodeAt(g.length-1),l);_.inside&&H$(p,!1),h.outside&&d!==`
|
|
83
|
+
`&&d!==`\r`&&H$(i,!1),_.outside&&(a=f),i.push({value:c,attention:n},...p,{value:c,attention:n}),o=c.charAt(c.length-1)}return i}function Y$(e,t,n){let r=new Map,i=J$(e,r,t,n),a=i,o=V$(a,t,n);for(;o;){let s=U$(e,r,o,t,n);if(!s){a=i;break}r=s.chosen,a=s.tokens,o=s.mistake}let s=``;for(let e of a)s+=e.value;return s}X$.attention=Z$,X$.peek=Q$;function X$(e,t,n,r){let i=n.enter(`phrasing`),a=Y$([q$(e,Z$,n,n.createTracker(r))],r.before,r.after);return i(),a}function Z$(e,t){return{construct:`emphasis`,markers:N$(t)===`*`?[`*`,`_`]:[`_`,`*`],sizes:[1]}}function Q$(e,t,n){return n.options.emphasis||`*`}function $$(e,t){let n=!1;return oZ(e,function(e){if(`value`in e&&/\r?\n|\r/.test(e.value)||e.type===`break`)return n=!0,!1}),!!((!e.depth||e.depth<3)&&ZK(e)&&(t.options.setext||n))}function e1(e,t,n,r){let i=Math.max(Math.min(6,e.depth||1),1),a=n.createTracker(r);if($$(e,n)){let t=n.enter(`headingSetext`),r=n.enter(`phrasing`),o=n.containerPhrasing(e,{...a.current(),before:`
|
|
84
|
+
`,after:`
|
|
85
|
+
`});return r(),t(),o+`
|
|
86
|
+
`+(i===1?`=`:`-`).repeat(o.length-(Math.max(o.lastIndexOf(`\r`),o.lastIndexOf(`
|
|
87
|
+
`))+1))}let o=`#`.repeat(i),s=n.enter(`headingAtx`),c=n.enter(`phrasing`);a.move(o+` `);let l=n.containerPhrasing(e,{before:`# `,after:`
|
|
88
|
+
`,...a.current()}),u=l.charCodeAt(0);return(u===9||u===32)&&(l=I$(u)+l.slice(1)),l=l?o+` `+l:o,n.options.closeAtx&&(l+=` `+o),c(),s(),l}t1.peek=n1;function t1(e){return e.value||``}function n1(){return`<`}r1.peek=i1;function r1(e,t,n,r){let i=j$(n),a=i===`"`?`Quote`:`Apostrophe`,o=n.enter(`image`),s=n.enter(`label`),c=n.createTracker(r),l=c.move(`![`);return l+=c.move(n.safe(e.alt,{before:l,after:`]`,...c.current()})),l+=c.move(`](`),s(),!e.url&&e.title||/[\0- \u007F]/.test(e.url)?(s=n.enter(`destinationLiteral`),l+=c.move(`<`),l+=c.move(n.safe(e.url,{before:l,after:`>`,...c.current()})),l+=c.move(`>`)):(s=n.enter(`destinationRaw`),l+=c.move(n.safe(e.url,{before:l,after:e.title?` `:`)`,...c.current()}))),s(),e.title&&(s=n.enter(`title${a}`),l+=c.move(` `+i),l+=c.move(n.safe(e.title,{before:l,after:i,...c.current()})),l+=c.move(i),s()),l+=c.move(`)`),o(),l}function i1(){return`!`}a1.peek=o1;function a1(e,t,n,r){let i=e.referenceType,a=n.enter(`imageReference`),o=n.enter(`label`),s=n.createTracker(r),c=s.move(`![`),l=n.safe(e.alt,{before:c,after:`]`,...s.current()});c+=s.move(l+`][`),o();let u=n.stack;n.stack=u.filter(function(e){return e!==`phrasing`}),o=n.enter(`reference`);let d=n.safe(n.associationId(e),{before:c,after:`]`,...s.current()});return o(),n.stack=u,a(),i===`full`||!l||l!==d?c+=s.move(d+`]`):i===`shortcut`?c=c.slice(0,-1):c+=s.move(`]`),c}function o1(){return`!`}s1.peek=c1;function s1(e,t,n){let r=e.value||``,i="`",a=-1;for(;RegExp("(^|[^`])"+i+"([^`]|$)").test(r);)i+="`";for(/[^\n\r ]/.test(r)&&(/^[\n\r ]/.test(r)&&/[\n\r ]$/.test(r)||/^`|`$/.test(r))&&(r=` `+r+` `);++a<n.unsafe.length;){let e=n.unsafe[a],t=n.compilePattern(e);if(!e.atBreak)continue;let i;for(;i=t.exec(r);){let e=i.index;r.charCodeAt(e)===10&&r.charCodeAt(e-1)===13&&e--,r=r.slice(0,e)+` `+r.slice(i.index+1)}}return i+r+i}function c1(){return"`"}function l1(e,t){let n=ZK(e);return!(t.options.resourceLink||!e.url||e.title||!e.children||e.children.length!==1||e.children[0].type!==`text`||n!==e.url&&`mailto:`+n!==e.url||!/^[a-z][+\-.a-z]+:/i.test(e.url)||/[\0- <>\u007F]/.test(e.url))}u1.peek=d1;function u1(e,t,n,r){let i=j$(n),a=i===`"`?`Quote`:`Apostrophe`,o=n.createTracker(r);if(l1(e,n)){let t=n.stack;n.stack=t.filter(function(e){return e!==`phrasing`});let r=n.enter(`autolink`),i=o.move(`<`);return i+=o.move(n.containerPhrasing(e,{before:i,after:`>`,...o.current()})),i+=o.move(`>`),r(),n.stack=t,i}let s=n.enter(`link`),c=n.enter(`label`),l=o.move(`[`),u=n.containerPhrasing(e,{before:l,after:`](`,...o.current()});l+=o.move(u),c(),l+=o.move(`](`);let d=/[\0- \u007F]/.test(e.url),f=r.before.charAt(r.before.length-1),p=e.title||void 0;if(!p&&!d&&(f===`
|
|
89
|
+
`||f===`\r`)){let e=0;for(;e<u.length&&u.charCodeAt(e)!==93;)e+=u.charCodeAt(e)===92?2:1;u.charCodeAt(e+1)===58&&(p=``)}return!e.url&&typeof p==`string`||d?(c=n.enter(`destinationLiteral`),l+=o.move(`<`),l+=o.move(n.safe(e.url,{before:l,after:`>`,...o.current()})),l+=o.move(`>`)):(c=n.enter(`destinationRaw`),l+=o.move(n.safe(e.url,{before:l,after:typeof p==`string`?` `:`)`,...o.current()}))),c(),typeof p==`string`&&(c=n.enter(`title${a}`),l+=o.move(` `+i),l+=o.move(n.safe(p,{before:l,after:i,...o.current()})),l+=o.move(i),c()),l+=o.move(`)`),s(),l}function d1(e,t,n){return l1(e,n)?`<`:`[`}f1.peek=p1;function f1(e,t,n,r){let i=e.referenceType,a=n.enter(`linkReference`),o=n.enter(`label`),s=n.createTracker(r),c=s.move(`[`),l=n.containerPhrasing(e,{before:c,after:`]`,...s.current()});c+=s.move(l+`][`),o();let u=n.stack;n.stack=u.filter(function(e){return e!==`phrasing`}),o=n.enter(`reference`);let d=n.safe(n.associationId(e),{before:c,after:`]`,...s.current()});return o(),n.stack=u,a(),i===`full`||!l||l!==d?c+=s.move(d+`]`):i===`shortcut`?c=c.slice(0,-1):c+=s.move(`]`),c}function p1(){return`[`}function m1(e){let t=e.options.bullet||`*`;if(t!==`*`&&t!==`+`&&t!==`-`)throw Error("Cannot serialize items with `"+t+"` for `options.bullet`, expected `*`, `+`, or `-`");return t}function h1(e){let t=m1(e),n=e.options.bulletOther;if(!n)return t===`*`?`-`:`*`;if(n!==`*`&&n!==`+`&&n!==`-`)throw Error("Cannot serialize items with `"+n+"` for `options.bulletOther`, expected `*`, `+`, or `-`");if(n===t)throw Error("Expected `bullet` (`"+t+"`) and `bulletOther` (`"+n+"`) to be different");return n}function g1(e){let t=e.options.bulletOrdered||`.`;if(t!==`.`&&t!==`)`)throw Error("Cannot serialize items with `"+t+"` for `options.bulletOrdered`, expected `.` or `)`");return t}function _1(e){let t=e.options.rule||`*`;if(t!==`*`&&t!==`-`&&t!==`_`)throw Error("Cannot serialize rules with `"+t+"` for `options.rule`, expected `*`, `-`, or `_`");return t}function v1(e,t,n,r){let i=n.enter(`list`),a=n.bulletCurrent,o=e.ordered?g1(n):m1(n),s=e.ordered?o===`.`?`)`:`.`:h1(n),c=t&&n.bulletLastUsed?o===n.bulletLastUsed:!1;if(!e.ordered){let t=e.children?e.children[0]:void 0;if(o!==`*`&&o!==`-`||!t||t.children&&t.children[0]||n.stack[n.stack.length-1]!==`list`||n.stack[n.stack.length-2]!==`listItem`||n.stack[n.stack.length-3]!==`list`||n.stack[n.stack.length-4]!==`listItem`||n.indexStack[n.indexStack.length-1]!==0||n.indexStack[n.indexStack.length-2]!==0||n.indexStack[n.indexStack.length-3]!==0||(c=!0),_1(n)===o&&t){let t=-1;for(;++t<e.children.length;){let n=e.children[t];if(n&&n.type===`listItem`&&n.children&&n.children[0]&&n.children[0].type===`thematicBreak`){c=!0;break}}}}c&&(o=s),n.bulletCurrent=o;let l=n.containerFlow(e,r);return n.bulletLastUsed=o,n.bulletCurrent=a,i(),l}function y1(e){let t=e.options.listItemIndent||`one`;if(t!==`tab`&&t!==`one`&&t!==`mixed`)throw Error("Cannot serialize items with `"+t+"` for `options.listItemIndent`, expected `tab`, `one`, or `mixed`");return t}function b1(e,t,n,r){let i=y1(n),a=n.bulletCurrent||m1(n);t&&t.type===`list`&&t.ordered&&(a=(typeof t.start==`number`&&t.start>-1?t.start:1)+(n.options.incrementListMarker===!1?0:t.children.indexOf(e))+a);let o=a.length+1;(i===`tab`||i===`mixed`&&(t&&t.type===`list`&&t.spread||e.spread))&&(o=Math.ceil(o/4)*4);let s=n.createTracker(r);s.move(a+` `.repeat(o-a.length)),s.shift(o);let c=n.enter(`listItem`),l=n.indentLines(n.containerFlow(e,s.current()),u);return c(),l;function u(e,t,n){return t?(n?``:` `.repeat(o))+e:(n?a:a+` `.repeat(o-a.length))+e}}function x1(e,t,n,r){let i=n.enter(`paragraph`),a=n.enter(`phrasing`),o=n.containerPhrasing(e,r);return a(),i(),o}function S1(e,t,n,r){if(!e.children.some(function(e){return b$(e)}))return n.containerFlow(e,r);let i=n.enter(`phrasing`),a=n.containerPhrasing(e,r);return i(),a}function C1(e){let t=e.options.strong||`*`;if(t!==`*`&&t!==`_`)throw Error("Cannot serialize strong with `"+t+"` for `options.strong`, expected `*`, or `_`");return t}w1.attention=T1,w1.peek=E1;function w1(e,t,n,r){let i=n.enter(`phrasing`),a=Y$([q$(e,T1,n,n.createTracker(r))],r.before,r.after);return i(),a}function T1(e,t){return{construct:`strong`,markers:C1(t)===`*`?[`*`,`_`]:[`_`,`*`],sizes:[2]}}function E1(e,t,n){return n.options.strong||`*`}function D1(e,t,n,r){let i=t?t.children:[],a=n.indexStack[n.indexStack.length-1];return n.safe(e.value,{...r,afterNode:i[a+1],beforeNode:i[a-1]})}function O1(e){let t=e.options.ruleRepetition||3;if(t<3)throw Error("Cannot serialize rules with repetition `"+t+"` for `options.ruleRepetition`, expected `3` or more");return t}function k1(e,t,n){let r=(_1(n)+(n.options.ruleSpaces?` `:``)).repeat(O1(n));return n.options.ruleSpaces?r.slice(0,-1):r}var A1={blockquote:x$,break:T$,code:k$,definition:M$,emphasis:X$,hardBreak:T$,heading:e1,html:t1,image:r1,imageReference:a1,inlineCode:s1,link:u1,linkReference:f1,list:v1,listItem:b1,paragraph:x1,root:S1,strong:w1,text:D1,thematicBreak:k1};function j1(){return{enter:{table:M1,tableData:I1,tableHeader:I1,tableRow:P1},exit:{codeText:L1,table:N1,tableData:F1,tableHeader:F1,tableRow:F1}}}function M1(e){let t=e._align;this.enter({type:`table`,align:t.map(function(e){return e===`none`?null:e}),children:[],position:void 0},e),this.data.inTable=!0}function N1(e){this.exit(e),this.data.inTable=void 0}function P1(e){this.enter({type:`tableRow`,children:[],position:void 0},e)}function F1(e){this.exit(e)}function I1(e){this.enter({type:`tableCell`,children:[],position:void 0},e)}function L1(e){let t=this.resume();this.data.inTable&&(t=t.replace(/\\([\\|])/g,R1));let n=this.stack[this.stack.length-1];n.type,n.value=t,this.exit(e)}function R1(e,t){return t===`|`?t:e}function z1(e){let{tableCellPadding:t,tablePipeAlign:n,stringLength:r}=e||{},i=t?` `:`|`;return{handlers:{inlineCode:d,table:a,tableCell:s,tableRow:o},join:[B1],unsafe:[{character:`\r`,inConstruct:`tableCell`},{character:`
|
|
90
|
+
`,inConstruct:`tableCell`},{atBreak:!0,character:`|`,after:`[ :-]`},{character:`|`,inConstruct:`tableCell`},{atBreak:!0,character:`:`,after:`-`},{atBreak:!0,character:`-`,after:`[:|-]`}]};function a(e,t,n,r){let i=l(e,n,r),a=i[0];if(a){let t=e.align?e.align.length:0,n=-1;if(!t)for(;++n<i.length;)i[n].length>t&&(t=i[n].length);for(;a.length<t;)a.push(``)}return c(i,e.align)}function o(e,t,n,r){let i=c([u(e,n,r)]);return i.slice(0,i.indexOf(`
|
|
91
|
+
`))}function s(e,t,n,r){let a=n.enter(`tableCell`),o=n.enter(`phrasing`),s=n.containerPhrasing(e,{...r,before:i,after:i});return o(),a(),s}function c(e,i){return _$(e,{align:i,alignDelimiters:n,fillRows:!1,padding:t,stringLength:r})}function l(e,t,n){let{children:r}=e,i=-1,a=[],o=t.enter(`table`);for(;++i<r.length;)a[i]=u(r[i],t,n);return o(),a}function u(e,t,n){let{children:r}=e,i=-1,a=[],o=t.enter(`tableRow`);for(;++i<r.length;)a[i]=s(r[i],e,t,n);return o(),a}function d(e,t,n){let r=A1.inlineCode(e,t,n);if(!n.stack.includes(`tableCell`))return r;let i=[],a=0,o=r.indexOf(`|`);for(;o!==-1;){let e=o;for(;e>a&&r.charCodeAt(e-1)===92;)e--;i.push(r.slice(a,o)),(o-e)%2==0&&i.push(`\\`),a=o,o=r.indexOf(`|`,o+1)}return i.push(r.slice(a)),i.join(``)}}function B1(e,t,n,r){if(e.type===`table`&&n.type===`listItem`&&n.spread===!1&&(t.type===`definition`||t.type===`heading`&&V1(t,r)||t.type===`paragraph`||t.type===`table`))return 1}function V1(e,t){let n=!1;return oZ(e,function(e){if(e.type===`break`||`value`in e&&/\r?\n|\r/.test(e.value))return n=!0,!1}),!!((!e.depth||e.depth<3)&&ZK(e)&&(t.options.setext||n))}function H1(){return{exit:{taskListCheckValueChecked:W1,taskListCheckValueUnchecked:W1,paragraph:G1}}}function U1(){return{unsafe:[{atBreak:!0,character:`-`,after:`[:|-]`}],handlers:{listItem:K1}}}function W1(e){let t=this.stack[this.stack.length-2];t.type,t.checked=e.type===`taskListCheckValueChecked`}function G1(e){let t=this.stack[this.stack.length-2];if(t&&t.type===`listItem`&&typeof t.checked==`boolean`){let e=this.stack[this.stack.length-1];e.type;let n=e.children[0];if(n&&n.type===`text`){let r=t.children,i=-1,a;for(;++i<r.length;){let e=r[i];if(e.type===`paragraph`){a=e;break}}a===e&&(n.value=n.value.slice(1),n.value.length===0?e.children.shift():e.position&&n.position&&typeof n.position.start.offset==`number`&&(n.position.start.column++,n.position.start.offset++,e.position.start=Object.assign({},n.position.start)))}}this.exit(e)}function K1(e,t,n,r){let i=e.children[0],a=typeof e.checked==`boolean`&&i&&i.type===`paragraph`,o=`[`+(e.checked?`x`:` `)+`] `,s=n.createTracker(r);a&&s.move(o);let c=A1.listItem(e,t,n,{...r,...s.current()});return a&&(c=c.replace(/^(?:[*+-]|\d+\.)([\r\n]| {1,3})/,l)),c;function l(e){return e+o}}function q1(){return[PQ(),i$(),l$(),j1(),H1()]}function J1(e){return{extensions:[FQ(),a$(e),u$(),z1(e),U1()]}}var Y1={tokenize:l0,partial:!0},X1={tokenize:u0,partial:!0},Z1={tokenize:d0,partial:!0},Q1={tokenize:f0,partial:!0},$1={tokenize:p0,partial:!0},e0={name:`wwwAutolink`,tokenize:s0,previous:m0},t0={name:`protocolAutolink`,tokenize:c0,previous:h0},n0={name:`emailAutolink`,tokenize:o0,previous:g0},r0={};function i0(){return{text:r0}}for(var a0=48;a0<123;)r0[a0]=n0,a0++,a0===58?a0=65:a0===91&&(a0=97);r0[43]=n0,r0[45]=n0,r0[46]=n0,r0[95]=n0,r0[72]=[n0,t0],r0[104]=[n0,t0],r0[87]=[n0,e0],r0[119]=[n0,e0];function o0(e,t,n){let r=this,i,a;return o;function o(t){return!_0(t)||!g0.call(r,r.previous)||v0(r.events)?n(t):(e.enter(`literalAutolink`),e.enter(`literalAutolinkEmail`),s(t))}function s(t){return _0(t)?(e.consume(t),s):t===64?(e.consume(t),c):n(t)}function c(t){return t===46?e.check($1,u,l)(t):t===45||t===95||fq(t)?(a=!0,e.consume(t),c):u(t)}function l(t){return e.consume(t),i=!0,c}function u(o){return a&&i&&dq(r.previous)?(e.exit(`literalAutolinkEmail`),e.exit(`literalAutolink`),t(o)):n(o)}}function s0(e,t,n){let r=this;return i;function i(t){return t!==87&&t!==119||!m0.call(r,r.previous)||v0(r.events)?n(t):(e.enter(`literalAutolink`),e.enter(`literalAutolinkWww`),e.check(Y1,e.attempt(X1,e.attempt(Z1,a),n),n)(t))}function a(n){return e.exit(`literalAutolinkWww`),e.exit(`literalAutolink`),t(n)}}function c0(e,t,n){let r=this,i=``,a=!1;return o;function o(t){return(t===72||t===104)&&h0.call(r,r.previous)&&!v0(r.events)?(e.enter(`literalAutolink`),e.enter(`literalAutolinkHttp`),i+=String.fromCodePoint(t),e.consume(t),s):n(t)}function s(t){if(dq(t)&&i.length<5)return i+=String.fromCodePoint(t),e.consume(t),s;if(t===58){let n=i.toLowerCase();if(n===`http`||n===`https`)return e.consume(t),c}return n(t)}function c(t){return t===47?(e.consume(t),a?l:(a=!0,c)):n(t)}function l(t){return t===null||mq(t)||yq(t)||Sq(t)||xq(t)?n(t):e.attempt(X1,e.attempt(Z1,u),n)(t)}function u(n){return e.exit(`literalAutolinkHttp`),e.exit(`literalAutolink`),t(n)}}function l0(e,t,n){let r=0;return i;function i(t){return(t===87||t===119)&&r<3?(r++,e.consume(t),i):t===46&&r===3?(e.consume(t),a):n(t)}function a(e){return e===null?n(e):t(e)}}function u0(e,t,n){let r,i,a;return o;function o(t){return t===46||t===95?e.check(Q1,c,s)(t):t===null||yq(t)||Sq(t)||t!==45&&xq(t)?c(t):(a=!0,e.consume(t),o)}function s(t){return t===95?r=!0:(i=r,r=void 0),e.consume(t),o}function c(e){return i||r||!a?n(e):t(e)}}function d0(e,t){let n=0,r=0;return i;function i(o){return o===40?(n++,e.consume(o),i):o===41&&r<n?a(o):o===33||o===34||o===38||o===39||o===41||o===42||o===44||o===46||o===58||o===59||o===60||o===63||o===93||o===95||o===126?e.check(Q1,t,a)(o):o===null||yq(o)||Sq(o)?t(o):(e.consume(o),i)}function a(t){return t===41&&r++,e.consume(t),i}}function f0(e,t,n){return r;function r(o){return o===33||o===34||o===39||o===41||o===42||o===44||o===46||o===58||o===59||o===63||o===95||o===126?(e.consume(o),r):o===38?(e.consume(o),a):o===93?(e.consume(o),i):o===60||o===null||yq(o)||Sq(o)?t(o):n(o)}function i(e){return e===null||e===40||e===91||yq(e)||Sq(e)?t(e):r(e)}function a(e){return dq(e)?o(e):n(e)}function o(t){return t===59?(e.consume(t),r):dq(t)?(e.consume(t),o):n(t)}}function p0(e,t,n){return r;function r(t){return e.consume(t),i}function i(e){return fq(e)?n(e):t(e)}}function m0(e){return e===null||e===40||e===42||e===95||e===91||e===93||e===126||yq(e)}function h0(e){return!dq(e)}function g0(e){return!(e===47||_0(e))}function _0(e){return e===43||e===45||e===46||e===95||fq(e)}function v0(e){let t=e.length,n=!1;for(;t--;){let r=e[t][1];if((r.type===`labelLink`||r.type===`labelImage`)&&!r._balanced){n=!0;break}if(r._gfmAutolinkLiteralWalkedInto){n=!1;break}}return e.length>0&&!n&&(e[e.length-1][1]._gfmAutolinkLiteralWalkedInto=!0),n}var y0={tokenize:D0,partial:!0};function b0(){return{document:{91:{name:`gfmFootnoteDefinition`,tokenize:w0,continuation:{tokenize:T0},exit:E0}},text:{91:{name:`gfmFootnoteCall`,tokenize:C0},93:{name:`gfmPotentialFootnoteCall`,add:`after`,tokenize:x0,resolveTo:S0}}}}function x0(e,t,n){let r=this,i=r.events.length,a=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]),o;for(;i--;){let e=r.events[i][1];if(e.type===`labelImage`){o=e;break}if(e.type===`gfmFootnoteCall`||e.type===`labelLink`||e.type===`label`||e.type===`image`||e.type===`link`)break}return s;function s(i){if(!o||!o._balanced)return n(i);let s=uq(r.sliceSerialize({start:o.end,end:r.now()}));return s.codePointAt(0)!==94||!a.includes(s.slice(1))?n(i):(e.enter(`gfmFootnoteCallLabelMarker`),e.consume(i),e.exit(`gfmFootnoteCallLabelMarker`),t(i))}}function S0(e,t){let n=e.length;for(;n--;)if(e[n][1].type===`labelImage`&&e[n][0]===`enter`){e[n][1];break}e[n+1][1].type=`data`,e[n+3][1].type=`gfmFootnoteCallLabelMarker`;let r={type:`gfmFootnoteCall`,start:Object.assign({},e[n+3][1].start),end:Object.assign({},e[e.length-1][1].end)},i={type:`gfmFootnoteCallMarker`,start:Object.assign({},e[n+3][1].end),end:Object.assign({},e[n+3][1].end)};i.end.column++,i.end.offset++,i.end._bufferIndex++;let a={type:`gfmFootnoteCallString`,start:Object.assign({},i.end),end:Object.assign({},e[e.length-1][1].start)},o={type:`chunkString`,contentType:`string`,start:Object.assign({},a.start),end:Object.assign({},a.end)},s=[e[n+1],e[n+2],[`enter`,r,t],e[n+3],e[n+4],[`enter`,i,t],[`exit`,i,t],[`enter`,a,t],[`enter`,o,t],[`exit`,o,t],[`exit`,a,t],e[e.length-2],e[e.length-1],[`exit`,r,t]];return e.splice(n,e.length-n+1,...s),e}function C0(e,t,n){let r=this,i=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]),a=0,o;return s;function s(t){return e.enter(`gfmFootnoteCall`),e.enter(`gfmFootnoteCallLabelMarker`),e.consume(t),e.exit(`gfmFootnoteCallLabelMarker`),c}function c(t){return t===94?(e.enter(`gfmFootnoteCallMarker`),e.consume(t),e.exit(`gfmFootnoteCallMarker`),e.enter(`gfmFootnoteCallString`),e.enter(`chunkString`).contentType=`string`,l):n(t)}function l(s){if(a>999||s===93&&!o||s===null||s===91||yq(s))return n(s);if(s===93){e.exit(`chunkString`);let a=e.exit(`gfmFootnoteCallString`);return i.includes(uq(r.sliceSerialize(a)))?(e.enter(`gfmFootnoteCallLabelMarker`),e.consume(s),e.exit(`gfmFootnoteCallLabelMarker`),e.exit(`gfmFootnoteCall`),t):n(s)}return yq(s)||(o=!0),a++,e.consume(s),s===92?u:l}function u(t){return t===91||t===92||t===93?(e.consume(t),a++,l):l(t)}}function w0(e,t,n){let r=this,i=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]),a,o=0,s;return c;function c(t){return e.enter(`gfmFootnoteDefinition`)._container=!0,e.enter(`gfmFootnoteDefinitionLabel`),e.enter(`gfmFootnoteDefinitionLabelMarker`),e.consume(t),e.exit(`gfmFootnoteDefinitionLabelMarker`),l}function l(t){return t===94?(e.enter(`gfmFootnoteDefinitionMarker`),e.consume(t),e.exit(`gfmFootnoteDefinitionMarker`),e.enter(`gfmFootnoteDefinitionLabelString`),e.enter(`chunkString`).contentType=`string`,u):n(t)}function u(t){if(o>999||t===93&&!s||t===null||t===91||yq(t))return n(t);if(t===93){e.exit(`chunkString`);let n=e.exit(`gfmFootnoteDefinitionLabelString`);return a=uq(r.sliceSerialize(n)),e.enter(`gfmFootnoteDefinitionLabelMarker`),e.consume(t),e.exit(`gfmFootnoteDefinitionLabelMarker`),e.exit(`gfmFootnoteDefinitionLabel`),f}return yq(t)||(s=!0),o++,e.consume(t),t===92?d:u}function d(t){return t===91||t===92||t===93?(e.consume(t),o++,u):u(t)}function f(t){return t===58?(e.enter(`definitionMarker`),e.consume(t),e.exit(`definitionMarker`),i.includes(a)||i.push(a),Tq(e,p,`gfmFootnoteDefinitionWhitespace`)):n(t)}function p(e){return t(e)}}function T0(e,t,n){return e.check(Uq,t,e.attempt(y0,t,n))}function E0(e){e.exit(`gfmFootnoteDefinition`)}function D0(e,t,n){let r=this;return Tq(e,i,`gfmFootnoteDefinitionIndent`,5);function i(e){let i=r.events[r.events.length-1];return i&&i[1].type===`gfmFootnoteDefinitionIndent`&&i[2].sliceSerialize(i[1],!0).length===4?t(e):n(e)}}function O0(e){let t=(e||{}).singleTilde,n={name:`strikethrough`,tokenize:i,resolveAll:r};return t??=!0,{text:{126:n},insideSpan:{null:[n]},attentionMarkers:{null:[126]}};function r(e,t){let n=-1;for(;++n<e.length;)if(e[n][0]===`enter`&&e[n][1].type===`strikethroughSequenceTemporary`&&e[n][1]._close){let r=n;for(;r--;)if(e[r][0]===`exit`&&e[r][1].type===`strikethroughSequenceTemporary`&&e[r][1]._open&&e[n][1].end.offset-e[n][1].start.offset===e[r][1].end.offset-e[r][1].start.offset){e[n][1].type=`strikethroughSequence`,e[r][1].type=`strikethroughSequence`;let i={type:`strikethrough`,start:Object.assign({},e[r][1].start),end:Object.assign({},e[n][1].end)},a={type:`strikethroughText`,start:Object.assign({},e[r][1].end),end:Object.assign({},e[n][1].start)},o=[[`enter`,i,t],[`enter`,e[r][1],t],[`exit`,e[r][1],t],[`enter`,a,t]],s=t.parser.constructs.insideSpan.null;s&&rq(o,o.length,0,Iq(s,e.slice(r+1,n),t)),rq(o,o.length,0,[[`exit`,a,t],[`enter`,e[n][1],t],[`exit`,e[n][1],t],[`exit`,i,t]]),rq(e,r-1,n-r+3,o),n=r+o.length-2;break}}for(n=-1;++n<e.length;)e[n][1].type===`strikethroughSequenceTemporary`&&(e[n][1].type=`data`);return e}function i(e,n,r){let i=this.previous,a=this.events,o=0;return s;function s(t){return i===126&&a[a.length-1][1].type!==`characterEscape`?r(t):(e.enter(`strikethroughSequenceTemporary`),c(t))}function c(a){let s=Fq(i);if(a===126)return o>1?r(a):(e.consume(a),o++,c);if(o<2&&!t)return r(a);let l=e.exit(`strikethroughSequenceTemporary`),u=Fq(a);return l._open=!u||u===2&&!!s,l._close=!s||s===2&&!!u,n(a)}}}var k0=class{constructor(){this.map=[],this.index=new Map}add(e,t,n){A0(this,e,t,n)}consume(e){if(this.map.sort(function(e,t){return e[0]-t[0]}),this.map.length===0)return;let t=this.map.length,n=[];for(;t>0;)--t,n.push(e.slice(this.map[t][0]+this.map[t][1]),this.map[t][2]),e.length=this.map[t][0];n.push(e.slice()),e.length=0;let r=n.pop();for(;r;){for(let t of r)e.push(t);r=n.pop()}this.map.length=0,this.index.clear()}};function A0(e,t,n,r){if(n===0&&r.length===0)return;let i=e.index.get(t);if(i){i[1]+=n,i[2].push(...r);return}let a=[t,n,r];e.map.push(a),e.index.set(t,a)}function j0(e,t){let n=!1,r=[];for(;t<e.length;){let i=e[t];if(n){if(i[0]===`enter`)i[1].type===`tableContent`&&r.push(e[t+1][1].type===`tableDelimiterMarker`?`left`:`none`);else if(i[1].type===`tableContent`){if(e[t-1][1].type===`tableDelimiterMarker`){let e=r.length-1;r[e]=r[e]===`left`?`center`:`right`}}else if(i[1].type===`tableDelimiterRow`)break}else i[0]===`enter`&&i[1].type===`tableDelimiterRow`&&(n=!0);t+=1}return r}function M0(){return{flow:{null:{name:`table`,tokenize:N0,resolveAll:P0}}}}function N0(e,t,n){let r=this,i=0,a=0,o;return s;function s(e){let t=r.events.length-1;for(;t>-1;){let{type:e}=r.events[t][1];if(e===`lineEnding`||e===`linePrefix`)t--;else break}let i=t>-1?r.events[t][1].type:null,a=i===`tableHead`||i===`tableRow`?S:c;return a===S&&r.parser.lazy[r.now().line]?n(e):a(e)}function c(t){return e.enter(`tableHead`),e.enter(`tableRow`),l(t)}function l(e){return e===124||(o=!0,a+=1),u(e)}function u(t){return t===null?n(t):vq(t)?a>1?(a=0,r.interrupt=!0,e.exit(`tableRow`),e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),p):n(t):bq(t)?Tq(e,u,`whitespace`)(t):(a+=1,o&&(o=!1,i+=1),t===124?(e.enter(`tableCellDivider`),e.consume(t),e.exit(`tableCellDivider`),o=!0,u):(e.enter(`data`),d(t)))}function d(t){return t===null||t===124||yq(t)?(e.exit(`data`),u(t)):(e.consume(t),t===92?f:d)}function f(t){return t===92||t===124?(e.consume(t),d):d(t)}function p(t){return r.interrupt=!1,r.parser.lazy[r.now().line]?n(t):(e.enter(`tableDelimiterRow`),o=!1,bq(t)?Tq(e,m,`linePrefix`,r.parser.constructs.disable.null.includes(`codeIndented`)?void 0:4)(t):m(t))}function m(t){return t===45||t===58?g(t):t===124?(o=!0,e.enter(`tableCellDivider`),e.consume(t),e.exit(`tableCellDivider`),h):x(t)}function h(t){return bq(t)?Tq(e,g,`whitespace`)(t):g(t)}function g(t){return t===58?(a+=1,o=!0,e.enter(`tableDelimiterMarker`),e.consume(t),e.exit(`tableDelimiterMarker`),_):t===45?(a+=1,_(t)):t===null||vq(t)?b(t):x(t)}function _(t){return t===45?(e.enter(`tableDelimiterFiller`),v(t)):x(t)}function v(t){return t===45?(e.consume(t),v):t===58?(o=!0,e.exit(`tableDelimiterFiller`),e.enter(`tableDelimiterMarker`),e.consume(t),e.exit(`tableDelimiterMarker`),y):(e.exit(`tableDelimiterFiller`),y(t))}function y(t){return bq(t)?Tq(e,b,`whitespace`)(t):b(t)}function b(n){return n===124?m(n):n===null||vq(n)?!o||i!==a?x(n):(e.exit(`tableDelimiterRow`),e.exit(`tableHead`),t(n)):x(n)}function x(e){return n(e)}function S(t){return e.enter(`tableRow`),C(t)}function C(n){return n===124?(e.enter(`tableCellDivider`),e.consume(n),e.exit(`tableCellDivider`),C):n===null||vq(n)?(e.exit(`tableRow`),t(n)):bq(n)?Tq(e,C,`whitespace`)(n):(e.enter(`data`),w(n))}function w(t){return t===null||t===124||yq(t)?(e.exit(`data`),C(t)):(e.consume(t),t===92?T:w)}function T(t){return t===92||t===124?(e.consume(t),w):w(t)}}function P0(e,t){let n=-1,r=!0,i=0,a=[0,0,0,0],o=[0,0,0,0],s=!1,c=0,l,u,d,f=new k0;for(;++n<e.length;){let p=e[n],m=p[1];p[0]===`enter`?m.type===`tableHead`?(s=!1,c!==0&&(I0(f,t,c,l,u),u=void 0,c=0),l={type:`table`,start:Object.assign({},m.start),end:Object.assign({},m.end)},f.add(n,0,[[`enter`,l,t]])):m.type===`tableRow`||m.type===`tableDelimiterRow`?(r=!0,d=void 0,a=[0,0,0,0],o=[0,n+1,0,0],s&&(s=!1,u={type:`tableBody`,start:Object.assign({},m.start),end:Object.assign({},m.end)},f.add(n,0,[[`enter`,u,t]])),i=m.type===`tableDelimiterRow`?2:u?3:1):i&&(m.type===`data`||m.type===`tableDelimiterMarker`||m.type===`tableDelimiterFiller`)?(r=!1,o[2]===0&&(a[1]!==0&&(o[0]=o[1],d=F0(f,t,a,i,void 0,d),a=[0,0,0,0]),o[2]=n)):m.type===`tableCellDivider`&&(r?r=!1:(a[1]!==0&&(o[0]=o[1],d=F0(f,t,a,i,void 0,d)),a=o,o=[a[1],n,0,0])):m.type===`tableHead`?(s=!0,c=n):m.type===`tableRow`||m.type===`tableDelimiterRow`?(c=n,a[1]===0?o[1]!==0&&(d=F0(f,t,o,i,n,d)):(o[0]=o[1],d=F0(f,t,a,i,n,d)),i=0):i&&(m.type===`data`||m.type===`tableDelimiterMarker`||m.type===`tableDelimiterFiller`)&&(o[3]=n)}for(c!==0&&I0(f,t,c,l,u),f.consume(t.events),n=-1;++n<t.events.length;){let e=t.events[n];e[0]===`enter`&&e[1].type===`table`&&(e[1]._align=j0(t.events,n))}return e}function F0(e,t,n,r,i,a){let o=r===1?`tableHeader`:r===2?`tableDelimiter`:`tableData`;n[0]!==0&&(a.end=Object.assign({},L0(t.events,n[0])),e.add(n[0],0,[[`exit`,a,t]]));let s=L0(t.events,n[1]);if(a={type:o,start:Object.assign({},s),end:Object.assign({},s)},e.add(n[1],0,[[`enter`,a,t]]),n[2]!==0){let i=L0(t.events,n[2]),a=L0(t.events,n[3]),o={type:`tableContent`,start:Object.assign({},i),end:Object.assign({},a)};if(e.add(n[2],0,[[`enter`,o,t]]),r!==2){let r=t.events[n[2]],i=t.events[n[3]];if(r[1].end=Object.assign({},i[1].end),r[1].type=`chunkText`,r[1].contentType=`text`,n[3]>n[2]+1){let t=n[2]+1,r=n[3]-n[2]-1;e.add(t,r,[])}}e.add(n[3]+1,0,[[`exit`,o,t]])}return i!==void 0&&(a.end=Object.assign({},L0(t.events,i)),e.add(i,0,[[`exit`,a,t]]),a=void 0),a}function I0(e,t,n,r,i){let a=[],o=L0(t.events,n);i&&(i.end=Object.assign({},o),a.push([`exit`,i,t])),r.end=Object.assign({},o),a.push([`exit`,r,t]),e.add(n+1,0,a)}function L0(e,t){let n=e[t],r=n[0]===`enter`?`start`:`end`;return n[1][r]}var R0={name:`tasklistCheck`,tokenize:B0};function z0(){return{text:{91:R0}}}function B0(e,t,n){let r=this;return i;function i(t){return r.previous!==null||!r._gfmTasklistFirstContentOfListItem?n(t):(e.enter(`taskListCheck`),e.enter(`taskListCheckMarker`),e.consume(t),e.exit(`taskListCheckMarker`),a)}function a(t){return yq(t)?(e.enter(`taskListCheckValueUnchecked`),e.consume(t),e.exit(`taskListCheckValueUnchecked`),o):t===88||t===120?(e.enter(`taskListCheckValueChecked`),e.consume(t),e.exit(`taskListCheckValueChecked`),o):n(t)}function o(t){return t===93?(e.enter(`taskListCheckMarker`),e.consume(t),e.exit(`taskListCheckMarker`),e.exit(`taskListCheck`),s):n(t)}function s(r){return vq(r)?t(r):bq(r)?e.check({tokenize:V0},t,n)(r):n(r)}}function V0(e,t,n){return Tq(e,r,`whitespace`);function r(e){return e===null?n(e):t(e)}}function H0(e){return oq([i0(),b0(),O0(e),M0(),z0()])}var U0={};function W0(e){let t=this,n=e||U0,r=t.data(),i=r.micromarkExtensions||=[],a=r.fromMarkdownExtensions||=[],o=r.toMarkdownExtensions||=[];i.push(H0(n)),a.push(q1()),o.push(J1(n))}var G0=({copiedDuration:e=3e3}={})=>{let[t,n]=(0,f.useState)(!1),r=(0,f.useRef)(void 0),i=(0,f.useRef)(0);return(0,f.useEffect)(()=>()=>{i.current+=1,r.current!==void 0&&(clearTimeout(r.current),r.current=void 0,n(!1))},[]),{isCopied:t,copyToClipboard:t=>{if(!t||typeof navigator>`u`||!navigator.clipboard)return;let a=i.current;navigator.clipboard.writeText(t).then(()=>{a===i.current&&(r.current!==void 0&&clearTimeout(r.current),n(!0),r.current=setTimeout(()=>{r.current=void 0,n(!1)},e))},()=>{})}}},K0=e=>{let t=(0,f.useRef)(e);if(e!==t.current){let n=t.current;e!==void 0&&n!==void 0&&Object.keys(n).length===Object.keys(e).length&&Object.keys(e).every(t=>n[t]===e[t])||(t.current=e)}return t.current},q0=({className:e,children:t,...n})=>{let r=HW(),i=/\blanguage-mine\b/.test(e??``)||!e,a=String(t??``).replace(/\n$/,``),[o,s]=(0,f.useState)(null);(0,f.useEffect)(()=>{if(!r||!i)return;let e=!1;return uN(a).then(t=>{e||s({code:a,html:t})}).catch(e=>{console.error(`[Markdown] Monaco 高亮失败:`,e)}),()=>{e=!0}},[a,r,i]);let c=Q(`font-mono`,r?`text-inherit`:Q(`aui-md-inline-code`,`rounded-md border border-border/60`,`bg-muted px-1.5 py-0.5`,`text-[0.85em] text-foreground`),e);if(!r||!i)return(0,J.jsx)(`code`,{className:c,...n,children:t});let l=o?.code===a?o.html:null;return l===null?(0,J.jsx)(`code`,{className:c,...n,children:t}):(0,J.jsx)(`code`,{className:c,...n,dangerouslySetInnerHTML:{__html:l}})},J0=(0,f.memo)(({components:e,componentsByLanguage:t})=>{let n=K0(e),r=K0(t),i=(0,f.useMemo)(()=>n?{...Y0,...BW(n)}:Y0,[n]);return(0,J.jsx)(TQ,{remarkPlugins:[W0],className:Q(`aui-md`,`min-w-0 break-words`,`text-[15px] leading-[1.75] text-foreground`,`[&_img]:max-w-full`,`[&_svg]:max-w-full`),components:i,componentsByLanguage:r,defer:!0})}),Y0=BW({h1:({className:e,...t})=>(0,J.jsx)(`h1`,{className:Q(`aui-md-h1`,`mt-7 mb-3 scroll-m-20`,`text-2xl font-semibold tracking-tight`,`leading-tight text-foreground`,`first:mt-0 last:mb-0`,e),...t}),h2:({className:e,...t})=>(0,J.jsx)(`h2`,{className:Q(`aui-md-h2`,`mt-6 mb-3 scroll-m-20`,`text-xl font-semibold tracking-tight`,`leading-snug text-foreground`,`first:mt-0 last:mb-0`,e),...t}),h3:({className:e,...t})=>(0,J.jsx)(`h3`,{className:Q(`aui-md-h3`,`mt-5 mb-2 scroll-m-20`,`text-lg font-semibold`,`leading-snug text-foreground`,`first:mt-0 last:mb-0`,e),...t}),h4:({className:e,...t})=>(0,J.jsx)(`h4`,{className:Q(`aui-md-h4`,`mt-4 mb-2 scroll-m-20`,`text-base font-semibold text-foreground`,`first:mt-0 last:mb-0`,e),...t}),h5:({className:e,...t})=>(0,J.jsx)(`h5`,{className:Q(`aui-md-h5`,`mt-3 mb-1`,`text-sm font-semibold text-foreground`,`first:mt-0 last:mb-0`,e),...t}),h6:({className:e,...t})=>(0,J.jsx)(`h6`,{className:Q(`aui-md-h6`,`mt-3 mb-1`,`text-sm font-medium text-muted-foreground`,`first:mt-0 last:mb-0`,e),...t}),p:({className:e,...t})=>(0,J.jsx)(`p`,{className:Q(`aui-md-p`,`my-3`,`text-[15px] leading-[1.75] text-foreground`,`first:mt-0 last:mb-0`,e),...t}),a:({className:e,...t})=>(0,J.jsx)(`a`,{className:Q(`aui-md-a`,`text-primary underline decoration-primary/40`,`underline-offset-4 transition-colors`,`hover:decoration-primary`,e),...t}),blockquote:({className:e,...t})=>(0,J.jsx)(`blockquote`,{className:Q(`aui-md-blockquote`,`my-4 border-s-2 border-border ps-4`,`text-muted-foreground`,`[&>p]:my-1`,e),...t}),ul:({className:e,...t})=>(0,J.jsx)(`ul`,{className:Q(`aui-md-ul`,`my-3 ms-6 list-disc`,`space-y-1`,`marker:text-muted-foreground`,`[&_ul]:my-1`,e),...t}),ol:({className:e,...t})=>(0,J.jsx)(`ol`,{className:Q(`aui-md-ol`,`my-3 ms-6 list-decimal`,`space-y-1`,`marker:text-muted-foreground`,`[&_ol]:my-1`,e),...t}),hr:({className:e,...t})=>(0,J.jsx)(`hr`,{className:Q(`aui-md-hr`,`my-6 border-0 border-t border-border`,e),...t}),table:({className:e,...t})=>(0,J.jsx)(`div`,{className:`aui-md-table-wrapper my-4 w-full overflow-x-auto rounded-lg border border-border`,children:(0,J.jsx)(`table`,{className:Q(`aui-md-table`,`w-full border-collapse text-sm`,e),...t})}),th:({className:e,...t})=>(0,J.jsx)(`th`,{className:Q(`aui-md-th`,`border-b border-border`,`bg-muted/60 px-3 py-2.5`,`text-start text-sm font-semibold text-foreground`,`[[align=center]]:text-center`,`[[align=right]]:text-right`,e),...t}),td:({className:e,...t})=>(0,J.jsx)(`td`,{className:Q(`aui-md-td`,`border-b border-border/70`,`px-3 py-2.5`,`text-start text-foreground`,`[[align=center]]:text-center`,`[[align=right]]:text-right`,e),...t}),tr:({className:e,...t})=>(0,J.jsx)(`tr`,{className:Q(`aui-md-tr`,`transition-colors`,`last:[&>td]:border-b-0`,`hover:bg-muted/30`,e),...t}),li:({className:e,...t})=>(0,J.jsx)(`li`,{className:Q(`aui-md-li`,`ps-0 leading-[1.75] text-foreground`,`[&>p]:my-1`,e),...t}),strong:({className:e,...t})=>(0,J.jsx)(`strong`,{className:Q(`aui-md-strong`,`font-semibold text-foreground`,e),...t}),sup:({className:e,...t})=>(0,J.jsx)(`sup`,{className:Q(`aui-md-sup`,`text-muted-foreground`,`[&>a]:text-xs [&>a]:no-underline`,e),...t}),pre:({className:e,...t})=>(0,J.jsx)(`pre`,{className:Q(`aui-md-pre`,`my-0 overflow-x-auto`,`rounded-b-xl border border-border`,`bg-[#f4f4f4] px-4 py-4`,`font-mono text-[13px] leading-6`,`text-[#242424]`,`dark:bg-[#2f2f2f] dark:text-[#ededed]`,`[&>code]:bg-transparent`,`[&>code]:p-0`,`[&>code]:text-inherit`,`[&>code]:border-0`,e),...t}),code:q0,CodeHeader:({language:e,code:t})=>{let{isCopied:n,copyToClipboard:r}=G0();return(0,J.jsxs)(`div`,{className:Q(`aui-code-header-root`,`mt-4 flex items-center justify-between`,`rounded-t-xl border border-b-0 border-border`,`bg-[#f4f4f4] px-4 py-2`,`dark:bg-[#2f2f2f]`,`text-xs`),children:[(0,J.jsx)(`span`,{className:`aui-code-header-language font-medium text-muted-foreground`,children:e||`code`}),(0,J.jsx)(SU,{tooltip:n?`已复制`:`复制代码`,onClick:()=>{t&&!n&&r(t)},className:Q(`size-7 rounded-md`,`text-muted-foreground`,`hover:bg-black/5 hover:text-foreground`,`dark:hover:bg-white/10`),children:n?(0,J.jsx)(BN,{className:`size-4`}):(0,J.jsx)(eP,{className:`size-4`})})]})}});function X0({controlled:e,default:t,name:n,state:r=`value`}){let{current:i}=f.useRef(e!==void 0),[a,o]=f.useState(()=>t),s=i&&e!==void 0?e:a;if(process.env.NODE_ENV!==`production`){f.useEffect(()=>{i!==(e!==void 0)&&dH([`A component is changing the ${i?``:`un`}controlled ${r} state of ${n} to be ${i?`un`:``}controlled.`,`Elements should not switch from uncontrolled to controlled (or vice versa).`,`Decide between using a controlled or uncontrolled ${n} element for the lifetime of the component.`,"The nature of the state is determined during the first render. It's considered controlled if the value is not `undefined`.",`More info: https://fb.me/react-controlled-components`].join(`
|
|
92
|
+
`))},[r,n,e]);let{current:a}=f.useRef(t);f.useEffect(()=>{!i&&Z0(a)!==Z0(t)&&dH([`A component is changing the default ${r} state of an uncontrolled ${n} after being initialized. To suppress this warning opt to use a controlled ${n}.`].join(`
|
|
93
|
+
`))},[t])}return[s,f.useCallback(e=>{i||o(e)},[])]}function Z0(e){let t=0,n=new WeakMap;try{return JSON.stringify(e,function(e,r){if(!(e===`_owner`&&this!=null&&typeof this==`object`&&`$$typeof`in this)){if(typeof r==`bigint`)return`__bigint__:${r}`;if(typeof r==`object`&&r){let e=n.get(r);if(e!==void 0)return`__object__:${e}`;n.set(r,t),t+=1}return r}})??`__top__:${typeof e}`}catch{return`__unserializable__`}}function Q0(e){let{open:t,defaultOpen:n=!1,onOpenChange:r,disabled:i}=e,[a,o]=X0({controlled:t,default:n,name:`Collapsible`,state:`open`}),{mounted:s,setMounted:c,transitionStatus:l}=cz(a,!0,!0),u=DB(),[d,p]=f.useState(),m=d===null?void 0:d??u,h=qI(e=>{let t=!a,n=yI(xI,e.nativeEvent);r(t,n),n.isCanceled||o(t)});return f.useMemo(()=>({defaultPanelId:u,disabled:i,handleTrigger:h,mounted:s,open:a,panelId:m,setMounted:c,setOpen:o,setPanelIdState:p,transitionStatus:l}),[u,i,h,s,a,m,c,o,p,l])}var $0=f.createContext(void 0);process.env.NODE_ENV!==`production`&&($0.displayName=`CollapsibleRootContext`);function e2(){let e=f.useContext($0);if(e===void 0)throw Error(process.env.NODE_ENV===`production`?dF(15):`Base UI: CollapsibleRootContext is missing. Collapsible parts must be placed within <Collapsible.Root>.`);return e}var t2=`data-open`,n2=`data-closed`,r2=WF,i2=`data-panel-open`,a2={[t2]:``},o2={[n2]:``},s2={open(e){return e?{[i2]:``}:null}},c2={open(e){return e?a2:o2},...JF},l2=f.forwardRef(function(e,t){let{render:n,className:r,defaultOpen:i=!1,disabled:a=!1,onOpenChange:o,open:s,style:c,...l}=e,u=qI(o),d=Q0({open:s,defaultOpen:i,onOpenChange:u,disabled:a}),p=f.useMemo(()=>({open:d.open,disabled:d.disabled,transitionStatus:d.transitionStatus}),[d.open,d.disabled,d.transitionStatus]),m=f.useMemo(()=>({...d,onOpenChange:u,state:p}),[d,u,p]),h=bR(`div`,e,{state:p,ref:t,props:l,stateAttributesMapping:c2});return(0,J.jsx)($0.Provider,{value:m,children:h})});process.env.NODE_ENV!==`production`&&(l2.displayName=`CollapsibleRoot`);var u2={...s2,...JF},d2=f.forwardRef(function(e,t){let{panelId:n,open:r,handleTrigger:i,state:a,disabled:o}=e2(),{className:s,disabled:c=o,render:l,nativeButton:u=!0,style:d,...f}=e,{getButtonProps:p,buttonRef:m}=gH({disabled:c,native:u});return bR(`button`,e,{state:a,ref:[t,m],props:[{"aria-controls":r?n:void 0,"aria-expanded":r,onClick:i},f,p],stateAttributesMapping:u2})});process.env.NODE_ENV!==`production`&&(d2.displayName=`CollapsibleTrigger`);var f2={height:void 0,width:void 0};function p2(e){let{externalRef:t,hiddenUntilFound:n,id:r,keepMounted:i,mounted:a,onOpenChange:o,open:s,setMounted:c,setOpen:l,transitionStatus:u}=e,d=f.useRef(null),p=f.useRef(null),[m,h]=f.useState(f2),g=f.useRef(f2),_=f.useRef(!1),v=f.useRef(s),y=f.useRef(!1),[b,x]=f.useState(!1),S=f.useRef(null),C=II(t,d),w=HI(s),T=fz(d),E=!s&&!a,D=b?`idle`:u,O=s&&(v.current||y.current),k=!s&&a&&p.current===`css-animation`&&m.height===void 0&&m.width===void 0?g.current:m,A=n&&E&&p.current!==`css-animation`,j=qI((e,t=!0)=>{t&&(g.current=e),h(e)}),M=qI(()=>{S.current?.(),S.current=null}),N=qI(e=>{M(),S.current=()=>{S.current=null,e()}}),P=qI(()=>{s&&a&&p.current===`css-animation`&&(y.current=!0)});lF(()=>{b&&u!==`starting`&&x(!1)},[b,u]),f.useEffect(()=>()=>{P(),M()},[P,M]),lF(()=>{s||(v.current=!1,y.current=!1);let e=d.current;if(!e)return;!s&&S.current&&M();let t=h2(e,O);if(p.current=t,s&&u===`idle`&&v.current&&t===`css-animation`){g.current=m2(e);return}if(s&&u===`starting`){let n=_.current;if(_.current=!1,t===`none`){j(m2(e)),x(!0);return}if(t===`css-transition`){let t=v2(e);if(j(m2(e)),!n)return t;let r=_2(e,`transition-duration`,`0s`);return N(r),x(!0),t}j(m2(e));let r=_2(e,`animation-name`,`none`);if(!n){r();return}let i=_2(e,`animation-duration`,`0s`);r(),N(i),x(!0);return}if(!s&&a&&(u===`idle`||u===`starting`)){if(t===`none`){j(f2,!1),c(!1);return}j(m2(e));return}if(u!==`ending`)return;if(t===`none`){c(!1);return}let n=m2(e);n.height>0||n.width>0?(j(n),t===`css-animation`&&_2(e,`animation-name`,`none`)()):c(!1)},[a,s,M,j,c,N,O,u]),pz({enabled:s&&a&&D===`idle`,open:!0,ref:d,onComplete(){s&&j(f2,!1)}}),f.useEffect(()=>{if(s||!a||D!==`ending`)return;if(!d.current){c(!1),j(f2,!1);return}let e=new AbortController,t=-1;function n(){w.current||(c(!1),j(f2,!1))}return t=$I.request(()=>{T(n,e.signal)}),()=>{$I.cancel(t),e.abort()}},[w,a,s,D,T,j,c]),lF(()=>{let e=d.current;e&&n&&E&&e.setAttribute(`hidden`,`until-found`)},[E,n]),f.useEffect(function(){let e=d.current;if(!e)return;let t=gF.create(),n=-1,r=(r,i)=>{t.start(0,()=>{w.current||(n=$I.request(()=>{w.current||(r&&(_.current=!1),i&&e.setAttribute(r2,``),e.setAttribute(`hidden`,`until-found`))}))})},i=PI(e,`beforematch`,t=>{let n=yI(bI,t);if(o(!0,n),n.isCanceled){r(!1,!1);return}_.current=!0;let i=e.hasAttribute(r2);e.removeAttribute(r2),l(!0),r(!0,i)});return()=>{t.clear(),$I.cancel(n),i()}},[w,o,l]);let F=i||n||a||s;return{height:k.height,props:{...A?{[r2]:``}:void 0,hidden:E,id:r},ref:C,shouldPreventOpenAnimation:O,shouldRender:F,transitionStatus:D,width:k.width}}function m2(e){return{height:e.scrollHeight,width:e.scrollWidth}}function h2(e,t){let n=wx(e).getComputedStyle(e),r=(n.animationName.split(`,`).map(e=>e.trim()).some(e=>e!==``&&e!==`none`)||t)&&g2(n.animationDuration),i=g2(n.transitionDuration);return r&&i?(process.env.NODE_ENV!==`production`&&nR(`CSS transitions and CSS animations both detected on Collapsible or Accordion panel.`,`Only one of either animation type should be used.`),`css-transition`):i?`css-transition`:r?`css-animation`:`none`}function g2(e){return e.split(`,`).map(e=>e.trim()).some(e=>e!==``&&Number.parseFloat(e)>0)}function _2(e,t,n){let r=e.style.getPropertyValue(t),i=e.style.getPropertyPriority(t);return e.style.setProperty(t,n),()=>{r===``?e.style.removeProperty(t):e.style.setProperty(t,r,i)}}function v2(e){let t={"justify-content":e.style.justifyContent,"align-items":e.style.alignItems,"align-content":e.style.alignContent,"justify-items":e.style.justifyItems};Object.keys(t).forEach(t=>{e.style.setProperty(t,`initial`,`important`)});function n(){Object.entries(t).forEach(([t,n])=>{n===``?e.style.removeProperty(t):e.style.setProperty(t,n)})}let r=$I.request(n);return()=>{$I.cancel(r),n()}}var y2=`--collapsible-panel-height`,b2=`--collapsible-panel-width`,x2=f.forwardRef(function(e,t){let{className:n,hiddenUntilFound:r,keepMounted:i,render:a,id:o,style:s,...c}=e;process.env.NODE_ENV!==`production`&&f.useEffect(()=>{r&&i===!1&&nR("The `keepMounted={false}` prop on `Collapsible.Panel` is ignored when `hiddenUntilFound` is enabled, since the panel must remain mounted while closed.")},[r,i]);let{defaultPanelId:l,mounted:u,onOpenChange:d,open:p,setMounted:m,setPanelIdState:h,setOpen:g,state:_,transitionStatus:v}=e2(),y=r??!1,b=i??!1,x=o||void 0,S=x??l;lF(()=>(h(e=>x??(e===null?void 0:e)),()=>{h(e=>e===x?null:e)}),[x,h]);let{height:C,props:w,ref:T,shouldPreventOpenAnimation:E,shouldRender:D,transitionStatus:O,width:k}=p2({externalRef:t,hiddenUntilFound:y,id:S,keepMounted:b,mounted:u,onOpenChange:d,open:p,setMounted:m,setOpen:g,transitionStatus:v}),A={..._,transitionStatus:O},j=aR(s,A),M=bR(`div`,{...e,style:void 0},{state:A,ref:T,props:[w,{style:{[y2]:C===void 0?`auto`:`${C}px`,[b2]:k===void 0?`auto`:`${k}px`}},c,j?{style:j}:void 0,E?{style:{animationName:`none`}}:void 0],stateAttributesMapping:c2});return D?M:null});process.env.NODE_ENV!==`production`&&(x2.displayName=`CollapsiblePanel`);var S2=(0,f.forwardRef)(function(e,t){return(0,J.jsx)(l2,{ref:t,"data-slot":`collapsible`,...e})});function C2({...e}){return(0,J.jsx)(d2,{"data-slot":`collapsible-trigger`,...e})}function w2({...e}){return(0,J.jsx)(x2,{"data-slot":`collapsible-content`,...e})}var T2=(0,f.createContext)({isPreview:!1,showContent:!0}),E2=nU(`aui-reasoning-root mb-0 w-full`,{variants:{variant:{outline:`rounded-lg px-0 py-2`,ghost:``,muted:`bg-muted/50 rounded-lg px-3 py-2`}},defaultVariants:{variant:`outline`}}),D2=(0,f.forwardRef)(function({className:e,variant:t,open:n,onOpenChange:r,defaultOpen:i=!1,streaming:a,showContent:o=!0,onAnimationStart:s,style:c,children:l,...u},d){let[p]=(0,f.useState)(i),[m,h]=(0,f.useState)(null),g=n!==void 0,_=g?n:m??(a||p),v=a===!0&&_,y=(0,f.useRef)(a);BU(()=>{y.current!==a&&(y.current=a,!g&&m===null&&!p&&s?.())},[a,g,m,p,s]);let b=(0,f.useCallback)(e=>{s?.(),g||h(e),r?.(e)},[s,g,r]),x={isPreview:o&&v,showContent:o};return o?(0,J.jsx)(S2,{ref:d,"data-slot":`reasoning-root`,"data-variant":t,open:_,onOpenChange:b,className:Q(`group/reasoning-root`,E2({variant:t,className:e})),style:{"--animation-duration":`200ms`,...typeof c==`object`&&c||{}},...u,children:(0,J.jsx)(T2.Provider,{value:x,children:l})}):(0,J.jsx)(`div`,{ref:d,"data-slot":`reasoning-root`,"data-variant":t,className:Q(`group/reasoning-root`,E2({variant:t,className:e})),style:typeof c==`function`?void 0:c,...u,children:(0,J.jsx)(T2.Provider,{value:x,children:l})})});function O2({side:e=`bottom`,className:t,...n}){return e===`top`?(0,J.jsx)(`div`,{"data-slot":`reasoning-fade`,className:Q(`aui-reasoning-fade pointer-events-none absolute inset-x-0 top-0 z-10 h-8`,`bg-[linear-gradient(to_bottom,var(--color-background),transparent)]`,`group-data-[variant=muted]/reasoning-root:bg-[linear-gradient(to_bottom,color-mix(in_oklab,var(--color-muted)_50%,var(--color-background)),transparent)]`,`fade-in-0 animate-in`,`animation-duration-(--animation-duration)`,t),...n}):(0,J.jsx)(`div`,{"data-slot":`reasoning-fade`,className:Q(`aui-reasoning-fade pointer-events-none absolute inset-x-0 bottom-0 z-10 h-8`,`bg-[linear-gradient(to_top,var(--color-background),transparent)]`,`group-data-[variant=muted]/reasoning-root:bg-[linear-gradient(to_top,color-mix(in_oklab,var(--color-muted)_50%,var(--color-background)),transparent)]`,`fade-in-0 animate-in`,`animation-duration-(--animation-duration)`,t),...n})}function k2({active:e,duration:t,className:n,...r}){let{showContent:i}=(0,f.useContext)(T2),a=e?`正在思考...`:t===void 0?`思考过程`:`思考了 ${t} 秒`,o=Q(`aui-reasoning-trigger flex max-w-[75%] origin-left items-center gap-2 py-1.5 text-sm text-muted-foreground`,e&&i&&`hover:text-foreground transition-colors active:scale-[0.98]`,n),s=(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(RN,{"data-slot":`reasoning-trigger-icon`,className:`aui-reasoning-trigger-icon size-4 shrink-0`}),(0,J.jsx)(`span`,{"data-slot":`reasoning-trigger-label`,className:Q(`aui-reasoning-trigger-label-wrapper inline-block leading-none tabular-nums`,e&&`shimmer motion-reduce:animate-none`),children:a})]});return!i||!e?(0,J.jsx)(`div`,{"data-slot":`reasoning-trigger`,className:o,children:s}):(0,J.jsx)(C2,{"data-slot":`reasoning-trigger`,className:o,...r,children:s})}function A2({className:e,children:t,...n}){let{showContent:r}=(0,f.useContext)(T2);return r?(0,J.jsx)(w2,{"data-slot":`reasoning-content`,className:Q(`aui-reasoning-content relative overflow-hidden text-sm text-muted-foreground outline-none`,`group/collapsible-content ease-[cubic-bezier(0.32,0.72,0,1)] motion-reduce:animate-none`,`data-closed:animate-collapsible-up`,`data-open:animate-collapsible-down`,`data-closed:fill-mode-forwards`,`data-closed:pointer-events-none`,`[--tw-duration:var(--animation-duration)]`,e),...n,children:t}):null}function j2({className:e,children:t,...n}){let{showContent:r}=(0,f.useContext)(T2);return r?(0,J.jsx)(`div`,{"data-slot":`reasoning-text`,className:Q(`aui-reasoning-text relative z-0 max-h-64 overflow-y-auto ps-6 pt-2 pb-2 leading-relaxed text-pretty`,`motion-reduce:animate-none`,e),...n,children:(0,J.jsx)(`div`,{className:`aui-reasoning-text-content space-y-4`,children:t})}):null}var M2=(0,f.forwardRef)(function({onAnimationStart:e,...t},n){let r=(0,f.useRef)(null),i=MM(r,200),a=(0,f.useCallback)(()=>{i(),e?.()},[i,e]),o=(0,f.useCallback)(e=>{if(r.current=e,typeof n==`function`){let t=n(e);if(typeof t==`function`)return()=>{r.current=null,t()}}else n&&(n.current=e)},[n]);return(0,J.jsx)(D2,{ref:o,onAnimationStart:a,...t})}),N2=()=>(0,J.jsx)(J0,{}),P2=({children:e,startIndex:t,endIndex:n})=>{let r=q(e=>{if(e.message.status?.type!==`running`)return!1;for(let r=t;r<=n;r++)if(e.message.parts[r]?.status.type===`running`)return!0;return!1});return(0,J.jsxs)(M2,{streaming:r,showContent:!1,children:[(0,J.jsx)(k2,{active:r}),(0,J.jsx)(A2,{"aria-busy":r,"aria-label":`AI 思考过程`,children:(0,J.jsx)(j2,{children:e})})]})},F2=(0,f.memo)(N2);F2.displayName=`Reasoning`,F2.Root=M2,F2.Trigger=k2,F2.Content=A2,F2.Text=j2,F2.Fade=O2;var I2=(0,f.memo)(P2);I2.displayName=`ReasoningGroup`;function L2({className:e,...t}){return(0,J.jsx)(`textarea`,{"data-slot":`textarea`,className:Q(`flex field-sizing-content min-h-16 w-full rounded-lg border border-input bg-transparent px-2.5 py-2 text-base transition-colors outline-none placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:bg-input/50 disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 md:text-sm dark:bg-input/30 dark:disabled:bg-input/80 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40`,e),...t})}var R2=200,z2=`active:scale-[0.98]`;function B2({className:e,open:t,onOpenChange:n,defaultOpen:r=!1,children:i,...a}){let o=(0,f.useRef)(null),[s,c]=(0,f.useState)(r),l=MM(o,R2),u=t!==void 0,d=u?t:s,p=(0,f.useCallback)(e=>{l(),u||c(e),n?.(e)},[l,u,n]);return(0,J.jsx)(S2,{ref:o,"data-slot":`tool-fallback-root`,open:d,onOpenChange:p,className:Q(`aui-tool-fallback-root group/tool-fallback-root w-full`,e),style:{"--animation-duration":`${R2}ms`},...a,children:i})}var V2={running:vP,complete:BN,incomplete:QN,"requires-action":JN},H2=e=>{if(e<1e3)return`<1秒`;let t=e/1e3;return t<10?`${(Math.floor(t*10)/10).toFixed(1)}秒`:t<60?`${Math.floor(t)}秒`:`${Math.floor(t/60)}分 ${Math.floor(t%60)}秒`};function U2({className:e,...t}){let n=Dv();return n===void 0?null:(0,J.jsx)(`span`,{"data-slot":`tool-fallback-duration`,className:Q(`aui-tool-fallback-duration text-muted-foreground text-xs tabular-nums`,e),...t,children:H2(n)})}function W2({toolName:e,status:t,responseDeliveryStatus:n,className:r,...i}){let a=t?.type??`complete`,o=a===`running`,s=t?.type===`incomplete`&&t.reason===`cancelled`,c=V2[a],l=n===`queued`?`回复已排队,尚未发送`:a===`running`?`正在执行工具`:a===`requires-action`?`等待工具操作`:a===`incomplete`?s?`已取消工具调用`:`工具执行失败`:`已调用工具`;return(0,J.jsxs)(C2,{"data-slot":`tool-fallback-trigger`,className:Q(`aui-tool-fallback-trigger group/trigger text-muted-foreground hover:text-foreground flex w-fit max-w-full origin-left items-center gap-2 py-1.5 text-sm transition-[color,scale] active:scale-[0.98]`,r),...i,children:[(0,J.jsx)(c,{"data-slot":`tool-fallback-trigger-icon`,className:Q(`aui-tool-fallback-trigger-icon size-4 shrink-0`,s&&`text-muted-foreground`,o&&`animate-spin [animation-duration:0.6s]`)}),(0,J.jsxs)(`span`,{"data-slot":`tool-fallback-trigger-label`,className:Q(`aui-tool-fallback-trigger-label-wrapper inline-block min-w-0 text-start leading-none wrap-anywhere`,s&&`text-muted-foreground line-through`,o&&`shimmer motion-reduce:animate-none`),children:[l,`:`,(0,J.jsx)(`b`,{children:e})]}),(0,J.jsx)(U2,{}),(0,J.jsx)(HN,{"data-slot":`tool-fallback-trigger-chevron`,className:Q(`aui-tool-fallback-trigger-chevron size-4 shrink-0`,`transition-transform duration-(--animation-duration) ease-[cubic-bezier(0.32,0.72,0,1)] motion-reduce:transition-none`,`-rotate-90`,`group-data-open/trigger:rotate-0`,`group-data-panel-open/trigger:rotate-0`)})]})}function G2({className:e,children:t,...n}){return(0,J.jsx)(w2,{"data-slot":`tool-fallback-content`,className:Q(`aui-tool-fallback-content relative overflow-hidden text-sm outline-none`,`group/collapsible-content ease-[cubic-bezier(0.32,0.72,0,1)] motion-reduce:animate-none`,`data-closed:animate-collapsible-up`,`data-open:animate-collapsible-down`,`data-closed:fill-mode-forwards`,`data-closed:pointer-events-none`,`[--tw-duration:var(--animation-duration)]`,e),...n,children:(0,J.jsx)(`div`,{className:Q(`flex flex-col gap-2 ps-6 pt-1 pb-2 ease-[cubic-bezier(0.32,0.72,0,1)] motion-reduce:animate-none`,`group-data-open/collapsible-content:animate-in group-data-open/collapsible-content:fade-in-0 group-data-open/collapsible-content:blur-in-[2px] group-data-open/collapsible-content:slide-in-from-top-1`,`group-data-closed/collapsible-content:animate-out group-data-closed/collapsible-content:fade-out-0 group-data-closed/collapsible-content:blur-out-[2px] group-data-closed/collapsible-content:slide-out-to-top-1`,`group-data-closed/collapsible-content:animation-duration-(--animation-duration) group-data-open/collapsible-content:animation-duration-(--animation-duration)`),children:t})})}function K2({argsText:e,className:t,...n}){return e?(0,J.jsx)(`div`,{"data-slot":`tool-fallback-args`,className:Q(`aui-tool-fallback-args`,t),...n,children:(0,J.jsx)(`pre`,{className:`aui-tool-fallback-args-value bg-muted/50 text-foreground/90 rounded-md p-2.5 text-xs break-words whitespace-pre-wrap`,children:e})}):null}var q2=(e,t)=>{if(typeof e==`string`)return e;try{if(e instanceof Error)return String(e);let n=JSON.stringify(e,null,t);if(n!==void 0)return n}catch{}try{return String(e)}catch{return`[无法序列化的数据]`}};function J2({result:e,className:t,...n}){return e===void 0?null:(0,J.jsxs)(`div`,{"data-slot":`tool-fallback-result`,className:Q(`aui-tool-fallback-result`,t),...n,children:[(0,J.jsx)(`p`,{className:`aui-tool-fallback-result-header text-muted-foreground text-xs font-medium`,children:`执行结果:`}),(0,J.jsx)(`pre`,{className:`aui-tool-fallback-result-content bg-muted/50 text-foreground/90 mt-1 rounded-md p-2.5 text-xs break-words whitespace-pre-wrap`,children:q2(e,2)})]})}function Y2({status:e,className:t,...n}){if(e?.type!==`incomplete`)return null;let r=e.error,i=r==null?null:q2(r);if(!i)return null;let a=e.reason===`cancelled`?`取消原因:`:`错误信息:`;return(0,J.jsxs)(`div`,{"data-slot":`tool-fallback-error`,className:Q(`aui-tool-fallback-error`,t),...n,children:[(0,J.jsx)(`p`,{className:`aui-tool-fallback-error-header text-muted-foreground font-semibold`,children:a}),(0,J.jsx)(`p`,{className:`aui-tool-fallback-error-reason text-muted-foreground break-words whitespace-pre-line`,children:i})]})}var X2=`Approved by user`,Z2=`User denied tool execution`,Q2={"allow-once":`允许一次`,"allow-always":`始终允许`,"reject-once":`拒绝一次`,"reject-always":`始终拒绝`},$2=e=>Object.hasOwn(Q2,e),e4=e=>e===`allow-once`||e===`allow-always`,t4=e=>e.label??($2(e.kind)?Q2[e.kind]:void 0)??e.id,n4=e=>e?.display===`select`||e?.display===`text`||e?.display===`questions`,r4=e=>!e.options?.length||e.allowFreeform===!0,i4=(e,t)=>[...(t?.optionIds??[]).map(t=>e.options?.find(e=>e.id===t)?.label??t),...t?.text?.trim()?[t.text]:[]],a4=e=>e!=null&&(e.approved!==void 0||e.resolution!==void 0),o4=e=>{if(e.resolution!==void 0)return{outcome:`closed`,label:e.resolution===`cancelled`?`已取消,未作出决定`:`已过期,未作出决定`};let t=e.optionId===void 0?void 0:e.options?.find(t=>t.id===e.optionId),n=t===void 0?e.optionId===void 0?void 0:e.optionId:t4(t),r=n4(e)||t!==void 0&&!$2(t.kind),i=e.isAutomatic?`(自动处理)`:``;return e.approved?{outcome:`allowed`,label:`${r?`已回答`:`已允许`}${i}`,option:n}:{outcome:`refused`,label:`${r?`已关闭`:`已拒绝`}${i}`,option:n}},s4={allowed:BN,refused:QN,closed:XN};function c4({approval:e,className:t,focusReceiptRef:n,receiptRef:r,...i}){(0,f.useLayoutEffect)(()=>{let t=n.current===e.id;n.current=null,t&&r.current?.focus({preventScroll:!0})},[e.id,n,r]);let a=o4(e),o=s4[a.outcome],s=[...new Set([e.text,e.reason].filter(e=>typeof e==`string`&&e!==``))];return(0,J.jsxs)(`div`,{ref:r,"data-slot":`tool-fallback-approval-receipt`,"data-outcome":a.outcome,tabIndex:-1,className:Q(`aui-tool-fallback-approval-receipt flex flex-col gap-1.5 pt-1`,t),...i,children:[e.prompt?(0,J.jsx)(`p`,{className:`aui-tool-fallback-approval-prompt text-muted-foreground whitespace-pre-line`,children:e.prompt}):null,(0,J.jsxs)(`p`,{className:`aui-tool-fallback-approval-receipt-label flex items-center gap-1.5`,children:[(0,J.jsx)(o,{"aria-hidden":!0,className:`text-muted-foreground size-3.5 shrink-0`}),(0,J.jsx)(`span`,{className:`font-medium`,children:a.label}),a.option===void 0?null:(0,J.jsxs)(`span`,{className:`text-muted-foreground`,children:[`· `,a.option]})]}),e.answers&&e.questions?.map(t=>{let n=i4(t,e.answers&&Object.hasOwn(e.answers,t.id)?e.answers[t.id]:void 0);return n.length===0?null:(0,J.jsxs)(`p`,{className:`aui-tool-fallback-approval-receipt-answer whitespace-pre-line`,children:[(0,J.jsx)(`span`,{className:`text-muted-foreground`,children:t.header??t.prompt}),` `,`· `,n.join(`、`)]},t.id)}),s.map(e=>(0,J.jsx)(`p`,{className:`aui-tool-fallback-approval-receipt-note text-muted-foreground whitespace-pre-line`,children:e},e))]})}function l4({questions:e,dismissible:t,locked:n,onSend:r,onDismiss:i}){let[a,o]=(0,f.useState)(()=>new Map),[s,c]=(0,f.useState)(()=>new Map),l=(e,t)=>o(n=>{let r=n.get(e.id)??[],i=r.includes(t)?r.filter(e=>e!==t):e.multiple?[...r,t]:[t];return new Map(n).set(e.id,i)}),u=e=>{let t=a.get(e.id)??[],n=s.get(e.id),r=n?.trim()?n:void 0;return{...t.length>0&&{optionIds:t},...r!==void 0&&{text:r}}},d=e.length>0&&e.every(e=>{let t=u(e);return t.optionIds!==void 0||t.text!==void 0});return(0,J.jsxs)(J.Fragment,{children:[e.map(e=>{let t=a.get(e.id)??[],r=e.options?.some(e=>e.description)??!1;return(0,J.jsxs)(`div`,{role:`group`,"aria-label":e.prompt,"data-slot":`tool-fallback-approval-question`,className:`aui-tool-fallback-approval-question flex flex-col gap-2`,children:[(0,J.jsxs)(`p`,{className:`aui-tool-fallback-approval-question-prompt text-foreground whitespace-pre-line`,children:[e.header?(0,J.jsx)(`span`,{className:`text-muted-foreground me-1.5 text-xs font-medium uppercase`,children:e.header}):null,e.prompt]}),e.options&&e.options.length>0?(0,J.jsx)(`div`,{className:Q(`flex gap-2`,r?`flex-col items-stretch`:`flex-wrap items-center`),children:e.options.map(i=>{let a=t.includes(i.id);return(0,J.jsxs)(iU,{size:`sm`,variant:a?`default`:`outline`,className:Q(z2,r&&`h-auto flex-col items-start gap-0.5 py-2 text-start whitespace-normal`),"aria-pressed":a,onClick:()=>l(e,i.id),disabled:n,children:[(0,J.jsx)(`span`,{children:i.label}),i.description?(0,J.jsx)(`span`,{className:`text-xs font-normal opacity-80`,children:i.description}):null]},i.id)})}):null,r4(e)?(0,J.jsx)(L2,{value:s.get(e.id)??``,onChange:t=>c(n=>new Map(n).set(e.id,t.target.value)),disabled:n,"aria-label":e.prompt,placeholder:e.options?.length?`或者输入其他答案`:`请输入你的答案`}):null]},e.id)}),(0,J.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,J.jsx)(iU,{size:`sm`,className:z2,onClick:()=>{!n&&d&&r(Object.fromEntries(e.map(e=>[e.id,u(e)])))},disabled:n||!d,children:`发送`}),t?(0,J.jsx)(iU,{size:`sm`,variant:`outline`,className:z2,onClick:i,disabled:n,children:`关闭`}):null]})]})}var u4=(e,t,n)=>e?.type!==`requires-action`||e.reason!==`interrupt`||t!=null||n!=null,d4=(0,f.forwardRef)(function(e,t){let n=(0,f.useRef)(!1);return(0,J.jsx)(f4,{carryFocusRef:n,forwardedRef:t,...e},e.approval?.id)});function f4({className:e,forwardedRef:t,carryFocusRef:n,addResult:r,resume:i,interrupt:a,approval:o,respondToApproval:s,status:c,...l}){let[u,d]=(0,f.useState)(!1),p=q(e=>e.thread.voice!==void 0),m=q(e=>e.thread.capabilities.answerToolCall),h=u||p,[g,_]=(0,f.useState)(null),[v,y]=(0,f.useState)(``),[b,x]=(0,f.useState)(null),S=c?.type===`requires-action`,[C,w]=(0,f.useState)(S),[T,E]=(0,f.useState)(0),D=(0,f.useRef)(T);(0,f.useLayoutEffect)(()=>{D.current=T},[T]),S!==C&&(w(S),S&&(d(!1),_(null),y(``),x(null),E(T+1)));let k=(0,f.useRef)(null),A=(0,f.useRef)(null),j=(0,f.useRef)(null);(0,f.useLayoutEffect)(()=>(n.current&&(n.current=!1,k.current?.focus({preventScroll:!0})),()=>{let e=k.current??A.current;n.current=e?.contains(e.ownerDocument.activeElement)??!1}),[n]),(0,f.useImperativeHandle)(t,()=>k.current??A.current);let M=(0,f.useCallback)(e=>{let t=k.current;j.current=!e&&t?.contains(t.ownerDocument.activeElement)?o?.id:null,k.current=e},[o?.id]),N=o!=null&&!a4(o)&&c!==void 0&&c.type!==`requires-action`&&!(u&&c.type===`running`);(0,f.useLayoutEffect)(()=>{N&&(j.current=null)},[N]);let P=()=>{let e=k.current;e?.contains(e.ownerDocument.activeElement)&&e.focus({preventScroll:!0})};if(o!=null&&a4(o))return(0,J.jsx)(c4,{approval:o,receiptRef:A,focusReceiptRef:j,className:e,...l});if(N||!u4(c,o,a))return null;let F=o?.prompt?(0,J.jsx)(`p`,{className:`aui-tool-fallback-approval-prompt text-foreground whitespace-pre-line`,children:o.prompt}):null;if(!m)return F&&(0,J.jsx)(`div`,{"data-slot":`tool-fallback-approval`,tabIndex:-1,className:Q(`aui-tool-fallback-approval flex flex-col gap-2 pt-1`,e),...l,ref:M,children:F});let I=s?o?.options:void 0,L=o!=null&&s!=null&&O(o),R=e=>{P(),d(!0),_(null),x(null),(async()=>{try{await e()}catch(e){if(D.current!==T)return;d(!1),x(e instanceof Error?e.message:String(e))}})()},z=e=>{if(!h){if(o!=null&&o.approved===void 0&&s)R(()=>s({approved:e,...te()}));else if(a)R(()=>i?.({approved:e}));else if(c?.type===`requires-action`&&c.reason===`interrupt`)return;else R(()=>r?.(e?X2:Z2))}},ee=e=>{h||R(()=>s?.($2(e.kind)?{optionId:e.id,...te()}:{optionId:e.id,approved:!0,...te()}))},te=()=>v.trim()?{text:v}:{},ne=()=>{h||R(()=>s?.({text:v}))},B=()=>{h||R(()=>s?.({approved:!1}))},re=e=>{e.confirm?(P(),_(e.id)):ee(e)},ie=g==null?void 0:I?.find(e=>e.id===g),V=n4(o),ae=V&&s!=null&&o?.dismissible===!0?(0,J.jsx)(iU,{size:`sm`,variant:`outline`,className:z2,onClick:B,disabled:h,children:`关闭`}):null,oe=b?(0,J.jsx)(`p`,{role:`alert`,className:`aui-tool-fallback-approval-error text-destructive text-xs whitespace-pre-line`,children:b}):null,se=L?(0,J.jsxs)(`div`,{className:`aui-tool-fallback-approval-answer flex flex-col items-start gap-2`,children:[(0,J.jsx)(L2,{value:v,onChange:e=>y(e.target.value),disabled:h,"aria-label":V?o?.prompt??`答案`:`备注`,placeholder:V?`请输入你的答案`:`填写决策备注`}),V&&(0,J.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,J.jsx)(iU,{size:`sm`,className:z2,onClick:ne,disabled:h,children:`发送`}),ae]})]}):null;if(o?.display===`questions`&&s)return(0,J.jsxs)(`div`,{"data-slot":`tool-fallback-approval`,tabIndex:-1,className:Q(`aui-tool-fallback-approval flex flex-col gap-3 pt-1`,e),...l,ref:M,children:[F,(0,J.jsx)(l4,{questions:o.questions??[],dismissible:o.dismissible===!0,locked:h,onSend:e=>R(()=>s({answers:e})),onDismiss:B}),oe]});if(ie){let t=typeof ie.confirm==`object`?ie.confirm:void 0,n=t?.description??ie.description;return(0,J.jsxs)(`div`,{"data-slot":`tool-fallback-approval-confirm`,tabIndex:-1,className:Q(`aui-tool-fallback-approval-confirm flex flex-col gap-2 pt-1`,e),...l,ref:M,children:[(0,J.jsx)(`p`,{className:`aui-tool-fallback-approval-confirm-title font-semibold`,children:t?.title??`${t4(ie)}?`}),n&&(0,J.jsx)(`p`,{className:`aui-tool-fallback-approval-confirm-description text-muted-foreground whitespace-pre-line`,children:n}),ie.grants&&ie.grants.length>0&&(0,J.jsx)(`ul`,{className:`aui-tool-fallback-approval-confirm-grants flex flex-col gap-1`,children:ie.grants.map(e=>(0,J.jsx)(`li`,{children:(0,J.jsx)(`code`,{className:`aui-tool-fallback-approval-confirm-grant bg-muted rounded px-1.5 py-0.5 text-xs`,children:e})},e))}),(0,J.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,J.jsx)(iU,{size:`sm`,className:z2,onClick:()=>ee(ie),disabled:h,children:`确认`}),(0,J.jsx)(iU,{size:`sm`,variant:`outline`,className:z2,onClick:()=>{P(),_(null)},disabled:h,children:`返回`})]})]})}if(I&&I.length>0){let t=I.filter(e=>e4(e.kind)),n=I.filter(e=>!$2(e.kind)),r=I.filter(e=>$2(e.kind)&&!e4(e.kind));return(0,J.jsxs)(`div`,{"data-slot":`tool-fallback-approval`,tabIndex:-1,className:Q(`aui-tool-fallback-approval flex flex-col gap-2 pt-1`,e),...l,ref:M,children:[F,(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[[...t,...n,...r].map(e=>(0,J.jsx)(iU,{size:`sm`,variant:e===t[0]?`default`:`outline`,className:z2,onClick:()=>re(e),disabled:h,children:t4(e)},e.id)),r.length===0&&!V&&(0,J.jsx)(iU,{size:`sm`,variant:`outline`,className:z2,onClick:()=>z(!1),disabled:h,children:`拒绝`}),!L&&ae]}),se,oe]})}return V?(0,J.jsxs)(`div`,{"data-slot":`tool-fallback-approval`,tabIndex:-1,className:Q(`aui-tool-fallback-approval flex flex-col gap-2 pt-1`,e),...l,ref:M,children:[F,se,!L&&ae&&(0,J.jsx)(`div`,{className:`flex items-center gap-2`,children:ae}),oe]}):(0,J.jsxs)(`div`,{"data-slot":`tool-fallback-approval`,tabIndex:-1,className:Q(`aui-tool-fallback-approval flex flex-col gap-2 pt-1`,e),...l,ref:M,children:[F,(0,J.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,J.jsx)(iU,{size:`sm`,className:z2,onClick:()=>z(!0),disabled:h,children:`允许`}),(0,J.jsx)(iU,{size:`sm`,variant:`outline`,className:z2,onClick:()=>z(!1),disabled:h,children:`拒绝`})]}),se,oe]})}var p4=(0,f.memo)(({toolName:e,argsText:t,result:n,status:r,responseDeliveryStatus:i,addResult:a,resume:o,interrupt:s,approval:c,respondToApproval:l})=>{let u=r?.type===`incomplete`&&r.reason===`cancelled`,d=r?.type===`requires-action`,p=c!=null||d&&u4(r,c,s),[m,h]=(0,f.useState)(d),[g,_]=(0,f.useState)(d);d!==g&&(_(d),d&&h(!0));let v=(0,f.useRef)(!1),y=(0,f.useRef)(null),b=(0,f.useRef)(null);return(0,f.useLayoutEffect)(()=>{let e=y.current;if(!e||e.isConnected||d||!v.current)return;let t=c==null||!a4(c);v.current=!1;let{activeElement:n,body:r}=e.ownerDocument;t&&(n==null||n===r)&&b.current?.focus({preventScroll:!0})},[c,d,r?.type]),(0,J.jsxs)(B2,{open:m,onOpenChange:h,children:[(0,J.jsx)(W2,{toolName:e,status:r,responseDeliveryStatus:i}),(0,J.jsxs)(G2,{children:[(0,J.jsx)(Y2,{status:r}),(0,J.jsx)(K2,{argsText:t,className:Q(u&&`opacity-60`)}),p&&(0,J.jsx)(d4,{addResult:a,resume:o,interrupt:s,approval:c,respondToApproval:l,status:r,onFocusCapture:e=>{let t=e.currentTarget.closest(`[data-slot="tool-fallback-root"]`);b.current=t?.querySelector(`[data-slot="tool-fallback-trigger"]`)??null,y.current=e.currentTarget,v.current=!0},onBlurCapture:e=>{let t=e.relatedTarget;(t?e.currentTarget.contains(t):e.currentTarget.contains(e.currentTarget.ownerDocument.activeElement))||(v.current=!1)}}),(0,J.jsx)(J2,{result:n})]})]})});p4.displayName=`ToolFallback`,p4.Root=B2,p4.Trigger=W2,p4.Content=G2,p4.Args=K2,p4.Result=J2,p4.Error=Y2,p4.Approval=d4;var m4=200,h4=nU(`aui-tool-group-root group/tool-group w-full`,{variants:{variant:{outline:`rounded-lg border py-3`,ghost:``,muted:`border-muted-foreground/30 bg-muted/30 rounded-lg border py-3`}},defaultVariants:{variant:`outline`}});function g4({className:e,variant:t,open:n,onOpenChange:r,defaultOpen:i=!1,children:a,...o}){let s=(0,f.useRef)(null),[c,l]=(0,f.useState)(i),u=MM(s,m4),d=n!==void 0,p=d?n:c,m=(0,f.useCallback)(e=>{u(),d||l(e),r?.(e)},[u,d,r]);return(0,J.jsx)(S2,{ref:s,"data-slot":`tool-group-root`,"data-variant":t??`outline`,open:p,onOpenChange:m,className:Q(h4({variant:t}),`group/tool-group-root`,e),style:{"--animation-duration":`${m4}ms`},...o,children:a})}function _4({count:e,active:t=!1,className:n,...r}){let i=`${e} 次工具调用`;return(0,J.jsxs)(C2,{"data-slot":`tool-group-trigger`,className:Q(`aui-tool-group-trigger group/trigger flex origin-left items-center gap-2 text-sm transition-[color,scale] active:scale-[0.98]`,`group-data-[variant=ghost]/tool-group-root:text-muted-foreground group-data-[variant=ghost]/tool-group-root:hover:text-foreground group-data-[variant=ghost]/tool-group-root:py-1.5`,`group-data-[variant=outline]/tool-group-root:w-full group-data-[variant=outline]/tool-group-root:px-4`,`group-data-[variant=muted]/tool-group-root:w-full group-data-[variant=muted]/tool-group-root:px-4`,n),...r,children:[t&&(0,J.jsx)(vP,{"data-slot":`tool-group-trigger-loader`,className:`aui-tool-group-trigger-loader size-3 shrink-0 animate-spin [animation-duration:0.6s]`}),(0,J.jsx)(`span`,{"data-slot":`tool-group-trigger-label`,className:Q(`aui-tool-group-trigger-label-wrapper inline-block text-start text-xs leading-none font-medium`,`group-data-[variant=ghost]/tool-group-root:font-normal`,`group-data-[variant=outline]/tool-group-root:grow`,`group-data-[variant=muted]/tool-group-root:grow`,t&&`shimmer motion-reduce:animate-none`),children:i}),(0,J.jsx)(HN,{"data-slot":`tool-group-trigger-chevron`,className:Q(`aui-tool-group-trigger-chevron size-3 shrink-0`,`transition-transform duration-(--animation-duration) ease-[cubic-bezier(0.32,0.72,0,1)] motion-reduce:transition-none`,`-rotate-90`,`group-data-open/trigger:rotate-0`,`group-data-panel-open/trigger:rotate-0`)})]})}function v4({className:e,children:t,...n}){return(0,J.jsx)(w2,{"data-slot":`tool-group-content`,className:Q(`aui-tool-group-content relative overflow-hidden text-sm outline-none`,`group/collapsible-content ease-[cubic-bezier(0.32,0.72,0,1)] motion-reduce:animate-none`,`data-closed:animate-collapsible-up`,`data-open:animate-collapsible-down`,`data-closed:fill-mode-forwards`,`data-closed:pointer-events-none`,`[--tw-duration:var(--animation-duration)]`,e),...n,children:(0,J.jsx)(`div`,{className:Q(`mt-2 flex flex-col gap-2`,`group-data-[variant=ghost]/tool-group-root:mt-1 group-data-[variant=ghost]/tool-group-root:gap-1`,`group-data-[variant=outline]/tool-group-root:mt-3 group-data-[variant=outline]/tool-group-root:border-t group-data-[variant=outline]/tool-group-root:px-4 group-data-[variant=outline]/tool-group-root:pt-3`,`group-data-[variant=muted]/tool-group-root:mt-3 group-data-[variant=muted]/tool-group-root:border-t group-data-[variant=muted]/tool-group-root:px-4 group-data-[variant=muted]/tool-group-root:pt-3`,`[&>*]:animate-in [&>*]:fade-in-0 [&>*]:blur-in-[2px] [&>*]:slide-in-from-top-1 [&>*]:animation-duration-(--animation-duration) [&>*]:ease-[cubic-bezier(0.32,0.72,0,1)]`,`[&>*]:motion-reduce:animate-none`,`[&>*:nth-child(2)]:[animation-delay:40ms]`,`[&>*:nth-child(3)]:[animation-delay:80ms]`,`[&>*:nth-child(4)]:[animation-delay:120ms]`,`[&>*:nth-child(n+5)]:[animation-delay:160ms]`),children:t})})}var y4=(0,f.memo)(({children:e,startIndex:t,endIndex:n})=>{let r=n-t+1;return(0,J.jsxs)(g4,{children:[(0,J.jsx)(_4,{count:r}),(0,J.jsx)(v4,{children:e})]})});y4.displayName=`ToolGroup`,y4.Root=g4,y4.Trigger=_4,y4.Content=v4;function b4({className:e,...t}){return(0,J.jsx)(`div`,{"data-slot":`skeleton`,className:Q(`animate-pulse rounded-md bg-muted`,e),...t})}var x4=({group:e,children:t})=>{let[n,r]=(0,f.useState)(!1);return(0,J.jsxs)(g4,{variant:`ghost`,open:n||e.counts.requiresAction>0,onOpenChange:r,children:[(0,J.jsx)(_4,{count:e.indices.length,active:e.status.type===`running`}),(0,J.jsx)(v4,{children:t})]})},S4=e=>!!e.thread.canResume&&e.composer.type===`thread`&&e.composer.isEmpty,C4=e=>e?.completedAt===void 0?void 0:Number(((e.completedAt-e.startedAt)/1e3).toFixed(1)),w4=gg({reasoning:[`group-chainOfThought`,`group-reasoning`],"tool-call":[`group-chainOfThought`,`group-reasoning`],"standalone-tool-call":[]}),T4=[`group-chainOfThought`,`group-task`],E4=(e,t)=>{let n=w4(e,t);return e.type===`tool-call`&&e.messages!==void 0&&n.length>0&&!t?.toolUIs?.[e.toolName]?.length?T4:n},D4={},O4=(0,f.createContext)(D4),k4=e=>e.thread.messages.length===0&&(!e.thread.isLoading||e.threads.isLoading),A4=e=>e.thread.messages.length===0&&e.thread.isLoading&&!e.thread.isDisabled&&!e.threads.isLoading,j4=()=>(0,J.jsxs)(`div`,{"data-slot":`aui_thread-history-skeleton`,role:`status`,className:`animate-in fade-in fill-mode-both flex flex-col gap-y-6 [animation-delay:150ms] [animation-duration:200ms]`,children:[(0,J.jsx)(`span`,{className:`sr-only`,children:`正在加载对话`}),(0,J.jsx)(b4,{className:`ml-auto h-9 w-2/5 rounded-xl motion-reduce:animate-none`}),(0,J.jsxs)(`div`,{className:`flex flex-col gap-y-2`,children:[(0,J.jsx)(b4,{className:`h-4 w-11/12 motion-reduce:animate-none`}),(0,J.jsx)(b4,{className:`h-4 w-4/5 motion-reduce:animate-none`}),(0,J.jsx)(b4,{className:`h-4 w-3/5 motion-reduce:animate-none`})]}),(0,J.jsx)(b4,{className:`ml-auto h-9 w-1/3 rounded-xl motion-reduce:animate-none`}),(0,J.jsxs)(`div`,{className:`flex flex-col gap-y-2`,children:[(0,J.jsx)(b4,{className:`h-4 w-10/12 motion-reduce:animate-none`}),(0,J.jsx)(b4,{className:`h-4 w-2/3 motion-reduce:animate-none`})]})]}),M4=({components:e=D4,autoFocus:t=!0})=>{let n=q(k4);return(0,J.jsx)(O4.Provider,{value:e,children:(0,J.jsx)(N4,{isEmpty:n,autoFocus:t})})},N4=({isEmpty:e,autoFocus:t})=>{let{Welcome:n=U4}=(0,f.useContext)(O4);return(0,J.jsx)(rM.Root,{className:`aui-root aui-thread-root bg-background @container flex h-full flex-col`,style:{"--thread-max-width":`44rem`,"--composer-bg":`color-mix(in oklab, var(--color-muted) 30%, transparent)`,"--composer-radius":`1rem`,"--composer-padding":`8px`},children:(0,J.jsx)(rM.Viewport,{turnAnchor:`top`,"data-slot":`aui_thread-viewport`,className:`relative flex flex-1 flex-col overflow-x-auto overflow-y-scroll scroll-smooth`,children:(0,J.jsxs)(`div`,{className:Q(`mx-auto flex w-full max-w-(--thread-max-width) flex-1 flex-col px-4 pt-4`,e&&`justify-center`),children:[(0,J.jsx)(Pu,{condition:k4,children:(0,J.jsx)(n,{})}),(0,J.jsx)(Pu,{condition:A4,children:(0,J.jsx)(j4,{})}),(0,J.jsx)(V4,{}),(0,J.jsx)(`div`,{"data-slot":`aui_message-group`,className:`mb-14 flex flex-col gap-y-6 empty:hidden`,children:(0,J.jsx)(rM.Messages,{children:()=>(0,J.jsx)(P4,{})})}),(0,J.jsxs)(rM.ViewportFooter,{className:Q(`aui-thread-viewport-footer bg-background flex flex-col gap-2 overflow-visible pb-4 md:pb-6`,!e&&`sticky bottom-0 mt-auto rounded-t-(--composer-radius)`),children:[(0,J.jsx)(H4,{}),(0,J.jsx)(pW,{}),!e&&(0,J.jsx)(`div`,{className:`mx-auto flex w-full max-w-(--thread-max-width) justify-start`,children:(0,J.jsxs)(xM.New,{render:(0,J.jsx)(`button`,{type:`button`,className:`inline-flex h-6 items-center gap-1 rounded text-xs text-muted-foreground transition-colors hover:bg-accent hover:text-foreground`}),children:[(0,J.jsx)(PP,{className:`size-3`}),`新建对话`]})}),(0,J.jsx)(K4,{autoFocus:t}),(0,J.jsx)(Pu,{condition:e=>k4(e)&&e.composer.isEmpty,children:(0,J.jsx)(W4,{})})]})]})})})},P4=()=>{let{AssistantMessage:e=Y4}=(0,f.useContext)(O4),t=q(e=>e.message.role),n=q(e=>e.message.composer.isEditing),r=q(e=>e.message.metadata.modality===`voice`);return n?(0,J.jsx)(n3,{}):r?(0,J.jsx)(L4,{}):t===`user`?(0,J.jsx)(e3,{}):(0,J.jsx)(e,{})},F4=()=>q(e=>{let t=e.thread.messages[e.message.index-1]?.metadata.modality===`voice`,n=e.thread.messages[e.message.index+1]?.metadata.modality===`voice`;return t?n?`middle`:`end`:n?`start`:`single`}),I4=({text:e})=>(0,J.jsx)(`p`,{className:`aui-spoken-message-text m-0`,children:e}),L4=()=>{let e=q(e=>e.message.role),t=F4(),n=q(e=>e.message.role===`assistant`&&e.message.status?.type===`running`),r=t===`start`||t===`single`;return(0,J.jsxs)(_j.Root,{"data-slot":`aui_spoken-message-root`,"data-role":e,"data-voice-run":t,className:Q(`aui-spoken-message bg-muted/40 mx-2 px-3 py-1.5 [contain-intrinsic-size:auto_48px] [content-visibility:auto]`,t===`single`&&`rounded-xl py-2`,t===`start`&&`rounded-t-xl pt-2`,t===`middle`&&`-mt-6`,t===`end`&&`-mt-6 rounded-b-xl pb-2`),children:[r&&(0,J.jsxs)(`div`,{"data-slot":`aui_spoken-exchange-header`,className:`text-muted-foreground mb-1.5 flex items-center gap-1.5 text-xs`,children:[(0,J.jsx)(AP,{className:`size-3`,"aria-hidden":!0}),(0,J.jsx)(`span`,{children:`语音对话`})]}),(0,J.jsxs)(`div`,{"data-slot":`aui_spoken-message-content`,className:`text-foreground flex items-start gap-2 text-sm leading-relaxed`,children:[(0,J.jsx)(`span`,{className:`text-muted-foreground mt-1 shrink-0`,"aria-hidden":!0,children:e===`user`?(0,J.jsx)(wP,{className:`size-3.5`}):(0,J.jsx)(PN,{className:`size-3.5`})}),(0,J.jsx)(`span`,{className:`sr-only`,children:e===`user`?`你说`:`助手说`}),(0,J.jsxs)(`div`,{className:`min-w-0 flex-1 wrap-break-word`,children:[(0,J.jsx)(_j.Parts,{components:{Text:I4}}),n&&(0,J.jsx)(`span`,{"data-slot":`aui_spoken-message-indicator`,role:`status`,className:`text-muted-foreground ms-1 animate-pulse font-sans`,"aria-label":`助手正在说话`,children:`●`})]}),(0,J.jsx)(R4,{})]})]})},R4=()=>(0,J.jsx)(jD.Root,{hideWhenRunning:!0,autohide:`always`,className:`aui-spoken-action-bar text-muted-foreground flex shrink-0 gap-1`,children:(0,J.jsxs)(jD.Copy,{render:(0,J.jsx)(SU,{tooltip:`复制`,className:`size-6`}),children:[(0,J.jsx)(Pu,{condition:e=>e.message.isCopied,children:(0,J.jsx)(BN,{className:`animate-in zoom-in-50 fade-in duration-200 ease-out`})}),(0,J.jsx)(Pu,{condition:e=>!e.message.isCopied,children:(0,J.jsx)(eP,{className:`animate-in zoom-in-75 fade-in duration-150`})})]})}),z4=`a[href], button:not([disabled]), input:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex='-1']):not([disabled])`,B4=e=>{for(let t=e.nextElementSibling;t;t=t.nextElementSibling){let e=t.matches(z4)?t:t.querySelector(z4);if(e instanceof HTMLElement)return e}return null},V4=()=>{let e=K(),t=q(e=>e.thread.hasEarlier),n=q(e=>e.thread.isLoadingEarlier),r=t||n,i=(0,f.useRef)(null),a=(0,f.useRef)(null),o=(0,f.useRef)(null),s=(0,f.useRef)(!1);return(0,f.useEffect)(()=>{if(!t||n){n||(s.current=!1);return}let r=a.current;if(!r)return;let i=r.closest(`[data-slot="aui_thread-viewport"]`);if(!i)return;let o=new IntersectionObserver(t=>{t[0]?.isIntersecting&&!s.current&&(s.current=!0,e.thread.loadEarlier().catch(e=>{console.error(`加载更早的消息失败:`,e),s.current=!1}))},{root:i,rootMargin:`120px 0px 0px 0px`,threshold:0});return o.observe(r),()=>{o.disconnect()}},[e,t,n]),(0,f.useLayoutEffect)(()=>{let e=o.current,t=i.current;if(r||!e||e.isConnected||!t)return;o.current=null;let n=document.activeElement;n&&n!==document.body||B4(t)?.focus()},[r]),(0,J.jsxs)(`div`,{ref:i,className:`contents`,onFocus:e=>{o.current=e.target},children:[(0,J.jsx)(`div`,{ref:a,"aria-hidden":`true`,className:`h-px w-full shrink-0`}),(0,J.jsx)(`span`,{role:`status`,className:`sr-only`,children:n?`正在加载更早的消息`:``}),r&&(0,J.jsx)(rM.LoadEarlier,{render:(0,J.jsx)(iU,{variant:`ghost`,size:`sm`,"data-slot":`aui_thread-load-earlier`,className:`aui-thread-load-earlier text-muted-foreground mb-6 self-center rounded-full`}),children:(0,J.jsx)(`span`,{className:Q(n&&`shimmer motion-reduce:animate-none`),children:n?`正在加载更早的消息...`:`加载更早的消息`})})]})},H4=()=>(0,J.jsx)(rM.ScrollToBottom,{render:(0,J.jsx)(SU,{tooltip:`滚动到底部`,variant:`outline`,className:`aui-thread-scroll-to-bottom dark:border-border dark:bg-background dark:hover:bg-accent absolute -top-12 z-10 self-center rounded-full p-4 disabled:invisible`}),children:(0,J.jsx)(AN,{})}),U4=()=>(0,J.jsx)(`div`,{className:`aui-thread-welcome-root mb-6 flex flex-col px-2`,children:(0,J.jsx)(`p`,{className:`aui-thread-welcome-message-inner fade-in slide-in-from-bottom-1 animate-in fill-mode-both text-2xl font-medium tracking-tight text-foreground duration-200 text-center`,children:`今天有什么可以帮你?`})}),W4=()=>(0,J.jsx)(`div`,{className:`aui-thread-welcome-suggestions flex w-full flex-col`,children:(0,J.jsx)(rM.Suggestions,{children:()=>(0,J.jsx)(G4,{})})}),G4=()=>(0,J.jsx)(`div`,{className:`aui-thread-welcome-suggestion-display fade-in slide-in-from-bottom-2 animate-in fill-mode-both duration-200`,children:(0,J.jsxs)(uM.Trigger,{send:!0,render:(0,J.jsx)(`button`,{type:`button`,className:`aui-thread-welcome-suggestion group hover:bg-foreground/[0.03] focus-visible:ring-ring/50 flex w-full items-baseline gap-2.5 rounded-md px-2 py-2 text-start text-sm transition-colors outline-none focus-visible:ring-1 motion-reduce:transition-none`}),children:[(0,J.jsx)(`span`,{"aria-hidden":!0,className:`text-muted-foreground/60 group-hover:text-foreground font-mono text-xs transition-colors motion-reduce:transition-none`,children:`>`}),(0,J.jsxs)(`span`,{className:`min-w-0 flex-1 truncate`,children:[(0,J.jsx)(uM.Title,{className:`aui-thread-welcome-suggestion-text-1 text-foreground`}),` `,(0,J.jsx)(uM.Description,{className:`aui-thread-welcome-suggestion-text-2 text-muted-foreground empty:hidden`})]})]})}),K4=({autoFocus:e})=>(0,J.jsx)(lA.Root,{className:`aui-composer-root relative flex w-full flex-col`,children:(0,J.jsxs)(lA.AttachmentDropzone,{render:(0,J.jsx)(`div`,{"data-slot":`aui_composer-shell`,className:`border-foreground/10 focus-within:border-foreground/25 data-[dragging=true]:border-ring flex w-full cursor-text flex-col gap-2 rounded-(--composer-radius) border bg-(--composer-bg) p-(--composer-padding) transition-[border-color] data-[dragging=true]:border-dashed data-[dragging=true]:bg-[color-mix(in_oklab,var(--color-accent)_50%,var(--color-background))]`}),children:[(0,J.jsx)(RU,{}),(0,J.jsx)(lA.Input,{placeholder:`请输入你的问题...`,className:`aui-composer-input text-foreground caret-primary placeholder:text-muted-foreground/60 max-h-48 min-h-10 w-full resize-none bg-transparent px-2.5 py-1 text-base leading-6 outline-none`,rows:1,autoFocus:e,enterKeyHint:`send`,"aria-label":`消息输入框`}),(0,J.jsx)(q4,{})]})}),q4=()=>{let{ComposerExtra:e}=(0,f.useContext)(O4),t=q(e=>e.composer.submission!==void 0&&!(e.thread.isRunning&&e.thread.capabilities.cancel));return(0,J.jsxs)(`div`,{className:`aui-composer-action-wrapper relative flex items-center justify-between`,children:[e?(0,J.jsxs)(`div`,{className:`aui-composer-action-start flex items-center gap-1.5`,children:[(0,J.jsx)(zU,{}),(0,J.jsx)(e,{})]}):(0,J.jsx)(zU,{}),(0,J.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,J.jsxs)(Pu,{condition:e=>e.thread.capabilities.dictation,children:[(0,J.jsx)(Pu,{condition:e=>e.composer.dictation==null,children:(0,J.jsx)(lA.Dictate,{render:(0,J.jsx)(SU,{tooltip:`语音输入`,side:`bottom`,type:`button`,variant:`ghost`,size:`icon`,className:`aui-composer-dictate text-muted-foreground hover:text-foreground size-7 rounded-full`,"aria-label":`开始语音输入`}),children:(0,J.jsx)(wP,{className:`aui-composer-dictate-icon size-4`})})}),(0,J.jsx)(Pu,{condition:e=>e.composer.dictation!=null,children:(0,J.jsx)(lA.StopDictation,{render:(0,J.jsx)(SU,{tooltip:`停止语音输入`,side:`bottom`,type:`button`,variant:`ghost`,size:`icon`,className:`aui-composer-stop-dictation text-destructive size-7 rounded-full`,"aria-label":`停止语音输入`}),children:(0,J.jsx)(BP,{className:`aui-composer-stop-dictation-icon size-3.5 animate-pulse fill-current`})})})]}),(0,J.jsx)(Pu,{condition:e=>(!e.composer.canCancel||e.thread.voice!==void 0&&e.composer.submission===void 0)&&!S4(e),children:(0,J.jsx)(lA.Send,{render:(0,J.jsx)(SU,{tooltip:`发送消息`,side:`bottom`,type:`button`,variant:`default`,size:`icon`,className:`aui-composer-send size-7 rounded-full`,"aria-label":`发送消息`}),children:(0,J.jsx)(MN,{className:`aui-composer-send-icon size-4`})})}),(0,J.jsx)(Pu,{condition:S4,children:(0,J.jsx)(lA.Resume,{render:(0,J.jsx)(SU,{tooltip:`继续生成`,side:`bottom`,type:`button`,variant:`default`,size:`icon`,className:`aui-composer-resume size-7 rounded-full`,"aria-label":`继续生成`}),children:(0,J.jsx)(MP,{className:`aui-composer-resume-icon size-4`})})}),(0,J.jsx)(Pu,{condition:e=>e.composer.canCancel&&(e.thread.voice===void 0||e.composer.submission!==void 0),children:(0,J.jsx)(lA.Cancel,{render:(0,J.jsx)(iU,{type:`button`,variant:`default`,size:`icon`,className:`aui-composer-cancel size-7 rounded-full`,"aria-label":t?`取消发送`:`停止生成`}),children:(0,J.jsx)(BP,{className:`aui-composer-cancel-icon size-3.5 fill-current`})})})]})]})},J4=()=>(0,J.jsx)(_j.Error,{children:(0,J.jsx)(FA.Root,{className:`aui-message-error-root border-destructive bg-destructive/10 text-destructive dark:bg-destructive/5 mt-2 rounded-md border p-3 text-sm dark:text-red-200`,children:(0,J.jsx)(FA.Message,{className:`aui-message-error-message line-clamp-2`})})}),Y4=()=>{let{ToolFallback:e=p4,ToolGroup:t,ReasoningGroup:n,TaskGroup:r}=(0,f.useContext)(O4),i=r?E4:w4;return(0,J.jsxs)(_j.Root,{"data-slot":`aui_assistant-message-root`,"data-role":`assistant`,className:`fade-in slide-in-from-bottom-1 animate-in relative -mb-7.5 pb-7.5 duration-150 [contain-intrinsic-size:auto_200px] [content-visibility:auto]`,children:[(0,J.jsxs)(`div`,{"data-slot":`aui_assistant-message-content`,className:`text-foreground px-2 text-left leading-relaxed wrap-break-word`,children:[(0,J.jsx)(_j.GroupedParts,{groupBy:i,children:({part:i,children:a})=>{switch(i.type){case`group-chainOfThought`:return(0,J.jsx)(`div`,{"data-slot":`aui_chain-of-thought`,children:a});case`group-task`:return r?(0,J.jsx)(r,{group:i}):null;case`group-tool`:return t?(0,J.jsx)(t,{group:i,children:a}):(0,J.jsx)(x4,{group:i,children:a});case`group-reasoning`:{if(n)return(0,J.jsx)(n,{group:i,children:a});let e=i.status.type===`running`;return(0,J.jsxs)(M2,{streaming:e,children:[(0,J.jsx)(k2,{active:e,duration:C4(i.timing)}),(0,J.jsx)(A2,{"aria-busy":e,children:(0,J.jsx)(j2,{children:a})})]})}case`text`:return(0,J.jsx)(J0,{});case`reasoning`:return(0,J.jsx)(F2,{...i});case`tool-call`:return i.toolUI??(0,J.jsx)(e,{...i});case`data`:return i.dataRendererUI;case`file`:return(0,J.jsx)(`div`,{"data-slot":`aui_assistant-message-file`,className:`py-1`,children:(0,J.jsx)(Z4,{...i})});case`image`:return(0,J.jsx)(`div`,{"data-slot":`aui_assistant-message-image`,className:`py-1`,children:(0,J.jsx)(IW,{...i})});case`indicator`:return(0,J.jsx)(`span`,{"data-slot":`aui_assistant-message-indicator`,className:`animate-pulse font-sans`,"aria-label":`助手正在处理`,children:`●`});default:return null}}}),(0,J.jsx)(J4,{})]}),(0,J.jsxs)(`div`,{"data-slot":`aui_assistant-message-footer`,className:Q(`ms-2 flex items-center`,`min-h-7.5 pt-1.5`),children:[(0,J.jsx)(r3,{}),(0,J.jsx)(X4,{})]})]})},X4=()=>(0,J.jsxs)(jD.Root,{hideWhenRunning:!0,autohide:`not-last`,className:`aui-assistant-action-bar-root text-muted-foreground animate-in fade-in col-start-3 row-start-2 -ms-1 flex gap-1 duration-200`,children:[(0,J.jsxs)(jD.Copy,{render:(0,J.jsx)(SU,{tooltip:`复制`}),children:[(0,J.jsx)(Pu,{condition:e=>e.message.isCopied,children:(0,J.jsx)(BN,{className:`animate-in zoom-in-50 fade-in duration-200 ease-out`})}),(0,J.jsx)(Pu,{condition:e=>!e.message.isCopied,children:(0,J.jsx)(eP,{className:`animate-in zoom-in-75 fade-in duration-150`})})]}),(0,J.jsxs)(Pu,{condition:e=>e.thread.capabilities.feedback,children:[(0,J.jsx)(jD.FeedbackPositive,{render:(0,J.jsx)(SU,{tooltip:`有帮助`,className:`data-[submitted=true]:bg-accent data-[submitted=true]:text-accent-foreground`}),children:(0,J.jsx)(HP,{})}),(0,J.jsx)(jD.FeedbackNegative,{render:(0,J.jsx)(SU,{tooltip:`没有帮助`,className:`data-[submitted=true]:bg-accent data-[submitted=true]:text-accent-foreground`}),children:(0,J.jsx)(WP,{})})]}),(0,J.jsx)(jD.Reload,{render:(0,J.jsx)(SU,{tooltip:`重新生成`}),children:(0,J.jsx)(IP,{})}),(0,J.jsxs)(HD.Root,{children:[(0,J.jsx)(HD.Trigger,{render:(0,J.jsx)(SU,{tooltip:`更多`,className:`data-[state=open]:bg-accent`}),children:(0,J.jsx)(oP,{})}),(0,J.jsx)(HD.Content,{side:`bottom`,align:`start`,sideOffset:6,className:`aui-action-bar-more-content bg-popover text-popover-foreground data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95 data-[state=open]:animate-in data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=closed]:animate-out data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 min-w-[8rem] overflow-hidden rounded-xl border p-1.5`,children:(0,J.jsxs)(jD.ExportMarkdown,{render:(0,J.jsx)(HD.Item,{className:`aui-action-bar-more-item hover:bg-accent hover:text-accent-foreground focus:bg-accent focus:text-accent-foreground flex items-center gap-2 rounded-lg px-2.5 py-1.5 text-sm outline-none select-none`}),children:[(0,J.jsx)(nP,{className:`size-4`}),`导出为 Markdown`]})})]})]}),Z4=e=>{let t=e.mimeType.toLowerCase().startsWith(`image/`)?$U(e.data,e.mimeType,e.sourceType):null;return t?(0,J.jsx)(IW,{type:`image`,image:t,status:e.status,...e.filename!==void 0&&{filename:e.filename}}):(0,J.jsx)(dW,{...e})},Q4=e=>(0,J.jsx)(`div`,{"data-slot":`aui_user-message-file`,className:`py-1`,children:(0,J.jsx)(Z4,{...e})}),$4=e=>(0,J.jsx)(`div`,{"data-slot":`aui_user-message-image`,className:`py-1`,children:(0,J.jsx)(IW,{...e})}),e3=()=>(0,J.jsxs)(_j.Root,{"data-slot":`aui_user-message-root`,className:`fade-in slide-in-from-bottom-1 animate-in grid auto-rows-auto grid-cols-[minmax(72px,1fr)_auto] content-start gap-y-2 px-2 duration-150 [contain-intrinsic-size:auto_200px] [content-visibility:auto] [&:where(>*)]:col-start-2`,"data-role":`user`,children:[(0,J.jsx)(LU,{}),(0,J.jsx)(`div`,{className:`aui-user-message-content-wrapper relative col-start-2 min-w-0`,children:(0,J.jsx)(`div`,{className:`aui-user-message-content peer rounded-(--composer-radius) bg-muted px-4 py-2 text-foreground wrap-break-word empty:hidden`,children:(0,J.jsx)(_j.Parts,{components:{File:Q4,Image:$4}})})}),(0,J.jsx)(`div`,{className:`col-start-2 -mt-1 flex justify-end min-h-8`,children:(0,J.jsx)(t3,{})}),(0,J.jsx)(r3,{"data-slot":`aui_user-branch-picker`,className:`col-span-full col-start-1 -me-1 justify-end`})]}),t3=()=>(0,J.jsxs)(jD.Root,{hideWhenRunning:!0,autohide:`not-last`,className:`aui-user-action-bar-root flex flex-row items-center gap-1`,children:[(0,J.jsxs)(jD.Copy,{render:(0,J.jsx)(SU,{tooltip:`复制`,className:`aui-user-action-copy size-8 rounded-md text-muted-foreground hover:bg-accent hover:text-foreground`}),children:[(0,J.jsx)(Pu,{condition:e=>e.message.isCopied,children:(0,J.jsx)(BN,{className:`animate-in zoom-in-50 fade-in duration-200 ease-out`})}),(0,J.jsx)(Pu,{condition:e=>!e.message.isCopied,children:(0,J.jsx)(eP,{className:`animate-in zoom-in-75 fade-in duration-150`})})]}),(0,J.jsx)(jD.Edit,{render:(0,J.jsx)(SU,{tooltip:`编辑`,className:`aui-user-action-edit size-8 rounded-md text-muted-foreground hover:bg-accent hover:text-foreground`}),children:(0,J.jsx)(OP,{className:`size-4`})})]}),n3=()=>(0,J.jsx)(_j.Root,{"data-slot":`aui_edit-composer-wrapper`,className:`flex flex-col px-2 [contain-intrinsic-size:auto_200px] [content-visibility:auto]`,children:(0,J.jsxs)(lA.Root,{className:`aui-edit-composer-root border-foreground/10 focus-within:border-foreground/25 ms-auto flex w-full max-w-[85%] cursor-text flex-col rounded-(--composer-radius) border bg-(--composer-bg) transition-[border-color]`,children:[(0,J.jsx)(lA.Input,{className:`aui-edit-composer-input text-foreground min-h-14 w-full resize-none bg-transparent px-4 pt-3 pb-1 text-base outline-none`,autoFocus:!0}),(0,J.jsxs)(`div`,{className:`aui-edit-composer-footer mx-2.5 mb-2.5 flex items-center gap-1.5 self-end`,children:[(0,J.jsx)(lA.Cancel,{render:(0,J.jsx)(iU,{variant:`ghost`,size:`sm`,className:`h-8 px-3`}),children:`取消`}),(0,J.jsx)(lA.Send,{render:(0,J.jsx)(iU,{size:`sm`,className:`h-8 px-3`}),children:`更新`})]})]})}),r3=({className:e,...t})=>(0,J.jsxs)(aO.Root,{hideWhenSingleBranch:!0,className:Q(`aui-branch-picker-root text-muted-foreground -ms-2 me-2 inline-flex items-center text-xs`,e),...t,children:[(0,J.jsx)(aO.Previous,{render:(0,J.jsx)(SU,{tooltip:`上一条回复`}),children:(0,J.jsx)(WN,{})}),(0,J.jsxs)(`span`,{className:`aui-branch-picker-state font-medium`,children:[(0,J.jsx)(aO.Number,{}),` /`,` `,(0,J.jsx)(aO.Count,{})]}),(0,J.jsx)(aO.Next,{render:(0,J.jsx)(SU,{tooltip:`下一条回复`}),children:(0,J.jsx)(KN,{})})]});function i3({onSelect:e}){return(0,J.jsxs)(`div`,{className:`flex h-full flex-col bg-background text-foreground`,children:[(0,J.jsx)(`div`,{className:`p-4`,children:(0,J.jsxs)(xM.New,{render:(0,J.jsx)(`button`,{type:`button`,onClick:e,className:`\r
|
|
94
|
+
flex w-full items-center justify-center gap-2\r
|
|
95
|
+
rounded-lg border border-border\r
|
|
96
|
+
bg-background px-4 py-3\r
|
|
97
|
+
text-sm font-medium text-foreground\r
|
|
98
|
+
transition-colors\r
|
|
99
|
+
hover:bg-accent hover:text-accent-foreground\r
|
|
100
|
+
`}),children:[(0,J.jsx)(PP,{className:`size-4`}),`新建对话`]})}),(0,J.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-3 pb-4`,children:[(0,J.jsx)(`div`,{className:`mb-3 px-2 text-xs font-medium text-muted-foreground`,children:`历史对话`}),(0,J.jsx)(xM.Items,{children:({threadListItem:t})=>(0,J.jsxs)(OM.Root,{className:`\r
|
|
101
|
+
group mb-1 flex items-center rounded-lg\r
|
|
102
|
+
text-foreground transition-colors\r
|
|
103
|
+
hover:bg-accent hover:text-accent-foreground\r
|
|
104
|
+
data-active:bg-accent\r
|
|
105
|
+
data-active:text-accent-foreground\r
|
|
106
|
+
`,children:[(0,J.jsxs)(OM.Trigger,{render:(0,J.jsx)(`button`,{type:`button`,onClick:e,className:`\r
|
|
107
|
+
flex min-w-0 flex-1 items-center gap-3\r
|
|
108
|
+
px-3 py-3 text-left text-sm\r
|
|
109
|
+
`}),children:[(0,J.jsx)(bP,{className:`size-4 shrink-0 text-muted-foreground`}),(0,J.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:(0,J.jsx)(OM.Title,{fallback:`新对话`})})]}),(0,J.jsx)(OM.Delete,{render:(0,J.jsx)(`button`,{type:`button`,className:`\r
|
|
110
|
+
mr-2 rounded-md p-2\r
|
|
111
|
+
text-muted-foreground\r
|
|
112
|
+
opacity-0 transition-colors\r
|
|
113
|
+
hover:bg-destructive/10\r
|
|
114
|
+
hover:text-destructive\r
|
|
115
|
+
group-hover:opacity-100\r
|
|
116
|
+
focus-visible:opacity-100\r
|
|
117
|
+
`,title:`删除对话`}),children:(0,J.jsx)(KP,{className:`size-4`})})]},t.id)})]})]})}function a3(e){let{theme:t}=e,[n,r]=(0,f.useState)(`chat`),i=()=>{r(`chat`)};return(0,f.useEffect)(()=>{dN(t)},[t]),(0,J.jsxs)(xM.Root,{className:`flex h-full min-h-0 w-full flex-col overflow-hidden`,children:[(0,J.jsxs)(`div`,{className:`flex h-12 shrink-0 items-center border-b bg-background px-2`,children:[(0,J.jsxs)(`button`,{type:`button`,onClick:i,className:`flex h-9 flex-1 items-center justify-center gap-2 rounded-md text-sm transition-colors ${n===`chat`?`bg-accent font-medium text-foreground`:`text-muted-foreground hover:bg-accent/50`}`,children:[(0,J.jsx)(bP,{className:`size-4`}),`对话`]}),(0,J.jsxs)(`button`,{type:`button`,onClick:()=>r(`conversations`),className:`flex h-9 flex-1 items-center justify-center gap-2 rounded-md text-sm transition-colors ${n===`conversations`?`bg-accent font-medium text-foreground`:`text-muted-foreground hover:bg-accent/50`}`,children:[(0,J.jsx)(SP,{className:`size-4`}),`所有对话`]})]}),(0,J.jsx)(`div`,{className:`min-h-0 flex-1 flex-col overflow-hidden ${n===`chat`?`flex`:`hidden`}`,children:(0,J.jsx)(`div`,{className:`min-h-0 flex-1`,children:(0,J.jsx)(M4,{})})}),(0,J.jsx)(`div`,{className:`min-h-0 flex-1 overflow-hidden ${n===`conversations`?`block`:`hidden`}`,children:(0,J.jsx)(i3,{onSelect:i})})]})}exports.ChatApp=a3,exports.ChatRuntimeProvider=mN;
|