claqueta-mcp 0.11.0 → 0.11.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/cli.js +139 -99
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -50,7 +50,7 @@ function ayudaConexionTodas(plataforma = process.platform) {
50
50
  }
51
51
 
52
52
  // src/config.ts
53
- var VERSION = true ? "0.11.0" : "dev";
53
+ var VERSION = true ? "0.11.2" : "dev";
54
54
  var construirAyuda = (plataforma = process.platform) => `claqueta-mcp ${VERSION}: puente stdio hacia el servidor MCP remoto de Claqueta.
55
55
 
56
56
  Uso:
@@ -398,7 +398,8 @@ ${falta.map(([k, r3]) => ` - ${k}: ${r3.mensaje}${r3.arreglo ? `
398
398
 
399
399
  // src/doctor.ts
400
400
  import { execFile } from "node:child_process";
401
- import { existsSync as existsSync4, readFileSync as readFileSync3, statfsSync, statSync as statSync2 } from "node:fs";
401
+ import * as nodeFs from "node:fs";
402
+ import { existsSync as existsSync4, readFileSync as readFileSync3, statSync as statSync2 } from "node:fs";
402
403
  import { homedir as homedir3, platform as plataformaReal } from "node:os";
403
404
  import { dirname as dirname2, join as join4 } from "node:path";
404
405
 
@@ -557,6 +558,7 @@ async function quitarServicio(d) {
557
558
  }
558
559
 
559
560
  // src/doctor.ts
561
+ var statfsSync2 = nodeFs.statfsSync;
560
562
  var PERFIL_VALIDO = /^[A-Za-z0-9._][A-Za-z0-9._-]{0,63}$/;
561
563
  var IMAGEN_VALIDA = /^[A-Za-z0-9][A-Za-z0-9._\-/:@]{0,254}$/;
562
564
  var MIN_NODE = 18;
@@ -639,7 +641,8 @@ var fsReal = {
639
641
  let dir = r2;
640
642
  while (!existsSync4(dir) && dirname2(dir) !== dir) dir = dirname2(dir);
641
643
  try {
642
- const s = statfsSync(dir);
644
+ if (typeof statfsSync2 !== "function") return null;
645
+ const s = statfsSync2(dir);
643
646
  return Number(s.bavail) * Number(s.bsize);
644
647
  } catch {
645
648
  return null;
@@ -2003,14 +2006,28 @@ var ErrorApi = class extends Error {
2003
2006
  return this.estado === 409;
2004
2007
  }
2005
2008
  };
2009
+ var cabReclamo = (reclamo) => reclamo ? { "x-claqueta-reclamo": reclamo } : {};
2010
+ var PLAZO_TRANSFERENCIA_MS = 10 * 6e4;
2011
+ function conPlazo(senal, ms = PLAZO_TRANSFERENCIA_MS) {
2012
+ const c = new AbortController();
2013
+ const t = setTimeout(() => c.abort(new Error(`la transferencia super\xF3 el plazo de ${Math.round(ms / 1e3)} s`)), ms);
2014
+ t.unref?.();
2015
+ const parar = () => {
2016
+ clearTimeout(t);
2017
+ c.abort(senal?.reason);
2018
+ };
2019
+ if (senal?.aborted) parar();
2020
+ else senal?.addEventListener("abort", parar, { once: true });
2021
+ return c.signal;
2022
+ }
2006
2023
  var camposCosto = (o) => o.costoUsd === void 0 ? {} : { costo_usd: o.costoUsd, ...o.desglose && Object.keys(o.desglose).length ? { desglose: o.desglose } : {} };
2007
2024
  var MIME_PIEZA = { png: "image/png", jpg: "image/jpeg", jpeg: "image/jpeg", webp: "image/webp" };
2008
2025
  function crearClienteApi(base, token, f = fetch) {
2009
2026
  const cab = (extra = {}) => ({ ...token ? { authorization: `Bearer ${token}` } : {}, ...extra });
2010
- async function llamar(metodo, ruta, cuerpo) {
2027
+ async function llamar(metodo, ruta, cuerpo, extra = {}) {
2011
2028
  const r2 = await f(`${base}${ruta}`, {
2012
2029
  method: metodo,
2013
- headers: cab(cuerpo === void 0 ? {} : { "content-type": "application/json" }),
2030
+ headers: cab({ ...cuerpo === void 0 ? {} : { "content-type": "application/json" }, ...extra }),
2014
2031
  ...cuerpo === void 0 ? {} : { body: JSON.stringify(cuerpo) }
2015
2032
  });
2016
2033
  return leer(r2);
@@ -2025,21 +2042,23 @@ function crearClienteApi(base, token, f = fetch) {
2025
2042
  }
2026
2043
  throw new ErrorApi(r2.status, msg);
2027
2044
  }
2028
- async function subirRender(id, version, clave, ruta, revision) {
2045
+ async function subirRender(id, version, clave, ruta, revision, o = {}) {
2046
+ const signal = conPlazo(o.senal);
2047
+ const rec = cabReclamo(o.reclamo);
2029
2048
  const bytes = await readFile2(ruta);
2030
2049
  const ajustes = await llamar("GET", "/api/ajustes");
2031
2050
  const base_rd = `/api/videos/${id}/versiones/${version}/renders/${encodeURIComponent(clave)}`;
2032
2051
  if (ajustes.s3?.bucket) {
2033
- const sub = await llamar("POST", `${base_rd}/url`, {});
2034
- const put = await f(sub.url, { method: "PUT", headers: sub.cabeceras, body: bytes });
2052
+ const sub = await llamar("POST", `${base_rd}/url`, {}, rec);
2053
+ const put = await f(sub.url, { method: "PUT", headers: sub.cabeceras, body: bytes, signal });
2035
2054
  if (!put.ok) throw new ErrorApi(put.status, `la subida a S3 del render ${clave} fall\xF3 (HTTP ${put.status})`);
2036
- await llamar("POST", `${base_rd}/confirmar`, { nombre: basename2(ruta), ...revision ? { revision } : {} });
2055
+ await llamar("POST", `${base_rd}/confirmar`, { nombre: basename2(ruta), ...revision ? { revision } : {} }, rec);
2037
2056
  return;
2038
2057
  }
2039
2058
  const form = new FormData();
2040
2059
  if (revision) form.append("revision", JSON.stringify(revision));
2041
2060
  form.append("archivo", new Blob([bytes], { type: "video/mp4" }), basename2(ruta));
2042
- await leer(await f(`${base}${base_rd}`, { method: "POST", headers: cab(), body: form }));
2061
+ await leer(await f(`${base}${base_rd}`, { method: "POST", headers: cab(rec), body: form, signal }));
2043
2062
  }
2044
2063
  return {
2045
2064
  reclamar: (o) => {
@@ -2051,16 +2070,18 @@ function crearClienteApi(base, token, f = fetch) {
2051
2070
  async progreso(id, p) {
2052
2071
  await llamar("POST", `/api/videos/${id}/progreso`, { ...p, etapa: acotarTexto(p.etapa, LIMITES.etapa, "desconocida"), porcentaje: acotarPorcentaje(p.porcentaje), mensaje: acotarTexto(p.mensaje, LIMITES.mensaje, "sin mensaje") });
2053
2072
  },
2054
- fallo: (id, x) => llamar("POST", `/api/videos/${id}/fallo`, { etapa: acotarOpcional(x.etapa, LIMITES.etapa) ?? null, causa: acotarTexto(x.causa, LIMITES.causa, "fallo sin causa conocida"), codigo: Number.isInteger(x.codigo) ? x.codigo : null, max_reintentos: x.maxReintentos, reintentable: x.reintentable, ...camposCosto(x) }),
2073
+ fallo: (id, x) => llamar("POST", `/api/videos/${id}/fallo`, { etapa: acotarOpcional(x.etapa, LIMITES.etapa) ?? null, causa: acotarTexto(x.causa, LIMITES.causa, "fallo sin causa conocida"), codigo: Number.isInteger(x.codigo) ? x.codigo : null, max_reintentos: x.maxReintentos, reintentable: x.reintentable, ...camposCosto(x), ...x.reclamo ? { reclamo: x.reclamo } : {} }),
2055
2074
  async adjuntarMp4(id, version, ruta, o = {}) {
2075
+ const signal = conPlazo(o.senal);
2076
+ const rec = cabReclamo(o.reclamo);
2056
2077
  const bytes = await readFile2(ruta);
2057
2078
  const ajustes = await llamar("GET", "/api/ajustes");
2058
2079
  const base_mp4 = `/api/videos/${id}/versiones/${version}/mp4`;
2059
2080
  if (ajustes.s3?.bucket) {
2060
- const sub = await llamar("POST", `${base_mp4}/url`, {});
2061
- const put = await f(sub.url, { method: "PUT", headers: sub.cabeceras, body: bytes });
2081
+ const sub = await llamar("POST", `${base_mp4}/url`, {}, rec);
2082
+ const put = await f(sub.url, { method: "PUT", headers: sub.cabeceras, body: bytes, signal });
2062
2083
  if (!put.ok) throw new ErrorApi(put.status, `la subida a S3 fall\xF3 (HTTP ${put.status})`);
2063
- return llamar("POST", `${base_mp4}/confirmar`, { nombre: basename2(ruta), ...camposCosto(o), ...o.revision ? { revision: o.revision } : {}, ...o.renders?.length ? { renders: o.renders } : {} });
2084
+ return llamar("POST", `${base_mp4}/confirmar`, { nombre: basename2(ruta), ...camposCosto(o), ...o.revision ? { revision: o.revision } : {}, ...o.renders?.length ? { renders: o.renders } : {} }, rec);
2064
2085
  }
2065
2086
  const form = new FormData();
2066
2087
  const costo = camposCosto(o);
@@ -2069,32 +2090,34 @@ function crearClienteApi(base, token, f = fetch) {
2069
2090
  if (o.revision) form.append("revision", JSON.stringify(o.revision));
2070
2091
  if (o.renders?.length) form.append("renders", JSON.stringify(o.renders));
2071
2092
  form.append("archivo", new Blob([bytes], { type: "video/mp4" }), basename2(ruta));
2072
- return leer(await f(`${base}${base_mp4}`, { method: "POST", headers: cab(), body: form }));
2093
+ return leer(await f(`${base}${base_mp4}`, { method: "POST", headers: cab(rec), body: form, signal }));
2073
2094
  },
2074
- async adjuntarRender(id, version, clave, ruta, revision) {
2095
+ async adjuntarRender(id, version, clave, ruta, revision, o = {}) {
2075
2096
  try {
2076
- await subirRender(id, version, clave, ruta, revision);
2097
+ await subirRender(id, version, clave, ruta, revision, o);
2077
2098
  } catch (e) {
2078
2099
  if (e instanceof ErrorApi && e.estado === 404 && e.message === "Not Found") throw new ErrorApi(501, "la API no admite renders m\xFAltiples todav\xEDa (CLA-57): actualiza el servidor antes que el worker");
2079
2100
  throw e;
2080
2101
  }
2081
2102
  },
2082
- async adjuntarPieza(id, version, ruta) {
2103
+ async adjuntarPieza(id, version, ruta, senal, reclamo) {
2104
+ const signal = conPlazo(senal);
2105
+ const rec = reclamo ? { "x-claqueta-reclamo": reclamo } : {};
2083
2106
  const nombre = basename2(ruta);
2084
2107
  const tipo = MIME_PIEZA[nombre.split(".").pop().toLowerCase()] ?? "application/octet-stream";
2085
2108
  const bytes = await readFile2(ruta);
2086
2109
  const ajustes = await llamar("GET", "/api/ajustes");
2087
2110
  const base_pz = `/api/videos/${id}/versiones/${version}/piezas/${encodeURIComponent(nombre)}`;
2088
2111
  if (ajustes.s3?.bucket) {
2089
- const sub = await llamar("POST", `${base_pz}/url`, {});
2090
- const put = await f(sub.url, { method: "PUT", headers: sub.cabeceras, body: bytes });
2112
+ const sub = await llamar("POST", `${base_pz}/url`, {}, rec);
2113
+ const put = await f(sub.url, { method: "PUT", headers: sub.cabeceras, body: bytes, signal });
2091
2114
  if (!put.ok) throw new ErrorApi(put.status, `la subida a S3 de ${nombre} fall\xF3 (HTTP ${put.status})`);
2092
- await llamar("POST", `${base_pz}/confirmar`, {});
2115
+ await llamar("POST", `${base_pz}/confirmar`, {}, rec);
2093
2116
  return;
2094
2117
  }
2095
2118
  const form = new FormData();
2096
2119
  form.append("archivo", new Blob([bytes], { type: tipo }), nombre);
2097
- await leer(await f(`${base}${base_pz}`, { method: "POST", headers: cab(), body: form }));
2120
+ await leer(await f(`${base}${base_pz}`, { method: "POST", headers: cab(rec), body: form, signal }));
2098
2121
  }
2099
2122
  };
2100
2123
  }
@@ -2333,7 +2356,7 @@ function extensionDe(a) {
2333
2356
  const porMime = { "image/png": ".png", "image/jpeg": ".jpg", "image/webp": ".webp", "image/gif": ".gif", "image/svg+xml": ".svg" };
2334
2357
  return porMime[a.mime ?? ""] ?? "";
2335
2358
  }
2336
- async function descargarMedia(media, pedidoDir, descargar2 = (u) => fetch(u)) {
2359
+ async function descargarMedia(media, pedidoDir, descargar2 = (u, senal2) => fetch(u, senal2 ? { signal: senal2 } : {}), senal) {
2337
2360
  const salida = {};
2338
2361
  const ids = Object.keys(media ?? {}).filter((id) => TIPOS_DESCARGABLES.includes(media[id].tipo));
2339
2362
  if (ids.length === 0) return salida;
@@ -2344,11 +2367,12 @@ async function descargarMedia(media, pedidoDir, descargar2 = (u) => fetch(u)) {
2344
2367
  if (!a.url) throw new ErrorMedia(`el asset ${id} (${a.nombre ?? "sin nombre"}) no tiene archivo en el servidor`, false);
2345
2368
  let r2;
2346
2369
  try {
2347
- r2 = await descargar2(a.url);
2370
+ r2 = await descargar2(a.url, conPlazo(senal));
2348
2371
  } catch (e) {
2349
2372
  throw new ErrorMedia(`no se pudo bajar el asset ${id}: ${e.message}`, true);
2350
2373
  }
2351
2374
  if (!r2.ok) throw new ErrorMedia(`el servidor respondi\xF3 ${r2.status} al bajar el asset ${id}`, r2.status >= 500 || r2.status === 429);
2375
+ if (senal?.aborted) throw new ErrorMedia(`descarga cancelada (${id})`, true);
2352
2376
  const datos = Buffer.from(await r2.arrayBuffer());
2353
2377
  if (a.bytes > 0 && datos.length !== a.bytes) throw new ErrorMedia(`el asset ${id} baj\xF3 con ${datos.length} bytes y deber\xEDa tener ${a.bytes}`, true);
2354
2378
  const sha = createHash2("sha256").update(datos).digest("hex");
@@ -2383,9 +2407,16 @@ async function trabajar(c, d, r2) {
2383
2407
  const salidaDir = join10(raiz, "salida");
2384
2408
  log(`reclamado ${id} v${r2.version} (intento ${r2.intento}): ${r2.titulo}`);
2385
2409
  let costo;
2410
+ const r_ = r2.reclamo ? { reclamo: r2.reclamo } : {};
2386
2411
  const fallar = async (etapa, causa, codigo, reintentable) => {
2387
2412
  log(`fall\xF3 ${id}: ${causa}`);
2388
- const f = await api.fallo(id, { etapa, causa, codigo, maxReintentos: c.maxReintentos, reintentable, ...costo ?? {} });
2413
+ let f;
2414
+ try {
2415
+ f = await api.fallo(id, { etapa, causa, codigo, maxReintentos: c.maxReintentos, reintentable, ...costo ?? {}, ...r_ });
2416
+ } catch (e) {
2417
+ if (e instanceof ErrorApi && (e.conflicto || e.estado === 404)) return { tipo: "cancelado", videoId: id };
2418
+ throw e;
2419
+ }
2389
2420
  return { tipo: "fallo", videoId: id, causa, reencolado: f.reencolado };
2390
2421
  };
2391
2422
  try {
@@ -2398,14 +2429,6 @@ async function trabajar(c, d, r2) {
2398
2429
  }
2399
2430
  await mkdir2(pedidoDir, { recursive: true });
2400
2431
  await mkdir2(salidaDir, { recursive: true });
2401
- try {
2402
- const locales = await descargarMedia(r2.media, pedidoDir, d.descargar);
2403
- if (Object.keys(locales).length) pedido["archivos_locales"] = locales;
2404
- } catch (e) {
2405
- if (e instanceof ErrorMedia) return await fallar("media", e.message, null, e.reintentable);
2406
- throw e;
2407
- }
2408
- await writeFile2(join10(pedidoDir, "pedido.json"), JSON.stringify(pedido, null, 2));
2409
2432
  const parar = new AbortController();
2410
2433
  const alCerrar = () => parar.abort();
2411
2434
  d.senal?.addEventListener("abort", alCerrar, { once: true });
@@ -2418,7 +2441,7 @@ async function trabajar(c, d, r2) {
2418
2441
  if (cancelado) return;
2419
2442
  if (!forzar && e.etapa === publicado.etapa && e.porcentaje < publicado.porcentaje + 5 && e.nivel !== "advertencia" && e.porcentaje < 100) return;
2420
2443
  try {
2421
- await api.progreso(id, { etapa: e.etapa, porcentaje: e.porcentaje, mensaje: e.mensaje, ...e.nivel === "advertencia" ? { nivel: "advertencia" } : {} });
2444
+ await api.progreso(id, { ...r_, etapa: e.etapa, porcentaje: e.porcentaje, mensaje: e.mensaje, ...e.nivel === "advertencia" ? { nivel: "advertencia" } : {} });
2422
2445
  publicado = { etapa: e.etapa, porcentaje: e.porcentaje };
2423
2446
  } catch (err) {
2424
2447
  if (err instanceof ErrorApi && (err.conflicto || err.estado === 404)) {
@@ -2430,76 +2453,91 @@ async function trabajar(c, d, r2) {
2430
2453
  };
2431
2454
  const latido = setInterval(() => publicar(ultimo, true), d.latidoMs ?? 3e4);
2432
2455
  publicar(ultimo, true);
2433
- let res;
2434
2456
  try {
2435
- res = await (d.motor ?? ejecutarMotor)(c, {
2436
- pedidoDir,
2437
- salidaDir,
2438
- nombreContenedor: `claqueta-motor-${id}-${r2.intento}`.replace(/[^a-zA-Z0-9_.-]/g, "_"),
2439
- senal: parar.signal,
2440
- onEvento: (e) => {
2441
- ultimo = e;
2442
- publicar(e);
2443
- }
2444
- });
2445
- } finally {
2446
- clearInterval(latido);
2447
- d.senal?.removeEventListener("abort", alCerrar);
2448
- await cadena;
2449
- }
2450
- if (cancelado) return { tipo: "cancelado", videoId: id };
2451
- if (res.abortado) return await fallar(ultimo.etapa, "el worker se detuvo mientras generaba; se reintentar\xE1", null, true);
2452
- const mp4 = join10(salidaDir, "video.mp4");
2453
- const advertencias = [];
2454
- if (res.codigo === 0 || res.codigo === 15) {
2455
- if (!await existe(mp4)) return await fallar(ultimo.etapa, `el motor termin\xF3 bien pero no dej\xF3 video.mp4`, res.codigo, true);
2456
- const manifiesto = await leerManifiesto(salidaDir, log);
2457
- costo = manifiesto.costo;
2458
- const avisar = (mensaje, nivel, datos) => api.progreso(id, { etapa: "revision", porcentaje: 100, mensaje, ...nivel ? { nivel } : {}, ...datos ? { datos } : {} }).catch(() => {
2459
- });
2460
- if (res.codigo === 15) {
2461
- const f = await checksFallidos(salidaDir);
2462
- if (c.siFallaRevision === "rechazar") return await fallar("revision", `La revisi\xF3n autom\xE1tica no pas\xF3: ${f}`, 15, true);
2463
- advertencias.push(`La revisi\xF3n autom\xE1tica no pas\xF3: ${f}`);
2464
- await api.progreso(id, { etapa: "revision", porcentaje: 100, mensaje: advertencias[0], nivel: "advertencia" }).catch(() => {
2457
+ try {
2458
+ const locales = await descargarMedia(r2.media, pedidoDir, d.descargar, parar.signal);
2459
+ if (Object.keys(locales).length) pedido["archivos_locales"] = locales;
2460
+ } catch (e) {
2461
+ if (cancelado) return { tipo: "cancelado", videoId: id };
2462
+ if (e instanceof ErrorMedia) return await fallar("media", e.message, null, e.reintentable);
2463
+ throw e;
2464
+ }
2465
+ await writeFile2(join10(pedidoDir, "pedido.json"), JSON.stringify(pedido, null, 2));
2466
+ if (cancelado) return { tipo: "cancelado", videoId: id };
2467
+ let res;
2468
+ try {
2469
+ res = await (d.motor ?? ejecutarMotor)(c, {
2470
+ pedidoDir,
2471
+ salidaDir,
2472
+ nombreContenedor: `claqueta-motor-${id}-${r2.intento}`.replace(/[^a-zA-Z0-9_.-]/g, "_"),
2473
+ senal: parar.signal,
2474
+ onEvento: (e) => {
2475
+ ultimo = e;
2476
+ publicar(e);
2477
+ }
2465
2478
  });
2479
+ } finally {
2480
+ await cadena;
2466
2481
  }
2467
- const sub = await subirPiezas(d, id, r2.version, salidaDir, dormir, log);
2468
- if (sub === "cancelado") return { tipo: "cancelado", videoId: id };
2469
- if (sub instanceof Error) return await fallar("piezas", `no se pudieron subir las piezas: ${sub.message}`, null, true);
2470
- const renders = manifiesto.renders;
2471
- const total = Math.max(renders.length, 1);
2472
- const subidos = [];
2473
- for (const [k, render] of renders.slice(1).entries()) {
2474
- const ruta = rutaDeRender(salidaDir, render);
2475
- if (!ruta || !await existe(ruta)) return await fallar("revision", `el manifiesto anuncia el render ${render.etiqueta} pero no est\xE1 ${render.ruta}`, res.codigo, true);
2476
- if (render.aprobada === false) {
2477
- const aviso = `El render ${render.etiqueta} no pas\xF3 la revisi\xF3n autom\xE1tica: ${render.checksFallidos.join(", ") || "sin detalle"}; se adjunta igual`;
2482
+ if (cancelado) return { tipo: "cancelado", videoId: id };
2483
+ if (res.abortado) return await fallar(ultimo.etapa, "el worker se detuvo mientras generaba; se reintentar\xE1", null, true);
2484
+ const mp4 = join10(salidaDir, "video.mp4");
2485
+ const advertencias = [];
2486
+ if (res.codigo === 0 || res.codigo === 15) {
2487
+ if (!await existe(mp4)) return await fallar(ultimo.etapa, `el motor termin\xF3 bien pero no dej\xF3 video.mp4`, res.codigo, true);
2488
+ const manifiesto = await leerManifiesto(salidaDir, log);
2489
+ costo = manifiesto.costo;
2490
+ const avisar = (mensaje, nivel, datos) => api.progreso(id, { etapa: "revision", porcentaje: 100, mensaje, ...nivel ? { nivel } : {}, ...datos ? { datos } : {} }).catch(() => {
2491
+ });
2492
+ if (res.codigo === 15) {
2493
+ const f = await checksFallidos(salidaDir);
2494
+ if (c.siFallaRevision === "rechazar") return await fallar("revision", `La revisi\xF3n autom\xE1tica no pas\xF3: ${f}`, 15, true);
2495
+ advertencias.push(`La revisi\xF3n autom\xE1tica no pas\xF3: ${f}`);
2496
+ await api.progreso(id, { etapa: "revision", porcentaje: 100, mensaje: advertencias[0], nivel: "advertencia", ...r_ }).catch(() => {
2497
+ });
2498
+ }
2499
+ const sub = await subirPiezas(d, id, r2.version, salidaDir, dormir, log, parar.signal, r2.reclamo ?? void 0);
2500
+ if (sub === "cancelado") return { tipo: "cancelado", videoId: id };
2501
+ if (sub instanceof Error) return await fallar("piezas", `no se pudieron subir las piezas: ${sub.message}`, null, true);
2502
+ const transf = { senal: parar.signal, ...r2.reclamo ? { reclamo: r2.reclamo } : {} };
2503
+ const renders = manifiesto.renders;
2504
+ const total = Math.max(renders.length, 1);
2505
+ const subidos = [];
2506
+ for (const [k, render] of renders.slice(1).entries()) {
2507
+ const ruta = rutaDeRender(salidaDir, render);
2508
+ if (!ruta || !await existe(ruta)) return await fallar("revision", `el manifiesto anuncia el render ${render.etiqueta} pero no est\xE1 ${render.ruta}`, res.codigo, true);
2509
+ if (render.aprobada === false) {
2510
+ const aviso = `El render ${render.etiqueta} no pas\xF3 la revisi\xF3n autom\xE1tica: ${render.checksFallidos.join(", ") || "sin detalle"}; se adjunta igual`;
2511
+ advertencias.push(aviso);
2512
+ await avisar(aviso, "advertencia");
2513
+ }
2514
+ await avisar(`subiendo render ${k + 2}/${total} (${render.etiqueta})`, void 0, { render: render.etiqueta, indice: k + 2, total, destinos: render.destinos });
2515
+ const adj2 = await reintentar(`render ${render.etiqueta}`, () => d.api.adjuntarRender(id, r2.version, render.etiqueta, ruta, revisionDe(render), transf), dormir, log, parar.signal);
2516
+ if (adj2 === "cancelado") return { tipo: "cancelado", videoId: id };
2517
+ if (adj2 instanceof Error) return await fallar("revision", `no se pudo adjuntar el render ${render.etiqueta}: ${adj2.message}`, null, true);
2518
+ subidos.push(render.etiqueta);
2519
+ }
2520
+ const pedidos = Array.isArray(pedido["renders"]) ? pedido["renders"].length : 1;
2521
+ if (pedidos > total) {
2522
+ const aviso = `El motor gener\xF3 ${total} de los ${pedidos} renders pedidos; los dem\xE1s quedan pendientes (\xBFimagen del motor anterior a 0.4.0?)`;
2478
2523
  advertencias.push(aviso);
2479
2524
  await avisar(aviso, "advertencia");
2480
2525
  }
2481
- await avisar(`subiendo render ${k + 2}/${total} (${render.etiqueta})`, void 0, { render: render.etiqueta, indice: k + 2, total, destinos: render.destinos });
2482
- const adj2 = await reintentar(`render ${render.etiqueta}`, () => d.api.adjuntarRender(id, r2.version, render.etiqueta, ruta, revisionDe(render)), dormir, log);
2483
- if (adj2 === "cancelado") return { tipo: "cancelado", videoId: id };
2484
- if (adj2 instanceof Error) return await fallar("revision", `no se pudo adjuntar el render ${render.etiqueta}: ${adj2.message}`, null, true);
2485
- subidos.push(render.etiqueta);
2526
+ const principal = renders[0];
2527
+ if (total > 1) await avisar(`subiendo render 1/${total} (${principal.etiqueta})`, void 0, { render: principal.etiqueta, indice: 1, total, destinos: principal.destinos });
2528
+ const opciones = { ...transf, ...manifiesto.costo ?? {}, ...principal && revisionDe(principal) ? { revision: revisionDe(principal) } : {}, ...subidos.length ? { renders: subidos } : {} };
2529
+ const adj = await reintentar("MP4", () => d.api.adjuntarMp4(id, r2.version, mp4, opciones), dormir, log, parar.signal);
2530
+ if (adj === "cancelado") return { tipo: "cancelado", videoId: id };
2531
+ if (adj instanceof Error) return await fallar("revision", `no se pudo adjuntar el MP4: ${adj.message}`, null, true);
2532
+ log(`listo ${id}: ${adj.estado}`);
2533
+ return { tipo: "listo", videoId: id, estado: adj.estado, advertencias };
2486
2534
  }
2487
- const pedidos = Array.isArray(pedido["renders"]) ? pedido["renders"].length : 1;
2488
- if (pedidos > total) {
2489
- const aviso = `El motor gener\xF3 ${total} de los ${pedidos} renders pedidos; los dem\xE1s quedan pendientes (\xBFimagen del motor anterior a 0.4.0?)`;
2490
- advertencias.push(aviso);
2491
- await avisar(aviso, "advertencia");
2492
- }
2493
- const principal = renders[0];
2494
- if (total > 1) await avisar(`subiendo render 1/${total} (${principal.etiqueta})`, void 0, { render: principal.etiqueta, indice: 1, total, destinos: principal.destinos });
2495
- const opciones = { ...manifiesto.costo ?? {}, ...principal && revisionDe(principal) ? { revision: revisionDe(principal) } : {}, ...subidos.length ? { renders: subidos } : {} };
2496
- const adj = await reintentar("MP4", () => d.api.adjuntarMp4(id, r2.version, mp4, opciones), dormir, log);
2497
- if (adj === "cancelado") return { tipo: "cancelado", videoId: id };
2498
- if (adj instanceof Error) return await fallar("revision", `no se pudo adjuntar el MP4: ${adj.message}`, null, true);
2499
- log(`listo ${id}: ${adj.estado}`);
2500
- return { tipo: "listo", videoId: id, estado: adj.estado, advertencias };
2535
+ return await fallar(res.error?.etapa ?? ultimo.etapa, causaLegible(res, Math.round(c.timeoutMs / 6e4)), res.codigo, res.codigo !== 2 || res.tiempoAgotado);
2536
+ } finally {
2537
+ clearInterval(latido);
2538
+ d.senal?.removeEventListener("abort", alCerrar);
2539
+ await cadena;
2501
2540
  }
2502
- return await fallar(res.error?.etapa ?? ultimo.etapa, causaLegible(res, Math.round(c.timeoutMs / 6e4)), res.codigo, res.codigo !== 2 || res.tiempoAgotado);
2503
2541
  } finally {
2504
2542
  if (!c.conservar) await rm(raiz, { recursive: true, force: true });
2505
2543
  }
@@ -2521,13 +2559,14 @@ async function piezasDelManifiesto(salidaDir) {
2521
2559
  return [];
2522
2560
  }
2523
2561
  }
2524
- async function subirPiezas(d, id, version, salidaDir, dormir, log) {
2562
+ async function subirPiezas(d, id, version, salidaDir, dormir, log, senal, reclamo) {
2525
2563
  for (const ruta of await piezasDelManifiesto(salidaDir)) {
2526
2564
  let hecho = false;
2527
2565
  let ultimo = new Error("sin intentos");
2528
2566
  for (let i = 1; i <= 3 && !hecho; i++) {
2567
+ if (senal?.aborted) return "cancelado";
2529
2568
  try {
2530
- await d.api.adjuntarPieza(id, version, ruta);
2569
+ await d.api.adjuntarPieza(id, version, ruta, senal, reclamo);
2531
2570
  hecho = true;
2532
2571
  } catch (e) {
2533
2572
  if (e instanceof ErrorApi && (e.conflicto || e.estado === 404)) return "cancelado";
@@ -2548,9 +2587,10 @@ function rutaDeRender(salidaDir, r2) {
2548
2587
  const ruta = resolve2(salidaDir, r2.ruta);
2549
2588
  return ruta.startsWith(resolve2(salidaDir) + sep) ? ruta : null;
2550
2589
  }
2551
- async function reintentar(que, accion, dormir, log) {
2590
+ async function reintentar(que, accion, dormir, log, senal) {
2552
2591
  let ultimo = new Error("sin intentos");
2553
2592
  for (let i = 1; i <= 3; i++) {
2593
+ if (senal?.aborted) return "cancelado";
2554
2594
  try {
2555
2595
  return await accion();
2556
2596
  } catch (e) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claqueta-mcp",
3
- "version": "0.11.0",
3
+ "version": "0.11.2",
4
4
  "description": "Cliente de Claqueta: puente stdio para el servidor MCP remoto, comando setup y worker de la cola. Úsalo con npx en Claude Desktop o Claude Code.",
5
5
  "type": "module",
6
6
  "bin": {