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.

feat(hypihub): identify requests with the distribution version (#202)

Sharky Wange0c220231b1a
diff --git a/packages/provider-hypihub/src/provider.ts b/packages/provider-hypihub/src/provider.ts
index 6156a305..7b88fe9f 100644
--- a/packages/provider-hypihub/src/provider.ts
+++ b/packages/provider-hypihub/src/provider.ts
@@ -1,3 +1,4 @@
+import { readFileSync } from "node:fs";
import { requestDeadline } from "@hypit/runtime-kit";
import type { AsyncEndpoint, EndpointCredential, EndpointFulfillment, EndpointInvocationContext, EndpointPollContext, EndpointPricingReader, EndpointStartContext, EndpointOutcome, ImmediateEndpointHandler } from "@hypit/endpoint-kit";
import { defineEndpointPackage, wakeAfter } from "@hypit/endpoint-kit";
@@ -23,6 +24,29 @@ import { createHypiHubAuth, hypiHubCredentialNeedsRefresh } from "./oauth.js";
import type { HypiHubAuth } from "./oauth.js";
import { HypiHubHttpError, HypiHubServiceError, hypiHubJobFailure } from "./errors.js";
+function distributionVersion(): string {
+ try {
+ const manifest = JSON.parse(readFileSync(new URL("../../../package.json", import.meta.url), "utf8")) as {
+ readonly name?: unknown; readonly version?: unknown;
+ };
+ if (manifest.name !== "@hypit/hypit" || typeof manifest.version !== "string" || manifest.version.length === 0) {
+ return "unknown";
+ }
+ return manifest.version;
+ } catch {
+ return "unknown";
+ }
+}
+
+const userAgent = `hypit/${distributionVersion()}`;
+
+const identifiedFetch = (fetcher: typeof globalThis.fetch): typeof globalThis.fetch =>
+ async (input, init) => {
+ const headers: Record<string, string> = { "user-agent": userAgent };
+ new Headers(init?.headers).forEach((value, name) => { headers[name] = value; });
+ return await fetcher(input, { ...init, headers });
+ };
+
export const hypiHubProviderModuleRef = { name: "@hypit/provider-hypihub", version: "1" } as const;
export type CreateHypiHubProviderOptions = {
@@ -113,7 +137,7 @@ class HypiHubClient {
this.timeout = options.timeout;
this.oauthTimeout = options.oauthTimeout;
this.downloadAttempts = options.downloadAttempts;
- this.fetcher = options.fetcher;
+ this.fetcher = identifiedFetch(options.fetcher);
this.uploader = new HypiHubUploader({
baseUrl: this.baseUrl,
requestTimeoutMs: this.timeout,