CanvasBuilder::render() logic around specific tool response is unclear
>>> [!note] Migrated issue <!-- Drupal.org comment --> <!-- Migrated from issue #3555464. --> Reported by: [tedbow](https://www.drupal.org/user/240860) Related to !286 >>> <h3 id="overview">Overview</h3> <p>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</p> <div class="codeblock"> <pre><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $map </span><span style="color: #007700">= [<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #0000BB">EditComponentJs</span><span style="color: #007700">::class =&gt; [</span><span style="color: #DD0000">'js_structure'</span><span style="color: #007700">, </span><span style="color: #DD0000">'props_metadata'</span><span style="color: #007700">],<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #0000BB">CreateComponent</span><span style="color: #007700">::class =&gt; [</span><span style="color: #DD0000">'component_structure'</span><span style="color: #007700">],<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #0000BB">CreateFieldContent</span><span style="color: #007700">:: class =&gt; [</span><span style="color: #DD0000">'created_content'</span><span style="color: #007700">],<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #0000BB">EditFieldContent</span><span style="color: #007700">:: class =&gt; [</span><span style="color: #DD0000">'refined_text'</span><span style="color: #007700">],<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #0000BB">AddMetadata</span><span style="color: #007700">::class =&gt; [</span><span style="color: #DD0000">'metadata'</span><span style="color: #007700">],<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #0000BB">SetAIGeneratedComponentStructure</span><span style="color: #007700">::class =&gt; [</span><span style="color: #DD0000">'operations'</span><span style="color: #007700">],<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (!empty(</span><span style="color: #0000BB">$tools</span><span style="color: #007700">)) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; foreach (</span><span style="color: #0000BB">$tools </span><span style="color: #007700">as </span><span style="color: #0000BB">$tool</span><span style="color: #007700">) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; foreach (</span><span style="color: #0000BB">$map </span><span style="color: #007700">as </span><span style="color: #0000BB">$class </span><span style="color: #007700">=&gt; </span><span style="color: #0000BB">$keys</span><span style="color: #007700">) {<br></span><span style="color: #0000BB">?&gt;</span></span></pre></div> <p>In <span class="drupalorg-gitlab-issue-link project-issue-status-info project-issue-status-7"><a href="https://www.drupal.org/project/experience_builder/issues/3537422" title="Status: Closed (fixed)">#3537422: XB AI: Validate AI generated Components before adding to XB</a></span> we already had to put this comment in all of the classes listed above</p> <div class="codeblock"> <pre><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br></span><span style="color: #FF8000">// \Drupal\xb_ai\Controller\XbBuilder::render() expects a YAML parsable<br>&nbsp;&nbsp;&nbsp; // string.<br>&nbsp;&nbsp;&nbsp; // @see \Drupal\xb_ai\Controller\XbBuilder::render()<br></span><span style="color: #0000BB">?&gt;</span></span></pre></div> <p>But inside <code>CanvasBuilder::render() </code> it is not clear what these classes are for and what strings that will be set to <code>$keys</code> are.</p> <p>Looking through the classes it seems the $keys will but sub-set of the tools output if the tool does not have any errors</p> <p>We should make this clearer by making an interface and not having to hardcode these class names</p> <h3 id="proposed-resolution">Proposed resolution</h3> <ol> <li>Create an new <code>BuilderResponseFunctionCallInterface</code> with getSuccessResponseData</li> <li>Have all the classes currently hardcoded implement this interface</li> </ol> <p>The names can be updated. Need feedback by those that know why this particular classes are hardcoded</p> <h3 id="ui-changes">User interface changes</h3> > Related issue: [Issue #3537422](https://www.drupal.org/node/3537422)
issue