diff --git a/packages/core/src/tool/plugin/opencode.ts b/packages/core/src/tool/plugin/opencode.ts index 7b076f8725b..c70c42592f6 100644 --- a/packages/core/src/tool/plugin/opencode.ts +++ b/packages/core/src/tool/plugin/opencode.ts @@ -264,13 +264,14 @@ export const Plugin = { left.providerID.localeCompare(right.providerID) || right.time.released - left.time.released, ) - .filter((model, index, sorted) => { - if (input.all || model.family === undefined) return true - return ( - sorted.findIndex( - (other) => other.providerID === model.providerID && other.family === model.family, - ) === index + // When browsing, hide older versions only: a family's same-day siblings, like free and paid offerings, + // stay listed. A search lists every match, so a version the user names is never hidden. + .filter((model, _, sorted) => { + if (input.all || terms.length > 0 || model.family === undefined) return true + const newest = sorted.find( + (other) => other.providerID === model.providerID && other.family === model.family, ) + return newest?.time.released === model.time.released }) const page = matching.slice(offset, offset + limit) const providers = Array.from(new Set(page.map((model) => model.providerID))).map((id) => ({ diff --git a/packages/core/test/tool-opencode.test.ts b/packages/core/test/tool-opencode.test.ts index 005d5eaa2bf..c9c8e79350d 100644 --- a/packages/core/test/tool-opencode.test.ts +++ b/packages/core/test/tool-opencode.test.ts @@ -29,6 +29,7 @@ const it = testEffect(PluginTestLayer) const alpha = { id: "test/alpha", name: "Alpha", released: 300, variants: ["fast"], cost: [], status: "beta" } const beta = { id: "other/beta", name: "Beta", released: 200, variants: [], cost: [], status: "active" } const gamma = { id: "other/gamma", name: "Gamma Flash", released: 100, variants: [], cost: [], status: "active" } +const gammaFree = { ...gamma, id: "other/gamma-free", name: "Gamma Flash Free" } const gammaOld = { id: "other/gamma-old", name: "Gamma Flash Old", @@ -64,6 +65,12 @@ it.effect("groups available models by provider with paging", () => model.time.released = 100 model.family = Model.Family.make("gamma") }) + // Same family and release day as gamma, like a free and a paid offering of one model. + editor.models.update(Provider.ID.make("other"), Model.ID.make("gamma-free"), (model) => { + model.name = "Gamma Flash Free" + model.time.released = 100 + model.family = Model.Family.make("gamma") + }) editor.models.update(Provider.ID.make("other"), Model.ID.make("gamma-old"), (model) => { model.name = "Gamma Flash Old" model.time.released = 50 @@ -97,9 +104,9 @@ it.effect("groups available models by provider with paging", () => expect(yield* run({})).toEqual({ providers: [ { id: "test", name: "test", models: [alpha] }, - { id: "other", name: "Other Provider", models: [beta, gamma] }, + { id: "other", name: "Other Provider", models: [beta, gamma, gammaFree] }, ], - total: 3, + total: 4, next: null, }) @@ -109,16 +116,16 @@ it.effect("groups available models by provider with paging", () => { id: "test", name: "test", models: [alpha] }, { id: "other", name: "Other Provider", models: [beta] }, ], - total: 3, + total: 4, next: 2, }) expect(yield* run({ limit: 2, offset: 2 })).toEqual({ - providers: [{ id: "other", name: "Other Provider", models: [gamma] }], - total: 3, + providers: [{ id: "other", name: "Other Provider", models: [gamma, gammaFree] }], + total: 4, next: null, }) - expect(yield* run({ provider: "other provider" })).toMatchObject({ total: 2, providers: [{ id: "other" }] }) + expect(yield* run({ provider: "other provider" })).toMatchObject({ total: 3, providers: [{ id: "other" }] }) expect(yield* run({ provider: "test" })).toEqual({ providers: [{ id: "test", name: "test", models: [alpha] }], total: 1, @@ -127,18 +134,21 @@ it.effect("groups available models by provider with paging", () => // Every word of the query must appear somewhere in the reference or display name, ignoring case. expect(yield* run({ query: "GAMMA" })).toEqual({ - providers: [{ id: "other", name: "Other Provider", models: [gamma] }], - total: 1, + providers: [{ id: "other", name: "Other Provider", models: [gamma, gammaFree, gammaOld] }], + total: 3, next: null, }) expect(yield* run({ query: "test/" })).toMatchObject({ total: 1, providers: [{ id: "test" }] }) - expect(yield* run({ query: "other flash" })).toMatchObject({ total: 1, providers: [{ models: [gamma] }] }) + expect(yield* run({ query: "other flash" })).toMatchObject({ + total: 3, + providers: [{ models: [gamma, gammaFree, gammaOld] }], + }) expect(yield* run({ query: "gamma beta" })).toEqual({ providers: [], total: 0, next: null }) - // Only the newest model of each family is listed unless `all` is set; the query is applied first. + // Browsing hides older versions of a family unless `all` is set; same-day siblings stay. Searches list every match. expect(yield* run({ all: true })).toMatchObject({ - total: 4, - providers: [{ id: "test" }, { id: "other", models: [beta, gamma, gammaOld] }], + total: 5, + providers: [{ id: "test" }, { id: "other", models: [beta, gamma, gammaFree, gammaOld] }], }) expect(yield* run({ query: "old" })).toMatchObject({ total: 1, providers: [{ models: [gammaOld] }] }) expect(yield* run({ provider: "other", query: "alpha" })).toEqual({ providers: [], total: 0, next: null })