fix(updates): respect the default CLI user agent

This commit is contained in:
Dax Raad
2026-09-07 16:49:59 -04:00
parent c05d07cd73
commit a3bbcd5c73
3 changed files with 6 additions and 4 deletions
-1
View File
@@ -125,7 +125,6 @@ const make = Effect.gen(function* () {
fetch(
`https://update.opencode.ai/api/${encodeURIComponent(channel)}/${encodeURIComponent(OPENCODE_ARTIFACT)}/npm?current=${encodeURIComponent(OPENCODE_VERSION)}`,
{
headers: { "User-Agent": `opencode/${OPENCODE_VERSION}` },
signal: AbortSignal.any([signal, AbortSignal.timeout(10_000)]),
},
),
+4 -2
View File
@@ -14,8 +14,10 @@ Each channel/name/distribution can mark one retained artifact as `minimum`, inde
of its `active` artifact. Set or clear it from the admin page. Publishing a new active
release preserves the minimum marker.
Clients send their running version as `?current=<version>`. Existing clients fall back
to `User-Agent: opencode/<version>`. A caller below the minimum receives that exact
Clients send their running version as `?current=<version>` and use the CLI's default
`User-Agent: opencode/<channel>/<version>/cli`. When `current` is absent, the service
parses that User-Agent or the older `opencode/<version>` format.
A caller below the minimum receives that exact
artifact; callers at or above it receive the active artifact. An unparseable caller
version receives the minimum. Requests with neither version source receive the active
artifact. All three public API paths apply the same selection and use `Cache-Control:
+2 -1
View File
@@ -70,7 +70,8 @@ export default {
}
const resolved = resolveChannel(path[0])
const current = url.searchParams.get("current") ?? request.headers.get("User-Agent")?.match(/^opencode\/(.*)$/)?.[1]
const agent = request.headers.get("User-Agent")?.match(/^opencode\/(?:[^/]+\/([^/]+)\/cli|(.*))$/)
const current = url.searchParams.get("current") ?? agent?.[1] ?? agent?.[2]
if (path.length === 1) return channel(env.DB, resolved, current)
if (path.length === 2) return artifactName(env.DB, resolved, path[1], current)
return artifactDistribution(env.DB, resolved, path[1], path[2], current)