@alwith/module-chat 0.1.0 → 0.1.2

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.
@@ -1 +1 @@
1
- import{jsx as g,jsxs as ee}from"react/jsx-runtime";import{useCallback as te,useEffect as C,useMemo as z,useRef as b,useState as N}from"react";import{NavigationPreview as ne}from"./navigation-preview.js";import"./navigation-rail.css";var re=4,ie=10;function de({audio:O,beforeReveal:k,ensureItemMounted:f,items:a,scrollRoot:u,targetTopMarginPx:A=16}){let[W,Y]=N(()=>new Set(a.length===0?[]:[a[a.length-1].id])),[p,h]=N(null),[B,P]=N(null),[U,w]=N(!1),[_,Q]=N(()=>new Set),{installUnlock:H,preload:L,playSequence:R}=O,M=b(null),I=b(null),T=b(!1),x=b(null),S=b(0),y=z(()=>a.map((e)=>e.id).join("\x00"),[a]),E=b(a);E.current=a;let G=b({itemIdsKey:y,scrollRoot:u}),K=G.current;if(K.itemIdsKey!==y||K.scrollRoot!==u)S.current+=1,G.current={itemIdsKey:y,scrollRoot:u};let m=z(()=>f===void 0?a.filter((e)=>_.has(e.id)):a,[f,a,_]),D=z(()=>m.map((e)=>({inputTokens:e.inputTokens,outputTokens:e.outputTokens})),[m]);C(()=>H(),[H]),C(()=>()=>{S.current+=1},[]),C(()=>{h(null),w(!1),P(null),I.current=null,T.current=!1,x.current=null},[y,u]),C(()=>{L()},[L]),C(()=>{if(u===null)return;let e=new Set,t=new Map,c=()=>{let r=new Set(t.values()),i=E.current.filter((s)=>r.has(s.id)).map((s)=>s.id),n=i.findIndex((s)=>e.has(s));if(n===-1)return;let l=n;for(let s=n+1;s<i.length;s++)if(e.has(i[s]))l=s;Y((s)=>{let j=new Set(i.slice(n,l+1));if(s.size===j.size&&[...s].every((Z)=>j.has(Z)))return s;return j})},d=new IntersectionObserver((r)=>{for(let i of r){let n=t.get(i.target);if(i.isIntersecting)e.add(n);else e.delete(n)}c()},{root:u,rootMargin:`-${A}px 0px 0px 0px`}),v=()=>{let r=new Set,i=new Set;for(let n of E.current){let l=u.querySelector(`[data-content-search-unit-key="${CSS.escape(n.id)}"]`);if(l===null)continue;if(r.add(n.id),i.add(l),t.has(l))continue;t.set(l,n.id),d.observe(l)}for(let n of t.keys()){if(i.has(n))continue;d.unobserve(n),e.delete(t.get(n)),t.delete(n)}Q((n)=>{if(n.size===r.size&&[...n].every((l)=>r.has(l)))return n;return r})};v();let o=new MutationObserver(v);return o.observe(u,{childList:!0,subtree:!0}),()=>{o.disconnect(),d.disconnect()}},[y,u,A]);let F=te(async(e)=>{if(u===null)throw Error("Thread user-message navigation scroll root is missing");let t=S.current+1;if(S.current=t,k(),f!==void 0){await f(e);return}let c=u.querySelector(`[data-content-search-unit-key="${CSS.escape(e.id)}"]`);if(c===null)throw Error(`Thread user-message navigation target is missing: ${e.id}`);if(S.current!==t)return;c.scrollIntoView({behavior:"instant",block:"start"})},[k,f,u]);if(m.length<re)return null;let q=M.current,X=p===null||q===null||!q.contains(p.button)?0:se(q,p.button),J=(e)=>{let t=e?.closest("[data-thread-user-message-navigation-item-id]"),c=M.current;if(t===void 0||t===null||!c.contains(t))return null;let d=t.dataset.threadUserMessageNavigationItemId,v=m.findIndex((o)=>o.id===d);return{button:t,item:m[v],index:v}},V=(e)=>{let t=I.current;if(t===null||t.pointerId!==e.pointerId)return;if(I.current=null,P(null),t.captureTarget.hasPointerCapture(e.pointerId))t.captureTarget.releasePointerCapture(e.pointerId)};return g("nav",{"aria-label":"User messages",className:"thread-user-message-navigation absolute start-4 top-1/2 z-20 -translate-y-1/2",children:g(ne,{open:U,onOpenChange:w,side:"inline-end",sideOffset:0,align:"center",alignOffset:X,trigger:g("div",{ref:M,"data-thread-user-message-navigation-rail-list":!0,"data-scrubbing":B===null?void 0:"",className:"thread-user-message-navigation-rail-list",onPointerEnter:()=>{x.current=null},onPointerDown:(e)=>{if(e.button!==0)return;let t=J(e.target instanceof Element?e.target:null);if(t===null)return;T.current=!1,I.current={pointerId:e.pointerId,itemId:t.item.id,itemIndex:t.index,captureTarget:t.button},t.button.setPointerCapture(e.pointerId),P(t.item.id),h(t),w(!0)},onPointerMove:(e)=>{let t=I.current;if(t===null){let r=J(e.target instanceof Element?e.target:null);if(r!==null){let i=x.current;if(i!==null&&i!==r.index)R(i,r.index,D);x.current=r.index,h(r)}return}if(t.pointerId!==e.pointerId)return;let c=e.currentTarget.getBoundingClientRect(),d=Math.max(0,Math.min(m.length-1,Math.floor((e.clientY-c.top+e.currentTarget.scrollTop)/ie))),o={button:e.currentTarget.querySelectorAll("[data-thread-user-message-navigation-item-id]")[d],item:m[d],index:d};if(o.item.id===t.itemId)return;R(t.itemIndex,o.index,D),x.current=o.index,I.current={...t,itemId:o.item.id,itemIndex:o.index},T.current=!0,P(o.item.id),h(o),F(o.item)},onPointerUp:V,onPointerCancel:V,onLostPointerCapture:V,onPointerLeave:()=>{if(x.current=null,I.current===null&&!U)h(null)},children:g("div",{className:"flex flex-col",children:m.map((e,t)=>g("button",{type:"button","data-thread-user-message-navigation-item-id":e.id,"data-scrub-target":B===e.id?"":void 0,"aria-current":W.has(e.id)?"true":void 0,"aria-label":`Jump to user message ${t+1}`,className:"thread-user-message-navigation-row",onClick:(c)=>{if(T.current){T.current=!1;return}let d={button:c.currentTarget,item:e,index:t};h(d),w(!0),F(e)},onFocus:(c)=>{h({button:c.currentTarget,item:e,index:t}),w(!0)},children:g("span",{className:"flex h-0.5 w-[30px] items-center",children:g("span",{className:"thread-user-message-navigation-marker"})})},e.id))})}),children:p!==null&&ee("div",{className:"bg-popover/95 text-popover-foreground ring-border w-80 max-w-[calc(100vw-1rem)] overflow-hidden rounded-xl p-2 text-sm leading-5 shadow-xl ring-[0.5px] backdrop-blur-sm",children:[g("div",{className:"min-w-0 truncate font-medium",children:p.item.label}),p.item.response.length>0&&g("div",{className:"text-muted-foreground mt-1 line-clamp-3",children:p.item.response})]})})})}function se(O,k){let f=O.getBoundingClientRect(),a=k.getBoundingClientRect();return a.top+a.height/2-(f.top+f.height/2)}export{de as ThreadUserMessageNavigationRail};
1
+ import{jsx as f,jsxs as ne}from"react/jsx-runtime";import{useCallback as re,useEffect as y,useMemo as B,useRef as g,useState as P}from"react";import{NavigationPreview as ie}from"./navigation-preview.js";import"./navigation-rail.css";var se=4,ae=10;function X(v,I){if(v.size!==I.size)return!1;for(let d of v)if(!I.has(d))return!1;return!0}function fe({audio:v,beforeReveal:I,ensureItemMounted:d,items:s,scrollRoot:o,targetTopMarginPx:R=16}){let[U,Z]=P(()=>new Set(s.length===0?[]:[s[s.length-1].id])),[h,b]=P(null),[_,O]=P(null),[z,S]=P(!1),[M,ee]=P(()=>new Set),{installUnlock:H,preload:L,playSequence:G}=v,E=g(null),x=g(null),C=g(!1),w=g(null),N=g(0),k=B(()=>s.map((e)=>e.id).join("\x00"),[s]),V=g(s);V.current=s;let K=g(M),D=g(U),F=g({itemIdsKey:k,scrollRoot:o}),J=F.current;if(J.itemIdsKey!==k||J.scrollRoot!==o)N.current+=1,F.current={itemIdsKey:k,scrollRoot:o};let m=B(()=>d===void 0?s.filter((e)=>M.has(e.id)):s,[d,s,M]),W=B(()=>m.map((e)=>({inputTokens:e.inputTokens,outputTokens:e.outputTokens})),[m]);y(()=>H(),[H]),y(()=>()=>{N.current+=1},[]),y(()=>{b(null),S(!1),O(null),x.current=null,C.current=!1,w.current=null},[k,o]),y(()=>{L()},[L]),y(()=>{if(o===null)return;let e=new Set,t=new Map,u=()=>{let r=new Set(t.values()),i=V.current.filter((l)=>r.has(l.id)).map((l)=>l.id),n=i.findIndex((l)=>e.has(l));if(n===-1)return;let p=n;for(let l=n+1;l<i.length;l++)if(e.has(i[l]))p=l;let A=new Set(i.slice(n,p+1));if(X(D.current,A))return;D.current=A,Z(A)},c=new IntersectionObserver((r)=>{for(let i of r){let n=t.get(i.target);if(i.isIntersecting)e.add(n);else e.delete(n)}u()},{root:o,rootMargin:`-${R}px 0px 0px 0px`}),T=()=>{let r=new Set,i=new Set;for(let n of V.current){let p=o.querySelector(`[data-content-search-unit-key="${CSS.escape(n.id)}"]`);if(p===null)continue;if(r.add(n.id),i.add(p),t.has(p))continue;t.set(p,n.id),c.observe(p)}for(let n of t.keys()){if(i.has(n))continue;c.unobserve(n),e.delete(t.get(n)),t.delete(n)}if(X(K.current,r))return;K.current=r,ee(r)};T();let a=new MutationObserver(T);return a.observe(o,{childList:!0,subtree:!0}),()=>{a.disconnect(),c.disconnect()}},[k,o,R]);let Y=re(async(e)=>{if(o===null)throw Error("Thread user-message navigation scroll root is missing");let t=N.current+1;if(N.current=t,I(),d!==void 0){await d(e);return}let u=o.querySelector(`[data-content-search-unit-key="${CSS.escape(e.id)}"]`);if(u===null)throw Error(`Thread user-message navigation target is missing: ${e.id}`);if(N.current!==t)return;u.scrollIntoView({behavior:"instant",block:"start"})},[I,d,o]);if(m.length<se)return null;let q=E.current,te=h===null||q===null||!q.contains(h.button)?0:oe(q,h.button),Q=(e)=>{let t=e?.closest("[data-thread-user-message-navigation-item-id]"),u=E.current;if(t===void 0||t===null||!u.contains(t))return null;let c=t.dataset.threadUserMessageNavigationItemId,T=m.findIndex((a)=>a.id===c);return{button:t,item:m[T],index:T}},j=(e)=>{let t=x.current;if(t===null||t.pointerId!==e.pointerId)return;if(x.current=null,O(null),t.captureTarget.hasPointerCapture(e.pointerId))t.captureTarget.releasePointerCapture(e.pointerId)};return f("nav",{"aria-label":"User messages",className:"thread-user-message-navigation absolute start-4 top-1/2 z-20 -translate-y-1/2",children:f(ie,{open:z,onOpenChange:S,side:"inline-end",sideOffset:0,align:"center",alignOffset:te,trigger:f("div",{ref:E,"data-thread-user-message-navigation-rail-list":!0,"data-scrubbing":_===null?void 0:"",className:"thread-user-message-navigation-rail-list",onPointerEnter:()=>{w.current=null},onPointerDown:(e)=>{if(e.button!==0)return;let t=Q(e.target instanceof Element?e.target:null);if(t===null)return;C.current=!1,x.current={pointerId:e.pointerId,itemId:t.item.id,itemIndex:t.index,captureTarget:t.button},t.button.setPointerCapture(e.pointerId),O(t.item.id),b(t),S(!0)},onPointerMove:(e)=>{let t=x.current;if(t===null){let r=Q(e.target instanceof Element?e.target:null);if(r!==null){let i=w.current;if(i!==null&&i!==r.index)G(i,r.index,W);w.current=r.index,b(r)}return}if(t.pointerId!==e.pointerId)return;let u=e.currentTarget.getBoundingClientRect(),c=Math.max(0,Math.min(m.length-1,Math.floor((e.clientY-u.top+e.currentTarget.scrollTop)/ae))),a={button:e.currentTarget.querySelectorAll("[data-thread-user-message-navigation-item-id]")[c],item:m[c],index:c};if(a.item.id===t.itemId)return;G(t.itemIndex,a.index,W),w.current=a.index,x.current={...t,itemId:a.item.id,itemIndex:a.index},C.current=!0,O(a.item.id),b(a),Y(a.item)},onPointerUp:j,onPointerCancel:j,onLostPointerCapture:j,onPointerLeave:()=>{if(w.current=null,x.current===null&&!z)b(null)},children:f("div",{className:"flex flex-col",children:m.map((e,t)=>f("button",{type:"button","data-thread-user-message-navigation-item-id":e.id,"data-scrub-target":_===e.id?"":void 0,"aria-current":U.has(e.id)?"true":void 0,"aria-label":`Jump to user message ${t+1}`,className:"thread-user-message-navigation-row",onClick:(u)=>{if(C.current){C.current=!1;return}let c={button:u.currentTarget,item:e,index:t};b(c),S(!0),Y(e)},onFocus:(u)=>{b({button:u.currentTarget,item:e,index:t}),S(!0)},children:f("span",{className:"flex h-0.5 w-[30px] items-center",children:f("span",{className:"thread-user-message-navigation-marker"})})},e.id))})}),children:h!==null&&ne("div",{className:"bg-popover/95 text-popover-foreground ring-border w-80 max-w-[calc(100vw-1rem)] overflow-hidden rounded-xl p-2 text-sm leading-5 shadow-xl ring-[0.5px] backdrop-blur-sm",children:[f("div",{className:"min-w-0 truncate font-medium",children:h.item.label}),h.item.response.length>0&&f("div",{className:"text-muted-foreground mt-1 line-clamp-3",children:h.item.response})]})})})}function oe(v,I){let d=v.getBoundingClientRect(),s=I.getBoundingClientRect();return s.top+s.height/2-(d.top+d.height/2)}export{fe as ThreadUserMessageNavigationRail};
@@ -34,6 +34,7 @@ export interface ModelSelectProps<T extends ChatModelOption> extends Omit<Compon
34
34
  showDescription?: boolean;
