mirror of
https://18126008609:longquanjian123@gitee.com/feigong123/aurask.git
synced 2026-04-19 16:40:33 +00:00
56 lines
2.1 KiB
JavaScript
56 lines
2.1 KiB
JavaScript
const apiBaseInput = document.querySelector("#apiBase");
|
|
const apiKeyInput = document.querySelector("#apiKey");
|
|
|
|
function apiBase() {
|
|
return apiBaseInput.value.replace(/\/$/, "");
|
|
}
|
|
|
|
async function request(path, options = {}) {
|
|
const headers = new Headers(options.headers || {});
|
|
headers.set("Content-Type", "application/json");
|
|
const apiKey = apiKeyInput.value.trim();
|
|
if (apiKey) headers.set("Authorization", `Bearer ${apiKey}`);
|
|
const response = await fetch(`${apiBase()}${path}`, { ...options, headers });
|
|
const payload = await response.json();
|
|
if (!response.ok) throw new Error(JSON.stringify(payload, null, 2));
|
|
return payload;
|
|
}
|
|
|
|
function render(target, payload) {
|
|
document.querySelector(target).textContent = JSON.stringify(payload, null, 2);
|
|
}
|
|
|
|
document.querySelector("#bootstrapBtn").addEventListener("click", async () => {
|
|
const payload = await request("/demo/bootstrap", {
|
|
method: "POST",
|
|
body: JSON.stringify({ tenant_name: "Aurask Protal Demo", email: "owner@example.com" }),
|
|
});
|
|
apiKeyInput.value = payload.api_key;
|
|
document.querySelector("#workspaceId").value = payload.workspace.id;
|
|
render("#quotaOutput", payload.quota);
|
|
render("#workspaceOutput", payload.workspace);
|
|
});
|
|
|
|
document.querySelector("#quotaBtn").addEventListener("click", async () => {
|
|
render("#quotaOutput", await request("/quota"));
|
|
});
|
|
|
|
document.querySelector("#workspaceBtn").addEventListener("click", async () => {
|
|
const payload = await request("/workspaces", {
|
|
method: "POST",
|
|
body: JSON.stringify({ name: document.querySelector("#workspaceName").value }),
|
|
});
|
|
document.querySelector("#workspaceId").value = payload.id;
|
|
render("#workspaceOutput", payload);
|
|
});
|
|
|
|
document.querySelector("#runBtn").addEventListener("click", async () => {
|
|
const workspaceId = document.querySelector("#workspaceId").value.trim();
|
|
const body = {
|
|
template_id: document.querySelector("#templateId").value,
|
|
inputs: { prompt: document.querySelector("#prompt").value },
|
|
};
|
|
if (workspaceId) body.workspace_id = workspaceId;
|
|
render("#runOutput", await request("/workflow-runs", { method: "POST", body: JSON.stringify(body) }));
|
|
});
|