Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
TypeScript agentic-aiagentsaiai-agentsaiagentsdeveloper-toolsfunction-callinggpt-4javascriptjsllmllmopsmcppythonremote-mcp-serverssetypescript
fix(docs): bound toolkit miss cache
jkomyno5ff344bc3407
diff --git a/docs/lib/toolkit-api.ts b/docs/lib/toolkit-api.tsindex 8ff72dfe9..6a9c452aa 100644--- a/docs/lib/toolkit-api.ts+++ b/docs/lib/toolkit-api.ts@@ -3,6 +3,7 @@ import { PRODUCTION_API_V3_URL } from '@/scripts/production-api.mjs';import type { AuthConfigDetail, AuthConfigField, Toolkit } from '@/types/toolkit';const NEGATIVE_CACHE_TTL_MS = 60_000;+const NEGATIVE_CACHE_MAX_ENTRIES = 1_024;const TOOLKIT_SLUG_PATTERN = /^[a-z0-9][a-z0-9_-]{0,63}$/;const negativeCache = new Map<string, number>();@@ -192,7 +193,18 @@ function toolkitFromRaw(raw: RawToolkit, slug: string): Toolkit {}function recordNegative(slug: string) {- negativeCache.set(slug, Date.now() + NEGATIVE_CACHE_TTL_MS);+ const now = Date.now();+ for (const [cachedSlug, expiresAt] of negativeCache) {+ if (expiresAt > now) break;+ negativeCache.delete(cachedSlug);+ }++ negativeCache.delete(slug);+ if (negativeCache.size >= NEGATIVE_CACHE_MAX_ENTRIES) {+ const oldestSlug = negativeCache.keys().next().value;+ if (oldestSlug !== undefined) negativeCache.delete(oldestSlug);+ }+ negativeCache.set(slug, now + NEGATIVE_CACHE_TTL_MS);}/** Fetch one toolkit's metadata from production after a checked-in snapshot miss. */diff --git a/docs/tests/static/toolkit-api.test.ts b/docs/tests/static/toolkit-api.test.tsindex fcd0fafb6..5df9eff49 100644--- a/docs/tests/static/toolkit-api.test.ts+++ b/docs/tests/static/toolkit-api.test.ts@@ -284,6 +284,21 @@ describe('fetchToolkitFromProduction', () => {expect(warning).toHaveBeenCalledTimes(2);});+ test('bounds negative-cache entries for unique missing slugs', async () => {+ useApiKey();+ const fetcher = mock(async () => new Response(null, { status: 404 }));+ globalThis.fetch = fetcher;+ spyOn(console, 'warn').mockImplementation(() => {});++ for (let index = 0; index <= 1_024; index += 1) {+ expect(await fetchToolkitFromProduction(`bounded-miss-${index}`)).toBeNull();+ }+ expect(fetcher).toHaveBeenCalledTimes(1_025);++ expect(await fetchToolkitFromProduction('bounded-miss-0')).toBeNull();+ expect(fetcher).toHaveBeenCalledTimes(1_026);+ });+test.each([['500 response', async () => new Response(null, { status: 500 })],['network error', async () => Promise.reject(new Error('offline'))],