@huggingface/inference 3.15.0 → 4.0.0

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.
Files changed (127) hide show
  1. package/README.md +102 -0
  2. package/dist/commonjs/errors.d.ts +46 -0
  3. package/dist/commonjs/errors.d.ts.map +1 -0
  4. package/dist/commonjs/errors.js +70 -0
  5. package/dist/commonjs/index.d.ts +1 -1
  6. package/dist/commonjs/index.d.ts.map +1 -1
  7. package/dist/commonjs/index.js +2 -3
  8. package/dist/commonjs/lib/getInferenceProviderMapping.d.ts.map +1 -1
  9. package/dist/commonjs/lib/getInferenceProviderMapping.js +27 -16
  10. package/dist/commonjs/lib/getProviderHelper.d.ts.map +1 -1
  11. package/dist/commonjs/lib/getProviderHelper.js +4 -3
  12. package/dist/commonjs/lib/makeRequestOptions.d.ts.map +1 -1
  13. package/dist/commonjs/lib/makeRequestOptions.js +12 -11
  14. package/dist/commonjs/package.d.ts +1 -1
  15. package/dist/commonjs/package.d.ts.map +1 -1
  16. package/dist/commonjs/package.js +1 -1
  17. package/dist/commonjs/providers/black-forest-labs.d.ts.map +1 -1
  18. package/dist/commonjs/providers/black-forest-labs.js +4 -4
  19. package/dist/commonjs/providers/fal-ai.d.ts.map +1 -1
  20. package/dist/commonjs/providers/fal-ai.js +29 -17
  21. package/dist/commonjs/providers/featherless-ai.d.ts.map +1 -1
  22. package/dist/commonjs/providers/featherless-ai.js +2 -2
  23. package/dist/commonjs/providers/hf-inference.d.ts.map +1 -1
  24. package/dist/commonjs/providers/hf-inference.js +27 -30
  25. package/dist/commonjs/providers/hyperbolic.d.ts.map +1 -1
  26. package/dist/commonjs/providers/hyperbolic.js +3 -3
  27. package/dist/commonjs/providers/nebius.d.ts.map +1 -1
  28. package/dist/commonjs/providers/nebius.js +2 -2
  29. package/dist/commonjs/providers/novita.d.ts.map +1 -1
  30. package/dist/commonjs/providers/novita.js +12 -8
  31. package/dist/commonjs/providers/nscale.d.ts.map +1 -1
  32. package/dist/commonjs/providers/nscale.js +2 -2
  33. package/dist/commonjs/providers/ovhcloud.d.ts.map +1 -1
  34. package/dist/commonjs/providers/ovhcloud.js +2 -2
  35. package/dist/commonjs/providers/providerHelper.js +3 -3
  36. package/dist/commonjs/providers/replicate.js +4 -4
  37. package/dist/commonjs/providers/sambanova.d.ts +16 -0
  38. package/dist/commonjs/providers/sambanova.d.ts.map +1 -1
  39. package/dist/commonjs/providers/sambanova.js +2 -18
  40. package/dist/commonjs/providers/together.d.ts.map +1 -1
  41. package/dist/commonjs/providers/together.js +3 -3
  42. package/dist/commonjs/tasks/audio/automaticSpeechRecognition.d.ts.map +1 -1
  43. package/dist/commonjs/tasks/audio/automaticSpeechRecognition.js +2 -2
  44. package/dist/commonjs/utils/request.d.ts.map +1 -1
  45. package/dist/commonjs/utils/request.js +77 -12
  46. package/dist/commonjs/vendor/type-fest/basic.d.ts +33 -0
  47. package/dist/commonjs/vendor/type-fest/basic.d.ts.map +1 -0
  48. package/dist/commonjs/vendor/type-fest/basic.js +2 -0
  49. package/dist/esm/errors.d.ts +46 -0
  50. package/dist/esm/errors.d.ts.map +1 -0
  51. package/dist/esm/errors.js +62 -0
  52. package/dist/esm/index.d.ts +1 -1
  53. package/dist/esm/index.d.ts.map +1 -1
  54. package/dist/esm/index.js +1 -1
  55. package/dist/esm/lib/getInferenceProviderMapping.d.ts.map +1 -1
  56. package/dist/esm/lib/getInferenceProviderMapping.js +27 -16
  57. package/dist/esm/lib/getProviderHelper.d.ts.map +1 -1
  58. package/dist/esm/lib/getProviderHelper.js +4 -3
  59. package/dist/esm/lib/makeRequestOptions.d.ts.map +1 -1
  60. package/dist/esm/lib/makeRequestOptions.js +12 -11
  61. package/dist/esm/package.d.ts +1 -1
  62. package/dist/esm/package.d.ts.map +1 -1
  63. package/dist/esm/package.js +1 -1
  64. package/dist/esm/providers/black-forest-labs.d.ts.map +1 -1
  65. package/dist/esm/providers/black-forest-labs.js +4 -4
  66. package/dist/esm/providers/fal-ai.d.ts.map +1 -1
  67. package/dist/esm/providers/fal-ai.js +29 -17
  68. package/dist/esm/providers/featherless-ai.d.ts.map +1 -1
  69. package/dist/esm/providers/featherless-ai.js +2 -2
  70. package/dist/esm/providers/hf-inference.d.ts.map +1 -1
  71. package/dist/esm/providers/hf-inference.js +27 -30
  72. package/dist/esm/providers/hyperbolic.d.ts.map +1 -1
  73. package/dist/esm/providers/hyperbolic.js +3 -3
  74. package/dist/esm/providers/nebius.d.ts.map +1 -1
  75. package/dist/esm/providers/nebius.js +2 -2
  76. package/dist/esm/providers/novita.d.ts.map +1 -1
  77. package/dist/esm/providers/novita.js +12 -8
  78. package/dist/esm/providers/nscale.d.ts.map +1 -1
  79. package/dist/esm/providers/nscale.js +2 -2
  80. package/dist/esm/providers/ovhcloud.d.ts.map +1 -1
  81. package/dist/esm/providers/ovhcloud.js +2 -2
  82. package/dist/esm/providers/providerHelper.js +3 -3
  83. package/dist/esm/providers/replicate.js +4 -4
  84. package/dist/esm/providers/sambanova.d.ts +16 -0
  85. package/dist/esm/providers/sambanova.d.ts.map +1 -1
  86. package/dist/esm/providers/sambanova.js +2 -18
  87. package/dist/esm/providers/together.d.ts.map +1 -1
  88. package/dist/esm/providers/together.js +3 -3
  89. package/dist/esm/tasks/audio/automaticSpeechRecognition.d.ts.map +1 -1
  90. package/dist/esm/tasks/audio/automaticSpeechRecognition.js +2 -2
  91. package/dist/esm/utils/request.d.ts.map +1 -1
  92. package/dist/esm/utils/request.js +77 -12
  93. package/dist/esm/vendor/type-fest/basic.d.ts +33 -0
  94. package/dist/esm/vendor/type-fest/basic.d.ts.map +1 -0
  95. package/dist/esm/vendor/type-fest/basic.js +1 -0
  96. package/package.json +2 -2
  97. package/src/errors.ts +82 -0
  98. package/src/index.ts +1 -1
  99. package/src/lib/getInferenceProviderMapping.ts +42 -22
  100. package/src/lib/getProviderHelper.ts +8 -3
  101. package/src/lib/makeRequestOptions.ts +20 -11
  102. package/src/package.ts +1 -1
  103. package/src/providers/black-forest-labs.ts +14 -4
  104. package/src/providers/fal-ai.ts +59 -23
  105. package/src/providers/featherless-ai.ts +2 -2
  106. package/src/providers/hf-inference.ts +75 -34
  107. package/src/providers/hyperbolic.ts +3 -4
  108. package/src/providers/nebius.ts +2 -2
  109. package/src/providers/novita.ts +30 -8
  110. package/src/providers/nscale.ts +2 -2
  111. package/src/providers/ovhcloud.ts +2 -2
  112. package/src/providers/providerHelper.ts +3 -3
  113. package/src/providers/replicate.ts +4 -4
  114. package/src/providers/sambanova.ts +3 -4
  115. package/src/providers/together.ts +3 -3
  116. package/src/tasks/audio/automaticSpeechRecognition.ts +2 -2
  117. package/src/utils/request.ts +127 -14
  118. package/src/vendor/type-fest/basic.ts +31 -0
  119. package/src/vendor/type-fest/license-cc0 +121 -0
  120. package/src/vendor/type-fest/license-mit +9 -0
  121. package/dist/commonjs/lib/InferenceOutputError.d.ts +0 -4
  122. package/dist/commonjs/lib/InferenceOutputError.d.ts.map +0 -1
  123. package/dist/commonjs/lib/InferenceOutputError.js +0 -10
  124. package/dist/esm/lib/InferenceOutputError.d.ts +0 -4
  125. package/dist/esm/lib/InferenceOutputError.d.ts.map +0 -1
  126. package/dist/esm/lib/InferenceOutputError.js +0 -6
  127. package/src/lib/InferenceOutputError.ts +0 -8
