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

Function fetchCcsharePayload

src/utils/ccshareResume.ts:80–123  ·  view source on GitHub ↗
(ccshareId: string)

Source from the content-addressed store, hash-verified

78}
79
80async function fetchCcsharePayload(ccshareId: string): Promise<unknown> {
81 await getAuthRuntime().resolveSession({ allowRefresh: true })
82
83 const urls = buildCcshareCandidateUrls(ccshareId)
84 const failures: string[] = []
85
86 for (const url of urls) {
87 try {
88 const response = await withOAuth401Retry(() => {
89 const authResult = getAuthHeaders()
90 if (authResult.error) {
91 throw new Error(`Failed to get auth headers: ${authResult.error}`)
92 }
93 return axios.get<string>(url, {
94 headers: {
95 ...authResult.headers,
96 Accept: 'application/json, text/plain;q=0.9, */*;q=0.1',
97 'User-Agent': getUserAgent(),
98 },
99 timeout: 15000,
100 responseType: 'text',
101 transformResponse: value => value,
102 })
103 }, {
104 also403Revoked: true,
105 })
106
107 logForDebugging(`ccshare fetch succeeded: ${url}`, { level: 'info' })
108 return parseTransportPayload(response.data)
109 } catch (error) {
110 const status = axios.isAxiosError(error) ? error.response?.status : null
111 const detail =
112 status !== undefined && status !== null
113 ? `${url} -> HTTP ${status}`
114 : `${url} -> ${errorMessage(error)}`
115 failures.push(detail)
116 logForDebugging(`ccshare fetch failed: ${detail}`, { level: 'warn' })
117 }
118 }
119
120 throw new Error(
121 `Unable to fetch shared transcript. Tried ${urls.length} endpoint${urls.length === 1 ? '' : 's'}: ${failures.join('; ')}`,
122 )
123}
124
125export function buildCcshareCandidateUrls(ccshareId: string): string[] {
126 const encoded = encodeURIComponent(ccshareId)

Callers 1

loadCcshareFunction · 0.85

Calls 10

getAuthRuntimeFunction · 0.85
withOAuth401RetryFunction · 0.85
getUserAgentFunction · 0.85
parseTransportPayloadFunction · 0.85
getAuthHeadersFunction · 0.70
logForDebuggingFunction · 0.70
errorMessageFunction · 0.70
resolveSessionMethod · 0.65
getMethod · 0.45

Tested by

no test coverage detected