PluginProbe
AI Builder – Generate pages, blocks, images & translate with AI / 2.3.0
AI Builder – Generate pages, blocks, images & translate with AI v2.3.0
2.7.10 2.7.9 2.7.8 2.0.8 2.0.9 2.1.0 2.1.1 2.1.10 2.1.11 2.1.12 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.3.0 2.3.10 All 122 releases
ai-builder / admin / pages / agent-chat.php

agent-chat.php in AI Builder – Generate pages, blocks, images & translate with AI 2.3.0, at admin/pages/agent-chat.php

802 lines 19.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Agent Chat Admin Page
4 *
5 * Provides a chat interface for interacting with WordPress via AI
6 * and settings for managing API route access.
7 *
8 * @package AI_Builder
9 */
10
11 if (!defined('ABSPATH')) {
12 exit;
13 }
14
15 // Check authentication
16 $jwt_token = get_option('aibui_jwt_token', '');
17 if (empty($jwt_token)) {
18 echo '<div class="wrap"><div class="notice notice-error"><p>' . esc_html__('Please sign in to use the Site Copilot.', 'ai-builder') . '</p></div></div>';
19 return;
20 }
21 ?>
22
23 <div class="wrap aibui-agent-wrap">
24 <h1><?php esc_html_e('Site Copilot', 'ai-builder'); ?></h1>
25 <p class="aibui-agent-description">
26 <?php esc_html_e('Chat with an AI assistant that can interact with your WordPress site.', 'ai-builder'); ?>
27 </p>
28
29 <div class="aibui-info-notice" style="background: #f0f6fc; border-left: 4px solid #2271b1; padding: 12px 16px; margin: 20px 0; border-radius: 4px;">
30 <p style="margin: 0; font-size: 14px; line-height: 1.6;">
31 <?php
32 printf(
33 /* translators: %s: Link to documentation article */
34 esc_html__('Want to learn more about Site Copilot? %s', 'ai-builder'),
35 sprintf(
36 '<a href="%s" target="_blank" rel="noopener noreferrer" style="color: #2271b1; text-decoration: underline;">%s</a>',
37 esc_url('https://website-ai-builder.com/action-chat-manage-wordpress-with-simple-commands/'),
38 esc_html__('Follow this guide for more information about this feature.', 'ai-builder')
39 )
40 );
41 ?>
42 </p>
43 </div>
44
45 <!-- Tabs Navigation -->
46 <nav class="nav-tab-wrapper aibui-agent-tabs">
47 <a href="#chat" class="nav-tab nav-tab-active" data-tab="chat">
48 <span class="dashicons dashicons-format-chat"></span>
49 <?php esc_html_e('Chat', 'ai-builder'); ?>
50 </a>
51 <a href="#security" class="nav-tab" data-tab="security">
52 <span class="dashicons dashicons-shield"></span>
53 <?php esc_html_e('API Security', 'ai-builder'); ?>
54 </a>
55 </nav>
56
57 <!-- Tab Content: Chat -->
58 <div id="tab-chat" class="aibui-tab-content aibui-tab-active">
59 <div class="aibui-chat-container">
60 <!-- Chat Messages Area -->
61 <div class="aibui-chat-messages" id="aibui-chat-messages">
62 <div class="aibui-chat-welcome">
63 <div class="aibui-welcome-icon">
64 <span class="dashicons dashicons-admin-site-alt3"></span>
65 </div>
66 <h2><?php esc_html_e('Welcome to AI Agent Chat', 'ai-builder'); ?></h2>
67 <p><?php esc_html_e('I can help you manage your WordPress site. Try asking me to:', 'ai-builder'); ?></p>
68 <ul class="aibui-suggestions">
69 <li><button type="button" class="aibui-suggestion-btn"><?php esc_html_e('List recent posts', 'ai-builder'); ?></button></li>
70 <li><button type="button" class="aibui-suggestion-btn"><?php esc_html_e('Show all pages', 'ai-builder'); ?></button></li>
71 <li><button type="button" class="aibui-suggestion-btn"><?php esc_html_e('List categories', 'ai-builder'); ?></button></li>
72 <li><button type="button" class="aibui-suggestion-btn"><?php esc_html_e('Show pending comments', 'ai-builder'); ?></button></li>
73 </ul>
74 </div>
75 </div>
76
77 <!-- Chat Input Area -->
78 <div class="aibui-chat-input-container">
79 <form id="aibui-chat-form" class="aibui-chat-form">
80 <div class="aibui-input-wrapper">
81 <textarea
82 id="aibui-chat-input"
83 class="aibui-chat-input"
84 placeholder="<?php esc_attr_e('Type your message...', 'ai-builder'); ?>"
85 rows="1"
86 maxlength="4000"
87 ></textarea>
88 <button type="submit" class="aibui-send-btn" id="aibui-send-btn" disabled>
89 <span class="dashicons dashicons-arrow-up-alt"></span>
90 </button>
91 </div>
92 <div class="aibui-chat-meta">
93 <div class="aibui-chat-meta-left">
94 <span class="aibui-char-count"><span id="aibui-char-count">0</span>/4000</span>
95 <span class="aibui-credits-indicator" id="aibui-credits-indicator" aria-live="polite"></span>
96 </div>
97 <button type="button" class="aibui-clear-btn" id="aibui-clear-chat" title="<?php esc_attr_e('Clear conversation', 'ai-builder'); ?>">
98 <span class="dashicons dashicons-trash"></span>
99 <?php esc_html_e('Clear', 'ai-builder'); ?>
100 </button>
101 </div>
102 </form>
103 </div>
104 </div>
105 </div>
106
107 <!-- Tab Content: Security -->
108 <div id="tab-security" class="aibui-tab-content">
109 <div class="aibui-security-container">
110 <div class="aibui-security-header">
111 <div class="aibui-security-info">
112 <h2><?php esc_html_e('API Route Access Control', 'ai-builder'); ?></h2>
113 <p><?php esc_html_e('Control which WordPress REST API routes the AI agent can access. Only whitelisted routes will be available as tools.', 'ai-builder'); ?></p>
114 </div>
115 <div class="aibui-security-actions">
116 <button type="button" class="button" id="aibui-reset-routes">
117 <span class="dashicons dashicons-image-rotate"></span>
118 <?php esc_html_e('Reset to Defaults', 'ai-builder'); ?>
119 </button>
120 <button type="button" class="button button-primary" id="aibui-save-routes">
121 <span class="dashicons dashicons-saved"></span>
122 <?php esc_html_e('Save Changes', 'ai-builder'); ?>
123 </button>
124 </div>
125 </div>
126
127 <!-- Stats -->
128 <div class="aibui-security-stats" id="aibui-security-stats">
129 <div class="aibui-stat">
130 <span class="aibui-stat-value" id="stat-total">-</span>
131 <span class="aibui-stat-label"><?php esc_html_e('Total Routes', 'ai-builder'); ?></span>
132 </div>
133 <div class="aibui-stat aibui-stat-enabled">
134 <span class="aibui-stat-value" id="stat-enabled">-</span>
135 <span class="aibui-stat-label"><?php esc_html_e('Enabled', 'ai-builder'); ?></span>
136 </div>
137 <div class="aibui-stat aibui-stat-disabled">
138 <span class="aibui-stat-value" id="stat-disabled">-</span>
139 <span class="aibui-stat-label"><?php esc_html_e('Disabled', 'ai-builder'); ?></span>
140 </div>
141 <div class="aibui-stat">
142 <span class="aibui-stat-value" id="stat-namespaces">-</span>
143 <span class="aibui-stat-label"><?php esc_html_e('Namespaces', 'ai-builder'); ?></span>
144 </div>
145 </div>
146
147 <!-- Search -->
148 <div class="aibui-search-box">
149 <span class="dashicons dashicons-search"></span>
150 <input type="text" id="aibui-route-search" placeholder="<?php esc_attr_e('Search routes...', 'ai-builder'); ?>" />
151 </div>
152
153 <!-- Routes List -->
154 <div class="aibui-routes-list" id="aibui-routes-list">
155 <div class="aibui-loading">
156 <span class="spinner is-active"></span>
157 <?php esc_html_e('Loading routes...', 'ai-builder'); ?>
158 </div>
159 </div>
160 </div>
161 </div>
162 </div>
163
164 <style>
165 /* Agent Chat Styles */
166 .aibui-agent-wrap {
167 max-width: 1400px;
168 margin-right: 20px;
169 }
170
171 .aibui-agent-description {
172 color: #50575e;
173 font-size: 14px;
174 margin-bottom: 20px;
175 }
176
177 /* Tabs */
178 .aibui-agent-tabs {
179 margin-bottom: 0;
180 border-bottom: 1px solid #c3c4c7;
181 }
182
183 .aibui-agent-tabs .nav-tab {
184 display: inline-flex;
185 align-items: center;
186 gap: 6px;
187 }
188
189 .aibui-agent-tabs .nav-tab .dashicons {
190 font-size: 18px;
191 width: 18px;
192 height: 18px;
193 }
194
195 /* Tab Content */
196 .aibui-tab-content {
197 display: none;
198 background: #fff;
199 border: 1px solid #c3c4c7;
200 border-top: none;
201 padding: 0;
202 }
203
204 .aibui-tab-content.aibui-tab-active {
205 display: block;
206 }
207
208 /* Chat Container */
209 .aibui-chat-container {
210 display: flex;
211 flex-direction: column;
212 height: calc(100vh - 280px);
213 min-height: 500px;
214 }
215
216 .aibui-chat-messages {
217 flex: 1;
218 overflow-y: auto;
219 padding: 24px;
220 background: #f6f7f7;
221 }
222
223 /* Welcome Screen */
224 .aibui-chat-welcome {
225 text-align: center;
226 padding: 60px 20px;
227 }
228
229 .aibui-welcome-icon {
230 width: 80px;
231 height: 80px;
232 background: linear-gradient(135deg, #2271b1, #135e96);
233 border-radius: 50%;
234 display: flex;
235 align-items: center;
236 justify-content: center;
237 margin: 0 auto 20px;
238 }
239
240 .aibui-welcome-icon .dashicons {
241 font-size: 40px;
242 width: 40px;
243 height: 40px;
244 color: #fff;
245 }
246
247 .aibui-chat-welcome h2 {
248 font-size: 24px;
249 font-weight: 600;
250 color: #1d2327;
251 margin-bottom: 10px;
252 }
253
254 .aibui-chat-welcome p {
255 color: #50575e;
256 font-size: 15px;
257 margin-bottom: 20px;
258 }
259
260 .aibui-suggestions {
261 display: flex;
262 flex-wrap: wrap;
263 justify-content: center;
264 gap: 10px;
265 list-style: none;
266 margin: 0;
267 padding: 0;
268 }
269
270 .aibui-suggestion-btn {
271 background: #fff;
272 border: 1px solid #c3c4c7;
273 border-radius: 20px;
274 padding: 8px 16px;
275 font-size: 13px;
276 color: #2271b1;
277 cursor: pointer;
278 transition: all 0.2s;
279 }
280
281 .aibui-suggestion-btn:hover {
282 background: #2271b1;
283 color: #fff;
284 border-color: #2271b1;
285 }
286
287 /* Chat Messages */
288 .aibui-message {
289 max-width: 80%;
290 margin-bottom: 16px;
291 animation: fadeIn 0.3s ease;
292 }
293
294 @keyframes fadeIn {
295 from { opacity: 0; transform: translateY(10px); }
296 to { opacity: 1; transform: translateY(0); }
297 }
298
299 .aibui-message-user {
300 margin-left: auto;
301 }
302
303 .aibui-message-assistant {
304 margin-right: auto;
305 }
306
307 .aibui-message-content {
308 padding: 12px 16px;
309 border-radius: 16px;
310 font-size: 14px;
311 line-height: 1.5;
312 }
313
314 .aibui-message-user .aibui-message-content {
315 background: #2271b1;
316 color: #fff;
317 border-bottom-right-radius: 4px;
318 }
319
320 .aibui-message-assistant .aibui-message-content {
321 background: #fff;
322 color: #1d2327;
323 border: 1px solid #e0e0e0;
324 border-bottom-left-radius: 4px;
325 }
326
327 .aibui-message-content pre {
328 background: #f0f0f1;
329 padding: 12px;
330 border-radius: 8px;
331 overflow-x: auto;
332 font-size: 13px;
333 margin: 10px 0;
334 }
335
336 .aibui-message-content code {
337 background: rgba(0,0,0,0.1);
338 padding: 2px 6px;
339 border-radius: 4px;
340 font-size: 13px;
341 }
342
343 /* Tool Execution Indicator */
344 .aibui-tool-execution {
345 display: flex;
346 align-items: center;
347 gap: 8px;
348 padding: 8px 12px;
349 background: #f0f6fc;
350 border: 1px solid #c5d9ed;
351 border-radius: 8px;
352 font-size: 12px;
353 color: #2271b1;
354 margin-bottom: 8px;
355 }
356
357 .aibui-tool-execution .dashicons {
358 animation: spin 1s linear infinite;
359 }
360
361 .aibui-tool-execution--completed .dashicons {
362 animation: none;
363 color: #00a32a;
364 }
365
366 .aibui-tool-execution--error {
367 background: #fcf0f1;
368 border-color: #d63638;
369 color: #d63638;
370 }
371
372 .aibui-tool-execution--error .dashicons {
373 animation: none;
374 color: #d63638;
375 }
376
377 @keyframes spin {
378 from { transform: rotate(0deg); }
379 to { transform: rotate(360deg); }
380 }
381
382 /* Loading Message */
383 .aibui-message-loading {
384 display: flex;
385 gap: 6px;
386 padding: 16px;
387 }
388
389 .aibui-loading-dot {
390 width: 8px;
391 height: 8px;
392 background: #c3c4c7;
393 border-radius: 50%;
394 animation: bounce 1.4s infinite ease-in-out both;
395 }
396
397 .aibui-loading-dot:nth-child(1) { animation-delay: -0.32s; }
398 .aibui-loading-dot:nth-child(2) { animation-delay: -0.16s; }
399
400 @keyframes bounce {
401 0%, 80%, 100% { transform: scale(0); }
402 40% { transform: scale(1); }
403 }
404
405 /* Chat Input */
406 .aibui-chat-input-container {
407 padding: 16px 24px;
408 background: #fff;
409 border-top: 1px solid #e0e0e0;
410 }
411
412 .aibui-chat-form {
413 max-width: 900px;
414 margin: 0 auto;
415 }
416
417 .aibui-input-wrapper {
418 display: flex;
419 align-items: flex-end;
420 gap: 12px;
421 background: #f6f7f7;
422 border: 1px solid #c3c4c7;
423 border-radius: 24px;
424 padding: 8px 8px 8px 16px;
425 transition: border-color 0.2s;
426 }
427
428 .aibui-input-wrapper:focus-within {
429 border-color: #2271b1;
430 box-shadow: 0 0 0 1px #2271b1;
431 }
432
433 .aibui-chat-input {
434 flex: 1;
435 border: none;
436 background: transparent;
437 font-size: 14px;
438 line-height: 1.5;
439 resize: none;
440 max-height: 150px;
441 outline: none;
442 }
443
444 .aibui-send-btn {
445 width: 36px;
446 height: 36px;
447 border-radius: 50%;
448 background: #2271b1;
449 border: none;
450 color: #fff;
451 cursor: pointer;
452 display: flex;
453 align-items: center;
454 justify-content: center;
455 transition: all 0.2s;
456 flex-shrink: 0;
457 }
458
459 .aibui-send-btn:disabled {
460 background: #c3c4c7;
461 cursor: not-allowed;
462 }
463
464 .aibui-send-btn:not(:disabled):hover {
465 background: #135e96;
466 transform: scale(1.05);
467 }
468
469 .aibui-chat-meta {
470 display: flex;
471 justify-content: space-between;
472 align-items: center;
473 margin-top: 8px;
474 padding: 0 8px;
475 }
476
477 .aibui-chat-meta-left {
478 display: flex;
479 align-items: center;
480 gap: 12px;
481 }
482
483 .aibui-char-count {
484 font-size: 12px;
485 color: #787c82;
486 }
487
488 .aibui-credits-indicator {
489 font-size: 12px;
490 color: #047857;
491 }
492
493 .aibui-clear-btn {
494 display: inline-flex;
495 align-items: center;
496 gap: 4px;
497 background: transparent;
498 border: none;
499 color: #787c82;
500 font-size: 12px;
501 cursor: pointer;
502 padding: 4px 8px;
503 border-radius: 4px;
504 transition: all 0.2s;
505 }
506
507 .aibui-clear-btn:hover {
508 background: #f0f0f1;
509 color: #d63638;
510 }
511
512 /* Security Tab */
513 .aibui-security-container {
514 padding: 24px;
515 }
516
517 .aibui-security-header {
518 display: flex;
519 justify-content: space-between;
520 align-items: flex-start;
521 margin-bottom: 24px;
522 flex-wrap: wrap;
523 gap: 16px;
524 }
525
526 .aibui-security-info h2 {
527 font-size: 18px;
528 font-weight: 600;
529 margin: 0 0 8px;
530 }
531
532 .aibui-security-info p {
533 color: #50575e;
534 margin: 0;
535 }
536
537 .aibui-security-actions {
538 display: flex;
539 gap: 8px;
540 }
541
542 .aibui-security-actions .button {
543 display: inline-flex;
544 align-items: center;
545 gap: 4px;
546 }
547
548 /* Stats */
549 .aibui-security-stats {
550 display: flex;
551 gap: 16px;
552 margin-bottom: 24px;
553 flex-wrap: wrap;
554 }
555
556 .aibui-stat {
557 background: #f6f7f7;
558 border-radius: 8px;
559 padding: 16px 24px;
560 text-align: center;
561 min-width: 120px;
562 }
563
564 .aibui-stat-value {
565 display: block;
566 font-size: 28px;
567 font-weight: 600;
568 color: #1d2327;
569 }
570
571 .aibui-stat-label {
572 font-size: 12px;
573 color: #50575e;
574 text-transform: uppercase;
575 letter-spacing: 0.5px;
576 }
577
578 .aibui-stat-enabled .aibui-stat-value {
579 color: #00a32a;
580 }
581
582 .aibui-stat-disabled .aibui-stat-value {
583 color: #d63638;
584 }
585
586 /* Search */
587 .aibui-search-box {
588 position: relative;
589 margin-bottom: 20px;
590 }
591
592 .aibui-search-box .dashicons {
593 position: absolute;
594 left: 12px;
595 top: 50%;
596 transform: translateY(-50%);
597 color: #787c82;
598 }
599
600 .aibui-search-box input {
601 width: 100%;
602 max-width: 400px;
603 padding: 10px 12px 10px 38px;
604 border: 1px solid #c3c4c7;
605 border-radius: 8px;
606 font-size: 14px;
607 }
608
609 /* Routes List */
610 .aibui-routes-list {
611 border: 1px solid #c3c4c7;
612 border-radius: 8px;
613 background: #fff;
614 max-height: 500px;
615 overflow-y: auto;
616 }
617
618 .aibui-loading {
619 display: flex;
620 align-items: center;
621 justify-content: center;
622 gap: 8px;
623 padding: 40px;
624 color: #50575e;
625 }
626
627 /* Namespace Group */
628 .aibui-namespace-group {
629 border-bottom: 1px solid #e0e0e0;
630 }
631
632 .aibui-namespace-group:last-child {
633 border-bottom: none;
634 }
635
636 .aibui-namespace-header {
637 display: flex;
638 align-items: center;
639 justify-content: space-between;
640 padding: 12px 16px;
641 background: #f6f7f7;
642 cursor: pointer;
643 user-select: none;
644 }
645
646 .aibui-namespace-header:hover {
647 background: #f0f0f1;
648 }
649
650 .aibui-namespace-name {
651 display: flex;
652 align-items: baseline;
653 gap: 8px;
654 }
655
656 .aibui-namespace-name .dashicons {
657 transition: transform 0.2s;
658 }
659
660 .aibui-namespace-title {
661 font-weight: 600;
662 font-size: 14px;
663 }
664
665 .aibui-namespace-description {
666 font-size: 12px;
667 color: #6b7280;
668 }
669
670 .aibui-namespace-group.collapsed .aibui-namespace-name .dashicons {
671 transform: rotate(-90deg);
672 }
673
674 .aibui-namespace-count {
675 font-size: 12px;
676 color: #50575e;
677 background: #e0e0e0;
678 padding: 2px 8px;
679 border-radius: 10px;
680 }
681
682 .aibui-namespace-routes {
683 display: block;
684 }
685
686 .aibui-namespace-group.collapsed .aibui-namespace-routes {
687 display: none;
688 }
689
690 /* Route Item */
691 .aibui-route-item {
692 display: flex;
693 align-items: center;
694 gap: 12px;
695 padding: 10px 16px 10px 32px;
696 border-top: 1px solid #f0f0f1;
697 transition: background 0.2s;
698 }
699
700 .aibui-route-item:hover {
701 background: #f6f7f7;
702 }
703
704 .aibui-route-item.aibui-route-disabled {
705 opacity: 0.6;
706 }
707
708 .aibui-route-checkbox {
709 margin-right: 12px;
710 }
711
712 .aibui-route-method {
713 font-size: 11px;
714 font-weight: 600;
715 padding: 2px 6px;
716 border-radius: 4px;
717 margin-right: 10px;
718 min-width: 50px;
719 text-align: center;
720 }
721
722 .aibui-route-method-get { background: #d1fae5; color: #065f46; }
723 .aibui-route-method-post { background: #dbeafe; color: #1e40af; }
724 .aibui-route-method-put { background: #fef3c7; color: #92400e; }
725 .aibui-route-method-patch { background: #e9d5ff; color: #6b21a8; }
726 .aibui-route-method-delete { background: #fee2e2; color: #991b1b; }
727
728 .aibui-route-path {
729 flex: 1;
730 font-family: monospace;
731 font-size: 13px;
732 color: #1d2327;
733 word-break: break-all;
734 }
735
736 .aibui-route-main {
737 flex: 1;
738 display: flex;
739 flex-direction: column;
740 gap: 2px;
741 }
742
743 .aibui-route-description {
744 font-size: 11px;
745 color: #6b7280;
746 }
747
748 .aibui-route-doc-link {
749 font-size: 11px;
750 padding: 4px 8px;
751 border-radius: 4px;
752 border: 1px solid #d0d4d9;
753 background: #ffffff;
754 color: #1d4ed8;
755 text-decoration: none;
756 white-space: nowrap;
757 transition: all 0.15s ease;
758 }
759
760 .aibui-route-doc-link:hover {
761 background: #eff6ff;
762 border-color: #93c5fd;
763 color: #1d4ed8;
764 }
765
766 .aibui-route-locked {
767 color: #787c82;
768 margin-left: 8px;
769 }
770
771 /* Toast Notification */
772 .aibui-toast {
773 position: fixed;
774 bottom: 40px;
775 right: 40px;
776 background: #1d2327;
777 color: #fff;
778 padding: 12px 20px;
779 border-radius: 8px;
780 font-size: 14px;
781 z-index: 100000;
782 animation: slideIn 0.3s ease;
783 display: flex;
784 align-items: center;
785 gap: 8px;
786 }
787
788 .aibui-toast.aibui-toast-success {
789 background: #00a32a;
790 }
791
792 .aibui-toast.aibui-toast-error {
793 background: #d63638;
794 }
795
796 @keyframes slideIn {
797 from { transform: translateY(20px); opacity: 0; }
798 to { transform: translateY(0); opacity: 1; }
799 }
800 </style>
801
802