-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfoopilot.php
More file actions
84 lines (68 loc) · 2.84 KB
/
foopilot.php
File metadata and controls
84 lines (68 loc) · 2.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
/**
* Plugin Name: FooPilot - WP Admin Vibe Agent
* Description: ChatGPT-like agent inside wp-admin with streaming, multiple LLM providers, MCP translators & pluggable tools.
* Version: 0.0.1
* Author: Your Name
*/
if ( ! defined( 'ABSPATH' ) ) exit;
define('FOOPILOT_PATH', plugin_dir_path(__FILE__));
define('FOOPILOT_URL', plugin_dir_url(__FILE__));
// Start autoloader.
require_once FOOPILOT_PATH . 'vendor/autoload.php';
/**
* Boot plugin.
*/
add_action('plugins_loaded', function () {
$registry = new \FooPilot\Registry\ToolRegistry();
(new \FooPilot\Tools\UpdatePostsFindReplace($registry))->register();
do_action('foopilot_register_tools', $registry);
\FooPilot\Bootstrap\Translators::run($registry);
$memory = new \FooPilot\Memory\OptionsMemoryStore();
// Provider factory (OpenAI default)
$provider = \FooPilot\LLM\ProviderFactory::make_from_options();
$agent = new \FooPilot\Agent\Agent($provider, $registry, $memory);
new \FooPilot\HTTP\RestController($agent);
new \FooPilot\Admin\Settings();
// Floating panel assets on every admin page
add_action('admin_enqueue_scripts', function () {
$asset_path = FOOPILOT_PATH . 'assets/panel.asset.php';
$asset = file_exists($asset_path)
? require $asset_path
: [
'dependencies' => ['wp-api-fetch', 'wp-element'],
'version' => '0.4.0',
];
wp_enqueue_style('foopilot-panel', FOOPILOT_URL . 'assets/panel.css', [], $asset['version']);
if (is_rtl() && file_exists(FOOPILOT_PATH . 'assets/panel-rtl.css')) {
wp_enqueue_style('foopilot-panel-rtl', FOOPILOT_URL . 'assets/panel-rtl.css', ['foopilot-panel'], $asset['version']);
}
wp_enqueue_script('foopilot-panel', FOOPILOT_URL . 'assets/panel.js', $asset['dependencies'], $asset['version'], true);
$stream_nonce = wp_create_nonce('wp_rest');
wp_localize_script('foopilot-panel', 'FOOPILOT_PANEL', [
'restBase' => esc_url_raw( rest_url('foopilot/v1') ),
'nonce' => wp_create_nonce('foopilot'),
'streamNonce' => $stream_nonce,
'userId' => get_current_user_id(),
'defaultWidth' => 420,
'historyLimit' => 20,
'mockEnabled' => false,
]);
});
// Admin bar toggle
add_action('admin_bar_menu', function ($wp_admin_bar) {
if (!current_user_can('manage_options')) {
return;
}
$wp_admin_bar->add_node([
'id' => 'foopilot-toggle',
'parent' => 'top-secondary',
'title' => 'Foopilot',
'href' => '#',
'meta' => [
'class' => 'foopilot-adminbar-toggle',
'title' => 'Toggle Foopilot panel',
],
]);
}, 100);
});