@@ -124,18 +124,25 @@ function wrapPluginToolCallbacks(entry: PluginToolRegistration, tool: AnyAgentTo
|
124 | 124 | } |
125 | 125 | |
126 | 126 | const prepareArguments = tool.prepareArguments; |
127 | | -const wrapped: AnyAgentTool = { |
128 | | - ...tool, |
129 | | - ...(prepareArguments |
130 | | - ? { |
131 | | -prepareArguments(args) { |
132 | | -return runWithPluginToolScope(entry, () => |
133 | | -Reflect.apply(prepareArguments, tool, [args]), |
134 | | -); |
135 | | -}, |
136 | | -} |
137 | | - : {}), |
138 | | -execute(toolCallId, params, signal, onUpdate) { |
| 127 | +const descriptors = Object.getOwnPropertyDescriptors(tool); |
| 128 | +delete descriptors.execute; |
| 129 | +delete descriptors.prepareArguments; |
| 130 | +const wrapped = Object.create(Object.getPrototypeOf(tool)) as AnyAgentTool; |
| 131 | +Object.defineProperties(wrapped, descriptors); |
| 132 | +if (prepareArguments) { |
| 133 | +Object.defineProperty(wrapped, "prepareArguments", { |
| 134 | +configurable: true, |
| 135 | +enumerable: Object.prototype.propertyIsEnumerable.call(tool, "prepareArguments"), |
| 136 | +value(args: unknown) { |
| 137 | +return runWithPluginToolScope(entry, () => Reflect.apply(prepareArguments, tool, [args])); |
| 138 | +}, |
| 139 | +writable: true, |
| 140 | +}); |
| 141 | +} |
| 142 | +Object.defineProperty(wrapped, "execute", { |
| 143 | +configurable: true, |
| 144 | +enumerable: Object.prototype.propertyIsEnumerable.call(tool, "execute"), |
| 145 | +value(toolCallId: string, params: unknown, signal?: AbortSignal, onUpdate?: unknown) { |
139 | 146 | return runWithPluginToolScope( |
140 | 147 | entry, |
141 | 148 | () => |
@@ -144,7 +151,8 @@ function wrapPluginToolCallbacks(entry: PluginToolRegistration, tool: AnyAgentTo
|
144 | 151 | >, |
145 | 152 | ); |
146 | 153 | }, |
147 | | -}; |
| 154 | +writable: true, |
| 155 | +}); |
148 | 156 | |
149 | 157 | copyPluginToolMeta(tool, wrapped); |
150 | 158 | const nextScopedByKey = scopedByKey ?? new Map<string, AnyAgentTool>(); |
|