mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 12:24:30 +01:00
Update provider management and model selection UI
This commit is contained in:
1 parent
23ec317c5c
commit
e2e6ca07ae
3 files changed
+547
-324
No files matched your search
@@ -92,6 +92,11 @@ export class OpenCodeClient {
|
||||
}
|
||||
|
||||
async getProviders() {
|
||||
const response = await this.client.get('/provider')
|
||||
return response.data
|
||||
}
|
||||
|
||||
async getConfigProviders() {
|
||||
const response = await this.client.get('/config/providers')
|
||||
return response.data
|
||||
}
|
||||
|
||||
+229
-146
@@ -1,6 +1,63 @@
|
||||
import { settingsApi } from "./settings";
|
||||
import axios from "axios";
|
||||
import { API_BASE_URL } from "@/config";
|
||||
import { settingsApi } from "./settings";
|
||||
|
||||
export type ProviderSource = "configured" | "local" | "builtin";
|
||||
|
||||
export interface OpenCodeModel {
|
||||
id: string;
|
||||
providerID: string;
|
||||
name: string;
|
||||
api: {
|
||||
id: string;
|
||||
url?: string;
|
||||
npm: string;
|
||||
};
|
||||
status: "active" | "deprecated";
|
||||
headers: Record<string, string>;
|
||||
options: Record<string, unknown>;
|
||||
cost: {
|
||||
input: number;
|
||||
output: number;
|
||||
cache: {
|
||||
read: number;
|
||||
write: number;
|
||||
};
|
||||
};
|
||||
limit: {
|
||||
context: number;
|
||||
output: number;
|
||||
};
|
||||
capabilities: {
|
||||
temperature: boolean;
|
||||
reasoning: boolean;
|
||||
attachment: boolean;
|
||||
toolcall: boolean;
|
||||
input: {
|
||||
text: boolean;
|
||||
audio: boolean;
|
||||
image: boolean;
|
||||
video: boolean;
|
||||
pdf: boolean;
|
||||
};
|
||||
output: {
|
||||
text: boolean;
|
||||
audio: boolean;
|
||||
image: boolean;
|
||||
video: boolean;
|
||||
pdf: boolean;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
export interface OpenCodeProvider {
|
||||
id: string;
|
||||
source: "custom" | "builtin";
|
||||
name: string;
|
||||
env: string[];
|
||||
options: Record<string, unknown>;
|
||||
models: Record<string, OpenCodeModel>;
|
||||
}
|
||||
|
||||
export interface Model {
|
||||
id: string;
|
||||
@@ -40,6 +97,7 @@ export interface Provider {
|
||||
npm?: string;
|
||||
models: Record<string, Model>;
|
||||
options?: Record<string, unknown>;
|
||||
source?: ProviderSource;
|
||||
}
|
||||
|
||||
export interface ProviderWithModels {
|
||||
@@ -49,168 +107,193 @@ export interface ProviderWithModels {
|
||||
env: string[];
|
||||
npm?: string;
|
||||
models: Model[];
|
||||
source: ProviderSource;
|
||||
}
|
||||
|
||||
// Default providers for common OpenCode setups
|
||||
const DEFAULT_PROVIDERS: Provider[] = [
|
||||
{
|
||||
id: "anthropic",
|
||||
name: "Anthropic",
|
||||
api: "https://api.anthropic.com",
|
||||
env: ["ANTHROPIC_API_KEY"],
|
||||
npm: "@anthropic-ai/sdk",
|
||||
models: {
|
||||
"claude-3-5-sonnet-20241022": {
|
||||
id: "claude-3-5-sonnet-20241022",
|
||||
name: "Claude 3.5 Sonnet (October 2024)",
|
||||
release_date: "2024-10-22",
|
||||
attachment: true,
|
||||
reasoning: false,
|
||||
temperature: true,
|
||||
tool_call: true,
|
||||
cost: { input: 3, output: 15 },
|
||||
limit: { context: 200000, output: 8192 },
|
||||
modalities: { input: ["text", "image"], output: ["text"] },
|
||||
experimental: false,
|
||||
},
|
||||
"claude-3-5-haiku-20241022": {
|
||||
id: "claude-3-5-haiku-20241022",
|
||||
name: "Claude 3.5 Haiku (October 2024)",
|
||||
release_date: "2024-10-22",
|
||||
attachment: true,
|
||||
reasoning: false,
|
||||
temperature: true,
|
||||
tool_call: true,
|
||||
cost: { input: 1, output: 5 },
|
||||
limit: { context: 200000, output: 8192 },
|
||||
modalities: { input: ["text", "image"], output: ["text"] },
|
||||
experimental: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "openai",
|
||||
name: "OpenAI",
|
||||
api: "https://api.openai.com/v1",
|
||||
env: ["OPENAI_API_KEY"],
|
||||
npm: "openai",
|
||||
models: {
|
||||
"gpt-4o": {
|
||||
id: "gpt-4o",
|
||||
name: "GPT-4o",
|
||||
release_date: "2024-05-13",
|
||||
attachment: true,
|
||||
reasoning: false,
|
||||
temperature: true,
|
||||
tool_call: true,
|
||||
cost: { input: 5, output: 15 },
|
||||
limit: { context: 128000, output: 4096 },
|
||||
modalities: {
|
||||
input: ["text", "image", "audio"],
|
||||
output: ["text", "audio"],
|
||||
},
|
||||
experimental: false,
|
||||
},
|
||||
"gpt-4o-mini": {
|
||||
id: "gpt-4o-mini",
|
||||
name: "GPT-4o Mini",
|
||||
release_date: "2024-07-18",
|
||||
attachment: true,
|
||||
reasoning: false,
|
||||
temperature: true,
|
||||
tool_call: true,
|
||||
cost: { input: 0.15, output: 0.6 },
|
||||
limit: { context: 128000, output: 16384 },
|
||||
modalities: { input: ["text", "image"], output: ["text"] },
|
||||
experimental: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "google",
|
||||
name: "Google",
|
||||
api: "https://generativelanguage.googleapis.com/v1beta",
|
||||
env: ["GOOGLE_API_KEY"],
|
||||
npm: "@google/generative-ai",
|
||||
models: {
|
||||
"gemini-1.5-pro": {
|
||||
id: "gemini-1.5-pro",
|
||||
name: "Gemini 1.5 Pro",
|
||||
release_date: "2024-02-15",
|
||||
attachment: true,
|
||||
reasoning: false,
|
||||
temperature: true,
|
||||
tool_call: true,
|
||||
cost: { input: 3.5, output: 10.5 },
|
||||
limit: { context: 2000000, output: 8192 },
|
||||
modalities: {
|
||||
input: ["text", "image", "audio", "video"],
|
||||
output: ["text"],
|
||||
},
|
||||
experimental: false,
|
||||
},
|
||||
"gemini-1.5-flash": {
|
||||
id: "gemini-1.5-flash",
|
||||
name: "Gemini 1.5 Flash",
|
||||
release_date: "2024-02-15",
|
||||
attachment: true,
|
||||
reasoning: false,
|
||||
temperature: true,
|
||||
tool_call: true,
|
||||
cost: { input: 0.075, output: 0.3 },
|
||||
limit: { context: 1000000, output: 8192 },
|
||||
modalities: {
|
||||
input: ["text", "image", "audio", "video"],
|
||||
output: ["text"],
|
||||
},
|
||||
experimental: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
];
|
||||
interface ConfigProvider {
|
||||
npm?: string;
|
||||
name?: string;
|
||||
api?: string;
|
||||
options?: {
|
||||
baseURL?: string;
|
||||
[key: string]: unknown;
|
||||
};
|
||||
models?: Record<string, ConfigModel>;
|
||||
}
|
||||
|
||||
async function getProvidersFromConfig(): Promise<Provider[]> {
|
||||
interface ConfigModel {
|
||||
id?: string;
|
||||
name?: string;
|
||||
limit?: {
|
||||
context?: number;
|
||||
output?: number;
|
||||
};
|
||||
[key: string]: unknown;
|
||||
}
|
||||
|
||||
const LOCAL_PROVIDER_IDS = ["ollama", "lmstudio", "llamacpp", "jan"];
|
||||
|
||||
function classifyProviderSource(providerId: string, isFromConfig: boolean): ProviderSource {
|
||||
if (!isFromConfig) return "builtin";
|
||||
if (LOCAL_PROVIDER_IDS.includes(providerId.toLowerCase())) return "local";
|
||||
return "configured";
|
||||
}
|
||||
|
||||
function getProviderPriority(source: ProviderSource): number {
|
||||
switch (source) {
|
||||
case "configured": return 1;
|
||||
case "local": return 2;
|
||||
case "builtin": return 3;
|
||||
default: return 4;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
async function getProvidersFromOpenCodeServer(): Promise<Provider[]> {
|
||||
try {
|
||||
const configResponse = await settingsApi.getDefaultOpenCodeConfig();
|
||||
if (configResponse?.content?.provider) {
|
||||
const providerRecord = configResponse.content.provider as Record<string, Provider>;
|
||||
const providers = Object.entries(providerRecord).map(([id, provider]) => ({
|
||||
...provider,
|
||||
id: provider.id || id,
|
||||
}));
|
||||
return providers;
|
||||
const response = await axios.get(`${API_BASE_URL}/api/opencode/provider`);
|
||||
|
||||
if (response?.data?.all && Array.isArray(response.data.all)) {
|
||||
return response.data.all.map((openCodeProvider: OpenCodeProvider) => {
|
||||
const models: Record<string, Model> = {};
|
||||
|
||||
Object.entries(openCodeProvider.models).forEach(([modelId, openCodeModel]) => {
|
||||
models[modelId] = {
|
||||
id: openCodeModel.id,
|
||||
name: openCodeModel.name,
|
||||
attachment: openCodeModel.capabilities.attachment,
|
||||
reasoning: openCodeModel.capabilities.reasoning,
|
||||
temperature: openCodeModel.capabilities.temperature,
|
||||
tool_call: openCodeModel.capabilities.toolcall,
|
||||
cost: {
|
||||
input: openCodeModel.cost.input,
|
||||
output: openCodeModel.cost.output,
|
||||
cache_read: openCodeModel.cost.cache.read,
|
||||
cache_write: openCodeModel.cost.cache.write,
|
||||
},
|
||||
limit: {
|
||||
context: openCodeModel.limit.context,
|
||||
output: openCodeModel.limit.output,
|
||||
},
|
||||
modalities: {
|
||||
input: Object.keys(openCodeModel.capabilities.input).filter(
|
||||
(key) => openCodeModel.capabilities.input[key as keyof typeof openCodeModel.capabilities.input]
|
||||
) as ("text" | "audio" | "image" | "video" | "pdf")[],
|
||||
output: Object.keys(openCodeModel.capabilities.output).filter(
|
||||
(key) => openCodeModel.capabilities.output[key as keyof typeof openCodeModel.capabilities.output]
|
||||
) as ("text" | "audio" | "image" | "video" | "pdf")[],
|
||||
},
|
||||
provider: {
|
||||
npm: openCodeModel.api.npm,
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
return {
|
||||
id: openCodeProvider.id,
|
||||
name: openCodeProvider.name,
|
||||
env: openCodeProvider.env,
|
||||
models,
|
||||
options: openCodeProvider.options,
|
||||
};
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn("Failed to load OpenCode config", error);
|
||||
console.warn("Failed to load providers from OpenCode server", error);
|
||||
}
|
||||
|
||||
return DEFAULT_PROVIDERS;
|
||||
return [];
|
||||
}
|
||||
|
||||
export async function getProviders(): Promise<Provider[]> {
|
||||
return await getProvidersFromConfig();
|
||||
return await getProvidersFromOpenCodeServer();
|
||||
}
|
||||
|
||||
async function getConfiguredProviders(): Promise<ProviderWithModels[]> {
|
||||
try {
|
||||
const config = await settingsApi.getDefaultOpenCodeConfig();
|
||||
if (!config?.content?.provider) return [];
|
||||
|
||||
const configProviders = config.content.provider as Record<string, ConfigProvider>;
|
||||
const result: ProviderWithModels[] = [];
|
||||
|
||||
for (const [providerId, providerConfig] of Object.entries(configProviders)) {
|
||||
if (!providerConfig || typeof providerConfig !== "object") continue;
|
||||
|
||||
const source = classifyProviderSource(providerId, true);
|
||||
const models: Model[] = [];
|
||||
|
||||
if (providerConfig.models) {
|
||||
for (const [modelId, modelConfig] of Object.entries(providerConfig.models)) {
|
||||
if (!modelConfig || typeof modelConfig !== "object") continue;
|
||||
|
||||
models.push({
|
||||
id: modelConfig.id || modelId,
|
||||
name: modelConfig.name || modelId,
|
||||
limit: modelConfig.limit ? {
|
||||
context: modelConfig.limit.context || 0,
|
||||
output: modelConfig.limit.output || 0,
|
||||
} : undefined,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
result.push({
|
||||
id: providerId,
|
||||
name: providerConfig.name || providerId,
|
||||
api: providerConfig.api || providerConfig.options?.baseURL,
|
||||
env: [],
|
||||
npm: providerConfig.npm,
|
||||
models,
|
||||
source,
|
||||
});
|
||||
}
|
||||
|
||||
return result;
|
||||
} catch (error) {
|
||||
console.warn("Failed to load configured providers", error);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
export async function getProvidersWithModels(): Promise<ProviderWithModels[]> {
|
||||
const providers = await getProviders();
|
||||
const [builtinProviders, configuredProviders] = await Promise.all([
|
||||
getProviders(),
|
||||
getConfiguredProviders(),
|
||||
]);
|
||||
|
||||
const result = providers.map((provider) => {
|
||||
const models = Object.entries(provider.models || {}).map(([id, model]) => ({
|
||||
...model,
|
||||
id: model.id || id,
|
||||
name: model.name || id,
|
||||
}));
|
||||
return {
|
||||
id: provider.id,
|
||||
name: provider.name,
|
||||
api: provider.api,
|
||||
env: provider.env || [],
|
||||
npm: provider.npm,
|
||||
models,
|
||||
};
|
||||
const configuredIds = new Set(configuredProviders.map((p) => p.id));
|
||||
|
||||
const builtinResult: ProviderWithModels[] = builtinProviders
|
||||
.filter((provider) => !configuredIds.has(provider.id))
|
||||
.map((provider) => {
|
||||
const models = Object.entries(provider.models || {}).map(([id, model]) => ({
|
||||
...model,
|
||||
id: model.id || id,
|
||||
name: model.name || id,
|
||||
}));
|
||||
return {
|
||||
id: provider.id,
|
||||
name: provider.name,
|
||||
api: provider.api,
|
||||
env: provider.env || [],
|
||||
npm: provider.npm,
|
||||
models,
|
||||
source: "builtin" as ProviderSource,
|
||||
};
|
||||
});
|
||||
|
||||
const allProviders = [...configuredProviders, ...builtinResult];
|
||||
|
||||
allProviders.sort((a, b) => {
|
||||
const priorityA = getProviderPriority(a.source);
|
||||
const priorityB = getProviderPriority(b.source);
|
||||
if (priorityA !== priorityB) return priorityA - priorityB;
|
||||
return a.name.localeCompare(b.name);
|
||||
});
|
||||
|
||||
return result;
|
||||
return allProviders;
|
||||
}
|
||||
|
||||
export async function getModel(
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useState, useEffect, useCallback } from "react";
|
||||
import { useState, useEffect, useMemo } from "react";
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
@@ -8,7 +8,8 @@ import {
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Loader2, Search, Check } from "lucide-react";
|
||||
import { Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectTrigger, SelectValue } from "@/components/ui/select";
|
||||
import { Loader2, Search, Check, Star, Home, Globe } from "lucide-react";
|
||||
import {
|
||||
getProvidersWithModels,
|
||||
formatModelName,
|
||||
@@ -17,7 +18,8 @@ import {
|
||||
import { useSettings } from "@/hooks/useSettings";
|
||||
import { useOpenCodeClient } from "@/hooks/useOpenCode";
|
||||
import { useParams } from "react-router-dom";
|
||||
import type { ProviderWithModels, Model } from "@/api/providers";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import type { Model, ProviderSource } from "@/api/providers";
|
||||
|
||||
interface ModelSelectDialogProps {
|
||||
open: boolean;
|
||||
@@ -30,38 +32,27 @@ export function ModelSelectDialog({
|
||||
onOpenChange,
|
||||
opcodeUrl,
|
||||
}: ModelSelectDialogProps) {
|
||||
const [providers, setProviders] = useState<ProviderWithModels[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [searchQuery, setSearchQuery] = useState("");
|
||||
const [selectedProvider, setSelectedProvider] = useState<string>("");
|
||||
const [viewMode, setViewMode] = useState<'providers' | 'models'>('providers');
|
||||
const { preferences, updateSettings } = useSettings();
|
||||
const client = useOpenCodeClient(opcodeUrl);
|
||||
const { sessionID } = useParams<{ sessionID: string }>();
|
||||
|
||||
const currentModel = preferences?.defaultModel || "";
|
||||
|
||||
const loadProviders = useCallback(async () => {
|
||||
try {
|
||||
setLoading(true);
|
||||
const data = await getProvidersWithModels();
|
||||
setProviders(data);
|
||||
|
||||
if (currentModel) {
|
||||
const [providerId] = currentModel.split("/");
|
||||
setSelectedProvider(providerId);
|
||||
}
|
||||
} catch {
|
||||
// Ignore errors when loading providers
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}, [opcodeUrl, currentModel]);
|
||||
const { data: providers = [], isLoading: loading } = useQuery({
|
||||
queryKey: ["providers-with-models"],
|
||||
queryFn: () => getProvidersWithModels(),
|
||||
enabled: open,
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
if (open) {
|
||||
loadProviders();
|
||||
if (currentModel && providers.length > 0) {
|
||||
const [providerId] = currentModel.split("/");
|
||||
setSelectedProvider(providerId);
|
||||
}
|
||||
}, [open, loadProviders]);
|
||||
}, [currentModel, providers]);
|
||||
|
||||
const filteredProviders = providers.filter((provider) => {
|
||||
const matchesSearch =
|
||||
@@ -72,12 +63,42 @@ export function ModelSelectDialog({
|
||||
model.id.toLowerCase().includes(searchQuery.toLowerCase()),
|
||||
);
|
||||
|
||||
const matchesProvider =
|
||||
!selectedProvider || provider.id === selectedProvider;
|
||||
const matchesSelectedProvider = !selectedProvider || provider.id === selectedProvider;
|
||||
|
||||
return matchesSearch && matchesProvider;
|
||||
return matchesSearch && matchesSelectedProvider;
|
||||
});
|
||||
|
||||
const selectedProviderData = providers.find(p => p.id === selectedProvider);
|
||||
|
||||
const groupedProviders = useMemo(() => {
|
||||
const configured = providers.filter(p => p.source === "configured");
|
||||
const local = providers.filter(p => p.source === "local");
|
||||
const builtin = providers.filter(p => p.source === "builtin");
|
||||
return { configured, local, builtin };
|
||||
}, [providers]);
|
||||
|
||||
const getSourceBadge = (source: ProviderSource) => {
|
||||
switch (source) {
|
||||
case "configured":
|
||||
return <Badge variant="default" className="text-xs px-1.5 py-0 bg-yellow-500/20 text-yellow-600 border-yellow-500/30">Custom</Badge>;
|
||||
case "local":
|
||||
return <Badge variant="default" className="text-xs px-1.5 py-0 bg-green-500/20 text-green-600 border-green-500/30">Local</Badge>;
|
||||
case "builtin":
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
const handleProviderSelect = (providerId: string) => {
|
||||
setSelectedProvider(providerId);
|
||||
setViewMode('models');
|
||||
setSearchQuery("");
|
||||
};
|
||||
|
||||
const handleBackToProviders = () => {
|
||||
setViewMode('providers');
|
||||
setSearchQuery("");
|
||||
};
|
||||
|
||||
const handleModelSelect = async (providerId: string, modelId: string) => {
|
||||
const newModel = `${providerId}/${modelId}`;
|
||||
|
||||
@@ -100,9 +121,7 @@ export function ModelSelectDialog({
|
||||
onOpenChange(false);
|
||||
};
|
||||
|
||||
const handleProviderChange = (providerId: string) => {
|
||||
setSelectedProvider(providerId);
|
||||
};
|
||||
|
||||
|
||||
const getStatusBadge = (model: Model) => {
|
||||
if (model.experimental)
|
||||
@@ -123,171 +142,287 @@ export function ModelSelectDialog({
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||
<DialogContent className="max-w-4xl max-h-[80vh] bg-background border-border text-foreground">
|
||||
<DialogHeader>
|
||||
<DialogTitle className="text-xl font-semibold">
|
||||
Select Model
|
||||
</DialogTitle>
|
||||
<DialogContent className="max-w-7xl w-[95vw] h-[90vh] max-h-[90vh] bg-background border-border text-foreground p-0 flex flex-col">
|
||||
<DialogHeader className="p-4 sm:p-6 pb-2 border-b border-border flex-shrink-0">
|
||||
<div className="flex items-center gap-2">
|
||||
{viewMode === 'models' && (
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={handleBackToProviders}
|
||||
className="p-1 h-8 w-8"
|
||||
>
|
||||
←
|
||||
</Button>
|
||||
)}
|
||||
<DialogTitle className="text-lg sm:text-xl font-semibold">
|
||||
{viewMode === 'providers' ? 'Select Model' : `Select Model - ${selectedProviderData?.name || ''}`}
|
||||
</DialogTitle>
|
||||
</div>
|
||||
</DialogHeader>
|
||||
|
||||
<div className="space-y-4">
|
||||
{/* Search */}
|
||||
<div className="relative">
|
||||
<Search className="absolute left-3 top-1/2 transform -translate-y-1/2 h-4 w-4 text-muted-foreground" />
|
||||
<Input
|
||||
placeholder="Search models or providers..."
|
||||
value={searchQuery}
|
||||
onChange={(e) => setSearchQuery(e.target.value)}
|
||||
className="pl-10 bg-card border-border text-foreground placeholder-muted-foreground"
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Provider Filter */}
|
||||
<div className="flex gap-2 flex-wrap">
|
||||
<Button
|
||||
variant={!selectedProvider ? "default" : "outline"}
|
||||
size="sm"
|
||||
onClick={() => handleProviderChange("")}
|
||||
className={
|
||||
!selectedProvider
|
||||
? "bg-blue-600 text-white"
|
||||
: "bg-[#2a2a2a] border-[#333] text-zinc-300 hover:bg-[#333]"
|
||||
}
|
||||
>
|
||||
All Providers
|
||||
</Button>
|
||||
{providers.map((provider) => (
|
||||
<div className="flex flex-1 overflow-hidden">
|
||||
{/* Sidebar - Provider List (Desktop) */}
|
||||
<div className="hidden sm:block w-48 lg:w-64 border-r border-border bg-muted/20 p-4 overflow-y-auto">
|
||||
<div className="space-y-4">
|
||||
<Button
|
||||
key={provider.id}
|
||||
variant={
|
||||
selectedProvider === provider.id ? "default" : "outline"
|
||||
}
|
||||
variant={!selectedProvider ? "secondary" : "ghost"}
|
||||
size="sm"
|
||||
onClick={() => handleProviderChange(provider.id)}
|
||||
className={
|
||||
selectedProvider === provider.id
|
||||
? "bg-blue-600 text-white"
|
||||
: "bg-[#2a2a2a] border-[#333] text-zinc-300 hover:bg-[#333]"
|
||||
}
|
||||
onClick={() => {
|
||||
setSelectedProvider("");
|
||||
handleBackToProviders();
|
||||
}}
|
||||
className="w-full justify-start text-sm"
|
||||
>
|
||||
{formatProviderName(provider)}
|
||||
All Providers
|
||||
</Button>
|
||||
))}
|
||||
|
||||
{groupedProviders.configured.length > 0 && (
|
||||
<div>
|
||||
<h3 className="text-xs font-semibold text-yellow-600 mb-2 flex items-center gap-1.5">
|
||||
<Star className="h-3 w-3" />
|
||||
Custom Providers
|
||||
</h3>
|
||||
<div className="space-y-1">
|
||||
{groupedProviders.configured.map((provider) => (
|
||||
<Button
|
||||
key={provider.id}
|
||||
variant={selectedProvider === provider.id ? "secondary" : "ghost"}
|
||||
size="sm"
|
||||
onClick={() => handleProviderSelect(provider.id)}
|
||||
className="w-full justify-start text-sm"
|
||||
>
|
||||
{formatProviderName(provider)}
|
||||
</Button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{groupedProviders.local.length > 0 && (
|
||||
<div>
|
||||
<h3 className="text-xs font-semibold text-green-600 mb-2 flex items-center gap-1.5">
|
||||
<Home className="h-3 w-3" />
|
||||
Local Providers
|
||||
</h3>
|
||||
<div className="space-y-1">
|
||||
{groupedProviders.local.map((provider) => (
|
||||
<Button
|
||||
key={provider.id}
|
||||
variant={selectedProvider === provider.id ? "secondary" : "ghost"}
|
||||
size="sm"
|
||||
onClick={() => handleProviderSelect(provider.id)}
|
||||
className="w-full justify-start text-sm"
|
||||
>
|
||||
{formatProviderName(provider)}
|
||||
</Button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{groupedProviders.builtin.length > 0 && (
|
||||
<div>
|
||||
<h3 className="text-xs font-semibold text-muted-foreground mb-2 flex items-center gap-1.5">
|
||||
<Globe className="h-3 w-3" />
|
||||
Built-in Providers
|
||||
</h3>
|
||||
<div className="space-y-1">
|
||||
{groupedProviders.builtin.map((provider) => (
|
||||
<Button
|
||||
key={provider.id}
|
||||
variant={selectedProvider === provider.id ? "secondary" : "ghost"}
|
||||
size="sm"
|
||||
onClick={() => handleProviderSelect(provider.id)}
|
||||
className="w-full justify-start text-sm"
|
||||
>
|
||||
{formatProviderName(provider)}
|
||||
</Button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Models List */}
|
||||
<div className="min-h-[300px] max-h-[400px] overflow-y-auto">
|
||||
{loading ? (
|
||||
<div className="flex items-center justify-center py-12">
|
||||
<Loader2 className="h-8 w-8 animate-spin text-zinc-500" />
|
||||
{/* Main Content */}
|
||||
<div className="flex-1 flex flex-col overflow-hidden">
|
||||
{/* Mobile Provider Dropdown */}
|
||||
<div className="sm:hidden p-3 border-b border-border">
|
||||
<Select onValueChange={handleProviderSelect} value={selectedProvider || undefined}>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="Select a provider..." />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{groupedProviders.configured.length > 0 && (
|
||||
<SelectGroup>
|
||||
<SelectLabel className="flex items-center gap-1.5 text-yellow-600">
|
||||
<Star className="h-3 w-3" />
|
||||
Custom Providers
|
||||
</SelectLabel>
|
||||
{groupedProviders.configured.map((provider) => (
|
||||
<SelectItem key={provider.id} value={provider.id}>
|
||||
{formatProviderName(provider)} ({provider.models.length})
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectGroup>
|
||||
)}
|
||||
{groupedProviders.local.length > 0 && (
|
||||
<SelectGroup>
|
||||
<SelectLabel className="flex items-center gap-1.5 text-green-600">
|
||||
<Home className="h-3 w-3" />
|
||||
Local Providers
|
||||
</SelectLabel>
|
||||
{groupedProviders.local.map((provider) => (
|
||||
<SelectItem key={provider.id} value={provider.id}>
|
||||
{formatProviderName(provider)} ({provider.models.length})
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectGroup>
|
||||
)}
|
||||
{groupedProviders.builtin.length > 0 && (
|
||||
<SelectGroup>
|
||||
<SelectLabel className="flex items-center gap-1.5 text-muted-foreground">
|
||||
<Globe className="h-3 w-3" />
|
||||
Built-in Providers
|
||||
</SelectLabel>
|
||||
{groupedProviders.builtin.map((provider) => (
|
||||
<SelectItem key={provider.id} value={provider.id}>
|
||||
{formatProviderName(provider)} ({provider.models.length})
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectGroup>
|
||||
)}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
{/* Search Bar */}
|
||||
<div className="p-3 sm:p-4 border-b border-border">
|
||||
<div className="relative max-w-md">
|
||||
<Search className="absolute left-3 top-1/2 transform -translate-y-1/2 h-4 w-4 text-muted-foreground" />
|
||||
<Input
|
||||
placeholder={selectedProvider ? "Search models..." : "Search models..."}
|
||||
value={searchQuery}
|
||||
onChange={(e) => setSearchQuery(e.target.value)}
|
||||
className="pl-10 text-sm"
|
||||
/>
|
||||
</div>
|
||||
) : filteredProviders.length === 0 ? (
|
||||
<div className="text-center py-12 text-zinc-500">
|
||||
No providers or models found
|
||||
</div>
|
||||
) : (
|
||||
<div className="space-y-4">
|
||||
{filteredProviders.map((provider) => (
|
||||
<div key={provider.id} className="space-y-2">
|
||||
<h3 className="font-medium text-zinc-200 flex items-center gap-2">
|
||||
{formatProviderName(provider)}
|
||||
{provider.api && (
|
||||
<Badge variant="outline" className="text-xs">
|
||||
API
|
||||
</Badge>
|
||||
)}
|
||||
</h3>
|
||||
<div className="grid gap-2 pl-4">
|
||||
{provider.models.map((model) => {
|
||||
const modelKey = `${provider.id}/${model.id}`;
|
||||
const isSelected = currentModel === modelKey;
|
||||
const capabilities = getModelCapabilities(model);
|
||||
</div>
|
||||
|
||||
return (
|
||||
<div
|
||||
key={model.id}
|
||||
className={`p-3 rounded-lg border cursor-pointer transition-colors ${
|
||||
isSelected
|
||||
? "bg-blue-600/20 border-blue-500"
|
||||
: "bg-[#0a0a0a] border-[#333] hover:bg-[#1a1a1a] hover:border-[#444]"
|
||||
}`}
|
||||
onClick={() =>
|
||||
handleModelSelect(provider.id, model.id)
|
||||
}
|
||||
>
|
||||
<div className="flex items-start justify-between">
|
||||
<div className="flex-1">
|
||||
<div className="flex items-center gap-2 mb-1">
|
||||
<h4 className="font-medium text-white">
|
||||
{formatModelName(model)}
|
||||
</h4>
|
||||
{isSelected && (
|
||||
<Check className="h-4 w-4 text-blue-400" />
|
||||
)}
|
||||
{getStatusBadge(model)}
|
||||
</div>
|
||||
<p className="text-sm text-zinc-400 mb-2">
|
||||
{model.id}
|
||||
</p>
|
||||
{/* Models Grid */}
|
||||
<div className="flex-1 overflow-y-auto p-3 sm:p-4">
|
||||
{loading ? (
|
||||
<div className="flex items-center justify-center h-full">
|
||||
<Loader2 className="h-8 w-8 animate-spin text-zinc-500" />
|
||||
</div>
|
||||
) : filteredProviders.length === 0 ? (
|
||||
<div className="text-center py-12 text-zinc-500">
|
||||
No models found
|
||||
</div>
|
||||
) : (
|
||||
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-3 sm:gap-4">
|
||||
{filteredProviders.flatMap((provider) =>
|
||||
provider.models.map((model) => {
|
||||
const modelKey = `${provider.id}/${model.id}`;
|
||||
const isSelected = currentModel === modelKey;
|
||||
const capabilities = getModelCapabilities(model);
|
||||
|
||||
{/* Capabilities */}
|
||||
{capabilities.length > 0 && (
|
||||
<div className="flex gap-1 flex-wrap mb-2">
|
||||
{capabilities.map((cap) => (
|
||||
<Badge
|
||||
key={cap}
|
||||
variant="secondary"
|
||||
className="text-xs"
|
||||
>
|
||||
{cap}
|
||||
</Badge>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Model Info */}
|
||||
<div className="text-xs text-zinc-500 space-y-1">
|
||||
<div>
|
||||
Context:{" "}
|
||||
{model.limit?.context?.toLocaleString() ||
|
||||
"N/A"}{" "}
|
||||
tokens
|
||||
</div>
|
||||
<div>
|
||||
Output:{" "}
|
||||
{model.limit?.output?.toLocaleString() ||
|
||||
"N/A"}{" "}
|
||||
tokens
|
||||
</div>
|
||||
{model.cost && (
|
||||
<div>
|
||||
Cost: ${model.cost.input.toFixed(6)}
|
||||
/input, ${model.cost.output.toFixed(6)}
|
||||
/output
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
return (
|
||||
<div
|
||||
key={`${provider.id}-${model.id}`}
|
||||
className={`p-3 sm:p-4 rounded-lg border cursor-pointer transition-all hover:shadow-md ${
|
||||
isSelected
|
||||
? "bg-blue-600/20 border-blue-500 shadow-blue-500/20"
|
||||
: "bg-card border-border hover:bg-accent"
|
||||
}`}
|
||||
onClick={() => handleModelSelect(provider.id, model.id)}
|
||||
>
|
||||
<div className="flex items-start justify-between mb-2">
|
||||
<div className="flex-1 min-w-0">
|
||||
<div className="flex items-center gap-1.5 mb-1">
|
||||
<h4 className="font-semibold text-sm truncate">
|
||||
{formatModelName(model)}
|
||||
</h4>
|
||||
{getSourceBadge(provider.source)}
|
||||
</div>
|
||||
<p className="text-xs text-muted-foreground truncate">
|
||||
{formatProviderName(provider)}
|
||||
</p>
|
||||
</div>
|
||||
{isSelected && (
|
||||
<Check className="h-4 w-4 text-blue-500 flex-shrink-0 ml-2" />
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
|
||||
<div className="text-xs text-muted-foreground mb-2 sm:mb-3 font-mono truncate">
|
||||
{model.id}
|
||||
</div>
|
||||
|
||||
{/* Capabilities */}
|
||||
{capabilities.length > 0 && (
|
||||
<div className="flex gap-1 flex-wrap mb-2 sm:mb-3">
|
||||
{capabilities.slice(0, 2).map((cap) => (
|
||||
<Badge
|
||||
key={cap}
|
||||
variant="secondary"
|
||||
className="text-xs px-1.5 py-0.5"
|
||||
>
|
||||
{cap}
|
||||
</Badge>
|
||||
))}
|
||||
{capabilities.length > 2 && (
|
||||
<Badge variant="secondary" className="text-xs px-1.5 py-0.5">
|
||||
+{capabilities.length - 2}
|
||||
</Badge>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Status Badge */}
|
||||
<div className="mb-2 sm:mb-3">
|
||||
{getStatusBadge(model)}
|
||||
</div>
|
||||
|
||||
{/* Specs */}
|
||||
<div className="text-xs text-muted-foreground space-y-1">
|
||||
{model.limit?.context && (
|
||||
<div className="flex justify-between">
|
||||
<span className="truncate">Context:</span>
|
||||
<span className="ml-1 flex-shrink-0">
|
||||
{model.limit.context >= 1000000
|
||||
? `${(model.limit.context / 1000000).toFixed(1)}M`
|
||||
: model.limit.context.toLocaleString()
|
||||
} tokens
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
{model.cost && (
|
||||
<div className="flex justify-between">
|
||||
<span>Cost:</span>
|
||||
<span className="ml-1 flex-shrink-0">
|
||||
${model.cost.input.toFixed(4)}/1K
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Footer */}
|
||||
{currentModel && (
|
||||
<div className="p-3 sm:p-4 border-t border-border bg-muted/20 flex-shrink-0">
|
||||
<p className="text-xs sm:text-sm text-muted-foreground">
|
||||
Current: <span className="font-medium text-foreground break-all">{currentModel}</span>
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Current Selection */}
|
||||
{currentModel && (
|
||||
<div className="pt-4 border-t border-[#333]">
|
||||
<p className="text-sm text-zinc-400">
|
||||
Current model:{" "}
|
||||
<span className="text-white font-medium">{currentModel}</span>
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
|
||||
Reference in new issue
Block a user