Compare commits

...
11 changed files with 307 additions and 124 deletions

No files matched your search

+33 -11
View File
@@ -196,6 +196,7 @@
"integrity": "sha512-e7jT4DxYvIDLk1ZHmU/m/mB19rex9sv0c2ftBtjSBv+kVM/902eh0fINUzD7UwLLNR+jU585GxUJ8/EBfAM5fw==",
"dev": true,
"license": "MIT",
"peer": true,
"dependencies": {
"@babel/code-frame": "^7.27.1",
"@babel/generator": "^7.28.5",
@@ -1831,6 +1832,7 @@
}
],
"license": "MIT",
"peer": true,
"engines": {
"node": ">=18"
},
@@ -1854,6 +1856,7 @@
}
],
"license": "MIT",
"peer": true,
"engines": {
"node": ">=18"
}
@@ -1875,6 +1878,7 @@
"resolved": "https://registry.npmjs.org/@dnd-kit/core/-/core-6.3.1.tgz",
"integrity": "sha512-xkGBRQQab4RLwgXxoqETICr6S5JlogafbhNsidmrkVv2YRs5MLwpjoF2qpiGjQt8S9AoxtIV603s0GIUpY5eYQ==",
"license": "MIT",
"peer": true,
"dependencies": {
"@dnd-kit/accessibility": "^3.1.1",
"@dnd-kit/utilities": "^3.2.2",
@@ -5459,8 +5463,7 @@
"resolved": "https://registry.npmjs.org/@types/aria-query/-/aria-query-5.0.4.tgz",
"integrity": "sha512-rfT93uj5s0PRL7EzccGMs3brplhcrghnDoV26NqKhCAS1hVo+WdNsPvE/yb6ilfr5hi2MEk6d5EWJTKdxg8jVw==",
"dev": true,
"license": "MIT",
"peer": true
"license": "MIT"
},
"node_modules/@types/cacheable-request": {
"version": "6.0.3",
@@ -5702,6 +5705,7 @@
"resolved": "https://registry.npmjs.org/@types/react/-/react-18.3.20.tgz",
"integrity": "sha512-IPaCZN7PShZK/3t6Q87pfTkRm6oLTd4vztyoj+cbHUF1g3FfVb2tFIL79uCRKEfv16AhqDMBywP2VW3KIZUvcg==",
"license": "MIT",
"peer": true,
"dependencies": {
"@types/prop-types": "*",
"csstype": "^3.0.2"
@@ -5713,6 +5717,7 @@
"integrity": "sha512-MEe3UeoENYVFXzoXEWsvcpg6ZvlrFNlOQ7EOsvhI3CfAXwzPfO8Qwuxd40nepsYKqyyVQnTdEfv68q91yLcKrQ==",
"devOptional": true,
"license": "MIT",
"peer": true,
"peerDependencies": {
"@types/react": "^18.0.0"
}
@@ -5817,6 +5822,7 @@
"integrity": "sha512-oU/OtYVydhXnumd0BobL9rkJg7wFJ9bFFPmSmB/bf/XWN85hlViji59ko6bSKBXyseT9V8l+CN1nwmlbiN0G7Q==",
"dev": true,
"license": "MIT",
"peer": true,
"dependencies": {
"@typescript-eslint/scope-manager": "8.31.1",
"@typescript-eslint/types": "8.31.1",
@@ -6176,6 +6182,7 @@
"resolved": "https://registry.npmjs.org/acorn/-/acorn-8.15.0.tgz",
"integrity": "sha512-NZyJarBfL7nWwIq+FDL6Zp/yHEhePMNnnJ0y3qfieCrmNvYct8uvtiV41UvlSe6apAfk0fY1FbWx+NwfmpvtTg==",
"license": "MIT",
"peer": true,
"bin": {
"acorn": "bin/acorn"
},
@@ -6679,6 +6686,7 @@
}
],
"license": "MIT",
"peer": true,
"dependencies": {
"baseline-browser-mapping": "^2.8.19",
"caniuse-lite": "^1.0.30001751",
@@ -6947,6 +6955,7 @@
"resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.6.0.tgz",
"integrity": "sha512-7VT13fmjotKpGipCW9JEQAusEPE+Ei8nl6/g4FBAmIm0GOOLMua9NDDo/DWp0ZAxCr3cPq5ZpBqmPAQgDda2Pw==",
"license": "MIT",
"peer": true,
"dependencies": {
"anymatch": "~3.1.2",
"braces": "~3.0.2",
@@ -7747,8 +7756,7 @@
"resolved": "https://registry.npmjs.org/dom-accessibility-api/-/dom-accessibility-api-0.5.16.tgz",
"integrity": "sha512-X7BJ2yElsnOJ30pZF4uIIDfBEVgF4XEBxL9Bxhy6dnrm5hkzqmsWHGTiHqRiITNhMyFLyAiWndIJP7Z1NTteDg==",
"dev": true,
"license": "MIT",
"peer": true
"license": "MIT"
},
"node_modules/dom-helpers": {
"version": "5.2.1",
@@ -7832,7 +7840,8 @@
"version": "8.6.0",
"resolved": "https://registry.npmjs.org/embla-carousel/-/embla-carousel-8.6.0.tgz",
"integrity": "sha512-SjWyZBHJPbqxHOzckOfo8lHisEaJWmwd23XppYFYVh10bU66/Pn5tkVkbkCMZVdbUE5eTCI2nD8OyIP4Z+uwkA==",
"license": "MIT"
"license": "MIT",
"peer": true
},
"node_modules/embla-carousel-react": {
"version": "8.6.0",
@@ -8146,6 +8155,7 @@
"integrity": "sha512-QldCVh/ztyKJJZLr4jXNUByx3gR+TDYZCRXEktiZoUR3PGy4qCmSbkxcIle8GEwGpb5JBZazlaJ/CxLidXdEbQ==",
"dev": true,
"license": "MIT",
"peer": true,
"dependencies": {
"@eslint-community/eslint-utils": "^4.2.0",
"@eslint-community/regexpp": "^4.12.1",
@@ -8411,6 +8421,7 @@
"resolved": "https://registry.npmjs.org/express/-/express-5.1.0.tgz",
"integrity": "sha512-DT9ck5YIRU+8GYzzU5kT3eHGA5iL+1Zd0EutOmTE9Dtk+Tvuzd23VBU+ec7HPNSTxXYO55gPV/hq4pSBJDjFpA==",
"license": "MIT",
"peer": true,
"dependencies": {
"accepts": "^2.0.0",
"body-parser": "^2.2.0",
@@ -9633,6 +9644,7 @@
}
],
"license": "MIT",
"peer": true,
"dependencies": {
"@babel/runtime": "^7.27.6"
},
@@ -10416,6 +10428,7 @@
"integrity": "sha512-Cvc9WUhxSMEo4McES3P7oK3QaXldCfNWp7pl2NNeiIFlCoLr3kfq9kb1fxftiwk1FLV7CvpvDfonxtzUDeSOPg==",
"dev": true,
"license": "MIT",
"peer": true,
"dependencies": {
"cssstyle": "^4.2.1",
"data-urls": "^5.0.0",
@@ -10812,7 +10825,6 @@
"integrity": "sha512-h5bgJWpxJNswbU7qCrV0tIKQCaS3blPDrqKWx+QxzuzL1zGUzij9XCWLrSLsJPu5t+eWA/ycetzYAO5IOMcWAQ==",
"dev": true,
"license": "MIT",
"peer": true,
"bin": {
"lz-string": "bin/bin.js"
}
@@ -12610,6 +12622,7 @@
}
],
"license": "MIT",
"peer": true,
"dependencies": {
"nanoid": "^3.3.8",
"picocolors": "^1.1.1",
@@ -12777,7 +12790,6 @@
"integrity": "sha512-Qb1gy5OrP5+zDf2Bvnzdl3jsTf1qXVMazbvCoKhtKqVs4/YK4ozX4gKQJJVyNe+cajNPn0KoC0MC3FUmaHWEmQ==",
"dev": true,
"license": "MIT",
"peer": true,
"dependencies": {
"ansi-regex": "^5.0.1",
"ansi-styles": "^5.0.0",
@@ -12793,7 +12805,6 @@
"integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==",
"dev": true,
"license": "MIT",
"peer": true,
"engines": {
"node": ">=8"
}
@@ -12804,7 +12815,6 @@
"integrity": "sha512-Cxwpt2SfTzTtXcfOlzGEee8O+c+MmUgGrNiBcXnuWxuFJHe6a5Hz7qwhwe5OgaSYI0IJvkLqWX1ASG+cJOkEiA==",
"dev": true,
"license": "MIT",
"peer": true,
"engines": {
"node": ">=10"
},
@@ -12817,8 +12827,7 @@
"resolved": "https://registry.npmjs.org/react-is/-/react-is-17.0.2.tgz",
"integrity": "sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w==",
"dev": true,
"license": "MIT",
"peer": true
"license": "MIT"
},
"node_modules/prismjs": {
"version": "1.30.0",
@@ -13026,6 +13035,7 @@
"resolved": "https://registry.npmjs.org/react/-/react-18.3.1.tgz",
"integrity": "sha512-wS+hAgJShR0KhEvPJArfuPVN1+Hz1t0Y6n5jLrGQbkb4urgPE/0Rve+1kMB1v/oWgHgm4WIcV+i7F2pTVj+2iQ==",
"license": "MIT",
"peer": true,
"dependencies": {
"loose-envify": "^1.1.0"
},
@@ -13052,6 +13062,7 @@
"resolved": "https://registry.npmjs.org/react-dom/-/react-dom-18.3.1.tgz",
"integrity": "sha512-5m4nQKp+rZRb09LNH59GM4BxTh9251/ylbKIbpe7TpGxfJ+9kv6BLkLBXIjjspbgbnIBNqlI23tRnTWT0snUIw==",
"license": "MIT",
"peer": true,
"dependencies": {
"loose-envify": "^1.1.0",
"scheduler": "^0.23.2"
@@ -13077,6 +13088,7 @@
"resolved": "https://registry.npmjs.org/react-hook-form/-/react-hook-form-7.56.1.tgz",
"integrity": "sha512-qWAVokhSpshhcEuQDSANHx3jiAEFzu2HAaaQIzi/r9FNPm1ioAvuJSD4EuZzWd7Al7nTRKcKPnBKO7sRn+zavQ==",
"license": "MIT",
"peer": true,
"engines": {
"node": ">=18.0.0"
},
@@ -13125,6 +13137,7 @@
"resolved": "https://registry.npmjs.org/react-markdown/-/react-markdown-10.1.0.tgz",
"integrity": "sha512-qKxVopLT/TyA6BX3Ue5NwabOsAzm0Q7kAPwq6L+wWDwisYs7R8vZ0nRXqq6rkueboxpkjvLGU9fWifiX/ZZFxQ==",
"license": "MIT",
"peer": true,
"dependencies": {
"@types/hast": "^3.0.0",
"@types/mdast": "^4.0.0",
@@ -13706,6 +13719,7 @@
"integrity": "sha512-C5VvvgCCyfyotVITIAv+4efVytl5F7wt+/I2i9q9GZcEXW9BP52YYOXC58igUi+LFZVHukErIIqQSWwv/M3WRw==",
"devOptional": true,
"license": "MIT",
"peer": true,
"dependencies": {
"@types/estree": "1.0.7"
},
@@ -14820,6 +14834,7 @@
"resolved": "https://registry.npmjs.org/tailwindcss/-/tailwindcss-3.4.17.tgz",
"integrity": "sha512-w33E2aCvSDP0tW9RZuNXadXlkHXqFzSkQew/aIa2i/Sj8fThxwovwlXHSPXTbAHwEIhBFXAedUhP2tueAKP8Og==",
"license": "MIT",
"peer": true,
"dependencies": {
"@alloc/quick-lru": "^5.2.0",
"arg": "^5.0.2",
@@ -15023,6 +15038,7 @@
"integrity": "sha512-M7BAV6Rlcy5u+m6oPhAPFgJTzAioX/6B0DxyvDlo9l8+T3nLKbrczg2WLUyzd45L8RqfUMyGPzekbMvX2Ldkwg==",
"dev": true,
"license": "MIT",
"peer": true,
"engines": {
"node": ">=12"
},
@@ -15318,6 +15334,7 @@
"integrity": "sha512-p1diW6TqL9L07nNxvRMM7hMMw4c5XOo/1ibL4aAIGmSAt9slTE1Xgw5KWuof2uTOvCg9BY7ZRi+GaF+7sfgPeQ==",
"devOptional": true,
"license": "Apache-2.0",
"peer": true,
"bin": {
"tsc": "bin/tsc",
"tsserver": "bin/tsserver"
@@ -15845,6 +15862,7 @@
"integrity": "sha512-cZn6NDFE7wdTpINgs++ZJ4N49W2vRp8LCKrn3Ob1kYNtOo21vfDoaV5GzBfLU4MovSAB8uNRm4jgzVQZ+mBzPQ==",
"dev": true,
"license": "MIT",
"peer": true,
"dependencies": {
"esbuild": "^0.25.0",
"fdir": "^6.4.4",
@@ -15989,6 +16007,7 @@
"integrity": "sha512-M7BAV6Rlcy5u+m6oPhAPFgJTzAioX/6B0DxyvDlo9l8+T3nLKbrczg2WLUyzd45L8RqfUMyGPzekbMvX2Ldkwg==",
"dev": true,
"license": "MIT",
"peer": true,
"engines": {
"node": ">=12"
},
@@ -16459,6 +16478,7 @@
"integrity": "sha512-B/gBuNg5SiMTrPkC+A2+cW0RszwxYmn6VYxB/inlBStS5nx6xHIt/ehKRhIMhqusl7a8LjQoZnjCs5vhwxOQ1g==",
"dev": true,
"license": "MIT",
"peer": true,
"dependencies": {
"fast-deep-equal": "^3.1.3",
"fast-uri": "^3.0.1",
@@ -16535,6 +16555,7 @@
"integrity": "sha512-fS6iqSPZDs3dr/y7Od6y5nha8dW1YnbgtsyotCVvoFGKbERG++CVRFv1meyGDE1SNItQA8BrnCw7ScdAhRJ3XQ==",
"dev": true,
"license": "MIT",
"peer": true,
"bin": {
"rollup": "dist/bin/rollup"
},
@@ -16994,6 +17015,7 @@
"resolved": "https://registry.npmjs.org/zod/-/zod-3.25.76.tgz",
"integrity": "sha512-gzUt/qt81nXsFGKIFcC3YnfEAx5NkunCfnDlvuBSSFS02bcXu4Lmea0AFIUwbLWxWPx3d9p8S5QoaujKcNQxcQ==",
"license": "MIT",
"peer": true,
"funding": {
"url": "https://github.com/sponsors/colinhacks"
}
+51 -25
View File
@@ -35,25 +35,51 @@ export function AppShowcase() {
}, [config.showcaseModerator]);
const isModerator = user?.pubkey === MODERATOR_HEX;
// Filter and shuffle submissions - memoized with stable dependency
const { templateApps, featuredApps, approvedApps } = useMemo(() => {
// Filter visible submissions
const visibleSubmissions = submissions.filter(app => !app.isHidden);
// Separate template apps from other apps
const templates = shuffleArray(visibleSubmissions.filter(app => app.appTags.includes('Template')));
const nonTemplateSubmissions = visibleSubmissions.filter(app => !app.appTags.includes('Template'));
// Shuffle featured and approved apps for random display order
const featured = shuffleArray(nonTemplateSubmissions.filter(app => app.isFeatured));
const approved = shuffleArray(nonTemplateSubmissions.filter(app => app.isApproved && !app.isFeatured));
// Categorize and organize submissions - single pass for efficiency
const {
displayedFeaturedApps,
displayedTemplateApps,
moreApps
} = useMemo(() => {
const DISPLAY_LIMIT = 6;
// Single pass categorization
const templates: typeof submissions = [];
const featured: typeof submissions = [];
const approved: typeof submissions = [];
for (const app of submissions) {
if (app.isHidden) continue;
const isTemplate = app.appTags.includes('Template');
const isFeatured = app.isFeatured;
const isApproved = app.isApproved;
if (isTemplate) {
templates.push(app);
} else if (isFeatured) {
featured.push(app);
} else if (isApproved) {
approved.push(app);
}
}
// Shuffle each category once
const shuffledTemplates = shuffleArray(templates);
const shuffledFeatured = shuffleArray(featured);
const shuffledApproved = shuffleArray(approved);
// Split into display and more sections
return {
templateApps: templates,
featuredApps: featured,
approvedApps: approved,
displayedFeaturedApps: shuffledFeatured.slice(0, DISPLAY_LIMIT),
displayedTemplateApps: shuffledTemplates.slice(0, DISPLAY_LIMIT),
moreApps: [
...shuffledFeatured.slice(DISPLAY_LIMIT),
...shuffledTemplates.slice(DISPLAY_LIMIT),
...shuffledApproved,
],
};
}, [submissions]); // Only depend on submissions, not intermediate filtered arrays
}, [submissions]);
// Don't show showcase if disabled in settings
if (!config.showcaseEnabled) {
@@ -124,7 +150,7 @@ export function AppShowcase() {
{/* Apps Grid */}
<div className="space-y-12">
{/* Featured Apps */}
{featuredApps.length > 0 && (
{displayedFeaturedApps.length > 0 && (
<div>
<div className="flex items-start gap-3 mb-6">
<div className="flex-none w-8 h-8 bg-yellow-100 dark:bg-yellow-900/30 rounded-lg flex items-center justify-center">
@@ -136,7 +162,7 @@ export function AppShowcase() {
</div>
</div>
<div className="grid md:grid-cols-2 lg:grid-cols-3 gap-6">
{featuredApps.slice(0, 6).map((app) => (
{displayedFeaturedApps.map((app) => (
<AppShowcaseCard
key={app.id}
app={app}
@@ -149,7 +175,7 @@ export function AppShowcase() {
)}
{/* Templates Section */}
{templateApps.length > 0 && (
{displayedTemplateApps.length > 0 && (
<div>
<div className="flex items-start gap-3 mb-6">
<div className="flex-none w-8 h-8 bg-purple-100 dark:bg-purple-900/30 rounded-lg flex items-center justify-center">
@@ -161,7 +187,7 @@ export function AppShowcase() {
</div>
</div>
<div className="grid md:grid-cols-2 lg:grid-cols-3 gap-6">
{templateApps.slice(0, 6).map((app) => (
{displayedTemplateApps.map((app) => (
<AppShowcaseCard
key={app.id}
app={app}
@@ -173,8 +199,8 @@ export function AppShowcase() {
</div>
)}
{/* More Apps (Approved) - Collapsible */}
{approvedApps.length > 0 && (
{/* More Apps (Remaining Featured, Templates, and Approved) - Collapsible */}
{moreApps.length > 0 && (
<div>
<Collapsible open={showAllApps} onOpenChange={setShowAllApps}>
<CollapsibleTrigger asChild>
@@ -185,7 +211,7 @@ export function AppShowcase() {
</div>
<div className="text-left">
<h3 className="text-xl font-bold text-foreground">
{t('moreAppsCount', { count: approvedApps.length })}
{t('moreAppsCount', { count: moreApps.length })}
</h3>
<p className="text-sm text-muted-foreground">
{showAllApps ? t('clickToCollapse') : t('clickToViewMore')}
@@ -196,7 +222,7 @@ export function AppShowcase() {
</CollapsibleTrigger>
<CollapsibleContent>
<div className="grid md:grid-cols-2 lg:grid-cols-3 gap-6">
{approvedApps.map((app) => (
{moreApps.map((app) => (
<AppShowcaseCard
key={app.id}
app={app}
+27 -10
View File
@@ -111,11 +111,13 @@ describe('ModelSelector', () => {
// Recently used section should NOT be visible
expect(screen.queryByText('Recently Used')).not.toBeInTheDocument();
// provider1 should be hidden since all its models are in recently used
expect(screen.queryByText('provider1')).not.toBeInTheDocument();
// provider1 should still be visible (models appear in both sections now)
expect(screen.getByText('provider1')).toBeInTheDocument();
expect(screen.getByText('model1')).toBeInTheDocument();
expect(screen.getByText('model2')).toBeInTheDocument();
// provider2 should still show with model3
expect(screen.getByText('provider2/model3')).toBeInTheDocument();
expect(screen.getByText('model3')).toBeInTheDocument();
});
it('shows recently used section when less than 5 models but some recently used are not available', async () => {
@@ -160,11 +162,17 @@ describe('ModelSelector', () => {
// Wait for the dropdown to open
await waitFor(() => {
expect(screen.getByText('provider1')).toBeInTheDocument();
// provider1 appears in both recently used and available sections
const provider1Elements = screen.queryAllByText('provider1');
expect(provider1Elements.length).toBeGreaterThan(0);
});
// Recently used section SHOULD be visible
expect(screen.getByText('Recently Used')).toBeInTheDocument();
// provider1 should appear in both sections (recently used and available)
const provider1Elements = screen.queryAllByText('provider1');
expect(provider1Elements.length).toBeGreaterThanOrEqual(1);
});
it('shows recently used section when 5 or more models are available', async () => {
@@ -217,13 +225,22 @@ describe('ModelSelector', () => {
// Recently used section SHOULD be visible
expect(screen.getByText('Recently Used')).toBeInTheDocument();
// provider1 should be hidden since all its models are in recently used
expect(screen.queryByText('provider1')).not.toBeInTheDocument();
// provider1 should still be visible (models appear in both sections now)
// Use queryAllByText since provider1 appears as a heading in both sections
const provider1Elements = screen.queryAllByText('provider1');
expect(provider1Elements.length).toBeGreaterThanOrEqual(1);
// Models should be visible (display text is just the model name, not full ID)
// model1 and model2 appear in both recently used and available sections
const model1Elements = screen.queryAllByText('model1');
expect(model1Elements.length).toBeGreaterThanOrEqual(1);
const model2Elements = screen.queryAllByText('model2');
expect(model2Elements.length).toBeGreaterThanOrEqual(1);
// provider2 and provider3 should still show
expect(screen.getByText('provider2/model3')).toBeInTheDocument();
expect(screen.getByText('provider2/model4')).toBeInTheDocument();
expect(screen.getByText('provider3/model5')).toBeInTheDocument();
// provider2 and provider3 should still show (only in available section)
expect(screen.getByText('model3')).toBeInTheDocument();
expect(screen.getByText('model4')).toBeInTheDocument();
expect(screen.getByText('model5')).toBeInTheDocument();
});
it('hides recently used section when no recently used models exist', async () => {
+185 -78
View File
@@ -1,10 +1,11 @@
import { useState, useMemo, useEffect, memo } from 'react';
import { useNavigate } from 'react-router-dom';
import { useTranslation } from 'react-i18next';
import { Decimal } from 'decimal.js';
import { Check, ChevronDown, Edit3, RefreshCw, AlertCircle, Settings, TriangleAlert } from 'lucide-react';
import { Button } from '@/components/ui/button';
import { Input } from '@/components/ui/input';
import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover';
import { Dialog, DialogContent, DialogTrigger } from '@/components/ui/dialog';
import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, CommandSeparator } from '@/components/ui/command';
import { Skeleton } from '@/components/ui/skeleton';
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@/components/ui/tooltip';
@@ -14,6 +15,72 @@ import { useIsMobile } from '@/hooks/useIsMobile';
import { ModelPricing } from '@/components/ModelPricing';
import { cn } from '@/lib/utils';
// Type for model (matches ProviderModel from useProviderModels)
type ModelType = {
id: string;
name?: string;
provider: string;
fullId: string;
description?: string;
contextLength?: number;
pricing?: {
prompt: Decimal;
completion: Decimal;
};
};
// Interface for grouped models by provider
interface ModelGroup {
provider: string;
models: ModelType[];
}
// Parse model ID into components (provider/company/model or provider/model)
function parseModelId(fullId: string) {
const parts = fullId.split('/');
return {
provider: parts[0] || '',
company: parts.length >= 3 ? parts[1] : null,
modelName: parts.length >= 3 ? parts.slice(2).join('/') : parts[1] || '',
};
}
// Group models by provider and sort
function groupModelsByProvider(models: ModelType[], excludeIds: Set<string>): ModelGroup[] {
const groups: Record<string, ModelType[]> = {};
// Group by provider
models.forEach(model => {
if (!excludeIds.has(model.fullId)) {
const { provider } = parseModelId(model.fullId);
if (!groups[provider]) groups[provider] = [];
groups[provider].push(model);
}
});
// Sort models within each group and convert to array
return Object.entries(groups)
.map(([provider, models]) => ({
provider,
models: models.sort((a, b) => {
const aParsed = parseModelId(a.fullId);
const bParsed = parseModelId(b.fullId);
// Sort by company, then model name
if (aParsed.company && bParsed.company) {
const diff = aParsed.company.localeCompare(bParsed.company);
if (diff !== 0) return diff;
}
return aParsed.modelName.localeCompare(bParsed.modelName);
}),
}))
.sort((a, b) => {
// Shakespeare first, then alphabetical
if (a.provider === 'shakespeare') return -1;
if (b.provider === 'shakespeare') return 1;
return a.provider.localeCompare(b.provider);
});
}
interface ModelSelectorProps {
value: string;
onChange: (value: string) => void;
@@ -24,6 +91,46 @@ interface ModelSelectorProps {
onOpenChange?: (open: boolean) => void;
}
// Render a model item in the list
const ModelItem = memo(({ model, currentValue, onSelect, valuePrefix = '' }: {
model: ModelType;
currentValue: string;
onSelect: (value: string) => void;
valuePrefix?: string;
}) => {
const parsed = parseModelId(model.fullId);
const displayText = parsed.company
? `${parsed.company}/${parsed.modelName}`
: parsed.modelName;
// Use prefix to make value unique (prevents both recently used and available from highlighting together)
const uniqueValue = valuePrefix ? `${valuePrefix}-${model.fullId}` : model.fullId;
return (
<CommandItem
key={model.fullId}
value={uniqueValue}
keywords={[model.fullId]}
onSelect={() => onSelect(model.fullId)}
className="cursor-pointer"
title={model.fullId}
>
<Check
className={cn(
"mr-2 h-4 w-4 shrink-0",
currentValue === model.fullId ? "opacity-100" : "opacity-0"
)}
/>
<span className="flex-1 min-w-0 truncate">
{displayText}
</span>
{model.pricing && (
<ModelPricing pricing={model.pricing} className="ml-2 shrink-0" />
)}
</CommandItem>
);
});
export const ModelSelector = memo(function ModelSelector({
value,
onChange,
@@ -52,25 +159,11 @@ export const ModelSelector = memo(function ModelSelector({
const recentlyUsedModels = useMemo(() => settings.recentlyUsedModels || [], [settings.recentlyUsedModels]);
// Create a Set of recently used model IDs for efficient lookup
const recentlyUsedSet = useMemo(() => new Set(recentlyUsedModels), [recentlyUsedModels]);
// Group models by provider, excluding models that are in the recently used section
const modelsByProvider = useMemo(() => {
const groups: Record<string, typeof models> = {};
for (const model of models) {
// Skip models that are already shown in recently used
if (recentlyUsedSet.has(model.fullId)) {
continue;
}
if (!groups[model.provider]) {
groups[model.provider] = [];
}
groups[model.provider].push(model);
}
return groups;
}, [models, recentlyUsedSet]);
// Group models by provider (don't exclude recently used - they should appear in both sections)
const modelGroups = useMemo(
() => groupModelsByProvider(models, new Set()),
[models]
);
// Determine if we should show the "Recently Used" section
const shouldShowRecentlyUsed = useMemo(() => {
@@ -95,6 +188,15 @@ export const ModelSelector = memo(function ModelSelector({
return !allRecentlyUsedAreAvailable;
}, [recentlyUsedModels, models]);
// Group recently used models (same structure as available models)
const recentlyUsedGroups = useMemo(() => {
if (!shouldShowRecentlyUsed) return [];
const recentModels = recentlyUsedModels
.map(id => models.find(m => m.fullId === id))
.filter((m): m is ModelType => m !== undefined);
return groupModelsByProvider(recentModels, new Set());
}, [recentlyUsedModels, models, shouldShowRecentlyUsed]);
// Check if the current model is free
const isCurrentModelFree = useMemo(() => {
if (!value) return false;
@@ -271,8 +373,8 @@ export const ModelSelector = memo(function ModelSelector({
</TooltipContent>
</Tooltip>
)}
<Popover open={open} onOpenChange={setOpen}>
<PopoverTrigger asChild>
<Dialog open={open} onOpenChange={setOpen}>
<DialogTrigger asChild>
<Button
variant="ghost"
role="combobox"
@@ -287,13 +389,28 @@ export const ModelSelector = memo(function ModelSelector({
</span>
<ChevronDown className="size-3 shrink-0 opacity-50" />
</Button>
</PopoverTrigger>
<PopoverContent className="p-0 w-80" align="end">
<Command>
</DialogTrigger>
<DialogContent
className={cn(
"p-0 max-w-[90vw] sm:max-w-lg md:max-w-2xl",
"max-h-[85vh] overflow-hidden flex flex-col"
)}
onOpenAutoFocus={(e) => e.preventDefault()}
>
<Command
className="flex flex-col h-full overflow-hidden"
filter={(value, search, keywords) => {
// Substring search: match if search appears anywhere in value or keywords
const s = search.toLowerCase();
if (value.toLowerCase().includes(s)) return 1;
if (keywords?.some(k => typeof k === 'string' && k.toLowerCase().includes(s))) return 1;
return 0;
}}
>
{(isConfigured && models.length >= 5) && (
<CommandInput placeholder={t('searchModels')} className="h-9" />
<CommandInput placeholder={t('searchModels')} className="h-9" autoFocus={false} />
)}
<CommandList>
<CommandList className="flex-1 overflow-y-auto overflow-x-hidden">
<CommandEmpty>
<div className="py-6 text-center text-sm text-muted-foreground">
<p>{t('noModelsFound')}</p>
@@ -301,34 +418,31 @@ export const ModelSelector = memo(function ModelSelector({
</div>
</CommandEmpty>
{/* Recently Used section */}
{shouldShowRecentlyUsed && (
<CommandGroup heading={t('recentlyUsed')}>
{recentlyUsedModels.map((modelId) => {
const modelData = models.find(m => m.fullId === modelId);
return (
<CommandItem
key={modelId}
value={modelId}
onSelect={() => handleSelect(modelId)}
className="cursor-pointer"
>
<Check
className={cn(
"mr-2 h-4 w-4",
value === modelId ? "opacity-100" : "opacity-0"
)}
<>
<CommandGroup heading={t('recentlyUsed')} />
{recentlyUsedGroups.map((group) => (
<CommandGroup key={`recent-${group.provider}`} heading={group.provider}>
{group.models.map((model) => (
<ModelItem
key={model.fullId}
model={model}
currentValue={value}
onSelect={handleSelect}
valuePrefix="recent"
/>
<span className="truncate flex-1">{modelId}</span>
{modelData?.pricing && (
<ModelPricing pricing={modelData.pricing} className="ml-2" />
)}
</CommandItem>
);
})}
</CommandGroup>
))}
</CommandGroup>
))}
{modelGroups.length > 0 && <CommandSeparator />}
</>
)}
{shouldShowRecentlyUsed && <CommandSeparator />}
{/* Available Models section */}
{!isLoading && modelGroups.length > 0 && (
<CommandGroup heading={t('availableModels')} />
)}
{/* Loading state */}
{isLoading && (
@@ -366,32 +480,25 @@ export const ModelSelector = memo(function ModelSelector({
</CommandGroup>
)}
{/* Provider models */}
{!isLoading && Object.entries(modelsByProvider).map(([provider, providerModels]) => (
<div key={provider}>
<CommandSeparator />
<CommandGroup heading={provider}>
{providerModels.map((model) => (
<CommandItem
key={model.fullId}
value={model.fullId}
onSelect={() => handleSelect(model.fullId)}
className="cursor-pointer"
>
<Check
className={cn(
"mr-2 h-4 w-4",
value === model.fullId ? "opacity-100" : "opacity-0"
)}
/>
<span className="truncate flex-1">{model.fullId}</span>
{model.pricing && (
<ModelPricing pricing={model.pricing} className="ml-2" />
)}
</CommandItem>
))}
</CommandGroup>
{/* No models available state */}
{!isLoading && !error && !shouldShowRecentlyUsed && modelGroups.length === 0 && (
<div className="py-12 text-center text-sm text-muted-foreground">
<p>{t('noModelsFound')}</p>
</div>
)}
{/* Provider models */}
{!isLoading && modelGroups.map((group) => (
<CommandGroup key={group.provider} heading={group.provider}>
{group.models.map((model) => (
<ModelItem
key={model.fullId}
model={model}
currentValue={value}
onSelect={handleSelect}
/>
))}
</CommandGroup>
))}
{/* Custom model option and manage providers - moved to bottom */}
@@ -418,8 +525,8 @@ export const ModelSelector = memo(function ModelSelector({
</CommandGroup>
</CommandList>
</Command>
</PopoverContent>
</Popover>
</DialogContent>
</Dialog>
</div>
</TooltipProvider>
);
+5
View File
@@ -113,11 +113,16 @@
border-color: hsl(var(--border));
}
html {
overscroll-behavior: none;
}
body {
background-color: hsl(var(--background));
color: hsl(var(--foreground));
font-family: 'Inter Variable', 'Inter', 'system-ui', 'sans-serif';
font-feature-settings: "rlig" 1, "calt" 1;
overscroll-behavior: none;
}
/* GitHub-style scrollbars */
+1
View File
@@ -281,6 +281,7 @@
"noModelsFound": "No models found.",
"tryCustomModel": "Try using a custom model instead.",
"recentlyUsed": "Recently Used",
"availableModels": "Available Models",
"errorLoadingModels": "Error Loading Models",
"apiAuthenticationFailed": "API Authentication Failed",
"invalidApiKey": "Invalid API key for {{provider}}. Please check your API key in Settings.",
+1
View File
@@ -267,6 +267,7 @@
"noModelsFound": "Ba a sami samfura ba.",
"tryCustomModel": "Gwada amfani da samfuri na musamman.",
"recentlyUsed": "An yi amfani da su kwanan nan",
"availableModels": "Samfura Masu Samuwa",
"errorLoadingModels": "Kuskure wajen Lodin Samfura",
"apiAuthenticationFailed": "Gazawar Tabbatarwar API",
"invalidApiKey": "Maɓallin API na {{provider}} ba daidai ba ne. Da fatan za a duba maɓallin API a cikin Saitunan.",
+1
View File
@@ -267,6 +267,7 @@
"noModelsFound": "Ahụghị ụdịdị ọ bụla.",
"tryCustomModel": "Gbalịa iji ụdịdị omenala kama.",
"recentlyUsed": "Ejiri Na Nso Nso A",
"availableModels": "Ụdịdị Dị",
"errorLoadingModels": "Njehie Na-ebu Ụdịdị",
"contextUsage": "Ojiji ọnọdụ: {{tokens}} / {{total}} tokens ({{percentage}}%)",
"totalCostSession": "Mkpokọta ọnụ ahịa maka oge nkata a",
+1
View File
@@ -277,6 +277,7 @@
"noModelsFound": "Nenhum modelo encontrado.",
"tryCustomModel": "Tente usar um modelo personalizado.",
"recentlyUsed": "Usados Recentemente",
"availableModels": "Modelos Disponíveis",
"errorLoadingModels": "Erro ao Carregar Modelos",
"apiAuthenticationFailed": "Falha na Autenticação da API",
"invalidApiKey": "Chave de API inválida para {{provider}}. Verifique sua chave de API nas Configurações.",
+1
View File
@@ -267,6 +267,7 @@
"noModelsFound": "Ko si awọn awoṣe ti a ri.",
"tryCustomModel": "Gbiyanju lilo awoṣe aṣa dipo.",
"recentlyUsed": "Ti a Lo Laipẹ",
"availableModels": "Awọn awoṣe Ti O Wa",
"errorLoadingModels": "Aṣiṣe Gbigbe Awọn awoṣe",
"contextUsage": "Lilo aaye oro: {{tokens}} / {{total}} awọn token ({{percentage}}%)",
"totalCostSession": "Lapapọ iye owo fun igba ibaraẹnisọrọ yii",
+1
View File
@@ -277,6 +277,7 @@
"noModelsFound": "未找到模型。",
"tryCustomModel": "尝试使用自定义模型。",
"recentlyUsed": "最近使用",
"availableModels": "可用模型",
"errorLoadingModels": "加载模型时出错",
"apiAuthenticationFailed": "API身份验证失败",
"invalidApiKey": "{{provider}}的API密钥无效。请在设置中检查您的API密钥。",