| @@ -169,8 +169,9 @@ | ||
| 169 | 169 | |
| 170 | 170 | if ( function_exists( 'wp_get_ability' ) ) { |
| 171 | 171 | $ability = wp_get_ability( $tool_name ); |
| 172 | 172 | if ( ! $ability || ! str_starts_with( $tool_name, 'wpfunnels/' ) ) { |
| 173 | + do_action( 'wpfnl_ai_tool_failed', $tool_name, 'unknown_tool' ); | |
| 173 | 174 | return [ |
| 174 | 175 | 'content' => sprintf( 'Unknown tool "%s".', $tool_name ), |
| 175 | 176 | 'is_error' => true, |
| 176 | 177 | ]; |
| @@ -200,8 +201,19 @@ | ||
| 200 | 201 | } |
| 201 | 202 | } |
| 202 | 203 | |
| 203 | 204 | if ( is_wp_error( $result ) ) { |
| 205 | + /** | |
| 206 | + * Fires when a copilot tool call fails (the counterpart of | |
| 207 | + * `wpfnl_ai_tool_executed`). | |
| 208 | + * | |
| 209 | + * @since 3.14.0 | |
| 210 | + * | |
| 211 | + * @param string $tool_name Ability name. | |
| 212 | + * @param string $error_code WP_Error code. | |
| 213 | + */ | |
| 214 | + do_action( 'wpfnl_ai_tool_failed', $tool_name, $result->get_error_code() ); | |
| 215 | + | |
| 204 | 216 | return [ |
| 205 | 217 | 'content' => wp_json_encode( |
| 206 | 218 | [ |
| 207 | 219 | 'error' => $result->get_error_code(), |