Skip to content

Commit 467d61f

Browse files
authored
chore(app): drop remeda from app and ui (#59016)
1 parent 193a556 commit 467d61f

7 files changed

Lines changed: 168 additions & 55 deletions

File tree

‎bun.lock‎

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎packages/app/package.json‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@
8585
"effect": "catalog:",
8686
"fuzzysort": "catalog:",
8787
"qr-scanner": "1.4.2",
88-
"remeda": "catalog:",
8988
"solid-js": "catalog:",
9089
"tailwindcss": "4.3.3"
9190
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { expect, test } from "bun:test"
2+
import { latestModels, uniqueModels } from "./models"
3+
4+
const model = (provider: string, id: string, release_date: string, family?: string) => ({
5+
id,
6+
family,
7+
release_date,
8+
provider: { id: provider },
9+
})
10+
11+
test("keeps the newest model of each provider and family", () => {
12+
expect(
13+
latestModels([
14+
model("a", "old", "2026-01-01", "f"),
15+
model("a", "new", "2026-03-01", "f"),
16+
model("a", "other", "2026-02-01", "g"),
17+
model("b", "b-only", "2026-01-01", "f"),
18+
]),
19+
).toEqual([
20+
{ providerID: "a", modelID: "new" },
21+
{ providerID: "a", modelID: "other" },
22+
{ providerID: "b", modelID: "b-only" },
23+
])
24+
})
25+
26+
test("a tie in release date keeps the first model listed", () => {
27+
expect(
28+
latestModels([model("a", "first", "2026-01-01", "f"), model("a", "second", "2026-01-01", "f")]),
29+
).toEqual([{ providerID: "a", modelID: "first" }])
30+
})
31+
32+
test("groups free models apart from their paid twin", () => {
33+
const free = { ...model("opencode", "x-free", "2026-01-01", "x"), cost: { input: 0 } }
34+
const paid = { ...model("opencode", "x", "2026-01-01", "x"), cost: { input: 1 } }
35+
36+
expect(latestModels([free, paid])).toEqual([
37+
{ providerID: "opencode", modelID: "x-free" },
38+
{ providerID: "opencode", modelID: "x" },
39+
])
40+
})
41+
42+
test("uniqueModels keeps the first of each model in order", () => {
43+
expect(
44+
uniqueModels([
45+
{ providerID: "a", modelID: "1" },
46+
{ providerID: "b", modelID: "1" },
47+
{ providerID: "a", modelID: "1" },
48+
{ providerID: "a", modelID: "2" },
49+
]),
50+
).toEqual([
51+
{ providerID: "a", modelID: "1" },
52+
{ providerID: "b", modelID: "1" },
53+
{ providerID: "a", modelID: "2" },
54+
])
55+
})

‎packages/app/src/providers/models/models.tsx‎

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { type Accessor, createMemo } from "solid-js"
2-
import { filter, firstBy, flat, groupBy, mapValues, pipe, uniqueBy, values } from "remeda"
32
import { createSimpleContext } from "@opencode/ui/context"
43
import { useProviders } from "@/providers/catalog/providers"
54
import { useGlobal } from "@/runtime/server/runtime"
@@ -20,6 +19,33 @@ function modelKey(model: ModelKey) {
2019
export const isFreeModel = (model: { provider: { id: string }; cost?: { input: number } }) =>
2120
model.provider.id === "opencode" && (!model.cost || model.cost.input === 0)
2221

22+
// The newest release of each family per provider. A free model shares its family and release date with its paid twin,
23+
// so the two are grouped apart. A tie keeps the first model listed.
24+
export function latestModels<T extends { id: string; provider: { id: string }; family?: string; release_date: string }>(
25+
models: T[],
26+
) {
27+
return [...Map.groupBy(models, (x) => x.provider.id).values()].flatMap((provider) =>
28+
[...Map.groupBy(provider, (x) => `${x.family}:${isFreeModel(x)}`).values()].map((group) => {
29+
const first = group.reduce((best, x) => (x.release_date > best.release_date ? x : best))
30+
31+
return { modelID: first.id, providerID: first.provider.id }
32+
}),
33+
)
34+
}
35+
36+
export function uniqueModels(models: ModelKey[]) {
37+
const seen = new Set<string>()
38+
39+
return models.filter((model) => {
40+
const key = modelKey(model)
41+
42+
if (seen.has(key)) return false
43+
seen.add(key)
44+
45+
return true
46+
})
47+
}
48+
2349
const createModelsController = (directory: Accessor<string | undefined>) => {
2450
const providers = useProviders(() => directory())
2551
const models = useGlobal().models
@@ -46,30 +72,12 @@ const createModelsController = (directory: Accessor<string | undefined>) => {
4672
)
4773

4874
const latest = createMemo(() =>
49-
pipe(
50-
available(),
51-
filter((x) => {
75+
latestModels(
76+
available().filter((x) => {
5277
const released = release().get(modelKey({ providerID: x.provider.id, modelID: x.id })) ?? NaN
5378

5479
return Math.abs(Date.now() - released) < sixMonths
5580
}),
56-
groupBy((x) => x.provider.id),
57-
mapValues((models) =>
58-
pipe(
59-
models,
60-
// A free model shares its family and release date with its paid twin, so group them apart.
61-
groupBy((x) => `${x.family}:${isFreeModel(x)}`),
62-
values(),
63-
(groups) =>
64-
groups.flatMap((g) => {
65-
const first = firstBy(g, [(x) => x.release_date, "desc"])
66-
67-
return first ? [{ modelID: first.id, providerID: first.provider.id }] : []
68-
}),
69-
),
70-
),
71-
values(),
72-
flat(),
7381
),
7482
)
7583

@@ -124,7 +132,7 @@ const createModelsController = (directory: Accessor<string | undefined>) => {
124132
}
125133

126134
const push = (model: ModelKey) => {
127-
const uniq = uniqueBy([model, ...store.recent], (x) => `${x.providerID}:${x.modelID}`)
135+
const uniq = uniqueModels([model, ...store.recent])
128136

129137
if (uniq.length > RECENT_LIMIT) uniq.pop()
130138
setStore("recent", uniq)

‎packages/ui/package.json‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@
121121
"katex": "0.16.47",
122122
"marked": "catalog:",
123123
"motion": "12.34.5",
124-
"remeda": "catalog:",
125124
"solid-list": "catalog:",
126125
"solid-sonner": "catalog:"
127126
},
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { expect, test } from "bun:test"
2+
import { groupItems } from "./use-filtered-list"
3+
4+
test("groups under one empty category without a groupBy", () => {
5+
expect(groupItems(["b", "a"], {})).toEqual([{ category: "", items: ["b", "a"] }])
6+
})
7+
8+
test("keeps item order within a group and first-seen order between groups", () => {
9+
const items = [
10+
{ name: "x1", group: "x" },
11+
{ name: "y1", group: "y" },
12+
{ name: "x2", group: "x" },
13+
]
14+
15+
expect(groupItems(items, { groupBy: (item) => item.group }).map((g) => [g.category, g.items.map((i) => i.name)])).toEqual([
16+
["x", ["x1", "x2"]],
17+
["y", ["y1"]],
18+
])
19+
})
20+
21+
test("lists numeric-looking categories first, as object keys do", () => {
22+
expect(groupItems(["b", "10", "a", "2"], { groupBy: (item) => item }).map((g) => g.category)).toEqual([
23+
"2",
24+
"10",
25+
"b",
26+
"a",
27+
])
28+
})
29+
30+
test("sorts items within groups and then the groups", () => {
31+
const groups = groupItems([3, 1, 4, 2], {
32+
groupBy: (n) => (n % 2 ? "odd" : "even"),
33+
sortBy: (a, b) => a - b,
34+
sortGroupsBy: (a, b) => a.category.localeCompare(b.category),
35+
})
36+
37+
expect(groups).toEqual([
38+
{ category: "even", items: [2, 4] },
39+
{ category: "odd", items: [1, 3] },
40+
])
41+
})

‎packages/ui/src/hooks/use-filtered-list.tsx‎

Lines changed: 42 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import fuzzysort from "fuzzysort"
2-
import { entries, flatMap, groupBy, map, pipe } from "remeda"
32
import { createEffect, createMemo, createResource, on } from "solid-js"
43
import { createStore } from "solid-js/store"
54
import { createList } from "solid-list"
@@ -17,55 +16,69 @@ export interface FilteredListProps<T> {
1716
noInitialSelection?: boolean
1817
}
1918

19+
export function groupItems<T>(
20+
items: T[],
21+
props: Pick<FilteredListProps<T>, "groupBy" | "sortBy" | "sortGroupsBy">,
22+
) {
23+
// A plain object keeps the group order of `Object.entries`, where numeric-looking categories sort first.
24+
const byCategory: Record<string, T[]> = {}
25+
26+
for (const item of items) {
27+
const category = props.groupBy ? props.groupBy(item) : ""
28+
byCategory[category] ??= []
29+
byCategory[category].push(item)
30+
}
31+
32+
const groups = Object.entries(byCategory).map(([category, group]) => ({
33+
category,
34+
items: props.sortBy ? group.sort(props.sortBy) : group,
35+
}))
36+
37+
return props.sortGroupsBy ? groups.sort(props.sortGroupsBy) : groups
38+
}
39+
2040
export function useFilteredList<T>(props: FilteredListProps<T>) {
2141
const [store, setStore] = createStore<{ filter: string }>({ filter: "" })
2242

2343
type Group = { category: string; items: [T, ...T[]] }
2444

2545
const empty: Group[] = []
2646

47+
const search = (all: T[], needle: string) => {
48+
const skipFilter = props.skipFilter
49+
const filterable = skipFilter ? all.filter((item) => !skipFilter(item)) : all
50+
const skipped = skipFilter ? all.filter(skipFilter) : []
51+
52+
// oxlint-disable-next-line anti-slop/no-runtime-typeof -- plain string lists have no keys to search by
53+
const strings = !props.filterKeys && filterable.every((e) => typeof e === "string")
54+
55+
// SAFETY: when `strings` holds, every element is a string, so the matched targets are the items.
56+
const filtered = strings
57+
? (fuzzysort.go(needle, filterable as string[]).map((x) => x.target) as T[])
58+
: fuzzysort.go(needle, filterable, { keys: props.filterKeys! }).map((x) => x.obj)
59+
60+
return skipped.length ? [...filtered, ...skipped] : filtered
61+
}
62+
2763
const [grouped, { refetch }] = createResource(
2864
() => ({
2965
filter: store.filter,
66+
// oxlint-disable-next-line anti-slop/no-runtime-typeof -- `items` is either a list or a loader for one
3067
items: typeof props.items === "function" ? props.items(store.filter) : props.items,
3168
}),
3269
async ({ filter, items }) => {
3370
const query = filter ?? ""
3471
const needle = query.toLowerCase()
3572
const all = (await Promise.resolve(items)) || []
3673

37-
const result = pipe(
38-
all,
39-
(x) => {
40-
if (!needle) return x
41-
const skipFilter = props.skipFilter
42-
const filterable = skipFilter ? x.filter((item) => !skipFilter(item)) : x
43-
const skipped = skipFilter ? x.filter(skipFilter) : []
44-
45-
const filtered =
46-
!props.filterKeys && Array.isArray(filterable) && filterable.every((e) => typeof e === "string")
47-
? (fuzzysort.go(needle, filterable).map((x) => x.target) as T[])
48-
: fuzzysort.go(needle, filterable, { keys: props.filterKeys! }).map((x) => x.obj)
49-
50-
return skipped.length ? [...filtered, ...skipped] : filtered
51-
},
52-
groupBy((x) => (props.groupBy ? props.groupBy(x) : "")),
53-
entries(),
54-
map(([k, v]) => ({ category: k, items: props.sortBy ? v.sort(props.sortBy) : v })),
55-
(groups) => (props.sortGroupsBy ? groups.sort(props.sortGroupsBy) : groups),
56-
)
57-
58-
return result
74+
const matched = needle ? search(all, needle) : all
75+
76+
return groupItems(matched, props)
5977
},
6078
{ initialValue: empty },
6179
)
6280

63-
const flat = createMemo(() => {
64-
return pipe(
65-
grouped.latest || [],
66-
flatMap((x) => x.items),
67-
)
68-
})
81+
const flat = createMemo(() => (grouped.latest || []).flatMap((x) => x.items))
6982

7083
function initialActive() {
7184
if (props.noInitialSelection) return ""

0 commit comments

Comments
 (0)