fix: patch bug in tool registry that was losing tools on build

This commit is contained in:
cpacker
2025-10-24 23:52:46 -07:00
parent f158917ff7
commit 33f2433095

View File

@@ -47,7 +47,17 @@ export type ToolExecutionResult = {
type ToolRegistry = Map<string, ToolDefinition>;
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.