File size: 7,090 Bytes
85a5ff4
 
 
 
7f6d77e
85a5ff4
 
7f6d77e
 
 
 
 
 
 
 
 
 
 
 
bbbaad4
7f6d77e
 
 
 
 
 
 
 
 
 
 
bbbaad4
7f6d77e
 
 
 
bbbaad4
7f6d77e
bbbaad4
7f6d77e
 
bbbaad4
7f6d77e
bbbaad4
7f6d77e
 
 
bbbaad4
7f6d77e
 
 
bbbaad4
7f6d77e
bbbaad4
7f6d77e
bbbaad4
 
7f6d77e
 
 
 
 
bbbaad4
7f6d77e
bbbaad4
 
 
7f6d77e
 
 
bbbaad4
 
7f6d77e
bbbaad4
 
7f6d77e
bbbaad4
7f6d77e
 
bf1cb6d
 
 
 
7f6d77e
 
 
bbbaad4
 
 
7f6d77e
 
bbbaad4
 
7f6d77e
 
 
 
 
 
 
 
 
 
 
bbbaad4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7f6d77e
 
 
 
bbbaad4
7f6d77e
 
 
bbbaad4
 
7f6d77e
bbbaad4
7f6d77e
 
 
 
 
 
 
 
 
 
bbbaad4
7f6d77e
 
 
85a5ff4
 
 
7f6d77e
85a5ff4
7f6d77e
 
85a5ff4
 
 
 
 
7f6d77e
85a5ff4
 
 
 
bf1cb6d
 
c6e7c55
bbbaad4
85a5ff4
bf1cb6d
bbbaad4
7f6d77e
bbbaad4
bf1cb6d
 
bbbaad4
85a5ff4
 
 
 
 
 
bbbaad4
85a5ff4
bbbaad4
85a5ff4
bf1cb6d
85a5ff4
 
bbbaad4
bf1cb6d
bbbaad4
7f6d77e
bf1cb6d
 
c6e7c55
bbbaad4
7f6d77e
c6e7c55
7f6d77e
bbbaad4
f4b9863
bf1cb6d
7f6d77e
f4b9863
bbbaad4
 
f4b9863
bbbaad4
 
 
 
 
 
 
f4b9863
 
bbbaad4
 
 
f4b9863
 
bbbaad4
 
f4b9863
bbbaad4
 
c6e7c55
bf1cb6d
 
 
bbbaad4
f4b9863
bf1cb6d
 
7f6d77e
 
 
c6e7c55
bbbaad4
c6e7c55
85a5ff4
bf1cb6d
85a5ff4
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
<!DOCTYPE html>
<html lang="es">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Mission Control v2 – Prueba</title>
  <style>
    :root {
      --primary: #27ae60;
      --primary-dark: #219653;
      --dark-bg: #1e1e1e;
      --text-light: #e0e0e0;
      --success: #4caf50;
      --success-light: #81c784;
      --error: #ef5350;
      --error-light: #ffccbc;
      --info: #3498db;
      --bg-light: #f8f9fa;
      --bg-card: #2d2d2d;
      --border: #444;
    }

    * { box-sizing: border-box; margin: 0; padding: 0; }
    body {
      font-family: Arial, sans-serif;
      background: var(--bg-light);
      color: #333;
      margin: 20px;
      line-height: 1.6;
    }

    h1 { color: #2c3e50; margin-bottom: 20px; text-align: center; }
    label { font-weight: bold; display: block; margin-bottom: 8px; }

    textarea {
      width: 100%;
      height: 140px;
      padding: 12px;
      margin-bottom: 16px;
      font-family: monospace;
      border: 1px solid #ccc;
      border-radius: 8px;
      resize: vertical;
      font-size: 1rem;
    }

    button {
      padding: 14px 32px;
      background: var(--primary);
      color: white;
      border: none;
      border-radius: 8px;
      cursor: pointer;
      font-size: 1.1rem;
      transition: background 0.2s;
      display: block;
      margin: 0 auto 30px;
    }
    button:hover { background: var(--primary-dark); }

    #result {
      margin-top: 30px;
      padding: 24px;
      background: white;
      border-radius: 12px;
      box-shadow: 0 4px 20px rgba(0,0,0,0.1);
      min-height: 200px;
    }

    .spinner {
      border: 5px solid #f3f3f3;
      border-top: 5px solid var(--info);
      border-radius: 50%;
      width: 50px;
      height: 50px;
      animation: spin 1s linear infinite;
      margin: 30px auto;
    }

    @keyframes spin {
      0% { transform: rotate(0deg); }
      100% { transform: rotate(360deg); }
    }

    /* Resultados de agentes */
    .agent-result {
      margin: 20px 0;
      padding: 18px;
      border-radius: 10px;
      background: var(--bg-card);
      color: var(--text-light);
      border-left: 5px solid var(--success);
      box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    }

    .agent-result.error {
      border-left-color: var(--error);
      background: #3d1f1f;
      color: var(--error-light);
    }

    .agent-result strong {
      color: var(--success-light);
      display: block;
      margin-bottom: 10px;
      font-size: 1.2rem;
    }

    .generated-image {
      margin: 20px 0;
      text-align: center;
    }

    .generated-image img {
      max-width: 100%;
      border-radius: 12px;
      box-shadow: 0 8px 20px rgba(0,0,0,0.3);
      margin-bottom: 10px;
    }

    .caption {
      color: #aaa;
      font-size: 0.95rem;
      margin-top: 8px;
    }

    .download-btn {
      display: inline-block;
      padding: 12px 28px;
      background: #1976d2;
      color: white;
      text-decoration: none;
      border-radius: 8px;
      margin-top: 20px;
      transition: background 0.2s;
      font-weight: bold;
    }

    .download-btn:hover {
      background: #1565c0;
    }

    pre {
      background: #272822;
      color: #f8f8f2;
      padding: 15px;
      border-radius: 8px;
      overflow-x: auto;
      margin: 12px 0;
    }
  </style>
