Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ui/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ function App() {
</header>
<main className="flex h-[calc(100vh-4rem)] gap-4 p-4 overflow-hidden">
<div className="w-3/5">
<Providers />
<Providers showToast={(message, type) => setToast({ message, type })} />
</div>
<div className="flex w-2/5 flex-col gap-4">
<div className="h-3/5">
Expand Down
19 changes: 17 additions & 2 deletions ui/src/components/ProviderList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ interface ProviderListProps {
providers: Provider[];
onEdit: (index: number) => void;
onRemove: (index: number) => void;
showToast: (message: string, type: 'success' | 'error' | 'warning') => void;
}

export function ProviderList({ providers, onEdit, onRemove }: ProviderListProps) {
export function ProviderList({ providers, onEdit, onRemove, showToast }: ProviderListProps) {
// Handle case where providers might be null or undefined
if (!providers || !Array.isArray(providers)) {
return (
Expand Down Expand Up @@ -61,7 +62,21 @@ export function ProviderList({ providers, onEdit, onRemove }: ProviderListProps)
<div className="flex flex-wrap gap-2 pt-2">
{models.map((model, modelIndex) => (
// Handle case where model might be null or undefined
<Badge key={modelIndex} variant="outline" className="font-normal transition-all-ease hover:scale-105">
<Badge
key={modelIndex}
variant="outline"
className="font-normal transition-all-ease hover:scale-105 cursor-pointer"
onClick={async () => {
const textToCopy = `${providerName},${model}`;
try {
await navigator.clipboard.writeText(textToCopy);
showToast(`"${textToCopy}" copied to clipboard!`, 'success');
} catch (err) {
console.error('Failed to copy text: ', err);
showToast('Failed to copy to clipboard.', 'error');
}
}}
>
{model || "Unnamed Model"}
</Badge>
))}
Expand Down
3 changes: 2 additions & 1 deletion ui/src/components/Providers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import type { Provider } from "@/types";

interface ProviderType extends Provider {}

export function Providers() {
export function Providers({ showToast }: { showToast: (message: string, type: 'success' | 'error' | 'warning') => void }) {
const { t } = useTranslation();
const { config, setConfig } = useConfig();
const [editingProviderIndex, setEditingProviderIndex] = useState<number | null>(null);
Expand Down Expand Up @@ -551,6 +551,7 @@ export function Providers() {
providers={filteredProviders}
onEdit={handleEditProvider}
onRemove={handleSetDeletingProviderIndex}
showToast={showToast}
/>
</CardContent>

Expand Down
5 changes: 4 additions & 1 deletion ui/src/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,13 @@ class ApiClient {
private async apiFetch<T>(endpoint: string, options: RequestInit = {}): Promise<T> {
const url = `${this.baseUrl}${endpoint}`;

// Only set Content-Type if there is a body
const contentType = options.body ? 'application/json' : '';

const config: RequestInit = {
...options,
headers: {
...this.createHeaders(),
...this.createHeaders(contentType),
...options.headers,
},
};
Expand Down