* A convenience method that builds and executes the tool in one step. * Never throws. * @param params The raw, untrusted parameters from the model. * @params abortSignal a signal to abort. * @returns The result of the tool execution.
(
params: TParams,
abortSignal: AbortSignal,
)
| 228 | * @returns The result of the tool execution. |
| 229 | */ |
| 230 | async validateBuildAndExecute( |
| 231 | params: TParams, |
| 232 | abortSignal: AbortSignal, |
| 233 | ): Promise<ToolResult> { |
| 234 | const invocationOrError = this.silentBuild(params); |
| 235 | if (invocationOrError instanceof Error) { |
| 236 | const errorMessage = invocationOrError.message; |
| 237 | return { |
| 238 | llmContent: `Error: Invalid parameters provided. Reason: ${errorMessage}`, |
| 239 | returnDisplay: errorMessage, |
| 240 | error: { |
| 241 | message: errorMessage, |
| 242 | type: ToolErrorType.INVALID_TOOL_PARAMS, |
| 243 | }, |
| 244 | }; |
| 245 | } |
| 246 | |
| 247 | try { |
| 248 | return await invocationOrError.execute(abortSignal); |
| 249 | } catch (error) { |
| 250 | const errorMessage = |
| 251 | error instanceof Error ? error.message : String(error); |
| 252 | return { |
| 253 | llmContent: `Error: Tool call execution failed. Reason: ${errorMessage}`, |
| 254 | returnDisplay: errorMessage, |
| 255 | error: { |
| 256 | message: errorMessage, |
| 257 | type: ToolErrorType.EXECUTION_FAILED, |
| 258 | }, |
| 259 | }; |
| 260 | } |
| 261 | } |
| 262 | } |
| 263 | |
| 264 | /** |