52 lines
2.0 KiB
PHP
52 lines
2.0 KiB
PHP
<?php
|
|
header("Content-Type: application/json");
|
|
header("Access-Control-Allow-Origin: *");
|
|
|
|
$q = $_GET["q"] ?? $_POST["q"] ?? "";
|
|
$limit = min((int)($_GET["limit"] ?? 10), 50);
|
|
|
|
if (!$q) {
|
|
// Return stats
|
|
$ch = curl_init("http://127.0.0.1:6333/collections/weval_skills");
|
|
curl_setopt_array($ch, [CURLOPT_RETURNTRANSFER=>true, CURLOPT_TIMEOUT=>5]);
|
|
$col = json_decode(curl_exec($ch), true); curl_close($ch);
|
|
echo json_encode(["ok"=>true, "collection"=>"weval_skills", "points"=>$col["result"]["points_count"]??0, "status"=>$col["result"]["status"]??"unknown"]);
|
|
exit;
|
|
}
|
|
|
|
// Search by scrolling and filtering by payload text match
|
|
$ch = curl_init("http://127.0.0.1:6333/collections/weval_skills/points/scroll");
|
|
curl_setopt_array($ch, [
|
|
CURLOPT_POST=>true, CURLOPT_RETURNTRANSFER=>true, CURLOPT_TIMEOUT=>10,
|
|
CURLOPT_HTTPHEADER=>["Content-Type: application/json"],
|
|
CURLOPT_POSTFIELDS=>json_encode([
|
|
"limit" => 500,
|
|
"with_payload" => true,
|
|
"filter" => ["should" => [
|
|
["key"=>"name", "match"=>["text"=>$q]],
|
|
["key"=>"desc", "match"=>["text"=>$q]],
|
|
]]
|
|
])
|
|
]);
|
|
$resp = json_decode(curl_exec($ch), true); curl_close($ch);
|
|
|
|
$results = [];
|
|
foreach (($resp["result"]["points"] ?? []) as $p) {
|
|
$pay = $p["payload"] ?? [];
|
|
if (stripos($pay["name"]??"", $q) !== false || stripos($pay["desc"]??"", $q) !== false) {
|
|
$results[] = $pay;
|
|
if (count($results) >= $limit) break;
|
|
}
|
|
}
|
|
|
|
// Fallback: grep /opt/ for matching SKILL.md
|
|
if (count($results) < 3) {
|
|
$grep = trim(shell_exec("grep -rl \"" . escapeshellarg($q) . "\" /opt/*/skills/*/SKILL.md /opt/antigravity-awesome-skills/*/SKILL.md 2>/dev/null | head -5"));
|
|
foreach (explode("\n", $grep) as $f) {
|
|
if (!$f) continue;
|
|
$results[] = ["name"=>basename(dirname($f)), "path"=>str_replace("/opt/","", $f), "source"=>"grep"];
|
|
}
|
|
}
|
|
|
|
echo json_encode(["ok"=>true, "query"=>$q, "results"=>array_slice($results, 0, $limit), "count"=>count($results)]);
|