modularizado de prompts

This commit is contained in:
Lucas Tettamanti
2026-01-25 20:51:33 -03:00
parent b91ece867b
commit a489ec66a2
43 changed files with 5408 additions and 89 deletions

View File

@@ -219,4 +219,84 @@ export const api = {
body: JSON.stringify({ woo_order_id, amount }),
}).then(r => r.json());
},
// --- Prompts CRUD ---
async prompts() {
return fetch("/prompts").then(r => r.json());
},
async getPrompt(key) {
return fetch(`/prompts/${encodeURIComponent(key)}`).then(r => r.json());
},
async savePrompt(key, { content, model, created_by }) {
return fetch(`/prompts/${encodeURIComponent(key)}`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ content, model, created_by }),
}).then(r => r.json());
},
async rollbackPrompt(key, version) {
return fetch(`/prompts/${encodeURIComponent(key)}/rollback/${version}`, {
method: "POST"
}).then(r => r.json());
},
async resetPrompt(key) {
return fetch(`/prompts/${encodeURIComponent(key)}/reset`, {
method: "POST"
}).then(r => r.json());
},
async testPrompt(key, { content, test_message, store_config }) {
return fetch(`/prompts/${encodeURIComponent(key)}/test`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ content, test_message, store_config }),
}).then(r => r.json());
},
// --- Human Takeovers ---
async takeovers({ limit = 50 } = {}) {
const u = new URL("/takeovers", location.origin);
u.searchParams.set("limit", String(limit));
return fetch(u).then(r => r.json());
},
async getTakeover(id) {
return fetch(`/takeovers/${id}`).then(r => r.json());
},
async respondTakeover(id, { response, add_alias }) {
return fetch(`/takeovers/${id}/respond`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ response, add_alias }),
}).then(r => r.json());
},
async cancelTakeover(id) {
return fetch(`/takeovers/${id}/cancel`, {
method: "POST"
}).then(r => r.json());
},
// --- Settings ---
async getSettings() {
return fetch("/settings").then(r => r.json());
},
async saveSettings(settings) {
const res = await fetch("/settings", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(settings),
});
const data = await res.json();
if (!res.ok || data.ok === false) {
throw new Error(data.message || data.error || "Error guardando configuración");
}
return data;
},
};