@@ -46,7 +46,7 @@ import type {
46
46
  ZeroShotImageClassificationOutput,
47
47
  } from "@huggingface/tasks";
48
48
  import { HF_ROUTER_URL } from "../config.js";
49
- import { InferenceOutputError } from "../lib/InferenceOutputError.js";
49
+ import { InferenceClientProviderOutputError } from "../errors.js";
50
50
  import type { AudioToAudioOutput } from "../tasks/audio/audioToAudio.js";
51
51
  import type { BaseArgs, BodyParams, HeaderParams, InferenceProvider, RequestArgs, UrlParams } from "../types.js";
52
52
  import { toArray } from "../utils/toArray.js";
@@ -320,7 +320,7 @@ export class BaseConversationalTask extends TaskProviderHelper implements Conver
320
320
  return response;
321
321
  }
322
322
 
323
- throw new InferenceOutputError("Expected ChatCompletionOutput");
323
+ throw new InferenceClientProviderOutputError("Expected ChatCompletionOutput");
324
324
  }
325
325
  }
326
326
 
@@ -353,6 +353,6 @@ export class BaseTextGenerationTask extends TaskProviderHelper implements TextGe
353
353
  return res[0];
354
354
  }
355
355
 
356
- throw new InferenceOutputError("Expected Array<{generated_text: string}>");
356
+ throw new InferenceClientProviderOutputError("Expected Array<{generated_text: string}>");
357
357
  }
