MCPcopy Create free account
hub / github.com/Noumena-Network/code / fetchTeamMemoryOnce

Function fetchTeamMemoryOnce

src/services/teamMemorySync/index.ts:186–304  ·  view source on GitHub ↗
(
  state: SyncState,
  repoSlug: string,
  etag?: string | null,
)

Source from the content-addressed store, hash-verified

184// ─── Fetch (pull) ────────────────────────────────────────────
185
186async function fetchTeamMemoryOnce(
187 state: SyncState,
188 repoSlug: string,
189 etag?: string | null,
190): Promise<TeamMemorySyncFetchResult> {
191 try {
192 const session = await getAuthRuntime().resolveSession({ allowRefresh: true })
193
194 const auth = getAuthHeaders(session)
195 if (auth.error) {
196 return {
197 success: false,
198 error: auth.error,
199 skipRetry: true,
200 errorType: 'auth',
201 }
202 }
203
204 const headers: Record<string, string> = { ...auth.headers }
205 if (etag) {
206 headers['If-None-Match'] = `"${etag.replace(/"/g, '')}"`
207 }
208
209 const endpoint = getTeamMemorySyncEndpoint(repoSlug)
210 const response = await axios.get(endpoint, {
211 headers,
212 timeout: TEAM_MEMORY_SYNC_TIMEOUT_MS,
213 validateStatus: status =>
214 status === 200 || status === 304 || status === 404,
215 })
216
217 if (response.status === 304) {
218 logForDebugging('team-memory-sync: not modified (304)', {
219 level: 'debug',
220 })
221 return { success: true, notModified: true, checksum: etag ?? undefined }
222 }
223
224 if (response.status === 404) {
225 logForDebugging('team-memory-sync: no remote data (404)', {
226 level: 'debug',
227 })
228 state.lastKnownChecksum = null
229 return { success: true, isEmpty: true }
230 }
231
232 const parsed = TeamMemoryDataSchema().safeParse(response.data)
233 if (!parsed.success) {
234 logForDebugging('team-memory-sync: invalid response format', {
235 level: 'warn',
236 })
237 return {
238 success: false,
239 error: 'Invalid team memory response format',
240 skipRetry: true,
241 errorType: 'parse',
242 }
243 }

Callers 1

fetchTeamMemoryFunction · 0.85

Calls 7

getAuthRuntimeFunction · 0.85
classifyAxiosErrorFunction · 0.85
getAuthHeadersFunction · 0.70
resolveSessionMethod · 0.65
logForDebuggingFunction · 0.50
getMethod · 0.45

Tested by

no test coverage detected