SPB Git
1.0 KB · 19 lines typescript
1"use client";2import useSWR from "swr";3import { fetcher } from "./fetcher";4import type { AIModel } from "./types";56export function useModels(all = false) {7  const { data, error, isLoading, mutate } = useSWR<{ models: AIModel[]; defaultModel: string | null; registry: { refreshedAt?: string } }>(`/api/models${all ? "?all=1" : ""}`, fetcher, { revalidateOnFocus: false, dedupingInterval: 60_000 });8  const models = data?.models ?? [];9  const chat = models.filter(m => m.available && ["chat", "chat-pro", "search"].includes(m.kind));10  return { models, chat, defaultModel: data?.defaultModel ?? null, registry: data?.registry, error, isLoading, mutate, byId: (id: string | null | undefined) => models.find(m => m.id === id) };11}1213export const PROVIDER_LABEL: Record<string, string> = { openai: "OpenAI", anthropic: "Anthropic", local: "MacLustr local" };1415export function shortName(m: AIModel | undefined | null, id?: string | null): string {16  if (!m) return id ?? "—";17  return m.displayName.replace(/^Claude /, "").replace(/ \(\d{4}-\d{2}-\d{2}\)$/, "");18}19
Files · laptop-build-20261101
Menu

Theme