CanvasBuilder::render() logic around tool specific tools response is unclear

Created on 31 October 2025, 1 day ago

Overview

Trying to follow the logic of \Drupal\canvas_ai\Controller\CanvasBuilder::render() it is not clear why this particular set of tools is special cased

      $map = [
        EditComponentJs::class => ['js_structure', 'props_metadata'],
        CreateComponent::class => ['component_structure'],
        CreateFieldContent:: class => ['created_content'],
        EditFieldContent:: class => ['refined_text'],
        AddMetadata::class => ['metadata'],
        SetAIGeneratedComponentStructure::class => ['operations'],
      ];
      if (!empty($tools)) {
        foreach ($tools as $tool) {
          foreach ($map as $class => $keys) {

In πŸ“Œ Allow AI to validate changes before publishing Active we already had to put this comment in all of the classes listed above

// \Drupal\xb_ai\Controller\XbBuilder::render() expects a YAML parsable
    // string.
    // @see \Drupal\xb_ai\Controller\XbBuilder::render()

But inside CanvasBuilder::render() it is not clear what these classes are for and what strings that will be set to $keys are.

Looking through the classes it seems the $keys will but sub-set of the tools output if the tool does not have any errors

We should make this clearer by making an interface and not having to hardcode these class names

Proposed resolution

  1. Create an new BuilderResponseFunctionCallInterface with getSuccessResponseData
  2. Have all the classes currently hardcoded implement this interface

The names can be updated. Need feedback by those that know why this particular classes are hardcoded

User interface changes

πŸ“Œ Task
Status

Active

Version

1.0

Component

AI

Created by

πŸ‡ΊπŸ‡ΈUnited States tedbow Ithaca, NY, USA

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024