@hyperframes/gcp-cloud-run 0.9.56 → 0.9.58
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/index.js +73 -27
- package/dist/sdk/index.js +10 -5
- package/dist/server.js +68 -22
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// src/server.ts
|
|
2
2
|
import { mkdirSync as mkdirSync3, mkdtempSync as mkdtempSync2, rmSync as rmSync3 } from "node:fs";
|
|
3
3
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
4
|
-
import { basename, extname, join as
|
|
4
|
+
import { basename, extname, join as join3 } from "node:path";
|
|
5
5
|
import { fileURLToPath } from "node:url";
|
|
6
6
|
import { serve } from "@hono/node-server";
|
|
7
7
|
import { Storage } from "@google-cloud/storage";
|
|
@@ -81,14 +81,19 @@ function formatExtension(format) {
|
|
|
81
81
|
// src/gcsTransport.ts
|
|
82
82
|
import {
|
|
83
83
|
createReadStream,
|
|
84
|
+
copyFileSync,
|
|
84
85
|
createWriteStream,
|
|
85
86
|
existsSync as existsSync2,
|
|
87
|
+
lstatSync,
|
|
86
88
|
mkdirSync,
|
|
89
|
+
readdirSync,
|
|
90
|
+
renameSync,
|
|
87
91
|
rmSync,
|
|
88
|
-
statSync
|
|
92
|
+
statSync,
|
|
93
|
+
constants as fsConstants
|
|
89
94
|
} from "node:fs";
|
|
90
|
-
import { createHash } from "node:crypto";
|
|
91
|
-
import { dirname } from "node:path";
|
|
95
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
96
|
+
import { dirname, join } from "node:path";
|
|
92
97
|
import { pipeline } from "node:stream/promises";
|
|
93
98
|
import * as tar from "tar";
|
|
94
99
|
function parseGcsUri(uri) {
|
|
@@ -220,6 +225,37 @@ async function tarDirectory(sourceDir, destTarball, files) {
|
|
|
220
225
|
files ?? ["."]
|
|
221
226
|
);
|
|
222
227
|
}
|
|
228
|
+
var UNPACKED_ENTRY_TYPES = /* @__PURE__ */ new Set([
|
|
229
|
+
"File",
|
|
230
|
+
"OldFile",
|
|
231
|
+
"ContiguousFile",
|
|
232
|
+
"Directory",
|
|
233
|
+
"Link"
|
|
234
|
+
]);
|
|
235
|
+
function hardLinkedFiles(dir, found = []) {
|
|
236
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
237
|
+
const path = join(dir, entry.name);
|
|
238
|
+
if (entry.isDirectory()) hardLinkedFiles(path, found);
|
|
239
|
+
else if (entry.isFile() && lstatSync(path).nlink > 1) found.push(path);
|
|
240
|
+
}
|
|
241
|
+
return found;
|
|
242
|
+
}
|
|
243
|
+
function copyHardLinkedFiles(destDir) {
|
|
244
|
+
for (const path of hardLinkedFiles(destDir)) {
|
|
245
|
+
if (lstatSync(path).nlink === 1) continue;
|
|
246
|
+
const copy = join(dirname(path), `.unlink-${randomUUID()}`);
|
|
247
|
+
try {
|
|
248
|
+
copyFileSync(path, copy, fsConstants.COPYFILE_EXCL);
|
|
249
|
+
renameSync(copy, path);
|
|
250
|
+
} catch (err) {
|
|
251
|
+
try {
|
|
252
|
+
rmSync(copy, { force: true });
|
|
253
|
+
} catch {
|
|
254
|
+
}
|
|
255
|
+
throw err;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
223
259
|
async function untarDirectory(tarballPath, destDir) {
|
|
224
260
|
if (!existsSync2(tarballPath)) {
|
|
225
261
|
throw new Error(`[gcsTransport] tarball missing: ${tarballPath}`);
|
|
@@ -228,14 +264,24 @@ async function untarDirectory(tarballPath, destDir) {
|
|
|
228
264
|
rmSync(destDir, { recursive: true, force: true });
|
|
229
265
|
}
|
|
230
266
|
mkdirSync(destDir, { recursive: true });
|
|
231
|
-
|
|
267
|
+
let sawHardLink = false;
|
|
268
|
+
await tar.extract({
|
|
269
|
+
file: tarballPath,
|
|
270
|
+
cwd: destDir,
|
|
271
|
+
filter: (_path, entry) => {
|
|
272
|
+
if (!("type" in entry) || !UNPACKED_ENTRY_TYPES.has(entry.type)) return false;
|
|
273
|
+
sawHardLink ||= entry.type === "Link";
|
|
274
|
+
return true;
|
|
275
|
+
}
|
|
276
|
+
});
|
|
277
|
+
if (sawHardLink) copyHardLinkedFiles(destDir);
|
|
232
278
|
}
|
|
233
279
|
|
|
234
280
|
// src/gcsPlanV2Publisher.ts
|
|
235
281
|
import { createHash as createHash2 } from "node:crypto";
|
|
236
282
|
import { mkdirSync as mkdirSync2, mkdtempSync, rmSync as rmSync2, statSync as statSync2, writeFileSync } from "node:fs";
|
|
237
283
|
import { tmpdir } from "node:os";
|
|
238
|
-
import { join } from "node:path";
|
|
284
|
+
import { join as join2 } from "node:path";
|
|
239
285
|
import {
|
|
240
286
|
PlanV2IntegrityError
|
|
241
287
|
} from "@hyperframes/producer/distributed";
|
|
@@ -311,8 +357,8 @@ var GcsPlanV2ArtifactPublisher = class {
|
|
|
311
357
|
}
|
|
312
358
|
}
|
|
313
359
|
const manifestDigest = createHash2("sha256").update(manifestBytes, "utf8").digest("hex");
|
|
314
|
-
const stagingDir = mkdtempSync(
|
|
315
|
-
const manifestPath =
|
|
360
|
+
const stagingDir = mkdtempSync(join2(this.#temporaryRoot, "hf-plan-v2-manifest-"));
|
|
361
|
+
const manifestPath = join2(stagingDir, "manifest.json");
|
|
316
362
|
try {
|
|
317
363
|
writeFileSync(manifestPath, manifestBytes, "utf8");
|
|
318
364
|
await uploadContentAddressedFileToGcs(
|
|
@@ -481,9 +527,9 @@ async function handlePlan(event, deps) {
|
|
|
481
527
|
const storage = deps?.storage ?? getStorage();
|
|
482
528
|
const primitive = deps?.primitives?.planV2WithPublisher ?? planV2WithPublisher;
|
|
483
529
|
primeChrome(deps);
|
|
484
|
-
const work = mkdtempSync2(
|
|
485
|
-
const projectArchive =
|
|
486
|
-
const projectDir =
|
|
530
|
+
const work = mkdtempSync2(join3(deps?.tmpRoot ?? tmpdir2(), "hf-cr-plan-v2-"));
|
|
531
|
+
const projectArchive = join3(work, "project.tar.gz");
|
|
532
|
+
const projectDir = join3(work, "project");
|
|
487
533
|
try {
|
|
488
534
|
await downloadGcsObjectToFile(storage, event.ProjectGcsUri, projectArchive);
|
|
489
535
|
await untarDirectory(projectArchive, projectDir);
|
|
@@ -522,7 +568,7 @@ async function handleRenderChunk(event, deps) {
|
|
|
522
568
|
const storage = deps?.storage ?? getStorage();
|
|
523
569
|
const primitive = deps?.primitives?.renderChunk ?? renderChunk;
|
|
524
570
|
primeChrome(deps);
|
|
525
|
-
const work = mkdtempSync2(
|
|
571
|
+
const work = mkdtempSync2(join3(deps?.tmpRoot ?? tmpdir2(), "hf-cr-chunk-v2-"));
|
|
526
572
|
try {
|
|
527
573
|
const planDir = await downloadAndMaterializePlanV2(
|
|
528
574
|
storage,
|
|
@@ -530,7 +576,7 @@ async function handleRenderChunk(event, deps) {
|
|
|
530
576
|
{ role: "chunk", chunkIndex: event.ChunkIndex },
|
|
531
577
|
work
|
|
532
578
|
);
|
|
533
|
-
const chunkOutputBase =
|
|
579
|
+
const chunkOutputBase = join3(
|
|
534
580
|
work,
|
|
535
581
|
event.Format === "png-sequence" ? `chunk-${pad(event.ChunkIndex)}` : `chunk-${pad(event.ChunkIndex)}${formatExtension(event.Format)}`
|
|
536
582
|
);
|
|
@@ -572,12 +618,12 @@ async function handleAssemble(event, deps) {
|
|
|
572
618
|
const started = Date.now();
|
|
573
619
|
const storage = deps?.storage ?? getStorage();
|
|
574
620
|
const primitive = deps?.primitives?.assemble ?? assemble;
|
|
575
|
-
const work = mkdtempSync2(
|
|
621
|
+
const work = mkdtempSync2(join3(deps?.tmpRoot ?? tmpdir2(), "hf-cr-assemble-v2-"));
|
|
576
622
|
try {
|
|
577
623
|
const planDir = await downloadAndMaterializePlanV2(storage, event, { role: "assembler" }, work);
|
|
578
624
|
const audioPath = resolvePlanAudioPath(planDir);
|
|
579
625
|
const chunkPaths = await downloadChunkObjects(storage, event.ChunkGcsUris, work, event.Format);
|
|
580
|
-
const finalOutput = event.Format === "png-sequence" ?
|
|
626
|
+
const finalOutput = event.Format === "png-sequence" ? join3(work, "output-frames") : join3(work, `output${formatExtension(event.Format)}`);
|
|
581
627
|
const result = await primitive(planDir, chunkPaths, audioPath, finalOutput, {
|
|
582
628
|
cfr: event.Cfr === true
|
|
583
629
|
});
|
|
@@ -600,12 +646,12 @@ async function handleAssemble(event, deps) {
|
|
|
600
646
|
}
|
|
601
647
|
}
|
|
602
648
|
async function downloadAndMaterializePlanV2(storage, event, target, work) {
|
|
603
|
-
const transportDir =
|
|
649
|
+
const transportDir = join3(work, "plan-v2");
|
|
604
650
|
mkdirSync3(transportDir, { recursive: true });
|
|
605
651
|
await downloadGcsObjectToFile(
|
|
606
652
|
storage,
|
|
607
653
|
event.PlanV2ManifestGcsUri,
|
|
608
|
-
|
|
654
|
+
join3(transportDir, "plan.json")
|
|
609
655
|
);
|
|
610
656
|
const manifest = readPlanV2Manifest(transportDir);
|
|
611
657
|
if (manifest.planHash !== event.PlanHash) {
|
|
@@ -618,7 +664,7 @@ async function downloadAndMaterializePlanV2(storage, event, target, work) {
|
|
|
618
664
|
await mapConcurrent(uniqueArtifacts, 16, async (artifact) => {
|
|
619
665
|
await downloadPlanV2Artifact(storage, event.PlanV2ArtifactGcsPrefix, transportDir, artifact);
|
|
620
666
|
});
|
|
621
|
-
const planDir =
|
|
667
|
+
const planDir = join3(work, "plan");
|
|
622
668
|
materializePlanV2Target(transportDir, target, planDir);
|
|
623
669
|
return planDir;
|
|
624
670
|
}
|
|
@@ -631,7 +677,7 @@ async function downloadPlanV2Artifact(storage, artifactPrefix, planV2Dir, artifa
|
|
|
631
677
|
);
|
|
632
678
|
}
|
|
633
679
|
function planV2BlobPath(planV2Dir, digest) {
|
|
634
|
-
return
|
|
680
|
+
return join3(planV2Dir, "artifacts", "sha256", digest.slice(0, 2), digest);
|
|
635
681
|
}
|
|
636
682
|
function planV2BlobUri(prefix, digest) {
|
|
637
683
|
return `${trimTrailingSlash2(prefix)}/${digest.slice(0, 2)}/${digest}`;
|
|
@@ -660,7 +706,7 @@ async function mapConcurrent(values, concurrency, fn) {
|
|
|
660
706
|
if (failure) throw failure.reason;
|
|
661
707
|
}
|
|
662
708
|
async function downloadChunkObjects(storage, uris, workDir, format) {
|
|
663
|
-
const chunksDir =
|
|
709
|
+
const chunksDir = join3(workDir, "chunks");
|
|
664
710
|
mkdirSync3(chunksDir, { recursive: true });
|
|
665
711
|
const local = new Array(uris.length);
|
|
666
712
|
await Promise.all(
|
|
@@ -669,10 +715,10 @@ async function downloadChunkObjects(storage, uris, workDir, format) {
|
|
|
669
715
|
throw new Error(`[handler] chunk URI at index ${i} is empty`);
|
|
670
716
|
}
|
|
671
717
|
const { key } = parseGcsUri(uri);
|
|
672
|
-
const localPath =
|
|
718
|
+
const localPath = join3(chunksDir, basename(key));
|
|
673
719
|
await downloadGcsObjectToFile(storage, uri, localPath);
|
|
674
720
|
if (format === "png-sequence") {
|
|
675
|
-
const dirPath =
|
|
721
|
+
const dirPath = join3(chunksDir, `frames-${pad(i)}`);
|
|
676
722
|
await untarDirectory(localPath, dirPath);
|
|
677
723
|
local[i] = dirPath;
|
|
678
724
|
} else {
|
|
@@ -810,7 +856,7 @@ if (process.argv[1] && fileURLToPath(import.meta.url) === process.argv[1]) {
|
|
|
810
856
|
// src/sdk/deploySite.ts
|
|
811
857
|
import { mkdtempSync as mkdtempSync3, rmSync as rmSync4, statSync as statSync3 } from "node:fs";
|
|
812
858
|
import { tmpdir as tmpdir3 } from "node:os";
|
|
813
|
-
import { join as
|
|
859
|
+
import { join as join4 } from "node:path";
|
|
814
860
|
import { Storage as Storage2 } from "@google-cloud/storage";
|
|
815
861
|
import { hashProjectDir, listSiteFilesForUpload } from "@hyperframes/producer/distributed";
|
|
816
862
|
async function deploySite(opts) {
|
|
@@ -834,9 +880,9 @@ async function deploySite(opts) {
|
|
|
834
880
|
uploaded: false
|
|
835
881
|
};
|
|
836
882
|
}
|
|
837
|
-
const workdir = mkdtempSync3(
|
|
883
|
+
const workdir = mkdtempSync3(join4(tmpdir3(), "hf-deploy-site-"));
|
|
838
884
|
try {
|
|
839
|
-
const tarball =
|
|
885
|
+
const tarball = join4(workdir, "project.tar.gz");
|
|
840
886
|
await tarDirectory(opts.projectDir, tarball, files);
|
|
841
887
|
const size = statSync3(tarball).size;
|
|
842
888
|
await uploadFileToGcs(storage, tarball, projectGcsUri, "application/gzip");
|
|
@@ -865,7 +911,7 @@ async function headObject(file) {
|
|
|
865
911
|
}
|
|
866
912
|
|
|
867
913
|
// src/sdk/renderToCloudRun.ts
|
|
868
|
-
import { randomUUID } from "node:crypto";
|
|
914
|
+
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
869
915
|
|
|
870
916
|
// src/sdk/validateConfig.ts
|
|
871
917
|
import { InvalidConfigError } from "@hyperframes/producer/distributed";
|
|
@@ -922,7 +968,7 @@ async function renderToCloudRun(opts) {
|
|
|
922
968
|
if (!opts.siteHandle && !opts.projectDir) {
|
|
923
969
|
throw new Error("[renderToCloudRun] either siteHandle or projectDir must be supplied");
|
|
924
970
|
}
|
|
925
|
-
const renderId = opts.renderId ?? `hf-render-${
|
|
971
|
+
const renderId = opts.renderId ?? `hf-render-${randomUUID2()}`;
|
|
926
972
|
if (!/^[A-Za-z0-9._-]+$/.test(renderId) || renderId.includes("..")) {
|
|
927
973
|
throw new Error(
|
|
928
974
|
`[renderToCloudRun] renderId must match [A-Za-z0-9._-]+ and not contain "..": ${JSON.stringify(renderId)}`
|
package/dist/sdk/index.js
CHANGED
|
@@ -1,20 +1,25 @@
|
|
|
1
1
|
// src/sdk/deploySite.ts
|
|
2
2
|
import { mkdtempSync, rmSync as rmSync2, statSync as statSync2 } from "node:fs";
|
|
3
3
|
import { tmpdir } from "node:os";
|
|
4
|
-
import { join } from "node:path";
|
|
4
|
+
import { join as join2 } from "node:path";
|
|
5
5
|
import { Storage } from "@google-cloud/storage";
|
|
6
6
|
import { hashProjectDir, listSiteFilesForUpload } from "@hyperframes/producer/distributed";
|
|
7
7
|
|
|
8
8
|
// src/gcsTransport.ts
|
|
9
9
|
import {
|
|
10
10
|
createReadStream,
|
|
11
|
+
copyFileSync,
|
|
11
12
|
createWriteStream,
|
|
12
13
|
existsSync,
|
|
14
|
+
lstatSync,
|
|
13
15
|
mkdirSync,
|
|
16
|
+
readdirSync,
|
|
17
|
+
renameSync,
|
|
14
18
|
rmSync,
|
|
15
|
-
statSync
|
|
19
|
+
statSync,
|
|
20
|
+
constants as fsConstants
|
|
16
21
|
} from "node:fs";
|
|
17
|
-
import { dirname } from "node:path";
|
|
22
|
+
import { dirname, join } from "node:path";
|
|
18
23
|
import * as tar from "tar";
|
|
19
24
|
function parseGcsUri(uri) {
|
|
20
25
|
if (!uri.startsWith("gs://")) {
|
|
@@ -82,9 +87,9 @@ async function deploySite(opts) {
|
|
|
82
87
|
uploaded: false
|
|
83
88
|
};
|
|
84
89
|
}
|
|
85
|
-
const workdir = mkdtempSync(
|
|
90
|
+
const workdir = mkdtempSync(join2(tmpdir(), "hf-deploy-site-"));
|
|
86
91
|
try {
|
|
87
|
-
const tarball =
|
|
92
|
+
const tarball = join2(workdir, "project.tar.gz");
|
|
88
93
|
await tarDirectory(opts.projectDir, tarball, files);
|
|
89
94
|
const size = statSync2(tarball).size;
|
|
90
95
|
await uploadFileToGcs(storage, tarball, projectGcsUri, "application/gzip");
|
package/dist/server.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// src/server.ts
|
|
2
2
|
import { mkdirSync as mkdirSync3, mkdtempSync as mkdtempSync2, rmSync as rmSync3 } from "node:fs";
|
|
3
3
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
4
|
-
import { basename, extname, join as
|
|
4
|
+
import { basename, extname, join as join3 } from "node:path";
|
|
5
5
|
import { fileURLToPath } from "node:url";
|
|
6
6
|
import { serve } from "@hono/node-server";
|
|
7
7
|
import { Storage } from "@google-cloud/storage";
|
|
@@ -81,14 +81,19 @@ function formatExtension(format) {
|
|
|
81
81
|
// src/gcsTransport.ts
|
|
82
82
|
import {
|
|
83
83
|
createReadStream,
|
|
84
|
+
copyFileSync,
|
|
84
85
|
createWriteStream,
|
|
85
86
|
existsSync as existsSync2,
|
|
87
|
+
lstatSync,
|
|
86
88
|
mkdirSync,
|
|
89
|
+
readdirSync,
|
|
90
|
+
renameSync,
|
|
87
91
|
rmSync,
|
|
88
|
-
statSync
|
|
92
|
+
statSync,
|
|
93
|
+
constants as fsConstants
|
|
89
94
|
} from "node:fs";
|
|
90
|
-
import { createHash } from "node:crypto";
|
|
91
|
-
import { dirname } from "node:path";
|
|
95
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
96
|
+
import { dirname, join } from "node:path";
|
|
92
97
|
import { pipeline } from "node:stream/promises";
|
|
93
98
|
import * as tar from "tar";
|
|
94
99
|
function parseGcsUri(uri) {
|
|
@@ -217,6 +222,37 @@ async function tarDirectory(sourceDir, destTarball, files) {
|
|
|
217
222
|
files ?? ["."]
|
|
218
223
|
);
|
|
219
224
|
}
|
|
225
|
+
var UNPACKED_ENTRY_TYPES = /* @__PURE__ */ new Set([
|
|
226
|
+
"File",
|
|
227
|
+
"OldFile",
|
|
228
|
+
"ContiguousFile",
|
|
229
|
+
"Directory",
|
|
230
|
+
"Link"
|
|
231
|
+
]);
|
|
232
|
+
function hardLinkedFiles(dir, found = []) {
|
|
233
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
234
|
+
const path = join(dir, entry.name);
|
|
235
|
+
if (entry.isDirectory()) hardLinkedFiles(path, found);
|
|
236
|
+
else if (entry.isFile() && lstatSync(path).nlink > 1) found.push(path);
|
|
237
|
+
}
|
|
238
|
+
return found;
|
|
239
|
+
}
|
|
240
|
+
function copyHardLinkedFiles(destDir) {
|
|
241
|
+
for (const path of hardLinkedFiles(destDir)) {
|
|
242
|
+
if (lstatSync(path).nlink === 1) continue;
|
|
243
|
+
const copy = join(dirname(path), `.unlink-${randomUUID()}`);
|
|
244
|
+
try {
|
|
245
|
+
copyFileSync(path, copy, fsConstants.COPYFILE_EXCL);
|
|
246
|
+
renameSync(copy, path);
|
|
247
|
+
} catch (err) {
|
|
248
|
+
try {
|
|
249
|
+
rmSync(copy, { force: true });
|
|
250
|
+
} catch {
|
|
251
|
+
}
|
|
252
|
+
throw err;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
220
256
|
async function untarDirectory(tarballPath, destDir) {
|
|
221
257
|
if (!existsSync2(tarballPath)) {
|
|
222
258
|
throw new Error(`[gcsTransport] tarball missing: ${tarballPath}`);
|
|
@@ -225,14 +261,24 @@ async function untarDirectory(tarballPath, destDir) {
|
|
|
225
261
|
rmSync(destDir, { recursive: true, force: true });
|
|
226
262
|
}
|
|
227
263
|
mkdirSync(destDir, { recursive: true });
|
|
228
|
-
|
|
264
|
+
let sawHardLink = false;
|
|
265
|
+
await tar.extract({
|
|
266
|
+
file: tarballPath,
|
|
267
|
+
cwd: destDir,
|
|
268
|
+
filter: (_path, entry) => {
|
|
269
|
+
if (!("type" in entry) || !UNPACKED_ENTRY_TYPES.has(entry.type)) return false;
|
|
270
|
+
sawHardLink ||= entry.type === "Link";
|
|
271
|
+
return true;
|
|
272
|
+
}
|
|
273
|
+
});
|
|
274
|
+
if (sawHardLink) copyHardLinkedFiles(destDir);
|
|
229
275
|
}
|
|
230
276
|
|
|
231
277
|
// src/gcsPlanV2Publisher.ts
|
|
232
278
|
import { createHash as createHash2 } from "node:crypto";
|
|
233
279
|
import { mkdirSync as mkdirSync2, mkdtempSync, rmSync as rmSync2, statSync as statSync2, writeFileSync } from "node:fs";
|
|
234
280
|
import { tmpdir } from "node:os";
|
|
235
|
-
import { join } from "node:path";
|
|
281
|
+
import { join as join2 } from "node:path";
|
|
236
282
|
import {
|
|
237
283
|
PlanV2IntegrityError
|
|
238
284
|
} from "@hyperframes/producer/distributed";
|
|
@@ -308,8 +354,8 @@ var GcsPlanV2ArtifactPublisher = class {
|
|
|
308
354
|
}
|
|
309
355
|
}
|
|
310
356
|
const manifestDigest = createHash2("sha256").update(manifestBytes, "utf8").digest("hex");
|
|
311
|
-
const stagingDir = mkdtempSync(
|
|
312
|
-
const manifestPath =
|
|
357
|
+
const stagingDir = mkdtempSync(join2(this.#temporaryRoot, "hf-plan-v2-manifest-"));
|
|
358
|
+
const manifestPath = join2(stagingDir, "manifest.json");
|
|
313
359
|
try {
|
|
314
360
|
writeFileSync(manifestPath, manifestBytes, "utf8");
|
|
315
361
|
await uploadContentAddressedFileToGcs(
|
|
@@ -478,9 +524,9 @@ async function handlePlan(event, deps) {
|
|
|
478
524
|
const storage = deps?.storage ?? getStorage();
|
|
479
525
|
const primitive = deps?.primitives?.planV2WithPublisher ?? planV2WithPublisher;
|
|
480
526
|
primeChrome(deps);
|
|
481
|
-
const work = mkdtempSync2(
|
|
482
|
-
const projectArchive =
|
|
483
|
-
const projectDir =
|
|
527
|
+
const work = mkdtempSync2(join3(deps?.tmpRoot ?? tmpdir2(), "hf-cr-plan-v2-"));
|
|
528
|
+
const projectArchive = join3(work, "project.tar.gz");
|
|
529
|
+
const projectDir = join3(work, "project");
|
|
484
530
|
try {
|
|
485
531
|
await downloadGcsObjectToFile(storage, event.ProjectGcsUri, projectArchive);
|
|
486
532
|
await untarDirectory(projectArchive, projectDir);
|
|
@@ -519,7 +565,7 @@ async function handleRenderChunk(event, deps) {
|
|
|
519
565
|
const storage = deps?.storage ?? getStorage();
|
|
520
566
|
const primitive = deps?.primitives?.renderChunk ?? renderChunk;
|
|
521
567
|
primeChrome(deps);
|
|
522
|
-
const work = mkdtempSync2(
|
|
568
|
+
const work = mkdtempSync2(join3(deps?.tmpRoot ?? tmpdir2(), "hf-cr-chunk-v2-"));
|
|
523
569
|
try {
|
|
524
570
|
const planDir = await downloadAndMaterializePlanV2(
|
|
525
571
|
storage,
|
|
@@ -527,7 +573,7 @@ async function handleRenderChunk(event, deps) {
|
|
|
527
573
|
{ role: "chunk", chunkIndex: event.ChunkIndex },
|
|
528
574
|
work
|
|
529
575
|
);
|
|
530
|
-
const chunkOutputBase =
|
|
576
|
+
const chunkOutputBase = join3(
|
|
531
577
|
work,
|
|
532
578
|
event.Format === "png-sequence" ? `chunk-${pad(event.ChunkIndex)}` : `chunk-${pad(event.ChunkIndex)}${formatExtension(event.Format)}`
|
|
533
579
|
);
|
|
@@ -569,12 +615,12 @@ async function handleAssemble(event, deps) {
|
|
|
569
615
|
const started = Date.now();
|
|
570
616
|
const storage = deps?.storage ?? getStorage();
|
|
571
617
|
const primitive = deps?.primitives?.assemble ?? assemble;
|
|
572
|
-
const work = mkdtempSync2(
|
|
618
|
+
const work = mkdtempSync2(join3(deps?.tmpRoot ?? tmpdir2(), "hf-cr-assemble-v2-"));
|
|
573
619
|
try {
|
|
574
620
|
const planDir = await downloadAndMaterializePlanV2(storage, event, { role: "assembler" }, work);
|
|
575
621
|
const audioPath = resolvePlanAudioPath(planDir);
|
|
576
622
|
const chunkPaths = await downloadChunkObjects(storage, event.ChunkGcsUris, work, event.Format);
|
|
577
|
-
const finalOutput = event.Format === "png-sequence" ?
|
|
623
|
+
const finalOutput = event.Format === "png-sequence" ? join3(work, "output-frames") : join3(work, `output${formatExtension(event.Format)}`);
|
|
578
624
|
const result = await primitive(planDir, chunkPaths, audioPath, finalOutput, {
|
|
579
625
|
cfr: event.Cfr === true
|
|
580
626
|
});
|
|
@@ -597,12 +643,12 @@ async function handleAssemble(event, deps) {
|
|
|
597
643
|
}
|
|
598
644
|
}
|
|
599
645
|
async function downloadAndMaterializePlanV2(storage, event, target, work) {
|
|
600
|
-
const transportDir =
|
|
646
|
+
const transportDir = join3(work, "plan-v2");
|
|
601
647
|
mkdirSync3(transportDir, { recursive: true });
|
|
602
648
|
await downloadGcsObjectToFile(
|
|
603
649
|
storage,
|
|
604
650
|
event.PlanV2ManifestGcsUri,
|
|
605
|
-
|
|
651
|
+
join3(transportDir, "plan.json")
|
|
606
652
|
);
|
|
607
653
|
const manifest = readPlanV2Manifest(transportDir);
|
|
608
654
|
if (manifest.planHash !== event.PlanHash) {
|
|
@@ -615,7 +661,7 @@ async function downloadAndMaterializePlanV2(storage, event, target, work) {
|
|
|
615
661
|
await mapConcurrent(uniqueArtifacts, 16, async (artifact) => {
|
|
616
662
|
await downloadPlanV2Artifact(storage, event.PlanV2ArtifactGcsPrefix, transportDir, artifact);
|
|
617
663
|
});
|
|
618
|
-
const planDir =
|
|
664
|
+
const planDir = join3(work, "plan");
|
|
619
665
|
materializePlanV2Target(transportDir, target, planDir);
|
|
620
666
|
return planDir;
|
|
621
667
|
}
|
|
@@ -628,7 +674,7 @@ async function downloadPlanV2Artifact(storage, artifactPrefix, planV2Dir, artifa
|
|
|
628
674
|
);
|
|
629
675
|
}
|
|
630
676
|
function planV2BlobPath(planV2Dir, digest) {
|
|
631
|
-
return
|
|
677
|
+
return join3(planV2Dir, "artifacts", "sha256", digest.slice(0, 2), digest);
|
|
632
678
|
}
|
|
633
679
|
function planV2BlobUri(prefix, digest) {
|
|
634
680
|
return `${trimTrailingSlash2(prefix)}/${digest.slice(0, 2)}/${digest}`;
|
|
@@ -657,7 +703,7 @@ async function mapConcurrent(values, concurrency, fn) {
|
|
|
657
703
|
if (failure) throw failure.reason;
|
|
658
704
|
}
|
|
659
705
|
async function downloadChunkObjects(storage, uris, workDir, format) {
|
|
660
|
-
const chunksDir =
|
|
706
|
+
const chunksDir = join3(workDir, "chunks");
|
|
661
707
|
mkdirSync3(chunksDir, { recursive: true });
|
|
662
708
|
const local = new Array(uris.length);
|
|
663
709
|
await Promise.all(
|
|
@@ -666,10 +712,10 @@ async function downloadChunkObjects(storage, uris, workDir, format) {
|
|
|
666
712
|
throw new Error(`[handler] chunk URI at index ${i} is empty`);
|
|
667
713
|
}
|
|
668
714
|
const { key } = parseGcsUri(uri);
|
|
669
|
-
const localPath =
|
|
715
|
+
const localPath = join3(chunksDir, basename(key));
|
|
670
716
|
await downloadGcsObjectToFile(storage, uri, localPath);
|
|
671
717
|
if (format === "png-sequence") {
|
|
672
|
-
const dirPath =
|
|
718
|
+
const dirPath = join3(chunksDir, `frames-${pad(i)}`);
|
|
673
719
|
await untarDirectory(localPath, dirPath);
|
|
674
720
|
local[i] = dirPath;
|
|
675
721
|
} else {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hyperframes/gcp-cloud-run",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.58",
|
|
4
4
|
"description": "Google Cloud Run + Workflows adapter for HyperFrames distributed rendering — request handler, client-side SDK, and Terraform module.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"hono": "^4.13.16",
|
|
46
46
|
"puppeteer-core": "^25.8.0",
|
|
47
47
|
"tar": "^7.5.22",
|
|
48
|
-
"@hyperframes/producer": "^0.9.
|
|
48
|
+
"@hyperframes/producer": "^0.9.58"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@types/node": "^25.0.10",
|