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

Function createServerCtx

packages/app/src/context/global.tsx:95–144  ·  view source on GitHub ↗
(
  conn: ServerConnection.Any,
  scope: ServerScope,
  projects: ReturnType<typeof createServerProjects>,
)

Source from the content-addressed store, hash-verified

93})
94
95function createServerCtx(
96 conn: ServerConnection.Any,
97 scope: ServerScope,
98 projects: ReturnType<typeof createServerProjects>,
99) {
100 const queryClient = new QueryClient({
101 defaultOptions: {
102 queries: {
103 refetchOnReconnect: false,
104 refetchOnMount: false,
105 refetchOnWindowFocus: false,
106 },
107 },
108 })
109 const sdk = createServerSdkContext(conn, scope)
110 const sync = createServerSyncContext(sdk)
111
112 function enrich(project: { worktree: string; expanded: boolean }) {
113 const [childStore] = sync.child(project.worktree, { bootstrap: false })
114 const projectID = childStore.project
115 const metadata = projectID
116 ? sync.data.project.find((x) => x.id === projectID)
117 : sync.data.project.find((x) => x.worktree === project.worktree)
118
119 // Preserve local icon override from per-workspace localStorage cache (childStore.icon).
120 // Without this, different subdirectories of the same git repo would share the same
121 // icon from the database instead of using their individual overrides.
122 const base = { ...metadata, ...project }
123 if (childStore.icon) {
124 return { ...base, icon: { ...base.icon, override: childStore.icon } }
125 }
126 return base
127 }
128
129 const projectsList = createMemo(() => projects.list().map(enrich))
130
131 const isLocal =
132 (conn?.type === "sidecar" && conn.variant === "base") || (conn?.type === "http" && isLocalHost(conn.http.url))
133
134 return {
135 queryClient,
136 sdk,
137 sync,
138 isLocal,
139 projects: {
140 ...projects,
141 list: projectsList,
142 },
143 }
144}
145
146export type ServerCtx = ReturnType<typeof createServerCtx>
147

Callers 1

ensureServerCtxFunction · 0.85

Calls 4

createServerSdkContextFunction · 0.90
createServerSyncContextFunction · 0.90
isLocalHostFunction · 0.70
listMethod · 0.65

Tested by

no test coverage detected