MCPcopy
hub / github.com/srcbookdev/srcbook / OpenRouterModelSelector

Function OpenRouterModelSelector

packages/web/src/routes/settings.tsx:497–591  ·  view source on GitHub ↗
({ onSelectModel, currentModel }: OpenRouterModelSelectorProps)

Source from the content-addressed store, hash-verified

495};
496
497function OpenRouterModelSelector({ onSelectModel, currentModel }: OpenRouterModelSelectorProps) {
498 const { openRouterModels, isLoadingOpenRouterModels, refreshOpenRouterModels } = useSettings();
499
500 // Format model ID for display - show just the model name, not the full provider/model path
501 function formatModelName(modelId: string): string {
502 // Validate input to ensure we never return undefined
503 if (typeof modelId !== 'string' || modelId.length === 0) {
504 return '';
505 }
506
507 // Split by / and take the last part if it exists
508 const parts = modelId.split('/');
509 if (parts.length > 1) {
510 // @ts-expect-error - We know this is valid based on the length check
511 return parts[parts.length - 1];
512 }
513
514 // Return the original value
515 return modelId;
516 }
517
518 // Get model display name with helpful context
519 const getModelDisplayName = (model: OpenRouterModel): string => {
520 // model.id is defined as string in OpenRouterModel type
521 const baseName = model.name || formatModelName(model.id);
522 const contextLength = model.context_length
523 ? ` (${Math.floor(model.context_length / 1000)}k ctx)`
524 : '';
525 return `${baseName}${contextLength}`;
526 };
527
528 return (
529 <div className="space-y-2">
530 <div className="flex items-center gap-2">
531 <span className="text-sm opacity-70">Select an OpenRouter model:</span>
532 <TooltipProvider>
533 <Tooltip>
534 <TooltipTrigger asChild>
535 <Button
536 size="icon"
537 variant="ghost"
538 className="h-6 w-6"
539 onClick={refreshOpenRouterModels}
540 disabled={isLoadingOpenRouterModels}
541 aria-label="Refresh model list"
542 >
543 <RefreshCw size={16} className={isLoadingOpenRouterModels ? 'animate-spin' : ''} />
544 </Button>
545 </TooltipTrigger>
546 <TooltipContent>
547 <p>Refresh model list</p>
548 </TooltipContent>
549 </Tooltip>
550 </TooltipProvider>
551 </div>
552
553 {isLoadingOpenRouterModels ? (
554 <div className="flex items-center gap-2 text-sm opacity-70">

Callers

nothing calls this directly

Calls 2

useSettingsFunction · 0.90
getModelDisplayNameFunction · 0.85

Tested by

no test coverage detected