hume 0.5.17 → 0.6.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 (71) hide show
  1. package/Client.d.ts +4 -3
  2. package/Client.js +6 -6
  3. package/api/resources/customModels/client/Client.d.ts +1 -0
  4. package/api/resources/customModels/resources/datasets/client/Client.d.ts +1 -0
  5. package/api/resources/customModels/resources/datasets/client/Client.js +38 -30
  6. package/api/resources/customModels/resources/files/client/Client.d.ts +1 -0
  7. package/api/resources/customModels/resources/files/client/Client.js +26 -20
  8. package/api/resources/customModels/resources/jobs/client/Client.d.ts +1 -0
  9. package/api/resources/customModels/resources/jobs/client/Client.js +6 -4
  10. package/api/resources/customModels/resources/models/client/Client.d.ts +1 -0
  11. package/api/resources/customModels/resources/models/client/Client.js +18 -12
  12. package/api/resources/empathicVoice/client/Client.d.ts +1 -0
  13. package/api/resources/empathicVoice/resources/chats/client/Client.d.ts +1 -0
  14. package/api/resources/empathicVoice/resources/chats/client/Client.js +6 -4
  15. package/api/resources/empathicVoice/resources/configs/client/Client.d.ts +1 -0
  16. package/api/resources/empathicVoice/resources/configs/client/Client.js +27 -18
  17. package/api/resources/empathicVoice/resources/prompts/client/Client.d.ts +1 -0
  18. package/api/resources/empathicVoice/resources/prompts/client/Client.js +27 -18
  19. package/api/resources/empathicVoice/resources/tools/client/Client.d.ts +1 -0
  20. package/api/resources/empathicVoice/resources/tools/client/Client.js +27 -18
  21. package/api/resources/expressionMeasurement/client/Client.d.ts +1 -0
  22. package/api/resources/expressionMeasurement/resources/batch/client/Client.d.ts +1 -0
  23. package/api/resources/expressionMeasurement/resources/batch/client/Client.js +17 -12
  24. package/api/resources/index.d.ts +1 -1
  25. package/api/resources/index.js +2 -2
  26. package/core/fetcher/Fetcher.d.ts +1 -0
  27. package/core/fetcher/Fetcher.js +106 -20
  28. package/core/form-data-utils/FormDataWrapper.d.ts +24 -0
  29. package/core/form-data-utils/FormDataWrapper.js +105 -0
  30. package/core/form-data-utils/index.d.ts +1 -0
  31. package/core/form-data-utils/index.js +17 -0
  32. package/core/index.d.ts +1 -0
  33. package/core/index.js +1 -0
  34. package/dist/Client.d.ts +4 -3
  35. package/dist/Client.js +6 -6
  36. package/dist/api/resources/customModels/client/Client.d.ts +1 -0
  37. package/dist/api/resources/customModels/resources/datasets/client/Client.d.ts +1 -0
  38. package/dist/api/resources/customModels/resources/datasets/client/Client.js +38 -30
  39. package/dist/api/resources/customModels/resources/files/client/Client.d.ts +1 -0
  40. package/dist/api/resources/customModels/resources/files/client/Client.js +26 -20
  41. package/dist/api/resources/customModels/resources/jobs/client/Client.d.ts +1 -0
  42. package/dist/api/resources/customModels/resources/jobs/client/Client.js +6 -4
  43. package/dist/api/resources/customModels/resources/models/client/Client.d.ts +1 -0
  44. package/dist/api/resources/customModels/resources/models/client/Client.js +18 -12
  45. package/dist/api/resources/empathicVoice/client/Client.d.ts +1 -0
  46. package/dist/api/resources/empathicVoice/resources/chats/client/Client.d.ts +1 -0
  47. package/dist/api/resources/empathicVoice/resources/chats/client/Client.js +6 -4
  48. package/dist/api/resources/empathicVoice/resources/configs/client/Client.d.ts +1 -0
  49. package/dist/api/resources/empathicVoice/resources/configs/client/Client.js +27 -18
  50. package/dist/api/resources/empathicVoice/resources/prompts/client/Client.d.ts +1 -0
  51. package/dist/api/resources/empathicVoice/resources/prompts/client/Client.js +27 -18
  52. package/dist/api/resources/empathicVoice/resources/tools/client/Client.d.ts +1 -0
  53. package/dist/api/resources/empathicVoice/resources/tools/client/Client.js +27 -18
  54. package/dist/api/resources/expressionMeasurement/client/Client.d.ts +1 -0
  55. package/dist/api/resources/expressionMeasurement/resources/batch/client/Client.d.ts +1 -0
  56. package/dist/api/resources/expressionMeasurement/resources/batch/client/Client.js +17 -12
  57. package/dist/api/resources/index.d.ts +1 -1
  58. package/dist/api/resources/index.js +2 -2
  59. package/dist/core/fetcher/Fetcher.d.ts +1 -0
  60. package/dist/core/fetcher/Fetcher.js +106 -20
  61. package/dist/core/form-data-utils/FormDataWrapper.d.ts +24 -0
  62. package/dist/core/form-data-utils/FormDataWrapper.js +105 -0
  63. package/dist/core/form-data-utils/index.d.ts +1 -0
  64. package/dist/core/form-data-utils/index.js +17 -0
  65. package/dist/core/index.d.ts +1 -0
  66. package/dist/core/index.js +1 -0
  67. package/dist/serialization/resources/index.d.ts +1 -1
  68. package/dist/serialization/resources/index.js +2 -2
  69. package/package.json +3 -1
  70. package/serialization/resources/index.d.ts +1 -1
  71. package/serialization/resources/index.js +2 -2