358
358
  }
@@ -14,7 +14,7 @@
14
14
  *
15
15
  * Thanks!
16
16
  */
17
- import { InferenceOutputError } from "../lib/InferenceOutputError.js";
17
+ import { InferenceClientProviderOutputError } from "../errors.js";
18
18
  import { isUrl } from "../lib/isUrl.js";
19
19
  import type { BodyParams, HeaderParams, UrlParams } from "../types.js";
20
20
  import { omit } from "../utils/omit.js";
@@ -99,7 +99,7 @@ export class ReplicateTextToImageTask extends ReplicateTask implements TextToIma
99
99
  return await urlResponse.blob();
100
100
  }
101
101
 
102
- throw new InferenceOutputError("Expected Replicate text-to-image response format");
102
+ throw new InferenceClientProviderOutputError("Received malformed response from Replicate text-to-image API");
103
103
  }
104
104
  }
105
105
 
@@ -132,7 +132,7 @@ export class ReplicateTextToSpeechTask extends ReplicateTask {
132
132
  }
133
133
  }
134
134
  }
135
- throw new InferenceOutputError("Expected Blob or object with output");
135
+ throw new InferenceClientProviderOutputError("Received malformed response from Replicate text-to-speech API");
136
136
  }
137
137
  }
138
138
 
@@ -149,6 +149,6 @@ export class ReplicateTextToVideoTask extends ReplicateTask implements TextToVid
149
149
  return await urlResponse.blob();
150
150
  }
151
151
 
152
- throw new InferenceOutputError("Expected { output: string }");
152
+ throw new InferenceClientProviderOutputError("Received malformed response from Replicate text-to-video API");
153
153
  }
154
154
  }
@@ -14,12 +14,11 @@
14
14
  *
15
15
  * Thanks!
16
16
  */
17
- import { InferenceOutputError } from "../lib/InferenceOutputError.js";
18
-
19
17
  import type { FeatureExtractionOutput } from "@huggingface/tasks";
20
18
  import type { BodyParams } from "../types.js";
21
19
  import type { FeatureExtractionTaskHelper } from "./providerHelper.js";
22
20
  import { BaseConversationalTask, TaskProviderHelper } from "./providerHelper.js";
21
+ import { InferenceClientProviderOutputError } from "../errors.js";
23
22
 
