(props: { providerID?: string })
| 10 | import { useSync } from "../context/sync" |
| 11 | |
| 12 | export function DialogModel(props: { providerID?: string }) { |
| 13 | const local = useLocal() |
| 14 | const sync = useSync() |
| 15 | const dialog = useDialog() |
| 16 | const [query, setQuery] = createSignal("") |
| 17 | |
| 18 | const connected = useConnected() |
| 19 | const providers = createDialogProviderOptions() |
| 20 | |
| 21 | const showExtra = createMemo(() => connected() && !props.providerID) |
| 22 | |
| 23 | const options = createMemo(() => { |
| 24 | const needle = query().trim() |
| 25 | const showSections = showExtra() && needle.length === 0 |
| 26 | const favorites = connected() ? local.model.favorite() : [] |
| 27 | const recents = local.model.recent() |
| 28 | |
| 29 | function toOptions(items: typeof favorites, category: string) { |
| 30 | if (!showSections) return [] |
| 31 | return items.flatMap((item) => { |
| 32 | const provider = sync.data.provider.find((provider) => provider.id === item.providerID) |
| 33 | if (!provider) return [] |
| 34 | const model = provider.models[item.modelID] |
| 35 | if (!model) return [] |
| 36 | return [ |
| 37 | { |
| 38 | key: item, |
| 39 | value: { providerID: provider.id, modelID: model.id }, |
| 40 | title: model.name ?? item.modelID, |
| 41 | description: provider.name, |
| 42 | category, |
| 43 | disabled: provider.id === "opencode" && model.id.includes("-nano"), |
| 44 | footer: model.cost?.input === 0 && provider.id === "opencode" ? "Free" : undefined, |
| 45 | onSelect: () => { |
| 46 | onSelect(provider.id, model.id) |
| 47 | }, |
| 48 | }, |
| 49 | ] |
| 50 | }) |
| 51 | } |
| 52 | |
| 53 | const favoriteOptions = toOptions(favorites, "Favorites") |
| 54 | const recentOptions = toOptions( |
| 55 | recents.filter( |
| 56 | (item) => !favorites.some((fav) => fav.providerID === item.providerID && fav.modelID === item.modelID), |
| 57 | ), |
| 58 | "Recent", |
| 59 | ) |
| 60 | |
| 61 | const providerOptions = pipe( |
| 62 | sync.data.provider, |
| 63 | sortBy( |
| 64 | (provider) => provider.id !== "opencode", |
| 65 | (provider) => provider.name, |
| 66 | ), |
| 67 | flatMap((provider) => |
| 68 | pipe( |
| 69 | provider.models, |
nothing calls this directly
no test coverage detected