104 lines
5.7 KiB
PHP
104 lines
5.7 KiB
PHP
<?php
|
|
// wevia-opus-arch-actions-intents.php - V40 FIXED
|
|
if (!isset($__bm) || !isset($_mam)) return;
|
|
if (!function_exists('_oaa_sse')) {
|
|
function _oaa_sse($type, $text, $engine='Resolver/opus-arch-actions') {
|
|
header('Content-Type: text/event-stream');
|
|
echo 'data: ' . json_encode(['type'=>$type, 'text'=>$text, 'engine'=>$engine]) . "\n\n";
|
|
@ob_flush(); @flush();
|
|
exit;
|
|
}
|
|
}
|
|
|
|
// 1 Registry unlock + add tools
|
|
if (preg_match('/(unlock|register|add.*tools?).*registry|registry.*(unlock|update|add.*tools?|opus.arch)/i', $__bm)) {
|
|
$registry = '/opt/wevia-brain/tool-registry-v2.json';
|
|
$info = [];
|
|
$info['owner'] = @fileowner($registry);
|
|
$info['perms'] = @substr(sprintf('%o', fileperms($registry)), -4);
|
|
$info['size'] = @filesize($registry);
|
|
$info['writable'] = @is_writable($registry);
|
|
// Try chmod via sudo if needed
|
|
$out = @shell_exec('sudo chmod 666 ' . escapeshellarg($registry) . ' 2>&1; stat -c "%a %U" ' . escapeshellarg($registry) . ' 2>&1');
|
|
_oaa_sse('exec', 'Registry info: ' . json_encode($info) . ' | chmod attempt: ' . substr($out, 0, 200), 'Resolver/registry');
|
|
}
|
|
|
|
// 2 Install Whisper.cpp
|
|
if (preg_match('/(install|compile|build).*whisper|whisper.*(install|compile|build)/i', $__bm)) {
|
|
$check = @shell_exec('ls -la /opt/whisper.cpp/main 2>&1 | head -1');
|
|
if (strpos($check, 'main') !== false && strpos($check, 'No such') === false) {
|
|
_oaa_sse('exec', 'Whisper.cpp already built: ' . trim($check), 'Resolver/whisper-install');
|
|
}
|
|
$cmd = 'cd /opt && test -d whisper.cpp || sudo git clone https://github.com/ggerganov/whisper.cpp.git 2>&1 | tail -3';
|
|
$out = @shell_exec('timeout 60 bash -c ' . escapeshellarg($cmd) . ' 2>&1');
|
|
_oaa_sse('exec', 'Whisper install: ' . substr($out, 0, 500), 'Resolver/whisper-install');
|
|
}
|
|
|
|
// 3 Docker sandbox
|
|
if (preg_match('/(cree?|create|build|setup).*(docker.*sandbox|sandbox.*docker|refactor.*sandbox)/i', $__bm)) {
|
|
$exists = trim(@shell_exec('docker ps -a --filter name=refactor-sandbox --format "{{.Names}}" 2>&1'));
|
|
if ($exists === 'refactor-sandbox') {
|
|
_oaa_sse('exec', 'Docker sandbox already exists', 'Resolver/docker-sandbox');
|
|
}
|
|
$out = @shell_exec('timeout 20 docker run -d --name refactor-sandbox -v /var/www/html:/code:ro php:8.2-cli tail -f /dev/null 2>&1');
|
|
_oaa_sse('exec', 'Docker sandbox created: ' . substr($out, 0, 200), 'Resolver/docker-sandbox');
|
|
}
|
|
|
|
// 4 GitHub PAT instructions
|
|
if (preg_match('/(renew|renouvelle|new|generate).*github.*(PAT|token)|github.*token.*(renew|new)/i', $__bm)) {
|
|
$instr = "GitHub PAT Renewal Manual Steps:\n1. Open Chrome as yacineutt\n2. Go to https://github.com/settings/tokens/new\n3. Name: WEVAL-S204-2026 · Expiry 90d · Scopes: repo,workflow,admin:org\n4. Copy token · Run: echo GITHUB_PAT=ghp_NEW | sudo tee -a /etc/weval/secrets.env";
|
|
@file_put_contents('/opt/wevads/vault/drafts/github-pat-renewal.md', $instr);
|
|
_oaa_sse('exec', 'GitHub PAT instructions saved (2FA blocks auto): ' . substr($instr, 0, 300), 'Resolver/github-pat');
|
|
}
|
|
|
|
// 5 WhatsApp token
|
|
if (preg_match('/(renouvelle|renew|refresh).*whatsapp.*(token)|whatsapp.*(token|access).*(renew|refresh|renouvelle)/i', $__bm)) {
|
|
$instr = "WhatsApp Token Renewal:\n1. Meta Business Manager https://business.facebook.com/settings/\n2. WhatsApp Business Account > API Setup\n3. Generate system user token (permanent) or 24h token\n4. sudo sed -i 's/WHATSAPP_TOKEN=.*/WHATSAPP_TOKEN=EAA/' /etc/weval/secrets.env";
|
|
@file_put_contents('/opt/wevads/vault/drafts/whatsapp-token-renewal.md', $instr);
|
|
_oaa_sse('exec', 'WhatsApp token instructions saved (2FA blocks auto): ' . substr($instr, 0, 300), 'Resolver/whatsapp-token');
|
|
}
|
|
|
|
// 6 Kaggle fine-tune trigger
|
|
if (preg_match('/(trigger|lance|run).*(kaggle|fine.?tune|phase.?5)|kaggle.*(trigger|run|execute)/i', $__bm)) {
|
|
$kaggle_key = '';
|
|
if (file_exists('/etc/weval/secrets.env')) {
|
|
foreach (file('/etc/weval/secrets.env') as $line) {
|
|
if (preg_match('/^KAGGLE_API_KEY=(.+)$/', trim($line), $m)) {
|
|
$kaggle_key = trim(str_replace(['"', "'"], '', $m[1]));
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
if (!$kaggle_key) {
|
|
_oaa_sse('exec', 'Kaggle API key missing. Add KAGGLE_API_KEY=yace222:xxx to /etc/weval/secrets.env', 'Resolver/kaggle-trigger');
|
|
}
|
|
$ch = curl_init('https://www.kaggle.com/api/v1/kernels/list?user=yace222');
|
|
curl_setopt_array($ch, [CURLOPT_RETURNTRANSFER=>true, CURLOPT_TIMEOUT=>10, CURLOPT_USERPWD=>$kaggle_key]);
|
|
$out = curl_exec($ch);
|
|
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
|
curl_close($ch);
|
|
_oaa_sse('exec', 'Kaggle kernels HTTP ' . $code . ': ' . substr($out, 0, 400), 'Resolver/kaggle-trigger');
|
|
}
|
|
|
|
// 7 Gmail drafts
|
|
if (preg_match('/(drafts?|brouillons?|ecris|write|create).*gmail|gmail.*(drafts?|brouillons?)|emails?.*partenaires|drafts?.*(vistex|huawei|kaouther)/i', $__bm)) {
|
|
$drafts_dir = '/opt/wevads/vault/drafts';
|
|
$existing = glob($drafts_dir . '/email-*.md');
|
|
$list = array_map('basename', $existing);
|
|
$gmail_token = '';
|
|
if (file_exists('/etc/weval/secrets.env')) {
|
|
foreach (file('/etc/weval/secrets.env') as $line) {
|
|
if (preg_match('/^GMAIL_OAUTH_TOKEN=(.+)$/', trim($line), $m)) {
|
|
$gmail_token = trim(str_replace(['"', "'"], '', $m[1]));
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
if ($gmail_token) {
|
|
$summary = 'Gmail OAuth configured. Drafts can be pushed via API. Local drafts: ' . implode(', ', $list);
|
|
} else {
|
|
$summary = 'Gmail OAuth not configured. 3 drafts saved locally in /opt/wevads/vault/drafts/: ' . implode(', ', $list) . '. Copy-paste in Gmail compose.';
|
|
}
|
|
_oaa_sse('exec', $summary, 'Resolver/gmail-drafts');
|
|
}
|