MCPcopy
hub / github.com/thesysdev/openui / evaluateQueries

Function evaluateQueries

packages/lang-core/src/runtime/queryManager.ts:319–394  ·  view source on GitHub ↗
(queryNodes: QueryNode[])

Source from the content-addressed store, hash-verified

317 // ── Query evaluation ─────────────────────────────────────────────────────
318
319 function evaluateQueries(queryNodes: QueryNode[]) {
320 if (disposed) return;
321
322 const activeIds = new Set(queryNodes.map((n) => n.statementId));
323
324 // Clean up removed queries
325 for (const [sid, q] of queries) {
326 if (!activeIds.has(sid)) {
327 if (q.timer) clearInterval(q.timer);
328 queries.delete(sid);
329 // Clean up cache entries that are no longer referenced
330 cleanupCacheEntry(q.cacheKey);
331 if (q.prevCacheKey) cleanupCacheEntry(q.prevCacheKey);
332 }
333 }
334
335 // Process active queries
336 for (const node of queryNodes) {
337 if (!node.complete) continue;
338
339 const cacheKey = buildCacheKey(node.toolName, node.args, node.deps);
340 const existing = queries.get(node.statementId);
341
342 if (existing) {
343 // Track previous cache key for fallback display
344 if (existing.cacheKey !== cacheKey) {
345 existing.prevCacheKey = existing.cacheKey;
346 }
347 existing.toolName = node.toolName;
348 existing.args = node.args;
349 existing.defaults = node.defaults;
350 existing.cacheKey = cacheKey;
351 } else {
352 queries.set(node.statementId, {
353 toolName: node.toolName,
354 args: node.args,
355 defaults: node.defaults,
356 cacheKey,
357 loading: false,
358 everFetched: false,
359 refreshInterval: 0,
360 needsRefetch: false,
361 });
362 }
363
364 const q = queries.get(node.statementId)!;
365
366 // Fire fetch if no settled data and not already in-flight
367 const entry = cache.get(cacheKey);
368 const hasSettledData = entry && entry.data !== undefined && !entry.inFlight;
369 if (toolProvider && !hasSettledData && !entry?.inFlight) {
370 executeFetch(cacheKey, node.statementId);
371 }
372
373 // Configure auto-refresh timer
374 const newInterval = node.refreshInterval ?? 0;
375 if (newInterval !== q.refreshInterval) {
376 if (q.timer) {

Callers

nothing calls this directly

Calls 8

cleanupCacheEntryFunction · 0.85
buildCacheKeyFunction · 0.85
executeFetchFunction · 0.85
hasMethod · 0.80
rebuildSnapshotFunction · 0.70
notifyFunction · 0.70
getMethod · 0.65
setMethod · 0.65

Tested by

no test coverage detected