@@ -44,7 +44,6 @@ const core = __importStar(require("../../../../../../core"));
44
44
  const url_join_1 = __importDefault(require("url-join"));
45
45
  const serializers = __importStar(require("../../../../../../serialization/index"));
46
46
  const errors = __importStar(require("../../../../../../errors/index"));
47
- const form_data_1 = __importDefault(require("form-data"));
48
47
  class Batch {
49
48
  constructor(_options = {}) {
50
49
  this._options = _options;
@@ -97,11 +96,12 @@ class Batch {
97
96
  const _response = yield ((_a = this._options.fetcher) !== null && _a !== void 0 ? _a : core.fetcher)({
98
97
  url: (0, url_join_1.default)((_b = (yield core.Supplier.get(this._options.environment))) !== null && _b !== void 0 ? _b : environments.HumeEnvironment.Production, "v0/batch/jobs"),
99
98
  method: "GET",
100
- headers: Object.assign({ "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "hume", "X-Fern-SDK-Version": "0.5.17", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version }, (yield this._getCustomAuthorizationHeaders())),
99
+ headers: Object.assign({ "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "hume", "X-Fern-SDK-Version": "0.6.0", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version }, (yield this._getCustomAuthorizationHeaders())),
101
100
  contentType: "application/json",
102
101
  queryParameters: _queryParams,
103
102
  timeoutMs: (requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
104
103
  maxRetries: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries,
104
+ abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
105
105
  });
106
106
  if (_response.ok) {
107
107
  return yield serializers.expressionMeasurement.batch.listJobs.Response.parseOrThrow(_response.body, {
@@ -151,13 +151,14 @@ class Batch {
151
151
  const _response = yield ((_a = this._options.fetcher) !== null && _a !== void 0 ? _a : core.fetcher)({
152
152
  url: (0, url_join_1.default)((_b = (yield core.Supplier.get(this._options.environment))) !== null && _b !== void 0 ? _b : environments.HumeEnvironment.Production, "v0/batch/jobs"),
153
153
  method: "POST",
154
- headers: Object.assign({ "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "hume", "X-Fern-SDK-Version": "0.5.17", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version }, (yield this._getCustomAuthorizationHeaders())),
154
+ headers: Object.assign({ "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "hume", "X-Fern-SDK-Version": "0.6.0", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version }, (yield this._getCustomAuthorizationHeaders())),
155
155
  contentType: "application/json",
156
156
  body: yield serializers.expressionMeasurement.InferenceBaseRequest.jsonOrThrow(request, {
157
157
  unrecognizedObjectKeys: "strip",
158
158
  }),
159
159
  timeoutMs: (requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
160
160
  maxRetries: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries,
161
+ abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
161
162
  });
162
163
  if (_response.ok) {
163
164
  return yield serializers.expressionMeasurement.JobId.parseOrThrow(_response.body, {
@@ -204,10 +205,11 @@ class Batch {
204
205
  const _response = yield ((_a = this._options.fetcher) !== null && _a !== void 0 ? _a : core.fetcher)({
205
206
  url: (0, url_join_1.default)((_b = (yield core.Supplier.get(this._options.environment))) !== null && _b !== void 0 ? _b : environments.HumeEnvironment.Production, `v0/batch/jobs/${encodeURIComponent(id)}`),
206
207
  method: "GET",
207
- headers: Object.assign({ "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "hume", "X-Fern-SDK-Version": "0.5.17", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version }, (yield this._getCustomAuthorizationHeaders())),
208
+ headers: Object.assign({ "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "hume", "X-Fern-SDK-Version": "0.6.0", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version }, (yield this._getCustomAuthorizationHeaders())),
208
209
  contentType: "application/json",
209
210
  timeoutMs: (requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
210
211
  maxRetries: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries,
212
+ abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
211
213
  });
212
214
  if (_response.ok) {
213
215
  return yield serializers.expressionMeasurement.UnionJob.parseOrThrow(_response.body, {
@@ -254,10 +256,11 @@ class Batch {
254
256
  const _response = yield ((_a = this._options.fetcher) !== null && _a !== void 0 ? _a : core.fetcher)({
255
257
  url: (0, url_join_1.default)((_b = (yield core.Supplier.get(this._options.environment))) !== null && _b !== void 0 ? _b : environments.HumeEnvironment.Production, `v0/batch/jobs/${encodeURIComponent(id)}/predictions`),
256
258
  method: "GET",
257
- headers: Object.assign({ "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "hume", "X-Fern-SDK-Version": "0.5.17", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version }, (yield this._getCustomAuthorizationHeaders())),
259
+ headers: Object.assign({ "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "hume", "X-Fern-SDK-Version": "0.6.0", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version }, (yield this._getCustomAuthorizationHeaders())),
258
260
  contentType: "application/json",
259
261
  timeoutMs: (requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
260
262
  maxRetries: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries,
263
+ abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
261
264
  });
262
265
  if (_response.ok) {
263
266
  return yield serializers.expressionMeasurement.batch.getJobPredictions.Response.parseOrThrow(_response.body, {
@@ -298,11 +301,12 @@ class Batch {
298
301
  const _response = yield ((_a = this._options.fetcher) !== null && _a !== void 0 ? _a : core.fetcher)({
299
302
  url: (0, url_join_1.default)((_b = (yield core.Supplier.get(this._options.environment))) !== null && _b !== void 0 ? _b : environments.HumeEnvironment.Production, `v0/batch/jobs/${encodeURIComponent(id)}/artifacts`),
300
303
  method: "GET",
301
- headers: Object.assign({ "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "hume", "X-Fern-SDK-Version": "0.5.17", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version }, (yield this._getCustomAuthorizationHeaders())),
304
+ headers: Object.assign({ "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "hume", "X-Fern-SDK-Version": "0.6.0", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version }, (yield this._getCustomAuthorizationHeaders())),
302
305
  contentType: "application/json",
303
306
  responseType: "streaming",
304
307
  timeoutMs: (requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
305
308
  maxRetries: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries,
309
+ abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
306
310
  });
307
311
  if (_response.ok) {
308
312
  return _response.body;
@@ -341,21 +345,22 @@ class Batch {
341
345
  startInferenceJobFromLocalFile(file, request, requestOptions) {
342
346
  var _a, _b;
343
347
  return __awaiter(this, void 0, void 0, function* () {
344
- const _request = new form_data_1.default();
348
+ const _request = new core.FormDataWrapper();
345
349
  if (request.json != null) {
346
- _request.append("json", JSON.stringify(request.json));
350
+ yield _request.append("json", JSON.stringify(request.json));
347
351
  }
348
352
  for (const _file of file) {
349
- _request.append("file", _file);
353
+ yield _request.append("file", _file);
350
354
  }
355
+ const _maybeEncodedRequest = _request.getRequest();
351
356
  const _response = yield ((_a = this._options.fetcher) !== null && _a !== void 0 ? _a : core.fetcher)({
352
357
  url: (0, url_join_1.default)((_b = (yield core.Supplier.get(this._options.environment))) !== null && _b !== void 0 ? _b : environments.HumeEnvironment.Production, "v0/batch/jobs"),
353
358
  method: "POST",
354
- headers: Object.assign({ "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "hume", "X-Fern-SDK-Version": "0.5.17", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version }, (yield this._getCustomAuthorizationHeaders())),
355
- contentType: "multipart/form-data; boundary=" + _request.getBoundary(),
356
- body: _request,
359
+ headers: Object.assign(Object.assign({ "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "hume", "X-Fern-SDK-Version": "0.6.0", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version }, (yield this._getCustomAuthorizationHeaders())), (yield _maybeEncodedRequest.getHeaders())),
360
+ body: yield _maybeEncodedRequest.getBody(),
357
361
  timeoutMs: (requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
358
362
  maxRetries: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries,
363
+ abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
359
364
  });
360
365
  if (_response.ok) {
361
366
  return yield serializers.expressionMeasurement.JobId.parseOrThrow(_response.body, {
@@ -1,3 +1,3 @@
1
- export * as customModels from "./customModels";
2
1
  export * as empathicVoice from "./empathicVoice";
2
+ export * as customModels from "./customModels";
3
3
  export * as expressionMeasurement from "./expressionMeasurement";
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.expressionMeasurement = exports.empathicVoice = exports.customModels = void 0;
27
- exports.customModels = __importStar(require("./customModels"));
26
+ exports.expressionMeasurement = exports.customModels = exports.empathicVoice = void 0;
28
27
  exports.empathicVoice = __importStar(require("./empathicVoice"));
28
+ exports.customModels = __importStar(require("./customModels"));
29
29
  exports.expressionMeasurement = __importStar(require("./expressionMeasurement"));
@@ -11,6 +11,7 @@ export declare namespace Fetcher {
11
11
  timeoutMs?: number;
12
12
  maxRetries?: number;
13
13
  withCredentials?: boolean;
14
+ abortSignal?: AbortSignal;
14
15
  responseType?: "json" | "blob" | "streaming" | "text";
15
16
  }
16
17
  type Error = FailedStatusCodeError | NonJsonError | TimeoutError | UnknownError;
@@ -1,4 +1,27 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
26
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
27
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -13,7 +36,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
13
36
  };
14
37
  Object.defineProperty(exports, "__esModule", { value: true });
15
38
  exports.fetcher = void 0;
16
- const form_data_1 = __importDefault(require("form-data"));
17
39
  const qs_1 = __importDefault(require("qs"));
18
40
  const runtime_1 = require("../runtime");
19
41
  const INITIAL_RETRY_DELAY = 1;
@@ -37,18 +59,34 @@ function fetcherImpl(args) {
37
59
  ? `${args.url}?${qs_1.default.stringify(args.queryParameters, { arrayFormat: "repeat" })}`
38
60
  : args.url;
39
61
  let body = undefined;
40
- if (args.body instanceof form_data_1.default) {
41
- // @ts-expect-error
42
- body = args.body;
43
- }
44
- else if (args.body instanceof Uint8Array) {
45
- body = args.body;
46
- }
47
- else if (args.contentType === "application/x-www-form-urlencoded" && typeof args.body === "string") {
48
- body = args.body;
62
+ const maybeStringifyBody = (body) => {
63
+ if (body instanceof Uint8Array) {
64
+ return body;
65
+ }
66
+ else if (args.contentType === "application/x-www-form-urlencoded" && typeof args.body === "string") {
67
+ return args.body;
68
+ }
69
+ else {
70
+ return JSON.stringify(body);
71
+ }
72
+ };
73
+ if (runtime_1.RUNTIME.type === "node") {
74
+ if (args.body instanceof (yield Promise.resolve().then(() => __importStar(require("formdata-node")))).FormData) {
75
+ // @ts-expect-error
76
+ body = args.body;
77
+ }
78
+ else {
79
+ body = maybeStringifyBody(args.body);
80
+ }
49
81
  }
50
82
  else {
51
- body = JSON.stringify(args.body);
83
+ if (args.body instanceof (yield Promise.resolve().then(() => __importStar(require("form-data")))).default) {
84
+ // @ts-expect-error
85
+ body = args.body;
86
+ }
87
+ else {
88
+ body = maybeStringifyBody(args.body);
89
+ }
52
90
  }
53
91
  // In Node.js environments, the SDK always uses`node-fetch`.
54
92
  // If not in Node.js the SDK uses global fetch if available,
@@ -56,25 +94,32 @@ function fetcherImpl(args) {
56
94
  const fetchFn = runtime_1.RUNTIME.type === "node"
57
95
  ? // `.default` is required due to this issue:
58
96
  // https://github.com/node-fetch/node-fetch/issues/450#issuecomment-387045223
59
- require("node-fetch").default
97
+ (yield Promise.resolve().then(() => __importStar(require("node-fetch")))).default
60
98
  : typeof fetch == "function"
61
99
  ? fetch
62
- : require("node-fetch").default;
100
+ : (yield Promise.resolve().then(() => __importStar(require("node-fetch")))).default;
63
101
  const makeRequest = () => __awaiter(this, void 0, void 0, function* () {
64
- const controller = new AbortController();
65
- let abortId = undefined;
102
+ const signals = [];
103
+ // Add timeout signal
104
+ let timeoutAbortId = undefined;
66
105
  if (args.timeoutMs != null) {
67
- abortId = setTimeout(() => controller.abort(), args.timeoutMs);
106
+ const { signal, abortId } = getTimeoutSignal(args.timeoutMs);
107
+ timeoutAbortId = abortId;
108
+ signals.push(signal);
109
+ }
110
+ // Add arbitrary signal
111
+ if (args.abortSignal != null) {
112
+ signals.push(args.abortSignal);
68
113
  }
69
114
  const response = yield fetchFn(url, {
70
115
  method: args.method,
71
116
  headers,
72
117
  body,
73
- signal: controller.signal,
118
+ signal: anySignal(signals),
74
119
  credentials: args.withCredentials ? "include" : undefined,
75
120
  });
76
- if (abortId != null) {
77
- clearTimeout(abortId);
121
+ if (timeoutAbortId != null) {
122
+ clearTimeout(timeoutAbortId);
78
123
  }
79
124
  return response;
80
125
  });
@@ -140,7 +185,16 @@ function fetcherImpl(args) {
140
185
  }
141
186
  }
142
187
  catch (error) {
143
- if (error instanceof Error && error.name === "AbortError") {
188
+ if (args.abortSignal != null && args.abortSignal.aborted) {
189
+ return {
190
+ ok: false,
191
+ error: {
192
+ reason: "unknown",
193
+ errorMessage: "The user aborted a request",
194
+ },
195
+ };
196
+ }
197
+ else if (error instanceof Error && error.name === "AbortError") {
144
198
  return {
145
199
  ok: false,
146
200
  error: {
@@ -167,4 +221,36 @@ function fetcherImpl(args) {
167
221
  }
168
222
  });
169
223
  }
224
+ const TIMEOUT = "timeout";
225
+ function getTimeoutSignal(timeoutMs) {
226
+ const controller = new AbortController();
227
+ const abortId = setTimeout(() => controller.abort(TIMEOUT), timeoutMs);
228
+ return { signal: controller.signal, abortId };
229
+ }
230
+ /**
231
+ * Returns an abort signal that is getting aborted when
232
+ * at least one of the specified abort signals is aborted.
233
+ *
234
+ * Requires at least node.js 18.
235
+ */
236
+ function anySignal(...args) {
237
+ // Allowing signals to be passed either as array
238
+ // of signals or as multiple arguments.
239
+ const signals = (args.length === 1 && Array.isArray(args[0]) ? args[0] : args);
240
+ const controller = new AbortController();
241
+ for (const signal of signals) {
242
+ if (signal.aborted) {
243
+ // Exiting early if one of the signals
244
+ // is already aborted.
245
+ controller.abort(signal === null || signal === void 0 ? void 0 : signal.reason);
246
+ break;
247
+ }
248
+ // Listening for signals and removing the listeners
249
+ // when at least one symbol is aborted.
250
+ signal.addEventListener("abort", () => controller.abort(signal === null || signal === void 0 ? void 0 : signal.reason), {
251
+ signal: controller.signal,
252
+ });
253
+ }
254
+ return controller.signal;
255
+ }
170
256
  exports.fetcher = fetcherImpl;
@@ -0,0 +1,24 @@
1
+ declare class FormDataRequestBody {
2
+ private fd;
3
+ private encoder;
4
+ constructor(fd: any);
5
+ setup(): Promise<void>;
6
+ /**
7
+ * @returns the multipart form data request
8
+ */
9
+ getBody(): Promise<any>;
10
+ /**
11
+ * @returns headers that need to be added to the multipart form data request
12
+ */
13
+ getHeaders(): Promise<Record<string, string>>;
14
+ }
15
+ /**
16
+ * FormDataWrapper is a utility to make form data
17
+ * requests across both Browser and Node.js runtimes.
18
+ */
19
+ export declare class FormDataWrapper {
20
+ private fd;
21
+ append(name: string, value: any): Promise<void>;
22
+ getRequest(): FormDataRequestBody;
23
+ }
24
+ export {};
@@ -0,0 +1,105 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ Object.defineProperty(exports, "__esModule", { value: true });
35
+ exports.FormDataWrapper = void 0;
36
+ const runtime_1 = require("../runtime");
37
+ class FormDataRequestBody {
38
+ constructor(fd) {
39
+ this.fd = fd;
40
+ }
41
+ setup() {
42
+ return __awaiter(this, void 0, void 0, function* () {
43
+ if (this.encoder == null && runtime_1.RUNTIME.type === "node") {
44
+ this.encoder = new (yield Promise.resolve().then(() => __importStar(require("form-data-encoder")))).FormDataEncoder(this.fd);
45
+ }
46
+ });
47
+ }
48
+ /**
49
+ * @returns the multipart form data request
50
+ */
51
+ getBody() {
52
+ return __awaiter(this, void 0, void 0, function* () {
53
+ if (runtime_1.RUNTIME.type !== "node") {
54
+ return this.fd;
55
+ }
56
+ else {
57
+ if (this.encoder == null) {
58
+ yield this.setup();
59
+ }
60
+ return (yield Promise.resolve().then(() => __importStar(require("node:stream")))).Readable.from(this.encoder);
61
+ }
62
+ });
63
+ }
64
+ /**
65
+ * @returns headers that need to be added to the multipart form data request
66
+ */
67
+ getHeaders() {
68
+ return __awaiter(this, void 0, void 0, function* () {
69
+ if (runtime_1.RUNTIME.type !== "node") {
70
+ return {};
71
+ }
72
+ else {
73
+ if (this.encoder == null) {
74
+ yield this.setup();
75
+ }
76
+ return {
77
+ "Content-Length": this.encoder.length,
78
+ };
79
+ }
80
+ });
81
+ }
82
+ }
83
+ /**
84
+ * FormDataWrapper is a utility to make form data
85
+ * requests across both Browser and Node.js runtimes.
86
+ */
87
+ class FormDataWrapper {
88
+ append(name, value) {
89
+ return __awaiter(this, void 0, void 0, function* () {
90
+ if (this.fd == null) {
91
+ if (runtime_1.RUNTIME.type === "node") {
92
+ this.fd = new (yield Promise.resolve().then(() => __importStar(require("formdata-node")))).FormData();
93
+ }
94
+ else {
95
+ this.fd = new (yield Promise.resolve().then(() => __importStar(require("form-data")))).default();
96
+ }
97
+ }
98
+ this.fd.append(name, value);
99
+ });
100
+ }
101
+ getRequest() {
102
+ return new FormDataRequestBody(this.fd);
103
+ }
104
+ }
105
+ exports.FormDataWrapper = FormDataWrapper;
@@ -0,0 +1 @@
1
+ export * from "./FormDataWrapper";
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./FormDataWrapper"), exports);
package/core/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from "./fetcher";
2
2
  export * from "./runtime";
3
+ export * from "./form-data-utils";
3
4
  export * from "./websocket";
4
5
  export * as serialization from "./schemas";
package/core/index.js CHANGED
@@ -29,5 +29,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
29
29
  exports.serialization = void 0;
30
30
  __exportStar(require("./fetcher"), exports);
31
31
  __exportStar(require("./runtime"), exports);
32
+ __exportStar(require("./form-data-utils"), exports);
32
33
  __exportStar(require("./websocket"), exports);
33
34
  exports.serialization = __importStar(require("./schemas"));
package/dist/Client.d.ts CHANGED
@@ -3,8 +3,8 @@
3
3
  */
4
4
  import * as environments from "./environments";
5
5
  import * as core from "./core";
6
- import { CustomModels } from "./api/resources/customModels/client/Client";
7
6
  import { EmpathicVoice } from "./api/resources/empathicVoice/client/Client";
7
+ import { CustomModels } from "./api/resources/customModels/client/Client";
8
8
  import { ExpressionMeasurement } from "./api/resources/expressionMeasurement/client/Client";
9
9
  export declare namespace HumeClient {
10
10
  interface Options {
@@ -15,15 +15,16 @@ export declare namespace HumeClient {
15
15
  interface RequestOptions {
16
16
  timeoutInSeconds?: number;
17
17
  maxRetries?: number;
18
+ abortSignal?: AbortSignal;
18
19
  }
19
20
  }
20
21
  export declare class HumeClient {
21
22
  protected readonly _options: HumeClient.Options;
22
23
  constructor(_options?: HumeClient.Options);
23
- protected _customModels: CustomModels | undefined;
24
- get customModels(): CustomModels;
25
24
  protected _empathicVoice: EmpathicVoice | undefined;
26
25
  get empathicVoice(): EmpathicVoice;
26
+ protected _customModels: CustomModels | undefined;
27
+ get customModels(): CustomModels;
27
28
  protected _expressionMeasurement: ExpressionMeasurement | undefined;
28
29
  get expressionMeasurement(): ExpressionMeasurement;
29
30
  }
package/dist/Client.js CHANGED
@@ -4,20 +4,20 @@
4
4
  */
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.HumeClient = void 0;
7
- const Client_1 = require("./api/resources/customModels/client/Client");
8
- const Client_2 = require("./api/resources/empathicVoice/client/Client");
7
+ const Client_1 = require("./api/resources/empathicVoice/client/Client");
8
+ const Client_2 = require("./api/resources/customModels/client/Client");
9
9
  const Client_3 = require("./api/resources/expressionMeasurement/client/Client");
10
10
  class HumeClient {
11
11
  constructor(_options = {}) {
12
12
  this._options = _options;
13
13
  }
14
- get customModels() {
14
+ get empathicVoice() {
15
15
  var _a;
16
- return ((_a = this._customModels) !== null && _a !== void 0 ? _a : (this._customModels = new Client_1.CustomModels(this._options)));
16
+ return ((_a = this._empathicVoice) !== null && _a !== void 0 ? _a : (this._empathicVoice = new Client_1.EmpathicVoice(this._options)));
17
17
  }
18
- get empathicVoice() {
18
+ get customModels() {
19
19
  var _a;
20
- return ((_a = this._empathicVoice) !== null && _a !== void 0 ? _a : (this._empathicVoice = new Client_2.EmpathicVoice(this._options)));
20
+ return ((_a = this._customModels) !== null && _a !== void 0 ? _a : (this._customModels = new Client_2.CustomModels(this._options)));
21
21
  }
22
22
  get expressionMeasurement() {
23
23
  var _a;
@@ -16,6 +16,7 @@ export declare namespace CustomModels {
16
16
  interface RequestOptions {
17
17
  timeoutInSeconds?: number;
18
18
  maxRetries?: number;
19
+ abortSignal?: AbortSignal;
19
20
  }
20
21
  }
21
22
  export declare class CustomModels {
@@ -15,6 +15,7 @@ export declare namespace Datasets {
15
15
  interface RequestOptions {
16
16
  timeoutInSeconds?: number;
17
17
  maxRetries?: number;
18
+ abortSignal?: AbortSignal;
18
19
  }
19
20
  }
20
21
  export declare class Datasets {