source dump of claude code
at main 26 lines 1.1 kB view raw
1import type { BetaTool } from '@anthropic-ai/sdk/resources/beta/messages/messages.mjs' 2 3// Session-scoped cache of rendered tool schemas. Tool schemas render at server 4// position 2 (before system prompt), so any byte-level change busts the entire 5// ~11K-token tool block AND everything downstream. GrowthBook gate flips 6// (tengu_tool_pear, tengu_fgts), MCP reconnects, or dynamic content in 7// tool.prompt() all cause this churn. Memoizing per-session locks the schema 8// bytes at first render — mid-session GB refreshes no longer bust the cache. 9// 10// Lives in a leaf module so auth.ts can clear it without importing api.ts 11// (which would create a cycle via plans→settings→file→growthbook→config→ 12// bridgeEnabled→auth). 13type CachedSchema = BetaTool & { 14 strict?: boolean 15 eager_input_streaming?: boolean 16} 17 18const TOOL_SCHEMA_CACHE = new Map<string, CachedSchema>() 19 20export function getToolSchemaCache(): Map<string, CachedSchema> { 21 return TOOL_SCHEMA_CACHE 22} 23 24export function clearToolSchemaCache(): void { 25 TOOL_SCHEMA_CACHE.clear() 26}