📄 File detail

utils/toolSchemaCache.ts

🧩 .ts📏 27 lines💾 1,061 bytes📝 text
← Back to All Files

🎯 Use case

This file lives under “utils/”, which covers cross-cutting helpers (shell, tempfiles, settings, messages, process input, …). On the API surface it exposes getToolSchemaCache and clearToolSchemaCache — mainly functions, hooks, or classes. Dependencies touch @anthropic-ai. What the file header says: Session-scoped cache of rendered tool schemas. Tool schemas render at server position 2 (before system prompt), so any byte-level change busts the entire ~11K-token tool block AND everything downstream. GrowthBook gate flips (tengu_tool_pear, tengu_fgts), MCP reconnects, or dynam.

Generated from folder role, exports, dependency roots, and inline comments — not hand-reviewed for every path.

🧠 Inline summary

Session-scoped cache of rendered tool schemas. Tool schemas render at server position 2 (before system prompt), so any byte-level change busts the entire ~11K-token tool block AND everything downstream. GrowthBook gate flips (tengu_tool_pear, tengu_fgts), MCP reconnects, or dynamic content in tool.prompt() all cause this churn. Memoizing per-session locks the schema bytes at first render — mid-session GB refreshes no longer bust the cache. Lives in a leaf module so auth.ts can clear it without importing api.ts (which would create a cycle via plans→settings→file→growthbook→config→ bridgeEnabled→auth).

📤 Exports (heuristic)

  • getToolSchemaCache
  • clearToolSchemaCache

📚 External import roots

Package roots from from "…" (relative paths omitted).

  • @anthropic-ai

🖥️ Source preview

import type { BetaTool } from '@anthropic-ai/sdk/resources/beta/messages/messages.mjs'

// Session-scoped cache of rendered tool schemas. Tool schemas render at server
// position 2 (before system prompt), so any byte-level change busts the entire
// ~11K-token tool block AND everything downstream. GrowthBook gate flips
// (tengu_tool_pear, tengu_fgts), MCP reconnects, or dynamic content in
// tool.prompt() all cause this churn. Memoizing per-session locks the schema
// bytes at first render — mid-session GB refreshes no longer bust the cache.
//
// Lives in a leaf module so auth.ts can clear it without importing api.ts
// (which would create a cycle via plans→settings→file→growthbook→config→
// bridgeEnabled→auth).
type CachedSchema = BetaTool & {
  strict?: boolean
  eager_input_streaming?: boolean
}

const TOOL_SCHEMA_CACHE = new Map<string, CachedSchema>()

export function getToolSchemaCache(): Map<string, CachedSchema> {
  return TOOL_SCHEMA_CACHE
}

export function clearToolSchemaCache(): void {
  TOOL_SCHEMA_CACHE.clear()
}