Refactor the `setupAiProvider` config action to be simpler
>>> [!note] Migrated issue
<!-- Drupal.org comment -->
<!-- Migrated from issue #3562262. -->
Reported by: [phenaproxima](https://www.drupal.org/user/205645)
>>>
<p>[Tracker]<br>
<strong>Update Summary: </strong>[One-line status update for stakeholders]<br>
<strong>Short Description: </strong>[One-line issue summary for stakeholders]<br>
<strong>Check-in Date: </strong>MM/DD/YYYY<br>
<em>Metadata is used by the <a href="https://www.drupalstarforge.ai/" title="AI Tracker">AI Tracker.</a> Docs and additional fields <a href="https://www.drupalstarforge.ai/ai-dashboard/docs" title="AI Issue Tracker Documentation">here</a>.</em><br>
[/Tracker]</p>
<h3 id="summary-problem-motivation">Problem/Motivation</h3>
<p>The <code>setupAiProvider</code> config action is extremely awkward. It was made as a shim, and it's severely limited in its ability to support providers other than OpenAI and Anthropic.</p>
<h3 id="summary-proposed-resolution">Proposed resolution</h3>
<p>Refactor it so that it runs only on the <code>ai.settings</code> config object, and works like this:</p>
<pre> ai.settings:<br> setupAiProvider:<br> key_value: ${api_key} # Use a general `api_key` input that can be used on any provider.<br> key_name: ai # Create a single key<br> key_label: '${provider} API key' # Use the `provider` input to name the key accurately.<br> # env_var: openai_api_key # Entirely deprecated. Drupal 11.3 ssupports inputs from env vars, so this can be moved to the input section.<br> provider: ${provider} # Just directly copy the input.<br> # How we handle this, from a BC standpoint, is that if the inner key has no period, we default to `ai_provider_$FOO.settings`.<br> simpleConfigUpdate:<br> openai: # If the provider is this...<br> ai_provider_openai.settings: # Then these are the configs to change...<br> moderation: true # And these are the values to set</pre><p>So, the entire recipe becomes consolidated (this is not <em>exactly</em> what we would do in Drupal CMS, but it's enough to illustrate the point).</p>
<pre>input:<br> provider:<br> data_type: string<br> description: Which AI provider to use.<br> default:<br> source: value<br> value: openai<br> form:<br> '#type': radios<br> '#title': Provider<br> '#description': Which AI provider to use.<br> '#options':<br> openai: OpenAI<br> anthropic: Anthropic<br> api_key:<br> data_type: string<br> description: The API key for your chosen provider.<br> prompt:<br> method: ask<br> arguments:<br> question: 'Enter your API key:'<br> form:<br> '#type': 'textfield'<br> '#description': 'Enter your API key. A paid plan is required for AI features to function.'<br> '#title': 'API Key'<br> '#required': false<br> '#maxlength': 256<br> '#attributes':<br> autocomplete: off<br> default:<br> source: env<br> env: ai_api_key<br>config:<br> actions:<br> ai.settings:<br> setupAiProvider:<br> key_value: ${api_key}<br> key_name: ai_api_key<br> key_label: 'AI API Key'<br> provider: ${provider}<br> simpleConfigUpdate:<br> openai:<br> ai_provider_openai.settings:<br> moderation: true<br> anthropic:<br> ai_provider_anthropic.settings:<br> openai_moderation: false</pre><p>Much simpler!</p>
<h3 id="summary-remaining-tasks">Remaining tasks</h3>
<p>Implement this and adjust tests.</p>
issue