mirror of
https://gitee.com/zhangsken/opencode.git
synced 2026-10-16 10:30:01 +08:00
fix(updates): respect the default CLI user agent
This commit is contained in:
@@ -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)]),
|
||||
},
|
||||
),
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user