Files
oh-my-pi/packages/coding-agent/src/extensibility/tool-proxy.ts
T
can1357 e92db73ec6 feat(coding-agent/tools): added explicit ArkType schema descriptions to agent tools
- Added explicit ArkType schema descriptions across all coding agent tool definitions.
- Updated schema definitions in autoresearch and commit tools with descriptive wrappers.
- Documented tool schema enhancements in the packages/coding-agent CHANGELOG.
2026-06-18 00:59:55 +02:00

29 lines
1.0 KiB
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];
// Bind real methods so `this` is preserved through the wrapper, but leave
// callable values that aren't plain functions untouched — notably an ArkType
// `Type` (the `parameters` schema) is callable yet lacks `Function.prototype.bind`.
return typeof value === "function" && typeof value.bind === "function" ? value.bind(tool) : value;
},
enumerable: true,
configurable: true,
});
}
current = Object.getPrototypeOf(current);
}
}