vfven commited on
Commit
3db0077
Β·
verified Β·
1 Parent(s): 0492bbb

Update templates/code_new.html

Browse files
Files changed (1) hide show
  1. templates/code_new.html +57 -0
templates/code_new.html CHANGED
@@ -986,6 +986,9 @@ function showView(viewId) {
986
  if (viewId === "diagnostics") startDiagPoller();
987
  else stopDiagPoller();
988
 
 
 
 
989
  // Actualizar nav activo
990
  const BOTTOM_LINKS = ["diagnostics", "logs"];
991
  Object.entries(NAV_ITEMS).forEach(([key, id]) => {
@@ -1177,6 +1180,60 @@ const AGENT_ICONS = {
1177
  image_agent: { icon: "image", color: "text-primary" },
1178
  };
1179
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1180
  function recordMission(task, managerData, missionData) {
1181
  const ts = new Date();
1182
  const mId = "MC-" + String(missionHistory.length + 1).padStart(4, "0");
 
986
  if (viewId === "diagnostics") startDiagPoller();
987
  else stopDiagPoller();
988
 
989
+ // Cargar historial desde DB al entrar
990
+ if (viewId === "history") loadHistoryFromDB();
991
+
992
  // Actualizar nav activo
993
  const BOTTOM_LINKS = ["diagnostics", "logs"];
994
  Object.entries(NAV_ITEMS).forEach(([key, id]) => {
 
1180
  image_agent: { icon: "image", color: "text-primary" },
1181
  };
1182
 
1183
+
1184
+ // ═══════════════════════════════════════════════════════════
1185
+ // HISTORY β€” carga desde DB al entrar a la vista
1186
+ // ═══════════════════════════════════════════════════════════
1187
+ async function loadHistoryFromDB() {
1188
+ try {
1189
+ const res = await fetch("/api/history");
1190
+ const data = await res.json();
1191
+ if (data.error) throw new Error(data.error);
1192
+
1193
+ // Convertir formato DB β†’ formato interno missionHistory
1194
+ const dbMissions = (data.missions || []).map((m, i) => {
1195
+ const agents = (m.results || []).map(r => r.agent).filter(Boolean);
1196
+ const agentResponses = [];
1197
+
1198
+ // Respuesta del manager desde plan
1199
+ const managerReasoning = m.plan?.reasoning || m.plan?.raw || null;
1200
+ if (managerReasoning) {
1201
+ agentResponses.push({ agent: "manager", text: managerReasoning });
1202
+ }
1203
+
1204
+ // Respuestas de agentes especializados
1205
+ (m.results || []).forEach(r => {
1206
+ if (r.response) agentResponses.push({ agent: r.agent, text: r.response });
1207
+ });
1208
+
1209
+ const success = (m.results || []).every(r => r.success !== false);
1210
+ const fileUrl = m.doc_file ? `/docs/${m.doc_file}` : null;
1211
+ const fileType = (m.results || []).find(r => r.file_type)?.file_type || null;
1212
+ const ts = m.ended_at ? new Date(m.ended_at) : new Date(m.started_at);
1213
+
1214
+ return {
1215
+ mId: `MC-${String(m.id).padStart(4, "0")}`,
1216
+ task: m.task,
1217
+ ts,
1218
+ agents,
1219
+ success,
1220
+ fileUrl,
1221
+ fileType,
1222
+ agentResponses,
1223
+ };
1224
+ });
1225
+
1226
+ // Reemplazar historial en memoria con datos de la DB
1227
+ missionHistory = dbMissions;
1228
+ updateHistoryStats();
1229
+ renderHistoryTable();
1230
+ console.log(`[History] ${dbMissions.length} misiones cargadas desde DB`);
1231
+
1232
+ } catch(e) {
1233
+ console.error("[History] error cargando desde DB:", e);
1234
+ }
1235
+ }
1236
+
1237
  function recordMission(task, managerData, missionData) {
1238
  const ts = new Date();
1239
  const mId = "MC-" + String(missionHistory.length + 1).padStart(4, "0");