fix(app): share synced session data (#33624)

This commit is contained in:
Brendan Allan 2026-06-24 16:40:35 +08:00 committed by GitHub
parent d465cd476a
commit 2312a15e57
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 12 deletions

View File

@ -7,7 +7,6 @@ import { useServerSync } from "./server-sync"
import { usePlatform } from "@/context/platform" import { usePlatform } from "@/context/platform"
import { useLanguage } from "@/context/language" import { useLanguage } from "@/context/language"
import { useSettings } from "@/context/settings" import { useSettings } from "@/context/settings"
import { Binary } from "@opencode-ai/core/util/binary"
import { base64Encode } from "@opencode-ai/core/util/encode" import { base64Encode } from "@opencode-ai/core/util/encode"
import { decode64 } from "@/utils/base64" import { decode64 } from "@/utils/base64"
import { EventSessionError } from "@opencode-ai/sdk/v2" import { EventSessionError } from "@opencode-ai/sdk/v2"
@ -208,12 +207,12 @@ export const { use: useNotification, provider: NotificationProvider } = createSi
const lookup = async (directory: string, sessionID?: string) => { const lookup = async (directory: string, sessionID?: string) => {
if (!sessionID) return undefined if (!sessionID) return undefined
const [syncStore] = serverSync().child(directory, { bootstrap: false }) const sync = serverSync().createDirSyncContext(directory)
const match = Binary.search(syncStore.session, sessionID, (s) => s.id) const session = sync.session.get(sessionID)
if (match.found) return syncStore.session[match.index] if (session) return session
return serverSDK() return sync.session
.client.session.get({ directory, sessionID }) .sync(sessionID)
.then((x) => x.data) .then(() => sync.session.get(sessionID))
.catch(() => undefined) .catch(() => undefined)
} }

View File

@ -1299,15 +1299,15 @@ export default function LegacyLayout(props: ParentProps) {
} }
const openSession = async (target: { directory: string; id: string }) => { const openSession = async (target: { directory: string; id: string }) => {
if (!canOpen(target.directory)) return false if (!canOpen(target.directory)) return false
const [data] = serverSync().child(target.directory, { bootstrap: false }) const sync = serverSync().createDirSyncContext(target.directory)
if (data.session.some((item) => item.id === target.id)) { if (sync.session.get(target.id)) {
setStore("lastProjectSession", root, { directory: target.directory, id: target.id, at: Date.now() }) setStore("lastProjectSession", root, { directory: target.directory, id: target.id, at: Date.now() })
navigateWithSidebarReset(`/${base64Encode(target.directory)}/session/${target.id}`) navigateWithSidebarReset(`/${base64Encode(target.directory)}/session/${target.id}`)
return true return true
} }
const resolved = await serverSDK() const resolved = await sync.session
.client.session.get({ sessionID: target.id }) .sync(target.id)
.then((x) => x.data) .then(() => sync.session.get(target.id))
.catch(() => undefined) .catch(() => undefined)
if (!resolved?.directory) return false if (!resolved?.directory) return false
if (!canOpen(resolved.directory)) return false if (!canOpen(resolved.directory)) return false