From 33f2433095c454eac28bb37c9ebd609308168736 Mon Sep 17 00:00:00 2001 From: cpacker Date: Fri, 24 Oct 2025 23:52:46 -0700 Subject: [PATCH] fix: patch bug in tool registry that was losing tools on build --- src/tools/manager.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/tools/manager.ts b/src/tools/manager.ts index 46d8315..37a4fdc 100644 --- a/src/tools/manager.ts +++ b/src/tools/manager.ts @@ -47,7 +47,17 @@ export type ToolExecutionResult = { type ToolRegistry = Map; -const toolRegistry: ToolRegistry = new Map(); +// Use globalThis to ensure singleton across bundle +// This prevents Bun's bundler from creating duplicate instances of the registry +const REGISTRY_KEY = Symbol.for("@letta/toolRegistry"); +function getRegistry(): ToolRegistry { + if (!(globalThis as any)[REGISTRY_KEY]) { + (globalThis as any)[REGISTRY_KEY] = new Map(); + } + return (globalThis as any)[REGISTRY_KEY]; +} + +const toolRegistry = getRegistry(); /** * Generates a Python stub for a tool that will be executed client-side.