MCPcopy Index your code
hub / github.com/anomalyco/opencode / createServerSyncContextInner

Function createServerSyncContextInner

packages/app/src/context/server-sync.tsx:102–513  ·  view source on GitHub ↗
(serverSDK: ServerSDK)

Source from the content-addressed store, hash-verified

100export type QueryOptionsApi = ReturnType<typeof makeQueryOptionsApi>
101
102export function createServerSyncContextInner(serverSDK: ServerSDK) {
103 const language = useLanguage()
104 const owner = getOwner()
105 if (!owner) throw new Error("ServerSync must be created within owner")
106
107 const sdkCache = new Map<string, OpencodeClient>()
108 const booting = new Map<string, Promise<void>>()
109 const sessionLoads = new Map<string, Promise<void>>()
110 const sessionMeta = new Map<string, { limit: number }>()
111
112 const sdkFor = (directory: string) => {
113 const key = directoryKey(directory)
114 const cached = sdkCache.get(key)
115 if (cached) return cached
116 const sdk = serverSDK.createClient({
117 directory,
118 throwOnError: true,
119 })
120 sdkCache.set(key, sdk)
121 return sdk
122 }
123
124 const queryOptionsApi = makeQueryOptionsApi(serverSDK.scope, () => serverSDK.client, sdkFor)
125
126 const [configQuery, providerQuery, pathQuery] = useQueries(() => ({
127 queries: [queryOptionsApi.globalConfig(), queryOptionsApi.providers(null), queryOptionsApi.path(null)],
128 }))
129
130 const [globalStore, setGlobalStore] = createStore<GlobalStore>({
131 get ready() {
132 return !bootstrap.isPending
133 },
134 project: [],
135 provider_auth: {},
136 get path() {
137 const EMPTY = { state: "", config: "", worktree: "", directory: "", home: "" }
138 if (pathQuery.isLoading) return EMPTY
139 return pathQuery.data ?? EMPTY
140 },
141 get provider() {
142 const EMPTY = { all: new Map(), connected: [], default: {} }
143 if (providerQuery.isLoading) return EMPTY
144 return providerQuery.data ?? EMPTY
145 },
146 get config() {
147 if (configQuery.isLoading) return {}
148 return configQuery.data ?? {}
149 },
150 get reload() {
151 return updateConfigMutation.isPending ? "pending" : undefined
152 },
153 })
154
155 const queryClient = useQueryClient()
156
157 let bootedAt = 0
158 let bootingRoot = false
159 let eventFrame: number | undefined

Callers 1

createServerSyncContextFunction · 0.85

Calls 15

bootstrapGlobalFunction · 0.90
createRefreshQueueFunction · 0.90
createServerSessionFunction · 0.90
createChildStoreManagerFunction · 0.90
retryFunction · 0.90
showToastFunction · 0.90
getFilenameFunction · 0.90
formatServerErrorFunction · 0.90
clearProviderRevFunction · 0.90
applyGlobalEventFunction · 0.90
applyDirectoryEventFunction · 0.90
toggleMcpFunction · 0.90

Tested by

no test coverage detected