| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) { |
| 3 |
exit; // Exit if accessed directly! |
| 4 |
} |
| 5 |
|
| 6 |
if ( ! class_exists( 'WPSC_ACB_Tool_Executor' ) ) : |
| 7 |
|
| 8 |
final class WPSC_ACB_Tool_Executor { |
| 9 |
|
| 10 |
/** |
| 11 |
* Execute a tool call. |
| 12 |
* |
| 13 |
* @param array $tool_call Tool call payload. |
| 14 |
* @param string $session_uuid Session ID or internal session ID. |
| 15 |
* @return array |
| 16 |
*/ |
| 17 |
public static function execute_tool_call( $tool_call, $session_uuid ) { |
| 18 |
|
| 19 |
$tool_name = sanitize_key( (string) ( $tool_call['name'] ?? '' ) ); |
| 20 |
$args = is_array( $tool_call['arguments'] ?? null ) ? $tool_call['arguments'] : array(); |
| 21 |
$handler = WPSC_ACB_Tool_Registry::get_tool_handler( $tool_name ); |
| 22 |
$class = WPSC_ACB_Tool_Registry::get_tool_handler_class( $tool_name ); |
| 23 |
|
| 24 |
if ( '' === $handler || ! is_callable( array( $class, $handler ) ) ) { |
| 25 |
return array( |
| 26 |
'success' => true, |
| 27 |
'response' => '<p>' . esc_html__( 'I can continue helping in chat. Please tell me what you need.', 'wpsc-ps' ) . '</p>', |
| 28 |
); |
| 29 |
} |
| 30 |
|
| 31 |
return call_user_func( array( $class, $handler ), $args, $session_uuid ); |
| 32 |
} |
| 33 |
} |
| 34 |
endif; |
| 35 |
|