Prompts: what AIPCF asks the AI on its own behalf. Saved to its own option. */ final class PromptsScreen { /** Prompts most people never change: under More settings. */ private const RARE = ['system_suffix', 'vision_system']; public static function render(): string { $rows = ''; $rare = ''; foreach (Prompts::definitions() as $key => $def) { $row = self::row((string) $key, $def); if (in_array($key, self::RARE, true)) { $rare .= $row; } else { $rows .= $row; } } $body = $rows . Ui::moreSettings($rare); return Ui::card(__('Prompts', 'aipcf-ai-provider-for-cloudflare'), $body, [ 'text' => __('What AIPCF asks the AI on its own behalf. Edit freely; Reset brings back the default.', 'aipcf-ai-provider-for-cloudflare'), ]) . Ui::more(__('Placeholders, and the AI plugin\'s own prompts', 'aipcf-ai-provider-for-cloudflare'), '

' . esc_html__('Words in braces are filled in when the prompt is sent. Developers can change any prompt with the aipcf_prompt filter. The AI plugin\'s editor features use their own prompts, not these.', 'aipcf-ai-provider-for-cloudflare') . '

'); } /** * @param array{label: string, description: string, placeholders: list, model: string, default: string} $def */ private static function row(string $key, array $def): string { $value = Prompts::raw($key); $id = 'aipcf-prompt-' . str_replace('_', '-', $key); $control = Ui::textarea(Prompts::OPTION . '[' . $key . ']', $value, $id, (int) min(10, substr_count($value, "\n") + 3), true); $actions = []; if (Prompts::isCustom($key)) { $control .= Ui::pill(__('Changed', 'aipcf-ai-provider-for-cloudflare'), 'warn'); $actions[] = [ 'label' => __('Reset to default', 'aipcf-ai-provider-for-cloudflare'), 'url' => wp_nonce_url(admin_url('admin-post.php?action=aipcf_prompt_test&reset=1&key=' . rawurlencode($key)), 'aipcf_prompt_test'), 'kind' => 'link', 'confirm' => __('Reset this prompt? Your changes to it are lost.', 'aipcf-ai-provider-for-cloudflare'), ]; } if (in_array($key, ['meta_description', 'alt_text'], true)) { $actions[] = [ 'label' => __('Try it on the latest item', 'aipcf-ai-provider-for-cloudflare'), 'url' => wp_nonce_url(admin_url('admin-post.php?action=aipcf_prompt_test&key=' . rawurlencode($key)), 'aipcf_prompt_test'), 'kind' => 'link', 'busy' => __('Trying...', 'aipcf-ai-provider-for-cloudflare'), ]; } if ($actions !== []) { $control .= Ui::actions($actions); } $help = $def['placeholders'] !== [] /* translators: %s: placeholders such as {site_name} */ ? sprintf(__('Placeholders: %s', 'aipcf-ai-provider-for-cloudflare'), implode(' ', $def['placeholders'])) : ''; return Ui::row($def['label'], $control, [ 'for' => $id, 'help' => $help, 'more' => '

' . esc_html($def['description'] . ' ' . $def['model']) . '

', ]); } }