__( 'Prepare a category/tag/brand change', 'addsynapse-store-assistant' ), 'description' => 'Plans adding, removing or replacing terms of one product taxonomy (categories, tags, brand taxonomy, global attribute) on the selected products and stores it as a DRAFT change set for the manager to approve. Changes nothing in the store.', 'category' => AbilitiesRegistrar::CATEGORY, 'input_schema' => self::input_schema(), 'execute_callback' => array( $this, 'execute' ), 'permission_callback' => array( AbilitiesRegistrar::class, 'can_manage' ), 'meta' => Shared::plan_meta(), ) ); } /** * Input schema (also the tool definition the AI provider receives). * * @return array */ public static function input_schema(): array { return array( 'type' => 'object', 'additionalProperties' => false, 'required' => array( 'taxonomy', 'mode' ), 'properties' => ProductSelector::schema_properties() + self::term_properties() + array( 'taxonomy' => array( 'type' => 'string', 'minLength' => 1, 'maxLength' => 100, ), 'mode' => array( 'type' => 'string', 'enum' => TermsPlanner::MODES, ), ), ); } /** * Term properties term_ids / term_names. * * @return array> */ public static function term_properties(): array { return array( 'term_ids' => array( 'type' => 'array', 'maxItems' => TermsPlanner::MAX_TERMS, 'items' => array( 'type' => 'integer', 'minimum' => 1, ), ), 'term_names' => array( 'type' => 'array', 'maxItems' => TermsPlanner::MAX_TERMS, 'items' => array( 'type' => 'string', 'minLength' => 1, 'maxLength' => 100, ), ), ); } /** * Execute callback. * * @param array $input Input. * @return array|\WP_Error */ public function execute( $input = null ) { $input = is_array( $input ) ? $input : array(); $context = array(); if ( Locales::is( 'brand', (string) ( $input['taxonomy'] ?? '' ) ) ) { // "brand" = wherever this store keeps brands, through its adapter (no guessing). $resolved = BrandResolver::resolve(); if ( is_wp_error( $resolved ) ) { return $resolved; } $context = array( 'taxonomy' => $resolved['adapter']->taxonomy(), 'warnings' => $resolved['warnings'], ); } return ( new TermsPlanner() )->plan( $input, get_current_user_id(), ToolRegistry::current_conversation_id(), $context ); } }