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

Function uploadTeamMemory

src/services/teamMemorySync/index.ts:460–551  ·  view source on GitHub ↗
(
  state: SyncState,
  repoSlug: string,
  entries: Record<string, string>,
  ifMatchChecksum?: string | null,
)

Source from the content-addressed store, hash-verified

458}
459
460async function uploadTeamMemory(
461 state: SyncState,
462 repoSlug: string,
463 entries: Record<string, string>,
464 ifMatchChecksum?: string | null,
465): Promise<TeamMemorySyncUploadResult> {
466 try {
467 const session = await getAuthRuntime().resolveSession({ allowRefresh: true })
468
469 const auth = getAuthHeaders(session)
470 if (auth.error) {
471 return { success: false, error: auth.error, errorType: 'auth' }
472 }
473
474 const headers: Record<string, string> = {
475 ...auth.headers,
476 'Content-Type': 'application/json',
477 }
478 if (ifMatchChecksum) {
479 headers['If-Match'] = `"${ifMatchChecksum.replace(/"/g, '')}"`
480 }
481
482 const endpoint = getTeamMemorySyncEndpoint(repoSlug)
483 const response = await axios.put(
484 endpoint,
485 { entries },
486 {
487 headers,
488 timeout: TEAM_MEMORY_SYNC_TIMEOUT_MS,
489 validateStatus: status => status === 200 || status === 412,
490 },
491 )
492
493 if (response.status === 412) {
494 logForDebugging('team-memory-sync: conflict (412 Precondition Failed)', {
495 level: 'info',
496 })
497 return { success: false, conflict: true, error: 'ETag mismatch' }
498 }
499
500 const responseChecksum = response.data?.checksum
501 if (responseChecksum) {
502 state.lastKnownChecksum = responseChecksum
503 }
504
505 logForDebugging(
506 `team-memory-sync: uploaded ${Object.keys(entries).length} entries (checksum: ${responseChecksum ?? 'none'})`,
507 { level: 'debug' },
508 )
509 return {
510 success: true,
511 checksum: responseChecksum,
512 lastModified: response.data?.lastModified,
513 }
514 } catch (error) {
515 const body = axios.isAxiosError(error)
516 ? JSON.stringify(error.response?.data ?? '')
517 : ''

Callers 1

pushTeamMemoryFunction · 0.85

Calls 7

getAuthRuntimeFunction · 0.85
classifyAxiosErrorFunction · 0.85
keysMethod · 0.80
getAuthHeadersFunction · 0.70
resolveSessionMethod · 0.65
logForDebuggingFunction · 0.50

Tested by

no test coverage detected