Skip to content

Commit 9185309

Browse files
committed
fix: treat released=0 as unknown date to keep config models visible
Models declared in opencode.jsonc that the server does not have a release date for are emitted with time.released=0. Mapping 0 to new Date(0) produces the ISO string "1970-01-01", which is a valid Luxon DateTime. The visibility filter in models.tsx only shows models whose release date is within the past 6 months or whose date is invalid/unknown. With a valid 1970-01-01 date the model fell into the "hidden by default" branch and never appeared in the model picker, even though the user had explicitly configured it. Fix: when model.time.released === 0, set release_date to undefined instead. That makes date?.isValid falsy in the visibility guard, which triggers the "return true" escape hatch and keeps the model visible. Also adds a dedicated regression test to normalizeProviderList covering active models with released=0 asserting release_date is undefined. Fixes: anomalyco#49605
1 parent 5a83358 commit 9185309

2 files changed

Lines changed: 35 additions & 5 deletions

File tree

‎packages/app/src/context/global-sync/utils.test.ts‎

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { describe, expect, test } from "bun:test"
1+
import { describe, expect, test } from "bun:test"
22
import type {
33
AgentListOutput,
44
ModelDefaultOutput,
@@ -118,6 +118,36 @@ describe("normalizeProviderList", () => {
118118
test("preserves an empty current default", () => {
119119
expect(normalizeProviderList([] as ProviderListOutput["data"], [], null).defaultModel).toBeNull()
120120
})
121+
122+
test("sets release_date to undefined when the server reports released=0", () => {
123+
// Models with time.released === 0 have no known release date. The server
124+
// uses 0 as a sentinel for "unreleased" or "config-only" models. Mapping 0
125+
// to "1970-01-01" produces a valid DateTime in the visibility filter, which
126+
// then hides the model because 1970-01-01 is outside the recent 6-month
127+
// window. Setting release_date to undefined instead triggers the
128+
// unknown-date escape hatch in models.tsx and keeps the model visible.
129+
const result = normalizeProviderList(
130+
[{ id: "custom", name: "Custom", package: "@custom/provider" }] as ProviderListOutput["data"],
131+
[
132+
{
133+
id: "my-model",
134+
modelID: "my-model",
135+
providerID: "custom",
136+
name: "My Model",
137+
capabilities: { tools: true, input: ["text"], output: ["text"] },
138+
variants: [],
139+
time: { released: 0 },
140+
cost: [],
141+
status: "active",
142+
enabled: true,
143+
limit: { context: 32_000, output: 4_096 },
144+
},
145+
] as ModelListOutput["data"],
146+
undefined,
147+
)
148+
149+
expect(result.all.get("custom")?.models["my-model"]?.release_date).toBeUndefined()
150+
})
121151
})
122152

123153
describe("directoryKey", () => {
@@ -135,4 +165,4 @@ describe("directoryKey", () => {
135165
expect(String(directoryKey("C:/"))).toBe("C:/")
136166
expect(String(directoryKey("/"))).toBe("/")
137167
})
138-
})
168+
})

‎packages/app/src/context/global-sync/utils.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type {
1+
import type {
22
AgentListOutput,
33
ModelDefaultOutput,
44
ModelListOutput,
@@ -131,7 +131,7 @@ export function normalizeProviderList(
131131
status: model.status,
132132
options: model.settings ?? {},
133133
headers: model.headers ?? {},
134-
release_date: new Date(model.time.released).toISOString().slice(0, 10),
134+
release_date: model.time.released === 0 ? undefined : new Date(model.time.released).toISOString().slice(0, 10),
135135
variants: Object.fromEntries(model.variants.map((variant) => [variant.id, variant.settings ?? {}])),
136136
}
137137
}
@@ -169,4 +169,4 @@ export function normalizeProjectInfo(project: Project | CurrentProject): Project
169169
...project,
170170
vcs: project.vcs === "git" ? "git" : undefined,
171171
}
172-
}
172+
}

0 commit comments

Comments
 (0)