Files
html/top-ia/_plugin-intents-loader.php

49 lines
1.9 KiB
PHP

<?php
// Plugin runtime loader — autodiscovery /opt/weval-plugins/*/plugin.json
// Called from wevia_opus_intents() via wevia_plugin_intents($msg)
function wevia_plugin_intents($msg) {
static $plugins_cache = null;
static $cache_ts = 0;
// Reload cache every 60s (lightweight discovery)
if ($plugins_cache === null || (time() - $cache_ts) > 60) {
$plugins_cache = [];
$cache_ts = time();
$store = "/opt/weval-plugins";
if (is_dir($store)) {
foreach (scandir($store) as $d) {
if ($d === '.' || $d === '..') continue;
$meta = "$store/$d/plugin.json";
if (!file_exists($meta)) continue;
$p = json_decode(@file_get_contents($meta), true);
if (!$p || empty($p['intents'])) continue;
foreach ($p['intents'] as $intent) {
if (empty($intent['name']) || empty($intent['trigger_regex']) || empty($intent['script'])) continue;
$script_path = "$store/$d/" . $intent['script'];
if (!file_exists($script_path) || !is_executable($script_path)) continue;
$plugins_cache[] = [
'name' => $intent['name'],
'regex' => $intent['trigger_regex'],
'script' => $script_path,
'plugin' => $p['name']
];
}
}
}
}
$m = mb_strtolower(trim($msg));
foreach ($plugins_cache as $p) {
if (@preg_match('/' . $p['regex'] . '/iu', $m)) {
$out = trim(@shell_exec(escapeshellcmd($p['script']) . ' 2>&1'));
return [
"provider" => "plugin-store",
"content" => "PLUGIN [{$p['plugin']}::{$p['name']}]:\n" . $out,
"tool" => "plugin-store",
"plugin" => $p['plugin']
];
}
}
return null;
}