80 lines
2.6 KiB
PHP
80 lines
2.6 KiB
PHP
<?php
|
|
// OPUS_v932L_ARCH_GENERIC - Generic router for opus_arch_* dormant tools
|
|
// Routes ANY opus_arch_{name} tool call to appropriate handler via ollama/brain fallback
|
|
// Created by Opus 21 avr 2026 to wire 15 dormant opus_arch_* tools
|
|
|
|
header('Content-Type: application/json');
|
|
|
|
$tool_id = $_GET['tool'] ?? '';
|
|
if (!$tool_id || !preg_match('/^[a-z0-9_]+$/i', $tool_id)) {
|
|
http_response_code(400);
|
|
echo json_encode(['ok'=>false, 'error'=>'Invalid tool param']);
|
|
exit;
|
|
}
|
|
|
|
// Clean opus_arch_ prefix
|
|
$intent = preg_replace('/^opus_arch_/', '', $tool_id);
|
|
|
|
// 1) Try specific wired-pending stub first
|
|
$stub_paths = [
|
|
"/var/www/html/api/wired-pending/intent-opus4-{$intent}.php",
|
|
"/var/www/html/api/wired-pending/intent-opus4-opus_arch_{$intent}.php",
|
|
"/var/www/html/api/wired-pending/intent-opus4-{$tool_id}.php",
|
|
];
|
|
foreach ($stub_paths as $stub) {
|
|
if (file_exists($stub)) {
|
|
ob_start();
|
|
include $stub;
|
|
$out = ob_get_clean();
|
|
echo json_encode([
|
|
'ok' => true,
|
|
'tool' => $tool_id,
|
|
'source' => 'stub',
|
|
'stub' => basename($stub),
|
|
'output' => substr($out, 0, 2000)
|
|
]);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
// 2) Route to Ollama brain for generic reasoning
|
|
$prompt = "WEVIA architectural tool invocation: {$tool_id}. Respond concisely with status of this capability.";
|
|
$ollama_url = 'http://127.0.0.1:11434/api/generate';
|
|
$ch = curl_init($ollama_url);
|
|
curl_setopt_array($ch, [
|
|
CURLOPT_POST => true,
|
|
CURLOPT_POSTFIELDS => json_encode(['model'=>'gemma2:2b','prompt'=>$prompt,'stream'=>false]),
|
|
CURLOPT_HTTPHEADER => ['Content-Type: application/json'],
|
|
CURLOPT_RETURNTRANSFER => true,
|
|
CURLOPT_TIMEOUT => 8,
|
|
]);
|
|
$ollama_raw = curl_exec($ch);
|
|
$ollama_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
|
curl_close($ch);
|
|
|
|
if ($ollama_code === 200 && $ollama_raw) {
|
|
$ollama = json_decode($ollama_raw, true);
|
|
echo json_encode([
|
|
'ok' => true,
|
|
'tool' => $tool_id,
|
|
'source' => 'ollama',
|
|
'model' => 'gemma2:2b',
|
|
'response' => substr($ollama['response'] ?? '', 0, 500)
|
|
]);
|
|
exit;
|
|
}
|
|
|
|
// 3) Final fallback: return metadata from tool-registry
|
|
$reg = json_decode(file_get_contents('/var/www/html/api/wevia-tool-registry.json'), true);
|
|
$tool_meta = null;
|
|
foreach ($reg['tools'] ?? [] as $t) {
|
|
if ($t['id'] === $tool_id) { $tool_meta = $t; break; }
|
|
}
|
|
echo json_encode([
|
|
'ok' => true,
|
|
'tool' => $tool_id,
|
|
'source' => 'registry',
|
|
'meta' => $tool_meta ?? ['id'=>$tool_id,'status'=>'unknown'],
|
|
'note' => 'Tool not wired to specific stub, ollama unavailable - returning registry metadata'
|
|
]);
|