All files / client/src/components model-selector-dialog.tsx

0% Statements 0/23
0% Branches 0/4
0% Functions 0/13
0% Lines 0/22

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174                                                                                                                                                                                                                                                                                                                                                           
import { useState, useEffect } from "react";
import {
  Dialog,
  DialogContent,
  DialogDescription,
  DialogHeader,
  DialogTitle,
  DialogFooter,
} from "@/components/ui/dialog";
import { Button } from "@/components/ui/button";
import { Checkbox } from "@/components/ui/checkbox";
import { Label } from "@/components/ui/label";
import { Badge } from "@/components/ui/badge";
 
interface ModelOption {
  id: string;
  name: string;
  provider: string;
  description: string;
}
 
interface ModelSelectorDialogProps {
  open: boolean;
  onOpenChange: (open: boolean) => void;
  selectedModels: string[];
  onConfirm: (models: string[]) => void;
}
 
const availableModels: ModelOption[] = [
  {
    id: "claude-sonnet-4-5",
    name: "Claude Sonnet 4.5",
    provider: "Anthropic",
    description: "Latest Claude model, excellent for complex reasoning and coding",
  },
  {
    id: "gpt-4o",
    name: "GPT-4o",
    provider: "OpenAI",
    description: "OpenAI's most advanced model with multimodal capabilities",
  },
  {
    id: "gemini-2.0-flash",
    name: "Gemini 2.0 Flash",
    provider: "Google",
    description: "Fast and efficient Google AI model with strong performance",
  },
];
 
const providerColors: Record<string, string> = {
  Anthropic: "bg-orange-500",
  OpenAI: "bg-green-500",
  Google: "bg-blue-500",
};
 
export function ModelSelectorDialog({
  open,
  onOpenChange,
  selectedModels,
  onConfirm
}: ModelSelectorDialogProps) {
  const [tempSelected, setTempSelected] = useState<string[]>(selectedModels);
 
  // Sync tempSelected with parent selectedModels when dialog opens or selectedModels changes
  useEffect(() => {
    if (open) {
      setTempSelected(selectedModels);
    }
  }, [open, selectedModels]);
 
  const handleToggle = (modelId: string) => {
    setTempSelected(prev => 
      prev.includes(modelId) 
        ? prev.filter(id => id !== modelId)
        : [...prev, modelId]
    );
  };
 
  const handleConfirm = () => {
    onConfirm(tempSelected);
    onOpenChange(false);
  };
 
  const handleSelectAll = () => {
    setTempSelected(availableModels.map(m => m.id));
  };
 
  const handleClearAll = () => {
    setTempSelected([]);
  };
 
  return (
    <Dialog open={open} onOpenChange={onOpenChange}>
      <DialogContent className="max-w-2xl">
        <DialogHeader>
          <DialogTitle>Select Models to Test</DialogTitle>
          <DialogDescription>
            Choose which AI models to run your prompt against. By default, all models are selected.
          </DialogDescription>
        </DialogHeader>
 
        <div className="space-y-4 py-4">
          <div className="flex gap-2">
            <Button 
              variant="outline" 
              size="sm" 
              onClick={handleSelectAll}
            >
              Select All
            </Button>
            <Button 
              variant="outline" 
              size="sm" 
              onClick={handleClearAll}
            >
              Clear All
            </Button>
            <div className="flex-1" />
            <span className="text-sm text-muted-foreground">
              {tempSelected.length} of {availableModels.length} selected
            </span>
          </div>
 
          <div className="space-y-3">
            {availableModels.map(model => (
              <div
                key={model.id}
                className="flex items-start space-x-3 p-4 border rounded-lg hover:bg-muted/50 cursor-pointer"
                onClick={() => handleToggle(model.id)}
              >
                <Checkbox
                  id={model.id}
                  checked={tempSelected.includes(model.id)}
                  onCheckedChange={() => handleToggle(model.id)}
                />
                <div className="flex-1">
                  <div className="flex items-center gap-2">
                    <Label 
                      htmlFor={model.id} 
                      className="font-semibold cursor-pointer"
                    >
                      {model.name}
                    </Label>
                    <Badge 
                      className={`${providerColors[model.provider]} text-white`}
                    >
                      {model.provider}
                    </Badge>
                  </div>
                  <p className="text-sm text-muted-foreground mt-1">
                    {model.description}
                  </p>
                </div>
              </div>
            ))}
          </div>
        </div>
 
        <DialogFooter>
          <Button variant="outline" onClick={() => onOpenChange(false)}>
            Cancel
          </Button>
          <Button 
            onClick={handleConfirm}
            disabled={tempSelected.length === 0}
          >
            Confirm Selection
          </Button>
        </DialogFooter>
      </DialogContent>
    </Dialog>
  );
}