24
23
  export class SambanovaConversationalTask extends BaseConversationalTask {
25
24
  constructor() {
@@ -40,8 +39,8 @@ export class SambanovaFeatureExtractionTask extends TaskProviderHelper implement
40
39
  if (typeof response === "object" && "data" in response && Array.isArray(response.data)) {
41
40
  return response.data.map((item) => item.embedding);
42
41
  }
43
- throw new InferenceOutputError(
44
- "Expected Sambanova feature-extraction (embeddings) response format to be {'data' : list of {'embedding' : number[]}}"
42
+ throw new InferenceClientProviderOutputError(
43
+ "Received malformed response from Sambanova feature-extraction (embeddings) API"
45
44
  );
46
45
  }
47
46
 
@@ -15,7 +15,6 @@
15
15
  * Thanks!
16
16
  */
17
17
  import type { ChatCompletionOutput, TextGenerationOutput, TextGenerationOutputFinishReason } from "@huggingface/tasks";
18
- import { InferenceOutputError } from "../lib/InferenceOutputError.js";
19
18
  import type { BodyParams } from "../types.js";
20
19
  import { omit } from "../utils/omit.js";
21
20
  import {
@@ -24,6 +23,7 @@ import {
24
23
  TaskProviderHelper,
25
24
  type TextToImageTaskHelper,
26
25
  } from "./providerHelper.js";
26
+ import { InferenceClientProviderOutputError } from "../errors.js";
27
27
 
28
28
  const TOGETHER_API_BASE_URL = "https://api.together.xyz";
29
29
 
@@ -74,7 +74,7 @@ export class TogetherTextGenerationTask extends BaseTextGenerationTask {
74
74
  generated_text: completion.text,
75
75
  };
76
76
  }
77
- throw new InferenceOutputError("Expected Together text generation response format");
77
+ throw new InferenceClientProviderOutputError("Received malformed response from Together text generation API");
78
78
  }
79
79
  }
80
80
 
@@ -113,6 +113,6 @@ export class TogetherTextToImageTask extends TaskProviderHelper implements TextT
113
113
  return fetch(`data:image/jpeg;base64,${base64Data}`).then((res) => res.blob());
114
114
  }
115
115
 
116
- throw new InferenceOutputError("Expected Together text-to-image response format");
116
+ throw new InferenceClientProviderOutputError("Received malformed response from Together text-to-image API");
117
117
  }
118
118
  }
@@ -1,10 +1,10 @@
1
1
  import type { AutomaticSpeechRecognitionInput, AutomaticSpeechRecognitionOutput } from "@huggingface/tasks";
2
2
  import { resolveProvider } from "../../lib/getInferenceProviderMapping.js";
3
3
  import { getProviderHelper } from "../../lib/getProviderHelper.js";
4
- import { InferenceOutputError } from "../../lib/InferenceOutputError.js";
5
4
  import type { BaseArgs, Options } from "../../types.js";
6
5
  import { innerRequest } from "../../utils/request.js";
7
6
  import type { LegacyAudioInput } from "./utils.js";
7
+ import { InferenceClientProviderOutputError } from "../../errors.js";
8
8
 
9
9
  export type AutomaticSpeechRecognitionArgs = BaseArgs & (AutomaticSpeechRecognitionInput | LegacyAudioInput);
10
10
  /**
@@ -24,7 +24,7 @@ export async function automaticSpeechRecognition(
24
24
  });
25
25
  const isValidOutput = typeof res?.text === "string";
26
26
  if (!isValidOutput) {
27
- throw new InferenceOutputError("Expected {text: string}");
27
+ throw new InferenceClientProviderOutputError("Received malformed response from automatic-speech-recognition API");
28
28
  }
29
29
  return providerHelper.getResponse(res);
30
30
  }
@@ -3,6 +3,8 @@ import { makeRequestOptions } from "../lib/makeRequestOptions.js";
3
3
  import type { InferenceTask, Options, RequestArgs } from "../types.js";
4
4
  import type { EventSourceMessage } from "../vendor/fetch-event-source/parse.js";
5
5
  import { getLines, getMessages } from "../vendor/fetch-event-source/parse.js";
6
+ import { InferenceClientProviderApiError } from "../errors.js";
7
+ import type { JsonObject } from "../vendor/type-fest/basic.js";
6
8
 
7
9
  export interface ResponseWrapper<T> {
8
10
  data: T;
@@ -12,6 +14,17 @@ export interface ResponseWrapper<T> {
12
14
  };
13
15
  }
14
16
 
17
+ function requestArgsToJson(args: RequestArgs): JsonObject {
18
+ // Convert the entire args object to a JSON-serializable format
19
+ const argsWithData = args as RequestArgs & { data?: Blob | ArrayBuffer };
20
+ return JSON.parse(
21
+ JSON.stringify({
22
+ ...argsWithData,
23
+ data: argsWithData.data ? "[Blob or ArrayBuffer]" : null,
24
+ })
25
+ ) as JsonObject;
26
+ }
27
+
15
28
  /**
16
29
  * Primitive to make custom calls to the inference provider
17
30
  */
