@hypit/hypit 0.1.9 → 0.1.10

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hypit/hypit",
3
- "version": "0.1.9",
3
+ "version": "0.1.10",
4
4
  "homepage": "https://hypit.ai",
5
5
  "repository": {
6
6
  "type": "git",
@@ -1,3 +1,4 @@
1
+ import { readFileSync } from "node:fs";
1
2
  import { requestDeadline } from "@hypit/runtime-kit";
2
3
  import type { AsyncEndpoint, EndpointCredential, EndpointFulfillment, EndpointInvocationContext, EndpointPollContext, EndpointPricingReader, EndpointStartContext, EndpointOutcome, ImmediateEndpointHandler } from "@hypit/endpoint-kit";
3
4
  import { defineEndpointPackage, wakeAfter } from "@hypit/endpoint-kit";
@@ -23,6 +24,29 @@ import { createHypiHubAuth, hypiHubCredentialNeedsRefresh } from "./oauth.js";
23
24
  import type { HypiHubAuth } from "./oauth.js";
24
25
  import { HypiHubHttpError, HypiHubServiceError, hypiHubJobFailure } from "./errors.js";
25
26
 
27
+ function distributionVersion(): string {
28
+ try {
29
+ const manifest = JSON.parse(readFileSync(new URL("../../../package.json", import.meta.url), "utf8")) as {
30
+ readonly name?: unknown; readonly version?: unknown;
31
+ };
32
+ if (manifest.name !== "@hypit/hypit" || typeof manifest.version !== "string" || manifest.version.length === 0) {
33
+ return "unknown";
34
+ }
35
+ return manifest.version;
36
+ } catch {
37
+ return "unknown";
38
+ }
39
+ }
40
+
41
+ const userAgent = `hypit/${distributionVersion()}`;
42
+
43
+ const identifiedFetch = (fetcher: typeof globalThis.fetch): typeof globalThis.fetch =>
44
+ async (input, init) => {
45
+ const headers: Record<string, string> = { "user-agent": userAgent };
46
+ new Headers(init?.headers).forEach((value, name) => { headers[name] = value; });
47
+ return await fetcher(input, { ...init, headers });
48
+ };
49
+
26
50
  export const hypiHubProviderModuleRef = { name: "@hypit/provider-hypihub", version: "1" } as const;
27
51
 
28
52
  export type CreateHypiHubProviderOptions = {
@@ -113,7 +137,7 @@ class HypiHubClient {
113
137
  this.timeout = options.timeout;
114
138
  this.oauthTimeout = options.oauthTimeout;
115
139
  this.downloadAttempts = options.downloadAttempts;
116
- this.fetcher = options.fetcher;
140
+ this.fetcher = identifiedFetch(options.fetcher);
117
141
  this.uploader = new HypiHubUploader({
118
142
  baseUrl: this.baseUrl,
119
143
  requestTimeoutMs: this.timeout,