@fieldwangai/agentflow 0.1.136 → 0.1.138
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/bin/lib/prd-workflow-collaboration.mjs +218 -17
- package/bin/lib/ui-server.mjs +943 -59
- package/bin/lib/workflow-report.mjs +290 -30
- package/builtin/web-ui/dist/assets/WorkflowAssistantThread-B3thaqH2.js +6 -0
- package/builtin/web-ui/dist/assets/index-COX1zMwq.css +1 -0
- package/builtin/web-ui/dist/assets/index-YS4XOpXF.js +590 -0
- package/builtin/web-ui/dist/index.html +2 -2
- package/package.json +1 -1
- package/skills/agentflow-cli/SKILL.md +3 -1
- package/skills/agentflow-cli/scripts/agentflow-cli.mjs +33 -4
- package/skills/agentflow-cli/scripts/workflow-report-client.mjs +3 -0
- package/skills/agentflow-workflow-report/SKILL.md +17 -17
- package/skills/agentflow-workflow-report/references/protocol.md +118 -45
- package/builtin/web-ui/dist/assets/index-HdswcJWY.js +0 -565
- package/builtin/web-ui/dist/assets/index-KIGufzQf.css +0 -1
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
var Lo=Object.defineProperty;var Vo=(t,e,s)=>e in t?Lo(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s;var m=(t,e,s)=>Vo(t,typeof e!="symbol"?e+"":e,s);import{R as J,r as M,j as p,g as Uo,a as qo,b as Ho,M as zo}from"./index-YS4XOpXF.js";function Gt(){return Gt=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var s=arguments[e];for(var r in s)({}).hasOwnProperty.call(s,r)&&(t[r]=s[r])}return t},Gt.apply(null,arguments)}let je=null;function Go(t,e){t.currentIndex=0,t.wipContextDeps=null,t.wipCommitCallbacks=[];const s=je;je=t;try{if(e(),t.isFirstRender=!1,t.cells.length!==t.currentIndex)throw new Error(`Rendered ${t.currentIndex} hooks but expected ${t.cells.length}. Hooks must be called in the exact same order in every render.`)}finally{je=s}}function Se(){if(!je)throw new Error("No resource fiber available");return je}function Ve(){return je}const ls=Symbol("tap.Context.defaultValue"),Ko=t=>t;let ge=new Map;const Ie=new Set,Jr=()=>new Map(ge),Ks=(t,e)=>{const s=ge;ge=t;try{return e()}finally{ge=s}},Xr=(t,e)=>{t[ls]=e},Zr=t=>typeof t=="object"&&t!==null&&ls in t,en=t=>typeof t=="object"&&t!==null&&"$$typeof"in t&&t.$$typeof===Symbol.for("react.context"),us=t=>Zr(t)||en(t),tn=t=>{if(!Zr(t)){if(en(t)){Xr(t,t._currentValue??t._currentValue2);return}throw new Error("A tap resource's `use()` only accepts a tap context.")}},sn=(t,e,s)=>{if(typeof t!="object"||t===null)throw new Error("useContextProvider only accepts a React context.");tn(t);const r=t,n=Se(),i=V(void 0),o=i.current===void 0||!Object.is(i.current.value,e);N(()=>{i.current={value:e}},[e]);const a=ge.get(r),c=a!==void 0||ge.has(r);ge.set(r,{value:e,source:n});try{return Wo(r,o,s)}finally{c?ge.set(r,a):ge.delete(r)}},Wo=(t,e,s)=>{const r=Ie.has(t);e?Ie.add(t):Ie.delete(t);try{return s()}finally{r?Ie.add(t):Ie.delete(t)}},Qo=t=>{tn(t);const e=t,s=Yo(e,t),r=Se();return(r.wipContextDeps??(r.wipContextDeps=new Map)).set(e,s.source),s.value},Yo=(t,e)=>ge.get(t)??{value:Ko(e)[ls],source:null},Jo=(t,e,s,r)=>{if(!r)return s;let n=s;for(const[i,o]of r)o===e||o===t||(n??(n=new Map)).set(i,o);return n},rn=(t,e=t.wipContextDeps)=>{const s=Ve();!s||!e||(s.wipContextDeps=Jo(s,t,s.wipContextDeps,e))},nn=()=>Ie.size>0,ds=t=>{if(!t.contextDeps||!nn())return!1;for(const e of Ie.keys())if(t.contextDeps.has(e))return!0;return!1},hs=(t,e)=>{if(t.length!==0){if(t.length===1)throw t[0];for(const s of t)console.error(s);throw new AggregateError(t,e)}},ye={HookState:0,EffectEvent:1,PassiveEffectCleanup:2,PassiveEffectSetup:3},Xo=[ye.HookState,ye.EffectEvent,ye.PassiveEffectCleanup,ye.PassiveEffectSetup];function Zo(t){const e=[];for(const s of Xo){const r=t[s];if(r!==void 0)for(let n=0;n<r.length;n++)try{r[n]()}catch(i){e.push(i)}}hs(e,"Errors during commit")}function ea(t){var s;const e=[];for(const r of t.cells)if((r==null?void 0:r.type)==="effect"&&(r.deps=null,r.cleanup))try{(s=r.cleanup)==null||s.call(r)}catch(n){e.push(n)}finally{r.cleanup=void 0}hs(e,"Errors during cleanup")}const on=t=>({version:0,committedVersion:0,context:Jr(),dispatchUpdate:t,changelog:[],rollbackCallbacks:[]}),gt=t=>{t.committedVersion=t.version,t.changelog.length=0,t.rollbackCallbacks.length=0},We=(t,e)=>{const s=t.version>e;if(t.version=e,s){for(let r=0;r<t.rollbackCallbacks.length;r++)t.rollbackCallbacks[r]();if(t.rollbackCallbacks.length=0,e<=t.committedVersion)t.committedVersion=e,t.changelog.length=0;else{for(;t.committedVersion+t.changelog.length>e;)t.changelog.pop();for(let r=0;r<t.changelog.length;r++)an(t.changelog[r]);gt(t)}}},an=t=>{var e;ln(t.fiber,t.cell),t.queued||(t.queued=!0,((e=t.cell).queue??(e.queue=[])).push(t))},Xe=(t,e,s)=>{const r=t.wipCommitCallbacks;(r[e]??(r[e]=[])).push(s)},cn=(t,e)=>{t.rollbackCallbacks.push(e)},ln=(t,e)=>{var s;e.isDirty||(e.isDirty=!0,(s=t.markDirty)==null||s.call(t),cn(t.root,()=>{if(e.queue!==null){for(const r of e.queue)r.queued=!1;e.queue=null}e.workInProgress=e.current,e.isDirty=!1}))},fs=()=>{throw new Error("Rendered more hooks than during the previous render. Hooks must be called in the exact same order in every render.")},ps=()=>{throw new Error("Hook order changed between renders")},ta=(t,e,s)=>{if(t.isNeverMounted)throw new Error("Resource updated before mount");let r=!1,n=!0;t.root.dispatchUpdate(()=>(r||(r=!0,s&&t.root.changelog.length===0&&!e.cell.isDirty&&!e.hasEagerState&&(e.eagerState=s(e.cell.workInProgress,e.action),e.hasEagerState=!0,n=!Object.is(e.cell.current,e.eagerState))),n),()=>(r=!0,n=!0,an(e),t.root.changelog.push(e),!0))},sa=(t,e,s,r,n)=>{const i=r?r(s):s,o={type:"reducer",workInProgress:i,current:i,isDirty:!1,queue:null,renderQueue:null,reducer:e,dispatch:a=>{const c=Ve();if(c!==null){if(c!==t)throw new Error("Cannot update a resource while rendering a different resource.");(t.renderPendingCells??(t.renderPendingCells=new Set)).add(o),(o.renderQueue??(o.renderQueue=[])).push(a)}else ta(t,{fiber:t,cell:o,action:a,hasEagerState:!1,eagerState:void 0,queued:!1},n?e:void 0)}};return o};function un(t,e,s,r){var l;const n=Se(),i=n.currentIndex++,o=n.cells[i],a=(()=>{if(o!==void 0)return o.type==="reducer"?o:ps();!n.isFirstRender&&i>=n.cells.length&&fs();const u=sa(n,t,e,s,r);return n.cells[i]=u,u})(),c=a.queue;if(c!==null){const u=t===a.reducer;for(let h=0;h<c.length;h++){const d=c[h];(!d.hasEagerState||!u)&&(d.eagerState=t(a.workInProgress,d.action),d.hasEagerState=!0),d.queued=!1,a.workInProgress=d.eagerState}a.queue=null}if(a.reducer=t,a.renderQueue!==null){let u=a.workInProgress;for(const h of a.renderQueue)u=t(u,h);a.renderQueue=null,(l=n.renderPendingCells)==null||l.delete(a),Object.is(u,a.workInProgress)||(ln(n,a),a.workInProgress=u)}return a.isDirty&&Xe(n,ye.HookState,()=>{a.current=a.workInProgress,a.isDirty=!1}),[a.workInProgress,a.dispatch]}function dn(t,e,s){return un(t,e,s,!1)}const ra=(t,e)=>typeof e=="function"?e(t):e,na=t=>t===void 0?void 0:typeof t=="function"?t():t;function gs(t){return un(ra,t,na,!0)}const Et=(t,e)=>{for(let s=0;s<t.length&&s<e.length;s++)if(!Object.is(t[s],e[s]))return!1;return!0},Ws=(t,e)=>{Xe(t,ye.HookState,()=>{e.current=e.wip,e.currentDeps=e.wipDeps,e.isDirty=!1})},Rt=(t,e)=>{const s=Se(),r=s.currentIndex++;let n=s.cells[r];if(n===void 0){!s.isFirstRender&&r>=s.cells.length&&fs();const a=t();return n={type:"memo",current:a,currentDeps:e,wip:a,wipDeps:e,isDirty:!1},s.cells[r]=n,a}n.type!=="memo"&&ps();const i=n;if(Et(i.wipDeps,e))return i.isDirty&&Ws(s,i),i.wip;const o=t();return i.wip=o,i.wipDeps=e,i.isDirty||(i.isDirty=!0,cn(s.root,()=>{i.wip=i.current,i.wipDeps=i.currentDeps,i.isDirty=!1})),Ws(s,i),o};function At(t){return Rt(()=>({current:t}),[])}const ms=(t,e)=>Rt(()=>t,e),ia=()=>({type:"effect",cleanup:void 0,deps:null});function Be(t,e){const s=Se(),r=s.currentIndex++,n=s.cells[r],i=n===void 0?ia():n.type==="effect"?n:ps();if(n===void 0&&(!s.isFirstRender&&r>=s.cells.length&&fs(),s.cells[r]=i),!(e&&i.deps&&Et(i.deps,e))){if(i.deps!==null&&!!e!=!!i.deps)throw new Error("useEffect called with and without dependencies across re-renders");Xe(s,ye.PassiveEffectCleanup,()=>{var o;try{(o=i.cleanup)==null||o.call(i)}finally{i.cleanup=void 0}}),Xe(s,ye.PassiveEffectSetup,()=>{try{const o=t();if(o!==void 0&&typeof o!="function")throw new Error(`An effect function must either return a cleanup function or nothing. Received: ${typeof o}`);i.cleanup=o}finally{i.deps=e}})}}function bs(t){const e=Se(),s=At(t);return s.current!==t&&Xe(e,ye.EffectEvent,()=>{s.current=t}),ms((...r)=>s.current(...r),[])}const mt=t=>{if(!us(t))throw new Error("A tap resource's `use()` only accepts a tap context.");return Qo(t)},hn=(t,e,s=e)=>{const r=At(!0),n=r.current?s():e();r.current=!1;const[,i]=gs(0),o=bs(()=>{try{if(Object.is(n,e()))return}catch{return}i(a=>a+1)});return Be(()=>(o(),t(o)),[t]),n},fn=(t,e)=>{},oa=J;function aa(t){const e=M.useRef(t);return M.useInsertionEffect(()=>{e.current=t}),M.useCallback((...s)=>e.current(...s),[])}const ca=oa.useEffectEvent??aa,ie=()=>Ve()!==null,oe=J,G=t=>ie()?gs(t):oe.useState(t),la=(t,e,s)=>ie()?dn(t,e,s):oe.useReducer(t,e,s),V=t=>ie()?At(t):oe.useRef(t),Y=(t,e)=>ie()?Rt(t,e):oe.useMemo(t,e),Qe=(t,e)=>ie()?ms(t,e):oe.useCallback(t,e),N=(t,e)=>ie()?Be(t,e):oe.useEffect(t,e),bt=(t,e)=>ie()?Be(t,e):oe.useLayoutEffect(t,e),le=t=>ie()?bs(t):ca(t),Ue=(t,e,s)=>ie()?hn(t,e,s):oe.useSyncExternalStore(t,e,s),ua=(t,e)=>ie()?fn():oe.useDebugValue(t,e),ae=t=>{const e=oe.createContext(t);return Xr(e,t),e},pn=t=>ie()&&us(t)?mt(t):oe.use(t),he=t=>ie()&&us(t)?mt(t):oe.useContext(t),gn=Symbol.for("react.memo_cache_sentinel"),mn=t=>new Array(t).fill(gn),da=(t,e)=>{const s=t.memoCache;let r=s.workInProgress;if(r===null){const o=s.current;r=o===null?[]:o.map(a=>a.slice()),s.workInProgress=r}const n=s.index++;let i=r[n];return i===void 0&&(i=mn(e),r[n]=i),i},bn=t=>da(Se(),t),ha=J,fa=t=>M.useMemo(()=>{const e=mn(t);return e[gn]=!0,e},[]);var Yr;const pa=((Yr=ha.__COMPILER_RUNTIME)==null?void 0:Yr.c)??fa,ga=()=>Ve()!==null,_=t=>ga()?bn(t):pa(t);function q(t){return(...e)=>({hook:t,args:e})}function ne(t,e,s){return typeof e=="function"?(...r)=>ne(t,e(...r)):s?{...e,key:t,deps:s}:{...e,key:t}}const ma=50;let me={schedulers:new Set([]),isScheduled:!1},_e=null;var ba=class{constructor(t){m(this,"_isDirty",!1);m(this,"_task");this._task=t}get isDirty(){return this._isDirty}markDirty(){if(_e&&(_e.get(this)??0)>=ma)throw new Error("Maximum update depth exceeded. This can happen when a resource repeatedly calls setState inside useEffect.");this._isDirty=!0,me.schedulers.add(this),_a()}runTask(){_e==null||_e.set(this,(_e.get(this)??0)+1),this._isDirty=!1,this._task()}};const _a=()=>{me.isScheduled||(me.isScheduled=!0,ya())},Kt=()=>{const t=_e;_e=new Map;try{const e=[];for(const s of me.schedulers)if(me.schedulers.delete(s),!!s.isDirty)try{s.runTask()}catch(r){e.push(r)}hs(e,"Errors occurred during flushSync")}finally{_e=t,me.schedulers.clear(),me.isScheduled=!1}},ya=(()=>{if(typeof MessageChannel<"u"){let t=null,e;return()=>{var s;if(!t){const r=new MessageChannel;r.port1.onmessage=()=>{var n;(n=t==null?void 0:t.unref)==null||n.call(t),Kt()},t=r.port1,e=r.port2}(s=t.ref)==null||s.call(t),e.postMessage(null)}}return()=>setTimeout(Kt,0)})(),Qs=t=>{const e=me;me={schedulers:new Set([]),isScheduled:!0};try{const s=t();return Kt(),s}finally{me=e}},va={useState:gs,useReducer:dn,useRef:At,useMemo:Rt,useCallback:ms,useEffect:Be,useLayoutEffect:Be,useInsertionEffect:Be,useEffectEvent:bs,useContext:mt,use:mt,useSyncExternalStore:hn,useDebugValue:fn,useMemoCache:bn},Ys=J,Te=Ys.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE??Ys.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,nt=Te==null?null:"H"in Te?{get current(){return Te.H},set current(t){Te.H=t}}:"ReactCurrentDispatcher"in Te?{get current(){return Te.ReactCurrentDispatcher.current},set current(t){Te.ReactCurrentDispatcher.current=t}}:null;function Sa(t){if(!nt)return t();const e=nt.current;nt.current=va;try{return t()}finally{nt.current=e}}function _n(t,e,s=void 0,r){return{hook:t,root:e,markDirty:s,devStrictMode:r,cells:[],contextDeps:null,wipContextDeps:null,commitCallbacks:null,wipCommitCallbacks:null,memoCache:{current:null,workInProgress:null,index:0},renderPendingCells:null,currentIndex:0,isFirstRender:!0,isMounted:!1,isNeverMounted:!0}}function Oe(t){if(!t.isMounted)throw new Error("Tried to unmount a fiber that is already unmounted");t.isMounted=!1,ea(t)}function Ee(t,e){var n;if(t.memoCache.workInProgress=null,t.renderPendingCells!==null){for(const i of t.renderPendingCells)i.renderQueue=null;t.renderPendingCells.clear()}let s=0,r;do{if(++s>25)throw new Error("Too many re-renders. tap limits the number of renders to prevent an infinite loop.");t.memoCache.index=0,Go(t,()=>{r=Sa(()=>t.hook(...e))})}while((((n=t.renderPendingCells)==null?void 0:n.size)??0)>0);return rn(t),r}function Ze(t){const e=t.wipCommitCallbacks??t.commitCallbacks??[];t.wipCommitCallbacks=null,t.commitCallbacks=e,t.isMounted=!0,t.contextDeps=t.wipContextDeps,gt(t.root),t.memoCache.workInProgress!==null&&(t.memoCache.current=t.memoCache.workInProgress,t.memoCache.workInProgress=null),t.isNeverMounted=!1,Zo(e)}const xa=()=>{const t=Se();return t.devStrictMode?t.isFirstRender?"child":"root":null},wa=()=>null,Ta=()=>wa,yn=()=>Ve()?xa:Ta(),Ca=t=>t(),Ia=t=>{const[e]=G(()=>new ba(()=>f())),[s]=G(()=>[]),r=yn(),[n]=G(()=>{const g=on((b,v)=>{if(!e.isDirty){if(!b())return;v()}We(g,g.committedVersion+g.changelog.length),s.push(v),e.markDirty()});return _n(Ca,g,void 0,r())}),i=Jr(),o=n.root.version-n.root.committedVersion,a=Ks(i,()=>Ee(n,[t])),c=V(!1),l=V([t]),u=V(a),[h]=G(()=>new Set),d=g=>{e.isDirty||u.current===g||(u.current=g,h.forEach(b=>b()))},f=le(()=>{We(n.root,n.root.committedVersion),s.forEach(b=>{b()}),We(n.root,n.root.committedVersion+n.root.changelog.length);const g=Ks(n.root.context,()=>Ee(n,l.current));if(e.isDirty)throw new Error("Scheduler is dirty, this should never happen");gt(n.root),s.length=0,c.current&&Ze(n),d(g)});return N(()=>(c.current=!0,()=>{c.current=!1,Oe(n)}),[n]),N(()=>{l.current=[t],gt(n.root),s.splice(0,o),n.root.context=i,Ze(n),d(a)}),Y(()=>({getValue:()=>u.current,subscribe:g=>(h.add(g),()=>h.delete(g))}),[h])},Ea=()=>{const t=V(0),e=t.current,s=Se();return{version:e,markDirty:Y(()=>()=>{var r;t.current++,(r=s==null?void 0:s.markDirty)==null||r.call(s)},[s]),root:s.root}},Ra=()=>{const[t]=G(()=>on((n,i)=>{let o=!1;r(a=>(o=!n(),o?a:a+1)),o||s(i)})),[e,s]=la((n,i)=>(We(t,n),n+(i()?1:0)),0),[,r]=G(0);return We(t,e),{root:t,version:e,markDirty:void 0}},_s=()=>{const t=yn(),{root:e,version:s,markDirty:r}=Ve()?Ea():Ra();return{version:s,createFiber:Qe((n,i,o)=>_n(n,e,o?()=>{o(),r==null||r()}:r,t()),[])}},vn=(t,e,s)=>{const r=V(null),n=r.current??(r.current={wipDeps:null,wip:null,currentDeps:null,current:null});return n.wipDeps=n.currentDeps,n.wip=n.current,N(()=>{n.currentDeps=n.wipDeps,n.current=n.wip}),!s&&n.currentDeps&&Et(n.currentDeps,e)?n.current:(n.wipDeps=e,n.wip=t(),n.wip)};function se(t){const{version:e,createFiber:s}=_s(),r=Y(()=>s(t.hook,t.key),[t.hook,t.key,s]),n=vn(()=>({value:Ee(r,t.args)}),[r,e,t.args],ds(r));return N(()=>()=>Oe(r),[r]),N(()=>{Ze(r)},[r,n]),n.value}const Js=(t,e)=>{const s=t.get(e);s&&(s.isDirty=!0)},Aa=(t,e)=>!t.isDirty&&!ds(t.fiber)&&e!==void 0&&t.committedDeps!==void 0&&Et(t.committedDeps,e),Ma=t=>{if(!nn())return!1;for(const{fiber:e}of t.values())if(ds(e))return!0;return!1};function Mt(t){const[e]=G(()=>new Map),{version:s,createFiber:r}=_s(),n=Ma(e),i=vn(()=>{const o=new Set,a=[];let c=0;for(let l=0;l<t.length;l++){const u=t[l],h=u.key;if(h===void 0)throw new Error(`useResources did not provide a key for array at index ${l}`);if(o.has(h))throw new Error(`Duplicate key ${h} in useResources`);o.add(h);let d=e.get(h);if(d)if(d.fiber.hook!==u.hook){const f=r(u.hook,u.key,()=>Js(e,h)),g=Ee(f,u.args);d.next={value:g,deps:u.deps,remount:f}}else if(Aa(d,u.deps))d.fiber.contextDeps&&rn(d.fiber,d.fiber.contextDeps),d.next="skip";else{const f=Ee(d.fiber,u.args);d.next={value:f,deps:u.deps}}else{const f=r(u.hook,u.key,()=>Js(e,h));d={fiber:f,next:{value:Ee(f,u.args),deps:u.deps},isDirty:!1,committedDeps:void 0,committedValue:void 0},c++,e.set(h,d)}a.push(typeof d.next=="object"?d.next.value:d.committedValue)}if(e.size>a.length-c)for(const l of e.keys())o.has(l)||(e.get(l).next="delete");return a},[t,e,r,s],n);return N(()=>()=>{for(const o of e.keys()){const a=e.get(o).fiber;Oe(a)}},[e]),N(()=>{for(const[o,a]of e.entries()){const c=a.next;c==="delete"?(a.fiber.isMounted&&Oe(a.fiber),e.delete(o)):c==="skip"||(c.remount&&(Oe(a.fiber),a.fiber=c.remount),Ze(a.fiber),a.committedDeps=c.deps,a.committedValue=c.value,a.isDirty=!1)}},[i,e]),i}const Pa=t=>t(),ka=t=>{const{createFiber:e}=_s(),s=Y(()=>e(Pa,void 0),[e]),r=Ee(s,[t]);N(()=>()=>{Oe(s)},[s]);let n=!1;const i=()=>{n&&s.isMounted||(n=!0,Ze(s))};return N(i),{value:r,effects:i}},$a=()=>{const t=_(4),[e,s]=G(ja);let r;t[0]===Symbol.for("react.memo_cache_sentinel")?(r=(c,l)=>(s(u=>({...u,renderers:{...u.renderers,[c]:[...u.renderers[c]??[],l]}})),()=>{s(u=>{var h;return{...u,renderers:{...u.renderers,[c]:((h=u.renderers[c])==null?void 0:h.filter(d=>d!==l))??[]}}})}),t[0]=r):r=t[0];const n=r;let i;t[1]===Symbol.for("react.memo_cache_sentinel")?(i=c=>(s(l=>({...l,fallbacks:[...l.fallbacks,c]})),()=>{s(l=>({...l,fallbacks:l.fallbacks.filter(u=>u!==c)}))}),t[1]=i):i=t[1];const o=i;let a;return t[2]!==e?(a={getState:()=>e,setDataUI:n,setFallbackDataUI:o},t[2]=e,t[3]=a):a=t[3],a},Da=q($a);function ja(){return{renderers:{},fallbacks:[]}}const Ba=t=>{const e=Array.from(t).map(r=>r.getModelContext()).sort((r,n)=>(n.priority??0)-(r.priority??0)),s={};return e.reduce((r,n)=>{var o;const i=n.priority??0;if(n.system&&(r.system?r.system+=`
|
|
2
|
+
|
|
3
|
+
${n.system}`:r.system=n.system),n.tools)for(const[a,c]of Object.entries(n.tools)){const l=(o=r.tools)==null?void 0:o[a];if(l&&l!==c){const u=s[a];if(u===i)throw new Error(`You tried to define a tool with the name ${a}, but it already exists.`);const h=u>i?l:c,d=u>i?c:l;r.tools[a]={...d,...h},s[a]=Math.max(u,i);continue}r.tools||(r.tools={}),r.tools[a]=c,s[a]??(s[a]=i)}return n.config&&(r.config={...r.config,...n.config}),n.callSettings&&(r.callSettings={...r.callSettings,...n.callSettings}),n.unstable_composerMetadata&&(r.unstable_composerMetadata={...r.unstable_composerMetadata,...n.unstable_composerMetadata}),r},{})};var Sn=class{constructor(){m(this,"_providers",new Set);m(this,"_subscribers",new Set)}getModelContext(){return Ba(this._providers)}registerModelContextProvider(t){var s;this._providers.add(t);const e=(s=t.subscribe)==null?void 0:s.call(t,()=>{this.notifySubscribers()});return this.notifySubscribers(),()=>{this._providers.delete(t),e==null||e(),this.notifySubscribers()}}notifySubscribers(){for(const t of this._subscribers)t()}subscribe(t){return this._subscribers.add(t),()=>{this._subscribers.delete(t)}}};const Wt=[],Oa={modelName:void 0,toolNames:Wt},Na=(t,e)=>t===e||t.length===e.length&&t.every((s,r)=>s===e[r]),it=(t,e)=>{var o;const s=t.getModelContext(),r=(o=s.config)==null?void 0:o.modelName,n=s.tools?Object.keys(s.tools).sort():Wt,i=n.length?n:Wt;return r===e.modelName&&Na(i,e.toolNames)?e:{modelName:r,toolNames:i}},Fa=()=>{const t=_(11);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=new Sn,t[0]=e):e=t[0];const s=e;let r;t[1]===Symbol.for("react.memo_cache_sentinel")?(r=()=>it(s,Oa),t[1]=r):r=t[1];const[n,i]=G(r);let o,a;t[2]===Symbol.for("react.memo_cache_sentinel")?(o=()=>(i(f=>it(s,f)),s.subscribe(()=>{i(f=>it(s,f))})),a=[s],t[2]=o,t[3]=a):(o=t[2],a=t[3]),N(o,a);let c;t[4]!==n?(c=()=>it(s,n),t[4]=n,t[5]=c):c=t[5];let l,u,h;t[6]===Symbol.for("react.memo_cache_sentinel")?(l=()=>s.getModelContext(),u=f=>s.subscribe(f),h=f=>s.registerModelContextProvider(f),t[6]=l,t[7]=u,t[8]=h):(l=t[6],u=t[7],h=t[8]);let d;return t[9]!==c?(d={getState:c,getModelContext:l,subscribe:u,register:h},t[9]=c,t[10]=d):d=t[10],d},xn=q(Fa),La=t=>t.display!==void 0?t.display==="standalone":t.type==="human",Va=(t,e)=>{var r,n;if(!(((r=e.status)==null?void 0:r.type)==="running"||((n=e.status)==null?void 0:n.type)==="requires-action")){const i=t.complete;return typeof i!="function"?i??null:i({args:e.args,result:e.result})}const s=t.running;return typeof s!="function"?s??null:s({args:e.args})},Ua=t=>function(s){return Va(t,s)},Qt=Symbol("assistant-ui.store.clientIndex"),qa=t=>t[Qt],wn=ae([]),ys=()=>pn(wn),Ha=(t,e)=>{const s=_(3),r=ys();let n;return s[0]!==t||s[1]!==r?(n=[...r,t],s[0]=t,s[1]=r,s[2]=n):n=s[2],sn(wn,n,e)},za=new Set(["$$typeof","nodeType","then"]),Pt=(t,e)=>{if(t===Symbol.toStringTag)return e;if(typeof t!="symbol"){if(t==="toJSON")return()=>e;if(!za.has(t))return!1}};var vs=class{getOwnPropertyDescriptor(t,e){const s=this.get(t,e);if(s!==void 0)return{value:s,writable:!1,enumerable:!0,configurable:!1}}set(){return!1}setPrototypeOf(){return!1}defineProperty(){return!1}deleteProperty(){return!1}preventExtensions(){return!1}};const _t=Symbol("assistant-ui.store.getValue"),Ga=t=>{var s;const e=t[_t];if(!e)throw new Error("Client scope contains a non-client resource. Ensure your Derived get() returns a client created with useClientResource(), not a plain resource.");return(s=e.getState)==null?void 0:s.call(e)},Xs=new Map;function Ka(t){let e=Xs.get(t);return e||(e=function(...s){if(!this||typeof this!="object")throw new Error(`Method "${String(t)}" called without proper context. This may indicate the function was called incorrectly.`);const r=this[_t];if(!r)throw new Error(`Method "${String(t)}" called on invalid client proxy. Ensure you are calling this method on a valid client instance.`);const n=r[t];if(!n)throw new Error(`Method "${String(t)}" is not implemented.`);if(typeof n!="function")throw new Error(`"${String(t)}" is not a function.`);return n(...s)},Xs.set(t,e)),e}var Wa=class extends vs{constructor(e,s){super();m(this,"boundFns");m(this,"cachedReceiver");m(this,"outputRef");m(this,"index");this.outputRef=e,this.index=s}get(e,s,r){if(s===_t)return this.outputRef.current;if(s===Qt)return this.index;const n=Pt(s,"ClientProxy");if(n!==!1)return n;const i=this.outputRef.current[s];if(typeof i=="function"){this.cachedReceiver!==r&&(this.boundFns=new Map,this.cachedReceiver=r);let o=this.boundFns.get(s);return o||(o=Ka(s).bind(r),this.boundFns.set(s,o)),o}return i}ownKeys(){return Object.keys(this.outputRef.current)}has(e,s){return s===_t||s===Qt?!0:s in this.outputRef.current}};const tt=t=>{var i;const e=V(null),s=ys().length,r=Y(()=>new Proxy({},new Wa(e,s)),[s]),n=Ha(r,function(){return se(t)});return e.current||(e.current=n),N(()=>{e.current=n}),{methods:r,state:(i=n.getState)==null?void 0:i.call(n),key:t.key}},Qa=q(tt),Ye=Symbol("assistant-ui.store.proxiedAssistantState"),Bt=t=>t==="on"||t==="subscribe"||typeof t=="symbol",Tn=t=>{class e extends vs{get(r,n){const i=Pt(n,"AssistantState");if(i!==!1)return i;const o=n;if(!Bt(o))return Ga(t[o]())}ownKeys(){return Object.keys(t).filter(r=>!Bt(r))}has(r,n){return!Bt(n)&&n in t}}return new Proxy({},new e)},Ya=t=>t[Ye],Zs=()=>()=>{},Cn=t=>{const e=()=>{throw new Error(t)};return e.source=null,e.query=null,e};var Ja=class extends vs{get(t,e){if(e==="subscribe"||e==="on")return Zs;if(e===Ye)return Xa;const s=Pt(e,"DefaultAssistantClient");return s!==!1?s:Cn("You are using a component or hook that requires an AuiProvider. Wrap your component in an <AuiProvider> component.")}ownKeys(){return["subscribe","on",Ye]}has(t,e){return e==="subscribe"||e==="on"||e===Ye}};const kt=new Proxy({},new Ja),Xa=Tn(kt),Za=()=>new Proxy({},{get(t,e){const s=Pt(e,"AssistantClient");return s!==!1?s:Cn(`The current scope does not have a "${String(e)}" property.`)}}),In=ae(kt),En=Symbol("assistant-ui.store.useEffects"),ec=()=>{},tc=t=>t[En]??ec,sc=()=>{"use no memo";const t=Rn();return N(tc(t)),null},Rn=()=>he(In),ue=({value:t,children:e})=>{"use no memo";return p.jsxs(In.Provider,{value:t,children:[p.jsx(sc,{}),e]})},Yt=t=>{throw new Error("Derived elements are config-only and must not be mounted")},re=q(Yt),Jt=Symbol("assistant-ui.transform-scopes");function An(t,e){const s=t;if(s[Jt])throw new Error("transformScopes is already attached to this resource");s[Jt]=e}function rc(t){return t[Jt]}const Mn=t=>typeof t=="string"?{scope:t.split(".")[0],event:t}:{scope:t.scope,event:t.event},Pn=ae(null),nc=(t,e)=>sn(Pn,t,e),kn=()=>{const t=pn(Pn);if(!t)throw new Error("AssistantTapContext is not available");return t},$n=()=>kn().clientRef,Ss=()=>{const t=_(3),{emit:e}=kn(),s=ys();let r;return t[0]!==s||t[1]!==e?(r=(n,i)=>{e(n,i,s)},t[0]=s,t[1]=e,t[2]=r):r=t[2],le(r)};function ic(t,e){const s={...t},r=new Set;let n=!0;for(;n;){n=!1;for(const a of Object.values(s)){if(a.hook===Yt||r.has(a.hook))continue;r.add(a.hook);const c=rc(a.hook);if(c){c(s,e),n=!0;break}}}const i={},o={};for(const[a,c]of Object.entries(s))c.hook===Yt?o[a]=c:i[a]=c;return{rootClients:i,derivedClients:o}}const er=t=>Y(()=>t,[...Object.entries(t).flat()]),oc=(t,e)=>{const s=_(6);let r;s[0]!==e||s[1]!==t?(r=ic(t,e),s[0]=e,s[1]=t,s[2]=r):r=s[2];const{rootClients:n,derivedClients:i}=r,o=er(n),a=er(i);let c;return s[3]!==o||s[4]!==a?(c={rootClients:o,derivedClients:a},s[3]=o,s[4]=a,s[5]=c):c=s[5],c},ac=()=>{const t=_(3);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=new Map,t[0]=e):e=t[0];const s=e;let r;t[1]===Symbol.for("react.memo_cache_sentinel")?(r=new Set,t[1]=r):r=t[1];const n=r;let i;if(t[2]===Symbol.for("react.memo_cache_sentinel")){const o=new Set;i={on(a,c){const l=c;if(a==="*")return n.add(l),()=>n.delete(l);let u=s.get(a);return u||(u=new Set,s.set(a,u)),u.add(l),()=>{u.delete(l),u.size===0&&s.delete(a)}},emit(a,c,l){const u=s.get(a);!u&&n.size===0||queueMicrotask(()=>{const h=[];if(u)for(const d of u)try{d(c,l)}catch(f){const g=f;h.push(g)}if(n.size>0){const d={event:a,payload:c};for(const f of n)try{f(d,l)}catch(g){const b=g;h.push(b)}}if(h.length>0){if(h.length===1)throw h[0];for(const d of h)console.error(d);throw new AggregateError(h,"Errors occurred during event emission")}})},subscribe(a){return o.add(a),()=>o.delete(a)},notifySubscribers(){for(const a of o)try{a()}catch(c){console.error("NotificationManager: subscriber callback error",c)}}},t[2]=i}else i=t[2];return i},cc=q(ac),Dn=t=>Y(()=>t,t),lc=({element:t,emit:e,clientRef:s})=>{const{methods:r,state:n}=nc({clientRef:s,emit:e},function(){return tt(t)});return Y(()=>({state:n,methods:r}),[r,n])},uc=({element:t,notifications:e,clientRef:s,name:r})=>{const n=Ia(function(){return lc({element:t,emit:e.emit,clientRef:s})});return N(()=>n.subscribe(e.notifySubscribers),[n,e]),Y(()=>{const i=()=>n.getValue().methods;return Object.defineProperties(i,{source:{value:"root",writable:!1},query:{value:{},writable:!1},name:{value:r,configurable:!0}}),i},[n,r])},dc=q(uc),hc=()=>{const t=_(2);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=[],t[0]=e):e=t[0];let s;return t[1]===Symbol.for("react.memo_cache_sentinel")?(s={clients:e,subscribe:void 0,on:void 0},t[1]=s):s=t[1],s},fc=q(hc),pc=t=>{const e=_(14),{clients:s,clientRef:r}=t;let n;e[0]===Symbol.for("react.memo_cache_sentinel")?(n=cc(),e[0]=n):n=e[0];const i=se(n);let o;e[1]!==r.parent||e[2]!==i.notifySubscribers?(o=()=>r.parent.subscribe(i.notifySubscribers),e[1]=r.parent,e[2]=i.notifySubscribers,e[3]=o):o=e[3];let a;e[4]!==r||e[5]!==i?(a=[r,i],e[4]=r,e[5]=i,e[6]=a):a=e[6],N(o,a);let c;e[7]!==r||e[8]!==s||e[9]!==i?(c=Object.keys(s).map(h=>ne(h,dc({element:s[h],notifications:i,clientRef:r,name:h}))),e[7]=r,e[8]=s,e[9]=i,e[10]=c):c=e[10];const l=Dn(Mt(c));let u;return e[11]!==i||e[12]!==l?(u={notifications:i,results:l},e[11]=i,e[12]=l,e[13]=u):u=e[13],u},gc=t=>{const{clientRef:e}=t,{notifications:s,results:r}=pc(t);return Y(()=>({clients:r,subscribe:s.subscribe,on:function(n,i){if(!this)throw new Error("const { on } = useAui() is not supported. Use aui.on() instead.");const{scope:o,event:a}=Mn(n);if(o!=="*"&&this[o].source===null)throw new Error(`Scope "${o}" is not available. Use { scope: "*", event: "${a}" } to listen globally.`);const c=s.on(a,(u,h)=>{if(o==="*"){i(u);return}const d=this[o]();d===h[qa(d)]&&i(u)});if(o!=="*"&&e.parent[o].source===null)return c;const l=e.parent.on(n,i);return()=>{c(),l()}}}),[r,s,e])},mc=q(gc),bc=({element:t,clientRef:e,name:s})=>{const r=V(t.args[0]);return r.current=t.args[0],Y(()=>{const n=()=>r.current.get(e.current);return Object.defineProperties(n,{source:{value:r.current.source},query:{value:r.current.query},name:{value:s,configurable:!0}}),n},[e,s])},_c=q(bc),yc=(t,e)=>{let s;try{const r={};for(const n of Object.keys(e.query).sort())r[n]=e.query[n];s=JSON.stringify(r)}catch{s=String(e.query)}return`${t}::${e.source}::${s}`},vc=t=>{const e=_(3),{clients:s,clientRef:r}=t;let n;return e[0]!==r||e[1]!==s?(n=Object.keys(s).map(i=>{const o=i,a=s[o];return ne(yc(o,a.args[0]),_c({element:a,clientRef:r,name:o}))}),e[0]=r,e[1]=s,e[2]=n):n=e[2],Dn(Mt(n))},Sc=t=>{const e=_(3),{rootClients:s,clientRef:r}=t;let n;return e[0]!==r||e[1]!==s?(n=Object.keys(s).length>0?mc({clients:s,clientRef:r}):fc(),e[0]=r,e[1]=s,e[2]=n):n=e[2],se(n)},xc=({parent:t,clients:e})=>{const{rootClients:s,derivedClients:r}=oc(e,t),n=V({parent:t,current:null}).current;N(()=>{n.current=a});const i=Sc({rootClients:s,clientRef:n}),o=vc({clients:r,clientRef:n}),a=Y(()=>{const c=t===kt?Za():t,l=Object.create(c);Object.assign(l,{subscribe:i.subscribe??t.subscribe,on:i.on??t.on,[Ye]:Tn(l)});for(const u of i.clients)l[u.name]=u;for(const u of o)l[u.name]=u;return l},[t,i,o]);return n.current===null&&(n.current=a),a},wc=t=>{const{value:e,effects:s}=ka(function(){return xc(t)});return e[En]=s,e};function F(t,{parent:e}={parent:Rn()}){if(t)return wc({parent:e??kt,clients:t});if(e===null)throw new Error("received null parent, this usage is not allowed");return e}const P=t=>{const e=_(6),s=F();let r;e[0]!==s?(r=Ya(s),e[0]=s,e[1]=r):r=e[1];const n=r;let i,o;e[2]!==n||e[3]!==t?(i=()=>t(n),o=()=>t(n),e[2]=n,e[3]=t,e[4]=i,e[5]=o):(i=e[4],o=e[5]);const a=Ue(s.subscribe,i,o);if(a===n)throw new Error("You tried to return the entire AssistantState. This is not supported due to technical limitations.");return ua(a),a},Tc=t=>{const e=F(),s=V(!1),r=s.current?null:t(e);return P(()=>s.current?t(e):r),()=>(s.current=!0,t(e))},Cc=Object.freeze({});function qe(t){const e=_(3),{getItemState:s,children:r}=t,n=Tc(s);let i;return e[0]!==r||e[1]!==n?(i=r(n),e[0]=r,e[1]=n,e[2]=i):i=e[2],Ic(i)}const Ic=t=>{const e=typeof t=="object"&&t!=null&&"type"in t?t:null,s=e==null?void 0:e.type,r=e==null?void 0:e.key;return Y(()=>e,[s,r,typeof(e==null?void 0:e.props)=="object"&&e.props!=null&&Object.entries(e.props).length===0?Cc:e==null?void 0:e.props])??t},Ec=J.createContext(!0);function tr(){throw new Error("A function wrapped in useEffectEvent can't be called during rendering.")}const Rc="use"in J?()=>{try{return J.use(Ec)}catch{return!1}}:()=>!1;function Ac(t){const e=J.useRef(tr);return J.useInsertionEffect(()=>{e.current=t},[t]),(...s)=>{Rc()&&tr();const r=e.current;return r(...s)}}const yt=(t,e)=>{const s=_(11),r=F(),n=Ac(e);let i;s[0]!==t?(i=Mn(t),s[0]=t,s[1]=i):i=s[1];const{scope:o,event:a}=i;let c;s[2]!==r||s[3]!==n||s[4]!==a||s[5]!==o?(c=()=>r.on({scope:o,event:a},n),s[2]=r,s[3]=n,s[4]=a,s[5]=o,s[6]=c):c=s[6];let l;s[7]!==r||s[8]!==a||s[9]!==o?(l=[r,o,a],s[7]=r,s[8]=a,s[9]=o,s[10]=l):l=s[10],N(c,l)},Mc=t=>{if(t.key===void 0)throw new Error("useClientLookup: Element has no key");return t.key};function Re(t){const e=_(15);let s;e[0]!==t?(s=t.map($c),e[0]=t,e[1]=s):s=e[1];const r=Mt(s);let n;e[2]!==r?(n=Object.keys(r),e[2]=r,e[3]=n):n=e[3];const i=n;let o;e[4]!==r?(o=r.reduce(kc,{}),e[4]=r,e[5]=o):o=e[5];const a=o;let c;e[6]!==r?(c=r.map(Pc),e[6]=r,e[7]=c):c=e[7];const l=c;let u;e[8]!==a||e[9]!==i||e[10]!==r?(u=d=>{if("index"in d){if(d.index<0||i.length===0)throw new Error(`useClientLookup: Index ${d.index} out of bounds (length: ${i.length})`);const g=Math.min(d.index,i.length-1);return g!==d.index&&console.warn(`useClientLookup: Clamped stale index ${d.index} to ${g} (length: ${i.length})`),r[g].methods}const f=a[d.key];if(f===void 0)throw new Error(`useClientLookup: Key "${d.key}" not found`);return r[f].methods},e[8]=a,e[9]=i,e[10]=r,e[11]=u):u=e[11];let h;return e[12]!==l||e[13]!==u?(h={state:l,get:u},e[12]=l,e[13]=u,e[14]=h):h=e[14],h}function Pc(t){return t.state}function kc(t,e,s){return t[e.key]=s,t}function $c(t){return ne(Mc(t),Qa(t),t.deps)}const jn=t=>{const e=_(15),{toolkit:s,mcpApp:r}=t;let n;e[0]!==r?(n=r?[ne("mcpApp",r)]:[],e[0]=r,e[1]=n):n=e[1];const i=Mt(n)[0],[o,a]=G(jc);let c;e[2]!==o?(c=Object.fromEntries(Object.entries(o).map(Oc)),e[2]=o,e[3]=c):c=e[3];let l;e[4]!==i||e[5]!==c||e[6]!==o?(l={toolUIs:o,mcpApp:i,tools:c},e[4]=i,e[5]=c,e[6]=o,e[7]=l):l=e[7];const u=l,h=$n();let d;e[8]===Symbol.for("react.memo_cache_sentinel")?(d=(x,S,T)=>{const y={render:S,standalone:(T==null?void 0:T.standalone)??!1};return a(w=>({...w,[x]:[...w[x]??[],y]})),()=>{a(w=>{var $;const C=(($=w[x])==null?void 0:$.filter(D=>D!==y))??[];if(C.length>0)return{...w,[x]:C};const I={...w};return delete I[x],I})}},e[8]=d):d=e[8];const f=d;let g,b;e[9]!==h||e[10]!==s?(g=()=>{if(!s)return;const x=[];for(const[T,y]of Object.entries(s)){const w="render"in y?y.render:void 0,C="renderText"in y?y.renderText:void 0,I=w??(C?Ua(C):void 0);I&&x.push(f(T,I,{standalone:La(y)}))}const S=Object.entries(s).reduce(Nc,{});return x.push(h.current.modelContext().register({getModelContext:()=>({tools:S})})),()=>{x.forEach(Fc)}},b=[s,f,h],e[9]=h,e[10]=s,e[11]=g,e[12]=b):(g=e[11],b=e[12]),N(g,b);let v;return e[13]!==u?(v={getState:()=>u,setToolUI:f},e[13]=u,e[14]=v):v=e[14],v},Dc=q(jn);An(jn,(t,e)=>{!t.modelContext&&e.modelContext.source===null&&(t.modelContext=xn())});function jc(){return{}}function Bc(t){return t.render}function Oc(t){const[e,s]=t;return[e,s.map(Bc)]}function Nc(t,e){const[s,r]=e;if(r.type==="mcp")return t;const{display:n,render:i,renderText:o,...a}=r;return t[s]=a,t}function Fc(t){return t()}const Pe=t=>Ue(t.subscribe,t.getState),Lc=t=>{const e=_(8),{runtime:s}=t,r=Pe(s);let n;e[0]!==r?(n=()=>r,e[0]=r,e[1]=n):n=e[1];let i;e[2]!==s?(i=()=>s,e[2]=s,e[3]=i):i=e[3];let o;return e[4]!==s.remove||e[5]!==n||e[6]!==i?(o={getState:n,remove:s.remove,__internal_getRuntime:i},e[4]=s.remove,e[5]=n,e[6]=i,e[7]=o):o=e[7],o},Bn=q(Lc),Vc=t=>{const e=_(5),{runtime:s,index:r}=t;let n;e[0]!==r||e[1]!==s?(n=s.getAttachmentByIndex(r),e[0]=r,e[1]=s,e[2]=n):n=e[2];const i=n;let o;return e[3]!==i?(o=Bn({runtime:i}),e[3]=i,e[4]=o):o=e[4],se(o)},Uc=q(Vc),qc=({item:t,onSteer:e,onRemove:s})=>({getState:()=>t,steer:e,remove:s}),Hc=q(qc),zc=t=>{const e=_(55),{threadIdRef:s,messageIdRef:r,runtime:n}=t,i=Pe(n),o=Ss();let a,c;e[0]!==o||e[1]!==r||e[2]!==n||e[3]!==s?(a=()=>{const I=[];for(const $ of["send","attachmentAdd"]){const D=n.unstable_on($,()=>{o(`composer.${$}`,{threadId:s.current,...r&&{messageId:r.current}})});I.push(D)}return I.push(n.unstable_on("attachmentAddError",$=>{o("composer.attachmentAddError",{threadId:s.current,...r&&{messageId:r.current},...$.attachmentId&&{attachmentId:$.attachmentId},reason:$.reason,message:$.message})})),()=>{for(const $ of I)$()}},c=[n,o,s,r],e[0]=o,e[1]=r,e[2]=n,e[3]=s,e[4]=a,e[5]=c):(a=e[4],c=e[5]),N(a,c);let l;if(e[6]!==n||e[7]!==i.attachments){let I;e[9]!==n?(I=($,D)=>ne($.id,Uc({runtime:n,index:D}),[n,D]),e[9]=n,e[10]=I):I=e[10],l=i.attachments.map(I),e[6]=n,e[7]=i.attachments,e[8]=l}else l=e[8];const u=Re(l),h=i.queue;let d;if(e[11]!==h||e[12]!==n){let I;e[14]!==n?(I=$=>ne($.id,Hc({item:$,onSteer:()=>n.steerQueueItem($.id),onRemove:()=>n.removeQueueItem($.id)})),e[14]=n,e[15]=I):I=e[15],d=h.map(I),e[11]=h,e[12]=n,e[13]=d}else d=e[13];const f=Re(d),g=i.type??"thread";let b;e[16]!==u.state||e[17]!==h||e[18]!==i.attachmentAccept||e[19]!==i.canCancel||e[20]!==i.canSend||e[21]!==i.dictation||e[22]!==i.isEditing||e[23]!==i.isEmpty||e[24]!==i.quote||e[25]!==i.role||e[26]!==i.runConfig||e[27]!==i.text||e[28]!==g?(b={text:i.text,role:i.role,attachments:u.state,runConfig:i.runConfig,isEditing:i.isEditing,canCancel:i.canCancel,canSend:i.canSend,attachmentAccept:i.attachmentAccept,isEmpty:i.isEmpty,type:g,dictation:i.dictation,quote:i.quote,queue:h},e[16]=u.state,e[17]=h,e[18]=i.attachmentAccept,e[19]=i.canCancel,e[20]=i.canSend,e[21]=i.dictation,e[22]=i.isEditing,e[23]=i.isEmpty,e[24]=i.quote,e[25]=i.role,e[26]=i.runConfig,e[27]=i.text,e[28]=g,e[29]=b):b=e[29];const v=b;let x;e[30]!==v?(x=()=>v,e[30]=v,e[31]=x):x=e[31];const S=n.beginEdit??Gc;let T;e[32]!==u?(T=I=>"id"in I?u.get({key:I.id}):u.get(I),e[32]=u,e[33]=T):T=e[33];let y;e[34]!==f?(y=I=>f.get(I),e[34]=f,e[35]=y):y=e[35];let w;e[36]!==n?(w=()=>n,e[36]=n,e[37]=w):w=e[37];let C;return e[38]!==n.addAttachment||e[39]!==n.cancel||e[40]!==n.clearAttachments||e[41]!==n.reset||e[42]!==n.send||e[43]!==n.setQuote||e[44]!==n.setRole||e[45]!==n.setRunConfig||e[46]!==n.setText||e[47]!==n.startDictation||e[48]!==n.stopDictation||e[49]!==y||e[50]!==w||e[51]!==x||e[52]!==S||e[53]!==T?(C={getState:x,setText:n.setText,setRole:n.setRole,setRunConfig:n.setRunConfig,addAttachment:n.addAttachment,reset:n.reset,clearAttachments:n.clearAttachments,send:n.send,cancel:n.cancel,beginEdit:S,startDictation:n.startDictation,stopDictation:n.stopDictation,setQuote:n.setQuote,attachment:T,queueItem:y,__internal_getRuntime:w},e[38]=n.addAttachment,e[39]=n.cancel,e[40]=n.clearAttachments,e[41]=n.reset,e[42]=n.send,e[43]=n.setQuote,e[44]=n.setRole,e[45]=n.setRunConfig,e[46]=n.setText,e[47]=n.startDictation,e[48]=n.stopDictation,e[49]=y,e[50]=w,e[51]=x,e[52]=S,e[53]=T,e[54]=C):C=e[54],C},On=q(zc);function Gc(){throw new Error("beginEdit is not supported in this runtime")}const Nn=t=>({get current(){return t()}}),Kc=t=>{const e=_(13),{runtime:s}=t,r=Pe(s);let n;e[0]!==r?(n=()=>r,e[0]=r,e[1]=n):n=e[1];let i,o,a,c;e[2]!==s?(i=u=>s.addToolResult(u),o=u=>s.resumeToolCall(u),a=u=>s.respondToToolApproval(u),c=()=>s,e[2]=s,e[3]=i,e[4]=o,e[5]=a,e[6]=c):(i=e[3],o=e[4],a=e[5],c=e[6]);let l;return e[7]!==n||e[8]!==i||e[9]!==o||e[10]!==a||e[11]!==c?(l={getState:n,addToolResult:i,resumeToolCall:o,respondToToolApproval:a,__internal_getRuntime:c},e[7]=n,e[8]=i,e[9]=o,e[10]=a,e[11]=c,e[12]=l):l=e[12],l},Wc=q(Kc),Qc=t=>{const e=_(5),{runtime:s,index:r}=t;let n;e[0]!==r||e[1]!==s?(n=s.getAttachmentByIndex(r),e[0]=r,e[1]=s,e[2]=n):n=e[2];const i=n;let o;return e[3]!==i?(o=Bn({runtime:i}),e[3]=i,e[4]=o):o=e[4],se(o)},Yc=q(Qc),Jc=t=>{const e=_(5),{runtime:s,index:r}=t;let n;e[0]!==r||e[1]!==s?(n=s.getMessagePartByIndex(r),e[0]=r,e[1]=s,e[2]=n):n=e[2];const i=n;let o;return e[3]!==i?(o=Wc({runtime:i}),e[3]=i,e[4]=o):o=e[4],se(o)},Xc=q(Jc),Zc=t=>{const e=_(55),{runtime:s,threadIdRef:r}=t,n=Pe(s),[i,o]=G(!1),[a,c]=G(!1);let l;e[0]!==s?(l=Nn(()=>s.getState().id),e[0]=s,e[1]=l):l=e[1];const u=l;let h;e[2]!==u||e[3]!==s.composer||e[4]!==r?(h=On({runtime:s.composer,threadIdRef:r,messageIdRef:u}),e[2]=u,e[3]=s.composer,e[4]=r,e[5]=h):h=e[5];const d=tt(h);let f;if(e[6]!==s||e[7]!==n.content){let j;e[9]!==s?(j=(U,z)=>ne("toolCallId"in U&&U.toolCallId!=null?`toolCallId-${U.toolCallId}`:`index-${z}`,Xc({runtime:s,index:z}),[s,z]),e[9]=s,e[10]=j):j=e[10],f=n.content.map(j),e[6]=s,e[7]=n.content,e[8]=f}else f=e[8];const g=Re(f);let b;e[11]!==n.attachments?(b=n.attachments??[],e[11]=n.attachments,e[12]=b):b=e[12];let v;if(e[13]!==s||e[14]!==b){let j;e[16]!==s?(j=(U,z)=>ne(U.id,Yc({runtime:s,index:z}),[s,z]),e[16]=s,e[17]=j):j=e[17],v=b.map(j),e[13]=s,e[14]=b,e[15]=v}else v=e[15];const x=Re(v),S=n;let T;e[18]!==d.state||e[19]!==i||e[20]!==a||e[21]!==g.state||e[22]!==S?(T={...S,parts:g.state,composer:d.state,isCopied:i,isHovering:a},e[18]=d.state,e[19]=i,e[20]=a,e[21]=g.state,e[22]=S,e[23]=T):T=e[23];const y=T;let w;e[24]!==y?(w=()=>y,e[24]=y,e[25]=w):w=e[25];let C;e[26]!==d.methods?(C=()=>d.methods,e[26]=d.methods,e[27]=C):C=e[27];let I,$,D,R,E,k,A;e[28]!==s?(I=()=>s.delete(),$=j=>s.reload(j),D=()=>s.speak(),R=()=>s.stopSpeaking(),E=j=>s.submitFeedback(j),k=j=>s.switchToBranch(j),A=()=>s.unstable_getCopyText(),e[28]=s,e[29]=I,e[30]=$,e[31]=D,e[32]=R,e[33]=E,e[34]=k,e[35]=A):(I=e[29],$=e[30],D=e[31],R=e[32],E=e[33],k=e[34],A=e[35]);let B;e[36]!==g?(B=j=>"index"in j?g.get({index:j.index}):g.get({key:`toolCallId-${j.toolCallId}`}),e[36]=g,e[37]=B):B=e[37];let O;e[38]!==x?(O=j=>"id"in j?x.get({key:j.id}):x.get(j),e[38]=x,e[39]=O):O=e[39];let L;e[40]!==s?(L=()=>s,e[40]=s,e[41]=L):L=e[41];let H;return e[42]!==I||e[43]!==$||e[44]!==D||e[45]!==R||e[46]!==E||e[47]!==k||e[48]!==A||e[49]!==B||e[50]!==O||e[51]!==L||e[52]!==w||e[53]!==C?(H={getState:w,composer:C,delete:I,reload:$,speak:D,stopSpeaking:R,submitFeedback:E,switchToBranch:k,getCopyText:A,part:B,attachment:O,setIsCopied:o,setIsHovering:c,__internal_getRuntime:L},e[42]=I,e[43]=$,e[44]=D,e[45]=R,e[46]=E,e[47]=k,e[48]=A,e[49]=B,e[50]=O,e[51]=L,e[52]=w,e[53]=C,e[54]=H):H=e[54],H},el=q(Zc),tl=t=>{const e=_(6),{runtime:s,id:r,threadIdRef:n}=t;let i;e[0]!==r||e[1]!==s?(i=s.getMessageById(r),e[0]=r,e[1]=s,e[2]=i):i=e[2];const o=i;let a;return e[3]!==o||e[4]!==n?(a=el({runtime:o,threadIdRef:n}),e[3]=o,e[4]=n,e[5]=a):a=e[5],se(a)},sl=q(tl),rl=t=>{const e=_(58),{runtime:s}=t,r=Pe(s),n=Ss();let i,o;e[0]!==n||e[1]!==s?(i=()=>{const w=[];for(const C of["runStart","runEnd","initialize","modelContextUpdate"]){const I=s.unstable_on(C,()=>{var D;const $=((D=s.getState())==null?void 0:D.threadId)||"unknown";n(`thread.${C}`,{threadId:$})});w.push(I)}return()=>{for(const C of w)C()}},o=[s,n],e[0]=n,e[1]=s,e[2]=i,e[3]=o):(i=e[2],o=e[3]),N(i,o);let a;e[4]!==s?(a=Nn(()=>s.getState().threadId),e[4]=s,e[5]=a):a=e[5];const c=a;let l;e[6]!==s.composer||e[7]!==c?(l=On({runtime:s.composer,threadIdRef:c}),e[6]=s.composer,e[7]=c,e[8]=l):l=e[8];const u=tt(l);let h;if(e[9]!==s||e[10]!==r.messages||e[11]!==c){let w;e[13]!==s||e[14]!==c?(w=C=>ne(C.id,sl({runtime:s,id:C.id,threadIdRef:c}),[s,C.id,c]),e[13]=s,e[14]=c,e[15]=w):w=e[15],h=r.messages.map(w),e[9]=s,e[10]=r.messages,e[11]=c,e[12]=h}else h=e[12];const d=Re(h),f=d.state.length===0&&!r.isLoading;let g;e[16]!==u.state||e[17]!==d.state||e[18]!==r.capabilities||e[19]!==r.extras||e[20]!==r.isDisabled||e[21]!==r.isLoading||e[22]!==r.isRunning||e[23]!==r.speech||e[24]!==r.state||e[25]!==r.suggestions||e[26]!==r.voice||e[27]!==f?(g={isEmpty:f,isDisabled:r.isDisabled,isLoading:r.isLoading,isRunning:r.isRunning,capabilities:r.capabilities,state:r.state,suggestions:r.suggestions,extras:r.extras,speech:r.speech,voice:r.voice,composer:u.state,messages:d.state},e[16]=u.state,e[17]=d.state,e[18]=r.capabilities,e[19]=r.extras,e[20]=r.isDisabled,e[21]=r.isLoading,e[22]=r.isRunning,e[23]=r.speech,e[24]=r.state,e[25]=r.suggestions,e[26]=r.voice,e[27]=f,e[28]=g):g=e[28];const b=g;let v;e[29]!==b?(v=()=>b,e[29]=b,e[30]=v):v=e[30];let x;e[31]!==u.methods?(x=()=>u.methods,e[31]=u.methods,e[32]=x):x=e[32];let S;e[33]!==d?(S=w=>"id"in w?d.get({key:w.id}):d.get(w),e[33]=d,e[34]=S):S=e[34];let T;e[35]!==s?(T=()=>s,e[35]=s,e[36]=T):T=e[36];let y;return e[37]!==s.append||e[38]!==s.cancelRun||e[39]!==s.connectVoice||e[40]!==s.deleteMessage||e[41]!==s.disconnectVoice||e[42]!==s.export||e[43]!==s.getModelContext||e[44]!==s.getVoiceVolume||e[45]!==s.import||e[46]!==s.muteVoice||e[47]!==s.reset||e[48]!==s.resumeRun||e[49]!==s.startRun||e[50]!==s.stopSpeaking||e[51]!==s.subscribeVoiceVolume||e[52]!==s.unmuteVoice||e[53]!==S||e[54]!==T||e[55]!==v||e[56]!==x?(y={getState:v,composer:x,append:s.append,deleteMessage:s.deleteMessage,startRun:s.startRun,resumeRun:s.resumeRun,cancelRun:s.cancelRun,getModelContext:s.getModelContext,export:s.export,import:s.import,reset:s.reset,stopSpeaking:s.stopSpeaking,connectVoice:s.connectVoice,disconnectVoice:s.disconnectVoice,getVoiceVolume:s.getVoiceVolume,subscribeVoiceVolume:s.subscribeVoiceVolume,muteVoice:s.muteVoice,unmuteVoice:s.unmuteVoice,message:S,__internal_getRuntime:T},e[37]=s.append,e[38]=s.cancelRun,e[39]=s.connectVoice,e[40]=s.deleteMessage,e[41]=s.disconnectVoice,e[42]=s.export,e[43]=s.getModelContext,e[44]=s.getVoiceVolume,e[45]=s.import,e[46]=s.muteVoice,e[47]=s.reset,e[48]=s.resumeRun,e[49]=s.startRun,e[50]=s.stopSpeaking,e[51]=s.subscribeVoiceVolume,e[52]=s.unmuteVoice,e[53]=S,e[54]=T,e[55]=v,e[56]=x,e[57]=y):y=e[57],y},nl=q(rl),il=t=>{const e=_(20),{runtime:s}=t,r=Pe(s),n=Ss();let i,o;e[0]!==n||e[1]!==s?(i=()=>{const u=[];for(const h of["switchedTo","switchedAway"]){const d=s.unstable_on(h,()=>{n(`threadListItem.${h}`,{threadId:s.getState().id})});u.push(d)}return()=>{for(const h of u)h()}},o=[s,n],e[0]=n,e[1]=s,e[2]=i,e[3]=o):(i=e[2],o=e[3]),N(i,o);let a;e[4]!==r?(a=()=>r,e[4]=r,e[5]=a):a=e[5];let c;e[6]!==s?(c=()=>s,e[6]=s,e[7]=c):c=e[7];let l;return e[8]!==s.archive||e[9]!==s.delete||e[10]!==s.detach||e[11]!==s.generateTitle||e[12]!==s.initialize||e[13]!==s.rename||e[14]!==s.switchTo||e[15]!==s.unarchive||e[16]!==s.updateCustom||e[17]!==a||e[18]!==c?(l={getState:a,switchTo:s.switchTo,rename:s.rename,updateCustom:s.updateCustom,archive:s.archive,unarchive:s.unarchive,delete:s.delete,generateTitle:s.generateTitle,initialize:s.initialize,detach:s.detach,__internal_getRuntime:c},e[8]=s.archive,e[9]=s.delete,e[10]=s.detach,e[11]=s.generateTitle,e[12]=s.initialize,e[13]=s.rename,e[14]=s.switchTo,e[15]=s.unarchive,e[16]=s.updateCustom,e[17]=a,e[18]=c,e[19]=l):l=e[19],l},ol=q(il),al=t=>{const e=_(5),{runtime:s,id:r}=t;let n;e[0]!==r||e[1]!==s?(n=s.getItemById(r),e[0]=r,e[1]=s,e[2]=n):n=e[2];const i=n;let o;return e[3]!==i?(o=ol({runtime:i}),e[3]=i,e[4]=o):o=e[4],se(o)},cl=q(al),ll=t=>{const e=_(40),{runtime:s,__internal_assistantRuntime:r}=t,n=Pe(s);let i;e[0]!==s.main?(i=nl({runtime:s.main}),e[0]=s.main,e[1]=i):i=e[1];const o=tt(i);let a;e[2]!==s||e[3]!==n.threadItems?(a=Object.keys(n.threadItems).map(C=>ne(C,cl({runtime:s,id:C}),[s,C])),e[2]=s,e[3]=n.threadItems,e[4]=a):a=e[4];const c=Re(a),l=n.newThreadId??null;let u;e[5]!==o.state||e[6]!==n.archivedThreadIds||e[7]!==n.hasMore||e[8]!==n.isLoading||e[9]!==n.isLoadingMore||e[10]!==n.mainThreadId||e[11]!==n.threadIds||e[12]!==l||e[13]!==c.state?(u={mainThreadId:n.mainThreadId,newThreadId:l,isLoading:n.isLoading,isLoadingMore:n.isLoadingMore,hasMore:n.hasMore,threadIds:n.threadIds,archivedThreadIds:n.archivedThreadIds,threadItems:c.state,main:o.state},e[5]=o.state,e[6]=n.archivedThreadIds,e[7]=n.hasMore,e[8]=n.isLoading,e[9]=n.isLoadingMore,e[10]=n.mainThreadId,e[11]=n.threadIds,e[12]=l,e[13]=c.state,e[14]=u):u=e[14];const h=u;let d;e[15]!==h?(d=()=>h,e[15]=h,e[16]=d):d=e[16];let f;e[17]!==o.methods?(f=()=>o.methods,e[17]=o.methods,e[18]=f):f=e[18];let g;e[19]!==h||e[20]!==c?(g=C=>{if(C==="main")return c.get({key:h.mainThreadId});if("id"in C)return c.get({key:C.id});const{index:I,archived:$}=C,D=$!==void 0&&$?h.archivedThreadIds[I]:h.threadIds[I];return c.get({key:D})},e[19]=h,e[20]=c,e[21]=g):g=e[21];let b,v,x,S,T;e[22]!==s?(S=async(C,I)=>{await s.switchToThread(C,I)},T=async()=>{await s.switchToNewThread()},b=()=>s.getLoadThreadsPromise(),v=()=>s.reload(),x=()=>s.loadMore(),e[22]=s,e[23]=b,e[24]=v,e[25]=x,e[26]=S,e[27]=T):(b=e[23],v=e[24],x=e[25],S=e[26],T=e[27]);let y;e[28]!==r?(y=()=>r,e[28]=r,e[29]=y):y=e[29];let w;return e[30]!==b||e[31]!==v||e[32]!==x||e[33]!==y||e[34]!==d||e[35]!==f||e[36]!==g||e[37]!==S||e[38]!==T?(w={getState:d,thread:f,item:g,switchToThread:S,switchToNewThread:T,getLoadThreadsPromise:b,reload:v,loadMore:x,__internal_getAssistantRuntime:y},e[30]=b,e[31]=v,e[32]=x,e[33]=y,e[34]=d,e[35]=f,e[36]=g,e[37]=S,e[38]=T,e[39]=w):w=e[39],w},ul=q(ll),dl=t=>({getState:()=>t}),hl=q(dl),fl=t=>{const e=_(11);let s;e[0]!==t?(s=()=>({suggestions:(t??[]).map(gl)}),e[0]=t,e[1]=s):s=e[1];const[r]=G(s);let n;e[2]!==r.suggestions?(n=r.suggestions.map(ml),e[2]=r.suggestions,e[3]=n):n=e[3];const i=Re(n);let o;e[4]!==r?(o=()=>r,e[4]=r,e[5]=o):o=e[5];let a;e[6]!==i?(a=l=>{const{index:u}=l;return i.get({index:u})},e[6]=i,e[7]=a):a=e[7];let c;return e[8]!==o||e[9]!==a?(c={getState:o,suggestion:a},e[8]=o,e[9]=a,e[10]=c):c=e[10],c},pl=q(fl);function gl(t){return typeof t=="string"?{title:t,label:"",prompt:t}:{title:t.title,label:t.label,prompt:t.prompt}}function ml(t,e){return ne(e,hl(t),[t])}const bl=(t,e)=>{t.thread??(t.thread=re({source:"threads",query:{type:"main"},get:s=>s.threads().thread("main")})),t.threadListItem??(t.threadListItem=re({source:"threads",query:{type:"main"},get:s=>s.threads().item("main")})),t.composer??(t.composer=re({source:"thread",query:{},get:s=>s.threads().thread("main").composer()})),!t.modelContext&&e.modelContext.source===null&&(t.modelContext=xn()),!t.suggestions&&e.suggestions.source===null&&(t.suggestions=pl())},Fn=t=>{const e=_(6),s=$n();let r,n;e[0]!==s||e[1]!==t?(r=()=>t.registerModelContextProvider(s.current.modelContext()),n=[t,s],e[0]=s,e[1]=t,e[2]=r,e[3]=n):(r=e[2],n=e[3]),N(r,n);let i;return e[4]!==t?(i=ul({runtime:t.threads,__internal_assistantRuntime:t}),e[4]=t,e[5]=i):i=e[5],se(i)},_l=q(Fn);An(Fn,(t,e)=>{bl(t,e),!t.tools&&e.tools.source===null&&(t.tools=Dc({})),!t.dataRenderers&&e.dataRenderers.source===null&&(t.dataRenderers=Da())});const yl=t=>{var e;return(e=t._core)==null?void 0:e.RenderComponent},vl=M.memo(({runtime:t,aui:e=null,children:s})=>{"use no memo";const r=F({threads:_l(t)},{parent:e}),n=yl(t),i=p.jsxs(ue,{value:r,children:[n&&p.jsx(n,{}),s]});return e?p.jsx(ue,{value:e,children:i}):i}),sr=t=>{let e;const s=new Set,r=(l,u)=>{const h=typeof l=="function"?l(e):l;if(!Object.is(h,e)){const d=e;e=u??(typeof h!="object"||h===null)?h:Object.assign({},e,h),s.forEach(f=>f(e,d))}},n=()=>e,a={setState:r,getState:n,getInitialState:()=>c,subscribe:l=>(s.add(l),()=>s.delete(l))},c=e=t(r,n,a);return a},Sl=t=>t?sr(t):sr,xl=t=>t;function wl(t,e=xl){const s=J.useSyncExternalStore(t.subscribe,J.useCallback(()=>e(t.getState()),[t,e]),J.useCallback(()=>e(t.getInitialState()),[t,e]));return J.useDebugValue(s),s}const rr=t=>{const e=Sl(t),s=r=>wl(e,r);return Object.assign(s,e),s},Tl=t=>t?rr(t):rr;function Z(t){return t!=null&&typeof t=="object"&&!Array.isArray(t)}function vt(t,e=0){return e>100?!1:t===null||typeof t=="string"||typeof t=="boolean"?!0:typeof t=="number"?!Number.isNaN(t)&&Number.isFinite(t):Array.isArray(t)?t.every(s=>vt(s,e+1)):Z(t)?Object.entries(t).every(([s,r])=>typeof s=="string"&&vt(r,e+1)):!1}const Cl=100,Xt=(t,e,s)=>{if(t===e)return!0;if(s>Cl||t==null||e==null)return!1;if(Array.isArray(t))return!Array.isArray(e)||t.length!==e.length?!1:t.every((i,o)=>Xt(i,e[o],s+1));if(Array.isArray(e)||!Z(t)||!Z(e))return!1;const r=Object.keys(t),n=Object.keys(e);return r.length!==n.length?!1:r.every(i=>Object.hasOwn(e,i)&&Xt(t[i],e[i],s+1))},xs=(t,e)=>!vt(t)||!vt(e)?!1:Xt(t,e,0);function Il(t){const e=t.metadata;if(!e||typeof e!="object")return;const s=e.custom;if(!s||typeof s!="object")return;const r=s.interactables;return Array.isArray(r)?r:void 0}function El(t){return`update_${t.replace(/[^a-zA-Z0-9_-]/g,"_")}`}const nr=t=>{if(!Z(t))return;const e=t.id;return typeof e=="string"||typeof e=="number"?e:void 0};function Rl(t,e,s){let r=Array.isArray(e.set)?[...e.set]:[...t];if(e.clear===!0&&(r=[]),Array.isArray(e.remove)&&e.remove.length>0){const i=new Set(e.remove);r=r.filter(o=>{const a=nr(o);return a!==void 0?!i.has(a):!i.has(o)})}const n=e.update;if(Array.isArray(n)&&n.length>0&&(r=r.map(i=>{const o=nr(i);if(o===void 0||!Z(i))return i;const a=n.find(c=>Z(c)&&c.id===o);return a?{...i,...a}:i})),Array.isArray(e.add)&&e.add.length>0){const i=s?e.add.map(o=>{if(!Z(o)||o.id!==void 0)return o;const a=s();return a===void 0?o:{...o,id:a}}):e.add;r=[...r,...i]}return r}function Ot(t,e,s){if(!Z(t)||!Z(e))return e;const r=Z(s==null?void 0:s.arrayBaseline)?s.arrayBaseline:t,n={...t};for(const[i,o]of Object.entries(e)){const a=r[i];Array.isArray(a)&&Z(o)?n[i]=Rl(a,o,s!=null&&s.idFactory&&(s.idKeyedFields===void 0||s.idKeyedFields.has(i))?()=>{var c;return(c=s.idFactory)==null?void 0:c.call(s,i)}:void 0):n[i]=o}return n}function Al(t,e){if(!Z(t)||!Z(e))return;for(const n of Object.keys(t))if(!(n in e))return;const s={};for(const[n,i]of Object.entries(e))(!(n in t)||!xs(t[n],i))&&(s[n]=i);const r=Object.keys(s).length;if(!(r===0||r===Object.keys(e).length))return s}const Ml=t=>{if(!t||typeof t!="object")return;const e=t;return e.type==="tool-call"?e:void 0},Pl=(t,e)=>{if(!t.args||typeof t.args!="object")return!1;const s=Z(t.result)?t.result:void 0;if((s==null?void 0:s.success)===!1)return!1;if(typeof(s==null?void 0:s.id)=="string")return s.id===e;const r=t.args.id;return r===e||r===void 0},kl=t=>{const e=Z(t)?t.addedItemIds:void 0;if(!Z(e))return;const s=new Map;for(const[r,n]of Object.entries(e)){if(!Array.isArray(n))continue;const i=n.filter(o=>typeof o=="string");i.length>0&&s.set(r,i)}if(s.size!==0)return r=>{var n;return(n=s.get(r))==null?void 0:n.shift()}},ir=new WeakMap;function $l(t,e,s){var l;let r=ir.get(t);r||(r=new Map,ir.set(t,r));let n=r.get(s);n||(n=new Map,r.set(s,n));const i=n.get(e);if(i)return i;const o=El(s),a=[],c=()=>a[a.length-1];for(const u of t){if(u.role==="user"){const h=(l=Il(u))==null?void 0:l.find(d=>d.id===e);if(!h)continue;if(h.partial){const d=c();d&&a.push({state:Ot(d.state,h.state),origin:"user-edit"})}else a.push({state:h.state,origin:"user-edit"});continue}if(u.role==="assistant")for(const h of u.content??[]){const d=Ml(h);if(d){if(d.toolCallId===e&&d.toolName===s)d.args&&typeof d.args=="object"&&a.push({state:d.args,origin:"create",toolCallId:e});else if(d.toolName===o&&Pl(d,e)){const f=c();if(f){const{id:g,...b}=d.args,v=kl(d.result);a.push({state:v?Ot(f.state,b,{idFactory:v}):Ot(f.state,b),origin:"update",toolCallId:d.toolCallId})}}}}}return n.set(e,a),a}function Dl(t,e,s){const r=$l(t,e,s),n=r[r.length-1];return n?{state:n.state}:void 0}function Ln(t,e){if(!t)return;const{interactables:s,...r}=t,n={...r};if(Array.isArray(s)){const i=[];for(const o of s){const a=Dl(e,o.id,o.name);if(!a){i.push({id:o.id,name:o.name,state:o.state});continue}if(xs(o.state,a.state))continue;const c=Al(a.state,o.state);i.push(c?{id:o.id,name:o.name,state:c,partial:!0}:{id:o.id,name:o.name,state:o.state})}i.length&&(n.interactables=i)}return Object.keys(n).length?n:void 0}const ws=()=>{let t,e;const s=new Promise((r,n)=>{t=r,e=n});if(!t||!e)throw new Error("Failed to create promise");return{promise:s,resolve:t,reject:e}},jl=()=>{const t=[];let e=!1,s,r;const n=i=>{i.promise||(i.promise=i.reader.read().then(({done:o,value:a})=>{i.promise=void 0,o?(t.splice(t.indexOf(i),1),e&&t.length===0&&s.close()):s.enqueue(a),r==null||r.resolve(),r=void 0}).catch(o=>{console.error(o),t.forEach(a=>{a.reader.cancel()}),t.length=0,s.error(o),r==null||r.reject(o),r=void 0}))};return{readable:new ReadableStream({start(i){s=i},pull(){return r=ws(),t.forEach(i=>{n(i)}),r.promise},cancel(){t.forEach(i=>{i.reader.cancel()}),t.length=0}}),isSealed(){return e},seal(){e=!0,t.length===0&&s.close()},addStream(i){if(e)throw new Error("Cannot add streams after the run callback has settled.");const o={reader:i.getReader()};t.push(o),n(o)},enqueue(i){this.addStream(new ReadableStream({start(o){o.enqueue(i),o.close()}}))}}};var or=class{constructor(t){m(this,"_controller");m(this,"_isClosed",!1);this._controller=t}append(t){return this._controller.enqueue({type:"text-delta",path:[],textDelta:t}),this}close(){this._isClosed||(this._isClosed=!0,this._controller.enqueue({type:"part-finish",path:[]}),this._controller.close())}};const Vn=t=>new ReadableStream({start(e){var s;return(s=t.start)==null?void 0:s.call(t,new or(e))},pull(e){var s;return(s=t.pull)==null?void 0:s.call(t,new or(e))},cancel(e){var s;return(s=t.cancel)==null?void 0:s.call(t,e)}}),ar=()=>{let t;return[Vn({start(e){t=e}}),t]};var cr=class{constructor(t){m(this,"_controller");m(this,"_isClosed",!1);m(this,"_mergeTask");m(this,"_argsTextController");this._controller=t;const e=Vn({start:r=>{this._argsTextController=r}});let s=!1;this._mergeTask=e.pipeTo(new WritableStream({write:r=>{switch(r.type){case"text-delta":s=!0,this._controller.enqueue(r);break;case"part-finish":s||this._controller.enqueue({type:"text-delta",textDelta:"{}",path:[]}),this._controller.enqueue({type:"tool-call-args-text-finish",path:[]});break;default:throw new Error(`Unexpected chunk type: ${r.type}`)}}}))}get argsText(){return this._argsTextController}async setResponse(t){this._argsTextController.close(),await Promise.resolve(),this._controller.enqueue({type:"result",path:[],...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}:{}})}async close(){this._isClosed||(this._isClosed=!0,this._argsTextController.close(),await this._mergeTask,this._controller.enqueue({type:"part-finish",path:[]}),this._controller.close())}};const Bl=t=>new ReadableStream({start(e){var s;return(s=t.start)==null?void 0:s.call(t,new cr(e))},pull(e){var s;return(s=t.pull)==null?void 0:s.call(t,new cr(e))},cancel(e){var s;return(s=t.cancel)==null?void 0:s.call(t,e)}}),Ol=()=>{let t;return[Bl({start(e){t=e}}),t]};var Un=class{constructor(){m(this,"value",-1)}up(){return++this.value}},Nl=class extends TransformStream{constructor(t){super({transform(e,s){s.enqueue({...e,path:[t,...e.path]})}})}};(class extends TransformStream{constructor(t){super({transform(e,s){const{path:[r,...n]}=e;if(t!==r)throw new Error(`Path mismatch: expected ${t}, got ${r}`);s.enqueue({...e,path:n})}})}});var Fl=class extends TransformStream{constructor(t){const e=new Un,s=new Map;super({transform(r,n){r.type==="part-start"&&r.path.length===0&&s.set(e.up(),t.up());const[i,...o]=r.path;if(i===void 0){n.enqueue(r);return}const a=s.get(i);if(a===void 0)throw new Error("Path not found");n.enqueue({...r,path:[a,...o]})}})}},Ll=class extends TransformStream{constructor(t){super();const e=t(super.readable);Object.defineProperty(this,"readable",{value:e,writable:!1})}},qn=class extends TransformStream{constructor(){const t=[];super({transform(e,s){if(e.type==="part-start"){if(e.path.length!==0){s.error(new Error("Nested parts are not supported"));return}t.push(e.part),s.enqueue(e);return}if(e.type==="text-delta"||e.type==="result"||e.type==="part-finish"||e.type==="tool-call-args-text-finish"){if(e.path.length!==1){s.error(new Error(`${e.type} chunks must have a path of length 1`));return}const r=e.path[0];if(r<0||r>=t.length){s.error(new Error(`Invalid path index: ${r}`));return}const n=t[r];s.enqueue({...e,meta:n});return}s.enqueue(e)}})}};let Vl=(t,e=21)=>(s=e)=>{let r="",n=s|0;for(;n-- >0;)r+=t[Math.random()*t.length|0];return r};const Ul=Vl("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",7);var ql=class Hn{constructor(e){m(this,"_state");m(this,"_parentId");this._state=e||{merger:jl(),contentCounter:new Un}}get __internal_isClosed(){return this._state.merger.isSealed()}__internal_getReadable(){return this._state.merger.readable}__internal_subscribeToClose(e){this._state.closeSubscriber=e}_addPart(e,s){this._state.append&&(this._state.append.controller.close(),this._state.append=void 0),this.enqueue({type:"part-start",part:e,path:[]}),this._state.merger.addStream(s.pipeThrough(new Nl(this._state.contentCounter.value)))}merge(e){this._state.merger.addStream(e.pipeThrough(new Fl(this._state.contentCounter)))}appendText(e){var s;(((s=this._state.append)==null?void 0:s.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){var s;(((s=this._state.append)==null?void 0:s.kind)!=="reasoning"||this._state.append.parentId!==this._parentId)&&(this._state.append={kind:"reasoning",parentId:this._parentId,controller:this.addReasoningPart()}),this._state.append.controller.append(e)}addTextPart(){const[e,s]=ar();return this._addPart(this._withParentIdOption({type:"text"}),e),s}addReasoningPart(){const[e,s]=ar();return this._addPart(this._withParentIdOption({type:"reasoning"}),e),s}addToolCallPart(e){const s=typeof e=="string"?{toolName:e}:e,r=s.toolName,n=s.toolCallId??Ul(),[i,o]=Ol();return this._addPart({type:"tool-call",toolName:r,toolCallId:n,...this._parentId&&{parentId:this._parentId}},i),s.argsText!==void 0&&(o.argsText.append(s.argsText),o.argsText.close()),s.args!==void 0&&(o.argsText.append(JSON.stringify(s.args)),o.argsText.close()),s.response!==void 0&&o.setResponse(s.response),o}_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())}appendFile(e){this._addPart(this._withParentIdOption(e),this._finishedPartStream())}appendData(e){this._addPart(this._withParentIdOption(e),this._finishedPartStream())}enqueue(e){this._state.merger.enqueue(e),e.type==="part-start"&&e.path.length===0&&this._state.contentCounter.up()}withParentId(e){const s=new Hn(this._state);return s._parentId=e,s}close(){var e,s,r,n;(s=(e=this._state.append)==null?void 0:e.controller)==null||s.close(),this._state.merger.seal(),(n=(r=this._state).closeSubscriber)==null||n.call(r)}};function Hl(t){const e=new ql;return(async()=>{try{await t(e)}catch(r){throw e.__internal_isClosed||e.enqueue({type:"error",path:[],error:String(r)}),r}finally{e.__internal_isClosed||e.close()}})(),e.__internal_getReadable()}function zl(){const{resolve:t,promise:e}=ws();let s;return[Hl(r=>(s=r,s.__internal_subscribeToClose(t),e)),s]}function Gl(t){const e=["ROOT"];let s=-1,r=null;const n=[];let i;function o(){i!==void 0&&(n.push(JSON.parse(`"${i}"`)),i=void 0)}function a(h,d,f){switch(h){case'"':s=d,e.pop(),e.push(f),e.push("INSIDE_STRING"),o();break;case"f":case"t":case"n":s=d,r=d,e.pop(),e.push(f),e.push("INSIDE_LITERAL");break;case"-":e.pop(),e.push(f),e.push("INSIDE_NUMBER"),o();break;case"0":case"1":case"2":case"3":case"4":case"5":case"6":case"7":case"8":case"9":s=d,e.pop(),e.push(f),e.push("INSIDE_NUMBER"),o();break;case"{":s=d,e.pop(),e.push(f),e.push("INSIDE_OBJECT_START"),o();break;case"[":s=d,e.pop(),e.push(f),e.push("INSIDE_ARRAY_START"),o();break}}function c(h,d){switch(h){case",":e.pop(),e.push("INSIDE_OBJECT_AFTER_COMMA");break;case"}":s=d,e.pop(),i=n.pop();break}}function l(h,d){switch(h){case",":e.pop(),e.push("INSIDE_ARRAY_AFTER_COMMA"),i=(Number(i)+1).toString();break;case"]":s=d,e.pop(),i=n.pop();break}}for(let h=0;h<t.length;h++){const d=t[h];switch(e[e.length-1]){case"ROOT":a(d,h,"FINISH");break;case"INSIDE_OBJECT_START":switch(d){case'"':e.pop(),e.push("INSIDE_OBJECT_KEY"),i="";break;case"}":s=h,e.pop(),i=n.pop();break}break;case"INSIDE_OBJECT_AFTER_COMMA":switch(d){case'"':e.pop(),e.push("INSIDE_OBJECT_KEY"),i="";break}break;case"INSIDE_OBJECT_KEY":switch(d){case'"':e.pop(),e.push("INSIDE_OBJECT_AFTER_KEY");break;case"\\":e.push("INSIDE_STRING_ESCAPE"),i+=d;break;default:i+=d;break}break;case"INSIDE_OBJECT_AFTER_KEY":switch(d){case":":e.pop(),e.push("INSIDE_OBJECT_BEFORE_VALUE");break}break;case"INSIDE_OBJECT_BEFORE_VALUE":a(d,h,"INSIDE_OBJECT_AFTER_VALUE");break;case"INSIDE_OBJECT_AFTER_VALUE":c(d,h);break;case"INSIDE_STRING":switch(d){case'"':e.pop(),s=h,i=n.pop();break;case"\\":e.push("INSIDE_STRING_ESCAPE");break;default:s=h}break;case"INSIDE_ARRAY_START":switch(d){case"]":s=h,e.pop(),i=n.pop();break;default:s=h,i="0",a(d,h,"INSIDE_ARRAY_AFTER_VALUE");break}break;case"INSIDE_ARRAY_AFTER_VALUE":switch(d){case",":e.pop(),e.push("INSIDE_ARRAY_AFTER_COMMA"),i=(Number(i)+1).toString();break;case"]":s=h,e.pop(),i=n.pop();break;default:s=h;break}break;case"INSIDE_ARRAY_AFTER_COMMA":a(d,h,"INSIDE_ARRAY_AFTER_VALUE");break;case"INSIDE_STRING_ESCAPE":e.pop(),e[e.length-1]==="INSIDE_STRING"?s=h:e[e.length-1]==="INSIDE_OBJECT_KEY"&&(i+=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":s=h;break;case"e":case"E":case"-":case".":break;case",":e.pop(),i=n.pop(),e[e.length-1]==="INSIDE_ARRAY_AFTER_VALUE"&&l(d,h),e[e.length-1]==="INSIDE_OBJECT_AFTER_VALUE"&&c(d,h);break;case"}":e.pop(),i=n.pop(),e[e.length-1]==="INSIDE_OBJECT_AFTER_VALUE"&&c(d,h);break;case"]":e.pop(),i=n.pop(),e[e.length-1]==="INSIDE_ARRAY_AFTER_VALUE"&&l(d,h);break;default:e.pop(),i=n.pop();break}break;case"INSIDE_LITERAL":{const f=t.substring(r,h+1);!"false".startsWith(f)&&!"true".startsWith(f)&&!"null".startsWith(f)?(e.pop(),e[e.length-1]==="INSIDE_OBJECT_AFTER_VALUE"?c(d,h):e[e.length-1]==="INSIDE_ARRAY_AFTER_VALUE"&&l(d,h)):s=h;break}}}let u=t.slice(0,s+1);for(let h=e.length-1;h>=0;h--)switch(e[h]){case"INSIDE_STRING":u+='"';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":u+="}";break;case"INSIDE_ARRAY_START":case"INSIDE_ARRAY_AFTER_COMMA":case"INSIDE_ARRAY_AFTER_VALUE":u+="]";break;case"INSIDE_LITERAL":{const d=t.substring(r,t.length);"true".startsWith(d)?u+="true".slice(d.length):"false".startsWith(d)?u+="false".slice(d.length):"null".startsWith(d)&&(u+="null".slice(d.length))}}return[u,n]}var He={exports:{}};const Kl=typeof Buffer<"u",lr=/"(?:_|\\u005[Ff])(?:_|\\u005[Ff])(?:p|\\u0070)(?:r|\\u0072)(?:o|\\u006[Ff])(?:t|\\u0074)(?:o|\\u006[Ff])(?:_|\\u005[Ff])(?:_|\\u005[Ff])"\s*:/,ur=/"(?: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 zn(t,e,s){s==null&&e!==null&&typeof e=="object"&&(s=e,e=void 0),Kl&&Buffer.isBuffer(t)&&(t=t.toString()),t&&t.charCodeAt(0)===65279&&(t=t.slice(1));const r=JSON.parse(t,e);if(r===null||typeof r!="object")return r;const n=s&&s.protoAction||"error",i=s&&s.constructorAction||"error";if(n==="ignore"&&i==="ignore")return r;if(n!=="ignore"&&i!=="ignore"){if(lr.test(t)===!1&&ur.test(t)===!1)return r}else if(n!=="ignore"&&i==="ignore"){if(lr.test(t)===!1)return r}else if(ur.test(t)===!1)return r;return Gn(r,{protoAction:n,constructorAction:i,safe:s&&s.safe})}function Gn(t,{protoAction:e="error",constructorAction:s="error",safe:r}={}){let n=[t];for(;n.length;){const i=n;n=[];for(const o of i){if(e!=="ignore"&&Object.prototype.hasOwnProperty.call(o,"__proto__")){if(r===!0)return null;if(e==="error")throw new SyntaxError("Object contains forbidden prototype property");delete o.__proto__}if(s!=="ignore"&&Object.prototype.hasOwnProperty.call(o,"constructor")&&o.constructor!==null&&typeof o.constructor=="object"&&Object.prototype.hasOwnProperty.call(o.constructor,"prototype")){if(r===!0)return null;if(s==="error")throw new SyntaxError("Object contains forbidden prototype property");delete o.constructor}for(const a in o){const c=o[a];c&&typeof c=="object"&&n.push(c)}}}return t}function Ts(t,e,s){const{stackTraceLimit:r}=Error;Error.stackTraceLimit=0;try{return zn(t,e,s)}finally{Error.stackTraceLimit=r}}function Wl(t,e){const{stackTraceLimit:s}=Error;Error.stackTraceLimit=0;try{return zn(t,e,{safe:!0})}catch{return}finally{Error.stackTraceLimit=s}}He.exports=Ts;He.exports.default=Ts;He.exports.parse=Ts;He.exports.safeParse=Wl;He.exports.scan=Gn;var Ql=He.exports;const Zt=Uo(Ql),ht=Symbol("aui.parse-partial-json-object.meta"),Yl=t=>t==null?void 0:t[ht],es=t=>{if(t.length===0)return{[ht]:{state:"partial",partialPath:[]}};try{const e=Zt.parse(t);if(typeof e!="object"||e===null)throw new Error("argsText is expected to be an object");return e[ht]={state:"complete",partialPath:[]},e}catch{try{const[e,s]=Gl(t),r=Zt.parse(e);if(typeof r!="object"||r===null)throw new Error("argsText is expected to be an object");return r[ht]={state:"partial",partialPath:s},r}catch{return}}},Kn=(t,e,s)=>{if(typeof t!="object"||t===null)return e.state;if(e.state==="complete")return"complete";if(s.length===0)return e.state;const[r,...n]=s;if(!Object.hasOwn(t,r))return"partial";const[i,...o]=e.partialPath;if(r!==i)return"complete";const a=t[r];return Kn(a,{state:"partial",partialPath:o},n)},Fe=(t,e)=>{const s=Yl(t);if(!s)throw new Error("unable to determine object state");return Kn(t,s,e.map(String))};async function*Jl(){const t=this.getReader();try{for(;;){const{done:e,value:s}=await t.read();if(e)break;yield s}}finally{t.releaseLock()}}function Nt(t){var e;return t[e=Symbol.asyncIterator]??(t[e]=Jl),t}const dr=Symbol.for("aui.tool-response");var ve=class ts{constructor(e){m(this,"artifact");m(this,"result");m(this,"isError");m(this,"modelContent");m(this,"messages");e.artifact!==void 0&&(this.artifact=e.artifact),this.result=e.result,this.isError=e.isError??!1,e.modelContent!==void 0&&(this.modelContent=e.modelContent),e.messages!==void 0&&(this.messages=e.messages)}get[dr](){return!0}static[Symbol.hasInstance](e){return typeof e=="object"&&e!==null&&dr in e}static toResponse(e){return e instanceof ts?e:new ts({result:e===void 0?"<no result>":e})}};function Xl(t,e,s){try{const r=t();if(typeof r=="object"&&r!==null&&"then"in r)return r.then(e,s);e(r)}catch(r){s(r)}}function Le(t,e){let s=t;for(const r of e){if(s==null)return;s=s[r]}return s}var Zl=class{constructor(t,e,s){m(this,"resolve");m(this,"reject");m(this,"disposed",!1);m(this,"fieldPath");this.resolve=t,this.reject=e,this.fieldPath=s}update(t){if(!this.disposed)try{if(Fe(t,this.fieldPath)==="complete"){const e=Le(t,this.fieldPath);e!==void 0&&(this.resolve(e),this.dispose())}}catch(e){this.reject(e),this.dispose()}}end(t){if(!this.disposed)try{const e=Le(t,this.fieldPath);this.resolve(e)}catch(e){this.reject(e)}finally{this.dispose()}}dispose(){this.disposed=!0}},eu=class{constructor(t,e){m(this,"controller");m(this,"disposed",!1);m(this,"fieldPath");this.controller=t,this.fieldPath=e}update(t){if(!this.disposed)try{const e=Le(t,this.fieldPath);e!==void 0&&this.controller.enqueue(e),Fe(t,this.fieldPath)==="complete"&&(this.controller.close(),this.dispose())}catch(e){this.controller.error(e),this.dispose()}}end(){this.disposed||(this.controller.close(),this.dispose())}dispose(){this.disposed=!0}},tu=class{constructor(t,e){m(this,"controller");m(this,"disposed",!1);m(this,"fieldPath");m(this,"lastValue");this.controller=t,this.fieldPath=e}update(t){var e;if(!this.disposed)try{const s=Le(t,this.fieldPath);if(s!==void 0&&typeof s=="string"){const r=s.substring(((e=this.lastValue)==null?void 0:e.length)||0);this.lastValue=s,this.controller.enqueue(r)}Fe(t,this.fieldPath)==="complete"&&(this.controller.close(),this.dispose())}catch(s){this.controller.error(s),this.dispose()}}end(){this.disposed||(this.controller.close(),this.dispose())}dispose(){this.disposed=!0}},su=class{constructor(t,e){m(this,"controller");m(this,"disposed",!1);m(this,"fieldPath");m(this,"processedIndexes",new Set);this.controller=t,this.fieldPath=e}update(t){if(!this.disposed)try{const e=Le(t,this.fieldPath);if(!Array.isArray(e))return;for(let s=0;s<e.length;s++)this.processedIndexes.has(s)||Fe(t,[...this.fieldPath,s])==="complete"&&(this.controller.enqueue(e[s]),this.processedIndexes.add(s));Fe(t,this.fieldPath)==="complete"&&(this.controller.close(),this.dispose())}catch(e){this.controller.error(e),this.dispose()}}end(){this.disposed||(this.controller.close(),this.dispose())}dispose(){this.disposed=!0}},ru=class{constructor(t){m(this,"argTextDeltas");m(this,"handles",new Set);m(this,"args",es(""));m(this,"finished",!1);this.argTextDeltas=t,this.processStream()}async processStream(){try{let t="";const e=this.argTextDeltas.getReader();for(;;){const{value:s,done:r}=await e.read();if(r)break;t+=s;const n=es(t);if(n!==void 0){this.args=n;for(const i of this.handles)i.update(n)}}}catch(t){console.error("Error processing argument stream:",t)}finally{this.finished=!0;for(const t of this.handles)t.end(this.args);this.handles.clear()}}get(...t){return new Promise((e,s)=>{const r=new Zl(e,s,t);if(this.args&&Fe(this.args,t)==="complete"){const n=Le(this.args,t);if(n!==void 0){e(n);return}}if(this.finished){r.end(this.args);return}this.handles.add(r),r.update(this.args)})}streamValues(...t){const e=t;let s;return Nt(new ReadableStream({start:r=>{s=new eu(r,e),this.finished||this.handles.add(s),s.update(this.args),this.finished&&s.end()},cancel:()=>{s&&(s.dispose(),this.handles.delete(s))}}))}streamText(...t){const e=t;let s;return Nt(new ReadableStream({start:r=>{s=new tu(r,e),this.finished||this.handles.add(s),s.update(this.args),this.finished&&s.end()},cancel:()=>{s&&(s.dispose(),this.handles.delete(s))}}))}forEach(...t){const e=t;let s;return Nt(new ReadableStream({start:r=>{s=new su(r,e),this.finished||this.handles.add(s),s.update(this.args),this.finished&&s.end()},cancel:()=>{s&&(s.dispose(),this.handles.delete(s))}}))}},nu=class{constructor(t){m(this,"promise");this.promise=t}get(){return this.promise}},iu=class{constructor(){m(this,"args");m(this,"response");m(this,"writable");m(this,"resolve");m(this,"argsText","");m(this,"result",{get:async()=>(await this.response.get()).result});const t=new TransformStream;this.writable=t.writable,this.args=new ru(t.readable);const{promise:e,resolve:s}=ws();this.resolve=s,this.response=new nu(e)}async appendArgsTextDelta(t){const e=this.writable.getWriter();try{await e.write(t)}catch(s){console.warn(s)}finally{e.releaseLock()}this.argsText+=t}async finishArgsText(){const t=this.writable.getWriter();try{await t.close()}catch(e){console.warn(e)}finally{t.releaseLock()}}setResponse(t){this.resolve(t)}},ou=class extends Ll{constructor(t){const e=new Map,s=new Map;super(r=>{const n=new TransformStream({async transform(i,o){switch((i.type!=="part-finish"||i.meta.type!=="tool-call")&&o.enqueue(i),i.type){case"part-start":if(i.part.type==="tool-call"){const a=new iu;s.set(i.part.toolCallId,a),t.streamCall({reader:a,toolCallId:i.part.toolCallId,toolName:i.part.toolName})}break;case"text-delta":if(i.meta.type==="tool-call"){const a=i.meta.toolCallId,c=s.get(a);if(!c)throw new Error("No controller found for tool call");await c.appendArgsTextDelta(i.textDelta)}break;case"result":{if(i.meta.type!=="tool-call")break;const{toolCallId:a}=i.meta,c=s.get(a);if(!c)throw new Error("No controller found for tool call");c.setResponse(new ve({result:i.result,artifact:i.artifact,isError:i.isError,modelContent:i.modelContent}));break}case"tool-call-args-text-finish":{if(i.meta.type!=="tool-call")break;const{toolCallId:a,toolName:c}=i.meta,l=s.get(a);if(!l)throw new Error("No controller found for tool call");await l.finishArgsText();let u=!1;const h=Xl(()=>{var g;let d;try{d=Zt.parse(l.argsText)}catch(b){throw new Error(`Function parameter parsing failed. ${JSON.stringify(b.message)}`)}const f=t.execute({toolCallId:a,toolName:c,args:d});return f!==void 0&&(u=!0,(g=t.onExecutionStart)==null||g.call(t,a,c)),f},d=>{var g;if(u&&((g=t.onExecutionEnd)==null||g.call(t,a,c)),d===void 0)return;const f=new ve({artifact:d.artifact,result:d.result,isError:d.isError,messages:d.messages,modelContent:d.modelContent});l.setResponse(f),o.enqueue({type:"result",path:i.path,...f})},d=>{var g;u&&((g=t.onExecutionEnd)==null||g.call(t,a,c));const f=new ve({result:String(d),isError:!0});l.setResponse(f),o.enqueue({type:"result",path:i.path,...f})});h&&e.set(a,h);break}case"part-finish":{if(i.meta.type!=="tool-call")break;const{toolCallId:a}=i.meta,c=e.get(a);c?c.then(()=>{e.delete(a),s.delete(a),o.enqueue(i)}):o.enqueue(i)}}},async flush(){await Promise.all(e.values())}});return r.pipeThrough(new qn).pipeThrough(n)})}};const au=t=>typeof t=="object"&&t!==null&&"~standard"in t&&t["~standard"].version===1;function cu(t,e,s,r){const n=t==null?void 0:t[s.toolName];return n!=null&&n.execute?(async o=>{if(e.aborted)return new ve({result:"Tool execution was cancelled.",isError:!0});let a=o;if(au(n.parameters)){let u=n.parameters["~standard"].validate(s.args);u instanceof Promise&&(u=await u),u.issues&&(a=n.experimental_onSchemaValidationError??(()=>{throw new Error(`Function parameter validation failed. ${JSON.stringify(u.issues)}`)}))}const c=new Promise(u=>{const h=()=>{queueMicrotask(()=>{queueMicrotask(()=>{u(new ve({result:"Tool execution was cancelled.",isError:!0}))})})};e.aborted?h():e.addEventListener("abort",h,{once:!0})}),l=(async()=>{const u=await a(s.args,{toolCallId:s.toolCallId,abortSignal:e,human:d=>r(s.toolCallId,d)}),h=ve.toResponse(u);if(n.toModelOutput&&!h.isError&&h.modelContent===void 0)try{const d=await n.toModelOutput({toolCallId:s.toolCallId,input:s.args,output:h.result});return new ve({result:h.result,artifact:h.artifact,isError:h.isError,messages:h.messages,modelContent:d})}catch(d){console.warn(`[assistant-stream] tool "${s.toolName}" toModelOutput threw; falling back to default projection.`,d)}return h})();return Promise.race([l,c])})(n.execute):void 0}function lu(t,e,s,r,n){var i,o;(o=(i=t==null?void 0:t[r.toolName])==null?void 0:i.streamCall)==null||o.call(i,s,{toolCallId:r.toolCallId,abortSignal:e,human:a=>n(r.toolCallId,a)})}function uu(t,e,s,r){const n=typeof t=="function"?t:()=>t,i=typeof e=="function"?e:()=>e;return new ou({execute:o=>cu(n(),i(),o,s),streamCall:({reader:o,...a})=>lu(n(),i(),o,a,s),onExecutionStart:r==null?void 0:r.onExecutionStart,onExecutionEnd:r==null?void 0:r.onExecutionEnd})}let du=(t,e=21)=>(s=e)=>{let r="",n=s|0;for(;n-- >0;)r+=t[Math.random()*t.length|0];return r};const Ae=du("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",7),Wn=t=>{const e=_(7),{index:s,children:r}=t;let n;e[0]!==s?(n=re({source:"message",query:{type:"index",index:s},get:c=>c.message().attachment({index:s})}),e[0]=s,e[1]=n):n=e[1];let i;e[2]!==n?(i={attachment:n},e[2]=n,e[3]=i):i=e[3];const o=F(i);let a;return e[4]!==o||e[5]!==r?(a=p.jsx(ue,{value:o,children:r}),e[4]=o,e[5]=r,e[6]=a):a=e[6],a},Qn=t=>{const e=_(7),{index:s,children:r}=t;let n;e[0]!==s?(n=re({source:"composer",query:{type:"index",index:s},get:c=>c.composer().attachment({index:s})}),e[0]=s,e[1]=n):n=e[1];let i;e[2]!==n?(i={attachment:n},e[2]=n,e[3]=i):i=e[3];const o=F(i);let a;return e[4]!==o||e[5]!==r?(a=p.jsx(ue,{value:o,children:r}),e[4]=o,e[5]=r,e[6]=a):a=e[6],a},Yn=t=>{const e=_(10),{index:s,children:r}=t;let n;e[0]!==s?(n=re({source:"thread",query:{type:"index",index:s},get:l=>l.thread().message({index:s})}),e[0]=s,e[1]=n):n=e[1];let i;e[2]!==s?(i=re({source:"message",query:{},get:l=>l.thread().message({index:s}).composer()}),e[2]=s,e[3]=i):i=e[3];let o;e[4]!==n||e[5]!==i?(o={message:n,composer:i},e[4]=n,e[5]=i,e[6]=o):o=e[6];const a=F(o);let c;return e[7]!==a||e[8]!==r?(c=p.jsx(ue,{value:a,children:r}),e[7]=a,e[8]=r,e[9]=c):c=e[9],c},Cs=t=>{const e=_(7),{index:s,children:r}=t;let n;e[0]!==s?(n=re({source:"message",query:{type:"index",index:s},get:c=>c.message().part({index:s})}),e[0]=s,e[1]=n):n=e[1];let i;e[2]!==n?(i={part:n},e[2]=n,e[3]=i):i=e[3];const o=F(i);let a;return e[4]!==o||e[5]!==r?(a=p.jsx(ue,{value:o,children:r}),e[4]=o,e[5]=r,e[6]=a):a=e[6],a},hu=t=>{const e=_(7),{text:s,isRunning:r}=t;let n;e[0]!==r?(n=r?{type:"running"}:{type:"complete"},e[0]=r,e[1]=n):n=e[1];let i;e[2]!==n||e[3]!==s?(i={type:"text",text:s,status:n},e[2]=n,e[3]=s,e[4]=i):i=e[4];const o=i;let a;return e[5]!==o?(a={getState:()=>o,addToolResult:pu,resumeToolCall:gu,respondToToolApproval:mu},e[5]=o,e[6]=a):a=e[6],a},fu=q(hu),Is=t=>{const e=_(8),{text:s,isRunning:r,children:n}=t,i=r===void 0?!1:r;let o;e[0]!==i||e[1]!==s?(o=fu({text:s,isRunning:i}),e[0]=i,e[1]=s,e[2]=o):o=e[2];let a;e[3]!==o?(a={part:o},e[3]=o,e[4]=a):a=e[4];const c=F(a);let l;return e[5]!==c||e[6]!==n?(l=p.jsx(ue,{value:c,children:n}),e[5]=c,e[6]=n,e[7]=l):l=e[7],l};function pu(){throw new Error("Not supported")}function gu(){throw new Error("Not supported")}function mu(){throw new Error("Not supported")}const bu=Object.freeze({type:"complete"}),_u=t=>{var h;const e=_(9),{parts:s,getMessagePart:r}=t,[n,i]=G(!0),o=((h=s[s.length-1])==null?void 0:h.status)??bu;let a;e[0]!==n||e[1]!==s||e[2]!==o?(a={parts:s,collapsed:n,status:o},e[0]=n,e[1]=s,e[2]=o,e[3]=a):a=e[3];const c=a;let l;e[4]!==c?(l=()=>c,e[4]=c,e[5]=l):l=e[5];let u;return e[6]!==r||e[7]!==l?(u={getState:l,setCollapsed:i,part:r},e[6]=r,e[7]=l,e[8]=u):u=e[8],u},yu=q(_u),vu=t=>{const e=_(5),{startIndex:s,endIndex:r,children:n}=t,i=P(Su).slice(s,r+1),o=F(),a=yu({parts:i,getMessagePart:h=>{const{index:d}=h;if(d<0||d>=i.length)throw new Error(`ChainOfThought part index ${d} is out of bounds (0..${i.length-1})`);return o.message().part({index:s+d})}});let c;e[0]!==a?(c={chainOfThought:a},e[0]=a,e[1]=c):c=e[1];const l=F(c);let u;return e[2]!==l||e[3]!==n?(u=p.jsx(ue,{value:l,children:n}),e[2]=l,e[3]=n,e[4]=u):u=e[4],u};function Su(t){return t.message.parts}const Jn=t=>{const e=_(7),{index:s,children:r}=t;let n;e[0]!==s?(n=re({source:"suggestions",query:{index:s},get:c=>c.suggestions().suggestion({index:s})}),e[0]=s,e[1]=n):n=e[1];let i;e[2]!==n?(i={suggestion:n},e[2]=n,e[3]=i):i=e[3];const o=F(i);let a;return e[4]!==o||e[5]!==r?(a=p.jsx(ue,{value:o,children:r}),e[4]=o,e[5]=r,e[6]=a):a=e[6],a},xu=t=>{const e=_(7),{index:s,children:r}=t;let n;e[0]!==s?(n=re({source:"composer",query:{index:s},get:c=>c.composer().queueItem({index:s})}),e[0]=s,e[1]=n):n=e[1];let i;e[2]!==n?(i={queueItem:n},e[2]=n,e[3]=i):i=e[3];const o=F(i);let a;return e[4]!==o||e[5]!==r?(a=p.jsx(ue,{value:o,children:r}),e[4]=o,e[5]=r,e[6]=a):a=e[6],a},Me=Symbol("innerMessage"),Ft=Symbol("innerMessages"),wu=[],Tu=(t,e)=>{Me in t||(t[Me]=e)},Cu=t=>{const e="messages"in t?t.messages:t,s=e[Ft]||e[Me];return s?Array.isArray(s)?s:(e[Ft]=[s],e[Ft]):wu},de=Symbol("skip-update");function Iu(t,e){if(t===void 0&&e===void 0)return!0;if(t===void 0||e===void 0)return!1;for(const s of Object.keys(t)){const r=t[s],n=e[s];if(!Object.is(r,n))return!1}return!0}var Eu=class{constructor(){m(this,"_subscribers",new Set)}subscribe(t){return this._subscribers.add(t),()=>this._subscribers.delete(t)}waitForUpdate(){return new Promise(t=>{const e=this.subscribe(()=>{e(),t()})})}_notifySubscribers(){const t=[];for(const e of this._subscribers)try{e()}catch(s){t.push(s)}if(t.length>0){if(t.length===1)throw t[0];for(const e of t)console.error(e);throw new AggregateError(t)}}},$t=class{constructor(){m(this,"_subscriptions",new Set);m(this,"_connection")}get isConnected(){return!!this._connection}notifySubscribers(t){for(const e of this._subscriptions)e(t)}_updateConnection(){var t;if(this._subscriptions.size>0){if(this._connection)return;this._connection=this._connect()}else(t=this._connection)==null||t.call(this),this._connection=void 0}subscribe(t){return this._subscriptions.add(t),this._updateConnection(),()=>{this._subscriptions.delete(t),this._updateConnection()}}},ce=class extends $t{constructor(e){super();m(this,"binding");m(this,"_previousState");m(this,"getState",()=>(this.isConnected||this._syncState(),this._previousState));this.binding=e;const s=e.getState();if(s===de)throw new Error("Entry not available in the store");this._previousState=s}get path(){return this.binding.path}_syncState(){const e=this.binding.getState();return e===de||Iu(e,this._previousState)?!1:(this._previousState=e,!0)}_connect(){const e=()=>{this._syncState()&&this.notifySubscribers()};return this.binding.subscribe(e)}},Es=class extends $t{constructor(e){super();m(this,"binding");m(this,"_previousStateDirty",!0);m(this,"_previousState");m(this,"getState",()=>{if(!this.isConnected||this._previousStateDirty){const e=this.binding.getState();e!==de&&(this._previousState=e),this._previousStateDirty=!1}if(this._previousState===void 0)throw new Error("Entry not available in the store");return this._previousState});this.binding=e}get path(){return this.binding.path}_connect(){const e=()=>{this._previousStateDirty=!0,this.notifySubscribers()};return this.binding.subscribe(e)}},St=class extends $t{constructor(e){super();m(this,"binding");this.binding=e}get path(){return this.binding.path}getState(){return this.binding.getState()}outerSubscribe(e){return this.binding.subscribe(e)}_connect(){const e=()=>{this.notifySubscribers()};let s=this.binding.getState(),r=s==null?void 0:s.subscribe(e);const n=()=>{const o=this.binding.getState();o!==s&&(s=o,r==null||r(),r=o==null?void 0:o.subscribe(e),e())},i=this.outerSubscribe(n);return()=>{i==null||i(),r==null||r()}}},Xn=class extends $t{constructor(e){super();m(this,"config");this.config=e}getState(){return this.config.binding.getState()}outerSubscribe(e){return this.config.binding.subscribe(e)}_connect(){const e=o=>{this.notifySubscribers(o)};let s=this.config.binding.getState(),r=s==null?void 0:s.unstable_on(this.config.event,e);const n=()=>{const o=this.config.binding.getState();o!==s&&(s=o,r==null||r(),r=o==null?void 0:o.unstable_on(this.config.event,e))},i=this.outerSubscribe(n);return()=>{i==null||i(),r==null||r()}}},Zn=class{constructor(t){m(this,"_core");this._core=t,this.__internal_bindMethods()}get path(){return this._core.path}__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(t){return this._core.subscribe(t)}},ei=class extends Zn{constructor(e,s){super(e);m(this,"_composerApi");this._composerApi=s}remove(){const e=this._composerApi.getState();if(!e)throw new Error("Composer is not available");return e.removeAttachment(this.getState().id)}},Ru=class extends ei{get source(){return"thread-composer"}},Au=class extends ei{get source(){return"edit-composer"}},Mu=class extends Zn{get source(){return"message"}remove(){throw new Error("Message attachments cannot be removed")}};const xt=Object.freeze([]),ti=Object.freeze({}),Pu=t=>Object.freeze({type:"thread",isEditing:(t==null?void 0:t.isEditing)??!1,canCancel:(t==null?void 0:t.canCancel)??!1,canSend:(t==null?void 0:t.canSend)??!1,isEmpty:(t==null?void 0:t.isEmpty)??!0,attachments:(t==null?void 0:t.attachments)??xt,text:(t==null?void 0:t.text)??"",role:(t==null?void 0:t.role)??"user",runConfig:(t==null?void 0:t.runConfig)??ti,attachmentAccept:(t==null?void 0:t.attachmentAccept)??"",dictation:t==null?void 0:t.dictation,quote:t==null?void 0:t.quote,queue:(t==null?void 0:t.queue)??xt,value:(t==null?void 0:t.text)??""}),ku=t=>Object.freeze({type:"edit",isEditing:(t==null?void 0:t.isEditing)??!1,canCancel:(t==null?void 0:t.canCancel)??!1,canSend:(t==null?void 0:t.canSend)??!1,isEmpty:(t==null?void 0:t.isEmpty)??!0,text:(t==null?void 0:t.text)??"",role:(t==null?void 0:t.role)??"user",attachments:(t==null?void 0:t.attachments)??xt,runConfig:(t==null?void 0:t.runConfig)??ti,attachmentAccept:(t==null?void 0:t.attachmentAccept)??"",dictation:t==null?void 0:t.dictation,quote:t==null?void 0:t.quote,queue:(t==null?void 0:t.queue)??xt,parentId:(t==null?void 0:t.parentId)??null,sourceId:(t==null?void 0:t.sourceId)??null,value:(t==null?void 0:t.text)??""});var si=class{constructor(t){m(this,"_core");m(this,"_eventSubscriptionSubjects",new Map);this._core=t}get path(){return this._core.path}__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.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(t){const e=this._core.getState();if(!e)throw new Error("Composer is not available");e.setText(t)}setRunConfig(t){const e=this._core.getState();if(!e)throw new Error("Composer is not available");e.setRunConfig(t)}addAttachment(t){const e=this._core.getState();if(!e)throw new Error("Composer is not available");return e.addAttachment(t)}reset(){const t=this._core.getState();if(!t)throw new Error("Composer is not available");return t.reset()}clearAttachments(){const t=this._core.getState();if(!t)throw new Error("Composer is not available");return t.clearAttachments()}send(t){const e=this._core.getState();if(!e)throw new Error("Composer is not available");e.send(t)}cancel(){const t=this._core.getState();if(!t)throw new Error("Composer is not available");t.cancel()}steerQueueItem(t){const e=this._core.getState();if(!e)throw new Error("Composer is not available");e.steerQueueItem(t)}removeQueueItem(t){const e=this._core.getState();if(!e)throw new Error("Composer is not available");e.removeQueueItem(t)}setRole(t){const e=this._core.getState();if(!e)throw new Error("Composer is not available");e.setRole(t)}startDictation(){const t=this._core.getState();if(!t)throw new Error("Composer is not available");t.startDictation()}stopDictation(){const t=this._core.getState();if(!t)throw new Error("Composer is not available");t.stopDictation()}setQuote(t){const e=this._core.getState();if(!e)throw new Error("Composer is not available");e.setQuote(t)}subscribe(t){return this._core.subscribe(t)}unstable_on(t,e){let s=this._eventSubscriptionSubjects.get(t);return s||(s=new Xn({event:t,binding:this._core}),this._eventSubscriptionSubjects.set(t,s)),s.subscribe(e)}},$u=class extends si{constructor(e){const s=new Es({path:e.path,getState:()=>Pu(e.getState()),subscribe:r=>e.subscribe(r)});super({path:e.path,getState:()=>e.getState(),subscribe:r=>s.subscribe(r)});m(this,"_getState");this._getState=s.getState.bind(s),this.__internal_bindMethods()}get path(){return this._core.path}get type(){return"thread"}getState(){return this._getState()}getAttachmentByIndex(e){return new Ru(new ce({path:{...this.path,attachmentSource:"thread-composer",attachmentSelector:{type:"index",index:e},ref:`${this.path.ref}.attachments[${e}]`},getState:()=>{const s=this.getState().attachments[e];return s?{...s,source:"thread-composer"}:de},subscribe:s=>this._core.subscribe(s)}),this._core)}},Du=class extends si{constructor(e,s){const r=new Es({path:e.path,getState:()=>ku(e.getState()),subscribe:n=>e.subscribe(n)});super({path:e.path,getState:()=>e.getState(),subscribe:n=>r.subscribe(n)});m(this,"_beginEdit");m(this,"_getState");this._beginEdit=s,this._getState=r.getState.bind(r),this.__internal_bindMethods()}get path(){return this._core.path}get type(){return"edit"}__internal_bindMethods(){super.__internal_bindMethods(),this.beginEdit=this.beginEdit.bind(this)}getState(){return this._getState()}beginEdit(){this._beginEdit()}getAttachmentByIndex(e){return new Au(new ce({path:{...this.path,attachmentSource:"edit-composer",attachmentSelector:{type:"index",index:e},ref:`${this.path.ref}.attachments[${e}]`},getState:()=>{const s=this.getState().attachments[e];return s?{...s,source:"edit-composer"}:de},subscribe:s=>this._core.subscribe(s)}),this._core)}};const et=t=>t.content.filter(e=>e.type==="text").map(e=>e.text).join(`
|
|
4
|
+
|
|
5
|
+
`),hr={"allow-once":!0,"allow-always":!0,"reject-once":!1,"reject-always":!1},ju=(t,e)=>{var n;let s,r;if("optionId"in e){const i=(n=t.options)==null?void 0:n.find(o=>o.id===e.optionId);if(!i)throw new Error(`Tool approval has no option with id "${e.optionId}"`);if("approved"in e)s=e.approved;else{if(!Object.hasOwn(hr,i.kind))throw new Error(`Tool approval option "${i.id}" has a custom kind "${i.kind}"; respond with an explicit approved value instead`);s=hr[i.kind]}r=i.id}else s=e.approved;return{approvalId:t.id,approved:s,...r!==void 0&&{optionId:r},...e.reason!=null&&{reason:e.reason}}};var fr=class{constructor(t,e,s){m(this,"contentBinding");m(this,"messageApi");m(this,"threadApi");this.contentBinding=t,this.messageApi=e,this.threadApi=s,this.__internal_bindMethods()}get path(){return this.contentBinding.path}__internal_bindMethods(){this.addToolResult=this.addToolResult.bind(this),this.resumeToolCall=this.resumeToolCall.bind(this),this.respondToToolApproval=this.respondToToolApproval.bind(this),this.getState=this.getState.bind(this),this.subscribe=this.subscribe.bind(this)}getState(){return this.contentBinding.getState()}addToolResult(t){const e=this.contentBinding.getState();if(!e)throw new Error("Message part is not available");if(e.type!=="tool-call")throw new Error("Tried to add tool result to non-tool message part");if(!this.messageApi)throw new Error("Message API is not available. This is likely a bug in assistant-ui.");if(!this.threadApi)throw new Error("Thread API is not available");const s=this.messageApi.getState();if(!s)throw new Error("Message is not available");const r=e.toolName,n=e.toolCallId,i=ve.toResponse(t);this.threadApi.getState().addToolResult({messageId:s.id,toolName:r,toolCallId:n,result:i.result,artifact:i.artifact,isError:i.isError})}resumeToolCall(t){const e=this.contentBinding.getState();if(!e)throw new Error("Message part is not available");if(e.type!=="tool-call")throw new Error("Tried to resume tool call on non-tool message part");if(!this.threadApi)throw new Error("Thread API is not available");const s=e.toolCallId;this.threadApi.getState().resumeToolCall({toolCallId:s,payload:t})}respondToToolApproval(t){const e=this.contentBinding.getState();if(!e)throw new Error("Message part is not available");if(e.type!=="tool-call")throw new Error("Tried to respond to tool approval on non-tool message part");if(!e.approval||e.approval.approved!==void 0||e.approval.resolution!==void 0)throw new Error("Tool call has no pending approval");if(!this.threadApi)throw new Error("Thread API is not available");this.threadApi.getState().respondToToolApproval(ju(e.approval,t))}subscribe(t){return this.contentBinding.subscribe(t)}};const ot=Object.freeze({type:"complete"}),Bu=(t,e,s)=>{if(t.role!=="assistant")return ot;if(s.type==="tool-call")return s.result?ot:t.status;const r=e===Math.max(0,t.content.length-1);return t.status.type==="requires-action"?ot:r?t.status:ot},pr=(t,e)=>{const s=t.content[e];if(!s)return de;const r=Bu(t,e,s);return Object.freeze({...s,[Me]:s[Me],status:r})};var Ou=class{constructor(t,e){m(this,"_core");m(this,"_threadBinding");m(this,"composer");m(this,"_getEditComposerRuntimeCore",()=>this._threadBinding.getState().getEditComposer(this._core.getState().id));this._core=t,this._threadBinding=e,this.composer=new Du(new St({path:{...this.path,ref:`${this.path.ref}${this.path.ref}.composer`,composerSource:"edit"},getState:this._getEditComposerRuntimeCore,subscribe:s=>this._threadBinding.subscribe(s)}),()=>this._threadBinding.getState().beginEdit(this._core.getState().id)),this.__internal_bindMethods()}get path(){return this._core.path}__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)}getState(){return this._core.getState()}delete(){const t=this._core.getState();return this._threadBinding.getState().deleteMessage(t.id)}reload(t={}){const e=this._getEditComposerRuntimeCore(),s=e??this._threadBinding.getState().composer,r=e??s,{runConfig:n=r.runConfig}=t,i=this._core.getState();if(i.role!=="assistant")throw new Error("Can only reload assistant messages");this._threadBinding.getState().startRun({parentId:i.parentId,sourceId:i.id,runConfig:n})}speak(){const t=this._core.getState();return this._threadBinding.getState().speak(t.id)}stopSpeaking(){var e;const t=this._core.getState();if(((e=this._threadBinding.getState().speech)==null?void 0:e.messageId)===t.id)this._threadBinding.getState().stopSpeaking();else throw new Error("Message is not being spoken")}submitFeedback({type:t}){const e=this._core.getState();this._threadBinding.getState().submitFeedback({messageId:e.id,type:t})}switchToBranch({position:t,branchId:e}){const s=this._core.getState();if(e&&t)throw new Error("May not specify both branchId and position");if(!e&&!t)throw new Error("Must specify either branchId or position");const r=this._threadBinding.getState().getBranches(s.id);let n=e;if(t==="previous"?n=r[s.branchNumber-2]:t==="next"&&(n=r[s.branchNumber]),!n)throw new Error("Branch not found");this._threadBinding.getState().switchToBranch(n)}unstable_getCopyText(){return et(this.getState())}subscribe(t){return this._core.subscribe(t)}getMessagePartByIndex(t){if(t<0)throw new Error("Message part index must be >= 0");return new fr(new ce({path:{...this.path,ref:`${this.path.ref}${this.path.ref}.content[${t}]`,messagePartSelector:{type:"index",index:t}},getState:()=>pr(this.getState(),t),subscribe:e=>this._core.subscribe(e)}),this._core,this._threadBinding)}getMessagePartByToolCallId(t){return new fr(new ce({path:{...this.path,ref:this.path.ref+`${this.path.ref}.content[toolCallId=${JSON.stringify(t)}]`,messagePartSelector:{type:"toolCallId",toolCallId:t}},getState:()=>{const e=this._core.getState(),s=e.content.findIndex(r=>r.type==="tool-call"&&r.toolCallId===t);return s===-1?de:pr(e,s)},subscribe:e=>this._core.subscribe(e)}),this._core,this._threadBinding)}getAttachmentByIndex(t){return new Mu(new ce({path:{...this.path,ref:`${this.path.ref}${this.path.ref}.attachments[${t}]`,attachmentSource:"message",attachmentSelector:{type:"index",index:t}},getState:()=>{var s;const e=(s=this.getState().attachments)==null?void 0:s[t];return e?{...e,source:"message"}:de},subscribe:e=>this._core.subscribe(e)}))}};const Nu=t=>({parentId:t.parentId??null,sourceId:t.sourceId??null,runConfig:t.runConfig??{},...t.stream?{stream:t.stream}:{}}),Fu=t=>({parentId:t.parentId??null,sourceId:t.sourceId??null,runConfig:t.runConfig??{}}),Lu=(t,e)=>{var s,r;return typeof e=="string"?{createdAt:new Date,parentId:((s=t.at(-1))==null?void 0:s.id)??null,sourceId:null,runConfig:{},role:"user",content:[{type:"text",text:e}],attachments:[],metadata:{custom:{}}}:{createdAt:e.createdAt??new Date,parentId:e.parentId??((r=t.at(-1))==null?void 0:r.id)??null,sourceId:e.sourceId??null,role:e.role??"user",content:e.content,attachments:e.attachments??[],metadata:e.metadata??{custom:{}},runConfig:e.runConfig??{},startRun:e.startRun}},Vu=(t,e)=>{const s=t.messages.at(-1);return Object.freeze({threadId:e.id,metadata:e,capabilities:t.capabilities,isDisabled:t.isDisabled,isLoading:t.isLoading,isRunning:t.isRunning??((s==null?void 0:s.role)!=="assistant"?!1:s.status.type==="running"),messages:t.messages,state:t.state,suggestions:t.suggestions,extras:t.extras,speech:t.speech,voice:t.voice})};var Uu=class{constructor(t,e){m(this,"_threadBinding");m(this,"composer");m(this,"_eventSubscriptionSubjects",new Map);const s=new ce({path:t.path,getState:()=>Vu(t.getState(),e.getState()),subscribe:r=>{const n=t.subscribe(r),i=e.subscribe(r);return()=>{n(),i()}}});this._threadBinding={path:t.path,getState:()=>t.getState(),getStateState:()=>s.getState(),outerSubscribe:r=>t.outerSubscribe(r),subscribe:r=>t.subscribe(r)},this.composer=new $u(new St({path:{...this.path,ref:`${this.path.ref}.composer`,composerSource:"thread"},getState:()=>this._threadBinding.getState().composer,subscribe:r=>this._threadBinding.subscribe(r)})),this.__internal_bindMethods()}get path(){return this._threadBinding.path}get __internal_threadBinding(){return this._threadBinding}__internal_bindMethods(){this.append=this.append.bind(this),this.deleteMessage=this.deleteMessage.bind(this),this.resumeRun=this.resumeRun.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.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)}getState(){return this._threadBinding.getStateState()}append(t){this._threadBinding.getState().append(Lu(this._threadBinding.getState().messages,t))}deleteMessage(t){return this._threadBinding.getState().deleteMessage(t)}subscribe(t){return this._threadBinding.subscribe(t)}getModelContext(){return this._threadBinding.getState().getModelContext()}startRun(t){return this._threadBinding.getState().startRun(Fu(t))}resumeRun(t){return this._threadBinding.getState().resumeRun(Nu(t))}exportExternalState(){return this._threadBinding.getState().exportExternalState()}importExternalState(t){this._threadBinding.getState().importExternalState(t)}cancelRun(){this._threadBinding.getState().cancelRun()}stopSpeaking(){return this._threadBinding.getState().stopSpeaking()}connectVoice(){this._threadBinding.getState().connectVoice()}disconnectVoice(){this._threadBinding.getState().disconnectVoice()}getVoiceVolume(){return this._threadBinding.getState().getVoiceVolume()}subscribeVoiceVolume(t){return this._threadBinding.getState().subscribeVoiceVolume(t)}muteVoice(){this._threadBinding.getState().muteVoice()}unmuteVoice(){this._threadBinding.getState().unmuteVoice()}export(){return this._threadBinding.getState().export()}import(t){this._threadBinding.getState().import(t)}reset(t){this._threadBinding.getState().reset(t)}getMessageByIndex(t){if(t<0)throw new Error("Message index must be >= 0");return this._getMessageRuntime({...this.path,ref:`${this.path.ref}.messages[${t}]`,messageSelector:{type:"index",index:t}},()=>{var r;const e=this._threadBinding.getState().messages,s=e[t];if(s)return{message:s,parentId:((r=e[t-1])==null?void 0:r.id)??null,index:t}})}getMessageById(t){return this._getMessageRuntime({...this.path,ref:`${this.path.ref}.messages[messageId=${JSON.stringify(t)}]`,messageSelector:{type:"messageId",messageId:t}},()=>this._threadBinding.getState().getMessageById(t))}_getMessageRuntime(t,e){return new Ou(new ce({path:t,getState:()=>{var c;const{message:s,parentId:r,index:n}=e()??{},{messages:i,speech:o}=this._threadBinding.getState();if(!s||r===void 0||n===void 0)return de;const a=this._threadBinding.getState().getBranches(s.id);return{...s,[Me]:s[Me],index:n,isLast:((c=i.at(-1))==null?void 0:c.id)===s.id,parentId:r,branchNumber:a.indexOf(s.id)+1,branchCount:a.length,speech:(o==null?void 0:o.messageId)===s.id?o:void 0}},subscribe:s=>this._threadBinding.subscribe(s)}),this._threadBinding)}unstable_on(t,e){let s=this._eventSubscriptionSubjects.get(t);return s||(s=new Xn({event:t,binding:this._threadBinding}),this._eventSubscriptionSubjects.set(t,s)),s.subscribe(e)}};const qu=ae(null),Hu=()=>he(qu);var at=class{constructor(t,e){m(this,"_core");m(this,"_threadListBinding");this._core=t,this._threadListBinding=e,this.__internal_bindMethods()}get path(){return this._core.path}__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(t){const e=this._core.getState();return this._threadListBinding.switchToThread(e.id,t)}rename(t){const e=this._core.getState();return this._threadListBinding.rename(e.id,t)}updateCustom(t){const e=this._core.getState();if(!this._threadListBinding.updateCustom)throw new Error("Thread list runtime does not support updating custom metadata");return this._threadListBinding.updateCustom(e.id,t)}archive(){const t=this._core.getState();return this._threadListBinding.archive(t.id)}unarchive(){const t=this._core.getState();return this._threadListBinding.unarchive(t.id)}delete(){const t=this._core.getState();return this._threadListBinding.delete(t.id)}initialize(){const t=this._core.getState();return this._threadListBinding.initialize(t.id)}generateTitle(){const t=this._core.getState();return this._threadListBinding.generateTitle(t.id)}unstable_on(t,e){let s=this._core.getState().isMain,r=this._core.getState().id;return this.subscribe(()=>{const n=this._core.getState(),i=n.isMain,o=n.id;s===i&&r===o||(s=i,r=o,!(t==="switchedTo"&&!i)&&(t==="switchedAway"&&i||e({})))})}subscribe(t){return this._core.subscribe(t)}detach(){const t=this._core.getState();this._threadListBinding.detach(t.id)}__internal_getRuntime(){return this}};const gr=Promise.resolve(),zu=t=>({mainThreadId:t.mainThreadId,newThreadId:t.newThreadId,threadIds:t.threadIds,archivedThreadIds:t.archivedThreadIds,isLoading:t.isLoading,isLoadingMore:t.isLoadingMore??!1,hasMore:t.hasMore??!1,threadItems:t.threadItems}),ct=(t,e)=>{if(e===void 0)return de;const s=t.getItemById(e);return s?{id:s.id,remoteId:s.remoteId,externalId:s.externalId,title:s.title,status:s.status,lastMessageAt:s.lastMessageAt,custom:s.custom,isMain:s.id===t.mainThreadId}:de};var Gu=class{constructor(t,e=Uu){m(this,"_core");m(this,"_runtimeFactory");m(this,"_getState");m(this,"_mainThreadListItemRuntime");m(this,"main");this._core=t,this._runtimeFactory=e;const s=new Es({path:{},getState:()=>zu(t),subscribe:r=>t.subscribe(r)});this._getState=s.getState.bind(s),this._mainThreadListItemRuntime=new at(new ce({path:{ref:"threadItems[main]",threadSelector:{type:"main"}},getState:()=>ct(this._core,this._core.mainThreadId),subscribe:r=>this._core.subscribe(r)}),this._core),this.main=new e(new St({path:{ref:"threads.main",threadSelector:{type:"main"}},getState:()=>t.getMainThreadRuntimeCore(),subscribe:r=>t.subscribe(r)}),this._mainThreadListItemRuntime),this.__internal_bindMethods()}__internal_bindMethods(){this.switchToThread=this.switchToThread.bind(this),this.switchToNewThread=this.switchToNewThread.bind(this),this.getLoadThreadsPromise=this.getLoadThreadsPromise.bind(this),this.reload=this.reload.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(t,e){return this._core.switchToThread(t,e)}switchToNewThread(){return this._core.switchToNewThread()}getLoadThreadsPromise(){return this._core.getLoadThreadsPromise()}reload(){var t,e;return((e=(t=this._core).reload)==null?void 0:e.call(t))??gr}loadMore(){var t,e;return((e=(t=this._core).loadMore)==null?void 0:e.call(t))??gr}getState(){return this._getState()}subscribe(t){return this._core.subscribe(t)}get mainItem(){return this._mainThreadListItemRuntime}getById(t){return new this._runtimeFactory(new St({path:{ref:`threads[threadId=${JSON.stringify(t)}]`,threadSelector:{type:"threadId",threadId:t}},getState:()=>this._core.getThreadRuntimeCore(t),subscribe:e=>this._core.subscribe(e)}),this.mainItem)}getItemByIndex(t){return new at(new ce({path:{ref:`threadItems[${t}]`,threadSelector:{type:"index",index:t}},getState:()=>ct(this._core,this._core.threadIds[t]),subscribe:e=>this._core.subscribe(e)}),this._core)}getArchivedItemByIndex(t){return new at(new ce({path:{ref:`archivedThreadItems[${t}]`,threadSelector:{type:"archiveIndex",index:t}},getState:()=>ct(this._core,this._core.archivedThreadIds[t]),subscribe:e=>this._core.subscribe(e)}),this._core)}getItemById(t){return new at(new ce({path:{ref:`threadItems[threadId=${t}]`,threadSelector:{type:"threadId",threadId:t}},getState:()=>ct(this._core,t),subscribe:e=>this._core.subscribe(e)}),this._core)}},Ku=class{constructor(t){m(this,"_core");m(this,"threads");m(this,"_thread");this._core=t,this.threads=new Gu(t.threads),this._thread=this.threads.main,this.__internal_bindMethods()}__internal_bindMethods(){this.registerModelContextProvider=this.registerModelContextProvider.bind(this)}get thread(){return this._thread}registerModelContextProvider(t){return this._core.registerModelContextProvider(t)}},Wu=class{constructor(){m(this,"_contextProvider",new Sn)}registerModelContextProvider(t){return this._contextProvider.registerModelContextProvider(t)}getModelContextProvider(){return this._contextProvider}};const Ce=Object.freeze([]),Ne="DEFAULT_THREAD_ID",Qu=Object.freeze([Ne]),Yu=Object.freeze({id:Ne,remoteId:void 0,externalId:void 0,status:"regular"}),Ju=Promise.resolve(),mr=Object.freeze({[Ne]:Yu});var Xu=class{constructor(t={},e){m(this,"threadFactory");m(this,"_mainThreadId",Ne);m(this,"_threads",Qu);m(this,"_archivedThreads",Ce);m(this,"_threadData",mr);m(this,"adapter",{});m(this,"_mainThread");m(this,"_subscriptions",new Set);this.threadFactory=e,this.__internal_setAdapter(t,!0)}get isLoading(){return this.adapter.isLoading??!1}get newThreadId(){}get threadIds(){return this._threads}get archivedThreadIds(){return this._archivedThreads}get threadItems(){return this._threadData}getLoadThreadsPromise(){return Ju}get mainThreadId(){return this._mainThreadId}getMainThreadRuntimeCore(){return this._mainThread}getThreadRuntimeCore(){throw new Error("Method not implemented.")}getItemById(t){return this._threadData[t]}__internal_setAdapter(t,e=!1){var l,u,h,d;const s=this.adapter;this.adapter=t;const r=t.threadId??Ne,n=t.threads??Ce,i=t.archivedThreads??Ce,o=s.threadId??Ne,a=s.threads??Ce,c=s.archivedThreads??Ce;!e&&o===r&&a===n&&c===i||((a!==n||c!==i||o!==r)&&(this._threadData={...mr,...Object.fromEntries(((l=t.threads)==null?void 0:l.map(f=>[f.id,{...f,remoteId:f.remoteId,externalId:f.externalId,status:"regular"}]))??[]),...Object.fromEntries(((u=t.archivedThreads)==null?void 0:u.map(f=>[f.id,{...f,remoteId:f.remoteId,externalId:f.externalId,status:"archived"}]))??[])}),a!==n&&(this._threads=((h=this.adapter.threads)==null?void 0:h.map(f=>f.id))??Ce),c!==i&&(this._archivedThreads=((d=this.adapter.archivedThreads)==null?void 0:d.map(f=>f.id))??Ce),(e||o!==r)&&(this._mainThreadId=r,this._mainThread=this.threadFactory()),this._threadData[this._mainThreadId]||(this._threadData={...this._threadData,[this._mainThreadId]:{id:this._mainThreadId,remoteId:void 0,externalId:void 0,status:"regular"}}),this._notifySubscribers())}async switchToThread(t,e){if(this._mainThreadId===t)return;const s=this.adapter.onSwitchToThread;if(!s)throw new Error("External store adapter does not support switching to thread");await s(t)}async switchToNewThread(){const t=this.adapter.onSwitchToNewThread;if(!t)throw new Error("External store adapter does not support switching to new thread");await t()}async rename(t,e){const s=this.adapter.onRename;if(!s)throw new Error("External store adapter does not support renaming");await s(t,e)}async updateCustom(t,e){const s=this.adapter.onUpdateCustom;if(!s)throw new Error("External store adapter does not support updating custom metadata");await s(t,e)}async detach(){}async archive(t){const e=this.adapter.onArchive;if(!e)throw new Error("External store adapter does not support archiving");await e(t)}async unarchive(t){const e=this.adapter.onUnarchive;if(!e)throw new Error("External store adapter does not support unarchiving");await e(t)}async delete(t){const e=this.adapter.onDelete;if(!e)throw new Error("External store adapter does not support deleting");await e(t)}initialize(t){return Promise.resolve({remoteId:t,externalId:void 0})}generateTitle(){throw new Error("Method not implemented.")}subscribe(t){return this._subscriptions.add(t),()=>this._subscriptions.delete(t)}_notifySubscribers(){for(const t of this._subscriptions)t()}};const Lt=(t,e)=>{if(t.startsWith("data-"))return{type:"data",name:t.substring(5),data:e}},wt=(t,e,s)=>{const{role:r,id:n,createdAt:i,attachments:o,status:a,metadata:c}=t,l={id:n??e,createdAt:i??new Date},u=typeof t.content=="string"?[{type:"text",text:t.content}]:t.content,h=({image:d,...f})=>typeof d!="string"?null:d.match(/^data:image\/(png|jpeg|jpg|gif|webp|svg\+xml);base64,(.*)$/)?{...f,image:d}:/^(https:\/\/|blob:)/.test(d)?{...f,image:d}:(console.warn("Invalid image data format detected"),null);if(r!=="user"&&(o!=null&&o.length))throw new Error("attachments are only supported for user messages");if(r!=="assistant"&&a)throw new Error("status is only supported for assistant messages");if(r!=="assistant"&&(c!=null&&c.steps))throw new Error("metadata.steps is only supported for assistant messages");switch(r){case"assistant":return{...l,role:r,content:u.map(d=>{var g;const f=d.type;switch(f){case"text":case"reasoning":return(g=d.text)!=null&&g.trim()?d:null;case"file":case"source":return d;case"image":return h(d);case"data":return d;case"generative-ui":return d;case"tool-call":{const{parentId:b,messages:v,...x}=d,S={...x,toolCallId:d.toolCallId??`tool-${Ae()}`,...b!==void 0&&{parentId:b},...v!==void 0&&{messages:v}};return d.args?{...S,args:d.args,argsText:d.argsText??JSON.stringify(d.args)}:{...S,args:es(d.argsText??"")??{},argsText:d.argsText??""}}default:{const b=Lt(f,d.data);if(b)return b;throw new Error(`Unsupported assistant message part type: ${f}`)}}}).filter(d=>!!d),status:a??s,metadata:{unstable_state:(c==null?void 0:c.unstable_state)??null,unstable_annotations:(c==null?void 0:c.unstable_annotations)??[],unstable_data:(c==null?void 0:c.unstable_data)??[],custom:(c==null?void 0:c.custom)??{},steps:(c==null?void 0:c.steps)??[],...(c==null?void 0:c.timing)&&{timing:c.timing},...(c==null?void 0:c.submittedFeedback)&&{submittedFeedback:c.submittedFeedback},...(c==null?void 0:c.isOptimistic)&&{isOptimistic:!0}}};case"user":return{...l,role:r,content:u.map(d=>{const f=d.type;switch(f){case"text":case"image":case"audio":case"file":case"data":return d;default:{const g=Lt(f,d.data);if(g)return g;throw new Error(`Unsupported user message part type: ${f}`)}}}),attachments:(o??[]).map(d=>({...d,content:d.content.map(f=>Lt(f.type,f.data)??f)})),metadata:{custom:(c==null?void 0:c.custom)??{}}};case"system":if(u.length!==1||u[0].type!=="text")throw new Error("System messages must have exactly one text message part.");return{...l,role:r,content:u,metadata:{custom:(c==null?void 0:c.custom)??{}}};default:throw new Error(`Unknown message role: ${r}`)}},ze=Symbol("autoStatus"),Zu=Object.freeze(Object.assign({type:"running"},{[ze]:!0})),ed=Object.freeze(Object.assign({type:"complete",reason:"unknown"},{[ze]:!0}));Object.freeze(Object.assign({type:"requires-action",reason:"tool-calls"},{[ze]:!0}));Object.freeze(Object.assign({type:"requires-action",reason:"interrupt"},{[ze]:!0}));const td=t=>t[ze]===!0,ss=(t,e,s,r,n)=>t&&n?Object.assign({type:"incomplete",reason:"error",error:n},{[ze]:!0}):t&&e?Zu:ed,ri={fromArray:t=>{const e=t.map(s=>wt(s,Ae(),ss(!1,!1,!1,!1,void 0)));return{messages:e.map((s,r)=>({parentId:r>0?e[r-1].id:null,message:s}))}},fromBranchableArray:(t,e)=>{const s=ss(!1,!1,!1,!1,void 0);return{...(e==null?void 0:e.headId)!==void 0?{headId:e.headId}:void 0,messages:t.map(({message:r,parentId:n})=>{if(!r.id)throw new Error("ExportedMessageRepository.fromBranchableArray: Each message must have an 'id' field set.");return{parentId:n,message:wt(r,r.id,s)}})}}},ft=t=>t.next?ft(t.next):"current"in t?t:null;var sd=class{constructor(t){m(this,"func");m(this,"_value",null);this.func=t}get value(){return this._value===null&&(this._value=this.func()),this._value}dirty(){this._value=null}},ni=class{constructor(){m(this,"messages",new Map);m(this,"head",null);m(this,"root",{children:[],next:null});m(this,"_messages",new sd(()=>{var e;const t=new Array((((e=this.head)==null?void 0:e.level)??-1)+1);for(let s=this.head;s;s=s.prev)t[s.level]=s.current;return t}))}updateLevels(t,e){t.level=e;for(const s of t.children){const r=this.messages.get(s);r&&this.updateLevels(r,e+1)}}performOp(t,e,s){const r=e.prev??this.root,n=t??this.root;if(!(s==="relink"&&r===n)){if(s!=="link"&&(r.children=r.children.filter(i=>i!==e.current.id),r.next===e)){const i=r.children.at(-1),o=i?this.messages.get(i):null;if(o===void 0)throw new Error("MessageRepository(performOp/cut): Fallback sibling message not found. This is likely an internal bug in assistant-ui.");r.next=o}if(s!=="cut"){for(let o=t;o;o=o.prev)if(o.current.id===e.current.id)throw new Error("MessageRepository(performOp/link): 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.");n.children=[...n.children,e.current.id],(ft(e)===this.head||n.next===null)&&(n.next=e),e.prev=t;const i=t?t.level+1:0;this.updateLevels(e,i)}}}get headId(){var t;return((t=this.head)==null?void 0:t.current.id)??null}get canonicalHeadId(){var e;let t=this.head;for(;(e=t==null?void 0:t.current.metadata)!=null&&e.isOptimistic;)t=t.prev;return(t==null?void 0:t.current.id)??null}getMessages(t){var r;if(t===void 0||t===((r=this.head)==null?void 0:r.current.id))return this._messages.value;const e=this.messages.get(t);if(!e)throw new Error("MessageRepository(getMessages): Head message not found. This is likely an internal bug in assistant-ui.");const s=new Array(e.level+1);for(let n=e;n;n=n.prev)s[n.level]=n.current;return s}addOrUpdateMessage(t,e){const s=this.messages.get(e.id),r=t?this.messages.get(t):null;if(r===void 0)throw new Error("MessageRepository(addOrUpdateMessage): Parent message not found. This is likely an internal bug in assistant-ui.");if(s){s.current=e,this.performOp(r,s,"relink"),this._messages.dirty();return}const n={prev:r,current:e,next:null,children:[],level:r?r.level+1:0};this.messages.set(e.id,n),this.performOp(r,n,"link"),this.head===r&&(this.head=n),this._messages.dirty()}getMessage(t){var s;const e=this.messages.get(t);if(!e)throw new Error("MessageRepository(updateMessage): Message not found. This is likely an internal bug in assistant-ui.");return{parentId:((s=e.prev)==null?void 0:s.current.id)??null,message:e.current,index:e.level}}deleteMessage(t,e){const s=this.messages.get(t);if(!s)throw new Error("MessageRepository(deleteMessage): Message not found. This is likely an internal bug in assistant-ui.");const r=e===void 0?s.prev:e===null?null:this.messages.get(e);if(r===void 0)throw new Error("MessageRepository(deleteMessage): Replacement not found. This is likely an internal bug in assistant-ui.");for(const n of s.children){const i=this.messages.get(n);if(!i)throw new Error("MessageRepository(deleteMessage): Child message not found. This is likely an internal bug in assistant-ui.");this.performOp(r,i,"relink")}this.performOp(null,s,"cut"),this.messages.delete(t),this.head===s&&(this.head=ft(r??this.root)),this._messages.dirty()}getBranches(t){const e=this.messages.get(t);if(!e)throw new Error("MessageRepository(getBranches): Message not found. This is likely an internal bug in assistant-ui.");const{children:s}=e.prev??this.root;return s}evictOffBranchOptimisticMessages(t,e){var n;if(!t)return;const s=new Set;for(let i=e;i;i=i.prev)s.add(i.current.id);const r=[];for(let i=t;i&&!s.has(i.current.id);i=i.prev)(n=i.current.metadata)!=null&&n.isOptimistic&&r.push(i.current.id);for(const i of r)this.messages.has(i)&&this.deleteMessage(i)}switchToBranch(t){const e=this.messages.get(t);if(!e)throw new Error("MessageRepository(switchToBranch): Branch not found. This is likely an internal bug in assistant-ui.");const s=this.head,r=e.prev??this.root;r.next=e,this.head=ft(e),this.evictOffBranchOptimisticMessages(s,this.head),this._messages.dirty()}resetHead(t){if(t===null){this.clear();return}const e=this.messages.get(t);if(!e)throw new Error("MessageRepository(resetHead): Branch not found. This is likely an internal bug in assistant-ui.");const s=this.head;if(e.children.length>0){const r=n=>{for(const i of n.children){const o=this.messages.get(i);o&&(r(o),this.messages.delete(i))}};r(e),e.children=[],e.next=null}this.head=e;for(let r=e;r;r=r.prev)r.prev?r.prev.next=r:this.root.next=r;this.evictOffBranchOptimisticMessages(s,this.head),this._messages.dirty()}clear(){this.messages.clear(),this.head=null,this.root={children:[],next:null},this._messages.dirty()}export(){var e,s;const t=[];for(const[,r]of this.messages)(e=r.current.metadata)!=null&&e.isOptimistic||t.push({message:r.current,parentId:((s=r.prev)==null?void 0:s.current.id)??null});return{headId:this.canonicalHeadId,messages:t}}import({headId:t,messages:e}){var s;for(const{message:r,parentId:n}of e)this.addOrUpdateMessage(n,r);this.resetHead(t??((s=e.at(-1))==null?void 0:s.message.id)??null)}};const Rs=Object.freeze([]);function br(t,e){if(e==="*")return!0;const s=e.split(",").map(i=>i.trim().toLowerCase()),r=`.${t.name.split(".").pop().toLowerCase()}`,n=t.type.toLowerCase();for(const i of s){if(i.startsWith(".")&&i===r||i.includes("/")&&i===n)return!0;if(i.endsWith("/*")){const o=i.split("/")[0];if(n.startsWith(`${o}/`))return!0}}return!1}function rd(t,e){return t.length!==e.length?!1:t.every((s,r)=>s.id===e[r].id)}function nd(t){const e=Ae();return t.type==="image"?{id:e,type:"image",name:t.filename??"image",content:[t],status:{type:"complete"}}:t.type==="file"?{id:e,type:"document",name:t.filename??"document",contentType:t.mimeType,content:[t],status:{type:"complete"}}:t.type==="audio"?{id:e,type:"audio",name:`audio.${t.audio.format}`,contentType:`audio/${t.audio.format}`,content:[t],status:{type:"complete"}}:{id:e,type:"data",name:t.name,content:[t],status:{type:"complete"}}}function id(t){const e=[];for(const s of t)s.type!=="text"&&e.push(nd(s));return e}const Vt=t=>t.status.type==="complete";var ii=class extends Eu{constructor(){super(...arguments);m(this,"isEditing",!0);m(this,"_attachments",[]);m(this,"_text","");m(this,"_role","user");m(this,"_runConfig",{});m(this,"_quote");m(this,"_dictation");m(this,"_dictationSession");m(this,"_dictationUnsubscribes",[]);m(this,"_dictationBaseText","");m(this,"_currentInterimText","");m(this,"_dictationSessionIdCounter",0);m(this,"_activeDictationSessionId");m(this,"_isCleaningDictation",!1);m(this,"_eventSubscribers",new Map)}enrichWithComposerMetadata(e,s){var r;return s?{...e,metadata:{...e.metadata,custom:{...(r=e.metadata)==null?void 0:r.custom,...s}}}:e}get attachmentAccept(){var e;return((e=this.getAttachmentAdapter())==null?void 0:e.accept)??"*"}get attachments(){return this._attachments}setAttachments(e){this._attachments=e,this._notifySubscribers()}get isEmpty(){return!this.text.trim()&&!this.attachments.length}get text(){return this._text}get role(){return this._role}get runConfig(){return this._runConfig}get quote(){return this._quote}setQuote(e){this._quote!==e&&(this._quote=e,this._notifySubscribers())}setText(e){if(this._text!==e){if(this._text=e,this._dictation){this._dictationBaseText=e,this._currentInterimText="";const{status:s,inputDisabled:r}=this._dictation;this._dictation=r?{status:s,inputDisabled:r}:{status:s}}this._notifySubscribers()}}setRole(e){this._role!==e&&(this._role=e,this._notifySubscribers())}setRunConfig(e){this._runConfig!==e&&(this._runConfig=e,this._notifySubscribers())}_emptyTextAndAttachments(){this._attachments=[],this._text="",this._notifySubscribers()}async _onClearAttachments(){const e=this.getAttachmentAdapter();if(e){const s=this._attachments.filter(r=>!Vt(r));await Promise.all(s.map(r=>e.remove(r)))}}async reset(){if(this._attachments.length===0&&this._text===""&&this._role==="user"&&Object.keys(this._runConfig).length===0&&this._quote===void 0)return;this._role="user",this._runConfig={},this._quote=void 0;const e=this._onClearAttachments();this._emptyTextAndAttachments(),await e}async clearAttachments(){const e=this._onClearAttachments();this.setAttachments([]),await e}async send(e){if(!this.canSend)return;this._dictationSession&&(this._dictationSession.cancel(),this._cleanupDictation());const s=this.getAttachmentAdapter(),r=this.attachments.length>0?Promise.all(this.attachments.map(async a=>{if(Vt(a))return a;if(!s)throw new Error("Attachments are not supported");return await s.send(a)})):[],n=this.text,i=this._quote;this._quote=void 0,this._emptyTextAndAttachments();const o={createdAt:new Date,role:this.role,content:n?[{type:"text",text:n}]:[],attachments:await r,runConfig:this.runConfig,metadata:{custom:{...i?{quote:i}:{}}}};this.handleSend(o,e),this._notifyEventSubscribers("send",{})}cancel(){this.handleCancel()}get queue(){return Rs}steerQueueItem(e){}removeQueueItem(e){}async addAttachment(e){if(!(e instanceof File)){const i=this.getAttachmentAdapter();if(i&&!br({name:e.name,type:e.contentType??""},i.accept)){const a=`File type ${e.contentType||"unknown"} is not accepted. Accepted types: ${i.accept}`,c=new Error(a);throw this._safeEmitAttachmentAddError("not-accepted",a,void 0,c),c}const o={id:e.id??Ae(),type:e.type??"document",name:e.name,contentType:e.contentType,content:e.content,status:{type:"complete"}};this._attachments=[...this._attachments,o],this._notifySubscribers(),this._notifyEventSubscribers("attachmentAdd",{});return}const s=i=>{const o=this._attachments.findIndex(a=>a.id===i.id);o!==-1?this._attachments=[...this._attachments.slice(0,o),i,...this._attachments.slice(o+1)]:this._attachments=[...this._attachments,i],this._notifySubscribers()},r=this.getAttachmentAdapter();if(!r){const i="Attachments are not supported",o=new Error(i);throw this._safeEmitAttachmentAddError("no-adapter",i,void 0,o),o}if(!br({name:e.name,type:e.type},r.accept)){const i=`File type ${e.type||"unknown"} is not accepted. Accepted types: ${r.accept}`,o=new Error(i);throw this._safeEmitAttachmentAddError("not-accepted",i,void 0,o),o}let n;try{const i=r.add({file:e});if(Symbol.asyncIterator in i)for await(const o of i)n=o,s(o);else n=await i,s(n)}catch(i){throw n&&s({...n,status:{type:"incomplete",reason:"error"}}),this._safeEmitAttachmentAddError("adapter-error",i instanceof Error?i.message:String(i),n==null?void 0:n.id,i instanceof Error?i:void 0),i}(n==null?void 0:n.status.type)==="incomplete"&&n.status.reason==="error"?this._safeEmitAttachmentAddError("adapter-error","Attachment upload did not complete successfully.",n==null?void 0:n.id):this._notifyEventSubscribers("attachmentAdd",{})}_safeEmitAttachmentAddError(e,s,r,n){try{this._notifyEventSubscribers("attachmentAddError",{reason:e,message:s,...r!==void 0&&{attachmentId:r},...n!==void 0&&{error:n}})}catch(i){console.error("[assistant-ui] attachmentAddError subscriber threw:",i)}}async removeAttachment(e){const s=this._attachments.findIndex(n=>n.id===e);if(s===-1)throw new Error("Attachment not found");const r=this._attachments[s];if(!Vt(r)){const n=this.getAttachmentAdapter();if(!n)throw new Error("Attachments are not supported");await n.remove(r)}this._attachments=this._attachments.filter(n=>n.id!==e),this._notifySubscribers()}get dictation(){return this._dictation}_isActiveSession(e,s){return this._activeDictationSessionId===e&&this._dictationSession===s}startDictation(){const e=this.getDictationAdapter();if(!e)throw new Error("Dictation adapter not configured");if(this._dictationSession){for(const l of this._dictationUnsubscribes)l();this._dictationUnsubscribes=[],this._dictationSession.stop().catch(()=>{}),this._dictationSession=void 0}const s=e.disableInputDuringDictation??!1;this._dictationBaseText=this._text,this._currentInterimText="";const r=e.listen();this._dictationSession=r;const n=++this._dictationSessionIdCounter;this._activeDictationSessionId=n,this._dictation={status:r.status,inputDisabled:s},this._notifySubscribers();const i=r.onSpeech(l=>{if(!this._isActiveSession(n,r))return;const u=l.isFinal!==!1,h=this._dictationBaseText&&!this._dictationBaseText.endsWith(" ")&&l.transcript?" ":"";if(u){if(this._dictationBaseText=this._dictationBaseText+h+l.transcript,this._currentInterimText="",this._text=this._dictationBaseText,this._dictation){const{transcript:d,...f}=this._dictation;this._dictation=f}this._notifySubscribers()}else this._currentInterimText=h+l.transcript,this._text=this._dictationBaseText+this._currentInterimText,this._dictation&&(this._dictation={...this._dictation,transcript:l.transcript}),this._notifySubscribers()});this._dictationUnsubscribes.push(i);const o=r.onSpeechStart(()=>{var l;this._isActiveSession(n,r)&&(this._dictation={status:{type:"running"},inputDisabled:s,...((l=this._dictation)==null?void 0:l.transcript)&&{transcript:this._dictation.transcript}},this._notifySubscribers())});this._dictationUnsubscribes.push(o);const a=r.onSpeechEnd(()=>{this._cleanupDictation({sessionId:n})});this._dictationUnsubscribes.push(a);const c=setInterval(()=>{this._isActiveSession(n,r)&&r.status.type==="ended"&&this._cleanupDictation({sessionId:n})},100);this._dictationUnsubscribes.push(()=>clearInterval(c))}stopDictation(){if(!this._dictationSession)return;const e=this._dictationSession,s=this._activeDictationSessionId;e.stop().finally(()=>{this._cleanupDictation({sessionId:s})})}_cleanupDictation(e){if(!((e==null?void 0:e.sessionId)!==void 0&&e.sessionId!==this._activeDictationSessionId||this._isCleaningDictation)){this._isCleaningDictation=!0;try{for(const s of this._dictationUnsubscribes)s();this._dictationUnsubscribes=[],this._dictationSession=void 0,this._activeDictationSessionId=void 0,this._dictation=void 0,this._dictationBaseText="",this._currentInterimText="",this._notifySubscribers()}finally{this._isCleaningDictation=!1}}}_notifyEventSubscribers(e,s){const r=this._eventSubscribers.get(e);if(r)for(const n of r)n(s)}unstable_on(e,s){const r=s;let n=this._eventSubscribers.get(e);return n||(n=new Set,this._eventSubscribers.set(e,n)),n.add(r),()=>{var i;(i=this._eventSubscribers.get(e))==null||i.delete(r)}}},od=class extends ii{constructor(e){super();m(this,"runtime");m(this,"_canCancel",!1);this.runtime=e,this.connect()}get canCancel(){return this._canCancel}get canSend(){return!this.isEmpty&&!this.runtime.isSendDisabled}get queue(){var e,s;return((s=(e=this.runtime).getQueueItems)==null?void 0:s.call(e))??Rs}steerQueueItem(e){var s,r;(r=(s=this.runtime).steerQueueItem)==null||r.call(s,e)}removeQueueItem(e){var s,r;(r=(s=this.runtime).removeQueueItem)==null||r.call(s,e)}getAttachmentAdapter(){var e;return(e=this.runtime.adapters)==null?void 0:e.attachments}getDictationAdapter(){var e;return(e=this.runtime.adapters)==null?void 0:e.dictation}connect(){let e=this.runtime.isSendDisabled,s=this.queue;return this.runtime.subscribe(()=>{let r=!1;this.canCancel!==this.runtime.capabilities.cancel&&(this._canCancel=this.runtime.capabilities.cancel,r=!0),e!==this.runtime.isSendDisabled&&(e=this.runtime.isSendDisabled,r=!0),s!==this.queue&&(s=this.queue,r=!0),r&&this._notifySubscribers()})}async handleSend(e,s){var i;const r=Ln(this.runtime.getModelContext().unstable_composerMetadata,this.runtime.messages),n=this.enrichWithComposerMetadata(e,r);this.runtime.append({...n,parentId:((i=this.runtime.messages.at(-1))==null?void 0:i.id)??null,sourceId:null,startRun:s==null?void 0:s.startRun,steer:s==null?void 0:s.steer})}async handleCancel(){this.runtime.cancelRun()}},ad=class extends ii{constructor(e,s,{parentId:r,message:n}){super();m(this,"runtime");m(this,"endEditCallback");m(this,"_previousText");m(this,"_previousAttachments");m(this,"_nonTextPassthrough");m(this,"_parentId");m(this,"_sourceId");this.runtime=e,this.endEditCallback=s,this._parentId=r,this._sourceId=n.id,this._previousText=et(n),this.setText(this._previousText),this.setRole(n.role),n.role==="user"?(this._previousAttachments=[...n.attachments??[],...id(n.content)],this._nonTextPassthrough=[]):(this._previousAttachments=n.attachments??[],this._nonTextPassthrough=n.content.filter(i=>i.type!=="text")),this.setAttachments(this._previousAttachments),this.setRunConfig({...e.composer.runConfig})}get canCancel(){return!0}get canSend(){return!this.isEmpty}getAttachmentAdapter(){var e;return(e=this.runtime.adapters)==null?void 0:e.attachments}getDictationAdapter(){var e;return(e=this.runtime.adapters)==null?void 0:e.dictation}get parentId(){return this._parentId}get sourceId(){return this._sourceId}async handleSend(e,s){const r=et(e),n=!rd(e.attachments??[],this._previousAttachments);if(r!==this._previousText||n||s!=null&&s.startRun){const i=this._nonTextPassthrough.length>0?[...e.content,...this._nonTextPassthrough]:e.content,o=this.runtime.messages,a=this._parentId===null?-1:o.findIndex(u=>u.id===this._parentId),c=Ln(this.runtime.getModelContext().unstable_composerMetadata,o.slice(0,a+1)),l=this.enrichWithComposerMetadata(e,c);this.runtime.append({...l,content:i,parentId:this._parentId,sourceId:this._sourceId,startRun:s==null?void 0:s.startRun})}this.handleCancel()}handleCancel(){this.endEditCallback(),this._notifySubscribers()}},cd=class{constructor(t){m(this,"_contextProvider");m(this,"_subscriptions",new Set);m(this,"_isInitialized",!1);m(this,"repository",new ni);m(this,"_voiceMessages",[]);m(this,"_voiceGeneration",0);m(this,"_cachedMergedMessages",null);m(this,"_cachedVoiceGeneration",-1);m(this,"_cachedMergedBase",null);m(this,"composer",new od(this));m(this,"_editComposers",new Map);m(this,"_stopSpeaking");m(this,"speech");m(this,"_voiceSession");m(this,"_voiceUnsubs",[]);m(this,"voice");m(this,"_voiceVolume",0);m(this,"_voiceVolumeSubscribers",new Set);m(this,"getVoiceVolume",()=>this._voiceVolume);m(this,"subscribeVoiceVolume",t=>(this._voiceVolumeSubscribers.add(t),()=>this._voiceVolumeSubscribers.delete(t)));m(this,"_currentAssistantMsg",null);m(this,"_eventSubscribers",new Map);this._contextProvider=t}_markVoiceMessagesDirty(){this._voiceGeneration++,this._cachedMergedMessages=null}_getBaseMessages(){return this.repository.getMessages()}get messages(){if(this._voiceMessages.length===0)return this._getBaseMessages();const t=this._getBaseMessages();return(this._cachedVoiceGeneration!==this._voiceGeneration||this._cachedMergedBase!==t)&&(this._cachedMergedMessages=[...t,...this._voiceMessages],this._cachedVoiceGeneration=this._voiceGeneration,this._cachedMergedBase=t),this._cachedMergedMessages}get state(){let t;for(const e of this.messages)e.role==="assistant"&&(t=e);return(t==null?void 0:t.metadata.unstable_state)??null}getModelContext(){return this._contextProvider.getModelContext()}getEditComposer(t){return this._editComposers.get(t)}beginEdit(t){if(this._editComposers.has(t))throw new Error("Edit already in progress");this._editComposers.set(t,new ad(this,()=>this._editComposers.delete(t),this.repository.getMessage(t))),this._notifySubscribers()}getMessageById(t){var e;try{return this.repository.getMessage(t)}catch{const s=this.repository.getMessages(),r=this._voiceMessages.findIndex(n=>n.id===t);return r!==-1?{parentId:r>0?this._voiceMessages[r-1].id:((e=s.at(-1))==null?void 0:e.id)??null,message:this._voiceMessages[r],index:s.length+r}:void 0}}getBranches(t){return this._voiceMessages.some(e=>e.id===t)?[]:this.repository.getBranches(t)}switchToBranch(t){this.repository.switchToBranch(t),this._notifySubscribers()}_notifySubscribers(){for(const t of this._subscriptions)t()}_notifyEventSubscribers(t,e){const s=this._eventSubscribers.get(t);if(s)for(const r of s)r(e)}subscribe(t){return this._subscriptions.add(t),()=>this._subscriptions.delete(t)}submitFeedback({messageId:t,type:e}){var i;const s=(i=this.adapters)==null?void 0:i.feedback;if(!s)throw new Error("Feedback adapter not configured");const{message:r,parentId:n}=this.repository.getMessage(t);if(s.submit({message:r,type:e}),r.role==="assistant"){const o={...r,metadata:{...r.metadata,submittedFeedback:{type:e}}};this.repository.addOrUpdateMessage(n,o)}this._notifySubscribers()}speak(t){var i,o;const e=(i=this.adapters)==null?void 0:i.speech;if(!e)throw new Error("Speech adapter not configured");const{message:s}=this.repository.getMessage(t);(o=this._stopSpeaking)==null||o.call(this);const r=e.speak(et(s)),n=r.subscribe(()=>{r.status.type==="ended"?(this._stopSpeaking=void 0,this.speech=void 0):this.speech={messageId:t,status:r.status},this._notifySubscribers()});this.speech={messageId:t,status:r.status},this._notifySubscribers(),this._stopSpeaking=()=>{r.cancel(),n(),this.speech=void 0,this._stopSpeaking=void 0}}stopSpeaking(){if(!this._stopSpeaking)throw new Error("No message is being spoken");this._stopSpeaking(),this._notifySubscribers()}connectVoice(){var n;const t=(n=this.adapters)==null?void 0:n.voice;if(!t)throw new Error("Voice adapter not configured");this.disconnectVoice();const e=t.connect({});this._voiceSession=e;const s=[];let r="listening";this.voice={status:e.status,isMuted:e.isMuted,mode:r},this._voiceVolume=0,this._notifySubscribers(),s.push(e.onStatusChange(i=>{i.type==="ended"?(this._finishVoiceAssistantMessage(),this._voiceSession=void 0,this.voice=void 0):this.voice={status:i,isMuted:e.isMuted,mode:r},this._notifySubscribers()})),s.push(e.onModeChange(i=>{r=i,this.voice&&(this.voice={...this.voice,mode:i},this._notifySubscribers())})),s.push(e.onVolumeChange(i=>{this._voiceVolume=i;for(const o of this._voiceVolumeSubscribers)o()})),s.push(e.onTranscript(i=>{this._handleVoiceTranscript(i)})),this._voiceUnsubs=s}_handleVoiceTranscript(t){if(this.ensureInitialized(),t.role==="user")this._finishVoiceAssistantMessage(),this._currentAssistantMsg=null,t.isFinal&&(this._voiceMessages.push({id:Ae(),role:"user",content:[{type:"text",text:t.text}],metadata:{custom:{}},createdAt:new Date,status:{type:"complete",reason:"unknown"},attachments:[]}),this._markVoiceMessagesDirty(),this._notifySubscribers());else{if(!this._currentAssistantMsg)this._currentAssistantMsg={id:Ae(),role:"assistant",content:[{type:"text",text:t.text}],metadata:{unstable_state:this.state,unstable_annotations:[],unstable_data:[],steps:[],custom:{}},status:{type:"running"},createdAt:new Date},this._voiceMessages.push(this._currentAssistantMsg);else{const e=this._voiceMessages.indexOf(this._currentAssistantMsg);if(e===-1)return;const s={...this._currentAssistantMsg,content:[{type:"text",text:t.text}],...t.isFinal?{status:{type:"complete",reason:"stop"}}:{}};this._voiceMessages[e]=s,this._currentAssistantMsg=s}t.isFinal&&(this._currentAssistantMsg=null),this._markVoiceMessagesDirty(),this._notifySubscribers()}}_finishVoiceAssistantMessage(){const t=this._voiceMessages.at(-1);if((t==null?void 0:t.role)==="assistant"&&t.status.type==="running"){const e=this._voiceMessages.length-1;this._voiceMessages[e]={...t,status:{type:"complete",reason:"stop"}},this._markVoiceMessagesDirty(),this._notifySubscribers()}}disconnectVoice(){var t;this._finishVoiceAssistantMessage(),this._currentAssistantMsg=null;for(const e of this._voiceUnsubs)e();this._voiceUnsubs=[],(t=this._voiceSession)==null||t.disconnect(),this._voiceSession=void 0,this.voice=void 0,this._voiceVolume=0;for(const e of this._voiceVolumeSubscribers)e();this._voiceMessages=[],this._markVoiceMessagesDirty(),this._notifySubscribers()}muteVoice(){if(!this._voiceSession)throw new Error("No active voice session");this._voiceSession.mute(),this.voice={...this.voice,isMuted:!0},this._notifySubscribers()}unmuteVoice(){if(!this._voiceSession)throw new Error("No active voice session");this._voiceSession.unmute(),this.voice={...this.voice,isMuted:!1},this._notifySubscribers()}ensureInitialized(){this._isInitialized||(this._isInitialized=!0,this._notifyEventSubscribers("initialize",{}))}export(){return this.repository.export()}import(t){this.ensureInitialized(),this.repository.clear(),this.repository.import(t),this._notifySubscribers()}reset(t){this.import(ri.fromArray(t??[]))}unstable_on(t,e){var n,i;const s=e;if(t==="modelContextUpdate")return((i=(n=this._contextProvider).subscribe)==null?void 0:i.call(n,()=>s({})))??(()=>{});let r=this._eventSubscribers.get(t);return r||(r=new Set,this._eventSubscribers.set(t,r)),r.add(s),t==="initialize"&&this._isInitialized&&queueMicrotask(()=>{r.has(s)&&s({})}),()=>{var o;(o=this._eventSubscribers.get(t))==null||o.delete(s)}}},_r=class{constructor(){m(this,"cache",new WeakMap)}convertMessages(t,e){return t.map((s,r)=>{const n=e(this.cache.get(s),s,r);return this.cache.set(s,n),n})}};const lt=t=>{try{return JSON.parse(t),!0}catch{return!1}},yr=t=>{try{return JSON.parse(t)}catch{return}},vr=(t,e)=>{const s=yr(t),r=yr(e);return s===void 0||r===void 0?!1:xs(s,r)};var ld=class{constructor(t,e){m(this,"_getTools");m(this,"_callbacks");m(this,"_entries",new Map);m(this,"_skipExecuteStreamIds",new Set);m(this,"_humanInput",new Map);m(this,"_executing",new Set);m(this,"_settledResolvers",[]);m(this,"_statuses",new Map);m(this,"_ac",new AbortController);m(this,"_pendingRestore",!0);m(this,"_lastSnapshot",null);m(this,"_isRunning",!1);m(this,"_controller");m(this,"_pipelineDead",!1);m(this,"_pipelineRestartUsed",!1);this._getTools=t,this._callbacks=e,this._initPipeline()}_initPipeline(){const[t,e]=zl();this._controller=e;const s=uu(()=>this._getWrappedTools(),()=>this._ac.signal,(r,n)=>this._onHumanInput(r,n),{onExecutionStart:r=>this._onExecutionStart(r),onExecutionEnd:r=>this._onExecutionEnd(r)});t.pipeThrough(s).pipeThrough(new qn).pipeTo(new WritableStream({write:r=>{try{if(r.type!=="result")return;this._handleResultChunk(r)}catch(n){console.error("[ToolInvocationTracker] result chunk handling failed",n)}}})).catch(r=>{console.error("[ToolInvocationTracker] stream pipeline failed; will attempt single restart on next setState",r),this._pipelineDead=!0})}setState(t){try{if(this._pipelineDead){if(this._pipelineRestartUsed)return;this._pipelineRestartUsed=!0,this._pipelineDead=!1,this._demoteEntriesToRestored(),this._executing.clear(),this._ac=new AbortController,this._initPipeline()}if(this._lastSnapshot&&this._lastSnapshot.messages===t.messages&&this._lastSnapshot.isRunning===t.isRunning&&this._lastSnapshot.isLoading===t.isLoading)return;t.isLoading===!0&&(this._pendingRestore=!0);const e=this._isRunning;this._isRunning=t.isRunning;try{this._processMessages(t.messages)}catch(s){throw this._isRunning=e,s}this._lastSnapshot=t,this._pendingRestore=!1}catch(e){console.error("[ToolInvocationTracker] setState failed; snapshot dropped",e)}}reset(){try{this._pendingRestore=!0,this._entries.clear(),this._lastSnapshot=null,this.abort().finally(()=>{this._executing.clear()})}catch(t){console.error("[ToolInvocationTracker] reset failed",t)}}abort(){try{return this._humanInput.forEach(({reject:t})=>{try{t(new Error("Tool execution aborted"))}catch{}}),this._humanInput.clear(),this._ac.abort(),this._ac=new AbortController,this._executing.size===0?Promise.resolve():new Promise(t=>{this._settledResolvers.push(t)})}catch(t){return console.error("[ToolInvocationTracker] abort failed",t),Promise.resolve()}}resume(t,e){try{const s=this._humanInput.get(t);return s?(this._humanInput.delete(t),this._setStatus(t,{type:"executing"}),s.resolve(e),!0):!1}catch(s){return console.error("[ToolInvocationTracker] resume failed",s),!1}}getStatuses(){return this._statuses}_getWrappedTools(){const t=this._getTools();if(t)return Object.fromEntries(Object.entries(t).map(([e,s])=>{const r=s.execute;return r===void 0?[e,s]:[e,{...s,execute:(...[n,i])=>this._skipExecuteStreamIds.has(i.toolCallId)?new Promise(()=>{}):r(n,i)}]}))}_onHumanInput(t,e){return new Promise((s,r)=>{const n=this._humanInput.get(t);if(n)try{n.reject(new Error("Human input request was superseded by a new request"))}catch{}this._humanInput.set(t,{resolve:s,reject:r}),this._setStatus(t,{type:"interrupt",payload:{type:"human",payload:e}})})}_onExecutionStart(t){this._skipExecuteStreamIds.has(t)||(this._executing.add(t),this._setStatus(t,{type:"executing"}))}_onExecutionEnd(t){this._executing.delete(t)&&(this._deleteStatus(t),this._executing.size===0&&this._settledResolvers.splice(0).forEach(e=>{try{e()}catch{}}))}_handleResultChunk(t){const e=t.meta.toolCallId,s=this._entries.get(e);!s&&this._skipExecuteStreamIds.has(e)||s!=null&&s.hasResult||this._invokeOnResult({type:"add-tool-result",toolCallId:e,toolName:t.meta.toolName,result:t.result,isError:t.isError,...t.artifact!==void 0&&{artifact:t.artifact},...t.modelContent!==void 0&&{modelContent:t.modelContent}})}_invokeOnResult(t){try{this._callbacks.onResult(t)}catch(e){console.error("[ToolInvocationTracker] onResult callback threw; result dropped",e)}}_invokeOnStatusesChange(){try{this._callbacks.onStatusesChange(this._statuses)}catch(t){console.error("[ToolInvocationTracker] onStatusesChange callback threw; status change not propagated",t)}}_setStatus(t,e){const s=new Map(this._statuses);s.set(t,e),this._statuses=s,this._invokeOnStatusesChange()}_deleteStatus(t){if(!this._statuses.has(t))return;const e=new Map(this._statuses);e.delete(t),this._statuses=e,this._invokeOnStatusesChange()}_hasExecutableTool(t){var s;const e=(s=this._getTools())==null?void 0:s[t];return(e==null?void 0:e.execute)!==void 0||(e==null?void 0:e.streamCall)!==void 0}_shouldCloseArgsStream({toolName:t,argsText:e,hasResult:s}){return s?!0:(this._hasExecutableTool(t)||!this._isRunning)&<(e)}_startActiveEntry(t,e,s){const r=this._controller.addToolCallPart({toolName:e,toolCallId:t});s&&this._skipExecuteStreamIds.add(t);const n={toolName:e,controller:r,argsText:"",hasResult:!1,argsComplete:!1};return this._entries.set(t,n),n}_demoteEntriesToRestored(){for(const[t,e]of this._entries)e.controller&&this._entries.set(t,{toolName:e.toolName,argsText:e.argsText,hasResult:e.hasResult})}_processArgsText(t,e){if(!t.controller)return;const s=e.result!==void 0;if(e.argsText!==t.argsText){let r=!0;if(t.argsComplete)vr(t.argsText,e.argsText)&&(t.argsText=e.argsText),r=!1;else if(!e.argsText.startsWith(t.argsText))if(lt(t.argsText)&<(e.argsText)&&vr(t.argsText,e.argsText)){const n=this._shouldCloseArgsStream({toolName:e.toolName,argsText:e.argsText,hasResult:s});n&&t.controller.argsText.close(),t.argsText=e.argsText,t.argsComplete=n,r=!1}else r=!1;if(r&&t.controller){const n=e.argsText.slice(t.argsText.length);t.controller.argsText.append(n);const i=this._shouldCloseArgsStream({toolName:e.toolName,argsText:e.argsText,hasResult:s});i&&t.controller.argsText.close(),t.argsText=e.argsText,t.argsComplete=i}}!t.argsComplete&&t.controller&&this._shouldCloseArgsStream({toolName:e.toolName,argsText:e.argsText,hasResult:s})&&(t.controller.argsText.close(),t.argsText=e.argsText,t.argsComplete=!0)}_processMessages(t){const e=this._pendingRestore;for(const s of t)if(!(!s||!Array.isArray(s.content)))for(const r of s.content){if(!r||r.type!=="tool-call")continue;const n=this._entries.get(r.toolCallId);if(e){n!=null&&n.controller||this._entries.set(r.toolCallId,{toolName:r.toolName,argsText:r.argsText,hasResult:r.result!==void 0}),r.messages&&this._processMessages(r.messages);continue}let i=n;if(i&&!i.controller){if(!(r.argsText!==i.argsText||r.result!==void 0!==i.hasResult)){r.messages&&this._processMessages(r.messages);continue}this._entries.delete(r.toolCallId),i=void 0}if(i||(i=this._startActiveEntry(r.toolCallId,r.toolName,r.result!==void 0)),this._processArgsText(i,r),r.result!==void 0&&!i.hasResult){const{controller:o}=i;if(!o)continue;i.hasResult=!0,i.argsComplete=!0,o.setResponse(new ve({result:r.result,artifact:r.artifact,isError:r.isError,...r.modelContent!==void 0?{modelContent:r.modelContent}:{}})),o.close()}r.messages&&this._processMessages(r.messages)}}};const ud=Object.freeze([]),Sr=(t,e)=>{const s=Object.keys(t);if(s.length!==Object.keys(e).length)return!1;for(const r of s)if(t[r]!==e[r])return!1;return!0},dd=(t,e)=>{var s;return t&&((s=e[e.length-1])==null?void 0:s.role)!=="assistant"};var hd=class extends cd{constructor(e,s){super(e);m(this,"_capabilities",{switchToBranch:!1,switchBranchDuringRun:!1,edit:!1,delete:!1,reload:!1,cancel:!1,unstable_copy:!1,speech:!1,dictation:!1,voice:!1,attachments:!1,feedback:!1,queue:!1});m(this,"_messages");m(this,"isDisabled");m(this,"isSendDisabled");m(this,"suggestions",[]);m(this,"extras");m(this,"_converter",new _r);m(this,"_store");m(this,"_toolInvocations",null);m(this,"_toolCallToMessageId",new Map);m(this,"_messagesForToolCallIndex",null);m(this,"updateMessages",e=>{var s,r,n,i;this._store.convertMessage!==void 0?(r=(s=this._store).setMessages)==null||r.call(s,e.flatMap(Cu)):(i=(n=this._store).setMessages)==null||i.call(n,e)});this.__internal_setAdapter(s)}get capabilities(){return this._capabilities}get isLoading(){return this._store.isLoading??!1}get isRunning(){return this._store.isRunning}_getBaseMessages(){return this._messages}get state(){return this._store.state??super.state}get adapters(){return this._store.adapters}beginEdit(e){if(!this._store.onEdit)throw new Error("Runtime does not support editing.");super.beginEdit(e)}__internal_setAdapter(e){var c,l,u,h,d,f,g,b,v;if(this._store===e)return;const s=e.isRunning??!1;this.isDisabled=e.isDisabled??!1,this.isSendDisabled=e.isSendDisabled??!1;const r=this._store;this._store=e,this.extras!==e.extras&&(this.extras=e.extras);const n=e.suggestions??ud;Sr(this.suggestions,n)||(this.suggestions=n);const i={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,cancel:this._store.onCancel!==void 0,speech:((c=this._store.adapters)==null?void 0:c.speech)!==void 0,dictation:((l=this._store.adapters)==null?void 0:l.dictation)!==void 0,voice:((u=this._store.adapters)==null?void 0:u.voice)!==void 0,unstable_copy:((h=this._store.unstable_capabilities)==null?void 0:h.copy)!==!1,attachments:!!((d=this._store.adapters)!=null&&d.attachments),feedback:!!((f=this._store.adapters)!=null&&f.feedback),queue:this._store.queue!==void 0};Sr(this._capabilities,i)||(this._capabilities=i);let o;if(e.messageRepository){if(r&&r.isRunning===e.isRunning&&r.messageRepository===e.messageRepository){this._notifySubscribers();return}const x=e.messageRepository.messages,S=e.messageRepository.headId??((g=x.at(-1))==null?void 0:g.message.id)??null;if(r&&r.messageRepository===e.messageRepository)this.repository.resetHead(S),o=this.repository.getMessages();else{const T=new Set(x.map(({message:y})=>y.id));for(const{message:y,parentId:w}of x)this.repository.addOrUpdateMessage(w,y);for(const{message:y}of this.repository.export().messages)T.has(y.id)||this.repository.deleteMessage(y.id);this.repository.resetHead(S),o=this.repository.getMessages()}}else if(e.messages){if(r){if(r.convertMessage!==e.convertMessage)this._converter=new _r;else if(r.isRunning===e.isRunning&&r.messages===e.messages){this._notifySubscribers();return}}o=e.convertMessage?this._converter.convertMessages(e.messages,(x,S,T)=>{var C;if(!e.convertMessage)return S;const y=ss(T===(((C=e.messages)==null?void 0:C.length)??0)-1,s,!1,!1,void 0);if(x&&(x.role!=="assistant"||!td(x.status)||x.status===y))return x;const w=wt(e.convertMessage(S,T),T.toString(),y);return Tu(w,S),w}):e.messages;for(let x=0;x<o.length;x++){const S=o[x],T=o[x-1];this.repository.addOrUpdateMessage((T==null?void 0:T.id)??null,S)}}else throw new Error("ExternalStoreAdapter must provide either 'messages' or 'messageRepository'");o.length>0&&this.ensureInitialized(),((r==null?void 0:r.isRunning)??!1)!==(e.isRunning??!1)&&(e.isRunning?this._notifyEventSubscribers("runStart",{}):this._notifyEventSubscribers("runEnd",{}));let a=null;dd(s,o)&&(a=Ae(),this.repository.addOrUpdateMessage(((b=o.at(-1))==null?void 0:b.id)??null,wt({role:"assistant",content:[],metadata:{isOptimistic:!0}},a,{type:"running"}))),this.repository.resetHead(a??((v=o.at(-1))==null?void 0:v.id)??null),this._messages=this.repository.getMessages(),this._driveToolInvocations(),this._notifySubscribers()}_driveToolInvocations(){var e,s;if(!this._store.unstable_enableToolInvocations){this._toolInvocations&&(this._toolInvocations.reset(),this._toolInvocations=null,(s=(e=this._store).setToolStatuses)==null||s.call(e,{}));return}this._toolInvocations||(this._toolInvocations=new ld(()=>this.getModelContext().tools,{onResult:r=>{var n,i;try{const o=this._findMessageIdForToolCall(r.toolCallId);if(o===void 0)return;(i=(n=this._store).onAddToolResult)==null||i.call(n,{messageId:o,toolCallId:r.toolCallId,toolName:r.toolName,result:r.result,isError:r.isError,...r.artifact!==void 0&&{artifact:r.artifact},...r.modelContent!==void 0&&{modelContent:r.modelContent}})}catch(o){console.error("[ExternalStoreThreadRuntimeCore] onAddToolResult dispatch failed",o)}},onStatusesChange:r=>{var n,i;(i=(n=this._store).setToolStatuses)==null||i.call(n,Object.fromEntries(r))}})),this._toolInvocations.setState({messages:this._messages,isRunning:this._store.isRunning??!1,...this._store.isLoading!==void 0&&{isLoading:this._store.isLoading}})}_findMessageIdForToolCall(e){if(this._messagesForToolCallIndex!==this._messages){this._toolCallToMessageId.clear();const s=r=>{for(const n of r)if(Array.isArray(n.content))for(const i of n.content)!i||i.type!=="tool-call"||(this._toolCallToMessageId.set(i.toolCallId,n.id),i.messages&&s(i.messages))};s(this._messages),this._messagesForToolCallIndex=this._messages}return this._toolCallToMessageId.get(e)}switchToBranch(e){if(!this._store.setMessages)throw new Error("Runtime does not support switching branches.");if(this._store.isRunning)return;const s=this._store.unstable_onBranchChange,r=s?this.repository.canonicalHeadId:null;this.repository.switchToBranch(e),this.updateMessages(this.repository.getMessages()),s&&this._notifyBranchChange(r,s)}_notifyBranchChange(e,s){const r=this.repository.canonicalHeadId;r!==e&&s({headId:r,visibleMessageIds:this.repository.getMessages().map(n=>n.id)})}async append(e){var r,n,i;const s=e.parentId!==(((r=this.messages.at(-1))==null?void 0:r.id)??null);if(!s&&this._store.queue){this._store.queue.enqueue(e,{steer:e.steer??!1});return}if((e.startRun??e.role==="user")&&await((n=this._toolInvocations)==null?void 0:n.abort()),s){if(!this._store.onEdit)throw new Error("Runtime does not support editing messages.");(i=this._store.queue)==null||i.clear("edit"),await this._store.onEdit(e)}else await this._store.onNew(e)}async deleteMessage(e){var r;if(this._store.onDelete){await this._store.onDelete(e);return}if(!this._store.setMessages)throw new Error("Runtime does not support deleting messages.");this._store.isRunning&&await((r=this._toolInvocations)==null?void 0:r.abort());const s=this.repository.getMessages();if(s.findIndex(n=>n.id===e)===-1)throw new Error("Message not found.");this.updateMessages(s.filter(n=>n.id!==e))}getQueueItems(){var e,s;return((s=(e=this._store)==null?void 0:e.queue)==null?void 0:s.items)??Rs}steerQueueItem(e){var s,r;(r=(s=this._store)==null?void 0:s.queue)==null||r.steer(e)}removeQueueItem(e){var s,r;(r=(s=this._store)==null?void 0:s.queue)==null||r.remove(e)}async startRun(e){var s,r;if(!this._store.onReload)throw new Error("Runtime does not support reloading messages.");(s=this._store.queue)==null||s.clear("reload"),await((r=this._toolInvocations)==null?void 0:r.abort()),await this._store.onReload(e.parentId,e)}async resumeRun(e){if(!this._store.onResume)throw new Error("Runtime does not support resuming runs.");await this._store.onResume(e)}exportExternalState(){if(!this._store.onExportExternalState)throw new Error("Runtime does not support exporting external states.");return this._store.onExportExternalState()}importExternalState(e){var s,r;if(!this._store.onLoadExternalState)throw new Error("Runtime does not support importing external states.");this._toolInvocations&&(this._toolInvocations.reset(),(r=(s=this._store).setToolStatuses)==null||r.call(s,{})),this._store.onLoadExternalState(e)}cancelRun(){var n,i,o;if(!this._store.onCancel)throw new Error("Runtime does not support cancelling runs.");(n=this._store.queue)==null||n.clear("cancel-run"),(i=this._toolInvocations)==null||i.abort(),this._store.onCancel();const e=this.repository.getMessages().at(-1);e&&e.metadata.isOptimistic&&e.content.length===0&&this.repository.deleteMessage(e.id);let s=this.repository.getMessages();const r=s[s.length-1];(r==null?void 0:r.role)==="user"&&r.id===((o=s.at(-1))==null?void 0:o.id)?(this.repository.deleteMessage(r.id),this.composer.text.trim()||this.composer.setText(et(r)),s=this.repository.getMessages()):this._notifySubscribers(),setTimeout(()=>{this.updateMessages(s)},0)}addToolResult(e){var s,r;if(!this._store.onAddToolResult)throw new Error("Runtime does not support tool results.");(r=(s=this._store).onAddToolResult)==null||r.call(s,e)}resumeToolCall(e){var s;if(!(((s=this._toolInvocations)==null?void 0:s.resume(e.toolCallId,e.payload))??!1)){if(this._store.onResumeToolCall){this._store.onResumeToolCall(e);return}throw new Error(`Tool call ${e.toolCallId} is not waiting for resume.`)}}respondToToolApproval(e){if(!this._store.onRespondToToolApproval)throw new Error("Runtime does not support tool approvals.");this._store.onRespondToToolApproval(e)}reset(e){const s=new ni;s.import(ri.fromArray(e??[])),this.updateMessages(s.getMessages())}import(e){super.import(e),this._store.onImport&&this._store.onImport(this.repository.getMessages())}};const xr=t=>{var e;return((e=t.adapters)==null?void 0:e.threadList)??{}};var fd=class extends Wu{constructor(e){super();m(this,"threads");this.threads=new Xu(xr(e),()=>new hd(this._contextProvider,e))}setAdapter(e){this.threads.__internal_setAdapter(xr(e)),this.threads.getMainThreadRuntimeCore().__internal_setAdapter(e)}};const pd=t=>{const e=_(11);let s;e[0]!==t?(s=()=>new fd(t),e[0]=t,e[1]=s):s=e[1];const[r]=G(s);let n;e[2]!==r||e[3]!==t?(n=()=>{r.setAdapter(t)},e[2]=r,e[3]=t,e[4]=n):n=e[4],N(n);const{modelContext:i}=Hu()??{};let o,a;e[5]!==i||e[6]!==r?(o=()=>{if(i)return r.registerModelContextProvider(i)},a=[i,r],e[5]=i,e[6]=r,e[7]=o,e[8]=a):(o=e[7],a=e[8]),N(o,a);let c;return e[9]!==r?(c=new Ku(r),e[9]=r,e[10]=c):c=e[10],c},gd=t=>{const e=_(10),{id:s,children:r}=t;let n;e[0]!==s?(n=re({source:"thread",query:{type:"id",id:s},get:l=>l.thread().message({id:s})}),e[0]=s,e[1]=n):n=e[1];let i;e[2]!==s?(i=re({source:"message",query:{},get:l=>l.thread().message({id:s}).composer()}),e[2]=s,e[3]=i):i=e[3];let o;e[4]!==n||e[5]!==i?(o={message:n,composer:i},e[4]=n,e[5]=i,e[6]=o):o=e[6];const a=F(o);let c;return e[7]!==a||e[8]!==r?(c=p.jsx(ue,{value:a,children:r}),e[7]=a,e[8]=r,e[9]=c):c=e[9],c},As=(t,e)=>t.Message===e.Message&&t.EditComposer===e.EditComposer&&t.UserEditComposer===e.UserEditComposer&&t.AssistantEditComposer===e.AssistantEditComposer&&t.SystemEditComposer===e.SystemEditComposer&&t.UserMessage===e.UserMessage&&t.AssistantMessage===e.AssistantMessage&&t.SystemMessage===e.SystemMessage,md=()=>null,wr=new WeakMap,bd=(t,e)=>{let s=wr.get(t);return s||(s=new Set(t.map(r=>r.id)),wr.set(t,s)),s.has(e)},_d=(t,e,s)=>{switch(e){case"user":return s?t.UserEditComposer??t.EditComposer??t.UserMessage??t.Message:t.UserMessage??t.Message;case"assistant":return s?t.AssistantEditComposer??t.EditComposer??t.AssistantMessage??t.Message:t.AssistantMessage??t.Message;case"system":return s?t.SystemEditComposer??t.EditComposer??t.SystemMessage??t.Message:t.SystemMessage??t.Message??md;default:throw new Error(`Unknown message role: ${e}`)}},Ms=t=>{const e=_(6),{components:s}=t,r=P(vd),n=P(Sd);let i;e[0]!==s||e[1]!==n||e[2]!==r?(i=_d(s,r,n),e[0]=s,e[1]=n,e[2]=r,e[3]=i):i=e[3];const o=i;let a;return e[4]!==o?(a=p.jsx(o,{}),e[4]=o,e[5]=a):a=e[5],a},oi=M.memo(t=>{const e=_(5),{index:s,components:r}=t;let n;e[0]!==r?(n=p.jsx(Ms,{components:r}),e[0]=r,e[1]=n):n=e[1];let i;return e[2]!==s||e[3]!==n?(i=p.jsx(Yn,{index:s,children:n}),e[2]=s,e[3]=n,e[4]=i):i=e[4],i},(t,e)=>t.index===e.index&&As(t.components,e.components));oi.displayName="ThreadPrimitive.MessageByIndex";const ai=M.memo(t=>{const e=_(7),{messageId:s,components:r}=t;let n;if(e[0]!==s?(n=a=>bd(a.thread.messages,s),e[0]=s,e[1]=n):n=e[1],!P(n))return null;let i;e[2]!==r?(i=p.jsx(Ms,{components:r}),e[2]=r,e[3]=i):i=e[3];let o;return e[4]!==s||e[5]!==i?(o=p.jsx(gd,{id:s,children:i}),e[4]=s,e[5]=i,e[6]=o):o=e[6],o},(t,e)=>t.messageId===e.messageId&&As(t.components,e.components));ai.displayName="ThreadPrimitive.Unstable_MessageById";const Tr=({children:t})=>{const e=P(s=>s.thread.messages.length);return Y(()=>e===0?null:Array.from({length:e},(s,r)=>p.jsx(Yn,{index:r,children:p.jsx(qe,{getItemState:n=>n.thread().message({index:r}).getState(),children:n=>t({get message(){return n()}})})},r)),[e,t])},ci=t=>{const e=_(4),{components:s,children:r}=t;if(s){let i;return e[0]!==s?(i=p.jsx(Tr,{children:()=>p.jsx(Ms,{components:s})}),e[0]=s,e[1]=i):i=e[1],i}let n;return e[2]!==r?(n=p.jsx(Tr,{children:r}),e[2]=r,e[3]=n):n=e[3],n};ci.displayName="ThreadPrimitive.Messages";const yd=M.memo(ci,(t,e)=>t.children||e.children?t.children===e.children:As(t.components,e.components));function vd(t){return t.message.role}function Sd(t){return t.message.composer.isEditing}const li=t=>{var s;const e=t.message.metadata;if(!(!e||typeof e!="object"))return(s=e.custom)==null?void 0:s.quote};var xd=class extends Error{constructor(e,s=`Component "${e}" is not in the generative-ui allowlist.`){super(s);m(this,"componentName");this.name="GenerativeUIRenderError",this.componentName=e}};const wd=t=>typeof t=="object"&&t!==null,ui=(t,e,s,r)=>{if(t==null)return null;if(typeof t=="string")return t;if(!wd(t)||!("component"in t)||typeof t.component!="string")return null;const{component:n,props:i,children:o,key:a}=t,c=e[n];if(!c){if(s)return p.jsx(s,{component:n,props:i},a??r);throw new xd(n)}const l=o!=null&&o.length?o.map((u,h)=>ui(u,e,s,`${r}/${h}`)):void 0;return M.createElement(c,{...i??{},key:a??r},...l??[])},Td=t=>{if(!t||t.root===void 0||t.root===null)return[];const e=t.root;return Array.isArray(e)?e:[e]},Ps=t=>{const e=_(11),{spec:s,components:r,Fallback:n}=t;let i;e[0]!==s?(i=Td(s),e[0]=s,e[1]=i):i=e[1];const o=i;let a;if(e[2]!==n||e[3]!==r||e[4]!==o){let l;e[6]!==n||e[7]!==r?(l=(u,h)=>ui(u,r,n,`${h}`),e[6]=n,e[7]=r,e[8]=l):l=e[8],a=o.map(l),e[2]=n,e[3]=r,e[4]=o,e[5]=a}else a=e[5];let c;return e[9]!==a?(c=p.jsx(p.Fragment,{children:a}),e[9]=a,e[10]=c):c=e[10],c};Ps.displayName="GenerativeUIRender";const di=t=>{const e=_(4),{components:s,spec:r,Fallback:n}=t,i=P(Cd),o=r??i;if(!o)return null;let a;return e[0]!==n||e[1]!==s||e[2]!==o?(a=p.jsx(Ps,{spec:o,components:s,Fallback:n}),e[0]=n,e[1]=s,e[2]=o,e[3]=a):a=e[3],a};di.displayName="MessagePrimitive.GenerativeUI";function Cd(t){const e=t.part;return(e==null?void 0:e.type)==="generative-ui"?e.spec:void 0}const Id="ui://",Ed=t=>!!(t!=null&&t.startsWith(Id)),Cr=t=>Symbol.iterator in t,Ir=t=>"entries"in t,Er=(t,e)=>{const s=t instanceof Map?t:new Map(t.entries()),r=e instanceof Map?e:new Map(e.entries());if(s.size!==r.size)return!1;for(const[n,i]of s)if(!r.has(n)||!Object.is(i,r.get(n)))return!1;return!0},Rd=(t,e)=>{const s=t[Symbol.iterator](),r=e[Symbol.iterator]();let n=s.next(),i=r.next();for(;!n.done&&!i.done;){if(!Object.is(n.value,i.value))return!1;n=s.next(),i=r.next()}return!!n.done&&!!i.done};function Ad(t,e){return Object.is(t,e)?!0:typeof t!="object"||t===null||typeof e!="object"||e===null||Object.getPrototypeOf(t)!==Object.getPrototypeOf(e)?!1:Cr(t)&&Cr(e)?Ir(t)&&Ir(e)?Er(t,e):Rd(t,e):Er({entries:()=>Object.entries(t)},{entries:()=>Object.entries(e)})}function rs(t){const e=J.useRef(void 0);return s=>{const r=t(s);return Ad(e.current,r)?e.current:e.current=r}}const Ut=t=>{let e=-1;return{startGroup:s=>{e===-1&&(e=s)},endGroup:(s,r)=>{e!==-1&&(r.push({type:t,startIndex:e,endIndex:s}),e=-1)},finalize:(s,r)=>{e!==-1&&r.push({type:t,startIndex:e,endIndex:s})}}},Md=(t,e,s)=>{const r=[];if(e){const n=Ut("chainOfThoughtGroup");for(let i=0;i<t.length;i++){const o=t[i];o==="tool-call"||o==="reasoning"?n.startGroup(i):(n.endGroup(i-1,r),r.push({type:"single",index:i}))}n.finalize(t.length-1,r)}else{const n=Ut("toolGroup"),i=Ut("reasoningGroup");for(let o=0;o<t.length;o++){const a=t[o];a==="tool-call"?(i.endGroup(o-1,r),n.startGroup(o)):a==="reasoning"?(n.endGroup(o-1,r),i.startGroup(o)):(n.endGroup(o-1,r),i.endGroup(o-1,r),r.push({type:"single",index:o}))}n.finalize(t.length-1,r),i.finalize(t.length-1,r)}if(s){const n=new Set;for(const i of r){if(i.type==="single")continue;const o=s[i.startIndex];o!==void 0&&!n.has(o)&&(n.add(o),i.idKey=`id:${o}`)}}return r},Pd=t=>{const e=_(10),s=P(rs(Wd)),r=P(rs(Yd));let n;e:{if(s.length===0){let a;e[0]===Symbol.for("react.memo_cache_sentinel")?(a=[],e[0]=a):a=e[0];let c;e[1]!==r?(c={ranges:a,partIds:r},e[1]=r,e[2]=c):c=e[2],n=c;break e}let i;e[3]!==s||e[4]!==r||e[5]!==t?(i=Md(s,t,r),e[3]=s,e[4]=r,e[5]=t,e[6]=i):i=e[6];let o;e[7]!==r||e[8]!==i?(o={ranges:i,partIds:r},e[7]=r,e[8]=i,e[9]=o):o=e[9],n=o}return n},kd=t=>{const e=_(9);let s,r;e[0]!==t?({Fallback:s,...r}=t,e[0]=t,e[1]=s,e[2]=r):(s=e[1],r=e[2]);let n;e[3]!==s||e[4]!==r.toolName?(n=a=>{var c,l;return((l=(c=a.tools.toolUIs[r.toolName])==null?void 0:c[0])==null?void 0:l.render)??s},e[3]=s,e[4]=r.toolName,e[5]=n):n=e[5];const i=P(n);if(!i)return null;let o;return e[6]!==i||e[7]!==r?(o=p.jsx(i,{...r}),e[6]=i,e[7]=r,e[8]=o):o=e[8],o},ks=(t,e,s)=>{var n;const r=(n=t.renderers[e])==null?void 0:n[0];return r||(t.fallbacks[0]??s)},$d=t=>{const e=_(9);let s,r;e[0]!==t?({Fallback:s,...r}=t,e[0]=t,e[1]=s,e[2]=r):(s=e[1],r=e[2]);let n;e[3]!==s||e[4]!==r.name?(n=a=>ks(a.dataRenderers,r.name,s),e[3]=s,e[4]=r.name,e[5]=n):n=e[5];const i=P(n);if(!i)return null;let o;return e[6]!==i||e[7]!==r?(o=p.jsx(i,{...r}),e[6]=i,e[7]=r,e[8]=o):o=e[8],o},X={Text:()=>null,Reasoning:()=>null,Source:()=>null,Image:()=>null,File:()=>null,Unstable_Audio:()=>null,ToolGroup:({children:t})=>t,ReasoningGroup:({children:t})=>t},Dd=t=>{var $,D,R;const e=_(47),{components:s}=t;let r;e[0]!==s?(r=s===void 0?{}:s,e[0]=s,e[1]=r):r=e[1];const{Text:n,Reasoning:i,Image:o,Source:a,File:c,Unstable_Audio:l,tools:u,data:h,generativeUI:d}=r,f=n===void 0?X.Text:n,g=i===void 0?X.Reasoning:i,b=o===void 0?X.Image:o,v=a===void 0?X.Source:a,x=c===void 0?X.File:c,S=l===void 0?X.Unstable_Audio:l;let T;e[2]!==u?(T=u===void 0?{}:u,e[2]=u,e[3]=T):T=e[3];const y=T,w=F(),C=P(Jd),I=C.type;if(I==="tool-call"){let E;e[4]!==w?(E=w.part(),e[4]=w,e[5]=E):E=e[5];const k=E.addToolResult;let A;e[6]!==w?(A=w.part(),e[6]=w,e[7]=A):A=e[7];const B=A.resumeToolCall;let O;e[8]!==w?(O=w.part(),e[8]=w,e[9]=O):O=e[9];const L=O.respondToToolApproval;if("Override"in y){let U;return e[10]!==k||e[11]!==C||e[12]!==L||e[13]!==B||e[14]!==y.Override?(U=p.jsx(y.Override,{...C,addResult:k,resume:B,respondToApproval:L}),e[10]=k,e[11]=C,e[12]=L,e[13]=B,e[14]=y.Override,e[15]=U):U=e[15],U}const H=(($=y.by_name)==null?void 0:$[C.toolName])??y.Fallback;let j;return e[16]!==H||e[17]!==k||e[18]!==C||e[19]!==L||e[20]!==B?(j=p.jsx(kd,{...C,Fallback:H,addResult:k,resume:B,respondToApproval:L}),e[16]=H,e[17]=k,e[18]=C,e[19]=L,e[20]=B,e[21]=j):j=e[21],j}if(((D=C.status)==null?void 0:D.type)==="requires-action")throw new Error("Encountered unexpected requires-action status");switch(I){case"text":{let E;return e[22]!==f||e[23]!==C?(E=p.jsx(f,{...C}),e[22]=f,e[23]=C,e[24]=E):E=e[24],E}case"reasoning":{let E;return e[25]!==g||e[26]!==C?(E=p.jsx(g,{...C}),e[25]=g,e[26]=C,e[27]=E):E=e[27],E}case"source":{let E;return e[28]!==v||e[29]!==C?(E=p.jsx(v,{...C}),e[28]=v,e[29]=C,e[30]=E):E=e[30],E}case"image":{let E;return e[31]!==b||e[32]!==C?(E=p.jsx(b,{...C}),e[31]=b,e[32]=C,e[33]=E):E=e[33],E}case"file":{let E;return e[34]!==x||e[35]!==C?(E=p.jsx(x,{...C}),e[34]=x,e[35]=C,e[36]=E):E=e[36],E}case"audio":{let E;return e[37]!==S||e[38]!==C?(E=p.jsx(S,{...C}),e[37]=S,e[38]=C,e[39]=E):E=e[39],E}case"data":{const E=((R=h==null?void 0:h.by_name)==null?void 0:R[C.name])??(h==null?void 0:h.Fallback);let k;return e[40]!==E||e[41]!==C?(k=p.jsx($d,{...C,Fallback:E}),e[40]=E,e[41]=C,e[42]=k):k=e[42],k}case"generative-ui":{if(!(d!=null&&d.components))return null;const E=C;let k;return e[43]!==d.Fallback||e[44]!==d.components||e[45]!==E.spec?(k=p.jsx(Ps,{spec:E.spec,components:d.components,Fallback:d.Fallback}),e[43]=d.Fallback,e[44]=d.components,e[45]=E.spec,e[46]=k):k=e[46],k}default:return console.warn(`Unknown message part type: ${I}`),null}},Je=M.memo(t=>{const e=_(5),{index:s,components:r}=t;let n;e[0]!==r?(n=p.jsx(Dd,{components:r}),e[0]=r,e[1]=n):n=e[1];let i;return e[2]!==s||e[3]!==n?(i=p.jsx(Cs,{index:s,children:n}),e[2]=s,e[3]=n,e[4]=i):i=e[4],i},(t,e)=>{var s,r,n,i,o,a,c,l,u,h,d,f,g,b,v,x,S,T,y,w,C,I;return t.index===e.index&&((s=t.components)==null?void 0:s.Text)===((r=e.components)==null?void 0:r.Text)&&((n=t.components)==null?void 0:n.Reasoning)===((i=e.components)==null?void 0:i.Reasoning)&&((o=t.components)==null?void 0:o.Source)===((a=e.components)==null?void 0:a.Source)&&((c=t.components)==null?void 0:c.Image)===((l=e.components)==null?void 0:l.Image)&&((u=t.components)==null?void 0:u.File)===((h=e.components)==null?void 0:h.File)&&((d=t.components)==null?void 0:d.Unstable_Audio)===((f=e.components)==null?void 0:f.Unstable_Audio)&&((g=t.components)==null?void 0:g.tools)===((b=e.components)==null?void 0:b.tools)&&((v=t.components)==null?void 0:v.data)===((x=e.components)==null?void 0:x.data)&&((S=t.components)==null?void 0:S.generativeUI)===((T=e.components)==null?void 0:T.generativeUI)&&((y=t.components)==null?void 0:y.ToolGroup)===((w=e.components)==null?void 0:w.ToolGroup)&&((C=t.components)==null?void 0:C.ReasoningGroup)===((I=e.components)==null?void 0:I.ReasoningGroup)});Je.displayName="MessagePrimitive.PartByIndex";const jd=t=>{const e=_(6),{status:s,component:r}=t,n=s.type==="running";let i;e[0]!==r||e[1]!==s?(i=p.jsx(r,{type:"text",text:"",status:s}),e[0]=r,e[1]=s,e[2]=i):i=e[2];let o;return e[3]!==n||e[4]!==i?(o=p.jsx(Is,{text:"",isRunning:n,children:i}),e[3]=n,e[4]=i,e[5]=o):o=e[5],o},Bd=Object.freeze({type:"complete"}),Od=Object.freeze({type:"running"}),Nd=t=>{const e=_(6),{components:s}=t,r=P(Xd);if(s!=null&&s.Empty){let o;return e[0]!==s.Empty||e[1]!==r?(o=p.jsx(s.Empty,{status:r}),e[0]=s.Empty,e[1]=r,e[2]=o):o=e[2],o}if(r.type!=="running")return null;const n=(s==null?void 0:s.Text)??X.Text;let i;return e[3]!==r||e[4]!==n?(i=p.jsx(jd,{status:r,component:n}),e[3]=r,e[4]=n,e[5]=i):i=e[5],i},hi=M.memo(Nd,(t,e)=>{var s,r,n,i;return((s=t.components)==null?void 0:s.Empty)===((r=e.components)==null?void 0:r.Empty)&&((n=t.components)==null?void 0:n.Text)===((i=e.components)==null?void 0:i.Text)}),Fd=t=>{const e=_(4),{components:s,enabled:r}=t;let n;if(e[0]!==r?(n=o=>{if(!r||o.message.parts.length===0)return!1;const a=o.message.parts[o.message.parts.length-1];return(a==null?void 0:a.type)!=="text"&&(a==null?void 0:a.type)!=="reasoning"},e[0]=r,e[1]=n):n=e[1],!P(n))return null;let i;return e[2]!==s?(i=p.jsx(hi,{components:s}),e[2]=s,e[3]=i):i=e[3],i},Ld=M.memo(Fd,(t,e)=>{var s,r,n,i;return t.enabled===e.enabled&&((s=t.components)==null?void 0:s.Empty)===((r=e.components)==null?void 0:r.Empty)&&((n=t.components)==null?void 0:n.Text)===((i=e.components)==null?void 0:i.Text)}),Vd=t=>{const e=_(4),{Quote:s}=t,r=P(li);if(!r)return null;let n;return e[0]!==s||e[1]!==r.messageId||e[2]!==r.text?(n=p.jsx(s,{text:r.text,messageId:r.messageId}),e[0]=s,e[1]=r.messageId,e[2]=r.text,e[3]=n):n=e[3],n},Ud=M.memo(Vd);function fi(t,e){var r,n,i,o;const s=((n=(r=t.toolUIs[e.toolName])==null?void 0:r[0])==null?void 0:n.render)??null;return s||(Ed((o=(i=e.mcp)==null?void 0:i.app)==null?void 0:o.resourceUri)&&t.mcpApp?t.mcpApp.render:null)}const pi=()=>{const t=_(12),e=F(),s=P(Zd),r=P(eh);if(!r||s.type!=="tool-call")return null;let n;t[0]!==e?(n=e.part(),t[0]=e,t[1]=n):n=t[1];const i=n.addToolResult;let o;t[2]!==e?(o=e.part(),t[2]=e,t[3]=o):o=t[3];const a=o.resumeToolCall;let c;t[4]!==e?(c=e.part(),t[4]=e,t[5]=c):c=t[5];let l;return t[6]!==r||t[7]!==s||t[8]!==n.addToolResult||t[9]!==o.resumeToolCall||t[10]!==c.respondToToolApproval?(l=p.jsx(r,{...s,addResult:i,resume:a,respondToApproval:c.respondToToolApproval}),t[6]=r,t[7]=s,t[8]=n.addToolResult,t[9]=o.resumeToolCall,t[10]=c.respondToToolApproval,t[11]=l):l=t[11],l},gi=()=>{const t=_(3),e=P(th),s=P(sh);if(!s||e.type!=="data")return null;const r=e;let n;return t[0]!==s||t[1]!==r?(n=p.jsx(s,{...r}),t[0]=s,t[1]=r,t[2]=n):n=t[2],n},qd=()=>{const t=_(2),e=P(rh);if(e==="tool-call"){let s;return t[0]===Symbol.for("react.memo_cache_sentinel")?(s=p.jsx(pi,{}),t[0]=s):s=t[0],s}if(e==="data"){let s;return t[1]===Symbol.for("react.memo_cache_sentinel")?(s=p.jsx(gi,{}),t[1]=s):s=t[1],s}return null},Hd=Object.freeze({type:"text",text:"",status:Od}),mi=({index:t,children:e})=>{const s=F(),r=P(n=>n.dataRenderers);return p.jsx(Cs,{index:t,children:p.jsx(qe,{getItemState:n=>n.message().part({index:t}).getState(),children:n=>e({get part(){const i=n();if(i.type==="tool-call"){const o=fi(s.tools().getState(),i)!==null,a=s.message().part({index:t});return{...i,toolUI:o?p.jsx(pi,{}):null,addResult:a.addToolResult,resume:a.resumeToolCall,respondToApproval:a.respondToToolApproval}}if(i.type==="data"){const o=ks(r,i.name,void 0)!==void 0;return{...i,dataRendererUI:o?p.jsx(gi,{}):null}}return i}})})})},zd=t=>{const e=_(9),{children:s}=t,r=P(nh),n=P(ih),i=r===0&&n;if(r===0){if(!i)return null;let a;e[0]!==s?(a=s({part:Hd}),e[0]=s,e[1]=a):a=e[1];let c;return e[2]!==a?(c=p.jsx(Is,{text:"",isRunning:!0,children:a}),e[2]=a,e[3]=c):c=e[3],c}let o;if(e[4]!==s||e[5]!==r){let a;e[7]!==s?(a=(c,l)=>p.jsx(mi,{index:l,children:u=>s(u)??p.jsx(qd,{})},l),e[7]=s,e[8]=a):a=e[8],o=p.jsx(p.Fragment,{children:Array.from({length:r},a)}),e[4]=s,e[5]=r,e[6]=o}else o=e[6];return o},ns=t=>{const e=_(5),{components:s,unstable_showEmptyOnNonTextEnd:r,children:n}=t,i=r===void 0?!0:r;if(n){let a;return e[0]!==n?(a=p.jsx(zd,{children:n}),e[0]=n,e[1]=a):a=e[1],a}let o;return e[2]!==s||e[3]!==i?(o=p.jsx(Gd,{components:s,unstable_showEmptyOnNonTextEnd:i}),e[2]=s,e[3]=i,e[4]=o):o=e[4],o};ns.displayName="MessagePrimitive.Parts";const Gd=t=>{const e=_(15),{components:s,unstable_showEmptyOnNonTextEnd:r}=t,n=P(oh),{ranges:i,partIds:o}=Pd(!!(s!=null&&s.ChainOfThought));let a;e:{if(n===0){let f;e[0]!==s?(f=p.jsx(hi,{components:s}),e[0]=s,e[1]=f):f=e[1],a=f;break e}let d;if(e[2]!==s||e[3]!==i||e[4]!==o){const f=new Set,g=b=>{const v=o[b];return v!==void 0&&!f.has(v)?(f.add(v),`part-id:${v}`):`part-${b}`};d=i.map(b=>{if(b.type==="single")return p.jsx(Je,{index:b.index,components:s},b.index);if(b.type==="chainOfThoughtGroup"){const v=s==null?void 0:s.ChainOfThought;return v?p.jsx(vu,{startIndex:b.startIndex,endIndex:b.endIndex,children:p.jsx(v,{})},`chainOfThought-${b.idKey??b.startIndex}`):null}else return b.type==="toolGroup"?p.jsx((s==null?void 0:s.ToolGroup)??X.ToolGroup,{startIndex:b.startIndex,endIndex:b.endIndex,children:Array.from({length:b.endIndex-b.startIndex+1},(v,x)=>{const S=b.startIndex+x;return p.jsx(Je,{index:S,components:s},g(S))})},`tool-${b.idKey??b.startIndex}`):p.jsx((s==null?void 0:s.ReasoningGroup)??X.ReasoningGroup,{startIndex:b.startIndex,endIndex:b.endIndex,children:Array.from({length:b.endIndex-b.startIndex+1},(v,x)=>{const S=b.startIndex+x;return p.jsx(Je,{index:S,components:s},`part-${S}`)})},`reasoning-${b.startIndex}`)}),e[2]=s,e[3]=i,e[4]=o,e[5]=d}else d=e[5];a=d}const c=a;let l;e[6]!==s?(l=(s==null?void 0:s.Quote)&&p.jsx(Ud,{Quote:s.Quote}),e[6]=s,e[7]=l):l=e[7];let u;e[8]!==s||e[9]!==r?(u=p.jsx(Ld,{components:s,enabled:r}),e[8]=s,e[9]=r,e[10]=u):u=e[10];let h;return e[11]!==c||e[12]!==l||e[13]!==u?(h=p.jsxs(p.Fragment,{children:[l,c,u]}),e[11]=c,e[12]=l,e[13]=u,e[14]=h):h=e[14],h};function Kd(t){return t.type}function Wd(t){return t.message.parts.map(Kd)}function Qd(t){return t.type==="tool-call"?t.toolCallId:void 0}function Yd(t){return t.message.parts.map(Qd)}function Jd(t){return t.part}function Xd(t){return t.message.status??Bd}function Zd(t){return t.part}function eh(t){return t.part.type==="tool-call"?fi(t.tools,t.part):null}function th(t){return t.part}function sh(t){return t.part.type==="data"?ks(t.dataRenderers,t.part.name,void 0)??null:null}function rh(t){return t.part.type}function nh(t){return t.message.parts.length}function ih(t){var e;return(((e=t.message.status)==null?void 0:e.type)??"complete")==="running"}function oh(t){return t.message.parts.length}const ah=Symbol.for("@assistant-ui/groupBy.memoKey"),Rr=t=>{const e=t.nextChildIdx++;return t.nodeKey===""?String(e):`${t.nodeKey}.${e}`},Ar=(t,e)=>{if(!(e===void 0||t.claimed.has(e)))return t.claimed.add(e),`id:${e}`},ch=(t,e)=>{const s={key:"",nodeKey:"",indices:[],children:[],nextChildIdx:0,claimed:new Set},r=[s],n=()=>{const i=r.pop(),o=r[r.length-1];o.children.push({type:"group",key:i.key,nodeKey:i.nodeKey,idKey:Ar(o,e==null?void 0:e[i.indices[0]]),indices:i.indices,children:i.children})};for(let i=0;i<t.length;i++){const o=t[i];let a=0;for(;a<r.length-1&&a<o.length&&r[a+1].key===o[a];)a++;for(;r.length-1>a;)n();for(;r.length-1<o.length;){const l=r[r.length-1];r.push({key:o[r.length-1],nodeKey:Rr(l),indices:[],children:[],nextChildIdx:0,claimed:new Set})}const c=r[r.length-1];c.children.push({type:"part",index:i,nodeKey:Rr(c),idKey:Ar(c,e==null?void 0:e[i])});for(let l=1;l<r.length;l++)r[l].indices.push(i)}for(;r.length>1;)n();return s.children},lh=Object.freeze({type:"complete"}),uh=(t,e,s)=>{if(!s)return!1;switch(t){case"never":return!1;case"always":return!0;case"empty":return e.length===0;case"no-text":{const r=e[e.length-1];return r===void 0||r.type!=="text"&&r.type!=="reasoning"}}},bi=()=>{throw new 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 skip it.")},_i=(t,e,s)=>{var n;if(t.type==="part")return p.jsx(mi,{index:t.index,children:({part:i})=>s({part:i,children:p.jsx(bi,{})})},t.idKey?`part-${t.idKey}`:`part-${t.index}`);const r=((n=e[t.indices.at(-1)])==null?void 0:n.status)??lh;return p.jsx(M.Fragment,{children:s({part:{type:t.key,status:r,indices:t.indices},children:p.jsx(p.Fragment,{children:t.children.map(i=>_i(i,e,s))})})},t.idKey??t.nodeKey)},yi=({groupBy:t,indicator:e="no-text",children:s})=>{const r=P(rs(o=>o.message.parts)),n=P(o=>o.tools.toolUIs),i=P(o=>{var a;return e==="never"?!1:((a=o.message.status)==null?void 0:a.type)==="running"});return p.jsxs(p.Fragment,{children:[Y(()=>{const o={toolUIs:n};return ch(r.map(a=>t(a,o)??[]),r.map(a=>a.type==="tool-call"?a.toolCallId:void 0))},[r,t[ah]??t,n]).map(o=>_i(o,r,s)),uh(e,r,i)&&s({part:{type:"indicator"},children:p.jsx(bi,{})})]})};yi.displayName="MessagePrimitive.GroupedParts";const dh=t=>{const e=_(5),{children:s}=t,r=P(li);if(!r)return null;let n;e[0]!==s||e[1]!==r?(n=s(r),e[0]=s,e[1]=r,e[2]=n):n=e[2];let i;return e[3]!==n?(i=p.jsx(p.Fragment,{children:n}),e[3]=n,e[4]=i):i=e[4],i},vi=M.memo(dh);vi.displayName="MessagePrimitive.Quote";const Si=(t,e)=>{switch(e.type){case"image":return(t==null?void 0:t.Image)??(t==null?void 0:t.Attachment);case"document":return(t==null?void 0:t.Document)??(t==null?void 0:t.Attachment);case"file":return(t==null?void 0:t.File)??(t==null?void 0:t.Attachment);default:return t==null?void 0:t.Attachment}},hh=t=>{const e=_(5),{components:s}=t,r=P(fh);if(!r)return null;const n=r;let i;e[0]!==s||e[1]!==n?(i=Si(s,n),e[0]=s,e[1]=n,e[2]=i):i=e[2];const o=i;if(!o)return null;let a;return e[3]!==o?(a=p.jsx(o,{}),e[3]=o,e[4]=a):a=e[4],a},xi=M.memo(t=>{const e=_(5),{index:s,components:r}=t;let n;e[0]!==r?(n=p.jsx(hh,{components:r}),e[0]=r,e[1]=n):n=e[1];let i;return e[2]!==s||e[3]!==n?(i=p.jsx(Wn,{index:s,children:n}),e[2]=s,e[3]=n,e[4]=i):i=e[4],i},(t,e)=>{var s,r,n,i,o,a,c,l;return t.index===e.index&&((s=t.components)==null?void 0:s.Image)===((r=e.components)==null?void 0:r.Image)&&((n=t.components)==null?void 0:n.Document)===((i=e.components)==null?void 0:i.Document)&&((o=t.components)==null?void 0:o.File)===((a=e.components)==null?void 0:a.File)&&((c=t.components)==null?void 0:c.Attachment)===((l=e.components)==null?void 0:l.Attachment)});xi.displayName="MessagePrimitive.AttachmentByIndex";const Mr=({children:t})=>{const e=P(s=>s.message.role!=="user"?0:(s.message.attachments??[]).length);return Y(()=>Array.from({length:e},(s,r)=>p.jsx(Wn,{index:r,children:p.jsx(qe,{getItemState:n=>n.message().attachment({index:r}).getState(),children:n=>t({get attachment(){return n()}})})},r)),[e,t])},wi=t=>{const e=_(4),{components:s,children:r}=t;if(s){let i;return e[0]!==s?(i=p.jsx(Mr,{children:o=>{const{attachment:a}=o,c=Si(s,a);return c?p.jsx(c,{}):null}}),e[0]=s,e[1]=i):i=e[1],i}let n;return e[2]!==r?(n=p.jsx(Mr,{children:r}),e[2]=r,e[3]=n):n=e[3],n};wi.displayName="MessagePrimitive.Attachments";function fh(t){return t.attachment}const Ti=(t,e)=>{switch(e.type){case"image":return(t==null?void 0:t.Image)??(t==null?void 0:t.Attachment);case"document":return(t==null?void 0:t.Document)??(t==null?void 0:t.Attachment);case"file":return(t==null?void 0:t.File)??(t==null?void 0:t.Attachment);default:return t==null?void 0:t.Attachment}},ph=t=>{const e=_(5),{components:s}=t,r=P(gh);if(!r)return null;let n;e[0]!==r||e[1]!==s?(n=Ti(s,r),e[0]=r,e[1]=s,e[2]=n):n=e[2];const i=n;if(!i)return null;let o;return e[3]!==i?(o=p.jsx(i,{}),e[3]=i,e[4]=o):o=e[4],o},Ci=M.memo(t=>{const e=_(5),{index:s,components:r}=t;let n;e[0]!==r?(n=p.jsx(ph,{components:r}),e[0]=r,e[1]=n):n=e[1];let i;return e[2]!==s||e[3]!==n?(i=p.jsx(Qn,{index:s,children:n}),e[2]=s,e[3]=n,e[4]=i):i=e[4],i},(t,e)=>{var s,r,n,i,o,a,c,l;return t.index===e.index&&((s=t.components)==null?void 0:s.Image)===((r=e.components)==null?void 0:r.Image)&&((n=t.components)==null?void 0:n.Document)===((i=e.components)==null?void 0:i.Document)&&((o=t.components)==null?void 0:o.File)===((a=e.components)==null?void 0:a.File)&&((c=t.components)==null?void 0:c.Attachment)===((l=e.components)==null?void 0:l.Attachment)});Ci.displayName="ComposerPrimitive.AttachmentByIndex";const Pr=({children:t})=>{const e=P(s=>s.composer.attachments.length);return Y(()=>Array.from({length:e},(s,r)=>p.jsx(Qn,{index:r,children:p.jsx(qe,{getItemState:n=>n.composer().attachment({index:r}).getState(),children:n=>t({get attachment(){return n()}})})},r)),[e,t])},Ii=t=>{const e=_(4),{components:s,children:r}=t;if(s){let i;return e[0]!==s?(i=p.jsx(Pr,{children:o=>{const{attachment:a}=o,c=Ti(s,a);return c?p.jsx(c,{}):null}}),e[0]=s,e[1]=i):i=e[1],i}let n;return e[2]!==r?(n=p.jsx(Pr,{children:r}),e[2]=r,e[3]=n):n=e[3],n};Ii.displayName="ComposerPrimitive.Attachments";function gh(t){return t.attachment}const mh=({children:t})=>{const e=P(s=>s.composer.queue.length);return Y(()=>Array.from({length:e},(s,r)=>p.jsx(xu,{index:r,children:p.jsx(qe,{getItemState:n=>n.composer().queueItem({index:r}).getState(),children:n=>t({get queueItem(){return n()}})})},r)),[e,t])},Ei=M.memo(mh);Ei.displayName="ComposerPrimitive.Queue";const $s=t=>{const{children:e}=t;return P(bh)?e:null};$s.displayName="MessagePartPrimitive.InProgress";function bh(t){return t.part.status.type==="running"}const Ri=t=>{const e=_(2),{components:s}=t,r=s.Suggestion;let n;return e[0]!==r?(n=p.jsx(r,{}),e[0]=r,e[1]=n):n=e[1],n},Ai=M.memo(t=>{const e=_(5),{index:s,components:r}=t;let n;e[0]!==r?(n=p.jsx(Ri,{components:r}),e[0]=r,e[1]=n):n=e[1];let i;return e[2]!==s||e[3]!==n?(i=p.jsx(Jn,{index:s,children:n}),e[2]=s,e[3]=n,e[4]=i):i=e[4],i},(t,e)=>t.index===e.index&&t.components.Suggestion===e.components.Suggestion);Ai.displayName="ThreadPrimitive.SuggestionByIndex";const kr=({children:t})=>{const e=P(s=>s.suggestions.suggestions.length);return Y(()=>e===0?null:Array.from({length:e},(s,r)=>p.jsx(Jn,{index:r,children:p.jsx(qe,{getItemState:n=>n.suggestions().suggestion({index:r}).getState(),children:n=>t({get suggestion(){return n()}})})},r)),[e,t])},Mi=t=>{const e=_(4),{components:s,children:r}=t;if(s){let i;return e[0]!==s?(i=p.jsx(kr,{children:()=>p.jsx(Ri,{components:s})}),e[0]=s,e[1]=i):i=e[1],i}let n;return e[2]!==r?(n=p.jsx(kr,{children:r}),e[2]=r,e[3]=n):n=e[3],n};Mi.displayName="ThreadPrimitive.Suggestions";const _h=M.memo(Mi,(t,e)=>t.children||e.children?t.children===e.children:t.components.Suggestion===e.components.Suggestion),yh=t=>{const e=_(3);let s;return e[0]!==t.dictation||e[1]!==t.editing?(s=r=>{if(t.editing===!0&&!r.composer.isEditing||t.editing===!1&&r.composer.isEditing)return!1;const n=r.composer.dictation!=null;return!(t.dictation===!0&&!n||t.dictation===!1&&n)},e[0]=t.dictation,e[1]=t.editing,e[2]=s):s=e[2],P(s)},Pi=t=>{const e=_(3);let s,r;return e[0]!==t?({children:s,...r}=t,e[0]=t,e[1]=s,e[2]=r):(s=e[1],r=e[2]),yh(r)?s:null};Pi.displayName="ComposerPrimitive.If";const vh=()=>{const t=_(5),e=F(),s=P(Sh);let r;t[0]!==e?(r=o=>{e.composer().send(o)},t[0]=e,t[1]=r):r=t[1];const n=r;let i;return t[2]!==s||t[3]!==n?(i={send:n,disabled:s},t[2]=s,t[3]=n,t[4]=i):i=t[4],i};function Sh(t){return!t.composer.canSend||t.thread.isRunning&&!t.thread.capabilities.queue}const xh=()=>{const t=_(5),e=F(),s=P(wh);let r;t[0]!==e?(r=()=>{e.composer().cancel()},t[0]=e,t[1]=r):r=t[1];const n=r;let i;return t[2]!==n||t[3]!==s?(i={cancel:n,disabled:s},t[2]=n,t[3]=s,t[4]=i):i=t[4],i};function wh(t){return!t.composer.canCancel}const Th=()=>{const t=_(5),e=F(),s=P(Ch);let r;t[0]!==e?(r=()=>{e.composer().startDictation()},t[0]=e,t[1]=r):r=t[1];const n=r;let i;return t[2]!==s||t[3]!==n?(i={startDictation:n,disabled:s},t[2]=s,t[3]=n,t[4]=i):i=t[4],i};function Ch(t){return t.composer.dictation!=null||!t.thread.capabilities.dictation||!t.composer.isEditing}const Ih=()=>{const t=_(5),e=F(),s=P(Eh);let r;t[0]!==e?(r=o=>e.composer().addAttachment(o),t[0]=e,t[1]=r):r=t[1];const n=r;let i;return t[2]!==n||t[3]!==s?(i={addAttachment:n,disabled:s},t[2]=n,t[3]=s,t[4]=i):i=t[4],i};function Eh(t){return!t.composer.isEditing}const Rh=t=>{const e=_(12);let s;e[0]!==t?(s=t===void 0?{}:t,e[0]=t,e[1]=s):s=e[1];const{copiedDuration:r,copyToClipboard:n}=s,i=r===void 0?3e3:r,o=F(),a=P(Mh),c=P(Ph),l=P(kh),u=P($h);let h;e[2]!==o||e[3]!==u||e[4]!==i||e[5]!==n||e[6]!==l?(h=()=>{const g=l?u:o.message().getCopyText();if(!g)return;const b=n??Dh;Promise.resolve(b(g)).then(()=>{o.message().setIsCopied(!0),setTimeout(()=>o.message().setIsCopied(!1),i)},jh)},e[2]=o,e[3]=u,e[4]=i,e[5]=n,e[6]=l,e[7]=h):h=e[7];const d=h;let f;return e[8]!==d||e[9]!==a||e[10]!==c?(f={copy:d,disabled:a,isCopied:c},e[8]=d,e[9]=a,e[10]=c,e[11]=f):f=e[11],f};function Ah(t){return t.type==="text"&&t.text.length>0}function Mh(t){var e;return!((t.message.role!=="assistant"||((e=t.message.status)==null?void 0:e.type)!=="running")&&t.message.parts.some(Ah))}function Ph(t){return t.message.isCopied}function kh(t){return t.composer.isEditing}function $h(t){return t.composer.text}function Dh(){}function jh(){}const Bh=()=>{const t=_(5),e=F(),s=P(Oh);let r;t[0]!==e?(r=()=>{e.composer().beginEdit()},t[0]=e,t[1]=r):r=t[1];const n=r;let i;return t[2]!==s||t[3]!==n?(i={edit:n,disabled:s},t[2]=s,t[3]=n,t[4]=i):i=t[4],i};function Oh(t){return t.composer.isEditing}const Nh=()=>{const t=_(5),e=F(),s=P(Fh);let r;t[0]!==e?(r=()=>{e.message().reload()},t[0]=e,t[1]=r):r=t[1];const n=r;let i;return t[2]!==s||t[3]!==n?(i={reload:n,disabled:s},t[2]=s,t[3]=n,t[4]=i):i=t[4],i};function Fh(t){return t.thread.isRunning||t.thread.isDisabled||t.message.role!=="assistant"}const Lh=()=>{const t=_(5),e=F(),s=P(Uh);let r;t[0]!==e?(r=()=>{e.message().submitFeedback({type:"positive"})},t[0]=e,t[1]=r):r=t[1];const n=r;let i;return t[2]!==s||t[3]!==n?(i={submit:n,isSubmitted:s},t[2]=s,t[3]=n,t[4]=i):i=t[4],i},Vh=()=>{const t=_(5),e=F(),s=P(qh);let r;t[0]!==e?(r=()=>{e.message().submitFeedback({type:"negative"})},t[0]=e,t[1]=r):r=t[1];const n=r;let i;return t[2]!==s||t[3]!==n?(i={submit:n,isSubmitted:s},t[2]=s,t[3]=n,t[4]=i):i=t[4],i};function Uh(t){var e;return((e=t.message.metadata.submittedFeedback)==null?void 0:e.type)==="positive"}function qh(t){var e;return((e=t.message.metadata.submittedFeedback)==null?void 0:e.type)==="negative"}const Hh=()=>{const t=_(5),e=F(),s=P(Gh);let r;t[0]!==e?(r=async()=>{e.message().speak()},t[0]=e,t[1]=r):r=t[1];const n=r;let i;return t[2]!==s||t[3]!==n?(i={speak:n,disabled:s},t[2]=s,t[3]=n,t[4]=i):i=t[4],i};function zh(t){return t.type==="text"&&t.text.length>0}function Gh(t){var e;return!((t.message.role!=="assistant"||((e=t.message.status)==null?void 0:e.type)!=="running")&&t.message.parts.some(zh))}const Kh=()=>{const t=_(5),e=F(),s=P(Wh);let r;t[0]!==e?(r=()=>{e.message().stopSpeaking()},t[0]=e,t[1]=r):r=t[1];const n=r;let i;return t[2]!==s||t[3]!==n?(i={stopSpeaking:n,disabled:s},t[2]=s,t[3]=n,t[4]=i):i=t[4],i};function Wh(t){return t.message.speech==null}const Qh=t=>{const e=_(8),{prompt:s,send:r,clearComposer:n}=t,i=n===void 0?!0:n,o=F(),a=P(Yh),c=r??!1;let l;e[0]!==o||e[1]!==i||e[2]!==s||e[3]!==c?(l=()=>{const d=o.thread().getState().isRunning;if(c&&!d)o.thread().append({content:[{type:"text",text:s}],runConfig:o.composer().getState().runConfig}),i&&o.composer().setText("");else if(i)o.composer().setText(s);else{const f=o.composer().getState().text;o.composer().setText(f.trim()?`${f} ${s}`:s)}},e[0]=o,e[1]=i,e[2]=s,e[3]=c,e[4]=l):l=e[4];const u=l;let h;return e[5]!==a||e[6]!==u?(h={trigger:u,disabled:a},e[5]=a,e[6]=u,e[7]=h):h=e[7],h};function Yh(t){return t.thread.isDisabled}const Jh=()=>P(Xh);function Xh(t){var e;return((e=t.message.status)==null?void 0:e.type)==="incomplete"&&t.message.status.reason==="error"?t.message.status.error??"An error occurred":void 0}const Zh=/:([\w-]{1,64})\[([^\]\n]{1,1024})\](?:\{name=([^}\n]{1,1024})\})?/gu,ki={serialize(t){const e=t.id!==t.label?`{name=${t.id}}`:"";return`:${t.type}[${t.label}]${e}`},parse(t){const e=[];let s=0;for(const r of t.matchAll(Zh)){r.index>s&&e.push({kind:"text",text:t.slice(s,r.index)});const n=r[2];e.push({kind:"mention",type:r[1],label:n,id:r[3]??n}),s=r.index+r[0].length}return s<t.length&&e.push({kind:"text",text:t.slice(s)}),e}};function ef(t,e){function s(r){const n=he(t);if(!(r!=null&&r.optional)&&!n)throw new Error(`This component must be used within ${e}.`);return n}return s}function $i(t,e){function s(n){const i=t(n);return i?i[e]:null}function r(n){let i=!1,o;typeof n=="function"?o=n:n&&typeof n=="object"&&(i=!!n.optional,o=n.selector);const a=s({optional:i});return a?o?a(o):a():null}return{[e]:r,[`${e}Store`]:s}}const Di=ae(null),{useThreadViewport:ke,useThreadViewportStore:$e}=$i(ef(Di,"ThreadPrimitive.Viewport"),"useThreadViewport"),$r=t=>{const e=new Map,s=()=>{let r=0;for(const n of e.values())r+=n;t(r)};return{register:()=>{const r=Symbol();return e.set(r,0),{setHeight:n=>{e.get(r)!==n&&(e.set(r,n),s())},unregister:()=>{e.delete(r),s()}}}}},tf=(t={})=>{const e=new Set,s=$r(o=>{i.setState({height:{...i.getState().height,viewport:o}})}),r=$r(o=>{i.setState({height:{...i.getState().height,inset:o}})}),n=(o,a)=>(i.setState({element:{...i.getState().element,[o]:a}}),()=>{i.getState().element[o]===a&&i.setState({element:{...i.getState().element,[o]:null}})}),i=Tl(()=>{var o,a;return{isAtBottom:!0,scrollToBottom:({behavior:c="auto"}={})=>{for(const l of e)l({behavior:c})},onScrollToBottom:c=>(e.add(c),()=>{e.delete(c)}),turnAnchor:t.turnAnchor??"bottom",topAnchorMessageClamp:{tallerThan:((o=t.topAnchorMessageClamp)==null?void 0:o.tallerThan)??"10em",visibleHeight:((a=t.topAnchorMessageClamp)==null?void 0:a.visibleHeight)??"6em"},height:{viewport:0,inset:0},element:{viewport:null,anchor:null,target:null},targetConfig:null,topAnchorTurn:null,registerViewport:s.register,registerContentInset:r.register,registerViewportElement:c=>n("viewport",c),registerAnchorElement:c=>n("anchor",c),registerAnchorTargetElement:(c,l)=>(i.setState({element:{...i.getState().element,target:c},targetConfig:c&&l?l:null}),()=>{i.getState().element.target===c&&i.setState({element:{...i.getState().element,target:null},targetConfig:null})}),setTopAnchorTurn:c=>{i.setState({topAnchorTurn:c})}}});return i},Tt=t=>t,sf=t=>{const e=_(11);let s;e[0]===Symbol.for("react.memo_cache_sentinel")?(s={optional:!0},e[0]=s):s=e[0];const r=$e(s);let n;e[1]!==t?(n=()=>tf(t),e[1]=t,e[2]=n):n=e[2];const[i]=G(n);let o,a;e[3]!==r||e[4]!==i?(o=()=>r==null?void 0:r.getState().onScrollToBottom(()=>{i.getState().scrollToBottom()}),a=[r,i],e[3]=r,e[4]=i,e[5]=o,e[6]=a):(o=e[5],a=e[6]),N(o,a);let c,l;return e[7]!==r||e[8]!==i?(c=()=>{if(r)return i.subscribe(u=>{r.getState().isAtBottom!==u.isAtBottom&&Tt(r).setState({isAtBottom:u.isAtBottom})})},l=[i,r],e[7]=r,e[8]=i,e[9]=c,e[10]=l):(c=e[9],l=e[10]),N(c,l),i},Ds=t=>{const e=_(7),{children:s,options:r}=t;let n;e[0]!==r?(n=r===void 0?{}:r,e[0]=r,e[1]=n):n=e[1];const i=sf(n);let o;e[2]!==i?(o=()=>({useThreadViewport:i}),e[2]=i,e[3]=o):o=e[3];const[a]=G(o);let c;return e[4]!==s||e[5]!==a?(c=p.jsx(Di.Provider,{value:a,children:s}),e[4]=s,e[5]=a,e[6]=c):c=e[6],c},rf=()=>{const t=_(3),e=F();let s,r;return t[0]!==e?(s=()=>{},r=[e],t[0]=e,t[1]=s,t[2]=r):(s=t[1],r=t[2]),N(s,r),null},nf=t=>{const e=_(7),{children:s,aui:r,runtime:n}=t,i=r??null;let o;e[0]===Symbol.for("react.memo_cache_sentinel")?(o=p.jsx(rf,{}),e[0]=o):o=e[0];let a;e[1]!==s?(a=p.jsx(Ds,{children:s}),e[1]=s,e[2]=a):a=e[2];let c;return e[3]!==n||e[4]!==i||e[5]!==a?(c=p.jsxs(vl,{runtime:n,aui:i,children:[o,a]}),e[3]=n,e[4]=i,e[5]=a,e[6]=c):c=e[6],c},of=M.memo(nf);var af=Object.defineProperty,js=(t,e)=>af(t,"name",{value:e,configurable:!0});function is(t,e){if(typeof t=="function")return t(e);t!=null&&(t.current=e)}js(is,"setRef");function ji(...t){return e=>{let s=!1;const r=t.map(n=>{const i=is(n,e);return!s&&typeof i=="function"&&(s=!0),i});if(s)return()=>{for(let n=0;n<r.length;n++){const i=r[n];typeof i=="function"?i():is(t[n],null)}}}}js(ji,"composeRefs");function we(...t){return M.useCallback(ji(...t),t)}js(we,"useComposedRefs");var Dr=Object.defineProperty,Dt=(t,e)=>{let s={};for(var r in t)Dr(s,r,{get:t[r],enumerable:!0});return Dr(s,Symbol.toStringTag,{value:"Module"}),s},cf=Object.defineProperty,fe=(t,e)=>cf(t,"name",{value:e,configurable:!0});function Bs(t){const e=M.forwardRef((s,r)=>{let{children:n,...i}=s,o=null,a=!1;const c=[];os(n)&&typeof ut=="function"&&(n=ut(n._payload)),M.Children.forEach(n,d=>{var f;if(Fi(d)){a=!0;const g=d;let b="child"in g.props?g.props.child:g.props.children;os(b)&&typeof ut=="function"&&(b=ut(b._payload)),o=uf(g,b),c.push((f=o==null?void 0:o.props)==null?void 0:f.children)}else c.push(d)}),o?o=M.cloneElement(o,void 0,c):!a&&M.Children.count(n)===1&&M.isValidElement(n)&&(o=n);const l=o?Ni(o):void 0,u=we(r,l);if(!o){if(n||n===0)throw new Error(a?ff(t):hf(t));return n}const h=Oi(i,o.props??{});return o.type!==M.Fragment&&(h.ref=r?u:l),M.cloneElement(o,h)});return e.displayName=`${t}.Slot`,e}fe(Bs,"createSlot");var Ct=Bs("Slot"),Bi=Symbol.for("radix.slottable");function lf(t){const e=fe(s=>"child"in s?s.children(s.child):s.children,"Slottable");return e.displayName=`${t}.Slottable`,e.__radixId=Bi,e}fe(lf,"createSlottable");var uf=fe((t,e)=>{if("child"in t.props){const s=t.props.child;return M.isValidElement(s)?M.cloneElement(s,void 0,t.props.children(s.props.children)):null}return M.isValidElement(e)?e:null},"getSlottableElementFromSlottable");function Oi(t,e){const s={...e};for(const r in e){const n=t[r],i=e[r];/^on[A-Z]/.test(r)?n&&i?s[r]=(...a)=>{const c=i(...a);return n(...a),c}:n&&(s[r]=n):r==="style"?s[r]={...n,...i}:r==="className"&&(s[r]=[n,i].filter(Boolean).join(" "))}return{...t,...s}}fe(Oi,"mergeProps");function Ni(t){var r,n;let e=(r=Object.getOwnPropertyDescriptor(t.props,"ref"))==null?void 0:r.get,s=e&&"isReactWarning"in e&&e.isReactWarning;return s?t.ref:(e=(n=Object.getOwnPropertyDescriptor(t,"ref"))==null?void 0:n.get,s=e&&"isReactWarning"in e&&e.isReactWarning,s?t.props.ref:t.props.ref||t.ref)}fe(Ni,"getElementRef");function Fi(t){return M.isValidElement(t)&&typeof t.type=="function"&&"__radixId"in t.type&&t.type.__radixId===Bi}fe(Fi,"isSlottable");var df=Symbol.for("react.lazy");function os(t){return t!=null&&typeof t=="object"&&"$$typeof"in t&&t.$$typeof===df&&"_payload"in t&&Li(t._payload)}fe(os,"isLazyComponent");function Li(t){return typeof t=="object"&&t!==null&&"then"in t}fe(Li,"isPromiseLike");var hf=fe(t=>`${t} failed to slot onto its children. Expected a single React element child or \`Slottable\`.`,"createSlotError"),ff=fe(t=>`${t} failed to slot onto its \`Slottable\`. Expected \`Slottable\` to receive a single React element child.`,"createSlottableError"),ut=qo[" use ".trim().toString()],pf=Object.defineProperty,gf=(t,e)=>pf(t,"name",{value:e,configurable:!0}),mf=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],bf=mf.reduce((t,e)=>{const s=Bs(`Primitive.${e}`),r=M.forwardRef((n,i)=>{const{asChild:o,...a}=n,c=o?s:e;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),p.jsx(c,{...a,ref:i})});return r.displayName=`Primitive.${e}`,{...t,[e]:r}},{});function _f(t,e){t&&Ho.flushSync(()=>t.dispatchEvent(e))}gf(_f,"dispatchDiscreteCustomEvent");const yf=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"];function vf(t){const e=M.forwardRef((s,r)=>{const n=_(17);let i,o,a,c;n[0]!==s?({render:a,asChild:i,children:o,...c}=s,n[0]=s,n[1]=i,n[2]=o,n[3]=a,n[4]=c):(i=n[1],o=n[2],a=n[3],c=n[4]);const l=t;if(a&&M.isValidElement(a)){const d=o!==void 0?o:a.props.children,f=c;let g;n[5]!==a||n[6]!==d?(g=M.cloneElement(a,void 0,d),n[5]=a,n[6]=d,n[7]=g):g=n[7];let b;return n[8]!==r||n[9]!==f||n[10]!==g?(b=p.jsx(l,{...f,asChild:!0,ref:r,children:g}),n[8]=r,n[9]=f,n[10]=g,n[11]=b):b=n[11],b}const u=c;let h;return n[12]!==i||n[13]!==o||n[14]!==r||n[15]!==u?(h=p.jsx(l,{...u,asChild:i,ref:r,children:o}),n[12]=i,n[13]=o,n[14]=r,n[15]=u,n[16]=h):h=n[16],h});return e.displayName=typeof t=="string"?t:t.displayName??t.name??"Component",e}function Sf(t){const e=bf[t],s=vf(e);return s.displayName=`Primitive.${t}`,s}const W=yf.reduce((t,e)=>(t[e]=Sf(e),t),{}),xf=t=>{const e=_(5),{hideWhenRunning:s,autohide:r,autohideFloat:n,forceVisible:i}=t;let o;return e[0]!==r||e[1]!==n||e[2]!==i||e[3]!==s?(o=a=>{if(s&&a.thread.isRunning)return"hidden";const c=r==="always"||r==="not-last"&&!a.message.isLast,l=i||a.message.isHovering;return c?l?n==="always"||n==="single-branch"&&a.message.branchCount<=1?"floating":"normal":"hidden":"normal"},e[0]=r,e[1]=n,e[2]=i,e[3]=s,e[4]=o):o=e[4],P(o)},wf=ae(null),Vi=M.forwardRef((t,e)=>{const s=_(18);let r,n,i,o;s[0]!==t?({hideWhenRunning:i,autohide:r,autohideFloat:n,...o}=t,s[0]=t,s[1]=r,s[2]=n,s[3]=i,s[4]=o):(r=s[1],n=s[2],i=s[3],o=s[4]);const[a,c]=G(0);let l;s[5]===Symbol.for("react.memo_cache_sentinel")?(l=()=>{let S=!1;return c(Tf),()=>{S||(S=!0,c(Cf))}},s[5]=l):l=s[5];const u=l;let h;s[6]===Symbol.for("react.memo_cache_sentinel")?(h={acquireInteractionLock:u},s[6]=h):h=s[6];const d=h,f=a>0;let g;s[7]!==r||s[8]!==n||s[9]!==i||s[10]!==f?(g={hideWhenRunning:i,autohide:r,autohideFloat:n,forceVisible:f},s[7]=r,s[8]=n,s[9]=i,s[10]=f,s[11]=g):g=s[11];const b=xf(g);if(b==="hidden")return null;let v;s[12]!==b?(v=b==="floating"?{"data-floating":"true"}:null,s[12]=b,s[13]=v):v=s[13];let x;return s[14]!==e||s[15]!==o||s[16]!==v?(x=p.jsx(wf.Provider,{value:d,children:p.jsx(W.div,{...v,...o,ref:e})}),s[14]=e,s[15]=o,s[16]=v,s[17]=x):x=s[17],x});Vi.displayName="ActionBarPrimitive.Root";function Tf(t){return t+1}function Cf(t){return Math.max(0,t-1)}var If=Object.defineProperty,Ge=(t,e)=>If(t,"name",{value:e,configurable:!0}),Ui=!!(typeof window<"u"&&window.document&&window.document.createElement);function K(t,e,{checkForDefaultPrevented:s=!0}={}){return Ge(function(n){if(t==null||t(n),s===!1||!n||!n.defaultPrevented)return e==null?void 0:e(n)},"handleEvent")}Ge(K,"composeEventHandlers");function Ef(t){var e;if(!Ui)throw new Error("Cannot access window outside of the DOM");return((e=t==null?void 0:t.ownerDocument)==null?void 0:e.defaultView)??window}Ge(Ef,"getOwnerWindow");function as(t){if(!Ui)throw new Error("Cannot access document outside of the DOM");return(t==null?void 0:t.ownerDocument)??document}Ge(as,"getOwnerDocument");function qi(t,e=!1){const{activeElement:s}=as(t);if(!(s!=null&&s.nodeName))return null;if(Hi(s)&&s.contentDocument)return qi(s.contentDocument.body,e);if(e){const r=s.getAttribute("aria-activedescendant");if(r){const n=as(s).getElementById(r);if(n)return n}}return s}Ge(qi,"getActiveElement");function Hi(t){return t.tagName==="IFRAME"}Ge(Hi,"isFrame");const Rf=t=>{const e=_(4);let s;e[0]!==t?(s=t===void 0?{}:t,e[0]=t,e[1]=s):s=e[1];const{copiedDuration:r}=s,n=r===void 0?3e3:r;let i;e[2]!==n?(i={copiedDuration:n,copyToClipboard:Af},e[2]=n,e[3]=i):i=e[3];const{copy:o,disabled:a}=Rh(i);return a?null:o},zi=M.forwardRef((t,e)=>{const s=_(20);let r,n,i,o;s[0]!==t?({copiedDuration:r,onClick:i,disabled:n,...o}=t,s[0]=t,s[1]=r,s[2]=n,s[3]=i,s[4]=o):(r=s[1],n=s[2],i=s[3],o=s[4]);const a=P(Mf);let c;s[5]!==r?(c={copiedDuration:r},s[5]=r,s[6]=c):c=s[6];const l=Rf(c);let u;s[7]!==a?(u=a?{"data-copied":"true"}:{},s[7]=a,s[8]=u):u=s[8];const h=n||!l;let d;s[9]!==l?(d=()=>{l==null||l()},s[9]=l,s[10]=d):d=s[10];let f;s[11]!==i||s[12]!==d?(f=K(i,d),s[11]=i,s[12]=d,s[13]=f):f=s[13];let g;return s[14]!==e||s[15]!==o||s[16]!==u||s[17]!==h||s[18]!==f?(g=p.jsx(W.button,{type:"button",...u,...o,ref:e,disabled:h,onClick:f}),s[14]=e,s[15]=o,s[16]=u,s[17]=h,s[18]=f,s[19]=g):g=s[19],g});zi.displayName="ActionBarPrimitive.Copy";function Af(t){return typeof navigator>"u"||!navigator.clipboard?Promise.reject(new Error("Clipboard API is unavailable")):navigator.clipboard.writeText(t)}function Mf(t){return t.message.isCopied}const be=(t,e,s=[])=>{const r=M.forwardRef((n,i)=>{const o=_(6),a={},c={};Object.keys(n).forEach(b=>{s.includes(b)?a[b]=n[b]:c[b]=n[b]});const l=e(a)??void 0,u=W,h="button",d=c.disabled||!l,f=K(c.onClick,l);let g;return o[0]!==i||o[1]!==c||o[2]!==u.button||o[3]!==d||o[4]!==f?(g=p.jsx(u.button,{...c,type:h,ref:i,disabled:d,onClick:f}),o[0]=i,o[1]=c,o[2]=u.button,o[3]=d,o[4]=f,o[5]=g):g=o[5],g});return r.displayName=t,r},Pf=()=>{const{disabled:t,reload:e}=Nh();return t?null:e},kf=be("ActionBarPrimitive.Reload",Pf),$f=()=>{const{disabled:t,edit:e}=Bh();return t?null:e},Df=be("ActionBarPrimitive.Edit",$f),jf=()=>{const{disabled:t,speak:e}=Hh();return t?null:e},Bf=be("ActionBarPrimitive.Speak",jf);var Of=Object.defineProperty,Nf=(t,e)=>Of(t,"name",{value:e,configurable:!0});function st(t){const e=M.useRef(t);return M.useEffect(()=>{e.current=t}),M.useMemo(()=>(...s)=>{var r;return(r=e.current)==null?void 0:r.call(e,...s)},[])}Nf(st,"useCallbackRef");var Ff=Object.defineProperty,Gi=(t,e)=>Ff(t,"name",{value:e,configurable:!0});function Os(t,e=globalThis==null?void 0:globalThis.document){const s=st(t);M.useEffect(()=>{const r=Gi(n=>{n.key==="Escape"&&s(n)},"handleKeyDown");return e.addEventListener("keydown",r,{capture:!0}),()=>e.removeEventListener("keydown",r,{capture:!0})},[s,e])}Gi(Os,"useEscapeKeydown");const Lf=()=>{const{disabled:t,stopSpeaking:e}=Kh();return t?null:e},Ki=M.forwardRef((t,e)=>{const s=_(12),r=Lf();let n;s[0]!==r?(n=l=>{r&&(l.preventDefault(),r())},s[0]=r,s[1]=n):n=s[1],Os(n);const i=!r;let o;s[2]!==r?(o=()=>{r==null||r()},s[2]=r,s[3]=o):o=s[3];let a;s[4]!==t.onClick||s[5]!==o?(a=K(t.onClick,o),s[4]=t.onClick,s[5]=o,s[6]=a):a=s[6];let c;return s[7]!==t||s[8]!==e||s[9]!==i||s[10]!==a?(c=p.jsx(W.button,{type:"button",disabled:i,...t,ref:e,onClick:a}),s[7]=t,s[8]=e,s[9]=i,s[10]=a,s[11]=c):c=s[11],c});Ki.displayName="ActionBarPrimitive.StopSpeaking";const Vf=()=>{const{submit:t}=Lh();return t},Wi=M.forwardRef((t,e)=>{const s=_(17);let r,n,i;s[0]!==t?({onClick:n,disabled:r,...i}=t,s[0]=t,s[1]=r,s[2]=n,s[3]=i):(r=s[1],n=s[2],i=s[3]);const o=P(Uf),a=Vf();let c;s[4]!==o?(c=o?{"data-submitted":"true"}:{},s[4]=o,s[5]=c):c=s[5];const l=r||!a;let u;s[6]!==a?(u=()=>{a==null||a()},s[6]=a,s[7]=u):u=s[7];let h;s[8]!==n||s[9]!==u?(h=K(n,u),s[8]=n,s[9]=u,s[10]=h):h=s[10];let d;return s[11]!==e||s[12]!==i||s[13]!==c||s[14]!==l||s[15]!==h?(d=p.jsx(W.button,{type:"button",...c,...i,ref:e,disabled:l,onClick:h}),s[11]=e,s[12]=i,s[13]=c,s[14]=l,s[15]=h,s[16]=d):d=s[16],d});Wi.displayName="ActionBarPrimitive.FeedbackPositive";function Uf(t){var e;return((e=t.message.metadata.submittedFeedback)==null?void 0:e.type)==="positive"}const qf=()=>{const{submit:t}=Vh();return t},Qi=M.forwardRef((t,e)=>{const s=_(17);let r,n,i;s[0]!==t?({onClick:n,disabled:r,...i}=t,s[0]=t,s[1]=r,s[2]=n,s[3]=i):(r=s[1],n=s[2],i=s[3]);const o=P(Hf),a=qf();let c;s[4]!==o?(c=o?{"data-submitted":"true"}:{},s[4]=o,s[5]=c):c=s[5];const l=r||!a;let u;s[6]!==a?(u=()=>{a==null||a()},s[6]=a,s[7]=u):u=s[7];let h;s[8]!==n||s[9]!==u?(h=K(n,u),s[8]=n,s[9]=u,s[10]=h):h=s[10];let d;return s[11]!==e||s[12]!==i||s[13]!==c||s[14]!==l||s[15]!==h?(d=p.jsx(W.button,{type:"button",...c,...i,ref:e,disabled:l,onClick:h}),s[11]=e,s[12]=i,s[13]=c,s[14]=l,s[15]=h,s[16]=d):d=s[16],d});Qi.displayName="ActionBarPrimitive.FeedbackNegative";function Hf(t){var e;return((e=t.message.metadata.submittedFeedback)==null?void 0:e.type)==="negative"}const zf=t=>{const e=_(6);let s;e[0]!==t?(s=t===void 0?{}:t,e[0]=t,e[1]=s):s=e[1];const{filename:r,onExport:n}=s,i=F(),o=P(Kf);let a;e[2]!==i||e[3]!==r||e[4]!==n?(a=async()=>{const l=i.message().getCopyText();if(!l)return;if(n){await n(l);return}const u=new Blob([l],{type:"text/markdown"}),h=URL.createObjectURL(u),d=document.createElement("a");d.href=h,d.download=r??`message-${Date.now()}.md`,d.click(),URL.revokeObjectURL(h)},e[2]=i,e[3]=r,e[4]=n,e[5]=a):a=e[5];const c=a;return o?c:null},Yi=M.forwardRef((t,e)=>{const s=_(19);let r,n,i,o,a;s[0]!==t?({filename:n,onExport:o,onClick:i,disabled:r,...a}=t,s[0]=t,s[1]=r,s[2]=n,s[3]=i,s[4]=o,s[5]=a):(r=s[1],n=s[2],i=s[3],o=s[4],a=s[5]);let c;s[6]!==n||s[7]!==o?(c={filename:n,onExport:o},s[6]=n,s[7]=o,s[8]=c):c=s[8];const l=zf(c),u=r||!l;let h;s[9]!==l?(h=()=>{l==null||l()},s[9]=l,s[10]=h):h=s[10];let d;s[11]!==i||s[12]!==h?(d=K(i,h),s[11]=i,s[12]=h,s[13]=d):d=s[13];let f;return s[14]!==e||s[15]!==a||s[16]!==u||s[17]!==d?(f=p.jsx(W.button,{type:"button",...a,ref:e,disabled:u,onClick:d}),s[14]=e,s[15]=a,s[16]=u,s[17]=d,s[18]=f):f=s[18],f});Yi.displayName="ActionBarPrimitive.ExportMarkdown";function Gf(t){return t.type==="text"&&t.text.length>0}function Kf(t){var e;return(t.message.role!=="assistant"||((e=t.message.status)==null?void 0:e.type)!=="running")&&t.message.parts.some(Gf)}var jr=Dt({Copy:()=>zi,Edit:()=>Df,ExportMarkdown:()=>Yi,FeedbackNegative:()=>Qi,FeedbackPositive:()=>Wi,Reload:()=>kf,Root:()=>Vi,Speak:()=>Bf,StopSpeaking:()=>Ki});const Wf=t=>{const e=_(12);let s;return e[0]!==t.assistant||e[1]!==t.copied||e[2]!==t.hasAttachments||e[3]!==t.hasBranches||e[4]!==t.hasContent||e[5]!==t.last||e[6]!==t.lastOrHover||e[7]!==t.speaking||e[8]!==t.submittedFeedback||e[9]!==t.system||e[10]!==t.user?(s=r=>{var d;const{role:n,attachments:i,parts:o,branchCount:a,isLast:c,speech:l,isCopied:u,isHovering:h}=r.message;return!(t.hasBranches===!0&&a<2||t.user&&n!=="user"||t.assistant&&n!=="assistant"||t.system&&n!=="system"||t.lastOrHover===!0&&!h&&!c||t.last!==void 0&&t.last!==c||t.copied===!0&&!u||t.copied===!1&&u||t.speaking===!0&&l==null||t.speaking===!1&&l!=null||t.hasAttachments===!0&&(n!=="user"||!(i!=null&&i.length))||t.hasAttachments===!1&&n==="user"&&(i!=null&&i.length)||t.hasContent===!0&&o.length===0||t.hasContent===!1&&o.length>0||t.submittedFeedback!==void 0&&(((d=r.message.metadata.submittedFeedback)==null?void 0:d.type)??null)!==t.submittedFeedback)},e[0]=t.assistant,e[1]=t.copied,e[2]=t.hasAttachments,e[3]=t.hasBranches,e[4]=t.hasContent,e[5]=t.last,e[6]=t.lastOrHover,e[7]=t.speaking,e[8]=t.submittedFeedback,e[9]=t.system,e[10]=t.user,e[11]=s):s=e[11],P(s)},Ji=t=>{const e=_(3);let s,r;return e[0]!==t?({children:s,...r}=t,e[0]=t,e[1]=s,e[2]=r):(s=e[1],r=e[2]),Wf(r)?s:null};Ji.displayName="MessagePrimitive.If";const Xi=ae(null),Ns=()=>he(Xi),Qf=t=>{const e=_(8),{children:s}=t;let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r=new Map,e[0]=r):r=e[0];const n=V(r);let i;e[1]===Symbol.for("react.memo_cache_sentinel")?(i=[],e[1]=i):i=e[1];const o=V(i);let a;e[2]===Symbol.for("react.memo_cache_sentinel")?(a=()=>{const v=Array.from(n.current.entries());v.sort(Yf),o.current=v.map(Jf)},e[2]=a):a=e[2];const c=a;let l;e[3]===Symbol.for("react.memo_cache_sentinel")?(l=(v,x)=>{const S=(x==null?void 0:x.priority)??0;return n.current.set(v,S),c(),()=>{n.current.delete(v),c()}},e[3]=l):l=e[3];const u=l;let h;e[4]===Symbol.for("react.memo_cache_sentinel")?(h=()=>o.current,e[4]=h):h=e[4];const d=h;let f;e[5]===Symbol.for("react.memo_cache_sentinel")?(f={register:u,getPlugins:d},e[5]=f):f=e[5];const g=f;let b;return e[6]!==s?(b=p.jsx(Xi.Provider,{value:g,children:s}),e[6]=s,e[7]=b):b=e[7],b};function Yf(t,e){return e[1]-t[1]}function Jf(t){const[e]=t;return e}const Fs=ae(null),Zi=ae(null),Ls=()=>{const t=he(Fs);if(!t)throw new Error("useTriggerPopoverRootContext must be used within ComposerPrimitive.TriggerPopoverRoot");return t},Vs=()=>he(Fs),Xf=()=>{const t=he(Zi);if(!t)throw new Error("useTriggerPopoverAriaPublish must be used within ComposerPrimitive.TriggerPopoverRoot");return t},Zf=()=>{const t=Ls();return Ue(t.subscribe,t.getTriggers,t.getTriggers)},ep=new Map,eo=()=>()=>{},Br=()=>ep,tp=()=>{const t=Vs();return Ue(t?t.subscribe:eo,t?t.getTriggers:Br,t?t.getTriggers:Br)},Or=()=>null,sp=()=>{const t=Vs();return Ue(t?t.subscribeAria:eo,t?t.getActiveAria:Or,t?t.getActiveAria:Or)};function Nr(){const t=_(4);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=new Set,t[0]=e):e=t[0];const s=V(e);let r;t[1]===Symbol.for("react.memo_cache_sentinel")?(r=()=>{for(const c of s.current)c()},t[1]=r):r=t[1];const n=r;let i;t[2]===Symbol.for("react.memo_cache_sentinel")?(i=c=>(s.current.add(c),()=>{s.current.delete(c)}),t[2]=i):i=t[2];const o=i;let a;return t[3]===Symbol.for("react.memo_cache_sentinel")?(a={notify:n,subscribe:o},t[3]=a):a=t[3],a}const Fr=t=>{const e=_(21),{children:s}=t;let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r=new Map,e[0]=r):r=e[0];const n=V(r);let i;e[1]===Symbol.for("react.memo_cache_sentinel")?(i=new Set,e[1]=i):i=e[1];const o=V(i),{notify:a,subscribe:c}=Nr();let l;e[2]!==a?(l=A=>{const{char:B}=A;if(n.current.has(B))return rp;const O=new Map(n.current);O.set(B,A),n.current=O,a();for(const L of o.current)L.added(A);return()=>{const L=new Map(n.current);L.delete(B),n.current=L,a();for(const H of o.current)H.removed(B)}},e[2]=a,e[3]=l):l=e[3];const u=l;let h;e[4]===Symbol.for("react.memo_cache_sentinel")?(h=()=>n.current,e[4]=h):h=e[4];const d=h;let f;e[5]===Symbol.for("react.memo_cache_sentinel")?(f=A=>(o.current.add(A),()=>{o.current.delete(A)}),e[5]=f):f=e[5];const g=f,b=V(null),v=V(null),{notify:x,subscribe:S}=Nr();let T;e[6]!==x?(T=(A,B)=>{if(B===null){if(v.current!==A)return;b.current=null,v.current=null,x();return}const O=b.current;v.current===A&&O!==null&&O.popoverId===B.popoverId&&O.highlightedItemId===B.highlightedItemId||(b.current=B,v.current=A,x())},e[6]=x,e[7]=T):T=e[7];const y=T;let w;e[8]===Symbol.for("react.memo_cache_sentinel")?(w=()=>b.current,e[8]=w):w=e[8];const C=w;let I;e[9]!==u||e[10]!==c||e[11]!==S?(I={register:u,getTriggers:d,subscribe:c,subscribeLifecycle:g,getActiveAria:C,subscribeAria:S},e[9]=u,e[10]=c,e[11]=S,e[12]=I):I=e[12];const $=I;let D;e[13]!==y?(D={setActiveAria:y},e[13]=y,e[14]=D):D=e[14];const R=D;let E;e[15]!==R||e[16]!==s?(E=p.jsx(Zi.Provider,{value:R,children:s}),e[15]=R,e[16]=s,e[17]=E):E=e[17];let k;return e[18]!==E||e[19]!==$?(k=p.jsx(Fs.Provider,{value:$,children:E}),e[18]=E,e[19]=$,e[20]=k):k=e[20],k},to=t=>{const e=_(4),{children:s}=t;if(Ns()){let n;return e[0]!==s?(n=p.jsx(Fr,{children:s}),e[0]=s,e[1]=n):n=e[1],n}let r;return e[2]!==s?(r=p.jsx(Qf,{children:p.jsx(Fr,{children:s})}),e[2]=s,e[3]=r):r=e[3],r};to.displayName="ComposerPrimitive.TriggerPopoverRoot";function rp(){}const Lr=/\s/u;function np(t,e,s){const r=t.slice(0,s);for(let n=r.length-1;n>=0;n--){const i=r[n];if(Lr.test(i))return null;if(r.startsWith(e,n)){if(n>0&&!Lr.test(r[n-1]))continue;return{query:r.slice(n+e.length),offset:n}}}return null}const ip=t=>{const e=_(7),{text:s,triggerChar:r}=t,[n,i]=G(s.length),o=Math.min(n,s.length);let a;e[0]!==o||e[1]!==s||e[2]!==r?(a=np(s,r,o),e[0]=o,e[1]=s,e[2]=r,e[3]=a):a=e[3];const c=a,l=(c==null?void 0:c.query)??"";let u;return e[4]!==l||e[5]!==c?(u={trigger:c,query:l,setCursorPosition:i},e[4]=l,e[5]=c,e[6]=u):u=e[6],u},op=q(ip);function ap(t){return"type"in t}const cp=t=>{const e=_(25),{navigableList:s,isSearchMode:r,activeCategoryId:n,query:i,popoverId:o,open:a,selectItem:c,selectCategory:l,goBack:u,close:h}=t,[d,f]=G(0);let g;e[0]===Symbol.for("react.memo_cache_sentinel")?(g=()=>{f(0)},e[0]=g):g=e[0];let b;e[1]!==s?(b=[s],e[1]=s,e[2]=b):b=e[2],N(g,b);let v;e[3]===Symbol.for("react.memo_cache_sentinel")?(v=()=>{f(0)},e[3]=v):v=e[3];let x;e[4]!==n||e[5]!==r?(x=[r,n],e[4]=n,e[5]=r,e[6]=x):x=e[6],N(v,x);let S;e[7]!==d||e[8]!==s.length?(S=D=>{D<0||D>=s.length||D!==d&&f(D)},e[7]=d,e[8]=s.length,e[9]=S):S=e[9];const T=le(S);let y;e[10]!==n||e[11]!==h||e[12]!==u||e[13]!==d||e[14]!==s||e[15]!==a||e[16]!==i||e[17]!==l||e[18]!==c?(y=D=>{if(!a)return!1;switch(D.key){case"ArrowDown":return D.preventDefault(),f(R=>{const E=s.length;return E===0?0:R<E-1?R+1:0}),!0;case"ArrowUp":return D.preventDefault(),f(R=>{const E=s.length;return E===0?0:R>0?R-1:E-1}),!0;case"Enter":case"Tab":{if(D.shiftKey)return!1;D.preventDefault();const R=s[d];return R&&(ap(R)?c(R):l(R.id)),!0}case"Escape":return D.preventDefault(),h(),!0;case"Backspace":return n&&i===""?(D.preventDefault(),u(),!0):!1;default:return!1}},e[10]=n,e[11]=h,e[12]=u,e[13]=d,e[14]=s,e[15]=a,e[16]=i,e[17]=l,e[18]=c,e[19]=y):y=e[19];const w=le(y),C=s[d],I=a&&C?`${o}-option-${C.id}`:void 0;let $;return e[20]!==w||e[21]!==T||e[22]!==d||e[23]!==I?($={highlightedIndex:d,highlightedItemId:I,highlightIndex:T,handleKeyDown:w},e[20]=w,e[21]=T,e[22]=d,e[23]=I,e[24]=$):$=e[24],$},lp=q(cp);function Vr(t,e){var s;return t.id.toLowerCase().includes(e)||t.label.toLowerCase().includes(e)||(((s=t.description)==null?void 0:s.toLowerCase().includes(e))??!1)}const up=t=>{const e=_(38),{adapter:s,query:r,open:n}=t,[i,o]=G(null);let a,c;e[0]!==n?(a=()=>{n||o(null)},c=[n],e[0]=n,e[1]=a,e[2]=c):(a=e[1],c=e[2]),N(a,c);let l;e:{if(!n||!s){let A;e[3]===Symbol.for("react.memo_cache_sentinel")?(A=[],e[3]=A):A=e[3],l=A;break e}let k;e[4]!==s?(k=s.categories(),e[4]=s,e[5]=k):k=e[5],l=k}const u=l,h=n?i:null;let d;e:{if(!h||!s){let A;e[6]===Symbol.for("react.memo_cache_sentinel")?(A=[],e[6]=A):A=e[6],d=A;break e}let k;e[7]!==s||e[8]!==h?(k=s.categoryItems(h),e[7]=s,e[8]=h,e[9]=k):k=e[9],d=k}const f=d;let g;e:{if(!n||!s||h){g=null;break e}if(!r&&u.length>0){g=null;break e}if(s.search){let A;e[10]!==s||e[11]!==r?(A=s.search(r),e[10]=s,e[11]=r,e[12]=A):A=e[12],g=A;break e}let k;if(e[13]!==s||e[14]!==u||e[15]!==r){k=[];const A=r.toLowerCase();for(const B of u)for(const O of s.categoryItems(B.id))Vr(O,A)&&k.push(O);e[13]=s,e[14]=u,e[15]=r,e[16]=k}else k=e[16];g=k}const b=g,v=b!==null;let x;e:{if(v){let A;e[17]===Symbol.for("react.memo_cache_sentinel")?(A=[],e[17]=A):A=e[17],x=A;break e}if(!r){x=u;break e}let k;if(e[18]!==u||e[19]!==r){const A=r.toLowerCase();k=u.filter(B=>B.label.toLowerCase().includes(A)),e[18]=u,e[19]=r,e[20]=k}else k=e[20];x=k}const S=x;let T;e:{if(v){let A;e[21]!==b?(A=b??[],e[21]=b,e[22]=A):A=e[22],T=A;break e}if(!r){T=f;break e}let k;if(e[23]!==f||e[24]!==r){const A=r.toLowerCase();k=f.filter(B=>Vr(B,A)),e[23]=f,e[24]=r,e[25]=k}else k=e[25];T=k}const y=T;let w;e:{if(v){let k;e[26]!==b?(k=b??[],e[26]=b,e[27]=k):k=e[27],w=k;break e}if(h){w=y;break e}w=S}const C=w;let I;e[28]===Symbol.for("react.memo_cache_sentinel")?(I=k=>{o(k)},e[28]=I):I=e[28];const $=le(I);let D;e[29]===Symbol.for("react.memo_cache_sentinel")?(D=()=>{o(null)},e[29]=D):D=e[29];const R=le(D);let E;return e[30]!==h||e[31]!==S||e[32]!==y||e[33]!==R||e[34]!==v||e[35]!==C||e[36]!==$?(E={categories:S,items:y,isSearchMode:v,activeCategoryId:h,navigableList:C,selectCategory:$,goBack:R},e[30]=h,e[31]=S,e[32]=y,e[33]=R,e[34]=v,e[35]=C,e[36]=$,e[37]=E):E=e[37],E},dp=q(up),hp=t=>{const e=_(15),{behavior:s,trigger:r,aui:n,triggerChar:i,setCursorPosition:o,onSelected:a}=t,c=V(null);let l;e[0]===Symbol.for("react.memo_cache_sentinel")?(l=v=>(c.current=v,()=>{c.current===v&&(c.current=null)}),e[0]=l):l=e[0];const u=le(l);let h;e[1]!==n||e[2]!==s||e[3]!==a||e[4]!==r||e[5]!==i?(h=v=>{var w,C;if(!r||!s)return;if((w=c.current)!=null&&w.call(c,v)){a();return}const x=n.composer().getState().text,S=x.slice(0,r.offset),T=x.slice(r.offset+i.length+r.query.length),y=()=>{const I=s.formatter.serialize(v);n.composer().setText(S+I+(T.startsWith(" ")?T:` ${T}`))};s.kind==="directive"?(y(),(C=s.onInserted)==null||C.call(s,v)):(s.removeOnExecute?n.composer().setText(S+(T.startsWith(" ")?T.slice(1):T)):y(),s.onExecute(v)),a()},e[1]=n,e[2]=s,e[3]=a,e[4]=r,e[5]=i,e[6]=h):h=e[6];const d=le(h);let f;e[7]!==a||e[8]!==o||e[9]!==r?(f=()=>{a(),r&&o(r.offset)},e[7]=a,e[8]=o,e[9]=r,e[10]=f):f=e[10];const g=le(f);let b;return e[11]!==g||e[12]!==u||e[13]!==d?(b={selectItem:d,close:g,registerSelectItemOverride:u},e[11]=g,e[12]=u,e[13]=d,e[14]=b):b=e[14],b},fp=q(hp),pp=t=>{const e=_(46),{adapter:s,text:r,triggerChar:n,behavior:i,aui:o,popoverId:a,isLoading:c}=t;let l;e[0]!==r||e[1]!==n?(l=op({text:r,triggerChar:n}),e[0]=r,e[1]=n,e[2]=l):l=e[2];const u=se(l),h=u.trigger!==null&&s!==void 0&&i!==void 0;let d;e[3]!==s||e[4]!==u.query||e[5]!==h?(d=dp({adapter:s,query:u.query,open:h}),e[3]=s,e[4]=u.query,e[5]=h,e[6]=d):d=e[6];const f=se(d);let g;e[7]!==f?(g=()=>{f.goBack()},e[7]=f,e[8]=g):g=e[8];const b=le(g);let v;e[9]!==o||e[10]!==i||e[11]!==u.setCursorPosition||e[12]!==u.trigger||e[13]!==b||e[14]!==n?(v=fp({behavior:i,trigger:u.trigger,aui:o,triggerChar:n,setCursorPosition:u.setCursorPosition,onSelected:b}),e[9]=o,e[10]=i,e[11]=u.setCursorPosition,e[12]=u.trigger,e[13]=b,e[14]=n,e[15]=v):v=e[15];const x=se(v);let S;e[16]!==u.query||e[17]!==f.activeCategoryId||e[18]!==f.goBack||e[19]!==f.isSearchMode||e[20]!==f.navigableList||e[21]!==f.selectCategory||e[22]!==h||e[23]!==a||e[24]!==x.close||e[25]!==x.selectItem?(S=lp({navigableList:f.navigableList,isSearchMode:f.isSearchMode,activeCategoryId:f.activeCategoryId,query:u.query,popoverId:a,open:h,selectItem:x.selectItem,selectCategory:f.selectCategory,goBack:f.goBack,close:x.close}),e[16]=u.query,e[17]=f.activeCategoryId,e[18]=f.goBack,e[19]=f.isSearchMode,e[20]=f.navigableList,e[21]=f.selectCategory,e[22]=h,e[23]=a,e[24]=x.close,e[25]=x.selectItem,e[26]=S):S=e[26];const T=se(S);let y;return e[27]!==u.query||e[28]!==u.setCursorPosition||e[29]!==c||e[30]!==T.handleKeyDown||e[31]!==T.highlightIndex||e[32]!==T.highlightedIndex||e[33]!==T.highlightedItemId||e[34]!==f.activeCategoryId||e[35]!==f.categories||e[36]!==f.goBack||e[37]!==f.isSearchMode||e[38]!==f.items||e[39]!==f.selectCategory||e[40]!==h||e[41]!==a||e[42]!==x.close||e[43]!==x.registerSelectItemOverride||e[44]!==x.selectItem?(y={open:h,query:u.query,activeCategoryId:f.activeCategoryId,categories:f.categories,items:f.items,highlightedIndex:T.highlightedIndex,isSearchMode:f.isSearchMode,isLoading:c,popoverId:a,highlightedItemId:T.highlightedItemId,selectCategory:f.selectCategory,goBack:f.goBack,selectItem:x.selectItem,close:x.close,highlightIndex:T.highlightIndex,handleKeyDown:T.handleKeyDown,setCursorPosition:u.setCursorPosition,registerSelectItemOverride:x.registerSelectItemOverride},e[27]=u.query,e[28]=u.setCursorPosition,e[29]=c,e[30]=T.handleKeyDown,e[31]=T.highlightIndex,e[32]=T.highlightedIndex,e[33]=T.highlightedItemId,e[34]=f.activeCategoryId,e[35]=f.categories,e[36]=f.goBack,e[37]=f.isSearchMode,e[38]=f.items,e[39]=f.selectCategory,e[40]=h,e[41]=a,e[42]=x.close,e[43]=x.registerSelectItemOverride,e[44]=x.selectItem,e[45]=y):y=e[45],y},gp=q(pp),Us=ae(null),Ke=()=>{const t=he(Us);if(!t)throw new Error("useTriggerPopoverScopeContext must be used within ComposerPrimitive.TriggerPopover");return t},mp=()=>he(Us),so=ae(null),ro=()=>{const t=he(so);if(!t)throw new Error("TriggerPopover.Directive / TriggerPopover.Action must be rendered inside ComposerPrimitive.TriggerPopover");return t},no=M.forwardRef((t,e)=>{const s=_(61);let r,n,i,o,a,c;s[0]!==t?({char:i,adapter:r,isLoading:c,"aria-label":n,children:o,...a}=t,s[0]=t,s[1]=r,s[2]=n,s[3]=i,s[4]=o,s[5]=a,s[6]=c):(r=s[1],n=s[2],i=s[3],o=s[4],a=s[5],c=s[6]);const l=c===void 0?!1:c,u=F(),h=P(bp),d=M.useId(),f=V(null),[g,b]=G(null),v=V(0);let x;s[7]!==i?(x=jt=>(v.current=v.current+1,f.current=jt,b(jt),()=>{v.current=Math.max(0,v.current-1),f.current===jt&&(f.current=null,b(null))}),s[7]=i,s[8]=x):x=s[8];const S=x;let T;s[9]!==S?(T={register:S},s[9]=S,s[10]=T):T=s[10];const y=T,w=g??void 0;let C;s[11]!==r||s[12]!==u||s[13]!==i||s[14]!==l||s[15]!==d||s[16]!==w||s[17]!==h?(C=gp({adapter:r,text:h,triggerChar:i,behavior:w,aui:u,popoverId:d,isLoading:l}),s[11]=r,s[12]=u,s[13]=i,s[14]=l,s[15]=d,s[16]=w,s[17]=h,s[18]=C):C=s[18];const I=se(C);let $;s[19]!==I?($=()=>I,s[19]=I,s[20]=$):$=s[20];const D=le($),R=Ls();let E;s[21]!==g||s[22]!==i||s[23]!==D||s[24]!==R?(E=()=>R.register({char:i,...g?{behavior:g}:{},resource:D()}),s[21]=g,s[22]=i,s[23]=D,s[24]=R,s[25]=E):E=s[25];let k;s[26]!==g||s[27]!==i||s[28]!==R?(k=[R,i,g],s[26]=g,s[27]=i,s[28]=R,s[29]=k):k=s[29],N(E,k);const A=Ns();let B;s[30]!==D||s[31]!==A?(B=()=>{if(A)return A.register(D())},s[30]=D,s[31]=A,s[32]=B):B=s[32];let O;s[33]!==A?(O=[A],s[33]=A,s[34]=O):O=s[34],N(B,O);const L=g!==null&&I.open,H=Xf();let j,U;s[35]!==H||s[36]!==i||s[37]!==L?(j=()=>{if(L)return()=>{H.setActiveAria(i,null)}},U=[H,i,L],s[35]=H,s[36]=i,s[37]=L,s[38]=j,s[39]=U):(j=s[38],U=s[39]),N(j,U);let z,Q;s[40]!==H||s[41]!==i||s[42]!==L||s[43]!==d||s[44]!==I.highlightedItemId?(z=()=>{L&&H.setActiveAria(i,{popoverId:d,highlightedItemId:I.highlightedItemId})},Q=[H,i,d,L,I.highlightedItemId],s[40]=H,s[41]=i,s[42]=L,s[43]=d,s[44]=I.highlightedItemId,s[45]=z,s[46]=Q):(z=s[45],Q=s[46]),N(z,Q);let ee;s[47]!==n||s[48]!==o||s[49]!==e||s[50]!==L||s[51]!==d||s[52]!==a||s[53]!==I.highlightedItemId?(ee=L?p.jsx(W.div,{role:"listbox",id:d,"aria-label":n??"Suggestions","aria-activedescendant":I.highlightedItemId,"data-state":"open",...a,ref:e,children:o}):o,s[47]=n,s[48]=o,s[49]=e,s[50]=L,s[51]=d,s[52]=a,s[53]=I.highlightedItemId,s[54]=ee):ee=s[54];let pe;s[55]!==I||s[56]!==ee?(pe=p.jsx(Us.Provider,{value:I,children:ee}),s[55]=I,s[56]=ee,s[57]=pe):pe=s[57];let rt;return s[58]!==y||s[59]!==pe?(rt=p.jsx(so.Provider,{value:y,children:pe}),s[58]=y,s[59]=pe,s[60]=rt):rt=s[60],rt});no.displayName="ComposerPrimitive.TriggerPopover";function bp(t){return t.composer.text}const io=()=>{const t=_(2),{disabled:e,send:s}=vh();let r;t[0]!==s?(r=()=>s(),t[0]=s,t[1]=r):r=t[1];const n=r;return e?null:n},_p=be("ComposerPrimitive.Send",io),oo=M.forwardRef((t,e)=>{const s=_(12);let r,n;s[0]!==t?({onSubmit:r,...n}=t,s[0]=t,s[1]=r,s[2]=n):(r=s[1],n=s[2]);const i=io();let o;s[3]!==i?(o=u=>{u.preventDefault(),i&&i()},s[3]=i,s[4]=o):o=s[4];const a=o;let c;s[5]!==a||s[6]!==r?(c=K(r,a),s[5]=a,s[6]=r,s[7]=c):c=s[7];let l;return s[8]!==e||s[9]!==n||s[10]!==c?(l=p.jsx(W.form,{...n,ref:e,onSubmit:c}),s[8]=e,s[9]=n,s[10]=c,s[11]=l):l=s[11],l});oo.displayName="ComposerPrimitive.Root";const ao=t=>{const e=_(4),s=st(t),r=ke(yp);let n,i;e[0]!==s||e[1]!==r?(n=()=>r(s),i=[r,s],e[0]=s,e[1]=r,e[2]=n,e[3]=i):(n=e[2],i=e[3]),N(n,i)};function yp(t){return t.onScrollToBottom}const vp=()=>!1,Sp=()=>{},co=t=>{const e=_(4);let s;e[0]!==t?(s=i=>{if(typeof window>"u"||t===null||!window.matchMedia)return Sp;const o=window.matchMedia(t);return o.addEventListener("change",i),()=>o.removeEventListener("change",i)},e[0]=t,e[1]=s):s=e[1];const r=s;let n;return e[2]!==t?(n=()=>typeof window>"u"||t===null||!window.matchMedia?!1:window.matchMedia(t).matches,e[2]=t,e[3]=n):n=e[3],Ue(r,n,vp)};function xp(){return P(wp)}function wp(t){return t.composer.isEditing?t.composer.text:""}function Tp(t){return!!P(Cp)||!!t}function Cp(t){var e;return t.thread.isDisabled||((e=t.composer.dictation)==null?void 0:e.inputDisabled)}function Ip(){const t=_(4),e=sp();if(!e){let r;return t[0]===Symbol.for("react.memo_cache_sentinel")?(r={},t[0]=r):r=t[0],r}let s;return t[1]!==e.highlightedItemId||t[2]!==e.popoverId?(s={"aria-controls":e.popoverId,"aria-expanded":!0,"aria-haspopup":"listbox","aria-activedescendant":e.highlightedItemId},t[1]=e.highlightedItemId,t[2]=e.popoverId,t[3]=s):s=t[3],s}function Ep(t,e){if(t==null)return{};var s={};for(var r in t)if({}.hasOwnProperty.call(t,r)){if(e.indexOf(r)!==-1)continue;s[r]=t[r]}return s}var Rp=M.useLayoutEffect,Ap=function(e){var s=J.useRef(e);return Rp(function(){s.current=e}),s},Ur=function(e,s){if(typeof e=="function"){e(s);return}e.current=s},Mp=function(e,s){var r=J.useRef();return J.useCallback(function(n){e.current=n,r.current&&Ur(r.current,null),r.current=s,s&&Ur(s,n)},[s])},qr={"min-height":"0","max-height":"none",height:"0",visibility:"hidden",overflow:"hidden",position:"absolute","z-index":"-1000",top:"0",right:"0",display:"block"},Pp=function(e){Object.keys(qr).forEach(function(s){e.style.setProperty(s,qr[s],"important")})},Hr=Pp,te=null,zr=function(e,s){var r=e.scrollHeight;return s.sizingStyle.boxSizing==="border-box"?r+s.borderSize:r-s.paddingSize};function kp(t,e,s,r){s===void 0&&(s=1),r===void 0&&(r=1/0),te||(te=document.createElement("textarea"),te.setAttribute("tabindex","-1"),te.setAttribute("aria-hidden","true"),Hr(te)),te.parentNode===null&&document.body.appendChild(te);var n=t.paddingSize,i=t.borderSize,o=t.sizingStyle,a=o.boxSizing;Object.keys(o).forEach(function(d){var f=d;te.style[f]=o[f]}),Hr(te),te.value=e;var c=zr(te,t);te.value=e,c=zr(te,t),te.value="x";var l=te.scrollHeight-n,u=l*s;a==="border-box"&&(u=u+n+i),c=Math.max(u,c);var h=l*r;return a==="border-box"&&(h=h+n+i),c=Math.min(h,c),[c,l]}var Gr=function(){},$p=function(e,s){return e.reduce(function(r,n){return r[n]=s[n],r},{})},Dp=["borderBottomWidth","borderLeftWidth","borderRightWidth","borderTopWidth","boxSizing","fontFamily","fontSize","fontStyle","fontWeight","letterSpacing","lineHeight","paddingBottom","paddingLeft","paddingRight","paddingTop","tabSize","textIndent","textRendering","textTransform","width","wordBreak","wordSpacing","scrollbarGutter"],jp=!!document.documentElement.currentStyle,Bp=function(e){var s=window.getComputedStyle(e);if(s===null)return null;var r=$p(Dp,s),n=r.boxSizing;if(n==="")return null;jp&&n==="border-box"&&(r.width=parseFloat(r.width)+parseFloat(r.borderRightWidth)+parseFloat(r.borderLeftWidth)+parseFloat(r.paddingRight)+parseFloat(r.paddingLeft)+"px");var i=parseFloat(r.paddingBottom)+parseFloat(r.paddingTop),o=parseFloat(r.borderBottomWidth)+parseFloat(r.borderTopWidth);return{sizingStyle:r,paddingSize:i,borderSize:o}},Op=Bp;function qs(t,e,s){var r=Ap(s);M.useLayoutEffect(function(){var n=function(o){return r.current(o)};if(t)return t.addEventListener(e,n),function(){return t.removeEventListener(e,n)}},[])}var Np=function(e,s){qs(document.body,"reset",function(r){e.current.form===r.target&&s(r)})},Fp=function(e){qs(window,"resize",e)},Lp=function(e){qs(document.fonts,"loadingdone",e)},Vp=["cacheMeasurements","maxRows","minRows","onChange","onHeightChange"],Up=function(e,s){var r=e.cacheMeasurements,n=e.maxRows,i=e.minRows,o=e.onChange,a=o===void 0?Gr:o,c=e.onHeightChange,l=c===void 0?Gr:c,u=Ep(e,Vp),h=u.value!==void 0,d=M.useRef(null),f=Mp(d,s),g=M.useRef(0),b=M.useRef(),v=function(){var T=d.current,y=r&&b.current?b.current:Op(T);if(y){b.current=y;var w=kp(y,T.value||T.placeholder||"x",i,n),C=w[0],I=w[1];g.current!==C&&(g.current=C,T.style.setProperty("height",C+"px","important"),l(C,{rowHeight:I}))}},x=function(T){h||v(),a(T)};return M.useLayoutEffect(v),Np(d,function(){if(!h){var S=d.current.value;requestAnimationFrame(function(){var T=d.current;T&&S!==T.value&&v()})}}),Fp(v),Lp(v),M.createElement("textarea",Gt({},u,{onChange:x,ref:f}))},qp=M.forwardRef(Up);const Hp="(pointer: coarse) and (not (any-pointer: fine))",lo=M.forwardRef(({autoFocus:t=!1,asChild:e,render:s,disabled:r,onChange:n,onKeyDown:i,onPaste:o,onSelect:a,submitOnEnter:c,submitMode:l,cancelOnEscape:u=!0,unstable_focusOnRunStart:h=!0,unstable_focusOnScrollToBottom:d=!0,unstable_focusOnThreadSwitched:f=!0,unstable_insertNewlineOnTouchEnter:g=!1,addAttachmentOnPaste:b=!0,...v},x)=>{const S=F(),T=Ns(),y=l??(c===!1?"none":"enter"),w=co(g?Hp:null),C=g&&w&&y==="enter"?"none":y,I=xp(),$=Tp(r),D=V(null),R=we(x,D),E=V(!1);Os(j=>{var z;if(!((z=D.current)!=null&&z.contains(j.target)))return;if(T){for(const Q of T.getPlugins())if(Q.handleKeyDown(j))return}if(!u)return;const U=S.composer();U.getState().canCancel&&(U.cancel(),j.preventDefault())});const k=j=>{var U,z;if(!$&&!j.nativeEvent.isComposing){if(T){for(const Q of T.getPlugins())if(Q.handleKeyDown(j))return}if(j.key==="Enter"){const Q=S.thread().getState(),ee=Q.capabilities.queue;if(j.shiftKey&&(j.ctrlKey||j.metaKey)&&ee&&y!=="none"&&S.composer().getState().canSend){j.preventDefault(),S.composer().send({steer:!0});return}if(j.shiftKey||Q.isRunning&&!ee)return;let pe=!1;C==="ctrlEnter"?pe=j.ctrlKey||j.metaKey:C==="enter"&&(pe=!0),pe&&(j.preventDefault(),(z=(U=D.current)==null?void 0:U.closest("form"))==null||z.requestSubmit())}}},A=async j=>{var Q;if(!b)return;const U=S.thread().getState().capabilities,z=Array.from(((Q=j.clipboardData)==null?void 0:Q.files)||[]);if(U.attachments&&z.length>0)try{j.preventDefault(),await Promise.all(z.map(ee=>S.composer().addAttachment(ee)))}catch(ee){console.error("Error adding attachment:",ee)}},B=t&&!$,O=Qe(()=>{const j=D.current;!j||!B||(j.focus({preventScroll:!0}),j.setSelectionRange(j.value.length,j.value.length))},[B]);N(()=>O(),[O]),ao(()=>{S.composer().getState().type==="thread"&&d&&O()}),N(()=>{if(!(S.composer().getState().type!=="thread"||!h))return S.on("thread.runStart",O)},[h,O,S]),N(()=>{if(!(S.composer().getState().type!=="thread"||!f))return S.on("threadListItem.switchedTo",O)},[f,O,S]);const L=Ip(),H={name:"input",value:I,...v,...L,ref:R,disabled:$,onChange:K(n,j=>{if(!S.composer().getState().isEditing)return;const U=j.nativeEvent.isComposing===!0;E.current&&!U&&(E.current=!1);const z=U||E.current;if(Qs(()=>{S.composer().setText(j.target.value)}),z)return;const Q=j.target.selectionStart??j.target.value.length;if(T)for(const ee of T.getPlugins())ee.setCursorPosition(Q)}),onKeyDown:K(i,k),onCompositionStart:K(v.onCompositionStart,()=>{E.current=!0}),onCompositionEnd:K(v.onCompositionEnd,j=>{if(E.current=!1,!S.composer().getState().isEditing)return;const U=j.target;Qs(()=>{S.composer().setText(U.value)});const z=U.selectionStart??U.value.length;if(T)for(const Q of T.getPlugins())Q.setCursorPosition(z)}),onSelect:K(a,j=>{if(E.current)return;const U=j.target,z=U.selectionStart??U.value.length;if(T)for(const Q of T.getPlugins())Q.setCursorPosition(z)}),onPaste:K(o,A)};if(s&&M.isValidElement(s)){const j=v.children!==void 0?v.children:s.props.children;return p.jsx(Ct,{...H,children:M.cloneElement(s,void 0,j)})}return p.jsx(e?Ct:qp,{...H})});lo.displayName="ComposerPrimitive.Input";const zp=()=>{const{disabled:t,cancel:e}=xh();return t?null:e},Gp=be("ComposerPrimitive.Cancel",zp),Kp=t=>{const e=_(6);let s;e[0]!==t?(s=t===void 0?{}:t,e[0]=t,e[1]=s):s=e[1];const{multiple:r}=s,n=r===void 0?!0:r,{disabled:i,addAttachment:o}=Ih(),a=F();let c;e[2]!==o||e[3]!==a||e[4]!==n?(c=()=>{const u=document.createElement("input");u.type="file",u.multiple=n,u.hidden=!0;const h=a.composer().getState().attachmentAccept;h!=="*"&&(u.accept=h),document.body.appendChild(u),u.onchange=d=>{const f=d.target.files;if(f){for(const g of f)o(g);document.body.removeChild(u)}},u.oncancel=()=>{(!u.files||u.files.length===0)&&document.body.removeChild(u)},u.click()},e[2]=o,e[3]=a,e[4]=n,e[5]=c):c=e[5];const l=c;return i?null:l},Wp=be("ComposerPrimitive.AddAttachment",Kp,["multiple"]),uo=M.forwardRef((t,e)=>{const s=_(30),{disabled:r,asChild:n,render:i,children:o,...a}=t,c=n===void 0?!1:n,[l,u]=G(!1),h=F();let d;s[0]!==r?(d=A=>{r||(A.preventDefault(),u(!0))},s[0]=r,s[1]=d):d=s[1];const f=d;let g;s[2]!==r||s[3]!==l?(g=A=>{r||(A.preventDefault(),l||u(!0))},s[2]=r,s[3]=l,s[4]=g):g=s[4];const b=g;let v;s[5]!==r?(v=A=>{if(r)return;A.preventDefault();const B=A.relatedTarget;B&&A.currentTarget.contains(B)||u(!1)},s[5]=r,s[6]=v):v=s[6];const x=v;let S;s[7]!==h||s[8]!==r?(S=async A=>{if(r)return;A.preventDefault(),u(!1);const B=Array.from(A.dataTransfer.files);await Promise.all(B.map(async O=>{try{await h.composer().addAttachment(O)}catch(L){console.error("Failed to add attachment:",L)}}))},s[7]=h,s[8]=r,s[9]=S):S=s[9];const T=S;let y;s[10]!==l?(y=l?{"data-dragging":"true"}:null,s[10]=l,s[11]=y):y=s[11];const w=K(a.onDragEnterCapture,f),C=K(a.onDragOverCapture,b),I=K(a.onDragLeaveCapture,x),$=K(a.onDropCapture,T);let D;s[12]!==e||s[13]!==a||s[14]!==$||s[15]!==y||s[16]!==w||s[17]!==C||s[18]!==I?(D={...y,...a,onDragEnterCapture:w,onDragOverCapture:C,onDragLeaveCapture:I,onDropCapture:$,ref:e},s[12]=e,s[13]=a,s[14]=$,s[15]=y,s[16]=w,s[17]=C,s[18]=I,s[19]=D):D=s[19];const R=D;if(i&&M.isValidElement(i)){const A=o!==void 0?o:i.props.children;let B;s[20]!==i||s[21]!==A?(B=M.cloneElement(i,void 0,A),s[20]=i,s[21]=A,s[22]=B):B=s[22];let O;return s[23]!==R||s[24]!==B?(O=p.jsx(Ct,{...R,children:B}),s[23]=R,s[24]=B,s[25]=O):O=s[25],O}const E=c?Ct:"div";let k;return s[26]!==E||s[27]!==o||s[28]!==R?(k=p.jsx(E,{...R,children:o}),s[26]=E,s[27]=o,s[28]=R,s[29]=k):k=s[29],k});uo.displayName="ComposerPrimitive.AttachmentDropzone";const Qp=()=>{const{disabled:t,startDictation:e}=Th();return t?null:e},Yp=be("ComposerPrimitive.Dictate",Qp),Jp=()=>{const t=_(2),e=F(),s=P(Zp);let r;t[0]!==e?(r=()=>{e.composer().stopDictation()},t[0]=e,t[1]=r):r=t[1];const n=r;return s?n:null},Xp=be("ComposerPrimitive.StopDictation",Jp);function Zp(t){return t.composer.dictation!=null}const ho=M.forwardRef((t,e)=>{const s=_(7);let r,n;s[0]!==t?({children:r,...n}=t,s[0]=t,s[1]=r,s[2]=n):(r=s[1],n=s[2]);const i=P(eg);if(!i)return null;const o=r??i;let a;return s[3]!==e||s[4]!==n||s[5]!==o?(a=p.jsx(W.span,{...n,ref:e,children:o}),s[3]=e,s[4]=n,s[5]=o,s[6]=a):a=s[6],a});ho.displayName="ComposerPrimitive.DictationTranscript";function eg(t){var e;return(e=t.composer.dictation)==null?void 0:e.transcript}const fo=M.forwardRef((t,e)=>{const s=_(3);if(!P(tg))return null;let r;return s[0]!==e||s[1]!==t?(r=p.jsx(W.div,{...t,ref:e}),s[0]=e,s[1]=t,s[2]=r):r=s[2],r});fo.displayName="ComposerPrimitive.Quote";const po=M.forwardRef((t,e)=>{const s=_(7);let r,n;s[0]!==t?({children:r,...n}=t,s[0]=t,s[1]=r,s[2]=n):(r=s[1],n=s[2]);const i=P(sg);if(!i)return null;const o=r??i;let a;return s[3]!==e||s[4]!==n||s[5]!==o?(a=p.jsx(W.span,{...n,ref:e,children:o}),s[3]=e,s[4]=n,s[5]=o,s[6]=a):a=s[6],a});po.displayName="ComposerPrimitive.QuoteText";const go=M.forwardRef((t,e)=>{const s=_(12);let r,n;s[0]!==t?({onClick:r,...n}=t,s[0]=t,s[1]=r,s[2]=n):(r=s[1],n=s[2]);const i=F();let o;s[3]!==i?(o=()=>{i.composer().setQuote(void 0)},s[3]=i,s[4]=o):o=s[4];const a=o;let c;s[5]!==a||s[6]!==r?(c=K(r,a),s[5]=a,s[6]=r,s[7]=c):c=s[7];let l;return s[8]!==e||s[9]!==n||s[10]!==c?(l=p.jsx(W.button,{type:"button",...n,ref:e,onClick:c}),s[8]=e,s[9]=n,s[10]=c,s[11]=l):l=s[11],l});go.displayName="ComposerPrimitive.QuoteDismiss";function tg(t){return t.composer.quote}function sg(t){var e;return(e=t.composer.quote)==null?void 0:e.text}const mo=M.forwardRef((t,e)=>{const s=_(12);let r,n,i;s[0]!==t?({children:n,"aria-label":r,...i}=t,s[0]=t,s[1]=r,s[2]=n,s[3]=i):(r=s[1],n=s[2],i=s[3]);const{categories:o,activeCategoryId:a,isSearchMode:c,open:l}=Ke();if(!l||a||c)return null;const u=r??"Categories";let h;s[4]!==o||s[5]!==n?(h=n(o),s[4]=o,s[5]=n,s[6]=h):h=s[6];let d;return s[7]!==e||s[8]!==i||s[9]!==u||s[10]!==h?(d=p.jsx(W.div,{role:"group","aria-label":u,...i,ref:e,children:h}),s[7]=e,s[8]=i,s[9]=u,s[10]=h,s[11]=d):d=s[11],d});mo.displayName="ComposerPrimitive.TriggerPopoverCategories";const bo=M.forwardRef((t,e)=>{const s=_(30);let r,n,i,o;s[0]!==t?({categoryId:r,onClick:n,onMouseMove:i,...o}=t,s[0]=t,s[1]=r,s[2]=n,s[3]=i,s[4]=o):(r=s[1],n=s[2],i=s[3],o=s[4]);const{selectCategory:a,highlightIndex:c,categories:l,highlightedIndex:u,activeCategoryId:h,isSearchMode:d,popoverId:f}=Ke();let g;s[5]!==r||s[6]!==a?(g=()=>{a(r)},s[5]=r,s[6]=a,s[7]=g):g=s[7];const b=g;let v;if(s[8]!==l||s[9]!==r){let R;s[11]!==r?(R=E=>E.id===r,s[11]=r,s[12]=R):R=s[12],v=l.findIndex(R),s[8]=l,s[9]=r,s[10]=v}else v=s[10];const x=v,S=!h&&!d&&x===u;let T;s[13]!==x||s[14]!==c?(T=()=>{c(x)},s[13]=x,s[14]=c,s[15]=T):T=s[15];const y=T,w=`${f}-option-${r}`,C=S?"":void 0;let I;s[16]!==b||s[17]!==n?(I=K(n,b),s[16]=b,s[17]=n,s[18]=I):I=s[18];let $;s[19]!==y||s[20]!==i?($=K(i,y),s[19]=y,s[20]=i,s[21]=$):$=s[21];let D;return s[22]!==e||s[23]!==S||s[24]!==o||s[25]!==w||s[26]!==C||s[27]!==I||s[28]!==$?(D=p.jsx(W.button,{type:"button",role:"option",id:w,"aria-selected":S,"data-highlighted":C,...o,ref:e,onClick:I,onMouseMove:$}),s[22]=e,s[23]=S,s[24]=o,s[25]=w,s[26]=C,s[27]=I,s[28]=$,s[29]=D):D=s[29],D});bo.displayName="ComposerPrimitive.TriggerPopoverCategoryItem";const _o=M.forwardRef((t,e)=>{const s=_(12);let r,n,i;s[0]!==t?({children:n,"aria-label":r,...i}=t,s[0]=t,s[1]=r,s[2]=n,s[3]=i):(r=s[1],n=s[2],i=s[3]);const{items:o,activeCategoryId:a,isSearchMode:c,open:l}=Ke();if(!l||!a&&!c)return null;const u=r??"Items";let h;s[4]!==n||s[5]!==o?(h=n(o),s[4]=n,s[5]=o,s[6]=h):h=s[6];let d;return s[7]!==e||s[8]!==i||s[9]!==u||s[10]!==h?(d=p.jsx(W.div,{role:"group","aria-label":u,...i,ref:e,children:h}),s[7]=e,s[8]=i,s[9]=u,s[10]=h,s[11]=d):d=s[11],d});_o.displayName="ComposerPrimitive.TriggerPopoverItems";const yo=M.forwardRef((t,e)=>{const s=_(30);let r,n,i,o,a;s[0]!==t?({item:n,index:r,onClick:i,onMouseMove:o,...a}=t,s[0]=t,s[1]=r,s[2]=n,s[3]=i,s[4]=o,s[5]=a):(r=s[1],n=s[2],i=s[3],o=s[4],a=s[5]);const{selectItem:c,highlightIndex:l,items:u,highlightedIndex:h,activeCategoryId:d,isSearchMode:f,popoverId:g}=Ke();let b;s[6]!==n||s[7]!==c?(b=()=>{c(n)},s[6]=n,s[7]=c,s[8]=b):b=s[8];const v=b;let x;s[9]!==r||s[10]!==n.id||s[11]!==u?(x=r??u.findIndex(E=>E.id===n.id),s[9]=r,s[10]=n.id,s[11]=u,s[12]=x):x=s[12];const S=x,T=(f||d!==null)&&S===h;let y;s[13]!==l||s[14]!==S?(y=()=>{l(S)},s[13]=l,s[14]=S,s[15]=y):y=s[15];const w=y,C=`${g}-option-${n.id}`,I=T?"":void 0;let $;s[16]!==v||s[17]!==i?($=K(i,v),s[16]=v,s[17]=i,s[18]=$):$=s[18];let D;s[19]!==w||s[20]!==o?(D=K(o,w),s[19]=w,s[20]=o,s[21]=D):D=s[21];let R;return s[22]!==e||s[23]!==T||s[24]!==a||s[25]!==C||s[26]!==I||s[27]!==$||s[28]!==D?(R=p.jsx(W.button,{type:"button",role:"option",id:C,"aria-selected":T,"data-highlighted":I,...a,ref:e,onClick:$,onMouseMove:D}),s[22]=e,s[23]=T,s[24]=a,s[25]=C,s[26]=I,s[27]=$,s[28]=D,s[29]=R):R=s[29],R});yo.displayName="ComposerPrimitive.TriggerPopoverItem";const vo=M.forwardRef((t,e)=>{const s=_(10);let r,n;s[0]!==t?({onClick:r,...n}=t,s[0]=t,s[1]=r,s[2]=n):(r=s[1],n=s[2]);const{activeCategoryId:i,isSearchMode:o,goBack:a,open:c}=Ke();if(!c||!i||o)return null;let l;s[3]!==a||s[4]!==r?(l=K(r,a),s[3]=a,s[4]=r,s[5]=l):l=s[5];let u;return s[6]!==e||s[7]!==n||s[8]!==l?(u=p.jsx(W.button,{type:"button",...n,ref:e,onClick:l}),s[6]=e,s[7]=n,s[8]=l,s[9]=u):u=s[9],u});vo.displayName="ComposerPrimitive.TriggerPopoverBack";const So=({formatter:t,onExecute:e,removeOnExecute:s})=>{const{register:r}=ro(),n=V(e);return n.current=e,N(()=>r({kind:"action",formatter:t??ki,onExecute:i=>n.current(i),...s!==void 0?{removeOnExecute:s}:{}}),[r,t,s]),null};So.displayName="ComposerPrimitive.TriggerPopoverAction";const xo=({formatter:t,onInserted:e})=>{const{register:s}=ro(),r=V(e);return r.current=e,N(()=>s({kind:"directive",formatter:t??ki,onInserted:n=>{var i;return(i=r.current)==null?void 0:i.call(r,n)}}),[s,t]),null};xo.displayName="ComposerPrimitive.TriggerPopoverDirective";const rg=Object.assign(no,{Directive:xo,Action:So});var qt=Dt({AddAttachment:()=>Wp,AttachmentByIndex:()=>Ci,AttachmentDropzone:()=>uo,Attachments:()=>Ii,Cancel:()=>Gp,Dictate:()=>Yp,DictationTranscript:()=>ho,If:()=>Pi,Input:()=>lo,Queue:()=>Ei,Quote:()=>fo,QuoteDismiss:()=>go,QuoteText:()=>po,Root:()=>oo,Send:()=>_p,StopDictation:()=>Xp,Unstable_TriggerPopover:()=>rg,Unstable_TriggerPopoverBack:()=>vo,Unstable_TriggerPopoverCategories:()=>mo,Unstable_TriggerPopoverCategoryItem:()=>bo,Unstable_TriggerPopoverItem:()=>yo,Unstable_TriggerPopoverItems:()=>_o,Unstable_TriggerPopoverRoot:()=>to,unstable_useTriggerPopoverRootContext:()=>Ls,unstable_useTriggerPopoverRootContextOptional:()=>Vs,unstable_useTriggerPopoverScopeContext:()=>Ke,unstable_useTriggerPopoverScopeContextOptional:()=>mp,unstable_useTriggerPopoverTriggers:()=>Zf,unstable_useTriggerPopoverTriggersOptional:()=>tp});const wo=()=>P(ng);function ng(t){if(t.part.type!=="text"&&t.part.type!=="reasoning")throw new Error("MessagePartText can only be used inside text or reasoning message parts.");return t.part}const ig=ae(null);function og(t){const e=he(ig);if(!(t!=null&&t.optional)&&!e)throw new Error("This component must be used within a SmoothContextProvider.");return e}const{useSmoothStatus:vm,useSmoothStatusStore:ag}=$i(og,"useSmoothStatus"),To=250,Co=5;var cg=class{constructor(t,e){m(this,"currentText");m(this,"setText");m(this,"animationFrameId",null);m(this,"lastUpdateTime",Date.now());m(this,"lastCommitTime",0);m(this,"targetText","");m(this,"drainMs",To);m(this,"maxCharIntervalMs",Co);m(this,"maxCharsPerFrame",1/0);m(this,"minCommitMs",0);m(this,"animate",()=>{const t=Date.now();let e=t-this.lastUpdateTime;const s=this.targetText.length-this.currentText.length,r=Math.min(this.maxCharIntervalMs,this.drainMs/s),n=Math.min(s,this.maxCharsPerFrame);let i=0;for(;e>=r&&i<n;)i++,e-=r;i===n&&n===this.maxCharsPerFrame&&(e=0),i!==s?this.animationFrameId=requestAnimationFrame(this.animate):this.animationFrameId=null,i!==0&&(this.currentText=this.targetText.slice(0,this.currentText.length+i),this.lastUpdateTime=t-e,(i===s||t-this.lastCommitTime>=this.minCommitMs)&&(this.lastCommitTime=t,this.setText(this.currentText)))});this.currentText=t,this.setText=e}start(){this.animationFrameId===null&&(this.lastUpdateTime=Date.now(),this.animate())}stop(){this.animationFrameId!==null&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=null)}};const Ht=Object.freeze({type:"running"}),dt=(t,e)=>t!==void 0&&t>0?t:e,lg=(t,e=!1)=>{const{text:s}=t,r=co("(prefers-reduced-motion: reduce)"),n=typeof e=="object"&&e!==null?e:void 0,i=e!==!1&&e!==null&&!r,o=dt(n==null?void 0:n.drainMs,To),a=dt(n==null?void 0:n.maxCharIntervalMs,Co),c=dt(n==null?void 0:n.maxCharsPerFrame,1/0),l=dt(n==null?void 0:n.minCommitMs,0),[u,h]=G(t.status.type==="running"?"":s),d=F(),f=P(()=>d.part()),[g,b]=G(f);(f!==g||!s.startsWith(u))&&(b(f),h(t.status.type==="running"?"":s));const v=ag({optional:!0}),x=st(y=>{if(h(y),v){const w=u!==y||t.status.type==="running"?Ht:t.status;Tt(v).setState(w,!0)}});N(()=>{if(v){const y=i&&(u!==s||t.status.type==="running")?Ht:t.status;Tt(v).setState(y,!0)}},[v,i,s,u,t.status]);const[S]=G(new cg(u,x));N(()=>{S.drainMs=o,S.maxCharIntervalMs=a,S.maxCharsPerFrame=c,S.minCommitMs=l},[S,o,a,c,l]);const T=V(f);return N(()=>{if(!i){S.stop();return}const y=T.current!==f;if(T.current=f,y||!s.startsWith(S.targetText)){t.status.type==="running"?(S.currentText="",S.targetText=s,S.lastCommitTime=0,S.start()):(S.currentText=s,S.targetText=s,S.stop());return}S.targetText=s,S.start()},[S,i,s,t.status.type,f]),N(()=>()=>{S.stop()},[S]),Y(()=>i?{...t,text:u,status:s===u?t.status:Ht}:t,[i,u,t,s])},ug=()=>P(dg);function dg(t){if(t.part.type!=="image")throw new Error("MessagePartImage can only be used inside image message parts.");return t.part}const Hs=M.forwardRef((t,e)=>{const s=_(10);let r,n,i;s[0]!==t?({smooth:n,component:i,...r}=t,s[0]=t,s[1]=r,s[2]=n,s[3]=i):(r=s[1],n=s[2],i=s[3]);const o=n===void 0?!0:n,a=i===void 0?"span":i,{text:c,status:l}=lg(wo(),o);let u;return s[4]!==a||s[5]!==e||s[6]!==r||s[7]!==l.type||s[8]!==c?(u=p.jsx(a,{"data-status":l.type,...r,ref:e,children:c}),s[4]=a,s[5]=e,s[6]=r,s[7]=l.type,s[8]=c,s[9]=u):u=s[9],u});Hs.displayName="MessagePartPrimitive.Text";const zs=M.forwardRef((t,e)=>{const s=_(4),{image:r}=ug();let n;return s[0]!==e||s[1]!==r||s[2]!==t?(n=p.jsx(W.img,{src:r,...t,ref:e}),s[0]=e,s[1]=r,s[2]=t,s[3]=n):n=s[3],n});zs.displayName="MessagePartPrimitive.Image";const De=t=>{const e=_(2),s=V(void 0);let r;return e[0]!==t?(r=n=>{s.current&&(s.current(),s.current=void 0),n&&(s.current=t(n))},e[0]=t,e[1]=r):r=e[1],r},Kr=(t,e)=>{const s=t.trim().match(/^(\d+(?:\.\d+)?|\.\d+)(em|px|rem)$/);if(!s)return Number.POSITIVE_INFINITY;const r=Number(s[1]),n=s[2];return n==="px"?r:n==="em"?r*(parseFloat(getComputedStyle(e).fontSize)||16):n==="rem"?r*(parseFloat(getComputedStyle(document.documentElement).fontSize)||16):Number.POSITIVE_INFINITY},hg=t=>t.dataset.messageId,fg=()=>{const t=document.createElement("div");return t.dataset.auiTopAnchorReserve="",t.style.height="0px",t.style.flexShrink="0",t.style.pointerEvents="none",t.setAttribute("aria-hidden","true"),t},Wr=(t,e)=>{const s=`${e}px`;return t.style.height!==s?(t.style.height=s,!0):!1},pg=t=>{const e=window.devicePixelRatio||1;return Math.round(t*e)/e},Io=()=>{const t=_(4),e=F();let s;t[0]!==e?(s=()=>e.message(),t[0]=e,t[1]=s):s=t[1];const r=P(s);let n;return t[2]!==r?(n=i=>{const o=()=>{r.setIsHovering(!0)},a=()=>{r.setIsHovering(!1)};return i.addEventListener("mouseenter",o),i.addEventListener("mouseleave",a),i.matches(":hover")&&queueMicrotask(()=>r.setIsHovering(!0)),()=>{i.removeEventListener("mouseenter",o),i.removeEventListener("mouseleave",a),r.setIsHovering(!1)}},t[2]=r,t[3]=n):n=t[3],De(n)},gg=()=>{const t=_(2),e=ke(Sg);let s;return t[0]!==e?(s=r=>{var n;return r.message.role==="user"&&r.message.index>0&&r.message.index===r.thread.messages.length-2&&((n=r.thread.messages.at(-1))==null?void 0:n.role)==="assistant"&&(r.message.id===e||r.thread.isRunning)},t[0]=e,t[1]=s):s=t[1],P(s)},mg=()=>{const t=_(2),e=ke(xg);let s;return t[0]!==e?(s=r=>{var n;return r.message.isLast&&r.message.role==="assistant"&&r.message.index>=1&&((n=r.thread.messages.at(r.message.index-1))==null?void 0:n.role)==="user"&&(r.message.id===e||r.thread.isRunning)},t[0]=e,t[1]=s):s=t[1],P(s)},bg=(t,e)=>{const s=_(3);let r;return s[0]!==t||s[1]!==e?(r=n=>{if(t)return e.getState().registerAnchorElement(n)},s[0]=t,s[1]=e,s[2]=r):r=s[2],De(r)},_g=t=>{const e=_(3),{active:s,threadViewportStore:r}=t;let n;return e[0]!==s||e[1]!==r?(n=i=>{if(!s)return;const o=r.getState(),a=o.topAnchorMessageClamp;return o.registerAnchorTargetElement(i,{tallerThan:Kr(a.tallerThan,i),visibleHeight:Kr(a.visibleHeight,i)})},e[0]=s,e[1]=r,e[2]=n):n=e[2],De(n)},yg=t=>{const e=_(7);let s,r;e[0]!==t?({forwardedRef:s,...r}=t,e[0]=t,e[1]=s,e[2]=r):(s=e[1],r=e[2]);const n=Io(),i=we(s,n),o=P(wg);let a;return e[3]!==o||e[4]!==r||e[5]!==i?(a=p.jsx(W.div,{...r,ref:i,"data-message-id":o}),e[3]=o,e[4]=r,e[5]=i,e[6]=a):a=e[6],a},vg=t=>{const e=_(13);let s,r,n;e[0]!==t?({forwardedRef:s,threadViewportStore:n,...r}=t,e[0]=t,e[1]=s,e[2]=r,e[3]=n):(s=e[1],r=e[2],n=e[3]);const i=Io(),o=gg(),a=mg(),c=bg(o,n);let l;e[4]!==a||e[5]!==n?(l={active:a,threadViewportStore:n},e[4]=a,e[5]=n,e[6]=l):l=e[6];const u=_g(l),h=we(s,i,c,u),d=P(Tg),f=o?"":void 0,g=a?"":void 0;let b;return e[7]!==d||e[8]!==r||e[9]!==h||e[10]!==f||e[11]!==g?(b=p.jsx(W.div,{...r,ref:h,"data-message-id":d,"data-aui-top-anchor-user":f,"data-aui-top-anchor-target":g}),e[7]=d,e[8]=r,e[9]=h,e[10]=f,e[11]=g,e[12]=b):b=e[12],b},Eo=M.forwardRef((t,e)=>{const s=_(7),r=$e();if(r.getState().turnAnchor==="top"){let i;return s[0]!==e||s[1]!==t||s[2]!==r?(i=p.jsx(vg,{...t,forwardedRef:e,threadViewportStore:r}),s[0]=e,s[1]=t,s[2]=r,s[3]=i):i=s[3],i}let n;return s[4]!==e||s[5]!==t?(n=p.jsx(yg,{...t,forwardedRef:e}),s[4]=e,s[5]=t,s[6]=n):n=s[6],n});Eo.displayName="MessagePrimitive.Root";function Sg(t){var e;return(e=t.topAnchorTurn)==null?void 0:e.anchorId}function xg(t){var e;return(e=t.topAnchorTurn)==null?void 0:e.targetId}function wg(t){return t.message.id}function Tg(t){return t.message.id}const zt={...X,Text:()=>p.jsxs("p",{style:{whiteSpace:"pre-line"},children:[p.jsx(Hs,{}),p.jsx($s,{children:p.jsx("span",{style:{fontFamily:"revert"},children:" ●"})})]}),Image:()=>p.jsx(zs,{})},cs=t=>{const e=_(10);if("children"in t){let a;return e[0]!==t.children?(a=p.jsx(ns,{children:t.children}),e[0]=t.children,e[1]=a):a=e[1],a}let s,r;e[2]!==t?({components:s,...r}=t,e[2]=t,e[3]=s,e[4]=r):(s=e[3],r=e[4]);let n;e[5]!==s?(n=s?{Text:s.Text??zt.Text,Image:s.Image??zt.Image,Reasoning:s.Reasoning??X.Reasoning,Source:s.Source??X.Source,File:s.File??X.File,Unstable_Audio:s.Unstable_Audio??X.Unstable_Audio,..."ChainOfThought"in s?{ChainOfThought:s.ChainOfThought}:{tools:s.tools,data:s.data,ToolGroup:s.ToolGroup??X.ToolGroup,ReasoningGroup:s.ReasoningGroup??X.ReasoningGroup},Empty:s.Empty,Quote:s.Quote,generativeUI:s.generativeUI}:zt,e[5]=s,e[6]=n):n=e[6];const i=n;let o;return e[7]!==r||e[8]!==i?(o=p.jsx(ns,{components:i,...r}),e[7]=r,e[8]=i,e[9]=o):o=e[9],o};cs.displayName="MessagePrimitive.Parts";const Ro=t=>{const{children:e}=t;return Jh()!==void 0?e:null};Ro.displayName="MessagePrimitive.Error";const Cg=t=>{var r;const e=new Map;for(let n=0;n<t.length;n++){const i=((r=t[n])==null?void 0:r.parentId)??`__ungrouped_${n}`,o=e.get(i)??[];o.push(n),e.set(i,o)}const s=[];for(const[n,i]of e){const o=n.startsWith("__ungrouped_")?void 0:n;s.push({groupKey:o,indices:i})}return s},Ig=t=>{const e=_(4),s=P(Bg);let r;e:{if(s.length===0){let i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i=[],e[0]=i):i=e[0],r=i;break e}let n;e[1]!==t||e[2]!==s?(n=t(s),e[1]=t,e[2]=s,e[3]=n):n=e[3],r=n}return r},Eg=t=>{const e=_(9);let s,r;e[0]!==t?({Fallback:s,...r}=t,e[0]=t,e[1]=s,e[2]=r):(s=e[1],r=e[2]);let n;e[3]!==s||e[4]!==r.toolName?(n=a=>{const c=a.tools.tools[r.toolName]??s;return Array.isArray(c)?c[0]??s:c},e[3]=s,e[4]=r.toolName,e[5]=n):n=e[5];const i=P(n);if(!i)return null;let o;return e[6]!==i||e[7]!==r?(o=p.jsx(i,{...r}),e[6]=i,e[7]=r,e[8]=o):o=e[8],o},Rg=t=>{const e=_(9);let s,r;e[0]!==t?({Fallback:s,...r}=t,e[0]=t,e[1]=s,e[2]=r):(s=e[1],r=e[2]);let n;e[3]!==s||e[4]!==r.name?(n=a=>{const c=a.dataRenderers.renderers[r.name]??s;return Array.isArray(c)?c[0]??s:c},e[3]=s,e[4]=r.name,e[5]=n):n=e[5];const i=P(n);if(!i)return null;let o;return e[6]!==i||e[7]!==r?(o=p.jsx(i,{...r}),e[6]=i,e[7]=r,e[8]=o):o=e[8],o},xe={Text:()=>p.jsxs("p",{style:{whiteSpace:"pre-line"},children:[p.jsx(Hs,{}),p.jsx($s,{children:p.jsx("span",{style:{fontFamily:"revert"},children:" ●"})})]}),Reasoning:()=>null,Source:()=>null,Image:()=>p.jsx(zs,{}),File:()=>null,Unstable_Audio:()=>null,Group:({children:t})=>t},Ag=t=>{var I,$,D;const e=_(43),{components:s}=t;let r;e[0]!==s?(r=s===void 0?{}:s,e[0]=s,e[1]=r):r=e[1];const{Text:n,Reasoning:i,Image:o,Source:a,File:c,Unstable_Audio:l,tools:u,data:h}=r,d=n===void 0?xe.Text:n,f=i===void 0?xe.Reasoning:i,g=o===void 0?xe.Image:o,b=a===void 0?xe.Source:a,v=c===void 0?xe.File:c,x=l===void 0?xe.Unstable_Audio:l;let S;e[2]!==u?(S=u===void 0?{}:u,e[2]=u,e[3]=S):S=e[3];const T=S,y=F(),w=P(Og),C=w.type;if(C==="tool-call"){let R;e[4]!==y?(R=y.part(),e[4]=y,e[5]=R):R=e[5];const E=R.addToolResult;let k;e[6]!==y?(k=y.part(),e[6]=y,e[7]=k):k=e[7];const A=k.resumeToolCall;let B;e[8]!==y?(B=y.part(),e[8]=y,e[9]=B):B=e[9];const O=B.respondToToolApproval;if("Override"in T){let j;return e[10]!==E||e[11]!==w||e[12]!==O||e[13]!==A||e[14]!==T.Override?(j=p.jsx(T.Override,{...w,addResult:E,resume:A,respondToApproval:O}),e[10]=E,e[11]=w,e[12]=O,e[13]=A,e[14]=T.Override,e[15]=j):j=e[15],j}const L=((I=T.by_name)==null?void 0:I[w.toolName])??T.Fallback;let H;return e[16]!==L||e[17]!==E||e[18]!==w||e[19]!==O||e[20]!==A?(H=p.jsx(Eg,{...w,Fallback:L,addResult:E,resume:A,respondToApproval:O}),e[16]=L,e[17]=E,e[18]=w,e[19]=O,e[20]=A,e[21]=H):H=e[21],H}if((($=w.status)==null?void 0:$.type)==="requires-action")throw new Error("Encountered unexpected requires-action status");switch(C){case"text":{let R;return e[22]!==d||e[23]!==w?(R=p.jsx(d,{...w}),e[22]=d,e[23]=w,e[24]=R):R=e[24],R}case"reasoning":{let R;return e[25]!==f||e[26]!==w?(R=p.jsx(f,{...w}),e[25]=f,e[26]=w,e[27]=R):R=e[27],R}case"source":{let R;return e[28]!==b||e[29]!==w?(R=p.jsx(b,{...w}),e[28]=b,e[29]=w,e[30]=R):R=e[30],R}case"image":{let R;return e[31]!==g||e[32]!==w?(R=p.jsx(g,{...w}),e[31]=g,e[32]=w,e[33]=R):R=e[33],R}case"file":{let R;return e[34]!==v||e[35]!==w?(R=p.jsx(v,{...w}),e[34]=v,e[35]=w,e[36]=R):R=e[36],R}case"audio":{let R;return e[37]!==x||e[38]!==w?(R=p.jsx(x,{...w}),e[37]=x,e[38]=w,e[39]=R):R=e[39],R}case"data":{const R=((D=h==null?void 0:h.by_name)==null?void 0:D[w.name])??(h==null?void 0:h.Fallback);let E;return e[40]!==R||e[41]!==w?(E=p.jsx(Rg,{...w,Fallback:R}),e[40]=R,e[41]=w,e[42]=E):E=e[42],E}default:return console.warn(`Unknown message part type: ${C}`),null}},Mg=t=>{const e=_(5),{partIndex:s,components:r}=t;let n;e[0]!==r?(n=p.jsx(Ag,{components:r}),e[0]=r,e[1]=n):n=e[1];let i;return e[2]!==s||e[3]!==n?(i=p.jsx(Cs,{index:s,children:n}),e[2]=s,e[3]=n,e[4]=i):i=e[4],i},Pg=M.memo(Mg,(t,e)=>{var s,r,n,i,o,a,c,l,u,h,d,f,g,b,v,x,S,T;return t.partIndex===e.partIndex&&((s=t.components)==null?void 0:s.Text)===((r=e.components)==null?void 0:r.Text)&&((n=t.components)==null?void 0:n.Reasoning)===((i=e.components)==null?void 0:i.Reasoning)&&((o=t.components)==null?void 0:o.Source)===((a=e.components)==null?void 0:a.Source)&&((c=t.components)==null?void 0:c.Image)===((l=e.components)==null?void 0:l.Image)&&((u=t.components)==null?void 0:u.File)===((h=e.components)==null?void 0:h.File)&&((d=t.components)==null?void 0:d.Unstable_Audio)===((f=e.components)==null?void 0:f.Unstable_Audio)&&((g=t.components)==null?void 0:g.tools)===((b=e.components)==null?void 0:b.tools)&&((v=t.components)==null?void 0:v.data)===((x=e.components)==null?void 0:x.data)&&((S=t.components)==null?void 0:S.Group)===((T=e.components)==null?void 0:T.Group)}),kg=t=>{const e=_(6),{status:s,component:r}=t,n=s.type==="running";let i;e[0]!==r||e[1]!==s?(i=p.jsx(r,{type:"text",text:"",status:s}),e[0]=r,e[1]=s,e[2]=i):i=e[2];let o;return e[3]!==n||e[4]!==i?(o=p.jsx(Is,{text:"",isRunning:n,children:i}),e[3]=n,e[4]=i,e[5]=o):o=e[5],o},$g=Object.freeze({type:"complete"}),Dg=t=>{const e=_(6),{components:s}=t,r=P(Ng);if(s!=null&&s.Empty){let o;return e[0]!==s.Empty||e[1]!==r?(o=p.jsx(s.Empty,{status:r}),e[0]=s.Empty,e[1]=r,e[2]=o):o=e[2],o}const n=(s==null?void 0:s.Text)??xe.Text;let i;return e[3]!==r||e[4]!==n?(i=p.jsx(kg,{status:r,component:n}),e[3]=r,e[4]=n,e[5]=i):i=e[5],i},jg=M.memo(Dg,(t,e)=>{var s,r,n,i;return((s=t.components)==null?void 0:s.Empty)===((r=e.components)==null?void 0:r.Empty)&&((n=t.components)==null?void 0:n.Text)===((i=e.components)==null?void 0:i.Text)}),Gs=t=>{const e=_(9),{groupingFunction:s,components:r}=t,n=P(Fg),i=Ig(s);let o;e:{if(n===0){let u;e[0]!==r?(u=p.jsx(jg,{components:r}),e[0]=r,e[1]=u):u=e[1],o=u;break e}let l;if(e[2]!==r||e[3]!==i){let u;e[5]!==r?(u=(h,d)=>p.jsx((r==null?void 0:r.Group)??xe.Group,{groupKey:h.groupKey,indices:h.indices,children:h.indices.map(f=>p.jsx(Pg,{partIndex:f,components:r},f))},`group-${d}-${h.groupKey??"ungrouped"}`),e[5]=r,e[6]=u):u=e[6],l=i.map(u),e[2]=r,e[3]=i,e[4]=l}else l=e[4];o=l}const a=o;let c;return e[7]!==a?(c=p.jsx(p.Fragment,{children:a}),e[7]=a,e[8]=c):c=e[8],c};Gs.displayName="MessagePrimitive.Unstable_PartsGrouped";const Ao=t=>{const e=_(6);let s,r;e[0]!==t?({components:s,...r}=t,e[0]=t,e[1]=s,e[2]=r):(s=e[1],r=e[2]);let n;return e[3]!==s||e[4]!==r?(n=p.jsx(Gs,{...r,components:s,groupingFunction:Cg}),e[3]=s,e[4]=r,e[5]=n):n=e[5],n};Ao.displayName="MessagePrimitive.Unstable_PartsGroupedByParentId";function Bg(t){return t.message.parts}function Og(t){return t.part}function Ng(t){return t.message.status??$g}function Fg(t){return t.message.parts.length}var It=Dt({AttachmentByIndex:()=>xi,Attachments:()=>wi,Content:()=>cs,Error:()=>Ro,GenerativeUI:()=>di,GroupedParts:()=>yi,If:()=>Ji,PartByIndex:()=>Je,Parts:()=>cs,Quote:()=>vi,Root:()=>Eo,Unstable_PartsGrouped:()=>Gs,Unstable_PartsGroupedByParentId:()=>Ao});const Lg=t=>{const e=_(2),s=st(t);let r;return e[0]!==s?(r=n=>{const i=new ResizeObserver(()=>{s()}),o=new MutationObserver(a=>{a.some(Vg)&&s()});return i.observe(n),o.observe(n,{childList:!0,subtree:!0,attributes:!0,characterData:!0}),()=>{i.disconnect(),o.disconnect()}},e[0]=s,e[1]=r):r=e[1],De(r)};function Vg(t){return t.type!=="attributes"||t.attributeName!=="style"}const Ug=({autoScroll:t,scrollToBottomOnRunStart:e=!0,scrollToBottomOnInitialize:s=!0,scrollToBottomOnThreadSwitch:r=!0})=>{const n=V(null),i=P(y=>y.thread.messages.length>0),o=V(!1),a=V(null),c=$e();t===void 0&&(t=c.getState().turnAnchor!=="top");const l=V(0),u=V(0),h=V(0),d=V(0),f=V(null),g=Qe(y=>{const w=n.current;w&&(f.current=y,w.scrollTo({top:w.scrollHeight,behavior:y}))},[]),b=Qe(y=>{f.current=y,a.current!==null&&cancelAnimationFrame(a.current),a.current=requestAnimationFrame(()=>{a.current=null,g(y)})},[g]);bt(()=>()=>{a.current!==null&&cancelAnimationFrame(a.current)},[]);const v=Qe(()=>{const y=c.getState();return y.turnAnchor==="top"&&y.element.viewport===n.current&&y.element.anchor!==null},[c]),x=()=>{const y=n.current;if(!y)return;const w=c.getState().isAtBottom,C=Math.abs(y.scrollHeight-y.scrollTop-y.clientHeight)<=1||y.scrollHeight<=y.clientHeight;!C&&l.current<y.scrollTop||(C?y.scrollHeight>y.clientHeight+1&&(f.current=null):l.current>y.scrollTop&&u.current===y.scrollHeight&&(f.current=null),(C||f.current===null)&&C!==w&&Tt(c).setState({isAtBottom:C})),l.current=y.scrollTop,u.current=y.scrollHeight},S=Lg(()=>{const y=n.current;if(!y)return;const{scrollHeight:w,clientHeight:C}=y;if(w===h.current&&C===d.current)return;h.current=w,d.current=C;const I=f.current;I&&v()?f.current=null:I?g(I):t&&c.getState().isAtBottom&&g("instant"),x()}),T=De(y=>{const w=()=>{f.current=null};return y.addEventListener("scroll",x),y.addEventListener("pointerdown",w),()=>{y.removeEventListener("scroll",x),y.removeEventListener("pointerdown",w)}});return bt(()=>{if(s){if(!i){o.current=!1;return}o.current||(o.current=!0,f.current===null&&b("instant"))}},[i,b,s]),ao(({behavior:y})=>{g(y)}),yt("thread.runStart",()=>{e&&c.getState().turnAnchor!=="top"&&b("auto")}),yt("threadListItem.switchedTo",()=>{r&&b("instant")}),we(S,T,n)},Mo=M.forwardRef((t,e)=>{const s=_(3);let r;return s[0]!==t||s[1]!==e?(r=p.jsx(W.div,{...t,ref:e}),s[0]=t,s[1]=e,s[2]=r):r=s[2],r});Mo.displayName="ThreadPrimitive.Root";const Po=t=>{const{children:e}=t;return P(qg)?e:null};Po.displayName="ThreadPrimitive.Empty";function qg(t){return t.thread.isEmpty}const Hg=t=>{const e=_(4);let s;return e[0]!==t.disabled||e[1]!==t.empty||e[2]!==t.running?(s=r=>!(t.empty===!0&&!r.thread.isEmpty||t.empty===!1&&r.thread.isEmpty||t.running===!0&&!r.thread.isRunning||t.running===!1&&r.thread.isRunning||t.disabled===!0&&!r.thread.isDisabled||t.disabled===!1&&r.thread.isDisabled),e[0]=t.disabled,e[1]=t.empty,e[2]=t.running,e[3]=s):s=e[3],P(s)},ko=t=>{const e=_(3);let s,r;return e[0]!==t?({children:s,...r}=t,e[0]=t,e[1]=s,e[2]=r):(s=e[1],r=e[2]),Hg(r)?s:null};ko.displayName="ThreadPrimitive.If";const $o=(t,e)=>{const s=_(3);let r;return s[0]!==e||s[1]!==t?(r=n=>{if(!t)return;const i=t(),o=()=>{const c=e?e(n):n.offsetHeight;i.setHeight(c)},a=new ResizeObserver(o);return a.observe(n),o(),()=>{a.disconnect(),i.unregister()}},s[0]=e,s[1]=t,s[2]=r):r=s[2],De(r)},Qr=t=>{let e=0,s=t;for(;s;)e+=s.offsetTop,s=s.offsetParent;return e},zg=(t,e)=>{let s=0,r=t;for(;r&&r!==e;)s+=r.offsetTop,r=r.offsetParent;return r===e?s:Qr(t)-Qr(e)},Do=({viewport:t,anchor:e,tallerThan:s,visibleHeight:r})=>{const n=zg(e,t),i=e.offsetHeight;return n+Math.max(0,i-(i<=s?i:r))},Gg=({scrollHeight:t,...e})=>{const{viewport:s}=e,r=Do(e)+s.clientHeight;return Math.max(0,r-t)},Kg=({viewport:t,reserve:e,...s})=>Gg({viewport:t,...s,scrollHeight:t.scrollHeight-e.offsetHeight}),Wg=t=>{const e=new ResizeObserver(t),s=new MutationObserver(t);let r=null,n=null,i=null;const o=()=>{e.disconnect(),s.disconnect(),r=null,n=null,i=null};return{target:(a,c,l)=>{r===a&&n===c&&i===l||(o(),e.observe(a),e.observe(c),e.observe(l),s.observe(l,{childList:!0,subtree:!0,characterData:!0}),r=a,n=c,i=l)},disconnect:o}},Qg=t=>{let e=null;return{schedule:()=>{e===null&&(e=requestAnimationFrame(()=>{e=null,t()}))},cancel:()=>{e!==null&&(cancelAnimationFrame(e),e=null)}}},Yg=t=>{let e=null,s;function r(){const a=t.getState(),{viewport:c,anchor:l,target:u}=a.element,h=a.targetConfig;if(a.turnAnchor!=="top"||!c||!l||!u||!h){i.disconnect(),e&&(Wr(e,0),e.remove());return}if(e??(e=fg()),(e.parentElement!==u.parentElement||e.previousElementSibling!==u)&&u.after(e),i.target(c,l,u),Wr(e,Kg({viewport:c,anchor:l,reserve:e,...h}))){n.schedule();return}const d=hg(l);if(d!==void 0&&s===d)return;const f=pg(Do({viewport:c,anchor:l,...h}));Math.abs(c.scrollTop-f)>1&&c.scrollTo({top:f,behavior:"smooth"}),d!==void 0&&(s=d)}const n=Qg(r),i=Wg(n.schedule);n.schedule();const o=t.subscribe(n.schedule);return()=>{n.cancel(),o(),i.disconnect(),e==null||e.remove()}},Jg=t=>{const e=_(4),s=$e();let r,n;e[0]!==t||e[1]!==s?(r=()=>{if(t)return Yg(s)},n=[t,s],e[0]=t,e[1]=s,e[2]=r,e[3]=n):(r=e[2],n=e[3]),bt(r,n)},jo=({isRunning:t,messages:e})=>{if(!t)return null;const s=e.at(-1),r=e.at(-2);return(r==null?void 0:r.role)!=="user"||(s==null?void 0:s.role)!=="assistant"?null:{anchorId:r.id,targetId:s.id}},Xg=t=>{var e;return(e=jo(t))==null?void 0:e.anchorId},Zg=t=>{var e;return(e=jo(t))==null?void 0:e.targetId},em=()=>$o(ke(rm),nm),tm=()=>De(ke(im)),sm=t=>{const e=_(13),s=$e();let r;e[0]!==t?(r=f=>{if(t)return Xg(f.thread)},e[0]=t,e[1]=r):r=e[1];const n=P(r);let i;e[2]!==t?(i=f=>{if(t)return Zg(f.thread)},e[2]=t,e[3]=i):i=e[3];const o=P(i);let a;e:{if(!n||!o){a=null;break e}let f;e[4]!==n||e[5]!==o?(f={anchorId:n,targetId:o},e[4]=n,e[5]=o,e[6]=f):f=e[6],a=f}const c=a;let l,u;e[7]!==c||e[8]!==s?(l=()=>{if(!c)return;const f=s.getState(),g=f.topAnchorTurn;(g==null?void 0:g.anchorId)===c.anchorId&&g.targetId===c.targetId||f.setTopAnchorTurn(c)},u=[c,s],e[7]=c,e[8]=s,e[9]=l,e[10]=u):(l=e[9],u=e[10]),bt(l,u);let h;e[11]!==s?(h=()=>{s.getState().setTopAnchorTurn(null)},e[11]=s,e[12]=h):h=e[12];const d=h;yt("thread.initialize",d),yt("threadListItem.switchedTo",d)},Bo=M.forwardRef((t,e)=>{const s=_(18);let r,n,i,o,a,c;s[0]!==t?({autoScroll:r,scrollToBottomOnRunStart:a,scrollToBottomOnInitialize:o,scrollToBottomOnThreadSwitch:c,children:n,...i}=t,s[0]=t,s[1]=r,s[2]=n,s[3]=i,s[4]=o,s[5]=a,s[6]=c):(r=s[1],n=s[2],i=s[3],o=s[4],a=s[5],c=s[6]);let l;s[7]!==r||s[8]!==o||s[9]!==a||s[10]!==c?(l={autoScroll:r,scrollToBottomOnRunStart:a,scrollToBottomOnInitialize:o,scrollToBottomOnThreadSwitch:c},s[7]=r,s[8]=o,s[9]=a,s[10]=c,s[11]=l):l=s[11];const u=Ug(l),h=em(),d=tm(),f=$e();let g;s[12]!==f?(g=f.getState(),s[12]=f,s[13]=g):g=s[13];const b=g.turnAnchor==="top";sm(b),Jg(b);const v=we(e,u,h,d);let x;return s[14]!==n||s[15]!==v||s[16]!==i?(x=p.jsx(W.div,{...i,ref:v,children:n}),s[14]=n,s[15]=v,s[16]=i,s[17]=x):x=s[17],x});Bo.displayName="ThreadPrimitive.ViewportScrollable";const Oo=M.forwardRef((t,e)=>{const s=_(13);let r,n,i;s[0]!==t?({turnAnchor:i,topAnchorMessageClamp:n,...r}=t,s[0]=t,s[1]=r,s[2]=n,s[3]=i):(r=s[1],n=s[2],i=s[3]);let o;s[4]!==n||s[5]!==i?(o={turnAnchor:i,topAnchorMessageClamp:n},s[4]=n,s[5]=i,s[6]=o):o=s[6];let a;s[7]!==r||s[8]!==e?(a=p.jsx(Bo,{...r,ref:e}),s[7]=r,s[8]=e,s[9]=a):a=s[9];let c;return s[10]!==o||s[11]!==a?(c=p.jsx(Ds,{options:o,children:a}),s[10]=o,s[11]=a,s[12]=c):c=s[12],c});Oo.displayName="ThreadPrimitive.Viewport";function rm(t){return t.registerViewport}function nm(t){return t.clientHeight}function im(t){return t.registerViewportElement}const No=M.forwardRef((t,e)=>{const s=_(3),r=we(e,$o(ke(om),am));let n;return s[0]!==t||s[1]!==r?(n=p.jsx(W.div,{...t,ref:r}),s[0]=t,s[1]=r,s[2]=n):n=s[2],n});No.displayName="ThreadPrimitive.ViewportFooter";function om(t){return t.registerContentInset}function am(t){const e=parseFloat(getComputedStyle(t).marginTop)||0;return t.offsetHeight+e}const cm=t=>{const e=_(5);let s;e[0]!==t?(s=t===void 0?{}:t,e[0]=t,e[1]=s):s=e[1];const{behavior:r}=s,n=ke(um),i=$e();let o;e[2]!==r||e[3]!==i?(o=()=>{i.getState().scrollToBottom({behavior:r})},e[2]=r,e[3]=i,e[4]=o):o=e[4];const a=o;return n?null:a},lm=be("ThreadPrimitive.ScrollToBottom",cm,["behavior"]);function um(t){return t.isAtBottom}const dm=t=>{const e=_(4),{prompt:s,send:r,clearComposer:n,autoSend:i}=t,o=r??i??!1;let a;e[0]!==n||e[1]!==s||e[2]!==o?(a={prompt:s,send:o,clearComposer:n},e[0]=n,e[1]=s,e[2]=o,e[3]=a):a=e[3];const{disabled:c,trigger:l}=Qh(a);return c?null:l},hm=be("ThreadPrimitive.Suggestion",dm,["prompt","send","clearComposer","autoSend","method"]);var pt=Dt({Empty:()=>Po,If:()=>ko,MessageByIndex:()=>oi,Messages:()=>yd,Root:()=>Mo,ScrollToBottom:()=>lm,Suggestion:()=>hm,SuggestionByIndex:()=>Ai,Suggestions:()=>_h,Unstable_MessageById:()=>ai,Viewport:()=>Oo,ViewportFooter:()=>No,ViewportProvider:()=>Ds});function fm(t,e){const s=t!=null&&t.createdAt?new Date(t.createdAt):void 0;return{id:String((t==null?void 0:t.id)||`workflow-message-${e}-${(t==null?void 0:t.role)||"assistant"}`),role:(t==null?void 0:t.role)==="user"?"user":"assistant",content:[{type:"text",text:String((t==null?void 0:t.content)||"")}],...s&&!Number.isNaN(s.getTime())?{createdAt:s}:{}}}function Fo(){const{text:t}=wo();return p.jsx(zo,{content:t})}function pm(){return p.jsxs("div",{className:"af-workflow-assistant-pending",role:"status","aria-label":"正在分析",children:[p.jsx("span",{}),p.jsx("span",{}),p.jsx("span",{}),p.jsx("em",{children:"正在结合需求与代码分析"})]})}function gm(){return p.jsxs(It.Root,{className:"af-workflow-assistant-message af-workflow-assistant-message--user",children:[p.jsx("div",{className:"af-workflow-assistant-message__meta",children:"你"}),p.jsx("div",{className:"af-workflow-assistant-message__bubble",children:p.jsx(It.Parts,{components:{Text:Fo}})})]})}function mm(){return p.jsxs(It.Root,{className:"af-workflow-assistant-message af-workflow-assistant-message--assistant",children:[p.jsxs("div",{className:"af-workflow-assistant-message__identity",children:[p.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"auto_awesome"}),p.jsx("strong",{children:"AgentFlow AI"})]}),p.jsx("div",{className:"af-workflow-assistant-message__bubble",children:p.jsx(It.Parts,{components:{Text:Fo,Empty:pm}})}),p.jsx(jr.Root,{className:"af-workflow-assistant-actions",hideWhenRunning:!0,children:p.jsxs(jr.Copy,{className:"af-workflow-assistant-copy",copiedDuration:1600,"aria-label":"复制回答",children:[p.jsx("span",{className:"material-symbols-outlined af-workflow-assistant-copy__idle","aria-hidden":!0,children:"content_copy"}),p.jsx("span",{className:"material-symbols-outlined af-workflow-assistant-copy__done","aria-hidden":!0,children:"check"}),p.jsx("span",{className:"af-workflow-assistant-copy__label",children:"复制"})]})})]})}function bm(){return p.jsx(pt.ViewportFooter,{className:"af-workflow-assistant-footer",children:p.jsxs(qt.Root,{className:"af-workflow-assistant-composer",children:[p.jsx(qt.Input,{className:"af-workflow-assistant-composer__input",rows:1,placeholder:"询问需求状态、代码实现、调用链或风险…","aria-label":"输入 Workflow 问题"}),p.jsxs("div",{className:"af-workflow-assistant-composer__bottom",children:[p.jsx("small",{children:"Enter 发送 · Shift + Enter 换行"}),p.jsx(qt.Send,{className:"af-workflow-assistant-composer__send","aria-label":"发送 Workflow 问题",children:p.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"arrow_upward"})})]})]})})}function Sm({messages:t=[],running:e=!1,error:s="",sources:r=[],suggestions:n=[],onSend:i}){const o=M.useCallback(async c=>{const l=(Array.isArray(c==null?void 0:c.content)?c.content:[]).filter(u=>(u==null?void 0:u.type)==="text").map(u=>u.text).join(`
|
|
6
|
+
`).trim();l&&await(i==null?void 0:i(l))},[i]),a=pd({messages:t,convertMessage:fm,isRunning:e,isSendDisabled:e,onNew:o,unstable_capabilities:{copy:!0}});return p.jsx(of,{runtime:a,children:p.jsx(pt.Root,{className:"af-workflow-assistant-thread",children:p.jsxs(pt.Viewport,{className:"af-workflow-assistant-viewport",autoScroll:!0,turnAnchor:"bottom",children:[t.length?null:p.jsxs("section",{className:"af-workflow-assistant-welcome",children:[p.jsx("div",{className:"af-workflow-assistant-welcome__icon",children:p.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"forum"})}),p.jsx("strong",{children:"从这个需求开始提问"}),p.jsx("p",{children:"AI 会先读取 Workflow 上下文,再结合 Owner 绑定的代码快照回答。"}),p.jsx("div",{className:"af-workflow-assistant-suggestions",children:n.map(c=>p.jsxs("button",{type:"button",disabled:e,onClick:()=>void(i==null?void 0:i(c)),children:[p.jsx("span",{children:c}),p.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"arrow_outward"})]},c))})]}),p.jsx(pt.Messages,{children:({message:c})=>c.role==="user"?p.jsx(gm,{}):p.jsx(mm,{})}),r.length?p.jsxs("details",{className:"af-workflow-assistant-sources",children:[p.jsxs("summary",{children:[p.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"source"}),"本次引用的代码版本",p.jsx("em",{children:r.length})]}),p.jsx("div",{className:"af-workflow-assistant-sources__list",children:r.map(c=>{var l;return p.jsxs("div",{children:[p.jsxs("span",{children:[p.jsx("strong",{children:c.label}),p.jsx("small",{children:c.available?c.selectedRef||"已解析":"不可用"})]}),p.jsx("code",{children:c.available?((l=c.commit)==null?void 0:l.slice(0,12))||c.selectedRef:c.reason})]},c.workspaceId)})})]}):null,s?p.jsxs("div",{className:"af-workflow-assistant-error",role:"alert",children:[p.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"error"}),p.jsx("span",{children:s})]}):null,p.jsx(bm,{})]})})})}export{Sm as default};
|