MCPcopy Create free account
hub / github.com/adcontextprotocol/adcp / getSession

Function getSession

server/src/training-agent/state.ts:309–336  ·  view source on GitHub ↗
(key: string)

Source from the content-addressed store, hash-verified

307 * machines see each other's writes.
308 */
309export async function getSession(key: string): Promise<SessionState> {
310 const ctx = requestCtx.getStore();
311 if (ctx) {
312 const cached = ctx.sessions.get(key);
313 if (cached) return cached;
314 }
315
316 let session: SessionState | undefined;
317 try {
318 const storedShape = await getStore().get<Record<string, unknown>>(SESSIONS_COLLECTION, key);
319 if (storedShape) session = deserializeSession(storedShape);
320 } catch (err) {
321 logger.warn({ err, key }, 'Failed to load session from store; creating fresh');
322 }
323 if (!session) {
324 session = createSession();
325 }
326 session.lastAccessedAt = new Date();
327
328 if (ctx) {
329 ctx.sessions.set(key, session);
330 // Snapshot the round-trip shape (serialize after deserialize) so any
331 // normalization done by (de)serialize doesn't register as a mutation.
332 // stableStringify drops lastAccessedAt so "touch-only" reads don't flush.
333 ctx.snapshots.set(key, stableStringify(serializeSession(session, key)));
334 }
335 return session;
336}
337
338
339const MAX_DOMAIN_LEN = 253; // RFC 1035 max hostname length

Callers 15

handleGetProductsFunction · 0.85
handleCreateMediaBuyFunction · 0.85
handleGetMediaBuysFunction · 0.85
handleSyncCreativesFunction · 0.85
handleListCreativesFunction · 0.85
handleUpdateMediaBuyFunction · 0.85
handleGetSignalsFunction · 0.85
handleActivateSignalFunction · 0.85
handleBuildCreativeFunction · 0.85
handlePreviewCreativeFunction · 0.85

Calls 8

getStoreFunction · 0.85
deserializeSessionFunction · 0.85
createSessionFunction · 0.85
serializeSessionFunction · 0.85
warnMethod · 0.80
stableStringifyFunction · 0.70
getMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected