fix: prevent bundled OpenCode self-upgrades (#2525)

* fix: prevent bundled OpenCode self-upgrades

* feat(vscode): support OpenCode upgrades

* fix: refresh OpenCode update status on runtime switch

---------

Co-authored-by: Bohdan Triapitsyn <artmore@protonmail.com>
This commit is contained in:
𝖎𝖚𝖑𝖎𝖎𝖆
2026-07-29 19:59:41 +03:00
committed by GitHub
co-authored by Bohdan Triapitsyn
parent c0405d3fa4
commit c88dd16d2a
21 changed files with 620 additions and 84 deletions
+1 -36
View File
@@ -64,7 +64,6 @@ import { getRegisteredRuntimeAPIs } from "@/contexts/runtimeAPIRegistry"
import { listGlobalSessionPages } from "@/stores/globalSessions"
import { areRequestArraysReferentiallyEqual, collectScopedBlockingRequests } from "./scoped-blocking-requests"
import { EMPTY_USER_MESSAGE_HISTORY_SNAPSHOT, buildUserMessageHistorySnapshot, type UserMessageHistorySnapshot } from "./user-message-history"
import { runtimeFetch } from "@/lib/runtime-fetch"
import {
EMPTY_SESSION_MESSAGE_LOAD_STATE,
SessionMessageLoader,
@@ -1741,40 +1740,6 @@ const dispatchOpenCodeUpdateAvailable = (payload: { version: string }) => {
window.dispatchEvent(new CustomEvent("openchamber:opencode-update-available", { detail: payload }))
}
let bundledOpenCodeRuntimeCache: { runtimeKey: string; promise: Promise<boolean> } | null = null
const isBundledOpenCodeRuntime = async () => {
const runtimeKey = getRuntimeKey()
if (!bundledOpenCodeRuntimeCache || bundledOpenCodeRuntimeCache.runtimeKey !== runtimeKey) {
bundledOpenCodeRuntimeCache = {
runtimeKey,
promise: runtimeFetch("/api/config/opencode-resolution", { signal: AbortSignal.timeout(4000) })
.then(async (response) => {
if (response.ok) {
const resolution = await response.json() as { source?: unknown; detectedSourceNow?: unknown }
return resolution.source === "bundled" || resolution.detectedSourceNow === "bundled"
}
const healthResponse = await runtimeFetch("/health", { signal: AbortSignal.timeout(4000) })
if (!healthResponse.ok) return false
const health = await healthResponse.json() as { opencodeBinarySource?: unknown }
return health.opencodeBinarySource === "bundled"
})
.catch(() => false),
}
}
return bundledOpenCodeRuntimeCache.promise
}
const dispatchOpenCodeUpdateAvailableUnlessBundled = (payload: { version: string }) => {
if (typeof window === "undefined") return
void isBundledOpenCodeRuntime().then((isBundled) => {
if (!isBundled) {
dispatchOpenCodeUpdateAvailable(payload)
}
})
}
export function SyncProvider(props: {
sdk: OpencodeClient
directory: string
@@ -2017,7 +1982,7 @@ export function SyncProvider(props: {
? (payload.properties as { version: string }).version
: ""
if (version) {
dispatchOpenCodeUpdateAvailableUnlessBundled({ version })
dispatchOpenCodeUpdateAvailable({ version })
}
}
handleEvent(directory, payload, childStores, routingIndex, runtimeKey, false, currentDirectoryRef.current, batch)