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

Function findSessionMatching

server/src/training-agent/state.ts:465–491  ·  view source on GitHub ↗
(predicate: (s: SessionState) => boolean)

Source from the content-addressed store, hash-verified

463 * persisted store (listed in pages of 100).
464 */
465export async function findSessionMatching(predicate: (s: SessionState) => boolean): Promise<SessionState | null> {
466 const ctx = requestCtx.getStore();
467 if (ctx) {
468 for (const session of ctx.sessions.values()) {
469 if (predicate(session)) return session;
470 }
471 }
472 const store = storeInstance;
473 if (!store) return null;
474 try {
475 const page = await store.list<Record<string, unknown>>(SESSIONS_COLLECTION, { limit: 100 });
476 for (const row of page.items ?? []) {
477 const sessionKey = typeof row.__sessionKey === 'string' ? row.__sessionKey : undefined;
478 const session = deserializeSession(row);
479 if (predicate(session)) {
480 if (ctx && sessionKey) {
481 ctx.sessions.set(sessionKey, session);
482 ctx.snapshots.set(sessionKey, stableStringify(serializeSession(session, sessionKey)));
483 }
484 return session;
485 }
486 }
487 } catch (err) {
488 logger.warn({ err }, 'findSessionMatching: store list failed');
489 }
490 return null;
491}
492
493export function findMediaBuyAcrossSessions(mediaBuyId: string): Promise<SessionState | null> {
494 return findSessionMatching(s => s.mediaBuys.has(mediaBuyId));

Calls 5

deserializeSessionFunction · 0.85
serializeSessionFunction · 0.85
warnMethod · 0.80
stableStringifyFunction · 0.70
setMethod · 0.45

Tested by

no test coverage detected