// xAI Platform page: thin client over /ai/xai/platform/* (all limits server side). (function () { "use strict"; var $ = function (id) { return document.getElementById(id); }; var out = $("xp-out"), err = $("xp-error"); // One example body per route. Ids are placeholders to replace. var templates = { "account": { action: "api_key" }, "files": { action: "list", limit: 10 }, "collections": { action: "list", limit: 10 }, "search": { query: "What were the key revenue drivers?", collection_ids: ["collection_ID"], retrieval_mode: "hybrid" }, "voices": { action: "list" }, "tts": { text: "Hello from Grok.", language: "en", voice_id: "eve", confirm: false }, "stt": { url: "https://example.com/audio.mp3", language: "en", confirm: false }, "realtime/secret": { expires_seconds: 300, confirm: false }, "realtime/session": { text: "Say hello in one sentence.", voice: "eve", turn_detection: "server_vad", confirm: false }, "realtime/session/preview": { voice: "eve", instructions: "You are a helpful agent.", turn_detection: "server_vad", output_speed: 1.0 }, "realtime/phone-numbers": { action: "list" }, "realtime/calls": { action: "hangup", call_id: "CALL_ID", confirm: false }, "webhook/verify": { secret: "whsec_...", webhook_id: "msg_1", webhook_timestamp: "1750000000", webhook_signature: "v1,...", body: "{}" }, "keys": { action: "validate" }, "billing": { action: "prepaid_balance", team_id: "TEAM_UUID" }, "audit": { team_id: "TEAM_UUID", page_size: 20 } }; function show(j, ok) { if (ok) { err.textContent = ""; out.textContent = JSON.stringify(j, null, 2); } else { err.textContent = j.message || "Request failed"; out.textContent = ""; } } function send() { var body; try { body = JSON.parse($("xp-body").value || "{}"); } catch (e) { err.textContent = "Body is not valid JSON"; return; } err.textContent = ""; out.textContent = "..."; fetch("/ai/xai/platform/" + $("xp-route").value, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(body) }).then(function (res) { return res.text().then(function (t) { var j; try { j = JSON.parse(t); } catch (e) { j = { message: t }; } show(j, res.ok); }); }).catch(function (e) { err.textContent = String(e); out.textContent = ""; }); } function fill() { $("xp-body").value = JSON.stringify(templates[$("xp-route").value], null, 1); } fetch("/ai/xai/platform/status").then(function (r) { return r.json(); }).then(function (s) { var parts = []; parts.push(s.api_key_configured ? "XAI_API_KEY found." : "No XAI_API_KEY: inference-host routes answer 503."); parts.push(s.management_key_configured ? "XAI_MANAGEMENT_KEY found." : "No XAI_MANAGEMENT_KEY: collections and management routes answer 503."); $("xp-config").textContent = parts.join(" "); }); $("xp-route").onchange = fill; $("xp-send").onclick = send; fill(); })();