PluginProbe
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot / 3.8.9
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot v3.8.9
4.9.2 4.9.1 4.9.0 4.8.2 4.8.1 4.8.0 4.7.0 4.6.2 4.6.1 4.6.0 4.5.6 4.5.5 4.5.4 4.5.3 4.5.2 4.5.1 4.5.0 4.4.1 4.4.0 3.3.4 3.4.0 3.4.1 3.4.2 3.5.0 3.5.1 All 200 releases
← All changes | includes/Core/WriteWithAI.php +1020 -582 4.8.13.8.9 View file →
@@ -1,680 +1,1118 @@
1 1 <?php
2 2
3 - namespace WPDeveloper\BetterDocs\Core;
3 +namespace WPDeveloper\BetterDocs\Core;
4 4
5 -if ( ! defined( 'ABSPATH' ) ) {
6 - exit;
7 -}
5 +use WPDeveloper\BetterDocs\Utils\Base;
6 +use WPDeveloper\BetterDocs\Core\Settings;
7 +use WPDeveloper\BetterDocs\Core\PostType;
8 8
9 +use WPDeveloper\BetterDocs\Utils\Helper;
9 10
10 - use WPDeveloper\BetterDocs\Utils\Base;
11 - use WPDeveloper\BetterDocs\Core\Settings;
12 - use WPDeveloper\BetterDocs\Core\PostType;
11 +class WriteWithAI extends Base {
13 12
14 - use WPDeveloper\BetterDocs\Utils\Helper;
15 - use WPDeveloper\BetterDocs\Utils\AIHelper;
16 - use WPDeveloper\BetterDocs\AI\ProviderFactory;
17 - use WPDeveloper\BetterDocs\AI\ModelRegistry;
18 - use WPDeveloper\BetterDocs\Utils\AIUsage;
19 - use WPDeveloper\BetterDocs\REST\AIEdit;
13 + public $settings;
20 14
21 - class WriteWithAI extends Base {
15 + public function __construct( Settings $settings ) {
16 + $this->settings = $settings;
17 + // Get the post ID from the URL
18 + $post_id = isset($_GET['post']) ? intval($_GET['post']) : 0; // phpcs:ignore
22 19
23 - public $settings;
20 + if (!empty($_GET['post_type'])) { // phpcs:ignore
21 + $post_type = $_GET['post_type']; // phpcs:ignore
22 + } elseif ( $post_id > 0 ) {
23 + $post_type = get_post_type( $post_id );
24 + } else {
25 + $post_type = '';
26 + }
24 27
25 - public function __construct( Settings $settings ) {
26 - $this->settings = $settings;
27 - // Get the post ID from the URL
28 - $post_id = isset( $_GET[ 'post' ] ) ? intval( $_GET[ 'post' ] ) : 0; // phpcs:ignore
28 + if ( ! empty( $this->isEnabledWriteWithAI() ) && $post_type == 'docs' ) {
29 + add_action( 'admin_footer', [ $this, 'ai_autowrite_button' ] );
30 + }
31 + add_action( 'wp_ajax_generate_openai_content', [ $this, 'generate_openai_content_callback' ] );
32 + }
29 33
30 - if ( ! empty( $_GET[ 'post_type' ] ) ) { // phpcs:ignore
31 - $post_type = $_GET[ 'post_type' ]; // phpcs:ignore
32 - } elseif ( $post_id > 0 ) {
33 - $post_type = get_post_type( $post_id );
34 - } else {
35 - $post_type = '';
36 - }
34 + public function isEnabledWriteWithAI() {
35 + $isEnableAutoWrite = $this->settings->get( 'enable_write_with_ai', true );
36 + return $isEnableAutoWrite;
37 + }
37 38
38 - if ( ! empty( $this->isEnabledWriteWithAI() ) && 'docs' == $post_type ) {
39 - add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_ai_edit_assets' ) );
40 - }
41 - // Legacy AJAX handler kept for back-compat; the redesigned modal uses the REST route.
42 - add_action( 'wp_ajax_generate_openai_content', array( $this, 'generate_openai_content_callback' ) );
43 - }
39 + public function isValidAPIKey( $apiKey ) {
40 + if ( empty( $apiKey ) ) {
41 + $api_response['valid'] = false;
42 + $api_response['message'] = 'Please Insert your <a href="/admin.php?page=betterdocs-settings">OpenAI API Key</a> to use this Write with AI feature.';
44 43
45 - public function enqueue_ai_edit_assets( $hook ) {
46 - if ( 'post.php' !== $hook && 'post-new.php' !== $hook ) {
47 - return;
48 - }
44 + return $api_response;
45 + }
49 46
50 - global $post_type;
51 - if ( 'docs' !== $post_type ) {
52 - return;
53 - }
47 + $ch = curl_init( 'https://api.openai.com/v1/engines' ); //phpcs:ignore WordPress.WP.AlternativeFunctions.curl_curl_init
48 + curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ); //phpcs:ignore WordPress.WP.AlternativeFunctions.curl_curl_setopt
49 + curl_setopt(
50 + $ch,
51 + CURLOPT_HTTPHEADER,
52 + [ //phpcs:ignore WordPress.WP.AlternativeFunctions.curl_curl_setopt
53 + 'Content-Type: application/json',
54 + 'Authorization: Bearer ' . $apiKey,
55 + ]
56 + );
54 57
55 - $factory = new ProviderFactory( $this->settings );
56 - $api_key = $factory->api_key_for( $factory->active_platform() );
57 - $has_key = ! empty( $api_key );
58 + $api_response = [];
58 59
59 - // Resolve the *active* AI platform + model (multi-platform aware) so the
60 - // modal reflects the current Settings → AI selection instead of the legacy
61 - // OpenAI-only `write_with_ai_model` key.
62 - $active_platform = $factory->active_platform();
63 - $active_model = $factory->active_model();
64 - $platform_labels = ModelRegistry::platforms();
65 - $model_labels = ModelRegistry::models( $active_platform );
60 + $response = curl_exec( $ch ); //phpcs:ignore WordPress.WP.AlternativeFunctions.curl_curl_exec
61 + $httpCode = curl_getinfo( $ch, CURLINFO_HTTP_CODE ); //phpcs:ignore WordPress.WP.AlternativeFunctions.curl_curl_getinfo
66 62
67 - // Glossary suggestions are existing-terms-only, and the glossaries taxonomy is only
68 - // registered for Pro (see Core\PostType::register_glossaries_taxonomy). So the "Suggest
69 - // glossaries" control must require, on top of the two settings, that Pro is active AND at
70 - // least one glossary term exists — otherwise the modal advertises an offer that can never
71 - // return anything. Mirrors the Docs-AI-suite availability check in Core\DocsAISuite.
72 - $glossary_count = wp_count_terms( array( 'taxonomy' => 'glossaries', 'hide_empty' => false ) );
73 - $has_glossary_terms = ! is_wp_error( $glossary_count ) && (int) $glossary_count > 0;
74 - $glossary_suggestions_enabled = (bool) $this->settings->get( 'enable_glossaries', false )
75 - && (bool) $this->settings->get( 'show_glossary_suggestions', true )
76 - && betterdocs()->is_pro_active()
77 - && $has_glossary_terms;
63 + curl_close( $ch ); //phpcs:ignore WordPress.WP.AlternativeFunctions.curl_curl_close
78 64
79 - // Write with AI — loads even without a key so the modal can show its
80 - // "add an API key" banner (matches the legacy inline form behavior).
81 - betterdocs()->assets->enqueue( 'betterdocs-write-with-ai', 'blocks/write-with-ai.js' );
82 - betterdocs()->assets->enqueue( 'betterdocs-write-with-ai-style', 'blocks/write-with-ai-style.css' );
65 + if ( $httpCode == 200 ) {
66 + $api_response['valid'] = true;
67 + $api_response['message'] = 'Valid API Key';
68 + } else {
69 + $responseData = json_decode( $response, true );
70 + // Access the message data (replace 'data' with the actual key used in the response)
71 + $messageData = $responseData['error'] ? $responseData['error'] : '';
72 + $api_response['valid'] = false;
73 + $api_response['message'] = $messageData['message'] ? $messageData['message'] : 'Invalid API Key';
74 + }
83 75
84 - wp_localize_script(
85 - 'betterdocs-write-with-ai',
86 - 'betterdocsWriteWithAI',
87 - array(
88 - 'rest_url' => esc_url_raw( rest_url( 'betterdocs/v1/write-with-ai' ) ),
89 - 'rest_nonce' => wp_create_nonce( 'wp_rest' ),
90 - 'post_id' => get_the_ID(),
91 - 'has_key' => $has_key,
92 - // Term-suggestion (Docs AI Suite) wiring reused by the Write-with-AI
93 - // preview step. Endpoint + gate mirror REST\DocsAISuite / Core\DocsAISuite.
94 - 'rest_suggest_url' => esc_url_raw( rest_url( 'betterdocs/v1/ai-suggest-terms' ) ),
95 - 'suggest_terms_enabled' => (bool) $this->settings->get( 'enable_docs_ai_suite', true ),
96 - // Glossary suggestions follow the glossary feature AND real availability
97 - // (Pro active + at least one glossary term); see the computation above.
98 - 'glossary_suggestions_enabled' => $glossary_suggestions_enabled,
99 - 'platform' => $active_platform,
100 - 'platform_label' => isset( $platform_labels[ $active_platform ] ) ? $platform_labels[ $active_platform ] : ucfirst( (string) $active_platform ),
101 - 'model' => $active_model,
102 - 'model_label' => isset( $model_labels[ $active_model ] ) ? $model_labels[ $active_model ] : $active_model,
103 - 'max_token' => (int) $this->settings->get( 'ai_autowrite_max_token', 2500 ),
104 - 'settings_url' => esc_url( admin_url( 'admin.php?page=betterdocs-settings#betterdocs-ai' ) ),
105 - 'woo_active' => class_exists( 'WooCommerce' ),
106 - 'is_multilingual_active' => Helper::is_multilingual_active(),
107 - 'language_options' => Helper::get_active_languages(),
108 - 'instructions' => $this->get_instruction_choices(),
109 - // From Git is a Pro feature. Pro is detected here; Git enabled/auth
110 - // status is filled in by Pro via the filter below (default: off).
111 - 'is_pro_active' => betterdocs()->is_pro_active(),
112 - 'git' => apply_filters(
113 - 'betterdocs_write_with_ai_git',
114 - array(
115 - 'enabled' => false,
116 - 'connected' => false,
117 - 'settings_url' => admin_url( 'admin.php?page=betterdocs-settings#git-sync' ),
118 - )
119 - ),
120 - )
121 - );
76 + // print_r($response);
122 77
123 - // AI Edit — only meaningful with a key configured.
124 - if ( ! $has_key ) {
125 - return;
126 - }
78 + return $api_response;
79 + }
127 80
128 - betterdocs()->assets->enqueue( 'betterdocs-ai-edit', 'blocks/ai-edit.js' );
129 - betterdocs()->assets->enqueue( 'betterdocs-ai-edit-style', 'blocks/ai-edit-style.css' );
81 + public function get_api_key() {
82 + $api_key = $this->settings->get( 'ai_autowrite_api_key', '' );
83 + return $api_key;
84 + }
130 85
131 - wp_localize_script(
132 - 'betterdocs-ai-edit',
133 - 'betterdocsAIEdit',
134 - array(
135 - 'rest_url' => esc_url_raw( rest_url( 'betterdocs/v1/ai-edit' ) ),
136 - 'rest_nonce' => wp_create_nonce( 'wp_rest' ),
137 - 'post_id' => get_the_ID(),
138 - 'instructions' => $this->get_instruction_choices(),
139 - 'actions' => AIEdit::get_localized_actions()
140 - )
141 - );
142 - }
143 86
144 - public function isEnabledWriteWithAI() {
145 - $isEnableAutoWrite = $this->settings->get( 'enable_write_with_ai', true );
146 - return $isEnableAutoWrite;
147 - }
87 + public function generate_openai_response( $prompt, $keywords ) {
88 + try {
89 + $api_key = $this->settings->get( 'ai_autowrite_api_key', '' );
90 + $max_tokens = $this->settings->get( 'ai_autowrite_max_token', 1500 );
148 91
149 - public function isValidAPIKey( $apiKey ) {
150 - if ( empty( $apiKey ) ) {
151 - return array(
152 - 'valid' => false,
153 - 'message' => 'Please Insert your <a href="/admin.php?page=betterdocs-settings#betterdocs-ai">API Key</a> to use this Write with AI feature.'
154 - );
155 - }
92 + $api_endpoint = 'https://api.openai.com/v1/chat/completions'; // Update the endpoint based on OpenAI API version
156 93
157 - $factory = new ProviderFactory( $this->settings );
158 - return $factory->validate( $factory->active_platform(), $apiKey );
159 - }
94 + $request_options = array(
95 + 'headers' => array(
96 + 'Content-Type' => 'application/json',
97 + 'Authorization' => 'Bearer ' . $api_key,
98 + ),
99 + 'body' => json_encode(
100 + array( //phpcs:ignore WordPress.WP.AlternativeFunctions.json_encode_json_encode
101 + 'model' => 'gpt-4o-mini', // Add the model parameter here
102 + 'messages' => array(
103 + array(
104 + 'role' => 'system',
105 + 'content' => 'You are a helpful assistant who writes documentation for users.'
106 + ),
107 + array(
108 + 'role' => 'user',
109 + 'content' => $prompt
110 + ),
111 + ),
112 + 'max_tokens' => $max_tokens,
160 113
161 - public function get_api_key() {
162 - $factory = new ProviderFactory( $this->settings );
163 - return $factory->api_key_for( $factory->active_platform() );
164 - }
114 + )
115 + ),
116 + 'timeout' => 50,
117 + );
165 118
166 - /**
167 - * The built-in "Default" instruction body.
168 - *
169 - * Single source of truth shared by {@see Settings::get_default()} (which seeds
170 - * the editable "Default" instruction set) and {@see self::get_system_prompt()}
171 - * (the fallback when no saved Default content exists).
172 - *
173 - * @return string
174 - */
175 - public static function default_instruction_content() {
176 - return <<<'PROMPT'
177 -You are a Senior Technical Writer specializing in comprehensive, high-quality documentation. Your goal is to produce documentation that scores 100/100 on clarity, completeness, and structure.
119 + $response = wp_remote_post( $api_endpoint, $request_options );
178 120
179 -## Output format
121 + if ( is_wp_error( $response ) ) {
122 + return 'Error: ' . $response->get_error_message();
123 + } else {
124 + $body = wp_remote_retrieve_body( $response );
180 125
181 -Return only HTML body content. Never wrap output in `<!doctype>`, `<html>`, `<head>`, `<body>`, or markdown code fences (no ```html ... ```).
126 + $data = json_decode( $body, true );
182 127
183 -Use semantic, Gutenberg-friendly tags only:
184 -- Headings: `<h2>`, `<h3>`, `<h4>` (do not emit `<h1>` — it is reserved for the document title)
185 -- Paragraphs: `<p>` for prose
186 -- Lists: `<ul>`/`<ol>` with `<li>` for any list of items, steps, or bullet points — never fake a list with paragraphs or `<br>`
187 -- Links: `<a href="https://...">link text</a>` with absolute URLs
188 -- Inline emphasis: `<strong>`, `<em>`, `<code>`
189 -- Code blocks: `<pre><code>...</code></pre>` for multi-line code or commands
190 -- Quotes: `<blockquote>`
191 -- Tables: `<table>` with `<thead>`, `<tbody>`, `<tr>`, `<th>`, `<td>`
192 -- Images: `<img src="..." alt="...">`
128 + if ( ! empty( $data['error'] ) ) {
129 + return $data['error']['message'];
130 + }
193 131
194 -Apply `<span class="highlight">key term</span>` to important topic terms inside headings and to the first occurrence of each keyword in body text. Use it sparingly — never wrap whole sentences or wrap text inside `href`, `src`, `alt`, or other attributes.
132 + return $data['choices'][0]['message']['content']; // Update this line to get the assistant's message
133 + }
134 + } catch ( Exception $error ) {
135 + return 'Error: ' . $error->getMessage();
136 + }
137 + }
195 138
196 -Do not emit `<style>`, `<script>`, `<iframe>`, `<form>`, or inline `style=""` / `class=""` attributes (other than the `highlight` class above).
197 139
198 -If — and only if — the user's prompt explicitly asks for raw/custom HTML, embed code, or a non-standard structure, follow that request instead of these defaults.
199 -PROMPT;
200 - }
201 140
202 - /**
203 - * The saved instruction sets, normalized to a list of { id, title, content }.
204 - *
205 - * Stored in the `write_with_ai_instructions` setting. Always returns at least
206 - * the built-in "Default" set so callers never have to special-case an empty
207 - * option (e.g. a site whose stored value predates this feature).
208 - *
209 - * @return array<int,array{id:string,title:string,content:string}>
210 - */
211 - public function get_instructions() {
212 - $stored = $this->settings->get( 'write_with_ai_instructions', array() );
141 + public function generate_openai_content_callback() {
142 + // Verify the nonce
143 + if (!isset($_POST['ai_nonce']) || !wp_verify_nonce($_POST['ai_nonce'], 'generate_openai_content_nonce')) { //phpcs:ignore
144 + wp_send_json_error( 'Invalid nonce' );
145 + wp_die();
146 + }
213 147
214 - $instructions = array();
215 - if ( is_array( $stored ) ) {
216 - foreach ( $stored as $item ) {
217 - if ( ! is_array( $item ) || empty( $item['id'] ) ) {
218 - continue;
219 - }
220 - $instructions[] = array(
221 - 'id' => sanitize_key( (string) $item['id'] ),
222 - 'title' => isset( $item['title'] ) ? (string) $item['title'] : '',
223 - 'content' => isset( $item['content'] ) ? (string) $item['content'] : '',
224 - );
225 - }
226 - }
148 + $prompt = sanitize_text_field($_POST['prompt']); //phpcs:ignore
149 + // $num_of_sections = sanitize_text_field($_POST['numOfSections']);
150 + // $num_of_paragraphs = sanitize_text_field($_POST['numOfParagraphs']);
151 + $keywords = sanitize_text_field($_POST['keywords']); //phpcs:ignore
227 152
228 - // Guarantee a Default set is always present.
229 - $has_default = false;
230 - foreach ( $instructions as $item ) {
231 - if ( 'default' === $item['id'] ) {
232 - $has_default = true;
233 - break;
234 - }
235 - }
236 - if ( ! $has_default ) {
237 - array_unshift(
238 - $instructions,
239 - array(
240 - 'id' => 'default',
241 - 'title' => __( 'Default/Core', 'betterdocs' ),
242 - 'content' => self::default_instruction_content(),
243 - )
244 - );
245 - }
153 + $ai_instance = new WriteWithAI( $this->settings );
246 154
247 - return $instructions;
248 - }
155 + $generated_content = $ai_instance->generate_openai_response( $prompt, $keywords );
249 156
250 - /**
251 - * The selectable (non-default) instruction sets exposed to the editor UI.
252 - *
253 - * Only id + title are sent to the browser; the prompt body stays server-side
254 - * and is resolved at request time by {@see self::get_instruction_messages()}.
255 - *
256 - * @return array<int,array{id:string,title:string}>
257 - */
258 - public function get_instruction_choices() {
259 - $choices = array();
260 - foreach ( $this->get_instructions() as $item ) {
261 - if ( 'default' === $item['id'] ) {
262 - continue;
263 - }
264 - if ( '' === trim( $item['content'] ) ) {
265 - continue; // skip empty sets — they'd inject nothing.
266 - }
267 - $choices[] = array(
268 - 'id' => $item['id'],
269 - 'title' => '' !== trim( $item['title'] ) ? $item['title'] : $item['id'],
270 - );
271 - }
272 - return $choices;
273 - }
157 + // Send the generated content as the AJAX response
158 + wp_send_json_success( $generated_content );
159 + wp_die();
160 + }
274 161
275 - /**
276 - * Resolve selected instruction ids into extra `system` messages.
277 - *
278 - * The "Default" set is intentionally excluded — it is always sent as the base
279 - * system prompt by {@see self::get_system_prompt()}. Unknown or empty ids are
280 - * silently ignored. Output order follows the requested $ids order.
281 - *
282 - * @param array $ids
283 - * @return array<int,array{role:string,content:string}>
284 - */
285 - public function get_instruction_messages( $ids ) {
286 - if ( empty( $ids ) || ! is_array( $ids ) ) {
287 - return array();
288 - }
162 + public function ai_autowrite_button() {
289 163
290 - $by_id = array();
291 - foreach ( $this->get_instructions() as $item ) {
292 - $by_id[ $item['id'] ] = $item;
293 - }
164 + ?>
165 + <script>
166 + var docsTitle;
294 167
295 - $messages = array();
296 - $seen = array();
297 - foreach ( $ids as $id ) {
298 - $id = sanitize_key( (string) $id );
299 - if ( 'default' === $id || isset( $seen[ $id ] ) || ! isset( $by_id[ $id ] ) ) {
300 - continue;
301 - }
302 - $content = trim( $by_id[ $id ]['content'] );
303 - if ( '' === $content ) {
304 - continue;
305 - }
306 - $seen[ $id ] = true;
307 - $messages[] = array(
308 - 'role' => 'system',
309 - 'content' => $content,
310 - );
311 - }
168 + function responseMessage(message) {
169 + return `<div class="warning-message">
170 + <span class="dashicons dashicons-warning"></span>
171 + <div class="footer-message">
172 + ${message}
173 + </div>
174 + </div>`;
175 + }
312 176
313 - return $messages;
314 - }
177 + function generateArticle(e) {
315 178
316 - /**
317 - * Coerce a list of extra messages into well-formed `system` chat messages.
318 - *
319 - * Accepts either pre-built [ 'role'=>'system', 'content'=>… ] entries (as
320 - * returned by {@see self::get_instruction_messages()}) or bare strings, and
321 - * drops anything empty. Keeps the OpenAI payload builders tolerant of either
322 - * shape so callers can pass instruction ids or ready-made messages.
323 - *
324 - * @param array $extra_system
325 - * @return array<int,array{role:string,content:string}>
326 - */
327 - protected function normalize_extra_system( $extra_system ) {
328 - if ( empty( $extra_system ) || ! is_array( $extra_system ) ) {
329 - return array();
330 - }
331 179
332 - $messages = array();
333 - foreach ( $extra_system as $entry ) {
334 - if ( is_string( $entry ) ) {
335 - $content = trim( $entry );
336 - $role = 'system';
337 - } elseif ( is_array( $entry ) && isset( $entry['content'] ) ) {
338 - $content = trim( (string) $entry['content'] );
339 - $role = isset( $entry['role'] ) ? (string) $entry['role'] : 'system';
340 - } else {
341 - continue;
342 - }
180 + const title = document.getElementById('betterdocs-ai-title').value;
181 + const keywords = document.getElementById('betterdocs-ai-keyword').value;
182 + // const sectionOptions = document.getElementById('bd-autowrtite-content-section');
183 + // const numOfSections = sectionOptions.options[sectionOptions.selectedIndex].value;
343 184
344 - if ( '' === $content ) {
345 - continue;
346 - }
185 + // const paragraphOptions = document.getElementById('bd-autowrtite-content-paragraph');
186 + // const numOfParagraphs = paragraphOptions.options[paragraphOptions.selectedIndex].value;
347 187
348 - $messages[] = array(
349 - 'role' => $role,
350 - 'content' => $content,
351 - );
352 - }
188 + const contentTextArea = document.getElementById('betterdocs-ai-content');
189 + const docGenerateBtnTxt = document.querySelector('.generate-btn span');
353 190
354 - return $messages;
355 - }
191 + // Add nonce value to the data being sent
192 + const nonce = document.querySelector('input[name="ai_nonce"]').value;
193 + const isOverwrite = document.getElementById('betterdocs-ai-checkbox').checked;
194 + const generateDocLabel = "<?php echo esc_html__( 'Generate Doc', 'betterdocs' ); ?>";
195 + const reGenerateDocLabel = "<?php echo esc_html__( 'Regenerate Doc', 'betterdocs' ); ?>";
356 196
357 - public function get_system_prompt() {
358 - // Prefer the saved (editable) "Default" instruction set; fall back to the
359 - // built-in body when it's missing or has been cleared.
360 - $prompt = self::default_instruction_content();
361 - foreach ( $this->get_instructions() as $item ) {
362 - if ( 'default' === $item['id'] && '' !== trim( $item['content'] ) ) {
363 - $prompt = $item['content'];
364 - break;
365 - }
366 - }
367 197
368 - return apply_filters( 'betterdocs_write_with_ai_system_prompt', $prompt );
369 - }
198 + // contentTextArea.value = `Write an article about ${title} in English. The article is organized by the following exact ${numOfSections} headings. Write exact ${numOfParagraphs} number of paragraphs per heading.${keywords} Use Markdown for formatting. Add an introduction and a conclusion. Style: creative. Tone: cheerful.`;
370 199
371 - /**
372 - * Build the system + user messages and chat options shared by the
373 - * Write-with-AI generator and the in-editor AI-Edit endpoint. Routes through
374 - * the active AI platform (ProviderFactory), so it works for every provider.
375 - *
376 - * @param string $prompt
377 - * @param int|null $max_tokens Optional cap override (e.g. a "large" doc).
378 - * @param array $extra_system Optional extra system messages.
379 - * @return array array( array $messages, array $options )
380 - */
381 - private function ai_request_args( $prompt, $max_tokens = null, $extra_system = array() ) {
382 - $messages = array_merge(
383 - array( array( 'role' => 'system', 'content' => $this->get_system_prompt() ) ),
384 - $this->normalize_extra_system( $extra_system ),
385 - array( array( 'role' => 'user', 'content' => $prompt ) )
386 - );
387 200
388 - return array( $messages, $this->ai_chat_options( $max_tokens ) );
389 - }
201 + // Check if the title is not empty
202 + if (title.trim() !== '' && keywords.trim() !== '') {
203 + e.preventDefault();
390 204
391 - /**
392 - * Assemble the chat options passed to the active provider. Document
393 - * generation is long-running on every platform: reasoning models (gpt-5*)
394 - * and larger non-OpenAI models (e.g. Claude Opus) routinely need well over
395 - * the old 50s default to return a full doc, which timed them out mid-
396 - * generation. Give every request a generous ceiling; fast models simply
397 - * finish early and are unaffected.
398 - *
399 - * @param int|null $max_tokens Optional token cap override.
400 - * @param float|null $temperature Optional sampling temperature.
401 - * @return array
402 - */
403 - private function ai_chat_options( $max_tokens = null, $temperature = null ) {
404 - $timeout = 300;
405 - if ( function_exists( 'set_time_limit' ) ) {
406 - set_time_limit( 300 );
407 - }
205 + if (!jQuery('#betterdocs-ai-error-message').parent().hasClass('hidden')) {
206 + jQuery('#betterdocs-ai-error-message').parent().addClass('hidden');
207 + }
408 208
409 - $options = array(
410 - 'max_tokens' => null !== $max_tokens ? (int) $max_tokens : (int) $this->settings->get( 'ai_autowrite_max_token', 2500 ),
411 - 'context' => 'write_with_ai',
412 - 'timeout' => $timeout,
413 - );
209 + docGenerateBtnTxt.innerHTML = "<?php echo esc_html__( 'Generating...', 'betterdocs' ); ?>";
210 + jQuery('.generate-btn').prop('disabled', true);
414 211
415 - if ( null !== $temperature ) {
416 - $options['temperature'] = $temperature;
417 - }
212 + jQuery.post({
213 + url: ajaxurl, // Make sure ajaxurl is defined in your script
214 + type: 'POST',
215 + data: {
216 + action: 'generate_openai_content',
217 + prompt: document.querySelector('#betterdocs-ai-content').value,
218 + // numOfSections: numOfSections,
219 + // numOfParagraphs: numOfParagraphs,
220 + keywords: keywords,
221 + ai_nonce: nonce, // Pass the nonce value
222 + },
223 + success: function(response) {
224 + // Update the content in the textarea
418 225
419 - return $options;
420 - }
226 + if (response.success && (typeof response.data === 'string')) {
227 + docGenerateBtnTxt.innerHTML = "<?php echo esc_html__( 'Generated', 'betterdocs' ); ?>";
228 + setTimeout(() => {
229 + insertContentToEditor(title, response.data, isOverwrite, keywords);
230 + docGenerateBtnTxt.innerHTML = reGenerateDocLabel;
231 + jQuery('.generate-btn').removeAttr('disabled');
421 232
422 - public function generate_openai_response( $prompt, $keywords, $max_tokens = null, $extra_system = array() ) {
423 - try {
424 - list( $messages, $options ) = $this->ai_request_args( $prompt, $max_tokens, $extra_system );
233 + // console.log(jQuery('.betterdocs-ai-autowrite-form-container').data('new-doc-page'));
425 234
426 - $result = ( new ProviderFactory( $this->settings ) )->make()->chat( $messages, $options );
235 + // if(jQuery('.betterdocs-ai-autowrite-form-container')?.data('new-doc-page')) {
236 + // docGenerateBtnTxt.innerHTML = reGenerateDocLabel;
237 + // }
238 + }, 2000);
239 + } else {
240 + // alert(response.data.message);
241 + jQuery('#betterdocs-ai-error-message').parent().removeClass('hidden');
242 + jQuery('#betterdocs-ai-error-message').html(responseMessage(response.data.message));
243 + docGenerateBtnTxt.innerHTML = generateDocLabel;
244 + jQuery('.generate-btn').removeAttr('disabled');
427 245
428 - if ( is_wp_error( $result ) ) {
429 - return $result->get_error_message();
430 - }
246 + }
247 + },
248 + error: function(error) {
249 + console.error(error);
250 + },
251 + });
431 252
432 - return $result['content'];
433 - } catch ( \Exception $error ) {
434 - return 'Error: ' . $error->getMessage();
435 - }
436 - }
253 + }
254 + }
437 255
438 - public function get_outline_system_prompt() {
439 - $prompt = <<<'PROMPT'
440 -You are a Senior Technical Writer. Produce a documentation OUTLINE only — not the full article.
256 + // Function to update the textarea
257 + function updateTextarea() {
258 + const title = document.getElementById('betterdocs-ai-title').value;
259 + const keywords = document.getElementById('betterdocs-ai-keyword').value;
260 + const sectionOptions = document.getElementById('bd-autowrtite-content-section');
261 + let language = 'English';
441 262
442 -Return ONLY a JSON array (no prose, no markdown, no code fences). Each element is an object:
443 - { "level": "h2" | "h3", "text": "Section heading" }
263 + if (language === '') {
264 + language = 'English';
265 + }
444 266
445 -Rules:
446 -- 5 to 9 top-level "h2" sections that comprehensively cover the topic.
447 -- Add "h3" sub-sections only where they genuinely help; keep each one directly after its parent h2.
448 -- Headings are concise, descriptive, and free of numbering.
449 -- Do not include an h1/title and do not include any text outside the JSON array.
450 -PROMPT;
267 + let keywordsText = keywords !== '' ? ` and incorporate the keywords: ${keywords}` : '';
451 268
452 - return apply_filters( 'betterdocs_write_with_ai_outline_system_prompt', $prompt );
453 - }
269 + const contentTextArea = document.getElementById('betterdocs-ai-content');
454 270
455 - /**
456 - * Generate a documentation outline as a structured array of sections.
457 - *
458 - * @param string $user_prompt The composed prompt (title/keywords/instructions).
459 - * @return array { success:bool, outline?:array<int,array{level:string,text:string}>, error?:string }
460 - */
461 - public function generate_outline_response( $user_prompt, $extra_system = array() ) {
462 - $result = $this->generate_text( $user_prompt, $this->get_outline_system_prompt(), $extra_system );
271 + if (!jQuery('#betterdocs-ai-error-message').parent().hasClass('hidden')) {
272 + jQuery('#betterdocs-ai-error-message').parent().addClass('hidden');
273 + }
463 274
464 - if ( empty( $result['success'] ) ) {
465 - return array(
466 - 'success' => false,
467 - 'error' => isset( $result['error'] ) ? $result['error'] : 'AI error',
468 - );
469 - }
275 + contentTextArea.value = `Generate a documentation using HTML heading tags for '${title}'. Include relevant details on ${keywords} in the documentation. Ensure all content is enclosed with <p> tags and apply a <span> tag with the class 'highlight' to headings and topic tags for emphasis.`;
276 + }
470 277
471 - $outline = $this->parse_outline( (string) $result['content'] );
278 + function convertMarkdownToHTML(markdownContent) {
279 + // Simple Markdown to HTML conversion (you may need to enhance this based on your needs)
280 + const htmlContent = markdownContent
281 + .replace(/^# (.+)$/gm, '<h1>$1</h1>')
282 + .replace(/^## (.+)$/gm, '<h2>$1</h2>')
283 + .replace(/^### (.+)$/gm, '<h3>$1</h3>')
284 + .replace(/\*\*(.+?)\*\*/g, '<strong>$1</strong>')
285 + .replace(/\*(.+?)\*/g, '<em>$1</em>');
472 286
473 - if ( empty( $outline ) ) {
474 - return array(
475 - 'success' => false,
476 - 'error' => 'The AI returned an outline we could not read. Please try again.',
477 - );
478 - }
287 + return htmlContent;
288 + }
479 289
480 - return array(
481 - 'success' => true,
482 - 'outline' => $outline,
483 - );
484 - }
290 + function replaceHeadingTitle(content, title, overviewTitle) {
291 + let regex = new RegExp(title, 'g');
292 + let updateContent = content.replace(regex, overviewTitle);
293 + return updateContent;
294 + }
485 295
486 - /**
487 - * Parse a model outline response (ideally a JSON array) into a clean list of
488 - * { level, text } sections. Tolerates code fences and stray prose.
489 - *
490 - * @param string $content
491 - * @return array<int,array{level:string,text:string}>
492 - */
493 - protected function parse_outline( $content ) {
494 - $content = trim( $content );
495 - $content = preg_replace( '/^```(?:json)?\s*/i', '', $content );
496 - $content = preg_replace( '/```\s*$/', '', $content );
296 + function removeFirstHeading(htmlString) {
297 + var newDiv = document.createElement('div');
298 + newDiv.innerHTML = htmlString;
299 + var firstHeading = newDiv.querySelector('h1');
300 + if (firstHeading) {
301 + firstHeading.parentNode.removeChild(firstHeading);
302 + }
303 + return newDiv.innerHTML;
304 + }
497 305
498 - // Grab the first JSON array if the model wrapped it in prose.
499 - if ( preg_match( '/\[[\s\S]*\]/', $content, $m ) ) {
500 - $content = $m[0];
501 - }
502 306
503 - $decoded = json_decode( $content, true );
504 - if ( ! is_array( $decoded ) ) {
505 - return array();
506 - }
307 + function wrapwithHeighlight(inputString, keywords) {
308 + let modifiedString = inputString.replace(/<(h\d)(.*?)>(.*?)<\/\1>/g, '<$1$2><span class="highlight">$3</span></$1>');
507 309
508 - $outline = array();
509 - foreach ( $decoded as $item ) {
510 - if ( ! is_array( $item ) || empty( $item['text'] ) ) {
511 - continue;
512 - }
513 - $level = isset( $item['level'] ) && 'h3' === strtolower( (string) $item['level'] ) ? 'h3' : 'h2';
514 - $text = sanitize_text_field( (string) $item['text'] );
515 - if ( '' === $text ) {
516 - continue;
517 - }
518 - $outline[] = array( 'level' => $level, 'text' => $text );
519 - }
310 + const keywordArray = keywords.split(',').map(keyword => keyword.trim());
520 311
521 - return $outline;
522 - }
312 + keywordArray.forEach(keyword => {
313 + modifiedString = modifiedString.replace(new RegExp(`\\b(${keyword})\\b`, 'gi'), '<span class="highlight">$1</span>');
314 + });
523 315
524 - public function generate_openai_response_ai_edit( $prompt, $extra_system = array() ) {
525 - $factory = new ProviderFactory( $this->settings );
526 - $model = $factory->active_model();
316 + return modifiedString;
317 + }
527 318
528 - $messages = array_merge(
529 - array( array( 'role' => 'system', 'content' => $this->get_system_prompt() ) ),
530 - $this->normalize_extra_system( $extra_system ),
531 - array( array( 'role' => 'user', 'content' => $prompt ) )
532 - );
319 + function getBodyContent(htmlString) {
320 + var match = htmlString.match(/<body[^>]*>([\s\S]*?)<\/body>/i);
533 321
534 - $result = $factory->make()->chat( $messages, $this->ai_chat_options() );
322 + // Check if match is null before accessing match[1]
323 + if (match) {
324 + console.log(match[1].replace(/<p>\s+/g, '<p>'));
325 + return match[1].replace(/<p>\s+/g, '<p>');
326 + } else {
327 + return '';
328 + }
329 + }
535 330
536 - if ( is_wp_error( $result ) ) {
537 - return array(
538 - 'success' => false,
539 - 'error' => $result->get_error_message(),
540 - 'model' => $model
541 - );
542 - }
543 331
544 - $usage = isset( $result['usage'] ) && is_array( $result['usage'] ) ? $result['usage'] : array();
545 332
546 - return array(
547 - 'success' => true,
548 - 'content' => $result['content'],
549 - 'model' => isset( $result['model'] ) ? $result['model'] : $model,
550 - 'prompt_tokens' => isset( $usage['prompt_tokens'] ) ? $usage['prompt_tokens'] : null,
551 - 'completion_tokens' => isset( $usage['completion_tokens'] ) ? $usage['completion_tokens'] : null,
552 - 'total_tokens' => isset( $usage['total_tokens'] ) ? $usage['total_tokens'] : null,
553 - 'finish_reason' => isset( $result['finish_reason'] ) ? $result['finish_reason'] : null
554 - );
555 - }
333 + function insertContentToEditor(title, htmlContent, isOverwrite, keywords) {
556 334
557 - /**
558 - * Generic chat completion using the active Write-with-AI platform/model/token
559 - * settings. Shared by lightweight, plain-text generators (glossary definitions,
560 - * FAQ answers, outlines) that need the same dynamic model as Write with AI /
561 - * AI Edit but a caller-supplied system prompt instead of the doc-authoring HTML
562 - * prompt. Routes through ProviderFactory so every provider is supported.
563 - *
564 - * @param string $user_prompt The user message.
565 - * @param string $system_prompt Optional system message (omitted when empty).
566 - * @param array $extra_system Optional extra system messages.
567 - * @return array { success:bool, content?:string, error?:string, model:string, *_tokens?:int }
568 - */
569 - public function generate_text( $user_prompt, $system_prompt = '', $extra_system = array() ) {
570 - $factory = new ProviderFactory( $this->settings );
571 - $model = $factory->active_model();
335 + const {
336 + dispatch,
337 + select
338 + } = wp.data;
572 339
573 - $messages = array();
574 - if ( $system_prompt !== '' ) {
575 - $messages[] = array( 'role' => 'system', 'content' => $system_prompt );
576 - }
577 - foreach ( $this->normalize_extra_system( $extra_system ) as $extra ) {
578 - $messages[] = $extra;
579 - }
580 - $messages[] = array( 'role' => 'user', 'content' => $user_prompt );
340 + htmlContent = getBodyContent(htmlContent);
341 + htmlContent = removeFirstHeading(htmlContent);
342 + htmlContent = wrapwithHeighlight(htmlContent, keywords);
343 + const isPostContent = `<?php echo isset($_GET['post']) ? esc_html(get_the_content($_GET['post'])) : ''; // phpcs:ignore ?>`;
581 344
582 - $result = $factory->make()->chat( $messages, $this->ai_chat_options() );
345 + const blocks = wp.blocks.rawHandler({
346 + HTML: htmlContent
347 + });
583 348
584 - if ( is_wp_error( $result ) ) {
585 - return array(
586 - 'success' => false,
587 - 'error' => $result->get_error_message(),
588 - 'model' => $model
589 - );
590 - }
349 + dispatch('core/editor').editPost({
350 + title: title,
351 + });
591 352
592 - $usage = isset( $result['usage'] ) && is_array( $result['usage'] ) ? $result['usage'] : array();
353 + const selectedBlockClientId = select('core/block-editor').getSelectedBlockClientId();
593 354
594 - return array(
595 - 'success' => true,
596 - 'content' => $result['content'],
597 - 'model' => isset( $result['model'] ) ? $result['model'] : $model,
598 - 'prompt_tokens' => isset( $usage['prompt_tokens'] ) ? $usage['prompt_tokens'] : null,
599 - 'completion_tokens' => isset( $usage['completion_tokens'] ) ? $usage['completion_tokens'] : null,
600 - 'total_tokens' => isset( $usage['total_tokens'] ) ? $usage['total_tokens'] : null,
601 - 'finish_reason' => isset( $result['finish_reason'] ) ? $result['finish_reason'] : null
602 - );
603 - }
355 + const allBlocks = select('core/block-editor').getBlocks();
604 356
605 - /**
606 - * Generate a chat completion with a caller-supplied system + user prompt.
607 - * Mirrors generate_openai_response_ai_edit() (same model/token floor/timeout
608 - * handling and return shape) but does NOT force the documentation-writer
609 - * system prompt, so callers such as the Docs AI Suite (taxonomy suggestions,
610 - * excerpts) can supply task-appropriate instructions. Routes through the active
611 - * provider via ProviderFactory.
612 - *
613 - * @param string $system_prompt System instruction for the model.
614 - * @param string $user_prompt User message / content payload.
615 - * @param float|null $temperature Optional sampling temperature (ignored for gpt-5*).
616 - * @return array{success:bool,content?:string,error?:string,model:string,...}
617 - */
618 - public function generate_openai_response_raw( $system_prompt, $user_prompt, $temperature = null ) {
619 - $factory = new ProviderFactory( $this->settings );
620 - $model = $factory->active_model();
357 + if (isOverwrite || isPostContent === '') {
621 358
622 - $messages = array(
623 - array( 'role' => 'system', 'content' => $system_prompt ),
624 - array( 'role' => 'user', 'content' => $user_prompt )
625 - );
359 + allBlocks.forEach((block) => {
360 + dispatch('core/block-editor').removeBlock(block.clientId);
361 + });
362 + dispatch('core/block-editor').insertBlocks(blocks);
626 363
627 - $result = $factory->make()->chat( $messages, $this->ai_chat_options( null, $temperature ) );
364 + } else if (selectedBlockClientId) {
365 + const selectedIndex = select('core/block-editor').getBlockIndex(selectedBlockClientId);
366 + dispatch('core/block-editor').insertBlocks(blocks, selectedIndex + 1);
367 + } else {
368 + dispatch('core/block-editor').insertBlocks(blocks);
369 + }
628 370
629 - if ( is_wp_error( $result ) ) {
630 - return array(
631 - 'success' => false,
632 - 'error' => $result->get_error_message(),
633 - 'model' => $model
634 - );
635 - }
371 + closeWriteWithAIForm('afterInsertContent');
372 + }
636 373
637 - $usage = isset( $result['usage'] ) && is_array( $result['usage'] ) ? $result['usage'] : array();
374 + function closeWriteWithAIForm(after) {
375 + jQuery('.betterdocs-ai-autowrite-form-container').addClass('hidden');
376 + jQuery('#betterdocs-ai-autowrite-form-container-overlay').addClass('hidden');
377 + jQuery('.betterdocs-ai-button').addClass('regenerate-btn');
378 + }
638 379
639 - return array(
640 - 'success' => true,
641 - 'content' => $result['content'],
642 - 'model' => isset( $result['model'] ) ? $result['model'] : $model,
643 - 'prompt_tokens' => isset( $usage['prompt_tokens'] ) ? $usage['prompt_tokens'] : null,
644 - 'completion_tokens' => isset( $usage['completion_tokens'] ) ? $usage['completion_tokens'] : null,
645 - 'total_tokens' => isset( $usage['total_tokens'] ) ? $usage['total_tokens'] : null,
646 - 'finish_reason' => isset( $result['finish_reason'] ) ? $result['finish_reason'] : null
647 - );
648 - }
649 380
650 - public function generate_openai_content_callback() {
651 - // Verify the nonce
652 - $ai_nonce = isset( $_POST['ai_nonce'] ) ? sanitize_text_field( wp_unslash( $_POST['ai_nonce'] ) ) : '';
653 - if ( ! wp_verify_nonce( $ai_nonce, 'generate_openai_content_nonce' ) ) {
654 - wp_send_json_error( 'Invalid nonce' );
655 - wp_die();
656 - }
381 + document.addEventListener('DOMContentLoaded', function() {
657 382
658 - if ( ! current_user_can( 'edit_posts' ) ) {
659 - wp_send_json_error( 'Insufficient permissions' );
660 - wp_die();
661 - }
383 + // Subscribe to changes in the editor state
384 + let previousDocsTitle = '';
662 385
663 - $prompt = isset( $_POST['prompt'] ) ? sanitize_text_field( wp_unslash( $_POST['prompt'] ) ) : '';
664 - $keywords = isset( $_POST['keywords'] ) ? sanitize_text_field( wp_unslash( $_POST['keywords'] ) ) : '';
386 + wp.data.subscribe(() => {
387 + // Get the updated post title
388 + // const docsTitle = wp.data.select('core/editor').getEditedPostAttribute('title');
665 389
666 - $ai_instance = new WriteWithAI( $this->settings );
390 + const docsTitle = wp.data.select('core/editor').getEditedPostAttribute('title');
667 391
668 - $generated_content = $ai_instance->generate_openai_response( $prompt, $keywords );
392 + // Check if the title has changed
393 + if (docsTitle !== previousDocsTitle) {
394 + let currentKeywords = jQuery('#betterdocs-ai-keyword').val();
395 + if (!currentKeywords) {
396 + currentKeywords = '{Documentation Keywords}';
397 + }
398 + const currentPrompt = `Generate documentation using HTML heading tags for '${docsTitle?docsTitle:'{Documentation title}'}'. Include relevant details on ${currentKeywords} in the documentation. Ensure all content is enclosed with <p> tags and apply a <span> tag with the class 'highlight' to headings and topic tags for emphasis.`;
399 + jQuery('#betterdocs-ai-content').val(currentPrompt);
669 400
670 - // Count a successful generation (skip obvious upstream errors).
671 - if ( is_string( $generated_content ) && $generated_content !== '' && strpos( $generated_content, 'Error:' ) !== 0 ) {
672 - $post_id = isset( $_POST[ 'post_id' ] ) ? intval( $_POST[ 'post_id' ] ) : 0; //phpcs:ignore
673 - AIUsage::record( 'write_with_ai', $post_id );
674 - }
401 + jQuery('#betterdocs-ai-title').val(docsTitle);
675 402
676 - // Send the generated content as the AJAX response
677 - wp_send_json_success( $generated_content );
678 - wp_die();
679 - }
403 + previousDocsTitle = docsTitle;
404 + }
405 +
406 +
407 + });
408 + });
409 +
410 +
411 + // This example assumes that this code is executed when your script is loaded.
412 + // You may want to place it within the appropriate context in your application.
413 +
414 +
415 + function writeWithAIForm() {
416 +
417 + let title = `<?php echo isset($_GET['post']) ? esc_html(get_the_title($_GET['post'])) : ''; // phpcs:ignore ?>`;
418 + if (docsTitle) {
419 + title = docsTitle;
420 + }
421 +
422 + const promtTitle = `<?php echo isset($_GET['post']) ? esc_html(get_the_title($_GET['post'])) : '{Documentation Title}'; // phpcs:ignore ?>`;
423 + const titlePlaceholder = "<?php echo esc_attr__( 'Enter a descriptive title for your documentation.', 'betterdocs' ); ?>";
424 + const keywords = "<?php echo esc_attr( '{Documentation Keywords}' ); ?>";
425 + const keywordsPlaceholder = "<?php echo esc_attr__( 'Add keywords to generate precise & relevant documentation (comma-separated).', 'betterdocs' ); ?>";
426 + const language = "<?php echo esc_attr( 'English' ); ?>";
427 + const titleLabel = "<?php echo esc_html__( 'Documentation Title:', 'betterdocs' ); ?>";
428 + const keywordLabel = "<?php echo esc_html__( 'Keywords:', 'betterdocs' ); ?>";
429 + const secLabel = "<?php echo esc_html__( '# of Sections:', 'betterdocs' ); ?>";
430 + const paraLabel = "<?php echo esc_html__( '# of Paragraph Per Section: ', 'betterdocs' ); ?>";
431 + const langLabel = "<?php echo esc_html__( 'Language:', 'betterdocs' ); ?>";
432 + const promtLabel = "<?php echo esc_html__( 'Prompt:', 'betterdocs' ); ?>";
433 + const promtBtnLabel = "<?php echo esc_html__( 'Generate Prompt', 'betterdocs' ); ?>";
434 + let promtArticleLabel = "<?php echo esc_html__( 'Generate Doc', 'betterdocs' ); ?>";
435 + const checkboxLabel = "<?php echo esc_html__( 'Overwrite your existing Doc:', 'betterdocs' ); ?>";
436 + const nonce = "<?php echo esc_attr( wp_create_nonce( 'generate_openai_content_nonce' ) ); ?>";
437 +
438 + <?php
439 + $is_valid = $this->get_api_key();
440 + $disable_field = 'disabled-input-field';
441 + if ( $this->get_api_key() ) {
442 + $disable_field = '';
443 + }
444 + ?>
445 +
446 + let hiddenClass = 'hidden';
447 + let newDocPageAtt = 'data-new-doc-page="true"';
448 + const isPostContent = `<?php echo isset($_GET['post']) ? esc_html(get_the_content($_GET['post'])) : ''; // phpcs:ignore ?>`;
449 +
450 + if (isPostContent !== '') {
451 + hiddenClass = '';
452 + newDocPageAtt = '';
453 + }
454 +
455 +
456 + // const prompt = `Make a knowledge base article with html heading tags about [${title}] in [${language}]. Here is some topic to describe the article: [${keywords}]. and wrap the content with p tag also add a span tag with a class named 'highlight' to all the heading and topic tags in the article.`;
457 +
458 + // const prompt = `Create a details knowledge base article in [${language}] about [${title}] with html heading tags. Here is some topic to describe the article: [${keywords}]. And wrap the content with p tag also add a span tag with a class named 'highlight' to all the heading and topic tags in the article.`;
459 +
460 + const prompt = `Generate a documentation using HTML heading tags for '${promtTitle}'. Include relevant details on ${keywords} in the documentation. Ensure all content is enclosed with <p> tags and apply a <span> tag with the class 'highlight' to headings and topic tags for emphasis.`;
461 +
462 + const aiIcon = `<svg xmlns="http://www.w3.org/2000/svg" width="21" height="20" viewBox="0 0 21 20" fill="none">
463 + <g clip-path="url(#clip0_2460_1729)">
464 + <path d="M10.3956 18.8608L6.10991 19.2322L6.48134 14.9465L15.3956 6.08936C15.5287 5.95329 15.6876 5.84518 15.863 5.77137C16.0384 5.69756 16.2268 5.65954 16.4171 5.65954C16.6074 5.65954 16.7957 5.69756 16.9711 5.77137C17.1466 5.84518 17.3054 5.95329 17.4385 6.08936L19.2528 7.91793C19.3865 8.05083 19.4926 8.20886 19.565 8.38293C19.6375 8.55701 19.6747 8.74368 19.6747 8.93221C19.6747 9.12075 19.6375 9.30742 19.565 9.48149C19.4926 9.65557 19.3865 9.8136 19.2528 9.9465L10.3956 18.8608ZM1.7042 5.67507C1.20277 5.58793 1.20277 4.86793 1.7042 4.78079C2.59203 4.62626 3.41374 4.21085 4.06456 3.58751C4.71538 2.96417 5.16583 2.16113 5.35848 1.28079L5.38848 1.14221C5.49705 0.647929 6.20277 0.643643 6.31705 1.13936L6.35277 1.29936C6.55248 2.17579 7.0067 2.97367 7.65837 3.59281C8.31005 4.21195 9.13013 4.62475 10.0156 4.77936C10.5199 4.86507 10.5199 5.58936 10.0156 5.67793C9.13005 5.83218 8.3098 6.24465 7.65787 6.86354C7.00594 7.48243 6.5514 8.28014 6.35134 9.1565L6.3142 9.31793C6.20134 9.81221 5.49563 9.80936 5.38705 9.31364L5.35848 9.17507C5.16564 8.29433 4.71476 7.49102 4.06339 6.86764C3.41202 6.24426 2.58969 5.82908 1.70134 5.67507H1.7042Z" stroke="white" stroke-width="1.42857" stroke-linecap="round" stroke-linejoin="round"/>
465 + </g>
466 + <defs>
467 + <clipPath id="clip0_2460_1729">
468 + <rect width="20" height="20" fill="white" transform="translate(0.5)"/>
469 + </clipPath>
470 + </defs>
471 + </svg>`;
472 +
473 +
474 +
475 + return `
476 + <div class="betterdocs-ai-autowrite-form-container hidden" ${newDocPageAtt}>
477 + <div class="betterdocs-ai-autowrite-form-content">
478 + <div class="betterdocs-ai-autowrite-top-part">
479 + <div class="autowrite-heading">
480 + <span class="autowrite-icon">
481 + <svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32" fill="none">
482 + <g clip-path="url(#clip0_2453_20882)">
483 + <path d="M15.8322 30.1765L8.97508 30.7708L9.56936 23.9136L23.8322 9.74219C24.0451 9.52448 24.2993 9.3515 24.58 9.23341C24.8606 9.11531 25.162 9.05447 25.4665 9.05447C25.771 9.05447 26.0724 9.11531 26.3531 9.23341C26.6337 9.3515 26.8879 9.52448 27.1008 9.74219L30.0037 12.6679C30.2176 12.8805 30.3874 13.1334 30.5033 13.4119C30.6192 13.6904 30.6788 13.9891 30.6788 14.2908C30.6788 14.5924 30.6192 14.8911 30.5033 15.1696C30.3874 15.4481 30.2176 15.701 30.0037 15.9136L15.8322 30.1765ZM1.92593 9.07933C1.12365 8.9399 1.12365 7.7879 1.92593 7.64848C3.34647 7.40124 4.6612 6.73658 5.70251 5.73923C6.74382 4.74188 7.46455 3.45703 7.77279 2.04848L7.82079 1.82676C7.99451 1.03591 9.12365 1.02905 9.30651 1.82219L9.36365 2.07819C9.68319 3.48048 10.4099 4.75709 11.4526 5.74772C12.4953 6.73834 13.8074 7.39881 15.2242 7.64619C16.0311 7.78333 16.0311 8.94219 15.2242 9.0839C13.8073 9.33071 12.4949 9.99066 11.4518 10.9809C10.4087 11.9711 9.68146 13.2474 9.36136 14.6496L9.30193 14.9079C9.12136 15.6988 7.99222 15.6942 7.81851 14.901L7.77279 14.6793C7.46424 13.2702 6.74284 11.9849 5.70064 10.9874C4.65845 9.99003 3.34273 9.32574 1.92136 9.07933H1.92593Z" stroke="#E31B54" stroke-width="2.28571" stroke-linecap="round" stroke-linejoin="round"/>
484 + </g>
485 + <defs>
486 + <clipPath id="clip0_2453_20882">
487 + <rect width="32" height="32" fill="white"/>
488 + </clipPath>
489 + </defs>
490 + </svg>
491 + </span>
492 + <h1><?php echo esc_html__( 'Write Documentation with BetterDocs AI', 'betterdocs' ); ?></h1>
493 +
494 + </div>
495 + <div class="autowrite-subheadding">
496 + <p><?php echo esc_html__( 'Generate documentation effortlessly with BetterDocs AI. Simply input your doc title, keywords, prompt and let the system automatically generate comprehensive documentation tailored to your needs.', 'betterdocs' ); ?></p>
497 + </div>
498 +
499 + <?php if ( empty( $this->get_api_key() ) ) : ?>
500 + <div id="betterdocs-ai-message">
501 + <div class="warning-message">
502 + <span class="dashicons dashicons-warning"></span>
503 + <div>
504 + <?php echo wp_kses_post( 'Please Insert your <a target="_blank" href="' . esc_url( admin_url( 'admin.php?page=betterdocs-settings&tab=tab-ai-autowrite' ) ) . '">OpenAI API Key</a> to use this Write with AI feature.', 'betterdocs' ); ?>
505 + </div>
506 + </div>
507 +
508 + </div>
509 + <?php endif; ?>
510 +
511 + <div class="form-group hidden">
512 + <div id="betterdocs-ai-error-message"></div>
513 + </div>
514 +
515 + </div>
516 + <form id="betterdocs-ai-form" class="<?php echo esc_attr( $disable_field ); ?>">
517 + <div class="form-inner-content">
518 + <div class="form-group">
519 + <label for="betterdocs-ai-title">${titleLabel}</label>
520 + <input type="text" placeholder="${titlePlaceholder}" id="betterdocs-ai-title" name="betterdocs-ai-title" required value="${title}">
521 + </div>
522 +
523 + <div class="form-group">
524 + <label for="betterdocs-ai-keyword">${keywordLabel}</label>
525 + <input type="text" placeholder="${keywordsPlaceholder}" id="betterdocs-ai-keyword" name="betterdocs-ai-keyword" required>
526 + </div>
527 +
528 + <div class="form-group prompt-field">
529 + <label for="betterdocs-ai-content">${promtLabel}</label>
530 + <textarea id="betterdocs-ai-content" name="betterdocs-ai-content" rows="6" required>${prompt}</textarea>
531 + <p class="input-description"><?php echo esc_html__( 'Ensure you include a clear and detailed prompt to receive the desired output. Follow the guidelines provided for the best results.', 'betterdocs' ); ?></p>
532 + </div>
533 + <div class="betterdocs-ai-checkbox-field ${hiddenClass}">
534 + <div class="form-group">
535 + <div class="checkbox-field-label">
536 + <label for="betterdocs-ai-checkbox">${checkboxLabel}</label>
537 + <p class="input-description"><?php echo esc_html__( 'Overwrite the existing doc with the AI Generated Content. If Disabled, new AI Generated content will be added in the section you are currently editing.', 'betterdocs' ); ?></p>
538 + </div>
539 +
540 + <div class="checkbox-input-field">
541 + <input type="checkbox" id="betterdocs-ai-checkbox" name="betterdocs-ai-checkbox" data-overwrite="false">
542 + <label for="betterdocs-ai-checkbox" class="toggle-label"></label>
543 + </div>
544 + </div>
545 + </div>
546 +
547 + <input type="hidden" name="ai_nonce" value="${nonce}" />
548 + </div>
549 + <div class="generate-button-container">
550 + <button type="submit" class="generate-btn" onclick="generateArticle(event)">
551 + ${aiIcon} <span>${promtArticleLabel}</span>
552 + </button>
553 + </div>
554 + </form>
555 + </div>
556 +
557 + <div class="bd-close-button" onclick="closeWriteWithAIForm('afterClosedClicked')">✕</div>
558 + </div>
559 +
560 + <div id="betterdocs-ai-autowrite-form-container-overlay" class="hidden"></div>
561 + `;
562 + }
563 +
564 + jQuery(document).on('click', '.regenerate-btn', function() {
565 + jQuery('.betterdocs-ai-autowrite-form-container').removeClass('hidden');
566 + jQuery('#betterdocs-ai-autowrite-form-container-overlay').removeClass('hidden');
567 + });
568 +
569 + jQuery(document).ready(function($) {
570 + // Check if we are in the Edit Post screen
571 +
572 + if ($('.block-editor-page').length > 0) {
573 +
574 + const bdAIButton = $(`<div class="betterdocs-ai-button-container">
575 + <button class="betterdocs-ai-button">
576 + <img src="<?php echo esc_url( BETTERDOCS_ABSURL . 'assets/admin/images/betterdocs-icon-white.png' ); ?>" alt="<?php echo esc_attr__( 'betterdocs icon', 'betterdocs' ); ?>" />
577 + <span><?php echo esc_html__( 'Write with AI', 'betterdocs' ); ?></span>
578 + </button>
579 + </div>`);
580 +
581 +
582 + const closeBtn = $('bd-close-button');
583 +
584 + const formHtml = writeWithAIForm();
585 + $(formHtml).addClass('hidden');
586 +
587 + $(document).on('click', '.betterdocs-ai-button', function() {
588 + $('.betterdocs-ai-autowrite-form-container').removeClass('hidden');
589 + $('#betterdocs-ai-autowrite-form-container-overlay').removeClass('hidden');
590 + });
591 +
592 + // $(document).on('click', '.betterdocs-ai-button', function() {
593 + if ($('.betterdocs-ai-autowrite-form-container').length < 1) {
594 + $('body').append(formHtml);
595 +
596 + // Add event listeners to input elements
597 + document.getElementById('betterdocs-ai-title').addEventListener('input', updateTextarea);
598 + document.getElementById('betterdocs-ai-keyword').addEventListener('input', updateTextarea);
599 + // document.getElementById('bd-autowrtite-content-section').addEventListener('change', updateTextarea);
600 + // document.getElementById('bd-autowrtite-content-paragraph').addEventListener('change', updateTextarea);
601 + // document.getElementById('betterdocs-ai-language').addEventListener('input', updateTextarea);
602 + }
603 + // });
604 + const btn = document.createElement('button');
605 + wp.data.subscribe(function() {
606 + setTimeout(() => {
607 + if ($('.edit-post-header__settings').length > 0) {
608 + $('.edit-post-header__settings').prepend(bdAIButton);
609 + } else if ($('.editor-header__settings').length > 0) {
610 + $('.editor-header__settings').prepend(bdAIButton);
611 + }
612 +
613 + }, 1);
614 + });
615 + }
616 +
617 + $(document).on('click', '#betterdocs-ai-autowrite-form-container-overlay', function() {
618 + closeWriteWithAIForm();
619 + });
620 + });
621 + </script>
622 +
623 + <style>
624 + .hidden {
625 + display: none !important;
626 + }
627 +
628 + .disabled-input-field input,
629 + .disabled-input-field textarea,
630 + .disabled-input-field button,
631 + .disabled-input-field label {
632 + pointer-events: none;
633 + opacity: 0.6;
634 + }
635 +
636 + .disabled-input-field label {
637 + opacity: 1;
638 + }
639 +
640 + .betterdocs-ai-button-container {
641 + margin-left: 10px;
642 + }
643 +
644 + .autowrite-icon {
645 + display: flex;
646 + align-items: center;
647 + width: 55px;
648 + height: 55px;
649 + background: #FFE4E8;
650 + justify-content: center;
651 + border-radius: 50px;
652 + }
653 +
654 + .autowrite-icon svg {
655 + width: 28px;
656 + height: 28px;
657 + }
658 +
659 + .autowrite-heading {
660 + display: flex;
661 + gap: 10px;
662 + align-items: center;
663 + }
664 +
665 + .autowrite-heading h1 {
666 + color: #1D2939;
667 + font-family: 'IBM Plex Sans', sans-serif;
668 + font-size: 24px;
669 + font-style: normal;
670 + font-weight: 500;
671 + line-height: normal;
672 + margin: 0;
673 + }
674 +
675 + .autowrite-heading p,
676 + form#betterdocs-ai-form p {
677 + margin: 0;
678 + margin-bottom: 24px;
679 + }
680 +
681 + .autowrite-subheadding p {
682 + font-family: 'IBM Plex Sans', sans-serif;
683 + font-size: 14px;
684 + }
685 +
686 + .prompt-field .input-description {
687 + margin: 0 !important;
688 + }
689 +
690 + .autowrite-heading p {
691 + color: #475467;
692 + font-family: 'IBM Plex Sans', sans-serif;
693 + font-size: 16px;
694 + font-style: normal;
695 + font-weight: 400;
696 + }
697 +
698 + .betterdocs-ai-button {
699 + background: #00B884;
700 + border: 1px solid transparent;
701 + color: #fff;
702 + box-shadow: none;
703 + font-size: 12px;
704 + margin-right: 8px;
705 + padding: 0px 15px;
706 + cursor: pointer;
707 + border-radius: 3px;
708 + height: 38px;
709 + display: flex;
710 + align-items: center;
711 + justify-content: space-between;
712 + gap: 10px;
713 + }
714 +
715 + .betterdocs-ai-button img {
716 + width: 20px;
717 + height: 20px;
718 + }
719 +
720 + .betterdocs-ai-autowrite-form-container {
721 + position: fixed;
722 + top: 50%;
723 + left: 50%;
724 + transform: translate(-50%, -50%);
725 + z-index: 100001;
726 + width: 650px;
727 + margin: 0 auto;
728 + background-color: #fff;
729 + border-radius: 5px;
730 + font-family: 'IBM Plex Sans', sans-serif;
731 + /* max-height: 600px; */
732 + max-height: 750px;
733 + max-width: 100%;
734 + }
735 +
736 + .betterdocs-ai-autowrite-form-content {
737 + background-color: #fff;
738 + padding: 20px 0px;
739 + border-radius: 5px;
740 + padding-bottom: 0;
741 + overflow: auto;
742 + /* max-height: 700px; */
743 + height: 100%;
744 +
745 + }
746 +
747 + .betterdocs-ai-autowrite-top-part {
748 + /* padding-bottom: 20px; */
749 + border-bottom: 1px solid #ddd;
750 + /* margin-bottom: 20px; */
751 + padding: 0 40px;
752 + }
753 +
754 + #betterdocs-ai-form {
755 + display: flex;
756 + flex-direction: column;
757 + /* height: 100%; */
758 + overflow: hidden;
759 + }
760 +
761 + .form-inner-content {
762 + overflow: auto;
763 + height: 100%;
764 + max-height: 435px;
765 + /* max-height: 330px; */
766 + padding: 0 40px;
767 + }
768 +
769 + .form-inner-content>.form-group {
770 + margin-top: 20px;
771 + }
772 +
773 +
774 + #betterdocs-ai-autowrite-form-container-overlay {
775 + position: fixed;
776 + top: 0;
777 + right: 0;
778 + bottom: 0;
779 + left: 0;
780 + background-color: rgba(0, 0, 0, .7);
781 + z-index: 100000;
782 + }
783 +
784 +
785 +
786 + #betterdocs-ai-form {
787 + display: flex;
788 + flex-direction: column;
789 + }
790 +
791 + #betterdocs-ai-form .form-group {
792 + margin-bottom: 24px;
793 + }
794 +
795 + #betterdocs-ai-form .bd-aiform-flex {
796 + display: flex;
797 + justify-content: space-between;
798 + }
799 +
800 + #betterdocs-ai-form label {
801 + font-weight: 600;
802 + margin-bottom: 5px;
803 + display: block;
804 + font-size: 14px;
805 + line-height: 20px;
806 + }
807 +
808 + select#bd-autowrtite-content-section,
809 + #bd-autowrtite-content-paragraph,
810 + #betterdocs-ai-language {
811 + width: 150px !important;
812 + height: 40px;
813 + }
814 +
815 + #betterdocs-ai-form input[type="text"],
816 + #betterdocs-ai-form textarea {
817 + width: 100%;
818 + padding: 8px;
819 + box-sizing: border-box;
820 + border: 1px solid #D0D5DD;
821 + border-radius: 4px;
822 + color: #667085;
823 + font-weight: 400;
824 + }
825 +
826 + /* Override autofill text color */
827 + #betterdocs-ai-form input:-webkit-autofill {
828 + -webkit-text-fill-color: #667085 !important;
829 + }
830 +
831 + #betterdocs-ai-form input::placeholder {
832 + color: #acb2bf;
833 + }
834 +
835 + #betterdocs-ai-form textarea {
836 + color: #667085;
837 + }
838 +
839 + #betterdocs-ai-form input:focus,
840 + #betterdocs-ai-form textarea:focus {
841 + box-shadow: none;
842 + }
843 +
844 + #betterdocs-ai-form textarea:focus {
845 + color: inherit;
846 + box-shadow: none;
847 +
848 + }
849 +
850 +
851 + .generate-button-container {
852 + position: sticky;
853 + bottom: 0px;
854 + width: 100%;
855 + margin-left: 0;
856 + z-index: 999999 !important;
857 + padding: 20px 0;
858 + display: flex;
859 + justify-content: end;
860 + border-top: 1px solid #ddd;
861 + background: white;
862 + border-bottom-right-radius: 5px;
863 + border-bottom-left-radius: 5px;
864 + }
865 +
866 + .generate-button-container button {
867 + display: flex;
868 + gap: 8px;
869 + align-items: center;
870 + justify-content: center;
871 + opacity: 1 !important;
872 + margin-right: 40px;
873 + }
874 +
875 + .input-description {
876 + font-size: 14px;
877 + color: #667085;
878 + }
879 +
880 + .betterdocs-ai-checkbox-field .form-group {
881 + display: flex;
882 + align-items: start;
883 + /* gap: 200px; */
884 + justify-content: space-between;
885 + }
886 +
887 + .betterdocs-ai-checkbox-field input {
888 + width: 20px;
889 + height: 20px;
890 + }
891 +
892 + /* Add this CSS to your existing stylesheet or create a new one */
893 +
894 + .betterdocs-ai-checkbox-field {
895 + position: relative;
896 + font-size: 16px;
897 + /* Adjust font size as needed */
898 + }
899 +
900 + .betterdocs-ai-checkbox-field input[type=checkbox]:checked::before {
901 + padding: 2px;
902 + }
903 +
904 + .betterdocs-ai-checkbox-field input[type=checkbox] {
905 + border: 1px solid #00b884;
906 + }
907 +
908 + .betterdocs-ai-checkbox-field input[type=checkbox]:checked::before {
909 + content: '\2713';
910 + color: #00b884;
911 + }
912 +
913 + /* Change the default checkbox color */
914 + .betterdocs-ai-checkbox-field input[type="checkbox"]:hover {
915 + -webkit-appearance: none;
916 + /* WebKit/Blink Browsers */
917 + -moz-appearance: none;
918 + /* Firefox */
919 + appearance: none;
920 + border: 1px solid #00b884;
921 + /* Set the height of the checkbox */
922 + /* Optional: Round the corners */
923 + outline: none;
924 + /* Remove the default outline */
925 + }
926 +
927 + /* Style the checked state */
928 + .betterdocs-ai-checkbox-field input[type="checkbox"]:checked {
929 + /* Set the background color when checked */
930 + border: 1px solid #00b884;
931 + /* Set the border color when checked */
932 + }
933 +
934 + .checkbox-field-label {
935 + width: calc(100% - 150px);
936 + }
937 +
938 + .checkbox-field-label p {
939 + margin: 0 !important;
940 + }
941 +
942 + .checkbox-input-field {
943 + width: 300px;
944 + text-align: right;
945 + }
946 +
947 + .checkbox-input-field {
948 + position: relative;
949 + display: inline-block;
950 + width: 60px;
951 + height: 34px;
952 + }
953 +
954 + .checkbox-input-field input {
955 + display: none;
956 + }
957 +
958 + .toggle-label {
959 + position: absolute;
960 + cursor: pointer;
961 + top: 0;
962 + left: 0;
963 + right: 0;
964 + bottom: 0;
965 + background-color: #ccc;
966 + border-radius: 34px;
967 + transition: background-color 0.3s;
968 + scale: .9;
969 + width: 52px;
970 + height: 26px;
971 + }
972 +
973 +
974 + .checkbox-input-field input:checked+.toggle-label {
975 + background-color: #00b884;
976 + }
977 +
978 + .toggle-label:after {
979 + content: "";
980 + position: absolute;
981 + height: 22px;
982 + width: 22px;
983 + left: 2px;
984 + bottom: 2px;
985 + background-color: white;
986 + border-radius: 50%;
987 + transition: transform 0.3s;
988 + }
989 +
990 + .checkbox-input-field input:checked+.toggle-label:after {
991 + transform: translateX(26px);
992 + }
993 +
994 + .generate-btn,
995 + .prompt-btn,
996 + .keep-btn {
997 + background-color: #00b884;
998 + color: #fff;
999 + border: none;
1000 + padding: 10px 15px;
1001 + text-align: center;
1002 + text-decoration: none;
1003 + display: inline-block;
1004 + font-size: 16px;
1005 + cursor: pointer;
1006 + border-radius: 4px;
1007 + }
1008 +
1009 + .generate-btn[disabled] {
1010 + cursor: unset;
1011 + }
1012 +
1013 + .bd-close-button {
1014 + cursor: pointer;
1015 + font-size: 18px;
1016 + font-weight: bold;
1017 + float: right;
1018 + position: absolute;
1019 + right: 1px;
1020 + top: 1px;
1021 + padding: 10px;
1022 + background: #ffffff;
1023 + border-radius: 25px;
1024 + width: 20px;
1025 + height: 20px;
1026 + display: flex;
1027 + align-items: center;
1028 + justify-content: center;
1029 + color: #281617;
1030 + right: -60px;
1031 + }
1032 +
1033 + div#betterdocs-ai-error-message,
1034 + #betterdocs-ai-message {
1035 + font-size: 14px;
1036 + font-family: 'IBM Plex Sans', sans-serif;
1037 + color: #667085;
1038 + margin-bottom: 20px;
1039 + }
1040 +
1041 + div#betterdocs-ai-error-message a,
1042 + #betterdocs-ai-message a {
1043 + text-decoration: none;
1044 + font-weight: 600;
1045 + }
1046 +
1047 + div#betterdocs-ai-error-message a:focus,
1048 + #betterdocs-ai-message a:focus {
1049 + outline: none;
1050 + box-shadow: none;
1051 + color: #2271b1;
1052 + }
1053 +
1054 + #betterdocs-ai-message span {
1055 + color: #d63638;
1056 + }
1057 +
1058 + .warning-message {
1059 + display: flex;
1060 + align-items: center;
1061 + gap: 10px;
1062 + background: #fbebed;
1063 + padding: 12px;
1064 + border-radius: 5px;
1065 + font-size: 14px;
1066 + line-height: 1.4em;
1067 + border-left: 4px solid #d63638;
1068 + }
1069 +
1070 + .warning-message svg {
1071 + width: 20px;
1072 + height: 20px;
1073 + }
1074 +
1075 + .warning-message span {
1076 + color: #d63638;
1077 + }
1078 +
1079 + .warning-message .footer-message {
1080 + width: calc(100% - 20px);
1081 + }
1082 +
1083 + @media only screen and (max-width: 991px) {
1084 + .betterdocs-ai-autowrite-form-container {
1085 + left: 0;
1086 + right: 0;
1087 + transform: translate(0%, -50%);
1088 + }
1089 +
1090 + .betterdocs-ai-autowrite-form-content {
1091 + overflow-x: auto;
1092 + }
1093 + }
1094 +
1095 + @media only screen and (max-width: 740px) {
1096 +
1097 + /* .bd-close-button {
1098 + right: px;
1099 + top: 1px;
1100 + border-radius: 5px;
1101 + width: 12px;
1102 + height: 12px;
1103 + color: #ffffff;
1104 + background: #00b884;
1105 + } */
1106 + .bd-close-button {
1107 + right: 0px;
1108 + top: 0px;
1109 + width: 12px;
1110 + height: 12px;
1111 + font-size: 14px;
1112 + }
1113 +
1114 + }
1115 + </style>
1116 + <?php
1117 + }
680 1118 }