Files
oh-my-pi/packages/coding-agent/src/extensibility/tool-proxy.ts
T
can1357 dcb8d10a72 refactor(coding-agent/extensibility): extracted tool proxy logic into reusable applyToolProxy utility function
- Extracted tool property proxying logic into a new applyToolProxy utility function to reduce duplication across wrapper classes.
- Simplified wrapper class implementations by replacing manual property assignments with declarative property forwarding via applyToolProxy.
- Converted explicit property declarations to declare statements and lazy getters that delegate to the underlying tool object.
- Removed renderCall and renderResult method declarations from wrapper classes, consolidating rendering logic handling in the tool-proxy module.
2026-02-04 07:06:21 +01:00

26 lines
769 B
TypeScript

/**
* Defines lazy proxy properties on a wrapper so it forwards to the underlying tool.
*/
export function applyToolProxy<TTool extends object>(tool: TTool, wrapper: object): void {
const visited = new Set<PropertyKey>();
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<PropertyKey, unknown>)[key];
return typeof value === "function" ? value.bind(tool) : value;
},
enumerable: true,
configurable: true,
});
}
current = Object.getPrototypeOf(current);
}
}