/** * Defines lazy proxy properties on a wrapper so it forwards to the underlying tool. */ export function applyToolProxy(tool: TTool, wrapper: object): void { const visited = new Set(); let current: object | null = tool; while (current && current !== Object.prototype) { for (const key of Reflect.ownKeys(current)) { if (key === "constructor" || visited.has(key) || key in wrapper) { continue; } visited.add(key); Object.defineProperty(wrapper, key, { get() { const value = (tool as Record)[key]; return typeof value === "function" ? value.bind(tool) : value; }, enumerable: true, configurable: true, }); } current = Object.getPrototypeOf(current); } }