claqueta-mcp 0.70.0 → 0.70.1
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.
- package/dist/cli.js +781 -482
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -83,7 +83,7 @@ function ayudaConexionTodas(plataforma = process.platform) {
|
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
// src/config.ts
|
|
86
|
-
var VERSION = true ? "0.70.
|
|
86
|
+
var VERSION = true ? "0.70.1" : "dev";
|
|
87
87
|
var construirAyuda = (plataforma = process.platform) => `claqueta-mcp ${VERSION}: puente stdio hacia el servidor MCP remoto de Claqueta.
|
|
88
88
|
|
|
89
89
|
Uso:
|
|
@@ -190,9 +190,9 @@ function normalizarUrl(bruta) {
|
|
|
190
190
|
u2.password = "";
|
|
191
191
|
u2.search = "";
|
|
192
192
|
u2.hash = "";
|
|
193
|
-
let
|
|
194
|
-
if (
|
|
195
|
-
u2.pathname = `${
|
|
193
|
+
let ruta2 = u2.pathname.replace(/\/+$/, "");
|
|
194
|
+
if (ruta2.endsWith("/mcp")) ruta2 = ruta2.slice(0, -4);
|
|
195
|
+
u2.pathname = `${ruta2}/mcp`;
|
|
196
196
|
return u2.toString();
|
|
197
197
|
}
|
|
198
198
|
function leerConfig(argv, env, archivo2 = {}) {
|
|
@@ -245,7 +245,7 @@ function leerConfig(argv, env, archivo2 = {}) {
|
|
|
245
245
|
|
|
246
246
|
// src/local/cli-local.ts
|
|
247
247
|
import { homedir as homedir8 } from "node:os";
|
|
248
|
-
import { join as
|
|
248
|
+
import { join as join35 } from "node:path";
|
|
249
249
|
|
|
250
250
|
// src/motor-docker.ts
|
|
251
251
|
import { spawn } from "node:child_process";
|
|
@@ -389,16 +389,16 @@ async function asegurarNavegador(d) {
|
|
|
389
389
|
}
|
|
390
390
|
var ultimaLinea = (t) => t.trim().split("\n").filter(Boolean).slice(-1)[0]?.slice(0, 200) ?? "";
|
|
391
391
|
var argsPrueba = (perfil) => ["--headless", "--disable-gpu", "--no-first-run", "--no-default-browser-check", `--user-data-dir=${perfil}`, "--dump-dom", "about:blank"];
|
|
392
|
-
var probarNavegadorReal = (
|
|
392
|
+
var probarNavegadorReal = (ruta2) => new Promise((fin) => {
|
|
393
393
|
const perfil = mkdtempSync(join(tmpdir(), "cq-navegador-"));
|
|
394
394
|
const t02 = Date.now();
|
|
395
|
-
execFile(
|
|
395
|
+
execFile(ruta2, argsPrueba(perfil), { timeout: 3e4, maxBuffer: 1024 * 1024, encoding: "utf8" }, (err, stdout, stderr) => {
|
|
396
396
|
rmSync(perfil, { recursive: true, force: true });
|
|
397
397
|
const e7 = err;
|
|
398
398
|
if (!e7 && /<html/i.test(stdout)) return fin({ ok: true, segundos: Math.round((Date.now() - t02) / 100) / 10 });
|
|
399
399
|
const detalle = ultimaLinea(stderr);
|
|
400
|
-
if (e7?.code === "ENOENT") return fin({ ok: false, motivo: `no existe ${
|
|
401
|
-
if (e7?.code === "EACCES") return fin({ ok: false, motivo: `${
|
|
400
|
+
if (e7?.code === "ENOENT") return fin({ ok: false, motivo: `no existe ${ruta2}` });
|
|
401
|
+
if (e7?.code === "EACCES") return fin({ ok: false, motivo: `${ruta2} no es ejecutable` });
|
|
402
402
|
if (e7?.killed) return fin({ ok: false, motivo: "no respondi\xF3 en 30 s" });
|
|
403
403
|
if (e7?.signal) return fin({ ok: false, motivo: `se cerr\xF3 con ${e7.signal}${detalle ? ` (${detalle})` : ""}` });
|
|
404
404
|
if (e7) return fin({ ok: false, motivo: `sali\xF3 con c\xF3digo ${String(e7.code)}${detalle ? ` (${detalle})` : ""}` });
|
|
@@ -456,9 +456,9 @@ function entornoMotorLocal(r2, navegador, env) {
|
|
|
456
456
|
};
|
|
457
457
|
}
|
|
458
458
|
function extrasDelMotor(motorDir) {
|
|
459
|
-
const
|
|
460
|
-
if (!existsSync2(
|
|
461
|
-
const texto7 = readFileSync(
|
|
459
|
+
const ruta2 = join2(motorDir, "pyproject.toml");
|
|
460
|
+
if (!existsSync2(ruta2)) return /* @__PURE__ */ new Set();
|
|
461
|
+
const texto7 = readFileSync(ruta2, "utf8");
|
|
462
462
|
const ini = texto7.indexOf("[project.optional-dependencies]");
|
|
463
463
|
if (ini < 0) return /* @__PURE__ */ new Set();
|
|
464
464
|
const resto = texto7.slice(ini + "[project.optional-dependencies]".length);
|
|
@@ -574,9 +574,9 @@ var vivoPorDefecto = (pid) => {
|
|
|
574
574
|
return e7.code === "EPERM";
|
|
575
575
|
}
|
|
576
576
|
};
|
|
577
|
-
function leerObjeto(
|
|
577
|
+
function leerObjeto(ruta2) {
|
|
578
578
|
try {
|
|
579
|
-
const v2 = JSON.parse(readFileSync2(
|
|
579
|
+
const v2 = JSON.parse(readFileSync2(ruta2, "utf8"));
|
|
580
580
|
return v2 && typeof v2 === "object" && !Array.isArray(v2) ? v2 : null;
|
|
581
581
|
} catch {
|
|
582
582
|
return null;
|
|
@@ -607,11 +607,11 @@ function seguro(id3) {
|
|
|
607
607
|
if (!RE_ID.test(id3) || id3.includes("..")) throw new Error(`id de video no v\xE1lido para el buz\xF3n: ${id3}`);
|
|
608
608
|
return id3;
|
|
609
609
|
}
|
|
610
|
-
function escribirAtomico(
|
|
611
|
-
const tmp = `${
|
|
610
|
+
function escribirAtomico(ruta2, datos) {
|
|
611
|
+
const tmp = `${ruta2}.${process.pid}.tmp`;
|
|
612
612
|
writeFileSync2(tmp, `${JSON.stringify(datos, null, 2)}
|
|
613
613
|
`, { mode: 384 });
|
|
614
|
-
renameSync(tmp,
|
|
614
|
+
renameSync(tmp, ruta2);
|
|
615
615
|
}
|
|
616
616
|
function leerRespuesta(buzonDir, videoId) {
|
|
617
617
|
const r2 = leerObjeto(rutaRespuesta(buzonDir, videoId));
|
|
@@ -681,9 +681,9 @@ var vivoPorDefecto2 = (pid) => {
|
|
|
681
681
|
return e7.code === "EPERM";
|
|
682
682
|
}
|
|
683
683
|
};
|
|
684
|
-
function leerObjeto2(
|
|
684
|
+
function leerObjeto2(ruta2) {
|
|
685
685
|
try {
|
|
686
|
-
const v2 = JSON.parse(readFileSync3(
|
|
686
|
+
const v2 = JSON.parse(readFileSync3(ruta2, "utf8"));
|
|
687
687
|
return v2 && typeof v2 === "object" && !Array.isArray(v2) ? v2 : null;
|
|
688
688
|
} catch {
|
|
689
689
|
return null;
|
|
@@ -800,13 +800,13 @@ function limpiarPresenciasMuertas(dir, esVivo = vivoPorDefecto2) {
|
|
|
800
800
|
}
|
|
801
801
|
}
|
|
802
802
|
function leerTrabajo(buzonDir, videoId) {
|
|
803
|
-
let
|
|
803
|
+
let ruta2;
|
|
804
804
|
try {
|
|
805
|
-
|
|
805
|
+
ruta2 = rutaTrabajo(buzonDir, videoId);
|
|
806
806
|
} catch {
|
|
807
807
|
return null;
|
|
808
808
|
}
|
|
809
|
-
const t = leerObjeto2(
|
|
809
|
+
const t = leerObjeto2(ruta2);
|
|
810
810
|
return t && t["formato"] === FORMATO_BUZON && typeof t["video_id"] === "string" && typeof t["estado"] === "string" ? t : null;
|
|
811
811
|
}
|
|
812
812
|
function listarBuzon(buzonDir, o = {}) {
|
|
@@ -829,10 +829,10 @@ function listarBuzon(buzonDir, o = {}) {
|
|
|
829
829
|
}
|
|
830
830
|
function tomarTrabajo(buzonDir, t, sesion, o = {}) {
|
|
831
831
|
const respuesta = { estado: "tomado", sesion, en: new Date(o.ahora ?? Date.now()).toISOString(), ...o.nota ? { nota: o.nota } : {} };
|
|
832
|
-
const
|
|
832
|
+
const ruta2 = rutaRespuesta(buzonDir, t.video_id);
|
|
833
833
|
let fd2;
|
|
834
834
|
try {
|
|
835
|
-
fd2 = openSync(
|
|
835
|
+
fd2 = openSync(ruta2, "wx", 384);
|
|
836
836
|
} catch (e7) {
|
|
837
837
|
if (e7.code === "EEXIST") return { tipo: "ocupado" };
|
|
838
838
|
throw e7;
|
|
@@ -846,7 +846,7 @@ function tomarTrabajo(buzonDir, t, sesion, o = {}) {
|
|
|
846
846
|
const actual = leerTrabajo(buzonDir, t.video_id);
|
|
847
847
|
if (!actual || actual.creado !== t.creado || actual.estado !== "esperando_agente" && actual.estado !== "tomado") {
|
|
848
848
|
const mia = leerRespuesta(buzonDir, t.video_id);
|
|
849
|
-
if (mia?.sesion === sesion && mia.en === respuesta.en) rmSync4(
|
|
849
|
+
if (mia?.sesion === sesion && mia.en === respuesta.en) rmSync4(ruta2, { force: true });
|
|
850
850
|
return { tipo: "perdido", motivo: actual ? `el worker ya lo pas\xF3 a \xAB${actual.estado}\xBB${actual.motivo ? ` (${actual.motivo})` : ""}` : "el trabajo ya no est\xE1 en el buz\xF3n" };
|
|
851
851
|
}
|
|
852
852
|
return { tipo: "tomado", trabajo: actual, respuesta };
|
|
@@ -873,26 +873,26 @@ function ultimaModificacion(dir) {
|
|
|
873
873
|
return 0;
|
|
874
874
|
}
|
|
875
875
|
for (const n of nombres) {
|
|
876
|
-
const
|
|
876
|
+
const ruta2 = join4(dir, n);
|
|
877
877
|
try {
|
|
878
|
-
const st2 = statSync(
|
|
879
|
-
max = Math.max(max, st2.isDirectory() ? ultimaModificacion(
|
|
878
|
+
const st2 = statSync(ruta2);
|
|
879
|
+
max = Math.max(max, st2.isDirectory() ? ultimaModificacion(ruta2) : st2.mtimeMs);
|
|
880
880
|
} catch {
|
|
881
881
|
}
|
|
882
882
|
}
|
|
883
883
|
return max;
|
|
884
884
|
}
|
|
885
885
|
function estadoFinal(carpeta2) {
|
|
886
|
-
const
|
|
886
|
+
const ruta2 = join4(carpeta2, "final", "video.mp4");
|
|
887
887
|
let final = 0;
|
|
888
888
|
try {
|
|
889
|
-
const st2 = statSync(
|
|
889
|
+
const st2 = statSync(ruta2);
|
|
890
890
|
if (st2.isFile() && st2.size > 0) final = st2.mtimeMs;
|
|
891
891
|
} catch {
|
|
892
892
|
}
|
|
893
893
|
const comp = ultimaModificacion(join4(carpeta2, "composicion"));
|
|
894
894
|
return {
|
|
895
|
-
ruta,
|
|
895
|
+
ruta: ruta2,
|
|
896
896
|
existe: final > 0,
|
|
897
897
|
al_dia: final > 0 && final >= comp,
|
|
898
898
|
final_en: final ? new Date(final).toISOString() : null,
|
|
@@ -10562,7 +10562,7 @@ var AlmacenLocal = class {
|
|
|
10562
10562
|
this.comprobarNuevaVersion(v2);
|
|
10563
10563
|
const pedidoNuevo = this.pedidoConCambios(v2, cambios);
|
|
10564
10564
|
const ver = this.leerVersion(videoId, v2.versionActual);
|
|
10565
|
-
const insumos = (ver?.insumos ?? []).map(({ ruta, sha256: sha2563, bytes }) => ({ ruta, sha256: sha2563, bytes }));
|
|
10565
|
+
const insumos = (ver?.insumos ?? []).map(({ ruta: ruta2, sha256: sha2563, bytes }) => ({ ruta: ruta2, sha256: sha2563, bytes }));
|
|
10566
10566
|
let huellas = null;
|
|
10567
10567
|
if (insumos.some((x2) => x2.ruta === "huellas.json")) {
|
|
10568
10568
|
try {
|
|
@@ -10603,12 +10603,12 @@ var AlmacenLocal = class {
|
|
|
10603
10603
|
const videosInsumo = [];
|
|
10604
10604
|
for (const [i, x2] of videos.entries()) {
|
|
10605
10605
|
if (!existsSync3(x2.archivo)) continue;
|
|
10606
|
-
let
|
|
10607
|
-
if (
|
|
10608
|
-
mkdirSync4(dirname(
|
|
10609
|
-
copyFileSync(x2.archivo,
|
|
10610
|
-
} else if (!existsSync3(
|
|
10611
|
-
videosInsumo.push({ clave: x2.clave, ruta, sha256: createHash("sha256").update(readFileSync4(
|
|
10606
|
+
let ruta2 = principal && i === 0 ? principal : join5(dir, "renders", `${x2.clave}.mp4`);
|
|
10607
|
+
if (ruta2 !== principal) {
|
|
10608
|
+
mkdirSync4(dirname(ruta2), { recursive: true });
|
|
10609
|
+
copyFileSync(x2.archivo, ruta2);
|
|
10610
|
+
} else if (!existsSync3(ruta2)) ruta2 = x2.archivo;
|
|
10611
|
+
videosInsumo.push({ clave: x2.clave, ruta: ruta2, sha256: createHash("sha256").update(readFileSync4(ruta2)).digest("hex") });
|
|
10612
10612
|
}
|
|
10613
10613
|
const nueva = { ...ver, insumos: registrados, videosInsumo };
|
|
10614
10614
|
this.guardarVersion(nueva);
|
|
@@ -10680,10 +10680,10 @@ var AlmacenLocal = class {
|
|
|
10680
10680
|
if (!ver) throw new ErrorAlmacen("no_existe", `no existe la versi\xF3n ${n} del video ${videoId}`);
|
|
10681
10681
|
const dir = this.carpetaVersion(videoId, n);
|
|
10682
10682
|
const guardados = { ...extra };
|
|
10683
|
-
for (const [clave,
|
|
10684
|
-
if (!
|
|
10685
|
-
const destino = join5(dir, clave === "video" ? "video.mp4" : basename(
|
|
10686
|
-
copyFileSync(
|
|
10683
|
+
for (const [clave, ruta2] of Object.entries(archivos)) {
|
|
10684
|
+
if (!ruta2 || !existsSync3(ruta2) || !statSync2(ruta2).isFile()) continue;
|
|
10685
|
+
const destino = join5(dir, clave === "video" ? "video.mp4" : basename(ruta2));
|
|
10686
|
+
copyFileSync(ruta2, destino);
|
|
10687
10687
|
guardados[clave] = destino;
|
|
10688
10688
|
}
|
|
10689
10689
|
const nueva = { ...ver, archivos: { ...ver.archivos, ...guardados } };
|
|
@@ -10798,20 +10798,20 @@ function listarDir(dir) {
|
|
|
10798
10798
|
return [];
|
|
10799
10799
|
}
|
|
10800
10800
|
}
|
|
10801
|
-
function leerJson(
|
|
10801
|
+
function leerJson(ruta2) {
|
|
10802
10802
|
try {
|
|
10803
|
-
const v2 = JSON.parse(readFileSync4(
|
|
10803
|
+
const v2 = JSON.parse(readFileSync4(ruta2, "utf8"));
|
|
10804
10804
|
return esObjeto(v2) ? v2 : null;
|
|
10805
10805
|
} catch {
|
|
10806
10806
|
return null;
|
|
10807
10807
|
}
|
|
10808
10808
|
}
|
|
10809
|
-
function escribirJson(
|
|
10810
|
-
const tmp = `${
|
|
10809
|
+
function escribirJson(ruta2, valor) {
|
|
10810
|
+
const tmp = `${ruta2}.${process.pid}.${randomBytes(4).toString("hex")}.tmp`;
|
|
10811
10811
|
writeFileSync3(tmp, `${JSON.stringify(valor, null, 2)}
|
|
10812
10812
|
`);
|
|
10813
10813
|
try {
|
|
10814
|
-
renameSync2(tmp,
|
|
10814
|
+
renameSync2(tmp, ruta2);
|
|
10815
10815
|
} catch (e7) {
|
|
10816
10816
|
rmSync5(tmp, { force: true });
|
|
10817
10817
|
throw e7;
|
|
@@ -10839,25 +10839,25 @@ var vivo = (pid) => {
|
|
|
10839
10839
|
return e7.code === "EPERM";
|
|
10840
10840
|
}
|
|
10841
10841
|
};
|
|
10842
|
-
function leerDueno(
|
|
10842
|
+
function leerDueno(ruta2) {
|
|
10843
10843
|
try {
|
|
10844
|
-
const j2 = JSON.parse(readFileSync5(
|
|
10844
|
+
const j2 = JSON.parse(readFileSync5(ruta2, "utf8"));
|
|
10845
10845
|
return typeof j2.pid === "number" ? j2 : null;
|
|
10846
10846
|
} catch {
|
|
10847
10847
|
return null;
|
|
10848
10848
|
}
|
|
10849
10849
|
}
|
|
10850
|
-
function duenoActivo(
|
|
10851
|
-
const d = leerDueno(
|
|
10850
|
+
function duenoActivo(ruta2, o = {}) {
|
|
10851
|
+
const d = leerDueno(ruta2);
|
|
10852
10852
|
return d && d.pid !== (o.pid ?? process.pid) && (o.esVivo ?? vivo)(d.pid) ? d : null;
|
|
10853
10853
|
}
|
|
10854
|
-
function tomarBloqueo(
|
|
10854
|
+
function tomarBloqueo(ruta2, datos, o = {}) {
|
|
10855
10855
|
const pid = o.pid ?? process.pid;
|
|
10856
10856
|
const esVivo = o.esVivo ?? vivo;
|
|
10857
|
-
mkdirSync5(dirname2(
|
|
10857
|
+
mkdirSync5(dirname2(ruta2), { recursive: true });
|
|
10858
10858
|
for (let intento = 0; intento < 2; intento++) {
|
|
10859
10859
|
try {
|
|
10860
|
-
const fd2 = openSync2(
|
|
10860
|
+
const fd2 = openSync2(ruta2, "wx", 384);
|
|
10861
10861
|
writeSync2(fd2, `${JSON.stringify({ pid, ...datos, desde: (o.ahora?.() ?? /* @__PURE__ */ new Date()).toISOString() })}
|
|
10862
10862
|
`);
|
|
10863
10863
|
closeSync2(fd2);
|
|
@@ -10865,21 +10865,21 @@ function tomarBloqueo(ruta, datos, o = {}) {
|
|
|
10865
10865
|
return () => {
|
|
10866
10866
|
if (suelto) return;
|
|
10867
10867
|
suelto = true;
|
|
10868
|
-
if (leerDueno(
|
|
10868
|
+
if (leerDueno(ruta2)?.pid === pid) rmSync6(ruta2, { force: true });
|
|
10869
10869
|
};
|
|
10870
10870
|
} catch (e7) {
|
|
10871
10871
|
if (e7.code !== "EEXIST") throw e7;
|
|
10872
|
-
const d = leerDueno(
|
|
10872
|
+
const d = leerDueno(ruta2);
|
|
10873
10873
|
if (d && esVivo(d.pid) && d.pid !== pid) throw new Ocupado(d);
|
|
10874
10874
|
if (d && d.pid === pid) throw new Ocupado(d);
|
|
10875
10875
|
if (intento === 0 && (!d || !esVivo(d.pid))) {
|
|
10876
|
-
rmSync6(
|
|
10876
|
+
rmSync6(ruta2, { force: true });
|
|
10877
10877
|
continue;
|
|
10878
10878
|
}
|
|
10879
10879
|
throw new Ocupado(d);
|
|
10880
10880
|
}
|
|
10881
10881
|
}
|
|
10882
|
-
throw new Ocupado(leerDueno(
|
|
10882
|
+
throw new Ocupado(leerDueno(ruta2));
|
|
10883
10883
|
}
|
|
10884
10884
|
|
|
10885
10885
|
// src/local/cola-local.ts
|
|
@@ -10933,18 +10933,18 @@ async function prepararReutilizar(r2, raiz, descargar2, senal) {
|
|
|
10933
10933
|
avisos.push(`insumo_invalido: videos/${String(v2?.clave).slice(0, 40)}`);
|
|
10934
10934
|
continue;
|
|
10935
10935
|
}
|
|
10936
|
-
const
|
|
10936
|
+
const ruta2 = `videos/${v2.clave}.mp4`;
|
|
10937
10937
|
const datos = await bajar(v2.url);
|
|
10938
10938
|
if (!datos) {
|
|
10939
|
-
avisos.push(`sin_insumo: ${
|
|
10939
|
+
avisos.push(`sin_insumo: ${ruta2}`);
|
|
10940
10940
|
continue;
|
|
10941
10941
|
}
|
|
10942
10942
|
if (v2.sha256 && sha256(datos) !== v2.sha256) {
|
|
10943
|
-
avisos.push(`insumo_invalido: ${
|
|
10943
|
+
avisos.push(`insumo_invalido: ${ruta2}`);
|
|
10944
10944
|
continue;
|
|
10945
10945
|
}
|
|
10946
10946
|
await mkdir(join7(dir, "videos"), { recursive: true });
|
|
10947
|
-
await writeFile(join7(dir,
|
|
10947
|
+
await writeFile(join7(dir, ruta2), datos);
|
|
10948
10948
|
videos += 1;
|
|
10949
10949
|
}
|
|
10950
10950
|
return { dir: huellas ? dir : null, insumos, videos, avisos };
|
|
@@ -11170,8 +11170,8 @@ function causaLegible(r2, timeoutMin) {
|
|
|
11170
11170
|
var CONTRATO_PASOS = "pasos/1";
|
|
11171
11171
|
var ErrorArgumento = class extends Error {
|
|
11172
11172
|
};
|
|
11173
|
-
function dentroDe(carpeta2,
|
|
11174
|
-
const abs = isAbsolute(
|
|
11173
|
+
function dentroDe(carpeta2, ruta2) {
|
|
11174
|
+
const abs = isAbsolute(ruta2) ? ruta2 : resolve3(carpeta2, ruta2);
|
|
11175
11175
|
const rel = relative2(carpeta2, abs);
|
|
11176
11176
|
return rel === "" || rel.startsWith("..") || isAbsolute(rel) ? null : rel.split(sep2).join("/");
|
|
11177
11177
|
}
|
|
@@ -11179,7 +11179,7 @@ var ENTORNO_PASA = ["CLAQUETA_WHISPER_MODELO", "CLAQUETA_KOKORO_MODELO", "CLAQUE
|
|
|
11179
11179
|
function comandoPaso(m, paso2, carpeta2, o, contenedor, usuario, env = process.env) {
|
|
11180
11180
|
const local = Boolean(m.comando);
|
|
11181
11181
|
const montajes2 = [];
|
|
11182
|
-
const
|
|
11182
|
+
const ruta2 = (r2, punto) => {
|
|
11183
11183
|
if (local) return isAbsolute(r2) ? r2 : resolve3(carpeta2, r2);
|
|
11184
11184
|
const rel = dentroDe(carpeta2, r2);
|
|
11185
11185
|
if (rel !== null) return `/carpeta/${rel}`;
|
|
@@ -11196,7 +11196,7 @@ function comandoPaso(m, paso2, carpeta2, o, contenedor, usuario, env = process.e
|
|
|
11196
11196
|
const args2 = [paso2, "--carpeta", local ? carpeta2 : "/carpeta"];
|
|
11197
11197
|
if (paso2 === "componer") {
|
|
11198
11198
|
if (!o.pedido) throw new ErrorArgumento("falta el pedido");
|
|
11199
|
-
args2.push("--pedido",
|
|
11199
|
+
args2.push("--pedido", ruta2(o.pedido, "/pedidos"));
|
|
11200
11200
|
if (o.forzar) args2.push("--forzar");
|
|
11201
11201
|
}
|
|
11202
11202
|
if ((paso2 === "componer" || paso2 === "render") && o.reutilizar) {
|
|
@@ -11217,7 +11217,7 @@ function comandoPaso(m, paso2, carpeta2, o, contenedor, usuario, env = process.e
|
|
|
11217
11217
|
}
|
|
11218
11218
|
if (paso2 === "parecido") {
|
|
11219
11219
|
if (!o.referencia) throw new ErrorArgumento("falta la referencia");
|
|
11220
|
-
args2.push("--referencia",
|
|
11220
|
+
args2.push("--referencia", ruta2(o.referencia, "/referencia"));
|
|
11221
11221
|
if (o.fotogramas !== void 0) args2.push("--fotogramas", String(o.fotogramas));
|
|
11222
11222
|
if (o.umbral !== void 0) args2.push("--umbral", String(o.umbral));
|
|
11223
11223
|
}
|
|
@@ -11446,9 +11446,9 @@ var ColaLocal = class {
|
|
|
11446
11446
|
for (const id3 of idsDeAssets(pedido)) {
|
|
11447
11447
|
const a = almacen.leerAsset(id3);
|
|
11448
11448
|
if (!a?.rutaLocal) throw new Error(`el asset ${id3} ya no est\xE1 en la biblioteca local`);
|
|
11449
|
-
const
|
|
11450
|
-
copyFileSync2(a.rutaLocal, join10(entrada,
|
|
11451
|
-
locales[id3] = { ruta, tipo: a.tipo, nombre: a.nombre, mime: a.mime };
|
|
11449
|
+
const ruta2 = `media/${id3}${extname2(a.rutaLocal)}`;
|
|
11450
|
+
copyFileSync2(a.rutaLocal, join10(entrada, ruta2));
|
|
11451
|
+
locales[id3] = { ruta: ruta2, tipo: a.tipo, nombre: a.nombre, mime: a.mime };
|
|
11452
11452
|
}
|
|
11453
11453
|
if (Object.keys(locales).length) pedido["archivos_locales"] = locales;
|
|
11454
11454
|
const pedidoRuta = join10(entrada, "pedido.json");
|
|
@@ -11470,15 +11470,15 @@ var ColaLocal = class {
|
|
|
11470
11470
|
const ru2 = this.o.almacen.insumosParaReutilizar(videoId, desde);
|
|
11471
11471
|
if (!ru2) return void 0;
|
|
11472
11472
|
rmSync7(copia, { recursive: true, force: true });
|
|
11473
|
-
const
|
|
11473
|
+
const leer3 = async (ruta2) => {
|
|
11474
11474
|
try {
|
|
11475
|
-
const b2 = readFileSync6(
|
|
11475
|
+
const b2 = readFileSync6(ruta2);
|
|
11476
11476
|
return { ok: true, status: 200, arrayBuffer: async () => b2.buffer.slice(b2.byteOffset, b2.byteOffset + b2.byteLength) };
|
|
11477
11477
|
} catch {
|
|
11478
11478
|
return { ok: false, status: 404, arrayBuffer: async () => new ArrayBuffer(0) };
|
|
11479
11479
|
}
|
|
11480
11480
|
};
|
|
11481
|
-
const p = await prepararReutilizar(ru2, copia,
|
|
11481
|
+
const p = await prepararReutilizar(ru2, copia, leer3, this.ctrl.signal);
|
|
11482
11482
|
const mensaje = p.dir ? `Reutilizo insumos de la versi\xF3n ${desde}: ${p.insumos} insumos y ${p.videos} video${p.videos === 1 ? "" : "s"}${p.avisos.length ? `; descartados ${p.avisos.length} (${p.avisos.slice(0, 3).join(", ")})` : ""}` : `Sin insumos v\xE1lidos de la versi\xF3n ${desde} (${p.avisos.slice(0, 3).join(", ") || "falta huellas.json"}): genero la versi\xF3n completa`;
|
|
11483
11483
|
this.o.almacen.evento(videoId, "reutilizar", mensaje, { reutilizar: { desde_version: desde, insumos: p.insumos, videos: p.videos, avisos: p.avisos } });
|
|
11484
11484
|
return p.dir ?? void 0;
|
|
@@ -11548,8 +11548,8 @@ function videosDelManifiesto(manifiesto, video) {
|
|
|
11548
11548
|
return (m.renders ?? []).flatMap((x2, i) => {
|
|
11549
11549
|
if (!Number.isInteger(x2.ancho) || !Number.isInteger(x2.alto)) return [];
|
|
11550
11550
|
const clave = `${String(x2.ancho)}x${String(x2.alto)}`;
|
|
11551
|
-
const
|
|
11552
|
-
return [{ clave, archivo: i === 0 ? video : resolve4(dirname5(manifiesto), typeof
|
|
11551
|
+
const ruta2 = x2.archivos?.video?.ruta;
|
|
11552
|
+
return [{ clave, archivo: i === 0 ? video : resolve4(dirname5(manifiesto), typeof ruta2 === "string" && ruta2 ? ruta2 : `renders/${clave}/video.mp4`) }];
|
|
11553
11553
|
});
|
|
11554
11554
|
} catch {
|
|
11555
11555
|
return [];
|
|
@@ -11720,19 +11720,19 @@ function anotar(carpetaAbs, entrada) {
|
|
|
11720
11720
|
} catch {
|
|
11721
11721
|
}
|
|
11722
11722
|
}
|
|
11723
|
-
function leerJson2(
|
|
11723
|
+
function leerJson2(ruta2) {
|
|
11724
11724
|
try {
|
|
11725
|
-
const v2 = JSON.parse(readFileSync7(
|
|
11725
|
+
const v2 = JSON.parse(readFileSync7(ruta2, "utf8"));
|
|
11726
11726
|
return esObjeto2(v2) ? v2 : null;
|
|
11727
11727
|
} catch {
|
|
11728
11728
|
return null;
|
|
11729
11729
|
}
|
|
11730
11730
|
}
|
|
11731
|
-
function imagen(
|
|
11732
|
-
if (!
|
|
11731
|
+
function imagen(ruta2) {
|
|
11732
|
+
if (!ruta2) return null;
|
|
11733
11733
|
try {
|
|
11734
|
-
if (statSync3(
|
|
11735
|
-
return { type: "image", data: readFileSync7(
|
|
11734
|
+
if (statSync3(ruta2).size > TOPE_IMAGEN) return texto(`(La hoja ${ruta2} pesa m\xE1s de 4 MB; \xE1brela con tu herramienta de lectura de archivos.)`);
|
|
11735
|
+
return { type: "image", data: readFileSync7(ruta2).toString("base64"), mimeType: "image/png" };
|
|
11736
11736
|
} catch {
|
|
11737
11737
|
return null;
|
|
11738
11738
|
}
|
|
@@ -11788,30 +11788,30 @@ ${JSON.stringify(r2, null, 2)}`)];
|
|
|
11788
11788
|
}
|
|
11789
11789
|
async function componer(ctx, a, l) {
|
|
11790
11790
|
const pedido = a["pedido"];
|
|
11791
|
-
const
|
|
11791
|
+
const ruta2 = cadena(a, "pedido_ruta");
|
|
11792
11792
|
if (pedido !== void 0 && !esObjeto2(pedido)) throw new ErrorUso("\xABpedido\xBB debe ser un objeto JSON");
|
|
11793
|
-
if (!pedido === !
|
|
11793
|
+
if (!pedido === !ruta2) throw new ErrorUso("pasa \xABpedido\xBB (objeto) o \xABpedido_ruta\xBB (ruta absoluta), uno de los dos");
|
|
11794
11794
|
const id3 = cadena(a, "id");
|
|
11795
11795
|
const existente = cadena(a, "carpeta");
|
|
11796
11796
|
if (id3 && !RE_ID3.test(id3)) throw new ErrorUso("\xABid\xBB solo admite letras, n\xFAmeros, punto, guion y guion bajo (m\xE1x. 100)");
|
|
11797
11797
|
if (id3 && existente) throw new ErrorUso("pasa \xABid\xBB (carpeta nueva) o \xABcarpeta\xBB (existente), no los dos");
|
|
11798
11798
|
let rutaPedido;
|
|
11799
11799
|
let pedidoObj = esObjeto2(pedido) ? pedido : null;
|
|
11800
|
-
if (
|
|
11801
|
-
rutaPedido = resolve5(expandir(
|
|
11800
|
+
if (ruta2) {
|
|
11801
|
+
rutaPedido = resolve5(expandir(ruta2));
|
|
11802
11802
|
if (!existsSync4(rutaPedido)) throw new ErrorUso(`no existe el pedido ${rutaPedido}`);
|
|
11803
11803
|
pedidoObj = leerJson2(rutaPedido);
|
|
11804
11804
|
}
|
|
11805
11805
|
mkdirSync7(ctx.base, { recursive: true });
|
|
11806
11806
|
const carpetaAbs = existente ? resolverCarpeta(ctx, existente) : join11(ctx.base, id3 ?? idNuevo(ctx, pedidoObj));
|
|
11807
11807
|
mkdirSync7(carpetaAbs, { recursive: true });
|
|
11808
|
-
if (!
|
|
11808
|
+
if (!ruta2) {
|
|
11809
11809
|
rutaPedido = join11(carpetaAbs, "entrada", "pedido.json");
|
|
11810
11810
|
mkdirSync7(join11(carpetaAbs, "entrada"), { recursive: true });
|
|
11811
11811
|
writeFileSync5(rutaPedido, `${JSON.stringify(pedido, null, 2)}
|
|
11812
11812
|
`);
|
|
11813
11813
|
}
|
|
11814
|
-
return paso(ctx, "componer", carpetaAbs, { pedido: rutaPedido, forzar: a["forzar"] === true }, { ...
|
|
11814
|
+
return paso(ctx, "componer", carpetaAbs, { pedido: rutaPedido, forzar: a["forzar"] === true }, { ...ruta2 ? { pedido_ruta: rutaPedido } : { pedido: "entrada/pedido.json" }, forzar: a["forzar"] === true }, l);
|
|
11815
11815
|
}
|
|
11816
11816
|
async function capacidades(ctx, a) {
|
|
11817
11817
|
const familia = cadena(a, "familia");
|
|
@@ -11854,9 +11854,9 @@ ${guia}`)] : []] };
|
|
|
11854
11854
|
};
|
|
11855
11855
|
return { content: [texto(JSON.stringify(salida, null, 2))] };
|
|
11856
11856
|
}
|
|
11857
|
-
var sha2562 = (
|
|
11857
|
+
var sha2562 = (ruta2) => {
|
|
11858
11858
|
try {
|
|
11859
|
-
return createHash3("sha256").update(readFileSync7(
|
|
11859
|
+
return createHash3("sha256").update(readFileSync7(ruta2)).digest("hex");
|
|
11860
11860
|
} catch {
|
|
11861
11861
|
return null;
|
|
11862
11862
|
}
|
|
@@ -11888,8 +11888,8 @@ function bitacora(ctx, a) {
|
|
|
11888
11888
|
creado: estado2["creado"],
|
|
11889
11889
|
formatos: renders.map((r2) => {
|
|
11890
11890
|
const idx = join11(c, String(r2["composicion"]), "index.html");
|
|
11891
|
-
const
|
|
11892
|
-
return { clave: r2["clave"], composicion: idx, editada:
|
|
11891
|
+
const sha3 = sha2562(idx);
|
|
11892
|
+
return { clave: r2["clave"], composicion: idx, editada: sha3 !== null && sha3 !== r2["index_sha256_original"] };
|
|
11893
11893
|
}),
|
|
11894
11894
|
final: existsSync4(join11(c, "final", "video.mp4")) ? join11(c, "final", "video.mp4") : null,
|
|
11895
11895
|
historial: estado2["historial"] ?? [],
|
|
@@ -11990,9 +11990,9 @@ function directorioConfig(env = process.env) {
|
|
|
11990
11990
|
return join12(xdg || join12(homedir4(), ".config"), "claqueta");
|
|
11991
11991
|
}
|
|
11992
11992
|
var rutaConfig = (env = process.env) => join12(directorioConfig(env), "config.json");
|
|
11993
|
-
function leerCrudo(
|
|
11994
|
-
if (!existsSync5(
|
|
11995
|
-
const j2 = JSON.parse(readFileSync8(
|
|
11993
|
+
function leerCrudo(ruta2) {
|
|
11994
|
+
if (!existsSync5(ruta2)) return { herramientas: {}, heredado: false };
|
|
11995
|
+
const j2 = JSON.parse(readFileSync8(ruta2, "utf8"));
|
|
11996
11996
|
const url = typeof j2["CLAQUETA_URL"] === "string" ? j2["CLAQUETA_URL"] : void 0;
|
|
11997
11997
|
const token = typeof j2["CLAQUETA_TOKEN"] === "string" && j2["CLAQUETA_TOKEN"].trim() ? j2["CLAQUETA_TOKEN"] : void 0;
|
|
11998
11998
|
const herramientas = {};
|
|
@@ -12037,14 +12037,14 @@ function herramientasConectadas(env = process.env) {
|
|
|
12037
12037
|
}
|
|
12038
12038
|
}
|
|
12039
12039
|
function leerArchivoConfig(env = process.env) {
|
|
12040
|
-
const
|
|
12040
|
+
const ruta2 = rutaConfig(env);
|
|
12041
12041
|
const avisos = [];
|
|
12042
|
-
if (!existsSync5(
|
|
12042
|
+
if (!existsSync5(ruta2)) return { datos: {}, avisos };
|
|
12043
12043
|
try {
|
|
12044
|
-
if (process.platform !== "win32" && (statSync4(
|
|
12045
|
-
avisos.push(`Aviso: ${
|
|
12044
|
+
if (process.platform !== "win32" && (statSync4(ruta2).mode & 63) !== 0) {
|
|
12045
|
+
avisos.push(`Aviso: ${ruta2} es legible por otros usuarios; corrige con: chmod 600 "${ruta2}"`);
|
|
12046
12046
|
}
|
|
12047
|
-
const crudo = leerCrudo(
|
|
12047
|
+
const crudo = leerCrudo(ruta2);
|
|
12048
12048
|
let token = crudo.token;
|
|
12049
12049
|
const slug = env["CLAQUETA_HERRAMIENTA"]?.trim();
|
|
12050
12050
|
if (slug) {
|
|
@@ -12055,7 +12055,7 @@ function leerArchivoConfig(env = process.env) {
|
|
|
12055
12055
|
const datos = { ...crudo.url ? { url: crudo.url } : {}, ...token ? { token } : {}, ...Object.keys(crudo.herramientas).length ? { herramientas: crudo.herramientas } : {} };
|
|
12056
12056
|
return { datos, avisos };
|
|
12057
12057
|
} catch {
|
|
12058
|
-
avisos.push(`Aviso: no pude leer ${
|
|
12058
|
+
avisos.push(`Aviso: no pude leer ${ruta2} (JSON inv\xE1lido); se ignora. Corre "npx claqueta-mcp@latest setup" para regenerarlo.`);
|
|
12059
12059
|
return { datos: {}, avisos };
|
|
12060
12060
|
}
|
|
12061
12061
|
}
|
|
@@ -12272,6 +12272,8 @@ function conPlazo(senal, ms2 = PLAZO_TRANSFERENCIA_MS) {
|
|
|
12272
12272
|
const c = new AbortController();
|
|
12273
12273
|
const t = setTimeout(() => c.abort(new Error(`la transferencia super\xF3 el plazo de ${Math.round(ms2 / 1e3)} s`)), ms2);
|
|
12274
12274
|
t.unref?.();
|
|
12275
|
+
const any = AbortSignal.any;
|
|
12276
|
+
if (senal && any) return any([senal, c.signal]);
|
|
12275
12277
|
const parar = () => {
|
|
12276
12278
|
clearTimeout(t);
|
|
12277
12279
|
c.abort(senal?.reason);
|
|
@@ -12290,21 +12292,21 @@ function crearClienteApi(base, token, f = fetch) {
|
|
|
12290
12292
|
} catch (e7) {
|
|
12291
12293
|
const razon = init.signal?.aborted ? init.signal.reason : void 0;
|
|
12292
12294
|
if (init.signal?.aborted && (!razon || razon.name === "AbortError")) throw e7;
|
|
12293
|
-
const
|
|
12295
|
+
const ruta2 = rutaSinQuery(init.method ?? "GET", url);
|
|
12294
12296
|
const causa = razon ? razon.name === "TimeoutError" ? "tiempo agotado" : razon.message : causaDeRed(e7);
|
|
12295
|
-
throw new ErrorApi(0, `sin respuesta de ${
|
|
12297
|
+
throw new ErrorApi(0, `sin respuesta de ${ruta2}: ${causa}`, { ruta: ruta2, red: true });
|
|
12296
12298
|
}
|
|
12297
12299
|
};
|
|
12298
|
-
async function llamar(metodo,
|
|
12299
|
-
const r2 = await fr2(`${base}${
|
|
12300
|
+
async function llamar(metodo, ruta2, cuerpo, extra = {}, signal) {
|
|
12301
|
+
const r2 = await fr2(`${base}${ruta2}`, {
|
|
12300
12302
|
method: metodo,
|
|
12301
12303
|
...signal ? { signal } : {},
|
|
12302
12304
|
headers: cab({ ...cuerpo === void 0 ? {} : { "content-type": "application/json" }, ...extra }),
|
|
12303
12305
|
...cuerpo === void 0 ? {} : { body: JSON.stringify(cuerpo) }
|
|
12304
12306
|
});
|
|
12305
|
-
return
|
|
12307
|
+
return leer3(r2, `${metodo} ${ruta2.split("?")[0]}`);
|
|
12306
12308
|
}
|
|
12307
|
-
async function
|
|
12309
|
+
async function leer3(r2, ruta2) {
|
|
12308
12310
|
if (r2.ok) return r2.status === 204 ? void 0 : await r2.json();
|
|
12309
12311
|
let msg = `HTTP ${r2.status}`;
|
|
12310
12312
|
if (r2.status === 426) throw new ErrorApi(426, mensajeClienteDesactualizado(leerClienteDesactualizado(await r2.text().catch(() => "")), process.env["CLAQUETA_VERSION"] || VERSION));
|
|
@@ -12313,32 +12315,32 @@ function crearClienteApi(base, token, f = fetch) {
|
|
|
12313
12315
|
if (j2.error) msg = j2.error;
|
|
12314
12316
|
} catch {
|
|
12315
12317
|
}
|
|
12316
|
-
const donde =
|
|
12318
|
+
const donde = ruta2 ?? (r2.url ? rutaSinQuery("", r2.url).trim() : null);
|
|
12317
12319
|
throw new ErrorApi(r2.status, r2.status >= 500 && donde ? `${msg} en ${donde}` : msg, { ruta: donde });
|
|
12318
12320
|
}
|
|
12319
|
-
async function subirRender(id3, version2, clave,
|
|
12321
|
+
async function subirRender(id3, version2, clave, ruta2, revision, o = {}) {
|
|
12320
12322
|
const signal = conPlazo(o.senal);
|
|
12321
12323
|
const rec = cabReclamo(o.reclamo);
|
|
12322
|
-
const bytes = await readFile2(
|
|
12324
|
+
const bytes = await readFile2(ruta2);
|
|
12323
12325
|
const ajustes = await llamar("GET", "/api/ajustes");
|
|
12324
12326
|
const base_rd = `/api/videos/${id3}/versiones/${version2}/renders/${encodeURIComponent(clave)}`;
|
|
12325
12327
|
if (ajustes.s3?.bucket) {
|
|
12326
12328
|
const sub = await llamar("POST", `${base_rd}/url`, {}, rec);
|
|
12327
12329
|
const put = await fr2(sub.url, { method: "PUT", headers: sub.cabeceras, body: bytes, signal });
|
|
12328
12330
|
if (!put.ok) throw new ErrorApi(put.status, `la subida a S3 del render ${clave} fall\xF3 (HTTP ${put.status})`);
|
|
12329
|
-
await llamar("POST", `${base_rd}/confirmar`, { nombre: basename3(
|
|
12331
|
+
await llamar("POST", `${base_rd}/confirmar`, { nombre: basename3(ruta2), ...revision ? { revision } : {}, ...duracionValida(o.duracionS) ? { duracion_s: o.duracionS } : {} }, rec);
|
|
12330
12332
|
return;
|
|
12331
12333
|
}
|
|
12332
12334
|
const form = new FormData();
|
|
12333
12335
|
if (revision) form.append("revision", JSON.stringify(revision));
|
|
12334
12336
|
if (duracionValida(o.duracionS)) form.append("duracion_s", String(o.duracionS));
|
|
12335
|
-
form.append("archivo", new Blob([bytes], { type: "video/mp4" }), basename3(
|
|
12336
|
-
await
|
|
12337
|
+
form.append("archivo", new Blob([bytes], { type: "video/mp4" }), basename3(ruta2));
|
|
12338
|
+
await leer3(await fr2(`${base}${base_rd}`, { method: "POST", headers: cab(rec), body: form, signal }));
|
|
12337
12339
|
}
|
|
12338
|
-
async function subirPoster(id3, version2, clave,
|
|
12340
|
+
async function subirPoster(id3, version2, clave, ruta2, o = {}, archivo2 = "poster") {
|
|
12339
12341
|
const signal = conPlazo(o.senal);
|
|
12340
12342
|
const rec = cabReclamo(o.reclamo);
|
|
12341
|
-
const bytes = await readFile2(
|
|
12343
|
+
const bytes = await readFile2(ruta2);
|
|
12342
12344
|
const ajustes = await llamar("GET", "/api/ajustes");
|
|
12343
12345
|
const base_rd = `/api/videos/${id3}/versiones/${version2}/renders/${encodeURIComponent(clave)}`;
|
|
12344
12346
|
if (ajustes.s3?.bucket) {
|
|
@@ -12346,49 +12348,49 @@ function crearClienteApi(base, token, f = fetch) {
|
|
|
12346
12348
|
if (!sub.clave?.endsWith(archivo2 === "poster" ? "/poster.jpg" : "/parecido.jpg")) throw new ErrorApi(501, archivo2 === "poster" ? "la API no admite p\xF3sters todav\xEDa (CLA-171): actualiza el servidor" : "la API no admite la hoja de parecido todav\xEDa (CLA-167): actualiza el servidor");
|
|
12347
12349
|
const put = await fr2(sub.url, { method: "PUT", headers: sub.cabeceras, body: bytes, signal });
|
|
12348
12350
|
if (!put.ok) throw new ErrorApi(put.status, `la subida a S3 del ${archivo2 === "poster" ? "p\xF3ster" : "hoja de parecido"} ${clave} fall\xF3 (HTTP ${put.status})`);
|
|
12349
|
-
await llamar("POST", `${base_rd}/confirmar?archivo=${archivo2}`, { nombre: basename3(
|
|
12351
|
+
await llamar("POST", `${base_rd}/confirmar?archivo=${archivo2}`, { nombre: basename3(ruta2) }, rec);
|
|
12350
12352
|
return;
|
|
12351
12353
|
}
|
|
12352
12354
|
const form = new FormData();
|
|
12353
|
-
form.append("archivo", new Blob([bytes], { type: "image/jpeg" }), basename3(
|
|
12354
|
-
await
|
|
12355
|
+
form.append("archivo", new Blob([bytes], { type: "image/jpeg" }), basename3(ruta2));
|
|
12356
|
+
await leer3(await fr2(`${base}${base_rd}?archivo=${archivo2}`, { method: "POST", headers: cab(rec), body: form, signal }));
|
|
12355
12357
|
}
|
|
12356
|
-
async function subirPrevia(id3, version2,
|
|
12358
|
+
async function subirPrevia(id3, version2, ruta2, o = {}) {
|
|
12357
12359
|
const signal = conPlazo(o.senal);
|
|
12358
12360
|
const rec = cabReclamo(o.reclamo);
|
|
12359
|
-
const bytes = await readFile2(
|
|
12361
|
+
const bytes = await readFile2(ruta2);
|
|
12360
12362
|
const ajustes = await llamar("GET", "/api/ajustes");
|
|
12361
12363
|
const base_pv = `/api/videos/${id3}/versiones/${version2}/previa`;
|
|
12362
12364
|
if (ajustes.s3?.bucket) {
|
|
12363
12365
|
const sub = await llamar("POST", `${base_pv}/url`, {}, rec);
|
|
12364
12366
|
const put = await fr2(sub.url, { method: "PUT", headers: sub.cabeceras, body: bytes, signal });
|
|
12365
12367
|
if (!put.ok) throw new ErrorApi(put.status, `la subida a S3 de la previa fall\xF3 (HTTP ${put.status})`);
|
|
12366
|
-
await llamar("POST", `${base_pv}/confirmar`, { nombre: basename3(
|
|
12368
|
+
await llamar("POST", `${base_pv}/confirmar`, { nombre: basename3(ruta2) }, rec);
|
|
12367
12369
|
return;
|
|
12368
12370
|
}
|
|
12369
12371
|
const form = new FormData();
|
|
12370
|
-
form.append("archivo", new Blob([bytes], { type: "video/mp4" }), basename3(
|
|
12371
|
-
await
|
|
12372
|
+
form.append("archivo", new Blob([bytes], { type: "video/mp4" }), basename3(ruta2));
|
|
12373
|
+
await leer3(await fr2(`${base}${base_pv}`, { method: "POST", headers: cab(rec), body: form, signal }));
|
|
12372
12374
|
}
|
|
12373
|
-
async function subirInsumo(id3, version2,
|
|
12375
|
+
async function subirInsumo(id3, version2, ruta2, rutaArchivo, o = {}) {
|
|
12374
12376
|
const signal = conPlazo(o.senal);
|
|
12375
12377
|
const rec = cabReclamo(o.reclamo);
|
|
12376
12378
|
const bytes = await readFile2(rutaArchivo);
|
|
12377
|
-
const meta = { ruta, bytes: bytes.byteLength, sha256: createHash4("sha256").update(bytes).digest("hex") };
|
|
12379
|
+
const meta = { ruta: ruta2, bytes: bytes.byteLength, sha256: createHash4("sha256").update(bytes).digest("hex") };
|
|
12378
12380
|
const ajustes = await llamar("GET", "/api/ajustes");
|
|
12379
12381
|
const base_in = `/api/videos/${id3}/versiones/${version2}/insumos`;
|
|
12380
12382
|
if (ajustes.s3?.bucket) {
|
|
12381
12383
|
const sub = await llamar("POST", `${base_in}/url`, meta, rec);
|
|
12382
12384
|
const put = await fr2(sub.url, { method: "PUT", headers: sub.cabeceras ?? {}, body: bytes, signal });
|
|
12383
|
-
if (!put.ok) throw new ErrorApi(put.status, `la subida a S3 del insumo ${
|
|
12385
|
+
if (!put.ok) throw new ErrorApi(put.status, `la subida a S3 del insumo ${ruta2} fall\xF3 (HTTP ${put.status})`);
|
|
12384
12386
|
await llamar("POST", `${base_in}/confirmar`, meta, rec);
|
|
12385
12387
|
return;
|
|
12386
12388
|
}
|
|
12387
12389
|
const form = new FormData();
|
|
12388
|
-
form.append("ruta",
|
|
12390
|
+
form.append("ruta", ruta2);
|
|
12389
12391
|
form.append("sha256", meta.sha256);
|
|
12390
|
-
form.append("archivo", new Blob([bytes], { type:
|
|
12391
|
-
await
|
|
12392
|
+
form.append("archivo", new Blob([bytes], { type: ruta2.endsWith(".wav") ? "audio/wav" : ruta2.endsWith(".srt") ? "application/x-subrip" : ruta2.endsWith(".vtt") ? "text/vtt" : "application/json" }), basename3(ruta2));
|
|
12393
|
+
await leer3(await fr2(`${base}${base_in}`, { method: "POST", headers: cab(rec), body: form, signal }));
|
|
12392
12394
|
}
|
|
12393
12395
|
return {
|
|
12394
12396
|
reclamar: (o) => {
|
|
@@ -12402,25 +12404,25 @@ function crearClienteApi(base, token, f = fetch) {
|
|
|
12402
12404
|
await llamar("POST", `/api/pruebas-voz/${encodeURIComponent(id3)}/resultado`, cuerpo, {}, senal);
|
|
12403
12405
|
},
|
|
12404
12406
|
async resultadoQuitarFondo(id3, r2, senal) {
|
|
12405
|
-
const
|
|
12407
|
+
const ruta2 = `/api/trabajos-fondo/${encodeURIComponent(id3)}`;
|
|
12406
12408
|
if (r2.estado === "error") {
|
|
12407
|
-
await llamar("POST", `${
|
|
12409
|
+
await llamar("POST", `${ruta2}/resultado`, { estado: "error", causa: acotarTexto(r2.causa, LIMITES.causa, "fallo sin causa conocida") }, {}, senal);
|
|
12408
12410
|
return;
|
|
12409
12411
|
}
|
|
12410
12412
|
const { png, ...resto } = r2;
|
|
12411
12413
|
if (png.byteLength <= MAX_BYTES_PNG_BASE64) {
|
|
12412
|
-
await llamar("POST", `${
|
|
12414
|
+
await llamar("POST", `${ruta2}/resultado`, { ...resto, png_base64: png.toString("base64") }, {}, senal);
|
|
12413
12415
|
return;
|
|
12414
12416
|
}
|
|
12415
|
-
const sub = await llamar("POST", `${
|
|
12417
|
+
const sub = await llamar("POST", `${ruta2}/url`, {}, {}, senal);
|
|
12416
12418
|
const put = await fr2(sub.url, { method: "PUT", headers: sub.cabeceras, body: new Uint8Array(png), signal: conPlazo(senal) });
|
|
12417
12419
|
if (!put.ok) throw new ErrorApi(put.status, `la subida a S3 del PNG sin fondo fall\xF3 (HTTP ${put.status})`);
|
|
12418
|
-
await llamar("POST", `${
|
|
12420
|
+
await llamar("POST", `${ruta2}/resultado`, { ...resto, clave: sub.clave }, {}, senal);
|
|
12419
12421
|
},
|
|
12420
12422
|
async resultadoStoryboard(id3, r2, senal) {
|
|
12421
|
-
const
|
|
12423
|
+
const ruta2 = `/api/storyboards/${encodeURIComponent(id3)}`;
|
|
12422
12424
|
if (r2.estado === "error") {
|
|
12423
|
-
await llamar("POST", `${
|
|
12425
|
+
await llamar("POST", `${ruta2}/resultado`, { ...r2, causa: acotarTexto(r2.causa, LIMITES.causa, "fallo sin causa conocida") }, {}, senal);
|
|
12424
12426
|
return;
|
|
12425
12427
|
}
|
|
12426
12428
|
const ajustes = await llamar("GET", "/api/ajustes", void 0, {}, senal);
|
|
@@ -12430,7 +12432,7 @@ function crearClienteApi(base, token, f = fetch) {
|
|
|
12430
12432
|
const bytes = await readFile2(rutaLocal);
|
|
12431
12433
|
const meta = { bytes: bytes.byteLength, sha256: createHash4("sha256").update(bytes).digest("hex") };
|
|
12432
12434
|
if (ajustes.s3?.bucket) {
|
|
12433
|
-
const sub = await llamar("POST", `${
|
|
12435
|
+
const sub = await llamar("POST", `${ruta2}/url`, { archivo: k }, {}, senal);
|
|
12434
12436
|
const put = await fr2(sub.url, { method: "PUT", headers: sub.cabeceras, body: new Uint8Array(bytes), signal: conPlazo(senal) });
|
|
12435
12437
|
if (!put.ok) throw new ErrorApi(put.status, `la subida a S3 de ${basename3(rutaLocal)} fall\xF3 (HTTP ${put.status})`);
|
|
12436
12438
|
archivos[k] = meta;
|
|
@@ -12438,7 +12440,7 @@ function crearClienteApi(base, token, f = fetch) {
|
|
|
12438
12440
|
}
|
|
12439
12441
|
const { archivos: _a2, ...resto } = r2;
|
|
12440
12442
|
void _a2;
|
|
12441
|
-
await llamar("POST", `${
|
|
12443
|
+
await llamar("POST", `${ruta2}/resultado`, { ...resto, archivos }, {}, senal);
|
|
12442
12444
|
},
|
|
12443
12445
|
async progresoStoryboard(id3, senal) {
|
|
12444
12446
|
await llamar("POST", `/api/storyboards/${encodeURIComponent(id3)}/progreso`, {}, {}, senal);
|
|
@@ -12466,17 +12468,17 @@ function crearClienteApi(base, token, f = fetch) {
|
|
|
12466
12468
|
}
|
|
12467
12469
|
},
|
|
12468
12470
|
fallo: (id3, x2) => llamar("POST", `/api/videos/${id3}/fallo`, { etapa: acotarOpcional(x2.etapa, LIMITES.etapa) ?? null, causa: acotarTexto(x2.causa, LIMITES.causa, "fallo sin causa conocida"), codigo: Number.isInteger(x2.codigo) ? x2.codigo : null, max_reintentos: x2.maxReintentos, reintentable: x2.reintentable, ...camposCosto(x2), ...x2.reclamo ? { reclamo: x2.reclamo } : {} }),
|
|
12469
|
-
async adjuntarMp4(id3, version2,
|
|
12471
|
+
async adjuntarMp4(id3, version2, ruta2, o = {}) {
|
|
12470
12472
|
const signal = conPlazo(o.senal);
|
|
12471
12473
|
const rec = cabReclamo(o.reclamo);
|
|
12472
|
-
const bytes = await readFile2(
|
|
12474
|
+
const bytes = await readFile2(ruta2);
|
|
12473
12475
|
const ajustes = await llamar("GET", "/api/ajustes");
|
|
12474
12476
|
const base_mp4 = `/api/videos/${id3}/versiones/${version2}/mp4`;
|
|
12475
12477
|
if (ajustes.s3?.bucket) {
|
|
12476
12478
|
const sub = await llamar("POST", `${base_mp4}/url`, {}, rec);
|
|
12477
12479
|
const put = await fr2(sub.url, { method: "PUT", headers: sub.cabeceras, body: bytes, signal });
|
|
12478
12480
|
if (!put.ok) throw new ErrorApi(put.status, `la subida a S3 fall\xF3 (HTTP ${put.status})`);
|
|
12479
|
-
return llamar("POST", `${base_mp4}/confirmar`, { nombre: basename3(
|
|
12481
|
+
return llamar("POST", `${base_mp4}/confirmar`, { nombre: basename3(ruta2), ...camposCosto(o), ...o.revision ? { revision: o.revision } : {}, ...o.renders?.length ? { renders: o.renders } : {}, ...duracionValida(o.duracionS) ? { duracion_s: o.duracionS } : {} }, rec);
|
|
12480
12482
|
}
|
|
12481
12483
|
const form = new FormData();
|
|
12482
12484
|
const costo = camposCosto(o);
|
|
@@ -12485,20 +12487,20 @@ function crearClienteApi(base, token, f = fetch) {
|
|
|
12485
12487
|
if (o.revision) form.append("revision", JSON.stringify(o.revision));
|
|
12486
12488
|
if (duracionValida(o.duracionS)) form.append("duracion_s", String(o.duracionS));
|
|
12487
12489
|
if (o.renders?.length) form.append("renders", JSON.stringify(o.renders));
|
|
12488
|
-
form.append("archivo", new Blob([bytes], { type: "video/mp4" }), basename3(
|
|
12489
|
-
return
|
|
12490
|
+
form.append("archivo", new Blob([bytes], { type: "video/mp4" }), basename3(ruta2));
|
|
12491
|
+
return leer3(await fr2(`${base}${base_mp4}`, { method: "POST", headers: cab(rec), body: form, signal }));
|
|
12490
12492
|
},
|
|
12491
|
-
async adjuntarRender(id3, version2, clave,
|
|
12493
|
+
async adjuntarRender(id3, version2, clave, ruta2, revision, o = {}) {
|
|
12492
12494
|
try {
|
|
12493
|
-
await subirRender(id3, version2, clave,
|
|
12495
|
+
await subirRender(id3, version2, clave, ruta2, revision, o);
|
|
12494
12496
|
} catch (e7) {
|
|
12495
12497
|
if (e7 instanceof ErrorApi && e7.estado === 404 && e7.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");
|
|
12496
12498
|
throw e7;
|
|
12497
12499
|
}
|
|
12498
12500
|
},
|
|
12499
|
-
async adjuntarPoster(id3, version2, clave,
|
|
12501
|
+
async adjuntarPoster(id3, version2, clave, ruta2, o = {}) {
|
|
12500
12502
|
try {
|
|
12501
|
-
await subirPoster(id3, version2, clave,
|
|
12503
|
+
await subirPoster(id3, version2, clave, ruta2, o);
|
|
12502
12504
|
} catch (e7) {
|
|
12503
12505
|
if (e7 instanceof ErrorApi && (e7.estado === 404 && e7.message === "Not Found" || e7.estado === 400 && /es el principal|debe ser un MP4|render subido/.test(e7.message))) {
|
|
12504
12506
|
throw new ErrorApi(501, "la API no admite p\xF3sters todav\xEDa (CLA-171): actualiza el servidor");
|
|
@@ -12506,9 +12508,9 @@ function crearClienteApi(base, token, f = fetch) {
|
|
|
12506
12508
|
throw e7;
|
|
12507
12509
|
}
|
|
12508
12510
|
},
|
|
12509
|
-
async adjuntarHojaParecido(id3, version2, clave,
|
|
12511
|
+
async adjuntarHojaParecido(id3, version2, clave, ruta2, o = {}) {
|
|
12510
12512
|
try {
|
|
12511
|
-
await subirPoster(id3, version2, clave,
|
|
12513
|
+
await subirPoster(id3, version2, clave, ruta2, o, "parecido");
|
|
12512
12514
|
} catch (e7) {
|
|
12513
12515
|
if (e7 instanceof ErrorApi && (e7.estado === 404 && e7.message === "Not Found" || e7.estado === 400 && /archivo debe ser|es el principal|debe ser un MP4|render subido/.test(e7.message))) {
|
|
12514
12516
|
throw new ErrorApi(501, "la API no admite la hoja de parecido todav\xEDa (CLA-167): actualiza el servidor");
|
|
@@ -12516,9 +12518,9 @@ function crearClienteApi(base, token, f = fetch) {
|
|
|
12516
12518
|
throw e7;
|
|
12517
12519
|
}
|
|
12518
12520
|
},
|
|
12519
|
-
async adjuntarPrevia(id3, version2,
|
|
12521
|
+
async adjuntarPrevia(id3, version2, ruta2, o = {}) {
|
|
12520
12522
|
try {
|
|
12521
|
-
await subirPrevia(id3, version2,
|
|
12523
|
+
await subirPrevia(id3, version2, ruta2, o);
|
|
12522
12524
|
} catch (e7) {
|
|
12523
12525
|
if (e7 instanceof ErrorApi && e7.estado === 404 && e7.message === "Not Found") throw new ErrorApi(501, "la API no admite previas todav\xEDa (CLA-102): actualiza el servidor antes que el worker");
|
|
12524
12526
|
throw e7;
|
|
@@ -12526,7 +12528,7 @@ function crearClienteApi(base, token, f = fetch) {
|
|
|
12526
12528
|
},
|
|
12527
12529
|
async adjuntarArtefacto(id3, version2, tipo, clave, contenido, o = {}) {
|
|
12528
12530
|
try {
|
|
12529
|
-
await
|
|
12531
|
+
await leer3(await fr2(`${base}/api/videos/${id3}/versiones/${version2}/artefactos/${encodeURIComponent(tipo)}/${encodeURIComponent(clave)}`, {
|
|
12530
12532
|
method: "POST",
|
|
12531
12533
|
headers: cab({ "content-type": "application/json", ...cabReclamo(o.reclamo) }),
|
|
12532
12534
|
body: JSON.stringify(contenido),
|
|
@@ -12537,12 +12539,12 @@ function crearClienteApi(base, token, f = fetch) {
|
|
|
12537
12539
|
throw e7;
|
|
12538
12540
|
}
|
|
12539
12541
|
},
|
|
12540
|
-
async adjuntarPieza(id3, version2,
|
|
12542
|
+
async adjuntarPieza(id3, version2, ruta2, senal, reclamo) {
|
|
12541
12543
|
const signal = conPlazo(senal);
|
|
12542
12544
|
const rec = reclamo ? { "x-claqueta-reclamo": reclamo } : {};
|
|
12543
|
-
const nombre = basename3(
|
|
12545
|
+
const nombre = basename3(ruta2);
|
|
12544
12546
|
const tipo = MIME_PIEZA[nombre.split(".").pop().toLowerCase()] ?? "application/octet-stream";
|
|
12545
|
-
const bytes = await readFile2(
|
|
12547
|
+
const bytes = await readFile2(ruta2);
|
|
12546
12548
|
const ajustes = await llamar("GET", "/api/ajustes");
|
|
12547
12549
|
const base_pz = `/api/videos/${id3}/versiones/${version2}/piezas/${encodeURIComponent(nombre)}`;
|
|
12548
12550
|
if (ajustes.s3?.bucket) {
|
|
@@ -12554,11 +12556,11 @@ function crearClienteApi(base, token, f = fetch) {
|
|
|
12554
12556
|
}
|
|
12555
12557
|
const form = new FormData();
|
|
12556
12558
|
form.append("archivo", new Blob([bytes], { type: tipo }), nombre);
|
|
12557
|
-
await
|
|
12559
|
+
await leer3(await fr2(`${base}${base_pz}`, { method: "POST", headers: cab(rec), body: form, signal }));
|
|
12558
12560
|
},
|
|
12559
|
-
async adjuntarInsumo(id3, version2,
|
|
12561
|
+
async adjuntarInsumo(id3, version2, ruta2, rutaArchivo, o = {}) {
|
|
12560
12562
|
try {
|
|
12561
|
-
await subirInsumo(id3, version2,
|
|
12563
|
+
await subirInsumo(id3, version2, ruta2, rutaArchivo, o);
|
|
12562
12564
|
} catch (e7) {
|
|
12563
12565
|
if (e7 instanceof ErrorApi && e7.estado === 404 && e7.message === "Not Found") throw new ErrorApi(501, "la API no admite insumos de versi\xF3n todav\xEDa (CLA-203)");
|
|
12564
12566
|
throw e7;
|
|
@@ -12621,8 +12623,8 @@ function verificarIntegridad(id3, esperado, datos) {
|
|
|
12621
12623
|
if (md5 !== etag) throw new ErrorMedia(`el asset ${id3} no coincide con su ETag (baj\xF3 md5 ${md5.slice(0, 12)}\u2026, esperado ${etag.slice(0, 12)}\u2026)`, true);
|
|
12622
12624
|
return;
|
|
12623
12625
|
}
|
|
12624
|
-
const
|
|
12625
|
-
if (
|
|
12626
|
+
const sha3 = createHash5("sha256").update(datos).digest("hex");
|
|
12627
|
+
if (sha3 !== esperado) throw new ErrorMedia(`el asset ${id3} no coincide con su sha256 (baj\xF3 ${sha3.slice(0, 12)}\u2026, esperado ${esperado.slice(0, 12)}\u2026)`, true);
|
|
12626
12628
|
}
|
|
12627
12629
|
async function descargarMedia(media, pedidoDir, descargar2 = (u2, senal2) => fetch(u2, senal2 ? { signal: senal2 } : {}), senal, clips = []) {
|
|
12628
12630
|
const salida = {};
|
|
@@ -12650,10 +12652,10 @@ async function bajarAsset(id3, a, pedidoDir, descargar2, senal) {
|
|
|
12650
12652
|
const datos = Buffer.from(await r2.arrayBuffer());
|
|
12651
12653
|
if (a.bytes > 0 && datos.length !== a.bytes) throw new ErrorMedia(`el asset ${id3} baj\xF3 con ${datos.length} bytes y deber\xEDa tener ${a.bytes}`, true);
|
|
12652
12654
|
verificarIntegridad(id3, a.sha256, datos);
|
|
12653
|
-
const
|
|
12655
|
+
const ruta2 = `media/${id3}${extensionDe(a)}`;
|
|
12654
12656
|
await mkdir2(join13(pedidoDir, "media"), { recursive: true });
|
|
12655
|
-
await writeFile2(join13(pedidoDir,
|
|
12656
|
-
return { ruta, tipo: a.tipo, nombre: a.nombre, mime: a.mime };
|
|
12657
|
+
await writeFile2(join13(pedidoDir, ruta2), datos);
|
|
12658
|
+
return { ruta: ruta2, tipo: a.tipo, nombre: a.nombre, mime: a.mime };
|
|
12657
12659
|
}
|
|
12658
12660
|
function idsDeClips(pedido) {
|
|
12659
12661
|
const escenas = pedido?.guion?.escenas;
|
|
@@ -13001,10 +13003,10 @@ async function extraerFotogramas(video, destino, bins, correr, n = MAX_FOTOGRAMA
|
|
|
13001
13003
|
const rutas = [];
|
|
13002
13004
|
const usados = [];
|
|
13003
13005
|
for (const t of tiempos) {
|
|
13004
|
-
const
|
|
13005
|
-
const r2 = await correr(bins.ffmpeg, ["-v", "error", "-y", "-ss", t.toFixed(3), "-i", video, "-frames:v", "1", "-vf", "scale=-2:'min(720,ih)'", "-q:v", "3",
|
|
13006
|
-
if (r2.codigo === 0 && existsSync7(
|
|
13007
|
-
rutas.push(
|
|
13006
|
+
const ruta2 = join17(destino, `f-${String(rutas.length + 1).padStart(2, "0")}.jpg`);
|
|
13007
|
+
const r2 = await correr(bins.ffmpeg, ["-v", "error", "-y", "-ss", t.toFixed(3), "-i", video, "-frames:v", "1", "-vf", "scale=-2:'min(720,ih)'", "-q:v", "3", ruta2], 3e4);
|
|
13008
|
+
if (r2.codigo === 0 && existsSync7(ruta2)) {
|
|
13009
|
+
rutas.push(ruta2);
|
|
13008
13010
|
usados.push(t);
|
|
13009
13011
|
}
|
|
13010
13012
|
}
|
|
@@ -13081,8 +13083,8 @@ function elegirReferencia(pedido, media, origen, motorDir) {
|
|
|
13081
13083
|
}
|
|
13082
13084
|
const estetica = (obj(origen?.["estetica"]) ? origen["estetica"]["nombre"] : void 0) ?? pedido["estetica"];
|
|
13083
13085
|
if (!motorDir || typeof estetica !== "string" || !/^[a-z0-9-]+$/.test(estetica)) return null;
|
|
13084
|
-
const
|
|
13085
|
-
return
|
|
13086
|
+
const ruta2 = videoDeEstetica(motorDir, estetica);
|
|
13087
|
+
return ruta2 ? { asset_id: null, nombre: basename4(ruta2), origen: "estetica", ruta: ruta2 } : null;
|
|
13086
13088
|
}
|
|
13087
13089
|
function videoDeEstetica(motorDir, estetica) {
|
|
13088
13090
|
const dir = join18(motorDir, "esteticas", estetica);
|
|
@@ -13341,6 +13343,16 @@ var PRESUPUESTO_POR_DEFECTO_USD = 6;
|
|
|
13341
13343
|
var FALLOS_PARA_APAGAR = 3;
|
|
13342
13344
|
var TOPE_DOCUMENTO = 200 * 1024;
|
|
13343
13345
|
var MINIMO_VUELTA_MS = 45e3;
|
|
13346
|
+
var LOG_ESPERA_MS = 6e4;
|
|
13347
|
+
var duracionTexto = (ms2) => {
|
|
13348
|
+
const s = Math.max(0, Math.round(ms2 / 1e3));
|
|
13349
|
+
return s < 60 ? `${s}s` : `${Math.floor(s / 60)}m${String(s % 60).padStart(2, "0")}s`;
|
|
13350
|
+
};
|
|
13351
|
+
function topeCompositor(opcionMs, familia) {
|
|
13352
|
+
if (opcionMs && opcionMs > 0) return { ms: opcionMs, origen: "opci\xF3n" };
|
|
13353
|
+
if (familia.topeS) return { ms: familia.topeS * 1e3, origen: "familia" };
|
|
13354
|
+
return { ms: TOPE_POR_DEFECTO_MS, origen: "por defecto" };
|
|
13355
|
+
}
|
|
13344
13356
|
var HF = `hyperframes@${HYPERFRAMES_VERSION}`;
|
|
13345
13357
|
var HERRAMIENTAS_PERMITIDAS = ["Read", "Write", "Edit", "Glob", "Grep", ...["check", "lint", "snapshot", "docs"].map((s) => `Bash(npx --yes ${HF} ${s}:*)`)];
|
|
13346
13358
|
var HERRAMIENTAS_PROHIBIDAS = ["WebFetch", "WebSearch", "Task", "Agent"];
|
|
@@ -13446,7 +13458,7 @@ function sha256Arbol(dir) {
|
|
|
13446
13458
|
recorrer("");
|
|
13447
13459
|
return h.digest("hex");
|
|
13448
13460
|
}
|
|
13449
|
-
var sha256Archivo = (
|
|
13461
|
+
var sha256Archivo = (ruta2) => createHash6("sha256").update(readFileSync12(ruta2)).digest("hex");
|
|
13450
13462
|
function crearCompositor(o, d = depsReales(o.plataforma)) {
|
|
13451
13463
|
let fallosSeguidos = 0;
|
|
13452
13464
|
let apagado2 = false;
|
|
@@ -13458,7 +13470,7 @@ function crearCompositor(o, d = depsReales(o.plataforma)) {
|
|
|
13458
13470
|
const respaldo2 = (motivo, detalle) => {
|
|
13459
13471
|
registro.segundos = Math.round((d.ahora() - inicio) / 100) / 10;
|
|
13460
13472
|
registro.motivo = detalle ? `${motivo}: ${detalle}` : motivo;
|
|
13461
|
-
|
|
13473
|
+
anotarFallo2(e7.log);
|
|
13462
13474
|
return { tipo: "respaldo", motivo, detalle, registro };
|
|
13463
13475
|
};
|
|
13464
13476
|
const claude = d.buscarEjecutable(o.comando, o.env);
|
|
@@ -13481,8 +13493,11 @@ function crearCompositor(o, d = depsReales(o.plataforma)) {
|
|
|
13481
13493
|
if (!prueba.ok) return sinNavegador(`${prueba.motivo} \u2014 ${describirNavegador(navegador, sistema)}${navegador.fuente === "variable" ? `; quita ${navegador.variable} para usar el Chrome propio` : ""}`);
|
|
13482
13494
|
const env = entornoAgente(o.env, node, claude, navegador.ruta);
|
|
13483
13495
|
const ctx = { node, env };
|
|
13484
|
-
const
|
|
13496
|
+
const tope = topeCompositor(o.topeMs, e7.familia);
|
|
13497
|
+
const topeMs = tope.ms;
|
|
13485
13498
|
const limite = inicio + topeMs;
|
|
13499
|
+
const minimoVuelta = o.minimoVueltaMs ?? MINIMO_VUELTA_MS;
|
|
13500
|
+
e7.log(`compositor: tope propio ${duracionTexto(topeMs)} (${tope.origen === "opci\xF3n" ? "--compositor-tiempo" : tope.origen === "familia" ? `familia ${e7.familia.nombre}` : "por defecto"}), aparte del tope por formato del motor`);
|
|
13486
13501
|
const dir = join20(e7.raiz, "composicion");
|
|
13487
13502
|
const valida = join20(e7.raiz, "composicion-valida");
|
|
13488
13503
|
const enc = join20(dir, "_encargo");
|
|
@@ -13511,20 +13526,27 @@ function crearCompositor(o, d = depsReales(o.plataforma)) {
|
|
|
13511
13526
|
let hayTokens = false;
|
|
13512
13527
|
for (let vuelta = 1; vuelta <= MAX_VUELTAS; vuelta++) {
|
|
13513
13528
|
const resta = limite - d.ahora();
|
|
13514
|
-
if (resta <
|
|
13515
|
-
if (vuelta === 1 || !ultimaValida) motivoFinal = { motivo: "tiempo agotado", detalle: `quedaban ${
|
|
13529
|
+
if (resta < minimoVuelta) {
|
|
13530
|
+
if (vuelta === 1 || !ultimaValida) motivoFinal = { motivo: "tiempo agotado", detalle: `quedaban ${duracionTexto(resta)} de su tope de ${duracionTexto(topeMs)}, menos de lo que pide una vuelta` };
|
|
13516
13531
|
break;
|
|
13517
13532
|
}
|
|
13518
13533
|
const presupuesto = Math.max(0.5, o.presupuestoUsd - gastado);
|
|
13519
13534
|
await rm3(join20(dir, "LISTO.json"), { force: true });
|
|
13520
13535
|
const prompt = vuelta === 1 ? promptInicial(e7) : ultimaValida ? promptRevision(hojasPrevias, hojaBase, medicionPrevia, reglaFija(e7.marca)) : promptCorreccion(erroresPrevios);
|
|
13521
13536
|
e7.onAvance(5 + (vuelta - 1) * 45, `compositor: vuelta ${vuelta} de ${MAX_VUELTAS} (${o.ejecutor})`);
|
|
13522
|
-
e7.log(`compositor: vuelta ${vuelta} (
|
|
13537
|
+
e7.log(`compositor: vuelta ${vuelta} de ${MAX_VUELTAS}\u2026 (quedan ${duracionTexto(resta)} del tope, presupuesto ${presupuesto.toFixed(2)} USD)`);
|
|
13523
13538
|
const t02 = d.ahora();
|
|
13539
|
+
let ultimoLog = t02;
|
|
13524
13540
|
const reloj = setInterval(() => {
|
|
13525
|
-
const
|
|
13526
|
-
|
|
13541
|
+
const ahora = d.ahora();
|
|
13542
|
+
const f = Math.min(1, (ahora - t02) / resta);
|
|
13543
|
+
e7.onAvance(5 + (vuelta - 1) * 45 + Math.round(f * 40), `compositor: vuelta ${vuelta}, ${Math.round((ahora - t02) / 1e3)} s`);
|
|
13544
|
+
if (ahora - ultimoLog >= LOG_ESPERA_MS) {
|
|
13545
|
+
ultimoLog = ahora;
|
|
13546
|
+
e7.log(`compositor: vuelta ${vuelta}\u2026 ${duracionTexto(ahora - t02)} de ${duracionTexto(resta)}`);
|
|
13547
|
+
}
|
|
13527
13548
|
}, 15e3);
|
|
13549
|
+
const finVuelta = (como) => e7.log(`compositor: vuelta ${vuelta} termin\xF3 en ${duracionTexto(d.ahora() - t02)} (${como})`);
|
|
13528
13550
|
let r2;
|
|
13529
13551
|
try {
|
|
13530
13552
|
r2 = await d.lanzar(claude, argumentosClaude(prompt, dir, presupuesto), { cwd: dir, env, timeoutMs: resta, ...e7.senal ? { senal: e7.senal } : {} });
|
|
@@ -13532,7 +13554,10 @@ function crearCompositor(o, d = depsReales(o.plataforma)) {
|
|
|
13532
13554
|
clearInterval(reloj);
|
|
13533
13555
|
}
|
|
13534
13556
|
registro.vueltas = vuelta;
|
|
13535
|
-
if (r2.abortado)
|
|
13557
|
+
if (r2.abortado) {
|
|
13558
|
+
finVuelta("cancelada");
|
|
13559
|
+
return { tipo: "cancelado" };
|
|
13560
|
+
}
|
|
13536
13561
|
const uso = leerSalidaClaude(r2.stdout);
|
|
13537
13562
|
if (uso.costo !== null) {
|
|
13538
13563
|
gastado += uso.costo;
|
|
@@ -13546,20 +13571,24 @@ function crearCompositor(o, d = depsReales(o.plataforma)) {
|
|
|
13546
13571
|
registro.modelo = uso.modelo ?? registro.modelo;
|
|
13547
13572
|
registro.tokens = hayTokens ? { ...tokens } : null;
|
|
13548
13573
|
if (r2.tiempoAgotado) {
|
|
13549
|
-
|
|
13574
|
+
finVuelta("tiempo agotado");
|
|
13575
|
+
motivoFinal = { motivo: "tiempo agotado", detalle: `la vuelta ${vuelta} super\xF3 el tope del compositor (${duracionTexto(topeMs)})` };
|
|
13550
13576
|
break;
|
|
13551
13577
|
}
|
|
13552
13578
|
if (r2.noEncontrado) {
|
|
13579
|
+
finVuelta("no se pudo lanzar");
|
|
13553
13580
|
motivoFinal = { motivo: "ausente", detalle: `no se pudo lanzar ${o.comando}` };
|
|
13554
13581
|
break;
|
|
13555
13582
|
}
|
|
13556
13583
|
if (r2.codigo !== 0 || uso.error) {
|
|
13584
|
+
finVuelta("error");
|
|
13557
13585
|
const cola = (r2.stderr || "").trim().split("\n").slice(-2).join(" | ").slice(0, 200);
|
|
13558
13586
|
motivoFinal = { motivo: "error", detalle: r2.codigo !== 0 ? `la CLI sali\xF3 con c\xF3digo ${r2.codigo}${cola ? ` (${cola})` : ""}` : uso.error };
|
|
13559
13587
|
break;
|
|
13560
13588
|
}
|
|
13561
13589
|
const v2 = await validarVuelta(dir, e7.familia, ctx, d, vuelta);
|
|
13562
13590
|
if (!v2.ok) {
|
|
13591
|
+
finVuelta("inv\xE1lida");
|
|
13563
13592
|
erroresPrevios = v2.errores;
|
|
13564
13593
|
motivoFinal = { motivo: "composici\xF3n inv\xE1lida", detalle: v2.errores.slice(0, 3).join("; ").slice(0, 300) };
|
|
13565
13594
|
e7.log(`compositor: vuelta ${vuelta} inv\xE1lida: ${motivoFinal.detalle}`);
|
|
@@ -13569,13 +13598,17 @@ function crearCompositor(o, d = depsReales(o.plataforma)) {
|
|
|
13569
13598
|
ultimaValida = vuelta;
|
|
13570
13599
|
if (v2.notas) notas.push(v2.notas);
|
|
13571
13600
|
await copiarComposicion(dir, valida);
|
|
13572
|
-
|
|
13601
|
+
finVuelta("v\xE1lida");
|
|
13602
|
+
if (vuelta < MAX_VUELTAS && limite - d.ahora() < minimoVuelta) {
|
|
13603
|
+
e7.log(`compositor: no queda tiempo del tope para la vuelta ${vuelta + 1}; me quedo con la vuelta ${vuelta}`);
|
|
13604
|
+
break;
|
|
13605
|
+
}
|
|
13573
13606
|
if (vuelta < MAX_VUELTAS) {
|
|
13574
13607
|
e7.onAvance(48, "compositor: vista previa de la vuelta 1");
|
|
13575
13608
|
hojasPrevias = await d.hojas(dir, join20(enc, `hoja-vuelta${vuelta}`), ctx).catch(() => []);
|
|
13576
13609
|
if (e7.parecido && registro.parecido) {
|
|
13577
13610
|
e7.onAvance(49, `compositor: midiendo la vuelta ${vuelta} contra la referencia`);
|
|
13578
|
-
const medida = await medirVuelta(e7.parecido, dir, join20(e7.raiz, `previa-vuelta${vuelta}.mp4`), ctx, d, Math.min(5 * 6e4, limite - d.ahora() -
|
|
13611
|
+
const medida = await medirVuelta(e7.parecido, dir, join20(e7.raiz, `previa-vuelta${vuelta}.mp4`), ctx, d, Math.min(5 * 6e4, limite - d.ahora() - minimoVuelta));
|
|
13579
13612
|
if (typeof medida === "string") {
|
|
13580
13613
|
registro.parecido.motivo = medida;
|
|
13581
13614
|
e7.log(`compositor: sin medici\xF3n de parecido de la vuelta ${vuelta} (${medida})`);
|
|
@@ -13592,6 +13625,7 @@ function crearCompositor(o, d = depsReales(o.plataforma)) {
|
|
|
13592
13625
|
}
|
|
13593
13626
|
}
|
|
13594
13627
|
registro.segundos = Math.round((d.ahora() - inicio) / 100) / 10;
|
|
13628
|
+
e7.log(`compositor: ${registro.vueltas} ${registro.vueltas === 1 ? "vuelta" : "vueltas"} en ${duracionTexto(d.ahora() - inicio)} de ${duracionTexto(topeMs)}`);
|
|
13595
13629
|
if (motivoFinal && motivoFinal.motivo !== "composici\xF3n inv\xE1lida") e7.log(`compositor: vuelta ${registro.vueltas}: ${motivoFinal.motivo} (${motivoFinal.detalle})`);
|
|
13596
13630
|
if (!ultimaValida) return respaldo2(motivoFinal?.motivo ?? "composici\xF3n inv\xE1lida", motivoFinal?.detalle ?? "ninguna vuelta dej\xF3 una composici\xF3n v\xE1lida");
|
|
13597
13631
|
if (motivoFinal) notas.unshift(`la vuelta ${registro.vueltas} no sirvi\xF3 (${motivoFinal.motivo}: ${motivoFinal.detalle}); se usa la vuelta ${ultimaValida}`);
|
|
@@ -13603,14 +13637,14 @@ function crearCompositor(o, d = depsReales(o.plataforma)) {
|
|
|
13603
13637
|
e7.onAvance(100, `compositor: composici\xF3n lista (${registro.vueltas} ${registro.vueltas === 1 ? "vuelta" : "vueltas"})`);
|
|
13604
13638
|
return { tipo: "ok", dir: valida, registro, notas };
|
|
13605
13639
|
}
|
|
13606
|
-
function
|
|
13640
|
+
function anotarFallo2(log) {
|
|
13607
13641
|
fallosSeguidos++;
|
|
13608
13642
|
if (fallosSeguidos >= FALLOS_PARA_APAGAR && !apagado2) {
|
|
13609
13643
|
apagado2 = true;
|
|
13610
13644
|
log(`compositor: ${fallosSeguidos} fallos seguidos; lo apago el resto de la sesi\xF3n (los videos salen con la composici\xF3n de la familia)`);
|
|
13611
13645
|
}
|
|
13612
13646
|
}
|
|
13613
|
-
return { ejecutor: o.ejecutor, apagado: () => apagado2, familia: (n) => leerFamilia(o.motorDir, n), componer: componer2, anotarFallo };
|
|
13647
|
+
return { ejecutor: o.ejecutor, apagado: () => apagado2, familia: (n) => leerFamilia(o.motorDir, n), componer: componer2, anotarFallo: anotarFallo2 };
|
|
13614
13648
|
}
|
|
13615
13649
|
async function medirVuelta(p, dir, mp42, ctx, d, timeoutMs) {
|
|
13616
13650
|
if (timeoutMs < 3e4) return "no quedaba tiempo para la vista previa";
|
|
@@ -13681,7 +13715,7 @@ async function prepararEncargo(e7, enc, d) {
|
|
|
13681
13715
|
const carpeta2 = `ref-${i + 1}`;
|
|
13682
13716
|
try {
|
|
13683
13717
|
const f = await d.fotogramas(join20(e7.pedidoDir, local.ruta), join20(enc, "referencias", carpeta2));
|
|
13684
|
-
const cuadros = f.rutas.map((
|
|
13718
|
+
const cuadros = f.rutas.map((ruta2, k) => `\`_encargo/referencias/${carpeta2}/${ruta2.slice(ruta2.lastIndexOf("/") + 1)}\` (${f.tiempos[k].toFixed(1)} s)`);
|
|
13685
13719
|
const ritmo = f.escenas && f.duracion_s ? `; ${f.escenas} ${f.escenas === 1 ? "escena" : "escenas"} en ${f.duracion_s.toFixed(1)} s (\u2248 ${(f.duracion_s / f.escenas).toFixed(1)} s por escena)` : f.duracion_s ? `; dura ${f.duracion_s.toFixed(1)} s` : "";
|
|
13686
13720
|
lineasRef.push(`- video ${local.nombre ? `\xAB${local.nombre}\xBB` : r2.asset_id ?? ""} (fotogramas clave${ritmo})${que ? `: ${que}` : ""}: ${cuadros.join(", ")}`);
|
|
13687
13721
|
Object.assign(reg, { usada: true, fotogramas: f.rutas.length, duracion_s: f.duracion_s, escenas: f.escenas });
|
|
@@ -13981,17 +14015,17 @@ var intentar = (accion, queFallo, avisar) => {
|
|
|
13981
14015
|
}
|
|
13982
14016
|
};
|
|
13983
14017
|
function prepararMaquina(env = process.env, equipo = hostname3()) {
|
|
13984
|
-
const
|
|
14018
|
+
const ruta2 = rutaMaquina(env);
|
|
13985
14019
|
const dir = directorioConfig(env);
|
|
13986
14020
|
const asegurarPermisos = (avisar) => {
|
|
13987
14021
|
intentar(() => chmodSync4(dir, 448), `dejar ${dir} con permisos 0700 (chmod 700)`, avisar);
|
|
13988
14022
|
intentar(() => {
|
|
13989
|
-
if (process.platform !== "win32" && (statSync7(
|
|
13990
|
-
}, `dejar ${
|
|
14023
|
+
if (process.platform !== "win32" && (statSync7(ruta2).mode & 63) !== 0) chmodSync4(ruta2, 384);
|
|
14024
|
+
}, `dejar ${ruta2} con permisos 0600 (chmod 600)`, avisar);
|
|
13991
14025
|
};
|
|
13992
14026
|
let idPrevio;
|
|
13993
14027
|
try {
|
|
13994
|
-
const guardada = JSON.parse(readFileSync13(
|
|
14028
|
+
const guardada = JSON.parse(readFileSync13(ruta2, "utf8"));
|
|
13995
14029
|
if (esMaquinaValida(guardada)) return { maquina: { id: guardada.id, nombre: guardada.nombre }, existente: true, guardar: asegurarPermisos };
|
|
13996
14030
|
const id4 = guardada?.id;
|
|
13997
14031
|
if (RE_MAQUINA_ID.test(String(id4))) idPrevio = String(id4);
|
|
@@ -14003,14 +14037,14 @@ function prepararMaquina(env = process.env, equipo = hostname3()) {
|
|
|
14003
14037
|
return {
|
|
14004
14038
|
maquina,
|
|
14005
14039
|
existente: false,
|
|
14006
|
-
...legible === null ? { aviso: `Aviso: el nombre del equipo (${citar(equipo)}) no sirve como nombre de m\xE1quina (1 a 80 caracteres, al menos una letra o n\xFAmero, sin caracteres invisibles); se usa "${maquina.nombre}". Puedes cambiarlo editando "nombre" en ${
|
|
14040
|
+
...legible === null ? { aviso: `Aviso: el nombre del equipo (${citar(equipo)}) no sirve como nombre de m\xE1quina (1 a 80 caracteres, al menos una letra o n\xFAmero, sin caracteres invisibles); se usa "${maquina.nombre}". Puedes cambiarlo editando "nombre" en ${ruta2}.` } : {},
|
|
14007
14041
|
guardar(avisar) {
|
|
14008
14042
|
mkdirSync11(dir, { recursive: true, mode: 448 });
|
|
14009
|
-
const tmp = `${
|
|
14043
|
+
const tmp = `${ruta2}.${process.pid}.tmp`;
|
|
14010
14044
|
writeFileSync9(tmp, `${JSON.stringify(maquina, null, 2)}
|
|
14011
14045
|
`, { mode: 384 });
|
|
14012
14046
|
chmodSync4(tmp, 384);
|
|
14013
|
-
renameSync5(tmp,
|
|
14047
|
+
renameSync5(tmp, ruta2);
|
|
14014
14048
|
asegurarPermisos(avisar);
|
|
14015
14049
|
}
|
|
14016
14050
|
};
|
|
@@ -14480,8 +14514,8 @@ async function ejecutarSetup(op2, deps = depsReales3()) {
|
|
|
14480
14514
|
cb2.cerrar();
|
|
14481
14515
|
}
|
|
14482
14516
|
const { token, reemplazados } = recibido;
|
|
14483
|
-
const
|
|
14484
|
-
salida(`Token recibido (${enmascarar(token)}) para ${nombre} y guardado en ${
|
|
14517
|
+
const ruta2 = guardarConfig({ url: apiUrl, token, herramienta }, env);
|
|
14518
|
+
salida(`Token recibido (${enmascarar(token)}) para ${nombre} y guardado en ${ruta2} (permisos 0600).`);
|
|
14485
14519
|
if (reemplazados !== void 0 && reemplazados > 0) {
|
|
14486
14520
|
salida(`La API revoc\xF3 ${reemplazados === 1 ? "el token anterior" : `${reemplazados} tokens anteriores`} de ${nombre} en esta m\xE1quina: se renov\xF3 en vez de duplicarse.`);
|
|
14487
14521
|
}
|
|
@@ -14524,7 +14558,7 @@ async function ejecutarSetup(op2, deps = depsReales3()) {
|
|
|
14524
14558
|
clearTimeout(reloj);
|
|
14525
14559
|
}
|
|
14526
14560
|
}
|
|
14527
|
-
return { rutaConfig:
|
|
14561
|
+
return { rutaConfig: ruta2, apiUrl, registrado, herramienta, agente, maquina, ...reemplazados !== void 0 ? { reemplazados } : {}, ...mcpLocal ? { mcpLocal } : {} };
|
|
14528
14562
|
}
|
|
14529
14563
|
|
|
14530
14564
|
// src/doctor.ts
|
|
@@ -14760,15 +14794,15 @@ async function chequeosAws(d, o, imagen2, imagenLocalP) {
|
|
|
14760
14794
|
}
|
|
14761
14795
|
function chequeoConfig(d, o) {
|
|
14762
14796
|
const titulo = "Archivo de configuraci\xF3n";
|
|
14763
|
-
const
|
|
14797
|
+
const ruta2 = rutaConfig(d.env);
|
|
14764
14798
|
const dir = directorioConfig(d.env);
|
|
14765
14799
|
const chequeos = [];
|
|
14766
14800
|
let archivo2 = {};
|
|
14767
14801
|
let roto = false;
|
|
14768
|
-
const existe4 = d.fs.existe(
|
|
14802
|
+
const existe4 = d.fs.existe(ruta2);
|
|
14769
14803
|
if (existe4) {
|
|
14770
14804
|
try {
|
|
14771
|
-
const j2 = JSON.parse(d.fs.leer(
|
|
14805
|
+
const j2 = JSON.parse(d.fs.leer(ruta2));
|
|
14772
14806
|
archivo2 = { ...typeof j2["CLAQUETA_URL"] === "string" ? { url: j2["CLAQUETA_URL"] } : {}, ...typeof j2["CLAQUETA_TOKEN"] === "string" ? { token: j2["CLAQUETA_TOKEN"] } : {} };
|
|
14773
14807
|
} catch {
|
|
14774
14808
|
roto = true;
|
|
@@ -14787,21 +14821,21 @@ function chequeoConfig(d, o) {
|
|
|
14787
14821
|
errorUrl = e7.message;
|
|
14788
14822
|
}
|
|
14789
14823
|
const arreglo = "npx claqueta-mcp@latest setup --modo escritura";
|
|
14790
|
-
if (roto) chequeos.push({ id: "config", titulo, estado: "bloqueo", mensaje: `${
|
|
14791
|
-
else if (!existe4 && !token) chequeos.push({ id: "config", titulo, estado: "bloqueo", mensaje: `No existe ${
|
|
14792
|
-
else if (!token) chequeos.push({ id: "config", titulo, estado: "bloqueo", mensaje: `${
|
|
14824
|
+
if (roto) chequeos.push({ id: "config", titulo, estado: "bloqueo", mensaje: `${ruta2} no es un JSON v\xE1lido.`, arreglo });
|
|
14825
|
+
else if (!existe4 && !token) chequeos.push({ id: "config", titulo, estado: "bloqueo", mensaje: `No existe ${ruta2} y no hay CLAQUETA_TOKEN en el entorno.`, arreglo });
|
|
14826
|
+
else if (!token) chequeos.push({ id: "config", titulo, estado: "bloqueo", mensaje: `${ruta2} no trae el token (CLAQUETA_TOKEN).`, arreglo });
|
|
14793
14827
|
else if (errorUrl) chequeos.push({ id: "config", titulo, estado: "bloqueo", mensaje: errorUrl, arreglo: `npx claqueta-mcp@latest doctor --url ${API_POR_DEFECTO} (o corrige CLAQUETA_URL)` });
|
|
14794
14828
|
else {
|
|
14795
|
-
const origen = tokenExplicito ? "el token reci\xE9n guardado" : !existe4 || envToken ? "variables CLAQUETA_*" :
|
|
14829
|
+
const origen = tokenExplicito ? "el token reci\xE9n guardado" : !existe4 || envToken ? "variables CLAQUETA_*" : ruta2;
|
|
14796
14830
|
chequeos.push({ id: "config", titulo, estado: "ok", mensaje: `URL ${url} y token cq_*** desde ${origen}.` });
|
|
14797
14831
|
}
|
|
14798
14832
|
if (existe4 && d.os.plataforma !== "win32") {
|
|
14799
|
-
const mArch = d.fs.modo(
|
|
14833
|
+
const mArch = d.fs.modo(ruta2);
|
|
14800
14834
|
const mDir = d.fs.modo(dir);
|
|
14801
14835
|
const abiertoA = mArch !== null && (mArch & 63) !== 0;
|
|
14802
14836
|
const abiertoD = mDir !== null && (mDir & 63) !== 0;
|
|
14803
14837
|
if (abiertoA || abiertoD) {
|
|
14804
|
-
const cmds = [...abiertoD ? [`chmod 700 ${q2(dir)}`] : [], ...abiertoA ? [`chmod 600 ${q2(
|
|
14838
|
+
const cmds = [...abiertoD ? [`chmod 700 ${q2(dir)}`] : [], ...abiertoA ? [`chmod 600 ${q2(ruta2)}`] : []];
|
|
14805
14839
|
const que = [...abiertoD ? [`la carpeta (${(mDir & 511).toString(8)}, debe ser 700)`] : [], ...abiertoA ? [`el archivo (${(mArch & 511).toString(8)}, debe ser 600)`] : []];
|
|
14806
14840
|
chequeos.push({ id: "config-permisos", titulo: "Permisos de la configuraci\xF3n", estado: "aviso", mensaje: `Otros usuarios podr\xEDan leer ${que.join(" y ")}; ah\xED vive tu token.`, arreglo: cmds.join(" && ") });
|
|
14807
14841
|
} else chequeos.push({ id: "config-permisos", titulo: "Permisos de la configuraci\xF3n", estado: "ok", mensaje: "Archivo 600 y carpeta 700." });
|
|
@@ -14997,11 +15031,11 @@ function chequeoDiscoLocal(d, dir) {
|
|
|
14997
15031
|
}
|
|
14998
15032
|
function chequeoBloqueo(d) {
|
|
14999
15033
|
const titulo = "Bloqueo del motor";
|
|
15000
|
-
const
|
|
15001
|
-
if (!d.fs.existe(
|
|
15034
|
+
const ruta2 = rutaBloqueoLocal(d.os.casa);
|
|
15035
|
+
if (!d.fs.existe(ruta2)) return { id: "local-bloqueo", titulo, estado: "ok", mensaje: "Libre: no hay ning\xFAn componer, previa, render ni video de la cola o del worker en curso." };
|
|
15002
15036
|
const dueno = (() => {
|
|
15003
15037
|
try {
|
|
15004
|
-
return JSON.parse(d.fs.leer(
|
|
15038
|
+
return JSON.parse(d.fs.leer(ruta2));
|
|
15005
15039
|
} catch {
|
|
15006
15040
|
return null;
|
|
15007
15041
|
}
|
|
@@ -15014,8 +15048,8 @@ function chequeoBloqueo(d) {
|
|
|
15014
15048
|
id: "local-bloqueo",
|
|
15015
15049
|
titulo,
|
|
15016
15050
|
estado: "aviso",
|
|
15017
|
-
mensaje: `Bloqueo hu\xE9rfano en ${
|
|
15018
|
-
arreglo: `rm ${q2(
|
|
15051
|
+
mensaje: `Bloqueo hu\xE9rfano en ${ruta2} (${pid === null ? "ilegible" : `el proceso ${pid} ya no existe`}): qued\xF3 de una sesi\xF3n que se cerr\xF3 a media corrida. El siguiente paso lo reemplaza solo, pero puedes borrarlo.`,
|
|
15052
|
+
arreglo: `rm ${q2(ruta2)}`
|
|
15019
15053
|
};
|
|
15020
15054
|
}
|
|
15021
15055
|
async function chequeosMcpLocal(o, d, imagen2) {
|
|
@@ -15164,7 +15198,7 @@ var codigoSalida = (inf) => inf.resumen.bloqueo > 0 ? 1 : 0;
|
|
|
15164
15198
|
// src/worker-cli.ts
|
|
15165
15199
|
import { mkdirSync as mkdirSync12 } from "node:fs";
|
|
15166
15200
|
import { homedir as homedir7, hostname as hostname6 } from "node:os";
|
|
15167
|
-
import { dirname as dirname12, join as
|
|
15201
|
+
import { dirname as dirname12, join as join34 } from "node:path";
|
|
15168
15202
|
|
|
15169
15203
|
// src/worker/avance.ts
|
|
15170
15204
|
var NOMBRES = {
|
|
@@ -15285,6 +15319,21 @@ function crearAvance(salida, ops = {}) {
|
|
|
15285
15319
|
};
|
|
15286
15320
|
}
|
|
15287
15321
|
|
|
15322
|
+
// src/worker/dormir.ts
|
|
15323
|
+
function dormir(ms2, ...senales) {
|
|
15324
|
+
const activas = senales.filter((s) => s !== void 0);
|
|
15325
|
+
if (activas.some((s) => s.aborted)) return Promise.resolve();
|
|
15326
|
+
return new Promise((resolver) => {
|
|
15327
|
+
const fin = () => {
|
|
15328
|
+
clearTimeout(t);
|
|
15329
|
+
for (const s of activas) s.removeEventListener("abort", fin);
|
|
15330
|
+
resolver();
|
|
15331
|
+
};
|
|
15332
|
+
const t = setTimeout(fin, Math.max(0, ms2));
|
|
15333
|
+
for (const s of activas) s.addEventListener("abort", fin, { once: true });
|
|
15334
|
+
});
|
|
15335
|
+
}
|
|
15336
|
+
|
|
15288
15337
|
// src/worker/motor-nuevo.ts
|
|
15289
15338
|
var REVISAR_MOTOR_CADA_MS = 6 * 60 * 6e4;
|
|
15290
15339
|
function avisoMotorNuevo(motorWorker, motorEsperado) {
|
|
@@ -15397,8 +15446,8 @@ async function reintentarPendientes(q3, api, o = { log: () => {
|
|
|
15397
15446
|
|
|
15398
15447
|
// src/worker/worker.ts
|
|
15399
15448
|
import { hostname as hostname4 } from "node:os";
|
|
15400
|
-
import { access as access3, mkdir as
|
|
15401
|
-
import { dirname as dirname11, join as
|
|
15449
|
+
import { access as access3, mkdir as mkdir13, readFile as readFile15, rm as rm10, writeFile as writeFile12 } from "node:fs/promises";
|
|
15450
|
+
import { dirname as dirname11, join as join33, resolve as resolve10, sep as sep5 } from "node:path";
|
|
15402
15451
|
|
|
15403
15452
|
// src/worker/formatos-intento.ts
|
|
15404
15453
|
import { createHash as createHash7 } from "node:crypto";
|
|
@@ -15443,11 +15492,11 @@ function pedidoConFaltantes(pedido, faltan) {
|
|
|
15443
15492
|
if (tipos(quedan) !== tipos(renders)) return null;
|
|
15444
15493
|
return { ...pedido, renders: quedan };
|
|
15445
15494
|
}
|
|
15446
|
-
async function sha256Archivo2(
|
|
15495
|
+
async function sha256Archivo2(ruta2) {
|
|
15447
15496
|
try {
|
|
15448
15497
|
const h = createHash7("sha256");
|
|
15449
15498
|
let bytes = 0;
|
|
15450
|
-
for await (const b2 of createReadStream(
|
|
15499
|
+
for await (const b2 of createReadStream(ruta2)) {
|
|
15451
15500
|
h.update(b2);
|
|
15452
15501
|
bytes += b2.byteLength;
|
|
15453
15502
|
}
|
|
@@ -15456,9 +15505,9 @@ async function sha256Archivo2(ruta) {
|
|
|
15456
15505
|
return null;
|
|
15457
15506
|
}
|
|
15458
15507
|
}
|
|
15459
|
-
async function leerJson3(
|
|
15508
|
+
async function leerJson3(ruta2) {
|
|
15460
15509
|
try {
|
|
15461
|
-
const x2 = JSON.parse(await readFile7(
|
|
15510
|
+
const x2 = JSON.parse(await readFile7(ruta2, "utf8"));
|
|
15462
15511
|
return x2 && typeof x2 === "object" && !Array.isArray(x2) ? x2 : null;
|
|
15463
15512
|
} catch {
|
|
15464
15513
|
return null;
|
|
@@ -15599,9 +15648,9 @@ async function restaurarCompleta(dir, salidaDir, plan) {
|
|
|
15599
15648
|
for (const f of plan.reutilizables) await trasladar(f.dir, join24(salidaDir, "renders", f.clave), false);
|
|
15600
15649
|
}
|
|
15601
15650
|
async function fusionarFormatos(salidaDir, plan, claves) {
|
|
15602
|
-
const
|
|
15603
|
-
const m = await leerJson3(
|
|
15604
|
-
if (!m || !Array.isArray(m["renders"])) return
|
|
15651
|
+
const ruta2 = join24(salidaDir, "manifiesto.json");
|
|
15652
|
+
const m = await leerJson3(ruta2);
|
|
15653
|
+
if (!m || !Array.isArray(m["renders"])) return null;
|
|
15605
15654
|
const nuevos = /* @__PURE__ */ new Map();
|
|
15606
15655
|
for (const e7 of m["renders"]) nuevos.set(`${e7?.["ancho"]}x${e7?.["alto"]}`, e7);
|
|
15607
15656
|
for (const f of plan.reutilizables) await trasladar(f.dir, join24(salidaDir, "renders", f.clave), false);
|
|
@@ -15610,13 +15659,39 @@ async function fusionarFormatos(salidaDir, plan, claves) {
|
|
|
15610
15659
|
const e7 = nuevos.get(c) ?? porClave.get(c);
|
|
15611
15660
|
return e7 ? [e7] : [];
|
|
15612
15661
|
});
|
|
15613
|
-
await writeFile6(
|
|
15662
|
+
await writeFile6(ruta2, JSON.stringify(m, null, 2));
|
|
15614
15663
|
const principal = claves[0];
|
|
15615
15664
|
if (porClave.has(principal)) {
|
|
15616
15665
|
await cp3(join24(salidaDir, "renders", principal, "video.mp4"), join24(salidaDir, "video.mp4"));
|
|
15617
15666
|
await cp3(join24(salidaDir, "renders", principal, "poster.jpg"), join24(salidaDir, "poster.jpg")).catch(() => void 0);
|
|
15618
15667
|
}
|
|
15619
|
-
return
|
|
15668
|
+
return { sinHuellas: await sumarHuellas(salidaDir, plan, claves) };
|
|
15669
|
+
}
|
|
15670
|
+
async function sumarHuellas(salidaDir, plan, claves) {
|
|
15671
|
+
if (!plan.reutilizables.length) return [];
|
|
15672
|
+
const ruta2 = join24(salidaDir, "insumos", "huellas.json");
|
|
15673
|
+
const h = await leerJson3(ruta2);
|
|
15674
|
+
if (!h || !Array.isArray(h["renders"])) return [];
|
|
15675
|
+
const delMotor = /* @__PURE__ */ new Map();
|
|
15676
|
+
for (const e7 of h["renders"]) if (e7 && typeof e7["clave"] === "string") delMotor.set(e7["clave"], e7);
|
|
15677
|
+
const reutilizadas = /* @__PURE__ */ new Map();
|
|
15678
|
+
const sinHuellas = [];
|
|
15679
|
+
for (const f of plan.reutilizables) {
|
|
15680
|
+
const propio = await leerJson3(join24(salidaDir, "renders", f.clave, "huellas.json"));
|
|
15681
|
+
const lista = propio && propio["version"] === h["version"] && Array.isArray(propio["renders"]) ? propio["renders"] : [];
|
|
15682
|
+
const e7 = lista.find((x2) => x2 && x2["clave"] === f.clave);
|
|
15683
|
+
if (e7) reutilizadas.set(f.clave, e7);
|
|
15684
|
+
else sinHuellas.push(f.clave);
|
|
15685
|
+
}
|
|
15686
|
+
if (!reutilizadas.size) return sinHuellas;
|
|
15687
|
+
const enOrden = claves.flatMap((c) => {
|
|
15688
|
+
const e7 = reutilizadas.get(c) ?? delMotor.get(c);
|
|
15689
|
+
return e7 ? [e7] : [];
|
|
15690
|
+
});
|
|
15691
|
+
const otros = h["renders"].filter((e7) => !claves.includes(e7?.["clave"]));
|
|
15692
|
+
h["renders"] = [...enOrden, ...otros];
|
|
15693
|
+
await writeFile6(ruta2, JSON.stringify(h, null, 2));
|
|
15694
|
+
return sinHuellas;
|
|
15620
15695
|
}
|
|
15621
15696
|
async function limpiarFormatos(trabajoDir, dir, ahora = Date.now()) {
|
|
15622
15697
|
if (dir) await rm5(dir, { recursive: true, force: true });
|
|
@@ -15756,10 +15831,10 @@ function resumenCorreccion(construccion) {
|
|
|
15756
15831
|
// src/worker/informe.ts
|
|
15757
15832
|
import { access, readFile as readFile8 } from "node:fs/promises";
|
|
15758
15833
|
import { join as join25, resolve as resolve9, sep as sep4 } from "node:path";
|
|
15759
|
-
var existe = (
|
|
15760
|
-
async function leerJson4(
|
|
15834
|
+
var existe = (ruta2) => access(ruta2).then(() => true, () => false);
|
|
15835
|
+
async function leerJson4(ruta2) {
|
|
15761
15836
|
try {
|
|
15762
|
-
const x2 = JSON.parse(await readFile8(
|
|
15837
|
+
const x2 = JSON.parse(await readFile8(ruta2, "utf8"));
|
|
15763
15838
|
return x2 && typeof x2 === "object" && !Array.isArray(x2) ? x2 : null;
|
|
15764
15839
|
} catch {
|
|
15765
15840
|
return null;
|
|
@@ -15777,8 +15852,8 @@ async function leerInformes(salidaDir, manifiesto, pedido) {
|
|
|
15777
15852
|
const raiz = resolve9(salidaDir);
|
|
15778
15853
|
const sinCarpetaRenders = !await existe(join25(raiz, "renders"));
|
|
15779
15854
|
const candidatos = manifiesto.renders.length ? manifiesto.renders.map((r2, i) => {
|
|
15780
|
-
const
|
|
15781
|
-
return { clave: r2.etiqueta, ruta:
|
|
15855
|
+
const ruta2 = resolve9(raiz, r2.rutaRevision ?? `renders/${r2.etiqueta}/revision.json`);
|
|
15856
|
+
return { clave: r2.etiqueta, ruta: ruta2.startsWith(raiz + sep4) ? ruta2 : null, respaldoRaiz: i === 0 && sinCarpetaRenders };
|
|
15782
15857
|
}) : [{ clave: clavePrincipalDePedido(pedido), ruta: join25(raiz, "revision.json"), respaldoRaiz: false }];
|
|
15783
15858
|
const por = manifiesto.tiempos?.["por_render"] ?? {};
|
|
15784
15859
|
const { por_render: _omitido, ...generales } = manifiesto.tiempos ?? {};
|
|
@@ -15839,8 +15914,8 @@ function leerEdicion(e7) {
|
|
|
15839
15914
|
if (!archivos || typeof archivos !== "object" || Array.isArray(archivos)) return void 0;
|
|
15840
15915
|
const salida = {};
|
|
15841
15916
|
for (const [k, v2] of Object.entries(archivos)) {
|
|
15842
|
-
const
|
|
15843
|
-
if (typeof
|
|
15917
|
+
const ruta2 = v2 && typeof v2 === "object" ? v2["ruta"] : void 0;
|
|
15918
|
+
if (typeof ruta2 === "string" && ruta2) salida[k] = ruta2;
|
|
15844
15919
|
}
|
|
15845
15920
|
return Object.keys(salida).length ? salida : void 0;
|
|
15846
15921
|
}
|
|
@@ -15856,7 +15931,7 @@ function leerRenders(lista, log) {
|
|
|
15856
15931
|
const rev = x2["revision"] ?? {};
|
|
15857
15932
|
const archivos = x2["archivos"] ?? {};
|
|
15858
15933
|
const rutaPoster = archivos.poster?.ruta;
|
|
15859
|
-
const
|
|
15934
|
+
const ruta2 = archivos.video?.ruta;
|
|
15860
15935
|
const rutaRev = archivos.revision?.ruta;
|
|
15861
15936
|
const etiqueta = `${x2["ancho"]}x${x2["alto"]}`;
|
|
15862
15937
|
renders.push({
|
|
@@ -15864,7 +15939,7 @@ function leerRenders(lista, log) {
|
|
|
15864
15939
|
ancho: x2["ancho"],
|
|
15865
15940
|
alto: x2["alto"],
|
|
15866
15941
|
etiqueta,
|
|
15867
|
-
ruta: typeof
|
|
15942
|
+
ruta: typeof ruta2 === "string" && ruta2 ? ruta2 : `renders/${etiqueta}/video.mp4`,
|
|
15868
15943
|
rutaPoster: typeof rutaPoster === "string" && rutaPoster ? rutaPoster : `renders/${etiqueta}/poster.jpg`,
|
|
15869
15944
|
destinos: Array.isArray(x2["destinos"]) ? x2["destinos"].filter((d) => typeof d === "string") : [],
|
|
15870
15945
|
aprobada: typeof rev["aprobada"] === "boolean" ? rev["aprobada"] : void 0,
|
|
@@ -15888,10 +15963,9 @@ function leerCosto(c) {
|
|
|
15888
15963
|
return { costoUsd: dosDecimales(total), ...Object.keys(desglose).length ? { desglose } : {} };
|
|
15889
15964
|
}
|
|
15890
15965
|
|
|
15891
|
-
// src/worker/
|
|
15892
|
-
var
|
|
15893
|
-
|
|
15894
|
-
var FAMILIAS_SOPORTADAS = [
|
|
15966
|
+
// src/worker/catalogo-motor.ts
|
|
15967
|
+
var FAMILIAS_MOTOR = [
|
|
15968
|
+
"algoritmo-visual",
|
|
15895
15969
|
"anuncio-producto",
|
|
15896
15970
|
"asi-se-hizo",
|
|
15897
15971
|
"base",
|
|
@@ -15899,26 +15973,121 @@ var FAMILIAS_SOPORTADAS = [
|
|
|
15899
15973
|
"explicativo-personaje",
|
|
15900
15974
|
"leccion-diagrama",
|
|
15901
15975
|
"lista-top-n",
|
|
15976
|
+
"matematica-animada",
|
|
15902
15977
|
"poster-oscuro",
|
|
15903
15978
|
"tres-objeciones"
|
|
15904
15979
|
];
|
|
15905
|
-
var
|
|
15906
|
-
|
|
15907
|
-
|
|
15908
|
-
var
|
|
15909
|
-
|
|
15910
|
-
|
|
15911
|
-
|
|
15912
|
-
|
|
15913
|
-
|
|
15914
|
-
|
|
15915
|
-
|
|
15916
|
-
"
|
|
15917
|
-
|
|
15918
|
-
|
|
15919
|
-
|
|
15920
|
-
|
|
15980
|
+
var ALIAS_FAMILIA_MOTOR = {
|
|
15981
|
+
"plantilla-vertical-a": "base"
|
|
15982
|
+
};
|
|
15983
|
+
var ESTETICAS_POR_FAMILIA_MOTOR = {
|
|
15984
|
+
"algoritmo-visual": [
|
|
15985
|
+
"pizarra",
|
|
15986
|
+
"doodle",
|
|
15987
|
+
"linea-minimal",
|
|
15988
|
+
"retro-consola",
|
|
15989
|
+
"bloques-juguete"
|
|
15990
|
+
],
|
|
15991
|
+
"anuncio-producto": [
|
|
15992
|
+
"vitrina",
|
|
15993
|
+
"transmision-deportiva",
|
|
15994
|
+
"vector-plano"
|
|
15995
|
+
],
|
|
15996
|
+
"asi-se-hizo": [
|
|
15997
|
+
"interfaz-oscura",
|
|
15998
|
+
"transmision-deportiva",
|
|
15999
|
+
"vector-plano"
|
|
16000
|
+
],
|
|
16001
|
+
"base": [
|
|
16002
|
+
"base",
|
|
16003
|
+
"marca-clara",
|
|
16004
|
+
"pizarra",
|
|
16005
|
+
"papel-recortado",
|
|
16006
|
+
"pixel",
|
|
16007
|
+
"linea-minimal",
|
|
16008
|
+
"flat-editorial",
|
|
16009
|
+
"comic",
|
|
16010
|
+
"boceto-neon",
|
|
16011
|
+
"doodle",
|
|
16012
|
+
"transmision-deportiva",
|
|
16013
|
+
"vector-plano"
|
|
16014
|
+
],
|
|
16015
|
+
"demo-producto": [
|
|
16016
|
+
"consola-oscura",
|
|
16017
|
+
"transmision-deportiva",
|
|
16018
|
+
"vector-plano",
|
|
16019
|
+
"interfaz-3d"
|
|
16020
|
+
],
|
|
16021
|
+
"explicativo-personaje": [
|
|
16022
|
+
"claro-puntos",
|
|
16023
|
+
"pizarra",
|
|
16024
|
+
"marca-clara",
|
|
16025
|
+
"poster-oscuro",
|
|
16026
|
+
"base",
|
|
16027
|
+
"papel-recortado",
|
|
16028
|
+
"pixel",
|
|
16029
|
+
"linea-minimal",
|
|
16030
|
+
"flat-editorial",
|
|
16031
|
+
"comic",
|
|
16032
|
+
"boceto-neon",
|
|
16033
|
+
"doodle",
|
|
16034
|
+
"transmision-deportiva",
|
|
16035
|
+
"vector-plano",
|
|
16036
|
+
"mundo-cubos",
|
|
16037
|
+
"cine-3d",
|
|
16038
|
+
"retro-consola",
|
|
16039
|
+
"bloques-juguete",
|
|
16040
|
+
"interfaz-3d"
|
|
16041
|
+
],
|
|
16042
|
+
"leccion-diagrama": [
|
|
16043
|
+
"tablero-plano",
|
|
16044
|
+
"pizarra",
|
|
16045
|
+
"papel-recortado",
|
|
16046
|
+
"pixel",
|
|
16047
|
+
"linea-minimal",
|
|
16048
|
+
"flat-editorial",
|
|
16049
|
+
"comic",
|
|
16050
|
+
"boceto-neon",
|
|
16051
|
+
"doodle",
|
|
16052
|
+
"transmision-deportiva",
|
|
16053
|
+
"vector-plano"
|
|
16054
|
+
],
|
|
16055
|
+
"lista-top-n": [
|
|
16056
|
+
"base",
|
|
16057
|
+
"marca-clara",
|
|
16058
|
+
"pizarra",
|
|
16059
|
+
"papel-recortado",
|
|
16060
|
+
"pixel",
|
|
16061
|
+
"linea-minimal",
|
|
16062
|
+
"flat-editorial",
|
|
16063
|
+
"comic",
|
|
16064
|
+
"boceto-neon",
|
|
16065
|
+
"doodle",
|
|
16066
|
+
"transmision-deportiva",
|
|
16067
|
+
"vector-plano"
|
|
16068
|
+
],
|
|
16069
|
+
"matematica-animada": [
|
|
16070
|
+
"pizarra-negra"
|
|
16071
|
+
],
|
|
16072
|
+
"poster-oscuro": [
|
|
16073
|
+
"poster-oscuro",
|
|
16074
|
+
"transmision-deportiva",
|
|
16075
|
+
"vector-plano"
|
|
16076
|
+
],
|
|
16077
|
+
"tres-objeciones": [
|
|
16078
|
+
"flat-editorial",
|
|
16079
|
+
"transmision-deportiva",
|
|
16080
|
+
"vector-plano"
|
|
16081
|
+
]
|
|
15921
16082
|
};
|
|
16083
|
+
|
|
16084
|
+
// src/worker/pedido.ts
|
|
16085
|
+
var FORMATOS_SOPORTADOS = ["9:16", "16:9", "1:1", "4:5"];
|
|
16086
|
+
var RESOLUCIONES2 = { "9:16": [1080, 1920], "16:9": [1920, 1080], "1:1": [1080, 1080], "4:5": [1080, 1350] };
|
|
16087
|
+
var FAMILIAS_SOPORTADAS = FAMILIAS_MOTOR;
|
|
16088
|
+
var ALIAS_FAMILIA = ALIAS_FAMILIA_MOTOR;
|
|
16089
|
+
var ESTETICAS_POR_FAMILIA = ESTETICAS_POR_FAMILIA_MOTOR;
|
|
16090
|
+
var ALIAS_TEXTO = Object.entries(ALIAS_FAMILIA).map(([a, f]) => `${a} = ${f}`).join(", ");
|
|
15922
16091
|
var PedidoNoSoportado = class extends Error {
|
|
15923
16092
|
constructor(mensaje) {
|
|
15924
16093
|
super(mensaje);
|
|
@@ -15935,7 +16104,7 @@ function traducirPedido(r2) {
|
|
|
15935
16104
|
if (v2 === void 0 || v2 === null) return void 0;
|
|
15936
16105
|
const nombre = ALIAS_FAMILIA[String(v2)] ?? String(v2);
|
|
15937
16106
|
if (!FAMILIAS_SOPORTADAS.includes(nombre)) {
|
|
15938
|
-
throw new PedidoNoSoportado(`el motor no tiene la familia \xAB${String(v2)}\xBB (${campo}); familias: ${FAMILIAS_SOPORTADAS.join(", ")}
|
|
16107
|
+
throw new PedidoNoSoportado(`el motor no tiene la familia \xAB${String(v2)}\xBB (${campo}); familias: ${FAMILIAS_SOPORTADAS.join(", ")}${ALIAS_TEXTO ? ` (${ALIAS_TEXTO})` : ""}`);
|
|
15939
16108
|
}
|
|
15940
16109
|
return nombre;
|
|
15941
16110
|
};
|
|
@@ -16228,22 +16397,22 @@ import { access as access2, readFile as readFile12, writeFile as writeFile9 } fr
|
|
|
16228
16397
|
import { join as join29 } from "node:path";
|
|
16229
16398
|
var ALIAS = { "plantilla-vertical-a": "base" };
|
|
16230
16399
|
var existe2 = (r2) => access2(r2).then(() => true, () => false);
|
|
16231
|
-
async function leerJson5(
|
|
16400
|
+
async function leerJson5(ruta2) {
|
|
16232
16401
|
try {
|
|
16233
|
-
const j2 = JSON.parse(await readFile12(
|
|
16402
|
+
const j2 = JSON.parse(await readFile12(ruta2, "utf8"));
|
|
16234
16403
|
return j2 && typeof j2 === "object" && !Array.isArray(j2) ? j2 : null;
|
|
16235
16404
|
} catch {
|
|
16236
16405
|
return null;
|
|
16237
16406
|
}
|
|
16238
16407
|
}
|
|
16239
16408
|
async function anotarManifiesto(salidaDir, registro) {
|
|
16240
|
-
const
|
|
16241
|
-
const m = await leerJson5(
|
|
16409
|
+
const ruta2 = join29(salidaDir, "manifiesto.json");
|
|
16410
|
+
const m = await leerJson5(ruta2);
|
|
16242
16411
|
if (!m) return;
|
|
16243
16412
|
m["compositor"] = registro;
|
|
16244
16413
|
const k = m["construccion"];
|
|
16245
16414
|
if (k && typeof k === "object" && !Array.isArray(k)) k["compositor"] = registro;
|
|
16246
|
-
await writeFile9(
|
|
16415
|
+
await writeFile9(ruta2, JSON.stringify(m, null, 2));
|
|
16247
16416
|
}
|
|
16248
16417
|
var resumen2 = (r2) => [`${r2.vueltas} ${r2.vueltas === 1 ? "vuelta" : "vueltas"}`, `${(r2.segundos / 60).toFixed(1)} min`, r2.costo_usd !== null ? `${r2.costo_usd.toFixed(2)} USD equivalentes` : null, r2.modelo].filter(Boolean).join(", ");
|
|
16249
16418
|
var conReferencias = (r2) => r2.referencias?.length ? `; referencias: ${resumenReferencias(r2.referencias)}` : "";
|
|
@@ -16317,7 +16486,8 @@ async function pasoCompositor(p) {
|
|
|
16317
16486
|
return { tipo: "sin_cambios" };
|
|
16318
16487
|
}
|
|
16319
16488
|
if (r2.tipo === "respaldo") {
|
|
16320
|
-
const
|
|
16489
|
+
const que = r2.motivo === "tiempo agotado" ? "compositor cancelado por su tope de tiempo" : `compositor no disponible: ${r2.motivo}`;
|
|
16490
|
+
const mensaje = `${que}${r2.detalle ? ` (${r2.detalle})` : ""}; sale la composici\xF3n de la familia${conReferencias(r2.registro)}`.slice(0, 480);
|
|
16321
16491
|
p.log(mensaje);
|
|
16322
16492
|
await anotarManifiesto(p.salidaDir, r2.registro);
|
|
16323
16493
|
await p.bitacora(mensaje, "advertencia", { compositor: r2.registro });
|
|
@@ -16325,7 +16495,9 @@ async function pasoCompositor(p) {
|
|
|
16325
16495
|
}
|
|
16326
16496
|
p.log(`compositor: ${resumen2(r2.registro)}; renderizo su composici\xF3n`);
|
|
16327
16497
|
const comun = { pedidoDir: p.pedidoDir, salidaDir: p.salidaDir, nombreContenedor: `${p.nombreContenedor}-c`, senal: p.senal, onEvento: p.onEvento, subcomando: "renderizar" };
|
|
16498
|
+
const t02 = Date.now();
|
|
16328
16499
|
const res = await p.motor(p.c, { ...comun, composicionDir: r2.dir });
|
|
16500
|
+
p.log(`compositor: render de su composici\xF3n en ${duracionTexto(Date.now() - t02)} (tope por formato aparte)`);
|
|
16329
16501
|
if (res.abortado) return { tipo: "renderizado", res };
|
|
16330
16502
|
if ((res.codigo === 0 || res.codigo === 15) && await existe2(join29(p.salidaDir, "video.mp4"))) {
|
|
16331
16503
|
const paleta = cambioDePaleta(base, r2.dir, construccion.paleta?.tokens ?? {});
|
|
@@ -16349,11 +16521,86 @@ async function pasoCompositor(p) {
|
|
|
16349
16521
|
return { tipo: "renderizado", res: otra, registro };
|
|
16350
16522
|
}
|
|
16351
16523
|
|
|
16352
|
-
// src/worker/
|
|
16524
|
+
// src/worker/guion-reintento.ts
|
|
16353
16525
|
import { createHash as createHash8 } from "node:crypto";
|
|
16526
|
+
import { mkdir as mkdir11, readFile as readFile13, readdir as readdir4, rm as rm8, stat as stat3, writeFile as writeFile10 } from "node:fs/promises";
|
|
16527
|
+
import { join as join30 } from "node:path";
|
|
16528
|
+
var CARPETA = ".guionista";
|
|
16529
|
+
var CADUCIDAD_GUION_MS = 7 * 24 * 60 * 6e4;
|
|
16530
|
+
var CONSERVAN = /* @__PURE__ */ new Set(["tiempo", "corte", "infraestructura"]);
|
|
16531
|
+
var TEXTO_CLASE = {
|
|
16532
|
+
validacion: "de validaci\xF3n del pedido",
|
|
16533
|
+
composicion: "de composici\xF3n",
|
|
16534
|
+
tiempo: "por tope de tiempo",
|
|
16535
|
+
corte: "por un corte (red o worker detenido)",
|
|
16536
|
+
infraestructura: "de infraestructura",
|
|
16537
|
+
desconocido: "sin causa reconocida"
|
|
16538
|
+
};
|
|
16539
|
+
function claseDeFalloMotor(r2) {
|
|
16540
|
+
if (r2.tiempoAgotado || r2.etapaAgotada) return "tiempo";
|
|
16541
|
+
if (r2.abortado) return "corte";
|
|
16542
|
+
if (r2.codigo === 2) return "validacion";
|
|
16543
|
+
if (r2.codigo === 12) return "composicion";
|
|
16544
|
+
if (r2.codigo === 125 || r2.codigo === 127 || r2.codigo === 137) return "infraestructura";
|
|
16545
|
+
const motivo = motivoDe([r2.error?.mensaje ?? "", ...r2.stderrCola].join(" "));
|
|
16546
|
+
if (motivo && !/ffmpeg/.test(motivo)) return "infraestructura";
|
|
16547
|
+
return "desconocido";
|
|
16548
|
+
}
|
|
16549
|
+
var sha = (x2) => createHash8("sha256").update(JSON.stringify(x2)).digest("hex");
|
|
16550
|
+
var ruta = (trabajoDir, videoId, version2) => join30(trabajoDir, CARPETA, `${videoId.replace(/[^A-Za-z0-9_-]/g, "_")}-v${version2}.json`);
|
|
16551
|
+
async function leer(trabajoDir, videoId, version2) {
|
|
16552
|
+
try {
|
|
16553
|
+
const g = JSON.parse(await readFile13(ruta(trabajoDir, videoId, version2), "utf8"));
|
|
16554
|
+
return g && g.v === 1 && g.video_id === videoId && g.version === version2 ? g : null;
|
|
16555
|
+
} catch {
|
|
16556
|
+
return null;
|
|
16557
|
+
}
|
|
16558
|
+
}
|
|
16559
|
+
async function purgarViejos(trabajoDir, ahora) {
|
|
16560
|
+
const dir = join30(trabajoDir, CARPETA);
|
|
16561
|
+
for (const n of await readdir4(dir).catch(() => [])) {
|
|
16562
|
+
const s = await stat3(join30(dir, n)).catch(() => null);
|
|
16563
|
+
if (s && ahora - s.mtimeMs > CADUCIDAD_GUION_MS) await rm8(join30(dir, n), { force: true });
|
|
16564
|
+
}
|
|
16565
|
+
}
|
|
16566
|
+
async function guardarGuion(trabajoDir, r2, pedido, registro, ahora = Date.now()) {
|
|
16567
|
+
await mkdir11(join30(trabajoDir, CARPETA), { recursive: true });
|
|
16568
|
+
await purgarViejos(trabajoDir, ahora);
|
|
16569
|
+
const g = { v: 1, video_id: r2.video_id, version: r2.version, intento: r2.intento, pedido_sha256: sha(r2.pedido), pedido, registro, guardado_en: ahora };
|
|
16570
|
+
await writeFile10(ruta(trabajoDir, r2.video_id, r2.version), JSON.stringify(g, null, 2));
|
|
16571
|
+
}
|
|
16572
|
+
async function anotarFallo(trabajoDir, r2, clase, causa) {
|
|
16573
|
+
const g = await leer(trabajoDir, r2.video_id, r2.version);
|
|
16574
|
+
if (!g) return;
|
|
16575
|
+
g.fallo = { intento: r2.intento, clase, causa: causa.slice(0, 300) };
|
|
16576
|
+
await writeFile10(ruta(trabajoDir, r2.video_id, r2.version), JSON.stringify(g, null, 2));
|
|
16577
|
+
}
|
|
16578
|
+
async function olvidarGuion(trabajoDir, r2) {
|
|
16579
|
+
await rm8(ruta(trabajoDir, r2.video_id, r2.version), { force: true });
|
|
16580
|
+
}
|
|
16581
|
+
function decidirReintento(g, r2) {
|
|
16582
|
+
const anterior = r2.intento - 1;
|
|
16583
|
+
const original = `reintento ${r2.intento}: sale con el pedido original`;
|
|
16584
|
+
if (!g || !g.fallo || g.fallo.intento !== anterior) return { tipo: "omitir", razon: `${original}: no s\xE9 por qu\xE9 fall\xF3 el intento ${anterior} en esta m\xE1quina, por si el guion reescrito caus\xF3 el fallo` };
|
|
16585
|
+
if (g.pedido_sha256 !== sha(r2.pedido)) return { tipo: "omitir", razon: `${original}: el pedido cambi\xF3 desde el intento ${g.intento}` };
|
|
16586
|
+
const clase = g.fallo.clase;
|
|
16587
|
+
if (!CONSERVAN.has(clase)) return { tipo: "omitir", razon: `${original} porque el intento ${anterior} fall\xF3 ${TEXTO_CLASE[clase]} y el guion reescrito pudo causarlo` };
|
|
16588
|
+
return {
|
|
16589
|
+
tipo: "conservar",
|
|
16590
|
+
pedido: g.pedido,
|
|
16591
|
+
registro: g.registro,
|
|
16592
|
+
mensaje: `guionista: reintento ${r2.intento}: conservo el guion reescrito en el intento ${g.intento} (el intento ${anterior} fall\xF3 ${TEXTO_CLASE[clase]}, no por el guion)`
|
|
16593
|
+
};
|
|
16594
|
+
}
|
|
16595
|
+
async function guionParaReintento(trabajoDir, r2) {
|
|
16596
|
+
return decidirReintento(await leer(trabajoDir, r2.video_id, r2.version), r2);
|
|
16597
|
+
}
|
|
16598
|
+
|
|
16599
|
+
// src/worker/guionista.ts
|
|
16600
|
+
import { createHash as createHash9 } from "node:crypto";
|
|
16354
16601
|
import { existsSync as existsSync12, readFileSync as readFileSync15 } from "node:fs";
|
|
16355
|
-
import { mkdir as
|
|
16356
|
-
import { dirname as dirname10, join as
|
|
16602
|
+
import { mkdir as mkdir12, readFile as readFile14, rm as rm9, writeFile as writeFile11 } from "node:fs/promises";
|
|
16603
|
+
import { dirname as dirname10, join as join31 } from "node:path";
|
|
16357
16604
|
var TOPE_GUIONISTA_MS = 5 * 6e4;
|
|
16358
16605
|
var PRESUPUESTO_GUIONISTA_USD = 1;
|
|
16359
16606
|
var MAX_VUELTAS_GUIONISTA = 2;
|
|
@@ -16370,7 +16617,7 @@ function leerEncargoGuionista(origen) {
|
|
|
16370
16617
|
const reglas = Array.isArray(g["reglas"]) ? g["reglas"].filter((x2) => typeof x2 === "string") : [];
|
|
16371
16618
|
return { origen: typeof g["origen"] === "string" ? g["origen"] : "grupo", reglas, revision: g["revision"] ?? null, propuesta: g["propuesta"] ?? null };
|
|
16372
16619
|
}
|
|
16373
|
-
var
|
|
16620
|
+
var sha2 = (x2) => createHash9("sha256").update(JSON.stringify(x2)).digest("hex");
|
|
16374
16621
|
var escenasDe = (p) => {
|
|
16375
16622
|
const e7 = p["guion"]?.escenas;
|
|
16376
16623
|
return Array.isArray(e7) ? e7 : [];
|
|
@@ -16409,20 +16656,20 @@ function argumentosGuionista(prompt, dir, presupuestoUsd) {
|
|
|
16409
16656
|
];
|
|
16410
16657
|
}
|
|
16411
16658
|
function catalogoIconos(motorDir) {
|
|
16412
|
-
const comun =
|
|
16413
|
-
const
|
|
16659
|
+
const comun = join31(motorDir, "plantillas", "_comun");
|
|
16660
|
+
const leer3 = (ruta2) => {
|
|
16414
16661
|
try {
|
|
16415
|
-
return JSON.parse(readFileSync15(
|
|
16662
|
+
return JSON.parse(readFileSync15(ruta2, "utf8"));
|
|
16416
16663
|
} catch {
|
|
16417
16664
|
return null;
|
|
16418
16665
|
}
|
|
16419
16666
|
};
|
|
16420
|
-
const lucide =
|
|
16667
|
+
const lucide = leer3(join31(comun, "lucide", "iconos.json"));
|
|
16421
16668
|
if (!lucide) return null;
|
|
16422
16669
|
const nombres = new Set(Object.keys(lucide));
|
|
16423
|
-
for (const set of ["phosphor", "tabler"]) for (const k of Object.keys(
|
|
16670
|
+
for (const set of ["phosphor", "tabler"]) for (const k of Object.keys(leer3(join31(comun, "recursos", set, "iconos.json")) ?? {})) nombres.add(`${set}:${k}`);
|
|
16424
16671
|
for (const set of ["aws", "azure", "gcp", "k8s", "ia", "marca", "emoji", "bandera", "dev", "salud", "clima", "lugar", "cripto"]) {
|
|
16425
|
-
const d =
|
|
16672
|
+
const d = leer3(join31(comun, "recursos", set, "iconos.json"));
|
|
16426
16673
|
for (const k of [...Object.keys(d?.iconos ?? {}), ...Object.keys(d?.alias ?? {})]) nombres.add(`${set}:${k}`);
|
|
16427
16674
|
}
|
|
16428
16675
|
return nombres;
|
|
@@ -16481,7 +16728,7 @@ function resumirCambios(antes, despues) {
|
|
|
16481
16728
|
const diag = (l) => l.filter((e7) => e7.visual?.diagrama).length;
|
|
16482
16729
|
if (diag(ea2) !== diag(ed2)) sal.push(`diagramas: ${diag(ea2)} \u2192 ${diag(ed2)}`);
|
|
16483
16730
|
if (antes["estilo"] !== despues["estilo"]) sal.push(`estilo: ${String(antes["estilo"] ?? "base")} \u2192 ${String(despues["estilo"])}`);
|
|
16484
|
-
if (!sal.length &&
|
|
16731
|
+
if (!sal.length && sha2(antes["guion"]) !== sha2(despues["guion"])) sal.push("textos de escena reescritos");
|
|
16485
16732
|
return sal;
|
|
16486
16733
|
}
|
|
16487
16734
|
function encargoMd(e7, objetivo) {
|
|
@@ -16534,7 +16781,7 @@ function crearGuionista(o, d = depsReales4(o.motorDir)) {
|
|
|
16534
16781
|
escenas_despues: escenasDe(original).length,
|
|
16535
16782
|
palabras_antes: palabras2(original),
|
|
16536
16783
|
palabras_despues: palabras2(original),
|
|
16537
|
-
pedido_sha256_antes:
|
|
16784
|
+
pedido_sha256_antes: sha2(original),
|
|
16538
16785
|
pedido_sha256_despues: null,
|
|
16539
16786
|
ignorados: []
|
|
16540
16787
|
};
|
|
@@ -16542,12 +16789,12 @@ function crearGuionista(o, d = depsReales4(o.motorDir)) {
|
|
|
16542
16789
|
const respaldo2 = (motivo, detalle, x2 = {}) => ({ tipo: "respaldo", registro: reg({ ...x2, respaldo: true, motivo: `${motivo}${detalle ? `: ${detalle}` : ""}`.slice(0, 300) }) });
|
|
16543
16790
|
const claude = d.buscarEjecutable(o.comando, o.env);
|
|
16544
16791
|
if (!claude) return respaldo2("ausente", `no encuentro \`${o.comando}\` en el PATH`);
|
|
16545
|
-
await
|
|
16546
|
-
await
|
|
16547
|
-
await
|
|
16548
|
-
await
|
|
16792
|
+
await rm9(e7.dir, { recursive: true, force: true });
|
|
16793
|
+
await mkdir12(join31(e7.dir, "_encargo"), { recursive: true });
|
|
16794
|
+
await writeFile11(join31(e7.dir, "pedido.json"), JSON.stringify(original, null, 2));
|
|
16795
|
+
await writeFile11(join31(e7.dir, "_encargo", "encargo.md"), encargoMd(e7, original["formato"]?.duracion_objetivo_s));
|
|
16549
16796
|
const iconos = d.iconos();
|
|
16550
|
-
await
|
|
16797
|
+
await writeFile11(join31(e7.dir, "_encargo", "iconos.txt"), iconos ? [...iconos].sort().join("\n") : "");
|
|
16551
16798
|
let costo = null;
|
|
16552
16799
|
let tokens = null;
|
|
16553
16800
|
let turnos = null;
|
|
@@ -16571,7 +16818,7 @@ function crearGuionista(o, d = depsReales4(o.motorDir)) {
|
|
|
16571
16818
|
if (s.codigo !== 0 || uso.error) return respaldo2("error", uso.error ?? `sali\xF3 con c\xF3digo ${s.codigo}: ${s.stderr.trim().slice(-160)}`, uso_);
|
|
16572
16819
|
let nuevo;
|
|
16573
16820
|
try {
|
|
16574
|
-
nuevo = JSON.parse(await
|
|
16821
|
+
nuevo = JSON.parse(await readFile14(join31(e7.dir, "pedido.json"), "utf8"));
|
|
16575
16822
|
} catch {
|
|
16576
16823
|
nuevo = null;
|
|
16577
16824
|
}
|
|
@@ -16579,11 +16826,11 @@ function crearGuionista(o, d = depsReales4(o.motorDir)) {
|
|
|
16579
16826
|
ignorados = rev.ignorados;
|
|
16580
16827
|
if (rev.pedido) {
|
|
16581
16828
|
const cambios = resumirCambios(original, rev.pedido);
|
|
16582
|
-
if (
|
|
16829
|
+
if (sha2(rev.pedido) === sha2(original)) return respaldo2("sin cambios", "el agente dej\xF3 el pedido igual", { ...uso_, ignorados });
|
|
16583
16830
|
return {
|
|
16584
16831
|
tipo: "ok",
|
|
16585
16832
|
pedido: rev.pedido,
|
|
16586
|
-
registro: reg({ ...uso_, respaldo: false, motivo: null, cambios, ignorados, escenas_despues: escenasDe(rev.pedido).length, palabras_despues: palabras2(rev.pedido), pedido_sha256_despues:
|
|
16833
|
+
registro: reg({ ...uso_, respaldo: false, motivo: null, cambios, ignorados, escenas_despues: escenasDe(rev.pedido).length, palabras_despues: palabras2(rev.pedido), pedido_sha256_despues: sha2(rev.pedido) })
|
|
16587
16834
|
};
|
|
16588
16835
|
}
|
|
16589
16836
|
ultimos = rev.errores;
|
|
@@ -16603,10 +16850,10 @@ function depsReales4(motorDir) {
|
|
|
16603
16850
|
};
|
|
16604
16851
|
}
|
|
16605
16852
|
async function anotarGuionistaEnManifiesto(salidaDir, registro, guionFinal) {
|
|
16606
|
-
const
|
|
16853
|
+
const ruta2 = join31(salidaDir, "manifiesto.json");
|
|
16607
16854
|
let m;
|
|
16608
16855
|
try {
|
|
16609
|
-
m = JSON.parse(await
|
|
16856
|
+
m = JSON.parse(await readFile14(ruta2, "utf8"));
|
|
16610
16857
|
} catch {
|
|
16611
16858
|
return;
|
|
16612
16859
|
}
|
|
@@ -16614,7 +16861,7 @@ async function anotarGuionistaEnManifiesto(salidaDir, registro, guionFinal) {
|
|
|
16614
16861
|
m["guionista"] = valor;
|
|
16615
16862
|
const k = m["construccion"];
|
|
16616
16863
|
if (k && typeof k === "object" && !Array.isArray(k)) k["guionista"] = valor;
|
|
16617
|
-
await
|
|
16864
|
+
await writeFile11(ruta2, JSON.stringify(m, null, 2));
|
|
16618
16865
|
}
|
|
16619
16866
|
function mensajeGuionista(r2) {
|
|
16620
16867
|
if (r2.respaldo) return `guionista no disponible: ${r2.motivo ?? "sin motivo"}; sale el guion original`.slice(0, 480);
|
|
@@ -16623,16 +16870,16 @@ function mensajeGuionista(r2) {
|
|
|
16623
16870
|
}
|
|
16624
16871
|
|
|
16625
16872
|
// src/worker/paso-parecido.ts
|
|
16626
|
-
import { join as
|
|
16873
|
+
import { join as join32 } from "node:path";
|
|
16627
16874
|
function crearParecidoDelVideo(o) {
|
|
16628
|
-
let
|
|
16875
|
+
let ruta2 = null;
|
|
16629
16876
|
let metricasRef = null;
|
|
16630
|
-
const rutaRef = () =>
|
|
16877
|
+
const rutaRef = () => ruta2 ??= (async () => {
|
|
16631
16878
|
if (o.referencia.ruta) return o.referencia.ruta;
|
|
16632
16879
|
const b2 = await o.bajarReferencias();
|
|
16633
16880
|
const local = b2.archivos[o.referencia.asset_id];
|
|
16634
16881
|
if (!local) throw new Error(`no se pudo bajar la referencia ${o.referencia.asset_id}${b2.fallos[o.referencia.asset_id] ? `: ${b2.fallos[o.referencia.asset_id]}` : ""}`);
|
|
16635
|
-
return
|
|
16882
|
+
return join32(o.pedidoDir, local.ruta);
|
|
16636
16883
|
})();
|
|
16637
16884
|
const ref = { asset_id: o.referencia.asset_id, nombre: o.referencia.nombre, origen: o.referencia.origen };
|
|
16638
16885
|
return {
|
|
@@ -16643,7 +16890,7 @@ function crearParecidoDelVideo(o) {
|
|
|
16643
16890
|
return { referencia: ref, ref: refM, base, medir: (v2) => o.medidor.medir(v2) };
|
|
16644
16891
|
},
|
|
16645
16892
|
async final(mp42, registro) {
|
|
16646
|
-
const c = await o.medidor.comparar(mp42, await rutaRef(),
|
|
16893
|
+
const c = await o.medidor.comparar(mp42, await rutaRef(), join32(o.raiz, "parecido"), `${o.titulo} vs ${o.referencia.nombre ?? "referencia"}`);
|
|
16647
16894
|
const vueltas = [...registro?.parecido?.vueltas ?? []];
|
|
16648
16895
|
if (registro && !registro.respaldo && registro.vuelta_usada && !vueltas.some((v2) => v2.vuelta === registro.vuelta_usada)) {
|
|
16649
16896
|
vueltas.push({ vuelta: registro.vuelta_usada, cambios_por_minuto: c.este.cambios_por_minuto, escena_media_s: c.este.escena_media_s, lectura_ritmo: c.lectura["ritmo_de_cortes"]?.lectura ?? null });
|
|
@@ -16668,7 +16915,7 @@ var motorPasosDe = (c) => ({
|
|
|
16668
16915
|
...c.entornoMotor ? { entorno: c.entornoMotor } : {}
|
|
16669
16916
|
});
|
|
16670
16917
|
var dormirReal = (ms2) => new Promise((r2) => setTimeout(r2, ms2));
|
|
16671
|
-
var existe3 = (
|
|
16918
|
+
var existe3 = (ruta2) => access3(ruta2).then(() => true, () => false);
|
|
16672
16919
|
async function procesarSiguiente(c, d) {
|
|
16673
16920
|
const log = d.log ?? (() => {
|
|
16674
16921
|
});
|
|
@@ -16696,15 +16943,15 @@ async function procesarSiguiente(c, d) {
|
|
|
16696
16943
|
soltar();
|
|
16697
16944
|
}
|
|
16698
16945
|
}
|
|
16699
|
-
async function esperarBloqueo(
|
|
16946
|
+
async function esperarBloqueo(ruta2, dormir2, log, senal) {
|
|
16700
16947
|
for (let avisado = false; ; ) {
|
|
16701
16948
|
try {
|
|
16702
|
-
return tomarBloqueo(
|
|
16949
|
+
return tomarBloqueo(ruta2, { paso: "worker-nube", carpeta: "" });
|
|
16703
16950
|
} catch (e7) {
|
|
16704
16951
|
if (!(e7 instanceof Ocupado) || senal?.aborted) throw e7;
|
|
16705
16952
|
if (!avisado) log(`espero al motor: ${e7.message}`);
|
|
16706
16953
|
avisado = true;
|
|
16707
|
-
await
|
|
16954
|
+
await dormir2(2e3);
|
|
16708
16955
|
}
|
|
16709
16956
|
}
|
|
16710
16957
|
}
|
|
@@ -16729,13 +16976,13 @@ async function trabajar(c, d, r2, turno) {
|
|
|
16729
16976
|
async function trabajarVideo(c, d, r2, turno, buzon) {
|
|
16730
16977
|
const log = d.log ?? (() => {
|
|
16731
16978
|
});
|
|
16732
|
-
const
|
|
16979
|
+
const dormir2 = d.dormir ?? dormirReal;
|
|
16733
16980
|
const { api } = d;
|
|
16734
16981
|
const id3 = r2.video_id;
|
|
16735
16982
|
const agenteB = d.agenteB && r2.pedido?.["previa"] !== true && agentesPresentes(d.agenteB.presenciaDir).length ? d.agenteB : null;
|
|
16736
|
-
const raiz = agenteB ?
|
|
16737
|
-
const pedidoDir =
|
|
16738
|
-
let salidaDir =
|
|
16983
|
+
const raiz = agenteB ? join33(agenteB.trabajoDir, `nube-${id3}-v${r2.version}-i${r2.intento}`) : join33(c.trabajoDir, `${id3}-v${r2.version}-i${r2.intento}`);
|
|
16984
|
+
const pedidoDir = join33(raiz, agenteB ? "entrada" : "pedido");
|
|
16985
|
+
let salidaDir = join33(raiz, "salida");
|
|
16739
16986
|
log(`reclamado ${id3} v${r2.version} (intento ${r2.intento}): ${r2.titulo}${agenteB ? " (hay un Agente B presente: compongo por pasos y lo dejo en el buz\xF3n)" : ""}`);
|
|
16740
16987
|
d.avance?.iniciar({ id: id3, titulo: r2.titulo, version: r2.version, intento: r2.intento });
|
|
16741
16988
|
let costo;
|
|
@@ -16743,7 +16990,8 @@ async function trabajarVideo(c, d, r2, turno, buzon) {
|
|
|
16743
16990
|
let reuso = null;
|
|
16744
16991
|
let entregado = false;
|
|
16745
16992
|
const r_2 = r2.reclamo ? { reclamo: r2.reclamo } : {};
|
|
16746
|
-
|
|
16993
|
+
let guionGuardado = false;
|
|
16994
|
+
const fallar = async (etapa, causa, codigo, reintentable, clase = "desconocido") => {
|
|
16747
16995
|
d.avance?.terminar(`${r2.titulo}: fall\xF3 (${causa})`, false);
|
|
16748
16996
|
log(`fall\xF3 ${id3}: ${causa}`);
|
|
16749
16997
|
let f;
|
|
@@ -16755,9 +17003,14 @@ async function trabajarVideo(c, d, r2, turno, buzon) {
|
|
|
16755
17003
|
if (e7 instanceof ErrorApi && (e7.conflicto || e7.estado === 404)) return { tipo: "cancelado", videoId: id3 };
|
|
16756
17004
|
if (!(e7 instanceof ErrorApi && e7.transitorio) || i >= INTENTOS_TRANSITORIO) throw e7;
|
|
16757
17005
|
log(`reportar el fallo de ${id3} fall\xF3 (intento ${i}/${INTENTOS_TRANSITORIO}): ${e7.message}`);
|
|
16758
|
-
await
|
|
17006
|
+
await dormir2(esperaConJitter(i, ESPERA_BASE_MS, ESPERA_TOPE_MS));
|
|
16759
17007
|
}
|
|
16760
17008
|
}
|
|
17009
|
+
if (guionGuardado) {
|
|
17010
|
+
const r22 = { video_id: id3, version: r2.version, intento: r2.intento };
|
|
17011
|
+
await (f.reencolado ? anotarFallo(c.trabajoDir, r22, clase, causa) : olvidarGuion(c.trabajoDir, r22)).catch(() => {
|
|
17012
|
+
});
|
|
17013
|
+
}
|
|
16761
17014
|
return { tipo: "fallo", videoId: id3, causa, reencolado: f.reencolado };
|
|
16762
17015
|
};
|
|
16763
17016
|
try {
|
|
@@ -16765,7 +17018,7 @@ async function trabajarVideo(c, d, r2, turno, buzon) {
|
|
|
16765
17018
|
try {
|
|
16766
17019
|
pedido = traducirPedido(r2);
|
|
16767
17020
|
} catch (e7) {
|
|
16768
|
-
if (e7 instanceof PedidoNoSoportado) return await fallar("voz", e7.message, null, false);
|
|
17021
|
+
if (e7 instanceof PedidoNoSoportado) return await fallar("voz", e7.message, null, false, "validacion");
|
|
16769
17022
|
throw e7;
|
|
16770
17023
|
}
|
|
16771
17024
|
if (pedidoConVozClonada(pedido)) {
|
|
@@ -16779,8 +17032,8 @@ async function trabajarVideo(c, d, r2, turno, buzon) {
|
|
|
16779
17032
|
c = { ...c, timeoutMs: tope.ms };
|
|
16780
17033
|
log(`${id3}: ${tope.duracionS && tope.duracionS >= 300 ? `video largo (~${tope.duracionS} s, ` : "("}${tope.formatos} formato${tope.formatos === 1 ? "" : "s"}): tope ${Math.round(tope.ms / 6e4)} min (${topes.formatoMin} por formato, ${topes.etapaMin} por etapa)`);
|
|
16781
17034
|
}
|
|
16782
|
-
await
|
|
16783
|
-
await
|
|
17035
|
+
await mkdir13(pedidoDir, { recursive: true });
|
|
17036
|
+
await mkdir13(salidaDir, { recursive: true });
|
|
16784
17037
|
const parar = new AbortController();
|
|
16785
17038
|
const alCerrar = () => parar.abort();
|
|
16786
17039
|
d.senal?.addEventListener("abort", alCerrar, { once: true });
|
|
@@ -16816,24 +17069,27 @@ async function trabajarVideo(c, d, r2, turno, buzon) {
|
|
|
16816
17069
|
}));
|
|
16817
17070
|
}
|
|
16818
17071
|
try {
|
|
16819
|
-
const guion = await pasoGuionista(d, r2, pedido, raiz, parar.signal, log, async (mensaje, nivel, datos) => {
|
|
17072
|
+
const guion = await pasoGuionista(d, c.trabajoDir, r2, pedido, raiz, parar.signal, log, async (mensaje, nivel, datos) => {
|
|
16820
17073
|
d.avance?.nota(mensaje);
|
|
16821
17074
|
await cadena2;
|
|
16822
17075
|
await api.progreso(id3, { ...r_2, etapa: "voz", porcentaje: 0, mensaje, ...nivel ? { nivel } : {}, datos }).catch(() => {
|
|
16823
17076
|
});
|
|
16824
17077
|
});
|
|
16825
17078
|
if (cancelado || guion.tipo === "cancelado") return { tipo: "cancelado", videoId: id3 };
|
|
16826
|
-
if (guion.tipo === "ok")
|
|
17079
|
+
if (guion.tipo === "ok") {
|
|
17080
|
+
pedido = traducirPedido({ ...r2, pedido: guion.pedido });
|
|
17081
|
+
guionGuardado = await guardarGuion(c.trabajoDir, r2, guion.pedido, guion.registro).then(() => true, () => false);
|
|
17082
|
+
}
|
|
16827
17083
|
const registroGuionista = guion.tipo === "sin_paso" ? null : guion;
|
|
16828
17084
|
try {
|
|
16829
17085
|
const locales = await descargarMedia(r2.media, pedidoDir, d.descargar, parar.signal, idsDeClips(pedido));
|
|
16830
17086
|
if (Object.keys(locales).length) pedido["archivos_locales"] = locales;
|
|
16831
17087
|
} catch (e7) {
|
|
16832
17088
|
if (cancelado) return { tipo: "cancelado", videoId: id3 };
|
|
16833
|
-
if (e7 instanceof ErrorMedia) return await fallar("media", e7.message, null, e7.reintentable);
|
|
17089
|
+
if (e7 instanceof ErrorMedia) return await fallar("media", e7.message, null, e7.reintentable, e7.reintentable ? "corte" : "validacion");
|
|
16834
17090
|
throw e7;
|
|
16835
17091
|
}
|
|
16836
|
-
await
|
|
17092
|
+
await writeFile12(join33(pedidoDir, "pedido.json"), JSON.stringify(pedido, null, 2));
|
|
16837
17093
|
if (cancelado) return { tipo: "cancelado", videoId: id3 };
|
|
16838
17094
|
let res;
|
|
16839
17095
|
const crono = new Cronometro();
|
|
@@ -16853,12 +17109,12 @@ async function trabajarVideo(c, d, r2, turno, buzon) {
|
|
|
16853
17109
|
const bajarReferencias = () => bajadas ??= descargarReferenciasVideo(r2.media, pedido["referencias"], pedidoDir, d.descargar, parar.signal);
|
|
16854
17110
|
let porAgente = false;
|
|
16855
17111
|
if (agenteB) {
|
|
16856
|
-
const b2 = await caminoAgenteB(c, d, r2, agenteB, { raiz, rutaPedido:
|
|
17112
|
+
const b2 = await caminoAgenteB(c, d, r2, agenteB, { raiz, rutaPedido: join33(pedidoDir, "pedido.json"), pedido, bajarReferencias, turno, senal: parar.signal, onEvento, log, buzon });
|
|
16857
17113
|
await cadena2;
|
|
16858
17114
|
if (cancelado || b2.tipo === "cancelado") return { tipo: "cancelado", videoId: id3 };
|
|
16859
17115
|
if (b2.tipo === "listo") {
|
|
16860
17116
|
res = b2.res;
|
|
16861
|
-
salidaDir =
|
|
17117
|
+
salidaDir = join33(raiz, "final");
|
|
16862
17118
|
porAgente = true;
|
|
16863
17119
|
}
|
|
16864
17120
|
}
|
|
@@ -16894,7 +17150,7 @@ async function trabajarVideo(c, d, r2, turno, buzon) {
|
|
|
16894
17150
|
if (!res) {
|
|
16895
17151
|
const reutilizarDir = r2.reutilizar && pedido["previa"] !== true ? await prepararInsumos(d, r2, raiz, parar.signal, log, () => cadena2) : null;
|
|
16896
17152
|
if (cancelado) return { tipo: "cancelado", videoId: id3 };
|
|
16897
|
-
if (reuso) await
|
|
17153
|
+
if (reuso) await writeFile12(join33(pedidoDir, "pedido.json"), JSON.stringify(reuso.pedidoMotor, null, 2));
|
|
16898
17154
|
try {
|
|
16899
17155
|
const motor2 = d.motor ?? ejecutarMotor;
|
|
16900
17156
|
res = await motor2(c, { pedidoDir, salidaDir, nombreContenedor: nombreContenedor2, senal: parar.signal, onEvento, versionVideo: r2.version, topeEtapaMs, ...reutilizarDir ? { reutilizarDir } : {} });
|
|
@@ -16904,12 +17160,22 @@ async function trabajarVideo(c, d, r2, turno, buzon) {
|
|
|
16904
17160
|
}
|
|
16905
17161
|
} finally {
|
|
16906
17162
|
await cadena2;
|
|
16907
|
-
if (reuso) await
|
|
17163
|
+
if (reuso) await writeFile12(join33(pedidoDir, "pedido.json"), JSON.stringify(pedido, null, 2));
|
|
16908
17164
|
}
|
|
16909
|
-
if (reuso && (res.codigo === 0 || res.codigo === 15) && !res.abortado && !cancelado
|
|
16910
|
-
await
|
|
16911
|
-
|
|
16912
|
-
|
|
17165
|
+
if (reuso && (res.codigo === 0 || res.codigo === 15) && !res.abortado && !cancelado) {
|
|
17166
|
+
const fusion = await fusionarFormatos(salidaDir, reuso.plan, reuso.claves);
|
|
17167
|
+
if (!fusion) {
|
|
17168
|
+
await rm10(formatosIntento.dir, { recursive: true, force: true });
|
|
17169
|
+
formatosIntento = null;
|
|
17170
|
+
return await fallar("render", "el motor no dej\xF3 manifiesto.json y no pude sumar los formatos reutilizados; se reintentar\xE1 con todos", res.codigo, true, "infraestructura");
|
|
17171
|
+
}
|
|
17172
|
+
if (fusion.sinHuellas.length) {
|
|
17173
|
+
const nombres = fusion.sinHuellas.map((k) => reuso.plan.reutilizables.find((f) => f.clave === k)?.aspecto ?? k);
|
|
17174
|
+
const mensaje = nombres.length === 1 ? `El formato reutilizado ${nombres[0]} no trae huellas.json (motor anterior a CLA-413): sus insumos se suben sin ellas y una correcci\xF3n de escena lo renderizar\xE1 completo` : `Los formatos reutilizados ${listaFormatos(nombres)} no traen huellas.json (motor anterior a CLA-413): sus insumos se suben sin ellas y una correcci\xF3n de escena los renderizar\xE1 completos`;
|
|
17175
|
+
log(`${id3}: ${mensaje}`);
|
|
17176
|
+
await api.progreso(id3, { ...r_2, etapa: ultimo.etapa, porcentaje: ultimo.porcentaje, mensaje, nivel: "advertencia", datos: { formatos_sin_huellas: fusion.sinHuellas } }).catch(() => {
|
|
17177
|
+
});
|
|
17178
|
+
}
|
|
16913
17179
|
}
|
|
16914
17180
|
const tiempos = crono.resumen();
|
|
16915
17181
|
if (tiempos && !cancelado) {
|
|
@@ -16920,8 +17186,8 @@ async function trabajarVideo(c, d, r2, turno, buzon) {
|
|
|
16920
17186
|
}
|
|
16921
17187
|
}
|
|
16922
17188
|
if (cancelado) return { tipo: "cancelado", videoId: id3 };
|
|
16923
|
-
if (res.abortado) return d.senal?.aborted ? await devolverAlApagar(c, d, r2, ultimo.etapa) : await fallar(ultimo.etapa, "el worker se detuvo mientras generaba; se reintentar\xE1", null, true);
|
|
16924
|
-
const mp42 =
|
|
17189
|
+
if (res.abortado) return d.senal?.aborted ? await devolverAlApagar(c, d, r2, ultimo.etapa) : await fallar(ultimo.etapa, "el worker se detuvo mientras generaba; se reintentar\xE1", null, true, "corte");
|
|
17190
|
+
const mp42 = join33(salidaDir, "video.mp4");
|
|
16925
17191
|
const refParecido = d.parecido && pedido["previa"] !== true ? elegirReferencia(pedido, r2.media, r2.origen, d.motorDir) : null;
|
|
16926
17192
|
const parecido = refParecido && d.parecido ? crearParecidoDelVideo({ medidor: d.parecido, referencia: refParecido, pedidoDir, raiz, titulo: r2.titulo, bajarReferencias }) : null;
|
|
16927
17193
|
let registroCompositor;
|
|
@@ -16953,7 +17219,7 @@ async function trabajarVideo(c, d, r2, turno, buzon) {
|
|
|
16953
17219
|
if (cancelado || paso2.tipo === "cancelado") return { tipo: "cancelado", videoId: id3 };
|
|
16954
17220
|
if (paso2.tipo === "renderizado") res = paso2.res;
|
|
16955
17221
|
registroCompositor = paso2.registro;
|
|
16956
|
-
if (res.abortado) return d.senal?.aborted ? await devolverAlApagar(c, d, r2, ultimo.etapa) : await fallar(ultimo.etapa, "el worker se detuvo mientras generaba; se reintentar\xE1", null, true);
|
|
17222
|
+
if (res.abortado) return d.senal?.aborted ? await devolverAlApagar(c, d, r2, ultimo.etapa) : await fallar(ultimo.etapa, "el worker se detuvo mientras generaba; se reintentar\xE1", null, true, "corte");
|
|
16957
17223
|
}
|
|
16958
17224
|
const advertencias = [];
|
|
16959
17225
|
if (res.codigo === 0 || res.codigo === 15) {
|
|
@@ -16969,9 +17235,9 @@ async function trabajarVideo(c, d, r2, turno, buzon) {
|
|
|
16969
17235
|
}
|
|
16970
17236
|
if (pedido["previa"] === true) {
|
|
16971
17237
|
if (!await esPrevia(salidaDir)) return await fallar("render", "el pedido es una previa pero el motor no la gener\xF3 (imagen del motor anterior a 0.9.0): actualiza la imagen del motor", null, false);
|
|
16972
|
-
const subida = await reintentar("previa 360p", () => d.api.adjuntarPrevia(id3, r2.version, mp42, { senal: parar.signal, ...r2.reclamo ? { reclamo: r2.reclamo } : {} }),
|
|
17238
|
+
const subida = await reintentar("previa 360p", () => d.api.adjuntarPrevia(id3, r2.version, mp42, { senal: parar.signal, ...r2.reclamo ? { reclamo: r2.reclamo } : {} }), dormir2, log, parar.signal);
|
|
16973
17239
|
if (subida === "cancelado") return { tipo: "cancelado", videoId: id3 };
|
|
16974
|
-
if (subida instanceof Error) return await fallar("revision", `no se pudo adjuntar la previa: ${subida.message}`, null, true);
|
|
17240
|
+
if (subida instanceof Error) return await fallar("revision", `no se pudo adjuntar la previa: ${subida.message}`, null, true, "corte");
|
|
16975
17241
|
d.avance?.terminar(`${r2.titulo}: previa lista`, true);
|
|
16976
17242
|
log(`previa lista ${id3}`);
|
|
16977
17243
|
return { tipo: "listo", videoId: id3, estado: "en_revision", advertencias };
|
|
@@ -16980,7 +17246,7 @@ async function trabajarVideo(c, d, r2, turno, buzon) {
|
|
|
16980
17246
|
const avisar = (mensaje, nivel, datos) => (d.avance?.nota(mensaje), api.progreso(id3, { etapa: "revision", porcentaje: 100, mensaje, ...nivel ? { nivel } : {}, ...datos ? { datos } : {} }).catch(() => {
|
|
16981
17247
|
}));
|
|
16982
17248
|
for (const { clave, informe } of await leerInformes(salidaDir, manifiesto, pedido)) {
|
|
16983
|
-
const sube = await reintentar(`informe de revisi\xF3n ${clave}`, () => d.api.adjuntarArtefacto(id3, r2.version, "revision", clave, informe, { senal: parar.signal, ...r2.reclamo ? { reclamo: r2.reclamo } : {} }),
|
|
17249
|
+
const sube = await reintentar(`informe de revisi\xF3n ${clave}`, () => d.api.adjuntarArtefacto(id3, r2.version, "revision", clave, informe, { senal: parar.signal, ...r2.reclamo ? { reclamo: r2.reclamo } : {} }), dormir2, log, parar.signal);
|
|
16984
17250
|
if (sube === "cancelado") return { tipo: "cancelado", videoId: id3 };
|
|
16985
17251
|
if (sube instanceof Error) {
|
|
16986
17252
|
const aviso = `No se pudo subir el informe de revisi\xF3n del render ${clave}: ${sube.message}`;
|
|
@@ -16989,7 +17255,7 @@ async function trabajarVideo(c, d, r2, turno, buzon) {
|
|
|
16989
17255
|
}
|
|
16990
17256
|
}
|
|
16991
17257
|
if (manifiesto.construccion) {
|
|
16992
|
-
const sube = await reintentar("registro de construcci\xF3n", () => d.api.adjuntarArtefacto(id3, r2.version, "construccion", "version", manifiesto.construccion, { senal: parar.signal, ...r2.reclamo ? { reclamo: r2.reclamo } : {} }),
|
|
17258
|
+
const sube = await reintentar("registro de construcci\xF3n", () => d.api.adjuntarArtefacto(id3, r2.version, "construccion", "version", manifiesto.construccion, { senal: parar.signal, ...r2.reclamo ? { reclamo: r2.reclamo } : {} }), dormir2, log, parar.signal);
|
|
16993
17259
|
if (sube === "cancelado") return { tipo: "cancelado", videoId: id3 };
|
|
16994
17260
|
if (sube instanceof Error) {
|
|
16995
17261
|
const aviso = `No se pudo subir el registro de construcci\xF3n de la versi\xF3n: ${sube.message}`;
|
|
@@ -17001,11 +17267,11 @@ async function trabajarVideo(c, d, r2, turno, buzon) {
|
|
|
17001
17267
|
await avisar(`midiendo el parecido con la referencia \xAB${parecido.referencia.nombre ?? "referencia"}\xBB`);
|
|
17002
17268
|
try {
|
|
17003
17269
|
const p = await parecido.final(mp42, registroCompositor);
|
|
17004
|
-
const sube = await reintentar("m\xE9tricas de parecido", () => d.api.adjuntarArtefacto(id3, r2.version, "parecido", "version", p.artefacto, transfP),
|
|
17270
|
+
const sube = await reintentar("m\xE9tricas de parecido", () => d.api.adjuntarArtefacto(id3, r2.version, "parecido", "version", p.artefacto, transfP), dormir2, log, parar.signal);
|
|
17005
17271
|
if (sube === "cancelado") return { tipo: "cancelado", videoId: id3 };
|
|
17006
17272
|
if (sube instanceof Error) throw sube;
|
|
17007
17273
|
if (p.hoja) {
|
|
17008
|
-
const hoja = await reintentar("hoja de parecido", () => d.api.adjuntarHojaParecido(id3, r2.version, renders0(manifiesto), p.hoja, transfP),
|
|
17274
|
+
const hoja = await reintentar("hoja de parecido", () => d.api.adjuntarHojaParecido(id3, r2.version, renders0(manifiesto), p.hoja, transfP), dormir2, log, parar.signal, true);
|
|
17009
17275
|
if (hoja === "cancelado") return { tipo: "cancelado", videoId: id3 };
|
|
17010
17276
|
if (hoja instanceof Error) {
|
|
17011
17277
|
p.resumen.hoja = false;
|
|
@@ -17023,7 +17289,7 @@ async function trabajarVideo(c, d, r2, turno, buzon) {
|
|
|
17023
17289
|
}
|
|
17024
17290
|
if (res.codigo === 15) {
|
|
17025
17291
|
const f = await checksFallidos(salidaDir);
|
|
17026
|
-
if (c.siFallaRevision === "rechazar") return await fallar("revision", `La revisi\xF3n autom\xE1tica no pas\xF3: ${f}`, 15, true);
|
|
17292
|
+
if (c.siFallaRevision === "rechazar") return await fallar("revision", `La revisi\xF3n autom\xE1tica no pas\xF3: ${f}`, 15, true, "composicion");
|
|
17027
17293
|
const avisoRevision = `La revisi\xF3n autom\xE1tica no pas\xF3: ${f}`;
|
|
17028
17294
|
advertencias.push(avisoRevision);
|
|
17029
17295
|
await api.progreso(id3, { etapa: "revision", porcentaje: 100, mensaje: avisoRevision, nivel: "advertencia", ...r_2 }).catch(() => {
|
|
@@ -17034,7 +17300,7 @@ async function trabajarVideo(c, d, r2, turno, buzon) {
|
|
|
17034
17300
|
const cola = d.pendientes === null ? null : d.pendientes ?? (c.trabajoDir ? colaPendientesDe(c) : null);
|
|
17035
17301
|
let guardados = 0;
|
|
17036
17302
|
for (const x2 of insumos) {
|
|
17037
|
-
const sube = await reintentar(`insumo ${x2.ruta}`, () => d.api.adjuntarInsumo(id3, r2.version, x2.ruta, x2.archivo, transfP),
|
|
17303
|
+
const sube = await reintentar(`insumo ${x2.ruta}`, () => d.api.adjuntarInsumo(id3, r2.version, x2.ruta, x2.archivo, transfP), dormir2, log, parar.signal, true);
|
|
17038
17304
|
if (sube === "cancelado") return { tipo: "cancelado", videoId: id3 };
|
|
17039
17305
|
if (sube instanceof ErrorApi && sube.estado === 501) {
|
|
17040
17306
|
log(`insumos: ${sube.message}`);
|
|
@@ -17055,12 +17321,12 @@ async function trabajarVideo(c, d, r2, turno, buzon) {
|
|
|
17055
17321
|
let total2 = 0;
|
|
17056
17322
|
let rechazada = false;
|
|
17057
17323
|
let enCola = 0;
|
|
17058
|
-
for (const [clave,
|
|
17324
|
+
for (const [clave, ruta2] of Object.entries(RUTAS_EDICION)) {
|
|
17059
17325
|
const rel = manifiesto.edicion[clave];
|
|
17060
17326
|
const archivo2 = rel ? rutaDentro(salidaDir, rel) : null;
|
|
17061
17327
|
if (!archivo2 || !await existe3(archivo2)) continue;
|
|
17062
17328
|
total2 += 1;
|
|
17063
|
-
const sube = await reintentar(`paquete para editar ${
|
|
17329
|
+
const sube = await reintentar(`paquete para editar ${ruta2}`, () => d.api.adjuntarInsumo(id3, r2.version, ruta2, archivo2, transfP).catch((e7) => e7 instanceof ErrorApi && e7.estado === 400 && /ruta de insumo inv/i.test(e7.message) ? e7 : Promise.reject(e7)), dormir2, log, parar.signal, true);
|
|
17064
17330
|
if (sube === "cancelado") return { tipo: "cancelado", videoId: id3 };
|
|
17065
17331
|
if (sube instanceof ErrorApi && sube.estado === 501) {
|
|
17066
17332
|
log(`paquete para editar: ${sube.message}`);
|
|
@@ -17071,8 +17337,8 @@ async function trabajarVideo(c, d, r2, turno, buzon) {
|
|
|
17071
17337
|
break;
|
|
17072
17338
|
}
|
|
17073
17339
|
if (sube instanceof Error) {
|
|
17074
|
-
sinSubir.push(
|
|
17075
|
-
if (cola) enCola += Number(await encolar(cola, { tipo: "insumo", videoId: id3, version: r2.version, destino:
|
|
17340
|
+
sinSubir.push(ruta2);
|
|
17341
|
+
if (cola) enCola += Number(await encolar(cola, { tipo: "insumo", videoId: id3, version: r2.version, destino: ruta2, archivo: archivo2, error: sube.message }, log));
|
|
17076
17342
|
}
|
|
17077
17343
|
}
|
|
17078
17344
|
const aviso = rechazada ? "La API no admite todav\xEDa el paquete para editar (rechaz\xF3 las rutas edicion/*): el video se entrega sin pistas separadas ni subt\xEDtulos descargables" : sinSubir.length ? `No se pudieron subir ${sinSubir.length} de ${total2} archivos del paquete para editar (${sinSubir.slice(0, 3).join(", ")}${sinSubir.length > 3 ? "\u2026" : ""}): el video se entrega igual${enCola ? " y quedan en la cola local de pendientes para reintentarse despu\xE9s" : ""}` : void 0;
|
|
@@ -17081,17 +17347,17 @@ async function trabajarVideo(c, d, r2, turno, buzon) {
|
|
|
17081
17347
|
await avisar(aviso, "advertencia");
|
|
17082
17348
|
}
|
|
17083
17349
|
}
|
|
17084
|
-
const sub = await subirPiezas(d, id3, r2.version, salidaDir,
|
|
17350
|
+
const sub = await subirPiezas(d, id3, r2.version, salidaDir, dormir2, log, parar.signal, r2.reclamo ?? void 0);
|
|
17085
17351
|
if (sub === "cancelado") return { tipo: "cancelado", videoId: id3 };
|
|
17086
|
-
if (sub instanceof Error) return await fallar("piezas", `no se pudieron subir las piezas: ${sub.message}`, null, true);
|
|
17352
|
+
if (sub instanceof Error) return await fallar("piezas", `no se pudieron subir las piezas: ${sub.message}`, null, true, "corte");
|
|
17087
17353
|
const transf = { senal: parar.signal, ...r2.reclamo ? { reclamo: r2.reclamo } : {} };
|
|
17088
17354
|
const renders = manifiesto.renders;
|
|
17089
|
-
const duracionDe = async (
|
|
17355
|
+
const duracionDe = async (ruta2) => {
|
|
17090
17356
|
if (manifiesto.duracionS) return manifiesto.duracionS;
|
|
17091
17357
|
try {
|
|
17092
|
-
if (d.medirDuracion) return await d.medirDuracion(
|
|
17358
|
+
if (d.medirDuracion) return await d.medirDuracion(ruta2);
|
|
17093
17359
|
const bins = buscarFfmpeg((cmd) => buscarEnPath(cmd, process.env));
|
|
17094
|
-
return bins ? await medirDuracion(
|
|
17360
|
+
return bins ? await medirDuracion(ruta2, bins, correrReal) : void 0;
|
|
17095
17361
|
} catch {
|
|
17096
17362
|
return void 0;
|
|
17097
17363
|
}
|
|
@@ -17099,18 +17365,18 @@ async function trabajarVideo(c, d, r2, turno, buzon) {
|
|
|
17099
17365
|
const total = Math.max(renders.length, 1);
|
|
17100
17366
|
const subidos = [];
|
|
17101
17367
|
for (const [k, render] of renders.slice(1).entries()) {
|
|
17102
|
-
const
|
|
17103
|
-
if (!
|
|
17368
|
+
const ruta2 = rutaDeRender(salidaDir, render);
|
|
17369
|
+
if (!ruta2 || !await existe3(ruta2)) return await fallar("revision", `el manifiesto anuncia el render ${render.etiqueta} pero no est\xE1 ${render.ruta}`, res.codigo, true);
|
|
17104
17370
|
if (render.aprobada === false) {
|
|
17105
17371
|
const aviso = `El render ${render.etiqueta} no pas\xF3 la revisi\xF3n autom\xE1tica: ${render.checksFallidos.join(", ") || "sin detalle"}; se adjunta igual`;
|
|
17106
17372
|
advertencias.push(aviso);
|
|
17107
17373
|
await avisar(aviso, "advertencia");
|
|
17108
17374
|
}
|
|
17109
17375
|
await avisar(`subiendo render ${k + 2}/${total} (${render.etiqueta})`, void 0, { render: render.etiqueta, indice: k + 2, total, destinos: render.destinos });
|
|
17110
|
-
const durRender = await duracionDe(
|
|
17111
|
-
const adj2 = await reintentar(`render ${render.etiqueta}`, () => d.api.adjuntarRender(id3, r2.version, render.etiqueta,
|
|
17376
|
+
const durRender = await duracionDe(ruta2);
|
|
17377
|
+
const adj2 = await reintentar(`render ${render.etiqueta}`, () => d.api.adjuntarRender(id3, r2.version, render.etiqueta, ruta2, revisionDe(render), { ...transf, ...durRender ? { duracionS: durRender } : {} }), dormir2, log, parar.signal);
|
|
17112
17378
|
if (adj2 === "cancelado") return { tipo: "cancelado", videoId: id3 };
|
|
17113
|
-
if (adj2 instanceof Error) return await fallar("revision", `no se pudo adjuntar el render ${render.etiqueta}: ${adj2.message}`, null, true);
|
|
17379
|
+
if (adj2 instanceof Error) return await fallar("revision", `no se pudo adjuntar el render ${render.etiqueta}: ${adj2.message}`, null, true, "corte");
|
|
17114
17380
|
subidos.push(render.etiqueta);
|
|
17115
17381
|
}
|
|
17116
17382
|
const pedidos = Array.isArray(pedido["renders"]) ? pedido["renders"].length : 1;
|
|
@@ -17120,16 +17386,16 @@ async function trabajarVideo(c, d, r2, turno, buzon) {
|
|
|
17120
17386
|
await avisar(aviso, "advertencia");
|
|
17121
17387
|
}
|
|
17122
17388
|
for (const render of renders) {
|
|
17123
|
-
const
|
|
17124
|
-
if (!
|
|
17125
|
-
const sube = await reintentar(`p\xF3ster ${render.etiqueta}`, () => d.api.adjuntarPoster(id3, r2.version, render.etiqueta,
|
|
17389
|
+
const ruta2 = rutaDentro(salidaDir, render.rutaPoster);
|
|
17390
|
+
if (!ruta2 || !await existe3(ruta2)) continue;
|
|
17391
|
+
const sube = await reintentar(`p\xF3ster ${render.etiqueta}`, () => d.api.adjuntarPoster(id3, r2.version, render.etiqueta, ruta2, transf), dormir2, log, parar.signal, true);
|
|
17126
17392
|
if (sube === "cancelado") return { tipo: "cancelado", videoId: id3 };
|
|
17127
17393
|
if (sube instanceof ErrorApi && sube.estado === 501) {
|
|
17128
17394
|
log(`p\xF3ster: ${sube.message}`);
|
|
17129
17395
|
break;
|
|
17130
17396
|
}
|
|
17131
17397
|
if (sube instanceof Error) {
|
|
17132
|
-
const guardado = cola ? await encolar(cola, { tipo: "poster", videoId: id3, version: r2.version, destino: render.etiqueta, archivo:
|
|
17398
|
+
const guardado = cola ? await encolar(cola, { tipo: "poster", videoId: id3, version: r2.version, destino: render.etiqueta, archivo: ruta2, error: sube.message }, log) : false;
|
|
17133
17399
|
const aviso = `No se pudo subir la miniatura del render ${render.etiqueta}: ${sube.message}${guardado ? " (queda en la cola local de pendientes)" : ""}`;
|
|
17134
17400
|
advertencias.push(aviso);
|
|
17135
17401
|
await avisar(aviso, "advertencia");
|
|
@@ -17142,9 +17408,9 @@ async function trabajarVideo(c, d, r2, turno, buzon) {
|
|
|
17142
17408
|
if (total > 1) await avisar(`subiendo render 1/${total} (${principal.etiqueta})`, void 0, { render: principal.etiqueta, indice: 1, total, destinos: principal.destinos });
|
|
17143
17409
|
const durPrincipal = await duracionDe(mp42);
|
|
17144
17410
|
const opciones = { ...transf, ...durPrincipal ? { duracionS: durPrincipal } : {}, ...manifiesto.costo ?? {}, ...principal && revisionDe(principal) ? { revision: revisionDe(principal) } : {}, ...subidos.length ? { renders: subidos } : {} };
|
|
17145
|
-
const adj = await reintentar("MP4", () => d.api.adjuntarMp4(id3, r2.version, mp42, opciones),
|
|
17411
|
+
const adj = await reintentar("MP4", () => d.api.adjuntarMp4(id3, r2.version, mp42, opciones), dormir2, log, parar.signal);
|
|
17146
17412
|
if (adj === "cancelado") return { tipo: "cancelado", videoId: id3 };
|
|
17147
|
-
if (adj instanceof Error) return await fallar("revision", `no se pudo adjuntar el MP4: ${adj.message}`, null, true);
|
|
17413
|
+
if (adj instanceof Error) return await fallar("revision", `no se pudo adjuntar el MP4: ${adj.message}`, null, true, "corte");
|
|
17148
17414
|
entregado = true;
|
|
17149
17415
|
clearInterval(latido);
|
|
17150
17416
|
cancelado = true;
|
|
@@ -17153,11 +17419,13 @@ async function trabajarVideo(c, d, r2, turno, buzon) {
|
|
|
17153
17419
|
log(avisoSb);
|
|
17154
17420
|
advertencias.push(avisoSb);
|
|
17155
17421
|
}
|
|
17422
|
+
if (guionGuardado) await olvidarGuion(c.trabajoDir, { video_id: id3, version: r2.version }).catch(() => {
|
|
17423
|
+
});
|
|
17156
17424
|
d.avance?.terminar(`${r2.titulo}: listo (${adj.estado})`, true);
|
|
17157
17425
|
log(`listo ${id3}: ${adj.estado}`);
|
|
17158
17426
|
return { tipo: "listo", videoId: id3, estado: adj.estado, advertencias };
|
|
17159
17427
|
}
|
|
17160
|
-
return await fallar(res.error?.etapa ?? ultimo.etapa, causaLegible(res, Math.round(c.timeoutMs / 6e4)), res.codigo, res.codigo !== 2 || res.tiempoAgotado);
|
|
17428
|
+
return await fallar(res.error?.etapa ?? ultimo.etapa, causaLegible(res, Math.round(c.timeoutMs / 6e4)), res.codigo, res.codigo !== 2 || res.tiempoAgotado, claseDeFalloMotor(res));
|
|
17161
17429
|
} finally {
|
|
17162
17430
|
d.avance?.detener();
|
|
17163
17431
|
clearInterval(latido);
|
|
@@ -17178,7 +17446,7 @@ async function trabajarVideo(c, d, r2, turno, buzon) {
|
|
|
17178
17446
|
log(`${id3}: no pude guardar los formatos del intento: ${e7.message}`);
|
|
17179
17447
|
}
|
|
17180
17448
|
}
|
|
17181
|
-
if (!c.conservar && !agenteB) await
|
|
17449
|
+
if (!c.conservar && !agenteB) await rm10(raiz, { recursive: true, force: true });
|
|
17182
17450
|
}
|
|
17183
17451
|
}
|
|
17184
17452
|
async function caminoAgenteB(c, d, r2, cfg, x2) {
|
|
@@ -17203,7 +17471,7 @@ async function caminoAgenteB(c, d, r2, cfg, x2) {
|
|
|
17203
17471
|
pedido_ruta: x2.rutaPedido,
|
|
17204
17472
|
referencias: {
|
|
17205
17473
|
pedido: Array.isArray(x2.pedido["referencias"]) ? x2.pedido["referencias"] : [],
|
|
17206
|
-
archivos: Object.fromEntries(Object.entries(refs.archivos).map(([k, v2]) => [k,
|
|
17474
|
+
archivos: Object.fromEntries(Object.entries(refs.archivos).map(([k, v2]) => [k, join33(dirname11(x2.rutaPedido), v2.ruta)])),
|
|
17207
17475
|
fallos: refs.fallos
|
|
17208
17476
|
},
|
|
17209
17477
|
carpeta: x2.raiz,
|
|
@@ -17229,7 +17497,7 @@ async function caminoAgenteB(c, d, r2, cfg, x2) {
|
|
|
17229
17497
|
}
|
|
17230
17498
|
actualizarTrabajo(cfg, trabajo, { estado: "aprobado" });
|
|
17231
17499
|
await x2.turno.tomar();
|
|
17232
|
-
const final =
|
|
17500
|
+
const final = join33(x2.raiz, "final", "video.mp4");
|
|
17233
17501
|
if (fin.respuesta.usar_final === true && await existe3(final)) {
|
|
17234
17502
|
x2.log(`buz\xF3n ${r2.video_id}: aprobado; uso el final/ que renderiz\xF3 el Agente B`);
|
|
17235
17503
|
return { tipo: "listo", res: { codigo: 0, tiempoAgotado: false, abortado: false, error: null, stderrCola: [] } };
|
|
@@ -17248,17 +17516,28 @@ async function caminoAgenteB(c, d, r2, cfg, x2) {
|
|
|
17248
17516
|
}
|
|
17249
17517
|
};
|
|
17250
17518
|
}
|
|
17251
|
-
async function pasoGuionista(d, r2, pedido, raiz, senal, log, bitacora2) {
|
|
17519
|
+
async function pasoGuionista(d, trabajoDir, r2, pedido, raiz, senal, log, bitacora2) {
|
|
17252
17520
|
const encargo = leerEncargoGuionista(r2.origen);
|
|
17253
17521
|
if (!encargo) return { tipo: "sin_paso" };
|
|
17254
|
-
const omitir = !d.guionista ? "el worker no lo activ\xF3 (--guionista)" : pedido["previa"] === true ? "vista previa" : r2.reutilizar ? "reutiliza escenas de la versi\xF3n anterior" :
|
|
17522
|
+
const omitir = !d.guionista ? "el worker no lo activ\xF3 (--guionista)" : pedido["previa"] === true ? "vista previa" : r2.reutilizar ? "reutiliza escenas de la versi\xF3n anterior" : null;
|
|
17523
|
+
if (!omitir && r2.intento > 1) {
|
|
17524
|
+
const dec = await guionParaReintento(trabajoDir, r2);
|
|
17525
|
+
if (dec.tipo === "conservar") {
|
|
17526
|
+
log(`${r2.video_id}: ${dec.mensaje}`);
|
|
17527
|
+
await bitacora2(dec.mensaje, void 0, { guionista: { ...dec.registro, conservado: true } });
|
|
17528
|
+
return { tipo: "ok", pedido: dec.pedido, registro: dec.registro };
|
|
17529
|
+
}
|
|
17530
|
+
log(`${r2.video_id}: guionista omitido (${dec.razon})`);
|
|
17531
|
+
await bitacora2(`guionista omitido: ${dec.razon}; sale el guion original`, "advertencia", { guionista: { omitido: true, razon: dec.razon } });
|
|
17532
|
+
return { tipo: "omitido", razon: dec.razon };
|
|
17533
|
+
}
|
|
17255
17534
|
if (omitir) {
|
|
17256
17535
|
log(`${r2.video_id}: guionista omitido (${omitir})`);
|
|
17257
17536
|
await bitacora2(`guionista omitido: ${omitir}; sale el guion original`, "advertencia", { guionista: { omitido: true, razon: omitir } });
|
|
17258
17537
|
return { tipo: "omitido", razon: omitir };
|
|
17259
17538
|
}
|
|
17260
17539
|
log(`${r2.video_id}: guionista: reescribiendo el guion con ${d.guionista.ejecutor}`);
|
|
17261
|
-
const res = await d.guionista.reescribir({ r: r2, encargo, dir:
|
|
17540
|
+
const res = await d.guionista.reescribir({ r: r2, encargo, dir: join33(raiz, "guionista"), senal });
|
|
17262
17541
|
if (res.tipo === "cancelado") return res;
|
|
17263
17542
|
const mensaje = mensajeGuionista(res.registro);
|
|
17264
17543
|
log(`${r2.video_id}: ${mensaje}`);
|
|
@@ -17330,14 +17609,14 @@ var ASPECTO_DE = { "1080x1920": "9:16", "1920x1080": "16:9", "1080x1080": "1:1",
|
|
|
17330
17609
|
var renders0 = (m) => m.renders[0]?.etiqueta ?? null;
|
|
17331
17610
|
async function esPrevia(salidaDir) {
|
|
17332
17611
|
try {
|
|
17333
|
-
return JSON.parse(await
|
|
17612
|
+
return JSON.parse(await readFile15(join33(salidaDir, "manifiesto.json"), "utf8")).previa === true;
|
|
17334
17613
|
} catch {
|
|
17335
17614
|
return false;
|
|
17336
17615
|
}
|
|
17337
17616
|
}
|
|
17338
17617
|
async function checksFallidos(salidaDir) {
|
|
17339
17618
|
try {
|
|
17340
|
-
const rev = JSON.parse(await
|
|
17619
|
+
const rev = JSON.parse(await readFile15(join33(salidaDir, "revision.json"), "utf8"));
|
|
17341
17620
|
const malos = (rev.checks ?? []).filter((x2) => !x2.ok && x2.nivel === "requerido").map((x2) => x2.detalle ? `${x2.id} (${x2.detalle})` : x2.id);
|
|
17342
17621
|
return malos.length ? malos.join(", ") : "sin detalle";
|
|
17343
17622
|
} catch {
|
|
@@ -17346,17 +17625,17 @@ async function checksFallidos(salidaDir) {
|
|
|
17346
17625
|
}
|
|
17347
17626
|
async function piezasDelManifiesto(salidaDir) {
|
|
17348
17627
|
try {
|
|
17349
|
-
const m = JSON.parse(await
|
|
17350
|
-
return (m.renders?.[0]?.archivos?.piezas ?? []).flatMap((p) => typeof p.ruta === "string" ? [
|
|
17628
|
+
const m = JSON.parse(await readFile15(join33(salidaDir, "manifiesto.json"), "utf8"));
|
|
17629
|
+
return (m.renders?.[0]?.archivos?.piezas ?? []).flatMap((p) => typeof p.ruta === "string" ? [join33(salidaDir, p.ruta)] : []);
|
|
17351
17630
|
} catch {
|
|
17352
17631
|
return [];
|
|
17353
17632
|
}
|
|
17354
17633
|
}
|
|
17355
|
-
async function subirPiezas(d, id3, version2, salidaDir,
|
|
17356
|
-
for (const
|
|
17357
|
-
const sube = await reintentar(`pieza ${
|
|
17634
|
+
async function subirPiezas(d, id3, version2, salidaDir, dormir2, log, senal, reclamo) {
|
|
17635
|
+
for (const ruta2 of await piezasDelManifiesto(salidaDir)) {
|
|
17636
|
+
const sube = await reintentar(`pieza ${ruta2.split("/").pop()}`, () => d.api.adjuntarPieza(id3, version2, ruta2, senal, reclamo), dormir2, log, senal);
|
|
17358
17637
|
if (sube === "cancelado" || sube instanceof Error) return sube;
|
|
17359
|
-
log(`pieza subida: ${
|
|
17638
|
+
log(`pieza subida: ${ruta2.split("/").pop()}`);
|
|
17360
17639
|
}
|
|
17361
17640
|
return "ok";
|
|
17362
17641
|
}
|
|
@@ -17367,15 +17646,15 @@ function rutaDeRender(salidaDir, r2) {
|
|
|
17367
17646
|
return rutaDentro(salidaDir, r2.ruta);
|
|
17368
17647
|
}
|
|
17369
17648
|
function rutaDentro(salidaDir, relativa) {
|
|
17370
|
-
const
|
|
17371
|
-
return
|
|
17649
|
+
const ruta2 = resolve10(salidaDir, relativa);
|
|
17650
|
+
return ruta2.startsWith(resolve10(salidaDir) + sep5) ? ruta2 : null;
|
|
17372
17651
|
}
|
|
17373
17652
|
var INTENTOS_TRANSITORIO = 5;
|
|
17374
17653
|
var INTENTOS_OTRO = 3;
|
|
17375
17654
|
var ESPERA_BASE_MS = 2e3;
|
|
17376
17655
|
var ESPERA_TOPE_MS = 3e4;
|
|
17377
17656
|
var intentosPara = (e7) => e7 instanceof ErrorApi && e7.transitorio ? INTENTOS_TRANSITORIO : INTENTOS_OTRO;
|
|
17378
|
-
async function reintentar(que, accion,
|
|
17657
|
+
async function reintentar(que, accion, dormir2, log, senal, sinReintentar501 = false) {
|
|
17379
17658
|
for (let i = 1; ; i++) {
|
|
17380
17659
|
if (senal?.aborted) return "cancelado";
|
|
17381
17660
|
try {
|
|
@@ -17386,7 +17665,7 @@ async function reintentar(que, accion, dormir, log, senal, sinReintentar501 = fa
|
|
|
17386
17665
|
const max = intentosPara(e7);
|
|
17387
17666
|
log(`adjuntar ${que} fall\xF3 (intento ${i}/${max}): ${e7.message}`);
|
|
17388
17667
|
if (i >= max) return e7;
|
|
17389
|
-
await
|
|
17668
|
+
await dormir2(esperaConJitter(i, ESPERA_BASE_MS, ESPERA_TOPE_MS));
|
|
17390
17669
|
}
|
|
17391
17670
|
}
|
|
17392
17671
|
}
|
|
@@ -17448,12 +17727,7 @@ async function correrBucle(c, d) {
|
|
|
17448
17727
|
}
|
|
17449
17728
|
}
|
|
17450
17729
|
if (!sigue()) break;
|
|
17451
|
-
await
|
|
17452
|
-
const t = setTimeout(res, espera);
|
|
17453
|
-
const fin = () => (clearTimeout(t), res());
|
|
17454
|
-
senal.addEventListener("abort", fin, { once: true });
|
|
17455
|
-
d.apagando?.addEventListener("abort", fin, { once: true });
|
|
17456
|
-
});
|
|
17730
|
+
await dormir(espera, senal, d.apagando);
|
|
17457
17731
|
}
|
|
17458
17732
|
if (d.apagando?.aborted && !senal.aborted) log("apagado ordenado: sin trabajo en curso, salgo");
|
|
17459
17733
|
return codigo;
|
|
@@ -17668,7 +17942,7 @@ function configWorker(o, conexion, env, nombreEquipo, casa) {
|
|
|
17668
17942
|
CLAQUETA_API_URL: conexion.url,
|
|
17669
17943
|
WORKER_NOMBRE: o.agente ?? nombreEquipo,
|
|
17670
17944
|
MOTOR_IMAGEN: o.motorImagen ?? IMAGEN_POR_DEFECTO,
|
|
17671
|
-
WORKER_TRABAJO_DIR: env["WORKER_TRABAJO_DIR"] ||
|
|
17945
|
+
WORKER_TRABAJO_DIR: env["WORKER_TRABAJO_DIR"] || join34(casa, ".cache", "claqueta", "trabajo"),
|
|
17672
17946
|
WORKER_SONDEO_S: String(o.intervaloS ?? (env["WORKER_SONDEO_S"] || 10)),
|
|
17673
17947
|
...o.topeFormatoMin ? { WORKER_TIMEOUT_MIN: String(o.topeFormatoMin) } : {},
|
|
17674
17948
|
...o.topeEtapaMin ? { WORKER_TIMEOUT_ETAPA_MIN: String(o.topeEtapaMin) } : {}
|
|
@@ -17676,11 +17950,7 @@ function configWorker(o, conexion, env, nombreEquipo, casa) {
|
|
|
17676
17950
|
const imagenClonacion = o.motorImagenClonacion ?? (IMAGEN_CLONACION_POR_DEFECTO || void 0);
|
|
17677
17951
|
return { ...c, apiToken: conexion.token, unaVez: o.unaVez, siFallaRevision: o.siFallaRevision, ...o.vozClonada ? { vozClonada: true, ...imagenClonacion ? { imagenClonacion } : {} } : {} };
|
|
17678
17952
|
}
|
|
17679
|
-
var dormirReal2 = (ms2, senal) =>
|
|
17680
|
-
if (senal?.aborted) return resolver();
|
|
17681
|
-
const t = setTimeout(resolver, ms2);
|
|
17682
|
-
senal?.addEventListener("abort", () => (clearTimeout(t), resolver()), { once: true });
|
|
17683
|
-
});
|
|
17953
|
+
var dormirReal2 = (ms2, senal) => dormir(ms2, senal);
|
|
17684
17954
|
function configAgenteB(env, casa) {
|
|
17685
17955
|
if (env["WORKER_AGENTE_B"] === "0") return void 0;
|
|
17686
17956
|
const min2 = (k, def) => {
|
|
@@ -17688,8 +17958,8 @@ function configAgenteB(env, casa) {
|
|
|
17688
17958
|
return (env[k] && Number.isFinite(n) && n > 0 ? n : def) * 6e4;
|
|
17689
17959
|
};
|
|
17690
17960
|
return {
|
|
17691
|
-
presenciaDir:
|
|
17692
|
-
buzonDir:
|
|
17961
|
+
presenciaDir: join34(casa, "Claqueta", "presencia"),
|
|
17962
|
+
buzonDir: join34(casa, "Claqueta", "buzon"),
|
|
17693
17963
|
trabajoDir: carpetaBasePorDefecto(env, casa),
|
|
17694
17964
|
tomaMs: min2("WORKER_AGENTE_B_TOMA_MIN", 5),
|
|
17695
17965
|
maxMs: min2("WORKER_AGENTE_B_MAX_MIN", 45),
|
|
@@ -17717,7 +17987,7 @@ async function ejecutarWorker(o, d) {
|
|
|
17717
17987
|
const verificar = d.verificar ?? ((x2) => ejecutarDoctor({ json: false, ...x2.compositor ? { compositor: x2.compositor } : {}, ...guionistaActivado(x2, d.env) ? { guionista: true, guionistaActivado: true } : {}, ...x2.url ? { url: x2.url } : {}, ...x2.perfilAws ? { perfilAws: x2.perfilAws } : {}, ...x2.motorImagen ? { motorImagen: x2.motorImagen } : {}, ...x2.topeFormatoMin ? { topeFormatoMin: x2.topeFormatoMin } : {}, ...x2.topeEtapaMin ? { topeEtapaMin: x2.topeEtapaMin } : {}, modo: x2.modo }, { ...depsReales2(d.env), ejecutar, os: { plataforma: d.plataforma ?? process.platform, casa } }));
|
|
17718
17988
|
let informe = await verificar(o);
|
|
17719
17989
|
if (!informe.listo && d.env["CLAQUETA_SERVICIO"] === "1" && o.accion === "correr") {
|
|
17720
|
-
const
|
|
17990
|
+
const dormir2 = d.dormir ?? dormirReal2;
|
|
17721
17991
|
let ultimo = "";
|
|
17722
17992
|
for (let i = 0; !informe.listo; i++) {
|
|
17723
17993
|
const texto7 = formatearInforme(informe, false);
|
|
@@ -17727,7 +17997,7 @@ async function ejecutarWorker(o, d) {
|
|
|
17727
17997
|
${texto7}`);
|
|
17728
17998
|
}
|
|
17729
17999
|
const espera = ESPERAS_SERVICIO_MS[Math.min(i, ESPERAS_SERVICIO_MS.length - 1)];
|
|
17730
|
-
await
|
|
18000
|
+
await dormir2(espera, d.apagando ?? d.senal);
|
|
17731
18001
|
if (d.senal?.aborted || d.apagando?.aborted) return 0;
|
|
17732
18002
|
informe = await verificar(o);
|
|
17733
18003
|
}
|
|
@@ -17797,7 +18067,7 @@ ${formatearInforme(informe, false)}Corrige lo marcado con \u2716 o salta la veri
|
|
|
17797
18067
|
env: d.env,
|
|
17798
18068
|
motorDir: motorEmpaquetado
|
|
17799
18069
|
});
|
|
17800
|
-
const parecido = d.crearMedidor ? d.crearMedidor(c) : c.modo === "local" ? c.comando ? crearMedidor({ modo: "local", python:
|
|
18070
|
+
const parecido = d.crearMedidor ? d.crearMedidor(c) : c.modo === "local" ? c.comando ? crearMedidor({ modo: "local", python: join34(dirname12(c.comando), "python3"), scripts: join34(motorEmpaquetado, "scripts"), ffmpeg: buscarFfmpeg((cmd) => buscarEnPath(cmd, d.env))?.ffmpeg ?? "ffmpeg", env: c.entornoMotor ?? {} }, correrReal) : void 0 : crearMedidor({ modo: "docker", imagen: c.imagen, ...typeof process.getuid === "function" ? { usuario: `${process.getuid()}:${process.getgid()}` } : {} }, correrReal);
|
|
17801
18071
|
const agenteB = configAgenteB(d.env, casa);
|
|
17802
18072
|
log(`worker ${c.nombre} \u2192 ${c.apiUrl} (${c.modo === "local" ? "motor local sin Docker" : `imagen ${c.imagen}`}, trabajo en ${c.trabajoDir}, si falla la revisi\xF3n: ${c.siFallaRevision}${c.vozClonada ? `, voz clonada${c.modo === "docker" ? ` (${c.imagenClonacion})` : ""}` : ""}${compositor ? `, compositor ${compositor.ejecutor}${o.compositorTiempoMin ? ` (tope ${o.compositorTiempoMin} min)` : ""}` : ""}${guionista ? "" : ", sin guionista"})`);
|
|
17803
18073
|
const salida = await (d.bucle ?? correrBucle)(c, { api, log, senal: parar.signal, ...avance ? { avance } : {}, ...compositor ? { compositor } : {}, ...guionista ? { guionista } : {}, ...parecido ? { parecido, motorDir: motorEmpaquetado } : {}, bloqueo: rutaBloqueoMotor(casa), ...agenteB ? { agenteB } : {}, ...d.apagando ? { apagando: d.apagando } : {} });
|
|
@@ -17873,7 +18143,7 @@ function crearContextoLocal(o, d) {
|
|
|
17873
18143
|
const simulado = d.env["CLAQUETA_MOTOR_COMANDO"]?.trim();
|
|
17874
18144
|
let listo = null;
|
|
17875
18145
|
const preparar = async () => {
|
|
17876
|
-
if (simulado) return { modo: o.modo, imagen: imagen2, cache:
|
|
18146
|
+
if (simulado) return { modo: o.modo, imagen: imagen2, cache: join35(casa, ".cache", "claqueta", "simulado"), shm: "1g", comando: simulado };
|
|
17877
18147
|
if (o.modo === "local") {
|
|
17878
18148
|
d.log(AVISO_SIN_AISLAMIENTO);
|
|
17879
18149
|
const l = await prepararMotorLocal({ ejecutar, env: d.env, plataforma: process.platform, versionNode: process.version, casa, log: d.log, motorEmpaquetado: d.motorEmpaquetado });
|
|
@@ -17938,7 +18208,7 @@ import { createInterface as createInterface4 } from "node:readline";
|
|
|
17938
18208
|
|
|
17939
18209
|
// src/local/herramientas-agente-b.ts
|
|
17940
18210
|
import { hostname as hostname7 } from "node:os";
|
|
17941
|
-
import { join as
|
|
18211
|
+
import { join as join36 } from "node:path";
|
|
17942
18212
|
var esObjeto3 = (v2) => typeof v2 === "object" && v2 !== null && !Array.isArray(v2);
|
|
17943
18213
|
var MINUTOS_POR_DEFECTO = 10;
|
|
17944
18214
|
var MINUTOS_MAX = 120;
|
|
@@ -18028,7 +18298,7 @@ function resumirPedido(p) {
|
|
|
18028
18298
|
if (Array.isArray(p["media"])) r2["media"] = p["media"].length;
|
|
18029
18299
|
return r2;
|
|
18030
18300
|
}
|
|
18031
|
-
var absolutas = (carpeta2, v2) => esObjeto3(v2) ? Object.fromEntries(Object.entries(v2).map(([k, x2]) => [k, typeof x2 === "string" && !x2.startsWith("/") ?
|
|
18301
|
+
var absolutas = (carpeta2, v2) => esObjeto3(v2) ? Object.fromEntries(Object.entries(v2).map(([k, x2]) => [k, typeof x2 === "string" && !x2.startsWith("/") ? join36(carpeta2, x2) : x2])) : v2;
|
|
18032
18302
|
function motor(ctx) {
|
|
18033
18303
|
const d = duenoActivo(ctx.bloqueo, { esVivo: ctx.esVivo ?? vivoPorDefecto2 });
|
|
18034
18304
|
return d ? { libre: false, ocupado_con: d.paso, carpeta: d.carpeta, desde: d.desde, pid: d.pid } : { libre: true };
|
|
@@ -18059,7 +18329,7 @@ async function esperar(a, ctx, l) {
|
|
|
18059
18329
|
const soloVideo = typeof a["video_id"] === "string" && a["video_id"].trim() ? a["video_id"].trim() : void 0;
|
|
18060
18330
|
const ahora = ctx.ahora ?? Date.now;
|
|
18061
18331
|
const esVivo = ctx.esVivo ?? vivoPorDefecto2;
|
|
18062
|
-
const
|
|
18332
|
+
const dormir2 = ctx.dormir ?? dormirPorDefecto;
|
|
18063
18333
|
const sondeo = ctx.sondeoMs ?? 2e3;
|
|
18064
18334
|
const cadaProgreso = ctx.progresoMs ?? 15e3;
|
|
18065
18335
|
const p = ctx.presencia;
|
|
@@ -18070,7 +18340,10 @@ async function esperar(a, ctx, l) {
|
|
|
18070
18340
|
}
|
|
18071
18341
|
const terminar = p.empezarEspera();
|
|
18072
18342
|
const inicio = ahora();
|
|
18073
|
-
const
|
|
18343
|
+
const monotono = ctx.monotono ?? (() => performance.now());
|
|
18344
|
+
const plazoMs = minutos * 6e4;
|
|
18345
|
+
const m02 = monotono();
|
|
18346
|
+
const transcurrido = () => Math.max(ahora() - inicio, monotono() - m02);
|
|
18074
18347
|
let ultimoProgreso = -Infinity;
|
|
18075
18348
|
const perdidos = [];
|
|
18076
18349
|
try {
|
|
@@ -18087,13 +18360,14 @@ async function esperar(a, ctx, l) {
|
|
|
18087
18360
|
}
|
|
18088
18361
|
if (r2.tipo === "perdido") perdidos.push(`${c.trabajo.video_id}: ${r2.motivo}`);
|
|
18089
18362
|
}
|
|
18090
|
-
|
|
18091
|
-
if (
|
|
18092
|
-
|
|
18093
|
-
|
|
18094
|
-
|
|
18363
|
+
const va2 = transcurrido();
|
|
18364
|
+
if (va2 >= plazoMs) break;
|
|
18365
|
+
if (va2 - ultimoProgreso >= cadaProgreso) {
|
|
18366
|
+
ultimoProgreso = va2;
|
|
18367
|
+
const restante = Math.max(0, Math.ceil((plazoMs - va2) / 6e4));
|
|
18368
|
+
l.progreso?.(Math.min(99, Math.floor(va2 / plazoMs * 100)), `esperando un video del worker (quedan ~${restante} min)`);
|
|
18095
18369
|
}
|
|
18096
|
-
await
|
|
18370
|
+
await dormir2(Math.min(sondeo, Math.max(0, plazoMs - va2)), l.senal);
|
|
18097
18371
|
}
|
|
18098
18372
|
} finally {
|
|
18099
18373
|
terminar();
|
|
@@ -18152,14 +18426,14 @@ function videoDeLaSesion(a, ctx) {
|
|
|
18152
18426
|
}
|
|
18153
18427
|
async function acuse(ctx, t, l) {
|
|
18154
18428
|
const ahora = ctx.ahora ?? Date.now;
|
|
18155
|
-
const
|
|
18429
|
+
const dormir2 = ctx.dormir ?? dormirPorDefecto;
|
|
18156
18430
|
const fin = ahora() + (ctx.acuseMs ?? 1e4);
|
|
18157
18431
|
for (; ; ) {
|
|
18158
18432
|
const actual = leerTrabajo(ctx.buzonDir, t.video_id);
|
|
18159
18433
|
if (!actual || actual.creado !== t.creado) return { confirmo: false, estado_buzon: "reemplazado" };
|
|
18160
18434
|
if (actual.estado !== "esperando_agente" && actual.estado !== "tomado") return { confirmo: true, estado_buzon: actual.estado, ...actual.motivo ? { motivo: actual.motivo } : {} };
|
|
18161
18435
|
if (ahora() >= fin || l.senal?.aborted) return { confirmo: false, estado_buzon: actual.estado };
|
|
18162
|
-
await
|
|
18436
|
+
await dormir2(Math.min(ctx.sondeoMs ?? 2e3, Math.max(0, fin - ahora())), l.senal);
|
|
18163
18437
|
}
|
|
18164
18438
|
}
|
|
18165
18439
|
async function devolver(tipo, a, ctx, l) {
|
|
@@ -18238,16 +18512,16 @@ async function llamarHerramientaAgenteB(nombre, argumentos, ctx, l = {}) {
|
|
|
18238
18512
|
// src/local/herramientas-almacen.ts
|
|
18239
18513
|
import { existsSync as existsSync13 } from "node:fs";
|
|
18240
18514
|
import { homedir as homedir9 } from "node:os";
|
|
18241
|
-
import { join as
|
|
18515
|
+
import { join as join37 } from "node:path";
|
|
18242
18516
|
var esObjeto4 = (v2) => typeof v2 === "object" && v2 !== null && !Array.isArray(v2);
|
|
18243
18517
|
function simuladorDelEsquema() {
|
|
18244
18518
|
const de2 = (nombre) => Object.entries(core_exports).find(([k]) => k === nombre)?.[1];
|
|
18245
18519
|
const f = de2("simularNuevaVersion");
|
|
18246
|
-
const
|
|
18520
|
+
const leer3 = de2("leerHuellas");
|
|
18247
18521
|
if (typeof f !== "function") return null;
|
|
18248
18522
|
const simular = f;
|
|
18249
|
-
if (typeof
|
|
18250
|
-
return (e7) => simular({ ...e7, huellas: e7.huellas == null ? null :
|
|
18523
|
+
if (typeof leer3 !== "function") return simular;
|
|
18524
|
+
return (e7) => simular({ ...e7, huellas: e7.huellas == null ? null : leer3(JSON.stringify(e7.huellas)) });
|
|
18251
18525
|
}
|
|
18252
18526
|
var esquema2 = (props, requeridos = []) => ({ type: "object", properties: props, required: requeridos, additionalProperties: false });
|
|
18253
18527
|
var id2 = { type: "string", description: "Id del video local (vid_\u2026)." };
|
|
@@ -18360,7 +18634,7 @@ function llamarHerramientaAlmacen(nombre, argumentos, ctx) {
|
|
|
18360
18634
|
version: video.versionActual,
|
|
18361
18635
|
existia,
|
|
18362
18636
|
avisos,
|
|
18363
|
-
almacen:
|
|
18637
|
+
almacen: join37(alm.raiz, "videos", video.id),
|
|
18364
18638
|
siguiente: existia ? "Ya exist\xEDa un video con ese solicitud_id; no se duplic\xF3." : "En la cola local: el worker local lo genera en segundo plano. Consulta con local_ver_video."
|
|
18365
18639
|
});
|
|
18366
18640
|
}
|
|
@@ -18405,11 +18679,11 @@ function llamarHerramientaAlmacen(nombre, argumentos, ctx) {
|
|
|
18405
18679
|
return texto4({ id: v2.id, estado: v2.estado, version: v2.versionActual, siguiente: "En la cola local. Consulta con local_ver_video." });
|
|
18406
18680
|
}
|
|
18407
18681
|
case "local_subir_media": {
|
|
18408
|
-
const
|
|
18409
|
-
if (!
|
|
18682
|
+
const ruta2 = cadena2("ruta");
|
|
18683
|
+
if (!ruta2) return fallo2("Falta \xABruta\xBB (ruta absoluta del archivo).");
|
|
18410
18684
|
const etiquetas = Array.isArray(a["etiquetas"]) ? a["etiquetas"].filter((x2) => typeof x2 === "string") : void 0;
|
|
18411
18685
|
const { asset, existia } = alm.registrarAsset({
|
|
18412
|
-
ruta:
|
|
18686
|
+
ruta: ruta2 === "~" || ruta2.startsWith("~/") ? join37(homedir9(), ruta2.slice(1)) : ruta2,
|
|
18413
18687
|
...cadena2("rol") ? { rol: cadena2("rol") } : {},
|
|
18414
18688
|
...cadena2("nombre") ? { nombre: cadena2("nombre") } : {},
|
|
18415
18689
|
...etiquetas ? { etiquetas } : {},
|
|
@@ -18421,7 +18695,7 @@ function llamarHerramientaAlmacen(nombre, argumentos, ctx) {
|
|
|
18421
18695
|
const f = {};
|
|
18422
18696
|
if (cadena2("rol")) f.rol = cadena2("rol");
|
|
18423
18697
|
if (cadena2("tipo")) f.tipo = cadena2("tipo");
|
|
18424
|
-
return texto4({ biblioteca:
|
|
18698
|
+
return texto4({ biblioteca: join37(alm.raiz, "biblioteca"), assets: alm.listarAssets(f).map((x2) => resumenAsset(alm, x2)) });
|
|
18425
18699
|
}
|
|
18426
18700
|
}
|
|
18427
18701
|
} catch (e7) {
|
|
@@ -18434,13 +18708,38 @@ function llamarHerramientaAlmacen(nombre, argumentos, ctx) {
|
|
|
18434
18708
|
// src/local/herramientas-maquina.ts
|
|
18435
18709
|
import { spawn as spawn5 } from "node:child_process";
|
|
18436
18710
|
import { closeSync as closeSync3, existsSync as existsSync14, mkdirSync as mkdirSync13, openSync as openSync3, readFileSync as readFileSync16, readSync, renameSync as renameSync6, rmSync as rmSync9, statSync as statSync9, writeFileSync as writeFileSync10 } from "node:fs";
|
|
18437
|
-
import { join as
|
|
18711
|
+
import { join as join38 } from "node:path";
|
|
18438
18712
|
|
|
18439
18713
|
// novedades-agentes.json
|
|
18440
18714
|
var novedades_agentes_default = {
|
|
18441
18715
|
componente: "cliente",
|
|
18442
18716
|
nota: "Novedades de claqueta-mcp (puente, worker y MCP local) para el agente que lo maneja (CLA-350). Una entrada por versi\xF3n publicada en npm, la m\xE1s nueva primero. Al subir la versi\xF3n de package.json agrega su entrada aqu\xED (src/novedades.test.ts lo exige) y sincroniza la API: claqueta-api `node packages/core/scripts/sincronizar-novedades.mjs`. Las l\xEDneas \xABMCP remoto\xBB son cambios de claqueta-api que llegaron con esta versi\xF3n del cliente. destacados: 1-5 frases cortas (van en las instructions); requiere: motor m\xEDnimo con el que se aprovecha.",
|
|
18443
18717
|
versiones: [
|
|
18718
|
+
{
|
|
18719
|
+
version: "0.70.1",
|
|
18720
|
+
fecha: "2026-11-30",
|
|
18721
|
+
resumen: "Arreglos del worker: familias del motor empaquetado, tope propio del compositor, reintento que conserva el guion del guionista, sin fuga de listeners y huellas de los formatos reutilizados.",
|
|
18722
|
+
destacados: [
|
|
18723
|
+
"Familias y est\xE9ticas del worker salen del motor empaquetado: ya acepta algoritmo-visual y matematica-animada (CLA-433).",
|
|
18724
|
+
"El compositor con agente tiene tope propio (--compositor-tiempo, 15 min por defecto) aparte del tope por formato, y su avance sale en el log (CLA-434).",
|
|
18725
|
+
"Si el intento fall\xF3 por tiempo, corte o infraestructura, el reintento conserva el guion del guionista sin volver a llamar a Claude (CLA-435).",
|
|
18726
|
+
"Sin fuga de listeners de abort en la espera del worker; local_esperar responde dentro de su plazo aunque cambie la hora (CLA-436).",
|
|
18727
|
+
"Las huellas de los formatos reutilizados se suman a insumos/huellas.json; si faltan, la bit\xE1cora lo avisa (CLA-432)."
|
|
18728
|
+
],
|
|
18729
|
+
campos_nuevos: [
|
|
18730
|
+
"--compositor-tiempo <min> (worker, 1 a 60)",
|
|
18731
|
+
"compositor_tope_s (familia.json)",
|
|
18732
|
+
"formatos_sin_huellas (datos del progreso)"
|
|
18733
|
+
],
|
|
18734
|
+
hacer_distinto: [
|
|
18735
|
+
"Reinicia el worker para tomar los arreglos; el motor sigue en 0.34.1.",
|
|
18736
|
+
"Ya puedes pedir las familias algoritmo-visual y matematica-animada con el worker."
|
|
18737
|
+
],
|
|
18738
|
+
obsoleto: [],
|
|
18739
|
+
requiere: {
|
|
18740
|
+
motor: "0.34.1"
|
|
18741
|
+
}
|
|
18742
|
+
},
|
|
18444
18743
|
{
|
|
18445
18744
|
version: "0.70.0",
|
|
18446
18745
|
fecha: "2026-11-30",
|
|
@@ -19080,7 +19379,7 @@ function novedadesParaVersion(desde) {
|
|
|
19080
19379
|
|
|
19081
19380
|
// src/local/herramientas-maquina.ts
|
|
19082
19381
|
var esObjeto5 = (v2) => typeof v2 === "object" && v2 !== null && !Array.isArray(v2);
|
|
19083
|
-
var rutasWorkerFondo = (casa) => ({ pid:
|
|
19382
|
+
var rutasWorkerFondo = (casa) => ({ pid: join38(casa, ".cache", "claqueta", "worker.pid"), log: join38(casa, ".cache", "claqueta", "worker.log") });
|
|
19084
19383
|
var TOPE_LOG = 5 * 1024 * 1024;
|
|
19085
19384
|
var esquema3 = (props, requeridos = []) => ({ type: "object", properties: props, required: requeridos, additionalProperties: false });
|
|
19086
19385
|
var PROPS_WORKER = {
|
|
@@ -19245,9 +19544,9 @@ var pidVivoReal2 = (pid) => {
|
|
|
19245
19544
|
return e7.code === "EPERM";
|
|
19246
19545
|
}
|
|
19247
19546
|
};
|
|
19248
|
-
function leerPidfile(
|
|
19547
|
+
function leerPidfile(ruta2) {
|
|
19249
19548
|
try {
|
|
19250
|
-
const v2 = JSON.parse(readFileSync16(
|
|
19549
|
+
const v2 = JSON.parse(readFileSync16(ruta2, "utf8"));
|
|
19251
19550
|
if (esObjeto5(v2) && typeof v2["pid"] === "number" && Number.isInteger(v2["pid"]) && v2["pid"] > 1) return v2;
|
|
19252
19551
|
} catch {
|
|
19253
19552
|
}
|
|
@@ -19278,19 +19577,19 @@ async function estadoServicio(ctx) {
|
|
|
19278
19577
|
const corriendo = /\bstate = running\b/.test(p.stdout) || Number.isInteger(pid);
|
|
19279
19578
|
return { aplica: true, instalado, cargado: true, corriendo, ...Number.isInteger(pid) ? { pid } : {}, ...base };
|
|
19280
19579
|
}
|
|
19281
|
-
function colaArchivo(
|
|
19282
|
-
if (!existsSync14(
|
|
19283
|
-
const tam = statSync9(
|
|
19284
|
-
const
|
|
19285
|
-
const buf = Buffer.alloc(
|
|
19286
|
-
const fd2 = openSync3(
|
|
19580
|
+
function colaArchivo(ruta2, n, filtro) {
|
|
19581
|
+
if (!existsSync14(ruta2)) return [];
|
|
19582
|
+
const tam = statSync9(ruta2).size;
|
|
19583
|
+
const leer3 = Math.min(tam, 512 * 1024);
|
|
19584
|
+
const buf = Buffer.alloc(leer3);
|
|
19585
|
+
const fd2 = openSync3(ruta2, "r");
|
|
19287
19586
|
try {
|
|
19288
|
-
readSync(fd2, buf, 0,
|
|
19587
|
+
readSync(fd2, buf, 0, leer3, tam - leer3);
|
|
19289
19588
|
} finally {
|
|
19290
19589
|
closeSync3(fd2);
|
|
19291
19590
|
}
|
|
19292
19591
|
let lineas = buf.toString("utf8").split("\n");
|
|
19293
|
-
if (
|
|
19592
|
+
if (leer3 < tam) lineas = lineas.slice(1);
|
|
19294
19593
|
lineas = lineas.map((l) => l.replace(/\x1b\[[0-9;?]*[A-Za-z]/g, "").replace(/\r/g, "")).filter((l) => l.trim() !== "");
|
|
19295
19594
|
if (filtro) lineas = lineas.filter((l) => l.toLowerCase().includes(filtro.toLowerCase()));
|
|
19296
19595
|
return lineas.slice(-n);
|
|
@@ -19342,7 +19641,7 @@ async function iniciar(ctx, a) {
|
|
|
19342
19641
|
);
|
|
19343
19642
|
}
|
|
19344
19643
|
const r2 = rutasWorkerFondo(ctx.casa);
|
|
19345
|
-
mkdirSync13(
|
|
19644
|
+
mkdirSync13(join38(ctx.casa, ".cache", "claqueta"), { recursive: true });
|
|
19346
19645
|
try {
|
|
19347
19646
|
if (existsSync14(r2.log) && statSync9(r2.log).size > TOPE_LOG) renameSync6(r2.log, `${r2.log}.1`);
|
|
19348
19647
|
} catch {
|
|
@@ -19384,17 +19683,17 @@ async function detener(ctx, a) {
|
|
|
19384
19683
|
return texto5("No hay ning\xFAn worker corriendo en segundo plano.");
|
|
19385
19684
|
}
|
|
19386
19685
|
const enviar = ctx.senal ?? ((pid, s) => process.kill(pid, s));
|
|
19387
|
-
const
|
|
19686
|
+
const dormir2 = ctx.dormir ?? dormirReal3;
|
|
19388
19687
|
const vivo2 = ctx.pidVivo ?? pidVivoReal2;
|
|
19389
19688
|
enviar(info.pid, "SIGTERM");
|
|
19390
19689
|
if (cortar) {
|
|
19391
|
-
await
|
|
19690
|
+
await dormir2(500);
|
|
19392
19691
|
if (vivo2(info.pid)) enviar(info.pid, "SIGINT");
|
|
19393
19692
|
}
|
|
19394
19693
|
const fin = Date.now() + esperar2 * 1e3;
|
|
19395
19694
|
let sigue = vivo2(info.pid);
|
|
19396
19695
|
while (sigue && Date.now() < fin) {
|
|
19397
|
-
await
|
|
19696
|
+
await dormir2(250);
|
|
19398
19697
|
sigue = vivo2(info.pid);
|
|
19399
19698
|
}
|
|
19400
19699
|
const { pid: rutaPid, log } = rutasWorkerFondo(ctx.casa);
|
|
@@ -19405,7 +19704,7 @@ async function detener(ctx, a) {
|
|
|
19405
19704
|
} catch {
|
|
19406
19705
|
enviar(info.pid, "SIGKILL");
|
|
19407
19706
|
}
|
|
19408
|
-
await
|
|
19707
|
+
await dormir2(300);
|
|
19409
19708
|
}
|
|
19410
19709
|
rmSync9(rutaPid, { force: true });
|
|
19411
19710
|
const cola = colaArchivo(log, 5).map((l) => enmascarar(l, secretos(ctx)));
|
|
@@ -19427,20 +19726,20 @@ async function verLog(ctx, a) {
|
|
|
19427
19726
|
if (!["auto", "fondo", "servicio"].includes(origen)) throw new ErrorUso2('\xABorigen\xBB debe ser "auto", "fondo" o "servicio"');
|
|
19428
19727
|
const fondoLog = rutasWorkerFondo(ctx.casa).log;
|
|
19429
19728
|
const servLog = rutasServicio(ctx.casa).log;
|
|
19430
|
-
let
|
|
19431
|
-
if (!
|
|
19432
|
-
if (await fondoVivo(ctx))
|
|
19433
|
-
else if ((await estadoServicio(ctx)).cargado)
|
|
19729
|
+
let ruta2 = origen === "fondo" ? fondoLog : origen === "servicio" ? servLog : "";
|
|
19730
|
+
if (!ruta2) {
|
|
19731
|
+
if (await fondoVivo(ctx)) ruta2 = fondoLog;
|
|
19732
|
+
else if ((await estadoServicio(ctx)).cargado) ruta2 = servLog;
|
|
19434
19733
|
else {
|
|
19435
19734
|
const mt2 = (r2) => existsSync14(r2) ? statSync9(r2).mtimeMs : -1;
|
|
19436
|
-
|
|
19735
|
+
ruta2 = mt2(servLog) > mt2(fondoLog) ? servLog : fondoLog;
|
|
19437
19736
|
}
|
|
19438
19737
|
}
|
|
19439
|
-
if (!existsSync14(
|
|
19738
|
+
if (!existsSync14(ruta2)) return texto5(`No hay log en ${ruta2} (el worker no ha corrido ${ruta2 === servLog ? "como servicio" : "en segundo plano"}).`);
|
|
19440
19739
|
const filtro = cad(a, "filtro");
|
|
19441
19740
|
const s = secretos(ctx);
|
|
19442
|
-
const lineas = colaArchivo(
|
|
19443
|
-
return texto5(`${
|
|
19741
|
+
const lineas = colaArchivo(ruta2, n, filtro).map((l) => enmascarar(l, s));
|
|
19742
|
+
return texto5(`${ruta2} (\xFAltimas ${lineas.length} l\xEDneas${filtro ? ` con \xAB${filtro}\xBB` : ""}):
|
|
19444
19743
|
${lineas.join("\n")}`);
|
|
19445
19744
|
}
|
|
19446
19745
|
var repositorioImagen = (imagen2) => imagen2.replace(/@sha256:[0-9a-f]+$/, "").replace(/:[^/:]+$/, "");
|
|
@@ -19563,22 +19862,22 @@ async function llamarHerramientaMaquina(nombre, argumentos, ctx) {
|
|
|
19563
19862
|
// src/local/skill.ts
|
|
19564
19863
|
import { cpSync as cpSync2, existsSync as existsSync15, mkdirSync as mkdirSync14, readFileSync as readFileSync17 } from "node:fs";
|
|
19565
19864
|
import { homedir as homedir10 } from "node:os";
|
|
19566
|
-
import { join as
|
|
19865
|
+
import { join as join39, resolve as resolve12 } from "node:path";
|
|
19567
19866
|
var NOMBRE_SKILL = "claqueta-motor";
|
|
19568
19867
|
var PROMPT_SKILL = "dirigir-motor";
|
|
19569
19868
|
var ARCHIVOS_SKILL = ["SKILL.md", "reglas.md", "referencia.md"];
|
|
19570
19869
|
var URI = (archivo2) => `claqueta://skill/${PROMPT_SKILL}/${archivo2}`;
|
|
19571
|
-
var destinoPorDefecto = (casa = homedir10()) =>
|
|
19572
|
-
function
|
|
19870
|
+
var destinoPorDefecto = (casa = homedir10()) => join39(casa, ".claude", "skills", NOMBRE_SKILL);
|
|
19871
|
+
function leer2(dir, archivo2) {
|
|
19573
19872
|
try {
|
|
19574
|
-
return readFileSync17(
|
|
19873
|
+
return readFileSync17(join39(dir, archivo2), "utf8");
|
|
19575
19874
|
} catch {
|
|
19576
19875
|
return null;
|
|
19577
19876
|
}
|
|
19578
19877
|
}
|
|
19579
19878
|
function recursosSkill(dir) {
|
|
19580
19879
|
if (!dir) return [];
|
|
19581
|
-
return ARCHIVOS_SKILL.filter((a) => existsSync15(
|
|
19880
|
+
return ARCHIVOS_SKILL.filter((a) => existsSync15(join39(dir, a))).map((a) => ({
|
|
19582
19881
|
uri: URI(a),
|
|
19583
19882
|
name: `${PROMPT_SKILL}/${a}`,
|
|
19584
19883
|
description: a === "SKILL.md" ? "Skill \xABdirigir el motor\xBB: flujo del compositor con las herramientas local_*" : a === "reglas.md" ? "Reglas del compositor (comunes con el worker)" : "Herramientas locales, carpeta de trabajo y c\xF3mo leer el parecido",
|
|
@@ -19587,11 +19886,11 @@ function recursosSkill(dir) {
|
|
|
19587
19886
|
}
|
|
19588
19887
|
function leerRecursoSkill(dir, uri) {
|
|
19589
19888
|
const a = ARCHIVOS_SKILL.find((x2) => URI(x2) === uri);
|
|
19590
|
-
const texto7 = dir && a ?
|
|
19889
|
+
const texto7 = dir && a ? leer2(dir, a) : null;
|
|
19591
19890
|
return texto7 === null ? null : { uri, mimeType: "text/markdown", text: texto7 };
|
|
19592
19891
|
}
|
|
19593
19892
|
function promptsSkill(dir) {
|
|
19594
|
-
if (!dir || !existsSync15(
|
|
19893
|
+
if (!dir || !existsSync15(join39(dir, "SKILL.md"))) return [];
|
|
19595
19894
|
return [{
|
|
19596
19895
|
name: PROMPT_SKILL,
|
|
19597
19896
|
description: "Dirige el motor local como compositor: componer \u2192 previa \u2192 fotogramas \u2192 parecido \u2192 editar (2 vueltas) \u2192 render \u2192 revisar.",
|
|
@@ -19603,7 +19902,7 @@ function promptsSkill(dir) {
|
|
|
19603
19902
|
}
|
|
19604
19903
|
function obtenerPromptSkill(dir, nombre, args2) {
|
|
19605
19904
|
if (nombre !== PROMPT_SKILL || !dir) return null;
|
|
19606
|
-
const partes3 = ARCHIVOS_SKILL.map((a) =>
|
|
19905
|
+
const partes3 = ARCHIVOS_SKILL.map((a) => leer2(dir, a)).filter((t) => t !== null);
|
|
19607
19906
|
if (!partes3.length) return null;
|
|
19608
19907
|
const pedido = typeof args2["pedido"] === "string" && args2["pedido"].trim() ? args2["pedido"].trim() : null;
|
|
19609
19908
|
const referencia = typeof args2["referencia"] === "string" && args2["referencia"].trim() ? args2["referencia"].trim() : null;
|
|
@@ -19620,11 +19919,11 @@ ${partes3.join("\n\n---\n\n")}` } }]
|
|
|
19620
19919
|
};
|
|
19621
19920
|
}
|
|
19622
19921
|
function instalarSkill(origen, destino = destinoPorDefecto()) {
|
|
19623
|
-
const faltan = ARCHIVOS_SKILL.filter((a) => !existsSync15(
|
|
19922
|
+
const faltan = ARCHIVOS_SKILL.filter((a) => !existsSync15(join39(origen, a)));
|
|
19624
19923
|
if (faltan.length) throw new Error(`el paquete no trae la skill completa en ${origen} (faltan ${faltan.join(", ")})`);
|
|
19625
19924
|
const d = resolve12(destino);
|
|
19626
19925
|
mkdirSync14(d, { recursive: true });
|
|
19627
|
-
for (const a of ARCHIVOS_SKILL) cpSync2(
|
|
19926
|
+
for (const a of ARCHIVOS_SKILL) cpSync2(join39(origen, a), join39(d, a));
|
|
19628
19927
|
return { destino: d, archivos: [...ARCHIVOS_SKILL] };
|
|
19629
19928
|
}
|
|
19630
19929
|
var AYUDA_SKILL = `claqueta-mcp skill: la skill \xABdirigir el motor\xBB (la sesi\xF3n de Claude como compositor del motor local).
|
|
@@ -19787,16 +20086,16 @@ var endpointDe = (url) => {
|
|
|
19787
20086
|
if (u2.protocol !== "http:" && u2.protocol !== "https:") return null;
|
|
19788
20087
|
u2.search = "";
|
|
19789
20088
|
u2.hash = "";
|
|
19790
|
-
let
|
|
19791
|
-
if (
|
|
19792
|
-
u2.pathname = `${
|
|
20089
|
+
let ruta2 = u2.pathname.replace(/\/+$/, "");
|
|
20090
|
+
if (ruta2.endsWith("/mcp")) ruta2 = ruta2.slice(0, -4);
|
|
20091
|
+
u2.pathname = `${ruta2}/mcp`;
|
|
19793
20092
|
return u2.toString();
|
|
19794
20093
|
} catch {
|
|
19795
20094
|
return null;
|
|
19796
20095
|
}
|
|
19797
20096
|
};
|
|
19798
20097
|
async function textoDiagnostico(e7) {
|
|
19799
|
-
const
|
|
20098
|
+
const ruta2 = rutaConfig(e7.env);
|
|
19800
20099
|
const slugEnv = e7.env["CLAQUETA_HERRAMIENTA"]?.trim();
|
|
19801
20100
|
const slug = slugEnv && esSlugValido(slugEnv) ? slugEnv : HERRAMIENTA_POR_DEFECTO;
|
|
19802
20101
|
const faltan = [...e7.url?.trim() ? [] : ["la URL (CLAQUETA_URL)"], ...e7.token?.trim() ? [] : ["el token (CLAQUETA_TOKEN)"]];
|
|
@@ -19804,13 +20103,13 @@ async function textoDiagnostico(e7) {
|
|
|
19804
20103
|
const arreglo = [
|
|
19805
20104
|
"C\xF3mo arreglarlo (elige una):",
|
|
19806
20105
|
` 1. En una terminal: npx ${PAQUETE} setup --herramienta ${slug}`,
|
|
19807
|
-
` Abre el navegador, confirmas y el token queda en ${
|
|
20106
|
+
` Abre el navegador, confirmas y el token queda en ${ruta2} (permisos 0600).`,
|
|
19808
20107
|
' 2. O define CLAQUETA_URL y CLAQUETA_TOKEN en el bloque "env" de la configuraci\xF3n MCP de tu herramienta.',
|
|
19809
20108
|
"Despu\xE9s reinicia la herramienta o reconecta el MCP (en Claude Code: /mcp)."
|
|
19810
20109
|
];
|
|
19811
20110
|
if (faltan.length > 0) {
|
|
19812
20111
|
l.push(`Estado: sin conexi\xF3n con Claqueta. Motivo: falta configuraci\xF3n, no hay ${faltan.join(" ni ")}.`);
|
|
19813
|
-
l.push(`Busqu\xE9 en las variables de entorno CLAQUETA_URL/CLAQUETA_TOKEN, en los argumentos y en ${
|
|
20112
|
+
l.push(`Busqu\xE9 en las variables de entorno CLAQUETA_URL/CLAQUETA_TOKEN, en los argumentos y en ${ruta2}.`);
|
|
19814
20113
|
if (slugEnv) l.push(esSlugValido(slugEnv) ? `Herramienta pedida: ${slugEnv} (CLAQUETA_HERRAMIENTA).` : `CLAQUETA_HERRAMIENTA tiene un valor que no es un slug (${citar(slugEnv)}); se asume ${HERRAMIENTA_POR_DEFECTO}.`);
|
|
19815
20114
|
l.push("", ...arreglo);
|
|
19816
20115
|
} else {
|
|
@@ -19905,8 +20204,8 @@ function servirDiagnostico(o) {
|
|
|
19905
20204
|
import { createInterface as createInterface6 } from "node:readline";
|
|
19906
20205
|
|
|
19907
20206
|
// src/local.ts
|
|
19908
|
-
import { createHash as
|
|
19909
|
-
import { readFile as
|
|
20207
|
+
import { createHash as createHash10 } from "node:crypto";
|
|
20208
|
+
import { readFile as readFile16, stat as stat4 } from "node:fs/promises";
|
|
19910
20209
|
import { homedir as homedir11 } from "node:os";
|
|
19911
20210
|
import { basename as basename5, extname as extname5, resolve as resolve13 } from "node:path";
|
|
19912
20211
|
var LIMITE_BASE64_BYTES = 3 * 1024 * 1024;
|
|
@@ -19931,7 +20230,7 @@ var MIME = {
|
|
|
19931
20230
|
".txt": "text/plain",
|
|
19932
20231
|
".csv": "text/csv"
|
|
19933
20232
|
};
|
|
19934
|
-
var mimeDe = (
|
|
20233
|
+
var mimeDe = (ruta2) => MIME[extname5(ruta2).toLowerCase()] ?? "application/octet-stream";
|
|
19935
20234
|
var esObjeto8 = (v2) => typeof v2 === "object" && v2 !== null && !Array.isArray(v2);
|
|
19936
20235
|
function falloHerramienta(id3, texto7) {
|
|
19937
20236
|
return { tipo: "respuesta", mensaje: { jsonrpc: "2.0", id: id3, result: { content: [{ type: "text", text: texto7 }], isError: true } } };
|
|
@@ -19945,10 +20244,10 @@ async function interceptarSubirMedia(msg, deps) {
|
|
|
19945
20244
|
if (args2["base64"] !== void 0) return null;
|
|
19946
20245
|
const id3 = msg["id"];
|
|
19947
20246
|
const pedida = args2["ruta"].trim();
|
|
19948
|
-
const
|
|
20247
|
+
const ruta2 = resolve13(pedida === "~" ? homedir11() : pedida.startsWith("~/") ? `${homedir11()}/${pedida.slice(2)}` : pedida);
|
|
19949
20248
|
let tam;
|
|
19950
20249
|
try {
|
|
19951
|
-
const st2 = await
|
|
20250
|
+
const st2 = await stat4(ruta2);
|
|
19952
20251
|
if (!st2.isFile()) return falloHerramienta(id3, `La ruta "${pedida}" no es un archivo.`);
|
|
19953
20252
|
tam = st2.size;
|
|
19954
20253
|
} catch {
|
|
@@ -19960,12 +20259,12 @@ async function interceptarSubirMedia(msg, deps) {
|
|
|
19960
20259
|
if (tam > limite) return falloGrande(id3, tam, limite);
|
|
19961
20260
|
let datos;
|
|
19962
20261
|
try {
|
|
19963
|
-
datos = await
|
|
20262
|
+
datos = await readFile16(ruta2);
|
|
19964
20263
|
} catch {
|
|
19965
20264
|
return falloHerramienta(id3, `No se pudo leer el archivo local "${pedida}".`);
|
|
19966
20265
|
}
|
|
19967
|
-
const sha2563 =
|
|
19968
|
-
const nombre = typeof args2["nombre"] === "string" && args2["nombre"] ? args2["nombre"] : basename5(
|
|
20266
|
+
const sha2563 = createHash10("sha256").update(datos).digest("hex");
|
|
20267
|
+
const nombre = typeof args2["nombre"] === "string" && args2["nombre"] ? args2["nombre"] : basename5(ruta2);
|
|
19969
20268
|
const { ruta: _r2, url: _u2, ...resto } = args2;
|
|
19970
20269
|
void _r2;
|
|
19971
20270
|
void _u2;
|
|
@@ -19998,7 +20297,7 @@ async function interceptarSubirMedia(msg, deps) {
|
|
|
19998
20297
|
}, null, 2);
|
|
19999
20298
|
return { tipo: "respuesta", mensaje: { jsonrpc: "2.0", id: id3, result: { content: [{ type: "text", text: texto8 }] } } };
|
|
20000
20299
|
}
|
|
20001
|
-
const md5 =
|
|
20300
|
+
const md5 = createHash10("md5").update(datos).digest("hex");
|
|
20002
20301
|
let putResp;
|
|
20003
20302
|
try {
|
|
20004
20303
|
putResp = await (deps.put ?? fetch)(permiso.url, { method: "PUT", headers: permiso.cabeceras ?? {}, body: datos });
|
|
@@ -20028,28 +20327,28 @@ function falloGrande(id3, tam, limite) {
|
|
|
20028
20327
|
}
|
|
20029
20328
|
|
|
20030
20329
|
// src/video-local.ts
|
|
20031
|
-
import { createHash as
|
|
20330
|
+
import { createHash as createHash11 } from "node:crypto";
|
|
20032
20331
|
import { existsSync as existsSync16, readFileSync as readFileSync18, statSync as statSync10 } from "node:fs";
|
|
20033
20332
|
import { homedir as homedir12, hostname as hostname8 } from "node:os";
|
|
20034
|
-
import { basename as basename6, isAbsolute as isAbsolute4, join as
|
|
20333
|
+
import { basename as basename6, isAbsolute as isAbsolute4, join as join40, resolve as resolve14 } from "node:path";
|
|
20035
20334
|
var esObjeto9 = (v2) => typeof v2 === "object" && v2 !== null && !Array.isArray(v2);
|
|
20036
20335
|
var LIMITE_VIDEO_LOCAL_BYTES = 1024 * 1024 * 1024;
|
|
20037
20336
|
var LIMITE_JSON = 256 * 1024;
|
|
20038
20337
|
var RE_ID4 = /^[A-Za-z0-9][A-Za-z0-9._-]{0,99}$/;
|
|
20039
20338
|
var RE_CLAVE = /^\d{1,5}x\d{1,5}$/;
|
|
20040
|
-
var carpetaTrabajoBase = (env = process.env, casa = homedir12()) => resolve14(env["CLAQUETA_TRABAJO_DIR"]?.trim() ||
|
|
20339
|
+
var carpetaTrabajoBase = (env = process.env, casa = homedir12()) => resolve14(env["CLAQUETA_TRABAJO_DIR"]?.trim() || join40(casa, "Claqueta", "trabajo"));
|
|
20041
20340
|
var ErrorCarpeta = class extends Error {
|
|
20042
20341
|
};
|
|
20043
20342
|
function resolverCarpeta2(valor, base) {
|
|
20044
|
-
const v2 = valor.trim() === "~" ? homedir12() : valor.trim().startsWith("~/") ?
|
|
20343
|
+
const v2 = valor.trim() === "~" ? homedir12() : valor.trim().startsWith("~/") ? join40(homedir12(), valor.trim().slice(2)) : valor.trim();
|
|
20045
20344
|
if (isAbsolute4(v2)) return resolve14(v2);
|
|
20046
|
-
if (RE_ID4.test(v2) && !v2.includes("..")) return
|
|
20345
|
+
if (RE_ID4.test(v2) && !v2.includes("..")) return join40(base, v2);
|
|
20047
20346
|
throw new ErrorCarpeta(`carpeta \xAB${valor}\xBB no v\xE1lida: usa el id de la carpeta de trabajo (p. ej. 20261119-1530-billar) o una ruta absoluta`);
|
|
20048
20347
|
}
|
|
20049
|
-
function leerJson6(
|
|
20348
|
+
function leerJson6(ruta2) {
|
|
20050
20349
|
try {
|
|
20051
|
-
if (!existsSync16(
|
|
20052
|
-
const v2 = JSON.parse(readFileSync18(
|
|
20350
|
+
if (!existsSync16(ruta2) || statSync10(ruta2).size > LIMITE_JSON * 8) return null;
|
|
20351
|
+
const v2 = JSON.parse(readFileSync18(ruta2, "utf8"));
|
|
20053
20352
|
return esObjeto9(v2) ? v2 : null;
|
|
20054
20353
|
} catch {
|
|
20055
20354
|
return null;
|
|
@@ -20057,17 +20356,17 @@ function leerJson6(ruta) {
|
|
|
20057
20356
|
}
|
|
20058
20357
|
var texto6 = (v2) => typeof v2 === "string" && v2.trim() ? v2.trim() : void 0;
|
|
20059
20358
|
var numero2 = (v2) => typeof v2 === "number" && Number.isFinite(v2) ? v2 : void 0;
|
|
20060
|
-
function archivo(
|
|
20061
|
-
if (!existsSync16(
|
|
20062
|
-
const st2 = statSync10(
|
|
20359
|
+
function archivo(ruta2) {
|
|
20360
|
+
if (!existsSync16(ruta2)) return null;
|
|
20361
|
+
const st2 = statSync10(ruta2);
|
|
20063
20362
|
if (!st2.isFile() || st2.size === 0) return null;
|
|
20064
|
-
if (st2.size > LIMITE_VIDEO_LOCAL_BYTES) throw new ErrorCarpeta(`${
|
|
20065
|
-
return { ruta, bytes: st2.size, md5:
|
|
20363
|
+
if (st2.size > LIMITE_VIDEO_LOCAL_BYTES) throw new ErrorCarpeta(`${ruta2} pesa ${(st2.size / 1024 / 1024).toFixed(0)} MB y el puente sube hasta ${LIMITE_VIDEO_LOCAL_BYTES / 1024 / 1024} MB por archivo`);
|
|
20364
|
+
return { ruta: ruta2, bytes: st2.size, md5: createHash11("md5").update(readFileSync18(ruta2)).digest("hex") };
|
|
20066
20365
|
}
|
|
20067
20366
|
function bitacoraDe(carpeta2, pasos) {
|
|
20068
20367
|
const salida = [];
|
|
20069
20368
|
try {
|
|
20070
|
-
const lineas = readFileSync18(
|
|
20369
|
+
const lineas = readFileSync18(join40(carpeta2, "bitacora.jsonl"), "utf8").split("\n").filter((l) => l.trim());
|
|
20071
20370
|
for (const l of lineas.slice(-60)) {
|
|
20072
20371
|
try {
|
|
20073
20372
|
const e7 = JSON.parse(l);
|
|
@@ -20090,11 +20389,11 @@ function bitacoraDe(carpeta2, pasos) {
|
|
|
20090
20389
|
}
|
|
20091
20390
|
function leerCarpetaLocal(carpeta2, opciones = {}) {
|
|
20092
20391
|
if (!existsSync16(carpeta2) || !statSync10(carpeta2).isDirectory()) throw new ErrorCarpeta(`no existe la carpeta ${carpeta2}`);
|
|
20093
|
-
const final =
|
|
20094
|
-
const manifiesto = leerJson6(
|
|
20392
|
+
const final = join40(carpeta2, "final");
|
|
20393
|
+
const manifiesto = leerJson6(join40(final, "manifiesto.json"));
|
|
20095
20394
|
if (!manifiesto) throw new ErrorCarpeta(`${carpeta2} no tiene un video terminado (falta final/manifiesto.json): termina con local_render`);
|
|
20096
|
-
const pasos = leerJson6(
|
|
20097
|
-
const pedido = leerJson6(
|
|
20395
|
+
const pasos = leerJson6(join40(carpeta2, "pasos.json"));
|
|
20396
|
+
const pedido = leerJson6(join40(carpeta2, "fuentes", "pedido.json")) ?? leerJson6(join40(final, "fuentes", "pedido.json"));
|
|
20098
20397
|
const rutas = {};
|
|
20099
20398
|
const revisiones = {};
|
|
20100
20399
|
const lista = Array.isArray(manifiesto["renders"]) ? manifiesto["renders"].filter(esObjeto9) : [];
|
|
@@ -20102,13 +20401,13 @@ function leerCarpetaLocal(carpeta2, opciones = {}) {
|
|
|
20102
20401
|
for (const [i, r2] of lista.entries()) {
|
|
20103
20402
|
const clave = `${numero2(r2["ancho"]) ?? ""}x${numero2(r2["alto"]) ?? ""}`;
|
|
20104
20403
|
if (!RE_CLAVE.test(clave) || renders.some((x2) => x2["clave"] === clave)) continue;
|
|
20105
|
-
const dir =
|
|
20106
|
-
const video = archivo(
|
|
20404
|
+
const dir = join40(final, "renders", clave);
|
|
20405
|
+
const video = archivo(join40(dir, "video.mp4")) ?? (i === 0 ? archivo(join40(final, "video.mp4")) : null);
|
|
20107
20406
|
if (!video) throw new ErrorCarpeta(`falta el MP4 del render ${clave} en ${dir}: vuelve a correr local_render`);
|
|
20108
|
-
const poster = archivo(
|
|
20407
|
+
const poster = archivo(join40(dir, "poster.jpg")) ?? (i === 0 ? archivo(join40(final, "poster.jpg")) : null);
|
|
20109
20408
|
rutas[`video:${clave}`] = video.ruta;
|
|
20110
20409
|
if (poster) rutas[`poster:${clave}`] = poster.ruta;
|
|
20111
|
-
const revisionJson = leerJson6(
|
|
20410
|
+
const revisionJson = leerJson6(join40(dir, "revision.json"));
|
|
20112
20411
|
if (revisionJson && Buffer.byteLength(JSON.stringify(revisionJson)) <= LIMITE_JSON) revisiones[clave] = revisionJson;
|
|
20113
20412
|
const rev = esObjeto9(r2["revision"]) ? r2["revision"] : null;
|
|
20114
20413
|
renders.push({
|
|
@@ -20123,14 +20422,14 @@ function leerCarpetaLocal(carpeta2, opciones = {}) {
|
|
|
20123
20422
|
if (!renders.length) {
|
|
20124
20423
|
const f = esObjeto9(manifiesto["formato"]) ? manifiesto["formato"] : {};
|
|
20125
20424
|
const clave = `${numero2(f["ancho"]) ?? 1080}x${numero2(f["alto"]) ?? 1920}`;
|
|
20126
|
-
const video = archivo(
|
|
20425
|
+
const video = archivo(join40(final, "video.mp4"));
|
|
20127
20426
|
if (!video) throw new ErrorCarpeta(`falta final/video.mp4 en ${carpeta2}: termina con local_render`);
|
|
20128
|
-
const poster = archivo(
|
|
20427
|
+
const poster = archivo(join40(final, "poster.jpg"));
|
|
20129
20428
|
rutas[`video:${clave}`] = video.ruta;
|
|
20130
20429
|
if (poster) rutas[`poster:${clave}`] = poster.ruta;
|
|
20131
20430
|
renders.push({ clave, video: { bytes: video.bytes, md5: video.md5 }, ...poster ? { poster: { bytes: poster.bytes, md5: poster.md5 } } : {} });
|
|
20132
20431
|
}
|
|
20133
|
-
const man = archivo(
|
|
20432
|
+
const man = archivo(join40(final, "manifiesto.json"));
|
|
20134
20433
|
rutas["manifiesto:null"] = man.ruta;
|
|
20135
20434
|
const construccion = esObjeto9(manifiesto["construccion"]) ? construccionConVersion(manifiesto["construccion"], manifiesto) : null;
|
|
20136
20435
|
const composicion = construccion && esObjeto9(construccion["composicion"]) ? construccion["composicion"] : null;
|
|
@@ -20169,18 +20468,18 @@ function leerCarpetaLocal(carpeta2, opciones = {}) {
|
|
|
20169
20468
|
var RE_VID = /^vid_[A-Za-z0-9_-]{1,40}$/;
|
|
20170
20469
|
function leerVideoDelAlmacen(raiz, vid, n, opciones = {}) {
|
|
20171
20470
|
if (!RE_VID.test(vid)) throw new ErrorCarpeta(`video local \xAB${vid}\xBB no v\xE1lido: usa el id vid_\u2026 de local_listar_videos`);
|
|
20172
|
-
const dir =
|
|
20173
|
-
const video = leerJson6(
|
|
20471
|
+
const dir = join40(raiz, "videos", vid);
|
|
20472
|
+
const video = leerJson6(join40(dir, "video.json"));
|
|
20174
20473
|
if (!video) throw new ErrorCarpeta(`no existe el video ${vid} en el almac\xE9n local ${raiz}`);
|
|
20175
20474
|
const version2 = n ?? numero2(video["versionActual"]) ?? 1;
|
|
20176
|
-
const ver = leerJson6(
|
|
20475
|
+
const ver = leerJson6(join40(dir, "versiones", String(version2), "version.json"));
|
|
20177
20476
|
const carpeta2 = esObjeto9(ver?.["archivos"]) ? texto6(ver["archivos"]["carpeta_trabajo"]) : void 0;
|
|
20178
20477
|
if (!carpeta2) throw new ErrorCarpeta(`la versi\xF3n ${version2} de ${vid} no tiene carpeta de trabajo: todav\xEDa no se genera`);
|
|
20179
20478
|
const titulo = opciones.titulo ?? texto6(video["titulo"]);
|
|
20180
20479
|
const l = leerCarpetaLocal(carpeta2, { ...titulo ? { titulo } : {}, ...opciones.maquina ? { maquina: opciones.maquina } : {} });
|
|
20181
20480
|
const bitacora2 = [];
|
|
20182
20481
|
try {
|
|
20183
|
-
for (const linea of readFileSync18(
|
|
20482
|
+
for (const linea of readFileSync18(join40(dir, "bitacora.jsonl"), "utf8").split("\n").filter((x2) => x2.trim()).slice(-60)) {
|
|
20184
20483
|
try {
|
|
20185
20484
|
const e7 = JSON.parse(linea);
|
|
20186
20485
|
const datos = esObjeto9(e7["datos"]) ? e7["datos"] : {};
|
|
@@ -20239,21 +20538,21 @@ async function interceptarSubirVideoLocal(msg, deps) {
|
|
|
20239
20538
|
if (r2.ya_subido) return responder2({ ...r2, subida: "ya estaba en la nube: no se duplic\xF3 nada" });
|
|
20240
20539
|
let bytes = 0;
|
|
20241
20540
|
for (const s of r2.subidas ?? []) {
|
|
20242
|
-
const
|
|
20243
|
-
if (!
|
|
20541
|
+
const ruta2 = leido.rutas[`${s.archivo}:${s.render}`];
|
|
20542
|
+
if (!ruta2) return fallo3(id3, `El servidor pidi\xF3 un archivo que no est\xE1 en la carpeta (${s.archivo} ${s.render ?? ""}).`);
|
|
20244
20543
|
let datos;
|
|
20245
20544
|
try {
|
|
20246
|
-
datos = readFileSync18(
|
|
20545
|
+
datos = readFileSync18(ruta2);
|
|
20247
20546
|
} catch {
|
|
20248
|
-
return fallo3(id3, `No se pudo leer ${
|
|
20547
|
+
return fallo3(id3, `No se pudo leer ${ruta2}.`);
|
|
20249
20548
|
}
|
|
20250
20549
|
let put;
|
|
20251
20550
|
try {
|
|
20252
20551
|
put = await (deps.put ?? fetch)(s.url, { method: "PUT", headers: s.cabeceras ?? {}, body: datos });
|
|
20253
20552
|
} catch (e7) {
|
|
20254
|
-
return fallo3(id3, `No se pudo subir ${basename6(
|
|
20553
|
+
return fallo3(id3, `No se pudo subir ${basename6(ruta2)} (${s.render ?? s.archivo}): ${e7 instanceof Error ? e7.message : String(e7)}. Reintenta: se reanuda sin duplicar.`);
|
|
20255
20554
|
}
|
|
20256
|
-
if (!put.ok) return fallo3(id3, `S3 rechaz\xF3 ${basename6(
|
|
20555
|
+
if (!put.ok) return fallo3(id3, `S3 rechaz\xF3 ${basename6(ruta2)} (HTTP ${put.status}). La URL firmada dura 15 minutos: reintenta.`);
|
|
20257
20556
|
bytes += datos.byteLength;
|
|
20258
20557
|
}
|
|
20259
20558
|
const conf = await deps.llamar("confirmar_video_local", { video_id: r2.video_id, ...leido.confirmacion });
|