@@ -39,18 +52,54 @@ export async function innerRequest<T>(
39
52
  if (["application/json", "application/problem+json"].some((ct) => contentType?.startsWith(ct))) {
40
53
  const output = await response.json();
41
54
  if ([400, 422, 404, 500].includes(response.status) && options?.chatCompletion) {
42
- throw new Error(
43
- `Server ${args.model} does not seem to support chat completion. Error: ${JSON.stringify(output.error)}`
55
+ throw new InferenceClientProviderApiError(
56
+ `Provider ${args.provider} does not seem to support chat completion for model ${
57
+ args.model
58
+ } . Error: ${JSON.stringify(output.error)}`,
59
+ {
60
+ url,
61
+ method: info.method ?? "GET",
62
+ headers: info.headers as Record<string, string>,
63
+ body: requestArgsToJson(args),
64
+ },
65
+ { requestId: response.headers.get("x-request-id") ?? "", status: response.status, body: output }
44
66
  );
45
67
  }
46
- if (output.error || output.detail) {
47
- throw new Error(JSON.stringify(output.error ?? output.detail));
68
+ if (typeof output.error === "string" || typeof output.detail === "string") {
69
+ throw new InferenceClientProviderApiError(
70
+ `Failed to perform inference: ${output.error ?? output.detail}`,
71
+ {
72
+ url,
73
+ method: info.method ?? "GET",
74
+ headers: info.headers as Record<string, string>,
75
+ body: requestArgsToJson(args),
76
+ },
77
+ { requestId: response.headers.get("x-request-id") ?? "", status: response.status, body: output }
78
+ );
48
79
  } else {
49
- throw new Error(output);
80
+ throw new InferenceClientProviderApiError(
81
+ `Failed to perform inference: an HTTP error occurred when requesting the provider.`,
82
+ {
83
+ url,
84
+ method: info.method ?? "GET",
85
+ headers: info.headers as Record<string, string>,
86
+ body: requestArgsToJson(args),
87
+ },
88
+ { requestId: response.headers.get("x-request-id") ?? "", status: response.status, body: output }
89
+ );
50
90
  }
51
91
  }
52
92
  const message = contentType?.startsWith("text/plain;") ? await response.text() : undefined;
53
- throw new Error(message ?? "An error occurred while fetching the blob");
93
+ throw new InferenceClientProviderApiError(
94
+ `Failed to perform inference: ${message ?? "an HTTP error occurred when requesting the provider"}`,
95
+ {
96
+ url,
97
+ method: info.method ?? "GET",
98
+ headers: info.headers as Record<string, string>,
99
+ body: requestArgsToJson(args),
100
+ },
101
+ { requestId: response.headers.get("x-request-id") ?? "", status: response.status, body: message ?? "" }
102
+ );
54
103
  }
55
104
 
56
105
  if (response.headers.get("Content-Type")?.startsWith("application/json")) {
@@ -85,26 +134,81 @@ export async function* innerStreamingRequest<T>(
85
134
  if (response.headers.get("Content-Type")?.startsWith("application/json")) {
86
135
  const output = await response.json();
87
136
  if ([400, 422, 404, 500].includes(response.status) && options?.chatCompletion) {
88
- throw new Error(`Server ${args.model} does not seem to support chat completion. Error: ${output.error}`);
137
+ throw new InferenceClientProviderApiError(
138
+ `Provider ${args.provider} does not seem to support chat completion for model ${
139
+ args.model
140
+ } . Error: ${JSON.stringify(output.error)}`,
141
+ {
142
+ url,
143
+ method: info.method ?? "GET",
144
+ headers: info.headers as Record<string, string>,
145
+ body: requestArgsToJson(args),
146
+ },
147
+ { requestId: response.headers.get("x-request-id") ?? "", status: response.status, body: output }
148
+ );
89
149
  }
90
150
  if (typeof output.error === "string") {
91
- throw new Error(output.error);
151
+ throw new InferenceClientProviderApiError(
152
+ `Failed to perform inference: ${output.error}`,
153
+ {
154
+ url,
155
+ method: info.method ?? "GET",
156
+ headers: info.headers as Record<string, string>,
157
+ body: requestArgsToJson(args),
158
+ },
159
+ { requestId: response.headers.get("x-request-id") ?? "", status: response.status, body: output }
160
+ );
92
161
  }
93
162
  if (output.error && "message" in output.error && typeof output.error.message === "string") {
94
163
  /// OpenAI errors
95
- throw new Error(output.error.message);
164
+ throw new InferenceClientProviderApiError(
165
+ `Failed to perform inference: ${output.error.message}`,
166
+ {
167
+ url,
168
+ method: info.method ?? "GET",
169
+ headers: info.headers as Record<string, string>,
170
+ body: requestArgsToJson(args),
171
+ },
172
+ { requestId: response.headers.get("x-request-id") ?? "", status: response.status, body: output }
173
+ );
96
174
  }
97
175
  // Sambanova errors
98
176
  if (typeof output.message === "string") {
99
- throw new Error(output.message);
177
+ throw new InferenceClientProviderApiError(
178
+ `Failed to perform inference: ${output.message}`,
179
+ {
180
+ url,
181
+ method: info.method ?? "GET",
182
+ headers: info.headers as Record<string, string>,
183
+ body: requestArgsToJson(args),
184
+ },
185
+ { requestId: response.headers.get("x-request-id") ?? "", status: response.status, body: output }
186
+ );
100
187
  }
101
188
  }
102
189
 
103
- throw new Error(`Server response contains error: ${response.status}`);
190
+ throw new InferenceClientProviderApiError(
191
+ `Failed to perform inference: an HTTP error occurred when requesting the provider.`,
192
+ {
193
+ url,
194
+ method: info.method ?? "GET",
195
+ headers: info.headers as Record<string, string>,
196
+ body: requestArgsToJson(args),
197
+ },
198
+ { requestId: response.headers.get("x-request-id") ?? "", status: response.status, body: "" }
199
+ );
104
200
  }
105
201
  if (!response.headers.get("content-type")?.startsWith("text/event-stream")) {
106
- throw new Error(
107
- `Server does not support event stream content type, it returned ` + response.headers.get("content-type")
202
+ throw new InferenceClientProviderApiError(
203
+ `Failed to perform inference: server does not support event stream content type, it returned ` +
204
+ response.headers.get("content-type"),
205
+ {
206
+ url,
207
+ method: info.method ?? "GET",
208
+ headers: info.headers as Record<string, string>,
209
+ body: requestArgsToJson(args),
210
+ },
211
+ { requestId: response.headers.get("x-request-id") ?? "", status: response.status, body: "" }
108
212
  );
109
213
  }
110
214
 
@@ -151,7 +255,16 @@ export async function* innerStreamingRequest<T>(
151
255
  typeof data.error.message === "string"
152
256
  ? data.error.message
153
257
  : JSON.stringify(data.error);
154
- throw new Error(`Error forwarded from backend: ` + errorStr);
258
+ throw new InferenceClientProviderApiError(
259
+ `Failed to perform inference: an occurred while streaming the response: ${errorStr}`,
260
+ {
261
+ url,
262
+ method: info.method ?? "GET",
263
+ headers: info.headers as Record<string, string>,
264
+ body: requestArgsToJson(args),
265
+ },
266
+ { requestId: response.headers.get("x-request-id") ?? "", status: response.status, body: data }
267
+ );
155
268
  }
156
269
  yield data as T;
157
270
  }
@@ -0,0 +1,31 @@
1
+ /**
2
+ Matches a JSON object.
3
+
4
+ This type can be useful to enforce some input to be JSON-compatible or as a super-type to be extended from. Don't use this as a direct return type as the user would have to double-cast it: `jsonObject as unknown as CustomResponse`. Instead, you could extend your CustomResponse type from it to ensure your type only uses JSON-compatible types: `interface CustomResponse extends JsonObject { … }`.
5
+
6
+ @category JSON
7
+ */
8
+ export type JsonObject = { [Key in string]: JsonValue } & { [Key in string]?: JsonValue | undefined };
9
+
10
+ /**
11
+ Matches a JSON array.
12
+
13
+ @category JSON
14
+ */
15
+ export type JsonArray = JsonValue[] | readonly JsonValue[];
16
+
17
+ /**
18
+ Matches any valid JSON primitive value.
19
+
20
+ @category JSON
21
+ */
22
+ export type JsonPrimitive = string | number | boolean | null;
23
+
24
+ /**
25
+ Matches any valid JSON value.
26
+
27
+ @see `Jsonify` if you need to transform a type to one that is assignable to `JsonValue`.
28
+
29
+ @category JSON
30
+ */
31
+ export type JsonValue = JsonPrimitive | JsonObject | JsonArray;
@@ -0,0 +1,121 @@
1
+ Creative Commons Legal Code
2
+
3
+ CC0 1.0 Universal
4
+
5
+ CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE
6
+ LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN
7
+ ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS
8
+ INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES
9
+ REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS
10
+ PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM
11
+ THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED
12
+ HEREUNDER.
13
+
14
+ Statement of Purpose
15
+
16
+ The laws of most jurisdictions throughout the world automatically confer
17
+ exclusive Copyright and Related Rights (defined below) upon the creator
18
+ and subsequent owner(s) (each and all, an "owner") of an original work of
19
+ authorship and/or a database (each, a "Work").
20
+
21
+ Certain owners wish to permanently relinquish those rights to a Work for
22
+ the purpose of contributing to a commons of creative, cultural and
23
+ scientific works ("Commons") that the public can reliably and without fear
24
+ of later claims of infringement build upon, modify, incorporate in other
25
+ works, reuse and redistribute as freely as possible in any form whatsoever
26
+ and for any purposes, including without limitation commercial purposes.
27
+ These owners may contribute to the Commons to promote the ideal of a free
28
+ culture and the further production of creative, cultural and scientific
29
+ works, or to gain reputation or greater distribution for their Work in
30
+ part through the use and efforts of others.
31
+
32
+ For these and/or other purposes and motivations, and without any
33
+ expectation of additional consideration or compensation, the person
34
+ associating CC0 with a Work (the "Affirmer"), to the extent that he or she
35
+ is an owner of Copyright and Related Rights in the Work, voluntarily
36
+ elects to apply CC0 to the Work and publicly distribute the Work under its
37
+ terms, with knowledge of his or her Copyright and Related Rights in the
38
+ Work and the meaning and intended legal effect of CC0 on those rights.
39
+
40
+ 1. Copyright and Related Rights. A Work made available under CC0 may be
41
+ protected by copyright and related or neighboring rights ("Copyright and
42
+ Related Rights"). Copyright and Related Rights include, but are not
43
+ limited to, the following:
44
+
45
+ i. the right to reproduce, adapt, distribute, perform, display,
46
+ communicate, and translate a Work;
47
+ ii. moral rights retained by the original author(s) and/or performer(s);
48
+ iii. publicity and privacy rights pertaining to a person's image or
49
+ likeness depicted in a Work;
50
+ iv. rights protecting against unfair competition in regards to a Work,
51
+ subject to the limitations in paragraph 4(a), below;
52
+ v. rights protecting the extraction, dissemination, use and reuse of data
53
+ in a Work;
54
+ vi. database rights (such as those arising under Directive 96/9/EC of the
55
+ European Parliament and of the Council of 11 March 1996 on the legal
56
+ protection of databases, and under any national implementation
57
+ thereof, including any amended or successor version of such
58
+ directive); and
59
+ vii. other similar, equivalent or corresponding rights throughout the
60
+ world based on applicable law or treaty, and any national
61
+ implementations thereof.
62
+
63
+ 2. Waiver. To the greatest extent permitted by, but not in contravention
64
+ of, applicable law, Affirmer hereby overtly, fully, permanently,
65
+ irrevocably and unconditionally waives, abandons, and surrenders all of
66
+ Affirmer's Copyright and Related Rights and associated claims and causes
67
+ of action, whether now known or unknown (including existing as well as
68
+ future claims and causes of action), in the Work (i) in all territories
69
+ worldwide, (ii) for the maximum duration provided by applicable law or
70
+ treaty (including future time extensions), (iii) in any current or future
71
+ medium and for any number of copies, and (iv) for any purpose whatsoever,
72
+ including without limitation commercial, advertising or promotional
73
+ purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each
74
+ member of the public at large and to the detriment of Affirmer's heirs and
75
+ successors, fully intending that such Waiver shall not be subject to
76
+ revocation, rescission, cancellation, termination, or any other legal or
77
+ equitable action to disrupt the quiet enjoyment of the Work by the public
78
+ as contemplated by Affirmer's express Statement of Purpose.
79
+
80
+ 3. Public License Fallback. Should any part of the Waiver for any reason
81
+ be judged legally invalid or ineffective under applicable law, then the
82
+ Waiver shall be preserved to the maximum extent permitted taking into
83
+ account Affirmer's express Statement of Purpose. In addition, to the
84
+ extent the Waiver is so judged Affirmer hereby grants to each affected
85
+ person a royalty-free, non transferable, non sublicensable, non exclusive,
86
+ irrevocable and unconditional license to exercise Affirmer's Copyright and
87
+ Related Rights in the Work (i) in all territories worldwide, (ii) for the
88
+ maximum duration provided by applicable law or treaty (including future
89
+ time extensions), (iii) in any current or future medium and for any number
90
+ of copies, and (iv) for any purpose whatsoever, including without
91
+ limitation commercial, advertising or promotional purposes (the
92
+ "License"). The License shall be deemed effective as of the date CC0 was
93
+ applied by Affirmer to the Work. Should any part of the License for any
94
+ reason be judged legally invalid or ineffective under applicable law, such
95
+ partial invalidity or ineffectiveness shall not invalidate the remainder
96
+ of the License, and in such case Affirmer hereby affirms that he or she
97
+ will not (i) exercise any of his or her remaining Copyright and Related
98
+ Rights in the Work or (ii) assert any associated claims and causes of
99
+ action with respect to the Work, in either case contrary to Affirmer's
100
+ express Statement of Purpose.
101
+
102
+ 4. Limitations and Disclaimers.
103
+
104
+ a. No trademark or patent rights held by Affirmer are waived, abandoned,
105
+ surrendered, licensed or otherwise affected by this document.
106
+ b. Affirmer offers the Work as-is and makes no representations or
107
+ warranties of any kind concerning the Work, express, implied,
108
+ statutory or otherwise, including without limitation warranties of
109
+ title, merchantability, fitness for a particular purpose, non
110
+ infringement, or the absence of latent or other defects, accuracy, or
111
+ the present or absence of errors, whether or not discoverable, all to
112
+ the greatest extent permissible under applicable law.
113
+ c. Affirmer disclaims responsibility for clearing rights of other persons
114
+ that may apply to the Work or any use thereof, including without
115
+ limitation any person's Copyright and Related Rights in the Work.
116
+ Further, Affirmer disclaims responsibility for obtaining any necessary
117
+ consents, permissions or other rights required for any use of the
118
+ Work.
119
+ d. Affirmer understands and acknowledges that Creative Commons is not a
120
+ party to this document and has no duty or obligation with respect to
121
+ this CC0 or use of the Work.
@@ -0,0 +1,9 @@
1
+ MIT License
2
+
3
+ Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,4 +0,0 @@
1
- export declare class InferenceOutputError extends TypeError {
2
- constructor(message: string);
3
- }
4
- //# sourceMappingURL=InferenceOutputError.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"InferenceOutputError.d.ts","sourceRoot":"","sources":["../../../src/lib/InferenceOutputError.ts"],"names":[],"mappings":"AAAA,qBAAa,oBAAqB,SAAQ,SAAS;gBACtC,OAAO,EAAE,MAAM;CAM3B"}
@@ -1,10 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.InferenceOutputError = void 0;
4
- class InferenceOutputError extends TypeError {
5
- constructor(message) {
6
- super(`Invalid inference output: ${message}. Use the 'request' method with the same parameters to do a custom call with no type checking.`);
7
- this.name = "InferenceOutputError";
8
- }
9
- }
10
- exports.InferenceOutputError = InferenceOutputError;
@@ -1,4 +0,0 @@
1
- export declare class InferenceOutputError extends TypeError {
2
- constructor(message: string);
3
- }
4
- //# sourceMappingURL=InferenceOutputError.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"InferenceOutputError.d.ts","sourceRoot":"","sources":["../../../src/lib/InferenceOutputError.ts"],"names":[],"mappings":"AAAA,qBAAa,oBAAqB,SAAQ,SAAS;gBACtC,OAAO,EAAE,MAAM;CAM3B"}
@@ -1,6 +0,0 @@
1
- export class InferenceOutputError extends TypeError {
2
- constructor(message) {
3
- super(`Invalid inference output: ${message}. Use the 'request' method with the same parameters to do a custom call with no type checking.`);
4
- this.name = "InferenceOutputError";
5
- }
6
- }
@@ -1,8 +0,0 @@
1
- export class InferenceOutputError extends TypeError {
2
- constructor(message: string) {
3
- super(
4
- `Invalid inference output: ${message}. Use the 'request' method with the same parameters to do a custom call with no type checking.`
5
- );
6
- this.name = "InferenceOutputError";
7
- }
8
- }