35
35
  showModelList?: boolean;
36
36
  loading?: boolean;
37
+ switching?: boolean;
37
38
  isLoading?: boolean;
38
39
  effortConfig?: ComponentProps<typeof EffortSlider> & {
39
40
  sizer?: string;
@@ -53,4 +54,4 @@ export interface ModelSelectProps<T extends ChatModelOption> extends Omit<Compon
53
54
  }>;
54
55
  t: (key: "model.loadingModels" | "model.switchProvider" | "model.moreModels" | "model.selectModel" | "model.switchModel" | "model.noModelsAvailable") => string;
55
56
  }
56
- export declare function ModelSelect<T extends ChatModelOption>({ value: selectedModel, onChange: setSelectedModel, models: currentProviderModels, modelGroups, providerMenu, header, className, condensed, stripLabelPrefix, showDescription, showModelList, loading, isLoading, effortConfig, booleanOptions, onBooleanChange, selectOptions, t, ...props }: ModelSelectProps<T>): import("react").JSX.Element;
57
+ export declare function ModelSelect<T extends ChatModelOption>({ value: selectedModel, onChange: setSelectedModel, models: currentProviderModels, modelGroups, providerMenu, header, className, condensed, stripLabelPrefix, showDescription, showModelList, loading, switching, isLoading, effortConfig, booleanOptions, onBooleanChange, selectOptions, t, ...props }: ModelSelectProps<T>): import("react").JSX.Element;
@@ -1 +1 @@
1
- import{jsx as e,jsxs as a,Fragment as c}from"react/jsx-runtime";import{ArrowUpRight as Z,ChevronUp as M,Loader2Icon as G}from"lucide-react";import{Fragment as P,useState as O}from"react";import{cn as h}from"cn";import{MenuRadioSelect as p}from"./menu-radio.js";import{EffortSlider as ee}from"./effort-slider.js";import{Button as D}from"../ui/button.js";import{Switch as ne}from"../ui/switch.js";import{Tooltip as V,TooltipContent as j,TooltipTrigger as T}from"../ui/tooltip.js";import{DropdownMenu as A,DropdownMenuContent as F,DropdownMenuGroup as k,DropdownMenuItem as S,DropdownMenuLabel as I,DropdownMenuSeparator as d,DropdownMenuSub as ae,DropdownMenuSubContent as ie,DropdownMenuSubTrigger as le,DropdownMenuTrigger as R}from"../ui/dropdown-menu.js";function ge({value:u,onChange:U,models:o,modelGroups:x,providerMenu:r,header:g,className:z,condensed:N,stripLabelPrefix:f,showDescription:B,showModelList:E=!0,loading:L,isLoading:W,effortConfig:t,booleanOptions:v,onBooleanChange:q,selectOptions:H=[],t:s,...w}){let[J,K]=O(!1),[Q,X]=O(!1),_=(n)=>f&&n.startsWith(f)?n.slice(f.length):n;if(L)return e("div",{className:"inline-flex min-w-0 items-center gap-1.5",children:a(D,{variant:"ghost",disabled:!0,className:h("h-7 min-w-0 shrink gap-1.5 rounded-md px-2 text-xs font-normal",z),children:[e(G,{className:"size-3 animate-spin"}),e("span",{className:"text-muted-foreground truncate",children:s("model.loadingModels")})]})});return a("div",{className:"inline-flex min-w-0 items-center gap-1.5",children:[r&&a(A,{open:J,onOpenChange:K,children:[a(V,{children:[e(T,{render:e(R,{render:a(D,{"data-testid":"provider-trigger",variant:"ghost",disabled:w.disabled,className:h("h-7 shrink-0 gap-1 rounded-md px-1.5","hover:bg-accent"),children:[r.icon,e(M,{className:"size-2.5 shrink-0 opacity-60"})]})})}),e(j,{children:s("model.switchProvider")})]}),a(F,{side:"top",align:"end",sideOffset:4,className:"z-100 min-w-[10rem]",children:[r.groups.map((n,l)=>a(P,{children:[l>0&&n.length>0&&e(d,{}),e(p,{value:r.value,onValueChange:r.onChange,options:n})]},l)),r.moreAction&&a(c,{children:[e(d,{}),a(S,{onClick:r.moreAction,className:"whitespace-nowrap",children:[e("span",{className:"min-w-0 flex-1 truncate",children:s("model.moreModels")}),e(Z,{className:"size-4"})]})]})]})]}),a(A,{open:Q,onOpenChange:X,children:[a(V,{children:[e(T,{render:e(R,{render:a(D,{"data-testid":"model-trigger",variant:"ghost",className:h("h-7 gap-1.5 rounded-md px-2 text-xs font-normal","hover:bg-accent","max-w-full min-w-0 shrink",N&&"h-7 gap-1 px-1.5 text-[11px]",z),...w,children:[e("span",{className:h("min-w-0 flex-1 truncate text-start",N&&"text-[11px]"),children:_(u.label)||s("model.selectModel")}),t&&a("span",{className:"text-muted-foreground grid shrink-0 justify-items-center",children:[e("span",{className:"invisible col-start-1 row-start-1",children:t.sizer??t.levels.reduce((n,l)=>l.name.length>n.length?l.name:n,"")}),e("span",{className:"col-start-1 row-start-1",children:t.levels.find((n)=>n.value===t.value)?.name??t.value})]}),e(M,{className:h("size-3 shrink-0",N&&"size-2.5")})]})})}),e(j,{children:s("model.switchModel")})]}),a(F,{side:"top",align:"end",sideOffset:4,className:"z-100 w-auto max-w-[min(24rem,calc(100vw-1rem))] min-w-[14rem]",children:[g&&a(c,{children:[a("div",{className:"flex items-center gap-2 px-2 py-2",children:[g.icon,e("span",{className:"min-w-0 flex-1 truncate text-sm font-medium",children:g.name}),g.action]}),e(d,{})]}),a(k,{children:[E&&(W?e(S,{disabled:!0,className:"text-muted-foreground",children:s("model.loadingModels")}):o.length===0?e(S,{disabled:!0,className:"text-muted-foreground",children:s("model.noModelsAvailable")}):(()=>{let n=o.filter((i)=>!i.more),l=o.filter((i)=>i.more),y=n.length>0&&l.length>0,b=(i,m)=>({value:i.api_id,label:_(i.label),description:m?.noDescription?void 0:B?i.description:void 0}),C=(i)=>{let m=o.find((Y)=>Y.api_id===i);if(m)U(m)};return a(c,{children:[x?x.map((i)=>a(k,{children:[e(I,{className:"text-muted-foreground text-xs font-normal",children:i.name}),e(p,{value:u.api_id,onValueChange:C,itemClassName:"font-medium whitespace-nowrap",options:i.models.map((m)=>b(m))})]},i.id)):e(p,{value:u.api_id,onValueChange:C,itemClassName:"font-medium whitespace-nowrap",options:(y?n:o).map((i)=>b(i))}),!x&&y&&a(ae,{children:[e(le,{className:"font-medium whitespace-nowrap",children:s("model.moreModels")}),e(ie,{children:e(p,{value:u.api_id,onValueChange:C,itemClassName:"font-medium whitespace-nowrap",options:l.map((i)=>b(i,{noDescription:!0}))})})]})]})})()),t&&a(c,{children:[e(d,{}),e(ee,{...t,disabled:w.disabled})]}),H.map((n)=>a(k,{children:[e(d,{}),e(I,{children:n.name}),e(p,{value:n.value,onValueChange:n.onChange,options:n.options,itemClassName:"whitespace-nowrap"})]},n.id)),v&&v.length>0&&a(c,{children:[!t&&e(d,{}),v.map((n)=>a("div",{className:"flex items-center justify-between gap-3 px-2 py-2.5",children:[e("span",{className:"text-sm font-medium",children:n.name}),e(ne,{"aria-label":n.name,disabled:w.disabled,checked:n.currentValue,onCheckedChange:(l)=>q?.(n.id,l)})]},n.id))]})]})]})]})]})}export{ge as ModelSelect};
1
+ import{jsx as e,jsxs as a,Fragment as c}from"react/jsx-runtime";import{ArrowUpRight as P,ChevronUp as O,Loader2Icon as V}from"lucide-react";import{Fragment as ee,useState as j}from"react";import{cn as h}from"cn";import{MenuRadioSelect as p}from"./menu-radio.js";import{EffortSlider as ne}from"./effort-slider.js";import{Button as D}from"../ui/button.js";import{Switch as ae}from"../ui/switch.js";import{Tooltip as T,TooltipContent as A,TooltipTrigger as F}from"../ui/tooltip.js";import{DropdownMenu as I,DropdownMenuContent as R,DropdownMenuGroup as k,DropdownMenuItem as z,DropdownMenuLabel as U,DropdownMenuSeparator as d,DropdownMenuSub as ie,DropdownMenuSubContent as se,DropdownMenuSubTrigger as te,DropdownMenuTrigger as B}from"../ui/dropdown-menu.js";function we({value:u,onChange:E,models:o,modelGroups:x,providerMenu:r,header:g,className:S,condensed:N,stripLabelPrefix:f,showDescription:L,showModelList:W=!0,loading:q,switching:y,isLoading:H,effortConfig:t,booleanOptions:v,onBooleanChange:J,selectOptions:K=[],t:l,...w}){let[Q,X]=j(!1),[Y,Z]=j(!1),_=(n)=>f&&n.startsWith(f)?n.slice(f.length):n;if(q)return e("div",{className:"inline-flex min-w-0 items-center gap-1.5",children:a(D,{variant:"ghost",disabled:!0,className:h("h-7 min-w-0 shrink gap-1.5 rounded-md px-2 text-xs font-normal",S),children:[e(V,{className:"size-3 animate-spin"}),e("span",{className:"text-muted-foreground truncate",children:l("model.loadingModels")})]})});return a("div",{className:"inline-flex min-w-0 items-center gap-1.5",children:[r&&a(I,{open:Q,onOpenChange:X,children:[a(T,{children:[e(F,{render:e(B,{render:a(D,{"data-testid":"provider-trigger",variant:"ghost",disabled:w.disabled,className:h("h-7 shrink-0 gap-1 rounded-md px-1.5","hover:bg-accent"),children:[r.icon,e(O,{className:"size-2.5 shrink-0 opacity-60"})]})})}),e(A,{children:l("model.switchProvider")})]}),a(R,{side:"top",align:"end",sideOffset:4,className:"z-100 min-w-[10rem]",children:[r.groups.map((n,s)=>a(ee,{children:[s>0&&n.length>0&&e(d,{}),e(p,{value:r.value,onValueChange:r.onChange,options:n})]},s)),r.moreAction&&a(c,{children:[e(d,{}),a(z,{onClick:r.moreAction,className:"whitespace-nowrap",children:[e("span",{className:"min-w-0 flex-1 truncate",children:l("model.moreModels")}),e(P,{className:"size-4"})]})]})]})]}),a(I,{open:Y,onOpenChange:Z,children:[a(T,{children:[e(F,{render:e(B,{render:a(D,{"data-testid":"model-trigger","aria-busy":y,variant:"ghost",className:h("h-7 gap-1.5 rounded-md px-2 text-xs font-normal","hover:bg-accent","max-w-full min-w-0 shrink",N&&"h-7 gap-1 px-1.5 text-[11px]",S),...w,children:[e("span",{className:h("min-w-0 flex-1 truncate text-start",N&&"text-[11px]"),children:_(u.label)||l("model.selectModel")}),t&&a("span",{className:"text-muted-foreground grid shrink-0 justify-items-center",children:[e("span",{className:"invisible col-start-1 row-start-1",children:t.sizer??t.levels.reduce((n,s)=>s.name.length>n.length?s.name:n,"")}),e("span",{className:"col-start-1 row-start-1",children:t.levels.find((n)=>n.value===t.value)?.name??t.value})]}),y?e(V,{"data-testid":"model-switch-loading",className:"size-3 shrink-0 animate-spin"}):e(O,{className:h("size-3 shrink-0",N&&"size-2.5")})]})})}),e(A,{children:l("model.switchModel")})]}),a(R,{side:"top",align:"end",sideOffset:4,className:"z-100 w-auto max-w-[min(24rem,calc(100vw-1rem))] min-w-[14rem]",children:[g&&a(c,{children:[a("div",{className:"flex items-center gap-2 px-2 py-2",children:[g.icon,e("span",{className:"min-w-0 flex-1 truncate text-sm font-medium",children:g.name}),g.action]}),e(d,{})]}),a(k,{children:[W&&(H?e(z,{disabled:!0,className:"text-muted-foreground",children:l("model.loadingModels")}):o.length===0?e(z,{disabled:!0,className:"text-muted-foreground",children:l("model.noModelsAvailable")}):(()=>{let n=o.filter((i)=>!i.more),s=o.filter((i)=>i.more),M=n.length>0&&s.length>0,b=(i,m)=>({value:i.api_id,label:_(i.label),description:m?.noDescription?void 0:L?i.description:void 0}),C=(i)=>{let m=o.find((G)=>G.api_id===i);if(m)E(m)};return a(c,{children:[x?x.map((i)=>a(k,{children:[e(U,{className:"text-muted-foreground text-xs font-normal",children:i.name}),e(p,{value:u.api_id,onValueChange:C,itemClassName:"font-medium whitespace-nowrap",options:i.models.map((m)=>b(m))})]},i.id)):e(p,{value:u.api_id,onValueChange:C,itemClassName:"font-medium whitespace-nowrap",options:(M?n:o).map((i)=>b(i))}),!x&&M&&a(ie,{children:[e(te,{className:"font-medium whitespace-nowrap",children:l("model.moreModels")}),e(se,{children:e(p,{value:u.api_id,onValueChange:C,itemClassName:"font-medium whitespace-nowrap",options:s.map((i)=>b(i,{noDescription:!0}))})})]})]})})()),t&&a(c,{children:[e(d,{}),e(ne,{...t,disabled:w.disabled})]}),K.map((n)=>a(k,{children:[e(d,{}),e(U,{children:n.name}),e(p,{value:n.value,onValueChange:n.onChange,options:n.options,itemClassName:"whitespace-nowrap"})]},n.id)),v&&v.length>0&&a(c,{children:[!t&&e(d,{}),v.map((n)=>a("div",{className:"flex items-center justify-between gap-3 px-2 py-2.5",children:[e("span",{className:"text-sm font-medium",children:n.name}),e(ae,{"aria-label":n.name,disabled:w.disabled,checked:n.currentValue,onCheckedChange:(s)=>J?.(n.id,s)})]},n.id))]})]})]})]})]})}export{we as ModelSelect};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alwith/module-chat",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "exports": {
@@ -282,9 +282,14 @@
282
282
  "prepack": "bun run build"
283
283
  },
284
284
  "devDependencies": {
285
+ "@happy-dom/global-registrator": "^20.14.3",
286
+ "@testing-library/dom": "^10.4.1",
287
+ "@testing-library/react": "^16.3.3",
285
288
  "@types/react": "^19.3.0",
286
- "typescript": "^7.0.2",
287
- "@types/react-dom": "^19.3.0"
289
+ "@types/react-dom": "^19.3.0",
290
+ "react": "^19.3.0",
291
+ "react-dom": "^19.3.0",
292
+ "typescript": "^7.0.2"
288
293
  },
289
294
  "dependencies": {
290
295
  "entities": "^8.1.0",