Files
html/api/ambre-early-doc-gen.php
opus 5060064915
Some checks failed
WEVAL NonReg / nonreg (push) Has been cancelled
auto-sync via WEVIA git_sync_all intent 2026-04-21T15:28:07+02:00
2026-04-21 15:28:07 +02:00

57 lines
2.1 KiB
PHP

<?php
/**
* ambre-early-doc-gen.php · AMBRE · priority intercept for file generation commands
* Included at top of master-api.php via @include.
* Detects: "Genere un PDF/Word/Excel/PPT sur: X" / "Genere un document" / "Genere une presentation"
* Action: call ambre-gen-pipeline → return response with file URL
*/
if (!isset($_mam) || empty($_mam)) return;
$__ad_msg = trim($_mam);
$__ad_lc = mb_strtolower($__ad_msg);
// Detection pattern: Genere + type + topic
if (!preg_match("/g[eé]n[eé]re?\s+(?:un|une|des|le|la)?\s*(pdf|pptx?|powerpoint|docx?|word|excel|xlsx?|pr[eé]sentation|presentation|document|tableau)[^:]*(?::|sur)\s*(.+)$/iu", $__ad_msg, $__ad_m)) return;
$__ad_raw_type = mb_strtolower($__ad_m[1]);
$__ad_topic = trim($__ad_m[2]);
$__ad_type_map = [
"pdf" => "pdf",
"pptx" => "pptx",
"ppt" => "pptx",
"powerpoint" => "pptx",
"presentation" => "pptx",
"présentation" => "pptx",
"docx" => "docx",
"doc" => "docx",
"word" => "docx",
"document" => "docx",
"xlsx" => "xlsx",
"excel" => "xlsx",
"tableau" => "xlsx",
];
$__ad_type = $__ad_type_map[$__ad_raw_type] ?? "pdf";
// XLSX not supported by pandoc directly → fallback to docx with table
if ($__ad_type === "xlsx") $__ad_type = "docx";
$__ad_url = "http://127.0.0.1/api/ambre-gen-pipeline.php?type=" . urlencode($__ad_type) . "&topic=" . urlencode($__ad_topic);
$__ad_ctx = stream_context_create(["http"=>["timeout"=>60, "header"=>"Host: weval-consulting.com\r\n"]]);
$__ad_out = @file_get_contents($__ad_url, false, $__ad_ctx);
if ($__ad_out && strlen($__ad_out) > 20) {
header("Content-Type: application/json");
echo json_encode([
"response" => $__ad_out,
"executed" => true,
"provider" => "ambre-doc-gen",
"intent" => "file_generation_real",
"type" => $__ad_type,
"topic" => $__ad_topic,
"source" => "ambre-early-doc-gen-v1",
], JSON_UNESCAPED_UNICODE);
exit;
}
// If pipeline failed, fall through to normal chat flow (no regression)