@alwith/module-chat 0.1.1 → 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.
@@ -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.1",
3
+ "version": "0.1.2",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "exports": {