</head>
<body>
  <h1>Mission Control v2 – Prueba</h1>

  <label for="task">Escribe tu misión:</label>
  <textarea id="task" placeholder="Ejemplo: Genera una imagen de un gato astronauta..."></textarea>

  <button onclick="launchMission()">Lanzar misión</button>

  <div id="result">
    <h3>Resultado:</h3>
    <div id="output">Esperando...</div>
  </div>

  <script>
    async function launchMission() {
      const taskInput = document.getElementById('task');
      const task = taskInput.value.trim();
      if (!task) return alert('Escribe algo primero');

      const output = document.getElementById('output');
      output.innerHTML = `
        <div style="text-align:center; color:#666; padding:40px;">
          <div class="spinner"></div>
          <p>Procesando tu misión... (puede tardar 10–90 segundos la primera vez)</p>
        </div>
      `;

      try {
        const res = await fetch('/api/mission', {
          method: 'POST',
          headers: { 'Content-Type': 'application/json' },
          body: JSON.stringify({ task })
        });

        const data = await res.json();

        if (!res.ok) {
          output.innerHTML = `<pre style="color:red; background:#ffebee; padding:15px; border-radius:8px;">Error ${res.status}: ${JSON.stringify(data, null, 2)}</pre>`;
          return;
        }

        let html = '<h3>Resultado de la misión</h3>';

        // Razonamiento del manager
        if (data.plan && data.plan.reasoning) {
          html += `<p><strong>Manager pensó:</strong> ${data.plan.reasoning}</p>`;
        }

        // Resultados de agentes
        if (data.results && data.results.length > 0) {
          html += '<h4>Agentes que trabajaron:</h4>';
          data.results.forEach(resultado => {
            const isError = !resultado.success;
            html += `
              <div class="agent-result ${isError ? 'error' : ''}">
                <strong>${resultado.agent} (${isError ? 'Error' : 'Éxito'})</strong>
                <div>${resultado.response ? resultado.response.substring(0, 400) + (resultado.response.length > 400 ? '...' : '') : resultado.error || 'Sin respuesta'}</div>`;

            // Mostrar imágenes si existen
            if (resultado.image_url) {
              html += `
                <div class="generated-image">
                  <img src="${resultado.image_url}" alt="Imagen generada por ${resultado.agent}">
                  <div class="caption">Generada con FLUX.1-schnell</div>
                </div>`;
            } else if (resultado.image_urls && resultado.image_urls.length > 0) {
              resultado.image_urls.forEach(url => {
                html += `
                  <div class="generated-image">
                    <img src="${url}" alt="Imagen generada por ${resultado.agent}">
                    <div class="caption">Generada con FLUX.1-schnell</div>
                  </div>`;
              });
            } else if (resultado.queries && resultado.queries.length > 0) {
              html += `<p><em>Ideas de imagen: ${resultado.queries.join(" • ")}</em></p>`;
            }

            html += '</div>';
          });
        } else {
          html += '<p>No se delegó a ningún agente.</p>';
        }

        // Link de descarga de documento
        if (data.file_url) {
          html += `
            <a href="${data.file_url}" target="_blank" class="download-btn" download>
              Descargar documento generado
            </a>`;
        }

        output.innerHTML = html;
      } catch (err) {
        output.innerHTML = `<pre style="color:red; background:#ffebee; padding:15px; border-radius:8px;">Error de conexión: ${err.message}</pre>`;
      }
    }
  </script>
</body>
</html>