Skip to content

armgit / hypit

Public Imported from GitHub
0

Clone any viral video with AI agents. Not just a script, the whole workflow: swap the face, the words, the B-roll, ship 100 variants in one command, and get your 100M views.

fix(provider-hypihub): remove legacy upload fallback

rponeb6fca9e4a3dd
diff --git a/packages/provider-hypihub/README.md b/packages/provider-hypihub/README.md
index c3b4ed8d..b5c78d9c 100644
--- a/packages/provider-hypihub/README.md
+++ b/packages/provider-hypihub/README.md
@@ -43,12 +43,9 @@ for every valid non-empty media file, including files compressed by the tool bef
are uploaded concurrently through short-lived signed URLs, so media bytes do not make an extra trip
through the HypiHub application server. A failed part alone is retried with a fresh signed URL.
-The server owns the size threshold, part size, concurrency, and URL lifetime. Clients do not need
-to duplicate that policy. `uploadPartTimeoutMs` (default five minutes) and `uploadPartAttempts`
-(default three) only control client retry behavior. During a rolling server upgrade, an exact 404
-from the policy endpoint falls back to the established multipart API; the server may also select
-that compatibility route when direct upload is disabled. Signed S3 URLs are never
-included in Provider error messages. Uploads remain deduplicated by Artifact digest within one
+The server owns the part size, concurrency, and URL lifetime. Clients do not need to duplicate that
+policy. `uploadPartTimeoutMs` (default five minutes) and `uploadPartAttempts` (default three) only
+control client retry behavior. Signed S3 URLs are never included in Provider error messages. Uploads remain deduplicated by Artifact digest within one
Runtime operation. Embedded callers may override the entire transport with `publicAssetUrl`.
The provider also serves `@hypit/whisperx#whisperx-alignment` through HypiHub's synchronous
diff --git a/packages/provider-hypihub/src/upload.ts b/packages/provider-hypihub/src/upload.ts
index 8bd0928b..a5c7bef4 100644
--- a/packages/provider-hypihub/src/upload.ts
+++ b/packages/provider-hypihub/src/upload.ts
@@ -77,7 +77,7 @@ function assertHTTPS(value: string, subject: string): void {
assert(protocol === "https:", `${subject} must use HTTPS`);
}
-/** Uploads media either through the compatibility form endpoint or directly to private regional S3. */
+/** Uploads media through HypiHub's session-negotiated private regional S3 multipart flow. */
export class HypiHubUploader {
readonly baseUrl: string;
readonly requestTimeout: number;
@@ -129,22 +129,6 @@ export class HypiHubUploader {
}
}
- private async uploadForm(input: HypiHubUploadInput, apiKey: string, digest: string): Promise<string> {
- const startedAt = Date.now();
- this.log(`compatibility upload started bytes=${input.bytes.byteLength} mime=${input.mediaType}`);
- const form = new FormData();
- const copy = new ArrayBuffer(input.bytes.byteLength);
- new Uint8Array(copy).set(input.bytes);
- form.append("file", new Blob([copy], { type: input.mediaType }),
- input.filename ?? `${digest}.${extension(input.mediaType)}`);
- form.append("purpose", input.purpose ?? "reference");
- const response = await this.json("/files", apiKey, { method: "POST", body: form });
- const url = requiredString(response.url, "HypiHub file upload URL");
- assert(/^https:\/\//iu.test(url), "HypiHub file upload returned no HTTPS URL");
- this.log(`compatibility upload completed bytes=${input.bytes.byteLength} elapsed=${this.elapsed(startedAt)}`);
- return url;
- }
-
private async signParts(uploadId: string, declarations: readonly PartDeclaration[], apiKey: string): Promise<Map<number, Record<string, unknown>>> {
const startedAt = Date.now();
this.log(`part signing started upload=${uploadId} parts=${declarations.length}`);
@@ -312,17 +296,7 @@ export class HypiHubUploader {
this.log(`upload session request finished elapsed=${this.elapsed(policyStartedAt)}`);
} catch (error) {
this.log(`upload session request failed elapsed=${this.elapsed(policyStartedAt)} reason=${this.safeReason(error)}`);
- if (!(error instanceof HypiHubHTTPError) || error.status !== 404) throw error;
- this.log("upload session endpoint returned 404; falling back to compatibility upload");
- const result = await this.uploadForm(input, apiKey, digest);
- this.log(`upload finished bytes=${input.bytes.byteLength} mime=${input.mediaType} elapsed=${this.elapsed(startedAt)}`);
- return result;
- }
- if (policy.upload_mode === "api_multipart") {
- this.log("HypiHub selected compatibility upload mode");
- const result = await this.uploadForm(input, apiKey, digest);
- this.log(`upload finished bytes=${input.bytes.byteLength} mime=${input.mediaType} elapsed=${this.elapsed(startedAt)}`);
- return result;
+ throw error;
}
assert(policy.upload_mode === "s3_multipart", "HypiHub returned an unknown upload mode");
const result = await this.uploadDirect(input.bytes, apiKey, policy);
diff --git a/packages/provider-hypihub/test/gemini.test.ts b/packages/provider-hypihub/test/gemini.test.ts
index 0c3c43dd..012f4324 100644
--- a/packages/provider-hypihub/test/gemini.test.ts
+++ b/packages/provider-hypihub/test/gemini.test.ts
@@ -14,14 +14,17 @@ test("HypiHub Gemini uses native wire format for text, image and video parts", a
fetch: async (input, init) => {
seenUrl = String(input);
if (seenUrl.endsWith("/v1/files/uploads")) {
- return Response.json({ upload_mode: "api_multipart" });
- }
- if (seenUrl.endsWith("/v1/files")) {
uploads += 1;
- assert.equal(init?.method, "POST");
- assert.ok(init?.body instanceof FormData);
- return Response.json({ url: `https://hypit.ai/files/ref-${uploads}.png` });
+ return Response.json({ upload_mode: "s3_multipart", upload_id: `up_native_${uploads}`, part_size: 16, part_count: 1, concurrency: 4 });
+ }
+ const uploadMatch = /\/v1\/files\/uploads\/(up_native_\d+)\/parts$/u.exec(seenUrl);
+ if (uploadMatch) {
+ const body = JSON.parse(String(init?.body)) as { parts: readonly { checksum_sha256: string }[] };
+ return Response.json({ parts: [{ part_number: 1, url: `https://s3.example/${uploadMatch[1]}`, headers: { "content-length": "5", "x-amz-checksum-sha256": body.parts[0]?.checksum_sha256 } }] });
}
+ if (seenUrl.startsWith("https://s3.example/")) return new Response(null, { status: 200, headers: { etag: '"part"' } });
+ const completeMatch = /\/v1\/files\/uploads\/(up_native_\d+)\/complete$/u.exec(seenUrl);
+ if (completeMatch) return Response.json({ url: `https://hypit.ai/files/ref-${completeMatch[1]}.png` });
seenBody = JSON.parse(String(init?.body)) as Record<string, unknown>;
return Response.json({ candidates: [{ content: { parts: [{ text: "OK" }] } }] });
},
@@ -36,8 +39,8 @@ test("HypiHub Gemini uses native wire format for text, image and video parts", a
assert.equal(uploads, 2);
assert.deepEqual(seenBody?.contents, [{ role: "user", parts: [
{ text: "inspect" },
- { fileData: { mimeType: "image/png", fileUri: "https://hypit.ai/files/ref-1.png" } },
- { fileData: { mimeType: "video/mp4", fileUri: "https://hypit.ai/files/ref-2.png" } },
+ { fileData: { mimeType: "image/png", fileUri: "https://hypit.ai/files/ref-up_native_1.png" } },
+ { fileData: { mimeType: "video/mp4", fileUri: "https://hypit.ai/files/ref-up_native_2.png" } },
] }]);
});
@@ -57,15 +60,18 @@ test("HypiHub Gemini retries upstream rate limits without reuploading files", as
apiKey: "test-key",
maxRateLimitRetries: 2,
rateLimitRetryDelayMs: 1,
- fetch: async (input) => {
+ fetch: async (input, init) => {
const url = String(input);
if (url.endsWith("/v1/files/uploads")) {
- return Response.json({ upload_mode: "api_multipart" });
- }
- if (url.endsWith("/v1/files")) {
uploads += 1;
- return Response.json({ url: "https://hypit.ai/files/ref" });
+ return Response.json({ upload_mode: "s3_multipart", upload_id: "up_retry", part_size: 16, part_count: 1, concurrency: 4 });
+ }
+ if (url.endsWith("/v1/files/uploads/up_retry/parts")) {
+ const body = JSON.parse(String(init?.body)) as { parts: readonly { checksum_sha256: string }[] };
+ return Response.json({ parts: [{ part_number: 1, url: "https://s3.example/retry", headers: { "content-length": "5", "x-amz-checksum-sha256": body.parts[0]?.checksum_sha256 } }] });
}
+ if (url === "https://s3.example/retry") return new Response(null, { status: 200, headers: { etag: '"part"' } });
+ if (url.endsWith("/v1/files/uploads/up_retry/complete")) return Response.json({ url: "https://hypit.ai/files/ref" });
generations += 1;
return generations < 3
? new Response("rate limited", { status: 429, headers: { "retry-after": "0" } })
diff --git a/packages/provider-hypihub/test/provider.test.ts b/packages/provider-hypihub/test/provider.test.ts
index 1b0ce122..71cae0bd 100644
--- a/packages/provider-hypihub/test/provider.test.ts
+++ b/packages/provider-hypihub/test/provider.test.ts
@@ -73,17 +73,17 @@ test("HypiHub uploads referenced Artifacts once, submits their HTTPS URLs, and p
const body = JSON.parse(String(init?.body)) as Record<string, unknown>;
assert.equal(body.bytes, 3);
assert.equal(typeof body.sha256, "string");
- return Response.json({ upload_mode: "api_multipart" });
+ return Response.json({ upload_mode: "s3_multipart", upload_id: "up_reference", part_size: 16, part_count: 1, concurrency: 4 });
}
- if (url.endsWith("/v1/files")) {
- assert.equal(init?.method, "POST");
- assert.equal((init?.headers as Record<string, string>).authorization, "Bearer test-key");
- assert.ok(init?.body instanceof FormData);
- assert.equal(init.body.get("purpose"), "reference");
- const file = init.body.get("file");
- assert.ok(file instanceof File);
- assert.equal(file.type, "image/png");
- assert.deepEqual(new Uint8Array(await file.arrayBuffer()), new Uint8Array([1, 2, 3]));
+ if (url.endsWith("/v1/files/uploads/up_reference/parts")) {
+ const body = JSON.parse(String(init?.body)) as { parts: readonly { checksum_sha256: string }[] };
+ return Response.json({ parts: [{ part_number: 1, url: "https://s3.example/reference", headers: { "content-length": "3", "x-amz-checksum-sha256": body.parts[0]?.checksum_sha256 } }] });
+ }
+ if (url === "https://s3.example/reference") {
+ assert.equal(init?.method, "PUT");
+ return new Response(null, { status: 200, headers: { etag: '"reference"' } });
+ }
+ if (url.endsWith("/v1/files/uploads/up_reference/complete")) {
return Response.json({ url: "https://hypit.ai/files/as_reference.png" });
}
if (url.endsWith("/v1/models/bytedance%2Fseedance-2-mini")) {
@@ -117,11 +117,11 @@ test("HypiHub uploads referenced Artifacts once, submits their HTTPS URLs, and p
};
const started = await endpoint.start(common);
assert.equal(started.status, "pending");
- assert.equal(calls.filter((url) => url.endsWith("/v1/files")).length, 1);
+ assert.equal(calls.filter((url) => url === "https://s3.example/reference").length, 1);
if (started.status !== "pending") return;
const completed = await endpoint.poll({ ...common, handle: started.handle });
assert.equal(completed.status, "completed");
- assert.equal(calls.length, 7);
+ assert.equal(calls.length, 9);
});
test("HypiHub fulfills Gemini through the Runtime endpoint and uploads every media Artifact", async () => {
@@ -144,13 +144,19 @@ test("HypiHub fulfills Gemini through the Runtime endpoint and uploads every med
await createHypiHubProvider({ fetch: async (input, init) => {
const url = String(input);
if (url.endsWith("/v1/files/uploads")) {
- return Response.json({ upload_mode: "api_multipart" });
+ const uploadId = `up_gemini_${uploads.length + 1}`;
+ return Response.json({ upload_mode: "s3_multipart", upload_id: uploadId, part_size: 16, part_count: 1, concurrency: 4 });
+ }
+ const partsMatch = /\/v1\/files\/uploads\/(up_gemini_\d+)\/parts$/u.exec(url);
+ if (partsMatch) {
+ const body = JSON.parse(String(init?.body)) as { parts: readonly { checksum_sha256: string }[] };
+ return Response.json({ parts: [{ part_number: 1, url: `https://s3.example/${partsMatch[1]}`, headers: { "content-length": "3", "x-amz-checksum-sha256": body.parts[0]?.checksum_sha256 } }] });
+ }
+ if (url.startsWith("https://s3.example/")) {
+ return new Response(null, { status: 200, headers: { etag: '"part"' } });
}
- if (url.endsWith("/v1/files")) {
- assert.ok(init?.body instanceof FormData);
- const file = init.body.get("file");
- assert.ok(file instanceof File);
- uploads.push(file.type);
+ if (/\/v1\/files\/uploads\/up_gemini_\d+\/complete$/u.test(url)) {
+ uploads.push("uploaded");
return Response.json({ url: `https://hypit.ai/files/${uploads.length}` });
}
if (url.includes(":generateContent")) {
@@ -167,7 +173,7 @@ test("HypiHub fulfills Gemini through the Runtime endpoint and uploads every med
need: request, artifacts, credentials: { apiKey: { secret: "test-key" } },
});
assert.deepEqual(result.value, { kind: "inline", value: { value: "provider works" } });
- assert.deepEqual(uploads, ["image/png", "video/mp4"]);
+ assert.equal(uploads.length, 2);
assert.deepEqual((generationBody?.contents as readonly unknown[]), [{ role: "user", parts: [
{ text: "Inspect both references." },
{ fileData: { mimeType: "image/png", fileUri: "https://hypit.ai/files/1" } },