hume 0.11.0 → 0.11.2
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/.mock/definition/empathic-voice/__package__.yml +39 -36
- package/.mock/definition/empathic-voice/chat.yml +18 -3
- package/.mock/definition/empathic-voice/chatGroups.yml +14 -10
- package/.mock/definition/empathic-voice/chatWebhooks.yml +2 -0
- package/.mock/definition/empathic-voice/chats.yml +2 -0
- package/.mock/definition/empathic-voice/configs.yml +4 -0
- package/.mock/definition/empathic-voice/customVoices.yml +1 -0
- package/.mock/definition/empathic-voice/prompts.yml +2 -0
- package/.mock/definition/empathic-voice/tools.yml +2 -0
- package/.mock/definition/expression-measurement/batch/__package__.yml +10 -10
- package/.mock/definition/expression-measurement/stream/stream.yml +1 -1
- package/.mock/definition/tts/__package__.yml +98 -55
- package/.mock/definition/tts/voices.yml +20 -9
- package/.mock/fern.config.json +1 -1
- package/Client.d.ts +11 -7
- package/Client.js +54 -6
- package/api/resources/empathicVoice/errors/BadRequestError.d.ts +2 -1
- package/api/resources/empathicVoice/errors/BadRequestError.js +2 -1
- package/api/resources/empathicVoice/resources/chatGroups/client/Client.d.ts +4 -2
- package/api/resources/empathicVoice/resources/chatGroups/client/Client.js +76 -42
- package/api/resources/empathicVoice/resources/chatGroups/client/requests/ChatGroupsGetAudioRequest.d.ts +4 -4
- package/api/resources/empathicVoice/resources/chats/client/Client.d.ts +2 -1
- package/api/resources/empathicVoice/resources/chats/client/Client.js +57 -32
- package/api/resources/empathicVoice/resources/configs/client/Client.d.ts +14 -7
- package/api/resources/empathicVoice/resources/configs/client/Client.js +136 -66
- package/api/resources/empathicVoice/resources/configs/client/requests/PostedConfig.d.ts +1 -0
- package/api/resources/empathicVoice/resources/configs/client/requests/PostedConfigVersion.d.ts +1 -0
- package/api/resources/empathicVoice/resources/customVoices/client/Client.d.ts +10 -5
- package/api/resources/empathicVoice/resources/customVoices/client/Client.js +89 -42
- package/api/resources/empathicVoice/resources/prompts/client/Client.d.ts +16 -8
- package/api/resources/empathicVoice/resources/prompts/client/Client.js +134 -63
- package/api/resources/empathicVoice/resources/tools/client/Client.d.ts +14 -7
- package/api/resources/empathicVoice/resources/tools/client/Client.js +136 -66
- package/api/resources/empathicVoice/types/AssistantInput.d.ts +1 -1
- package/api/resources/empathicVoice/types/AssistantMessage.d.ts +1 -1
- package/api/resources/empathicVoice/types/PauseAssistantMessage.d.ts +1 -1
- package/api/resources/empathicVoice/types/PostedNudgeSpec.d.ts +12 -0
- package/api/resources/empathicVoice/types/ReturnConfig.d.ts +1 -0
- package/api/resources/empathicVoice/types/ReturnNudgeSpec.d.ts +12 -0
- package/api/resources/empathicVoice/types/ToolCallMessage.d.ts +1 -1
- package/api/resources/empathicVoice/types/ToolErrorMessage.d.ts +2 -2
- package/api/resources/empathicVoice/types/ToolResponseMessage.d.ts +3 -3
- package/api/resources/empathicVoice/types/UserInput.d.ts +1 -1
- package/api/resources/empathicVoice/types/UserMessage.d.ts +3 -3
- package/api/resources/empathicVoice/types/WebhookEventChatStatus.d.ts +2 -1
- package/api/resources/empathicVoice/types/WebhookEventChatStatus.js +1 -0
- package/api/resources/empathicVoice/types/index.d.ts +2 -4
- package/api/resources/empathicVoice/types/index.js +2 -4
- package/api/resources/expressionMeasurement/resources/batch/client/Client.d.ts +12 -6
- package/api/resources/expressionMeasurement/resources/batch/client/Client.js +89 -38
- package/api/resources/tts/client/Client.d.ts +28 -22
- package/api/resources/tts/client/Client.js +88 -50
- package/api/resources/tts/client/index.d.ts +1 -1
- package/api/resources/tts/client/index.js +15 -0
- package/api/resources/tts/client/requests/SynthesizeJsonRequest.d.ts +36 -0
- package/api/resources/tts/client/requests/index.d.ts +1 -0
- package/api/resources/tts/client/requests/index.js +2 -0
- package/api/resources/tts/errors/BadRequestError.d.ts +2 -1
- package/api/resources/tts/errors/BadRequestError.js +2 -1
- package/api/resources/tts/errors/UnprocessableEntityError.d.ts +2 -1
- package/api/resources/tts/errors/UnprocessableEntityError.js +2 -1
- package/api/resources/tts/resources/voices/client/Client.d.ts +9 -5
- package/api/resources/tts/resources/voices/client/Client.js +51 -26
- package/api/resources/tts/resources/voices/client/requests/VoicesListRequest.d.ts +4 -1
- package/api/resources/tts/types/PostedTts.d.ts +6 -6
- package/api/resources/tts/types/PostedUtterance.d.ts +5 -5
- package/api/resources/tts/types/PostedUtteranceVoiceWithId.d.ts +6 -7
- package/api/resources/tts/types/PostedUtteranceVoiceWithName.d.ts +6 -7
- package/api/resources/tts/types/ReturnGeneration.d.ts +1 -1
- package/api/resources/tts/types/ReturnTts.d.ts +1 -1
- package/api/resources/tts/types/ReturnVoice.d.ts +2 -8
- package/api/resources/tts/types/Snippet.d.ts +2 -0
- package/api/resources/tts/types/SnippetAudioChunk.d.ts +2 -0
- package/core/fetcher/APIResponse.d.ts +10 -0
- package/core/fetcher/Fetcher.js +7 -0
- package/core/fetcher/Headers.d.ts +2 -0
- package/core/fetcher/Headers.js +84 -0
- package/core/fetcher/HttpResponsePromise.d.ts +58 -0
- package/core/fetcher/HttpResponsePromise.js +103 -0
- package/core/fetcher/RawResponse.d.ts +29 -0
- package/core/fetcher/RawResponse.js +44 -0
- package/core/fetcher/index.d.ts +3 -0
- package/core/fetcher/index.js +7 -1
- package/core/form-data-utils/FormDataWrapper.d.ts +3 -0
- package/core/form-data-utils/FormDataWrapper.js +48 -9
- package/core/pagination/Page.d.ts +5 -2
- package/core/pagination/Page.js +5 -2
- package/core/pagination/Pageable.d.ts +2 -0
- package/dist/Client.d.ts +11 -7
- package/dist/Client.js +54 -6
- package/dist/api/resources/empathicVoice/errors/BadRequestError.d.ts +2 -1
- package/dist/api/resources/empathicVoice/errors/BadRequestError.js +2 -1
- package/dist/api/resources/empathicVoice/resources/chatGroups/client/Client.d.ts +4 -2
- package/dist/api/resources/empathicVoice/resources/chatGroups/client/Client.js +76 -42
- package/dist/api/resources/empathicVoice/resources/chatGroups/client/requests/ChatGroupsGetAudioRequest.d.ts +4 -4
- package/dist/api/resources/empathicVoice/resources/chats/client/Client.d.ts +2 -1
- package/dist/api/resources/empathicVoice/resources/chats/client/Client.js +57 -32
- package/dist/api/resources/empathicVoice/resources/configs/client/Client.d.ts +14 -7
- package/dist/api/resources/empathicVoice/resources/configs/client/Client.js +136 -66
- package/dist/api/resources/empathicVoice/resources/configs/client/requests/PostedConfig.d.ts +1 -0
- package/dist/api/resources/empathicVoice/resources/configs/client/requests/PostedConfigVersion.d.ts +1 -0
- package/dist/api/resources/empathicVoice/resources/customVoices/client/Client.d.ts +10 -5
- package/dist/api/resources/empathicVoice/resources/customVoices/client/Client.js +89 -42
- package/dist/api/resources/empathicVoice/resources/prompts/client/Client.d.ts +16 -8
- package/dist/api/resources/empathicVoice/resources/prompts/client/Client.js +134 -63
- package/dist/api/resources/empathicVoice/resources/tools/client/Client.d.ts +14 -7
- package/dist/api/resources/empathicVoice/resources/tools/client/Client.js +136 -66
- package/dist/api/resources/empathicVoice/types/AssistantInput.d.ts +1 -1
- package/dist/api/resources/empathicVoice/types/AssistantMessage.d.ts +1 -1
- package/dist/api/resources/empathicVoice/types/PauseAssistantMessage.d.ts +1 -1
- package/dist/api/resources/empathicVoice/types/PostedNudgeSpec.d.ts +12 -0
- package/dist/api/resources/empathicVoice/types/ReturnConfig.d.ts +1 -0
- package/dist/api/resources/empathicVoice/types/ReturnNudgeSpec.d.ts +12 -0
- package/dist/api/resources/empathicVoice/types/ToolCallMessage.d.ts +1 -1
- package/dist/api/resources/empathicVoice/types/ToolErrorMessage.d.ts +2 -2
- package/dist/api/resources/empathicVoice/types/ToolResponseMessage.d.ts +3 -3
- package/dist/api/resources/empathicVoice/types/UserInput.d.ts +1 -1
- package/dist/api/resources/empathicVoice/types/UserMessage.d.ts +3 -3
- package/dist/api/resources/empathicVoice/types/WebhookEventChatStatus.d.ts +2 -1
- package/dist/api/resources/empathicVoice/types/WebhookEventChatStatus.js +1 -0
- package/dist/api/resources/empathicVoice/types/index.d.ts +2 -4
- package/dist/api/resources/empathicVoice/types/index.js +2 -4
- package/dist/api/resources/expressionMeasurement/resources/batch/client/Client.d.ts +12 -6
- package/dist/api/resources/expressionMeasurement/resources/batch/client/Client.js +89 -38
- package/dist/api/resources/tts/client/Client.d.ts +28 -22
- package/dist/api/resources/tts/client/Client.js +88 -50
- package/dist/api/resources/tts/client/index.d.ts +1 -1
- package/dist/api/resources/tts/client/index.js +15 -0
- package/dist/api/resources/tts/client/requests/SynthesizeJsonRequest.d.ts +36 -0
- package/dist/api/resources/tts/client/requests/index.d.ts +1 -0
- package/dist/api/resources/tts/client/requests/index.js +2 -0
- package/dist/api/resources/tts/errors/BadRequestError.d.ts +2 -1
- package/dist/api/resources/tts/errors/BadRequestError.js +2 -1
- package/dist/api/resources/tts/errors/UnprocessableEntityError.d.ts +2 -1
- package/dist/api/resources/tts/errors/UnprocessableEntityError.js +2 -1
- package/dist/api/resources/tts/resources/voices/client/Client.d.ts +9 -5
- package/dist/api/resources/tts/resources/voices/client/Client.js +51 -26
- package/dist/api/resources/tts/resources/voices/client/requests/VoicesListRequest.d.ts +4 -1
- package/dist/api/resources/tts/types/PostedTts.d.ts +6 -6
- package/dist/api/resources/tts/types/PostedUtterance.d.ts +5 -5
- package/dist/api/resources/tts/types/PostedUtteranceVoiceWithId.d.ts +6 -7
- package/dist/api/resources/tts/types/PostedUtteranceVoiceWithName.d.ts +6 -7
- package/dist/api/resources/tts/types/ReturnGeneration.d.ts +1 -1
- package/dist/api/resources/tts/types/ReturnTts.d.ts +1 -1
- package/dist/api/resources/tts/types/ReturnVoice.d.ts +2 -8
- package/dist/api/resources/tts/types/Snippet.d.ts +2 -0
- package/dist/api/resources/tts/types/SnippetAudioChunk.d.ts +2 -0
- package/dist/core/fetcher/APIResponse.d.ts +10 -0
- package/dist/core/fetcher/Fetcher.js +7 -0
- package/dist/core/fetcher/Headers.d.ts +2 -0
- package/dist/core/fetcher/Headers.js +84 -0
- package/dist/core/fetcher/HttpResponsePromise.d.ts +58 -0
- package/dist/core/fetcher/HttpResponsePromise.js +103 -0
- package/dist/core/fetcher/RawResponse.d.ts +29 -0
- package/dist/core/fetcher/RawResponse.js +44 -0
- package/dist/core/fetcher/index.d.ts +3 -0
- package/dist/core/fetcher/index.js +7 -1
- package/dist/core/form-data-utils/FormDataWrapper.d.ts +3 -0
- package/dist/core/form-data-utils/FormDataWrapper.js +48 -9
- package/dist/core/pagination/Page.d.ts +5 -2
- package/dist/core/pagination/Page.js +5 -2
- package/dist/core/pagination/Pageable.d.ts +2 -0
- package/dist/errors/HumeError.d.ts +7 -2
- package/dist/errors/HumeError.js +10 -10
- package/dist/serialization/resources/empathicVoice/resources/configs/client/requests/PostedConfig.d.ts +2 -0
- package/dist/serialization/resources/empathicVoice/resources/configs/client/requests/PostedConfig.js +2 -0
- package/dist/serialization/resources/empathicVoice/resources/configs/client/requests/PostedConfigVersion.d.ts +2 -0
- package/dist/serialization/resources/empathicVoice/resources/configs/client/requests/PostedConfigVersion.js +2 -0
- package/dist/serialization/resources/empathicVoice/types/PostedNudgeSpec.d.ts +13 -0
- package/dist/serialization/resources/empathicVoice/types/{TextInput.js → PostedNudgeSpec.js} +4 -3
- package/dist/serialization/resources/empathicVoice/types/ReturnConfig.d.ts +2 -0
- package/dist/serialization/resources/empathicVoice/types/ReturnConfig.js +2 -0
- package/dist/serialization/resources/empathicVoice/types/ReturnNudgeSpec.d.ts +13 -0
- package/dist/serialization/resources/empathicVoice/types/{FunctionCallResponseInput.js → ReturnNudgeSpec.js} +4 -3
- package/dist/serialization/resources/empathicVoice/types/WebhookEventChatStatus.d.ts +1 -1
- package/dist/serialization/resources/empathicVoice/types/WebhookEventChatStatus.js +1 -0
- package/dist/serialization/resources/empathicVoice/types/index.d.ts +2 -4
- package/dist/serialization/resources/empathicVoice/types/index.js +2 -4
- package/dist/serialization/resources/tts/types/Snippet.d.ts +1 -0
- package/dist/serialization/resources/tts/types/Snippet.js +1 -0
- package/dist/serialization/resources/tts/types/SnippetAudioChunk.d.ts +1 -0
- package/dist/serialization/resources/tts/types/SnippetAudioChunk.js +1 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/wrapper/expressionMeasurement/ExpressionMeasurementClient.js +2 -0
- package/dist/wrapper/expressionMeasurement/batch/BatchClient.d.ts +2 -1
- package/dist/wrapper/expressionMeasurement/batch/BatchClient.js +43 -17
- package/errors/HumeError.d.ts +7 -2
- package/errors/HumeError.js +10 -10
- package/package.json +3 -2
- package/reference.md +26 -22
- package/serialization/resources/empathicVoice/resources/configs/client/requests/PostedConfig.d.ts +2 -0
- package/serialization/resources/empathicVoice/resources/configs/client/requests/PostedConfig.js +2 -0
- package/serialization/resources/empathicVoice/resources/configs/client/requests/PostedConfigVersion.d.ts +2 -0
- package/serialization/resources/empathicVoice/resources/configs/client/requests/PostedConfigVersion.js +2 -0
- package/serialization/resources/empathicVoice/types/PostedNudgeSpec.d.ts +13 -0
- package/{dist/serialization/resources/empathicVoice/types/TtsInput.js → serialization/resources/empathicVoice/types/PostedNudgeSpec.js} +4 -3
- package/serialization/resources/empathicVoice/types/ReturnConfig.d.ts +2 -0
- package/serialization/resources/empathicVoice/types/ReturnConfig.js +2 -0
- package/serialization/resources/empathicVoice/types/ReturnNudgeSpec.d.ts +13 -0
- package/{dist/serialization/resources/empathicVoice/types/PostedPromptSpec.js → serialization/resources/empathicVoice/types/ReturnNudgeSpec.js} +4 -3
- package/serialization/resources/empathicVoice/types/WebhookEventChatStatus.d.ts +1 -1
- package/serialization/resources/empathicVoice/types/WebhookEventChatStatus.js +1 -0
- package/serialization/resources/empathicVoice/types/index.d.ts +2 -4
- package/serialization/resources/empathicVoice/types/index.js +2 -4
- package/serialization/resources/tts/types/Snippet.d.ts +1 -0
- package/serialization/resources/tts/types/Snippet.js +1 -0
- package/serialization/resources/tts/types/SnippetAudioChunk.d.ts +1 -0
- package/serialization/resources/tts/types/SnippetAudioChunk.js +1 -0
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/wrapper/expressionMeasurement/ExpressionMeasurementClient.js +2 -0
- package/wrapper/expressionMeasurement/batch/BatchClient.d.ts +2 -1
- package/wrapper/expressionMeasurement/batch/BatchClient.js +43 -17
- package/api/resources/empathicVoice/types/FunctionCallResponseInput.d.ts +0 -6
- package/api/resources/empathicVoice/types/PostedPromptSpec.d.ts +0 -9
- package/api/resources/empathicVoice/types/TextInput.d.ts +0 -6
- package/api/resources/empathicVoice/types/TtsInput.d.ts +0 -6
- package/dist/api/resources/empathicVoice/types/FunctionCallResponseInput.d.ts +0 -6
- package/dist/api/resources/empathicVoice/types/PostedPromptSpec.d.ts +0 -9
- package/dist/api/resources/empathicVoice/types/TextInput.d.ts +0 -6
- package/dist/api/resources/empathicVoice/types/TextInput.js +0 -5
- package/dist/api/resources/empathicVoice/types/TtsInput.d.ts +0 -6
- package/dist/api/resources/empathicVoice/types/TtsInput.js +0 -5
- package/dist/serialization/resources/empathicVoice/types/FunctionCallResponseInput.d.ts +0 -12
- package/dist/serialization/resources/empathicVoice/types/PostedPromptSpec.d.ts +0 -12
- package/dist/serialization/resources/empathicVoice/types/TextInput.d.ts +0 -12
- package/dist/serialization/resources/empathicVoice/types/TtsInput.d.ts +0 -12
- package/serialization/resources/empathicVoice/types/FunctionCallResponseInput.d.ts +0 -12
- package/serialization/resources/empathicVoice/types/FunctionCallResponseInput.js +0 -43
- package/serialization/resources/empathicVoice/types/PostedPromptSpec.d.ts +0 -12
- package/serialization/resources/empathicVoice/types/PostedPromptSpec.js +0 -43
- package/serialization/resources/empathicVoice/types/TextInput.d.ts +0 -12
- package/serialization/resources/empathicVoice/types/TextInput.js +0 -43
- package/serialization/resources/empathicVoice/types/TtsInput.d.ts +0 -12
- package/serialization/resources/empathicVoice/types/TtsInput.js +0 -43
- /package/api/resources/empathicVoice/types/{FunctionCallResponseInput.js → PostedNudgeSpec.js} +0 -0
- /package/api/resources/empathicVoice/types/{PostedPromptSpec.js → ReturnNudgeSpec.js} +0 -0
- /package/api/resources/{empathicVoice/types/TextInput.js → tts/client/requests/SynthesizeJsonRequest.js} +0 -0
- /package/{api/resources/empathicVoice/types/TtsInput.js → dist/api/resources/empathicVoice/types/PostedNudgeSpec.js} +0 -0
- /package/dist/api/resources/empathicVoice/types/{FunctionCallResponseInput.js → ReturnNudgeSpec.js} +0 -0
- /package/dist/api/resources/{empathicVoice/types/PostedPromptSpec.js → tts/client/requests/SynthesizeJsonRequest.js} +0 -0
|
@@ -60,7 +60,7 @@ class Voices {
|
|
|
60
60
|
this._options = _options;
|
|
61
61
|
}
|
|
62
62
|
/**
|
|
63
|
-
* Lists voices
|
|
63
|
+
* Lists voices you have saved in your account, or voices from the [Voice Library](https://platform.hume.ai/tts/voice-library).
|
|
64
64
|
*
|
|
65
65
|
* @param {Hume.tts.VoicesListRequest} request
|
|
66
66
|
* @param {Voices.RequestOptions} requestOptions - Request-specific configuration.
|
|
@@ -74,7 +74,7 @@ class Voices {
|
|
|
74
74
|
*/
|
|
75
75
|
list(request, requestOptions) {
|
|
76
76
|
return __awaiter(this, void 0, void 0, function* () {
|
|
77
|
-
const list = (request) => __awaiter(this, void 0, void 0, function* () {
|
|
77
|
+
const list = core.HttpResponsePromise.interceptFunction((request) => __awaiter(this, void 0, void 0, function* () {
|
|
78
78
|
var _a, _b, _c;
|
|
79
79
|
const { provider, pageNumber, pageSize, ascendingOrder } = request;
|
|
80
80
|
const _queryParams = {};
|
|
@@ -93,7 +93,7 @@ class Voices {
|
|
|
93
93
|
const _response = yield ((_a = this._options.fetcher) !== null && _a !== void 0 ? _a : core.fetcher)({
|
|
94
94
|
url: (0, url_join_1.default)((_c = (_b = (yield core.Supplier.get(this._options.baseUrl))) !== null && _b !== void 0 ? _b : (yield core.Supplier.get(this._options.environment))) !== null && _c !== void 0 ? _c : environments.HumeEnvironment.Production, "v0/tts/voices"),
|
|
95
95
|
method: "GET",
|
|
96
|
-
headers: Object.assign(Object.assign({ "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "hume", "X-Fern-SDK-Version": "0.
|
|
96
|
+
headers: Object.assign(Object.assign({ "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "hume", "X-Fern-SDK-Version": "0.11.2", "User-Agent": "hume/0.11.2", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version }, (yield this._getCustomAuthorizationHeaders())), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers),
|
|
97
97
|
contentType: "application/json",
|
|
98
98
|
queryParameters: _queryParams,
|
|
99
99
|
requestType: "json",
|
|
@@ -102,12 +102,15 @@ class Voices {
|
|
|
102
102
|
abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
|
|
103
103
|
});
|
|
104
104
|
if (_response.ok) {
|
|
105
|
-
return
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
105
|
+
return {
|
|
106
|
+
data: serializers.tts.ReturnPagedVoices.parseOrThrow(_response.body, {
|
|
107
|
+
unrecognizedObjectKeys: "passthrough",
|
|
108
|
+
allowUnrecognizedUnionMembers: true,
|
|
109
|
+
allowUnrecognizedEnumValues: true,
|
|
110
|
+
breadcrumbsPrefix: ["response"],
|
|
111
|
+
}),
|
|
112
|
+
rawResponse: _response.rawResponse,
|
|
113
|
+
};
|
|
111
114
|
}
|
|
112
115
|
if (_response.error.reason === "status-code") {
|
|
113
116
|
switch (_response.error.statusCode) {
|
|
@@ -117,11 +120,12 @@ class Voices {
|
|
|
117
120
|
allowUnrecognizedUnionMembers: true,
|
|
118
121
|
allowUnrecognizedEnumValues: true,
|
|
119
122
|
breadcrumbsPrefix: ["response"],
|
|
120
|
-
}));
|
|
123
|
+
}), _response.rawResponse);
|
|
121
124
|
default:
|
|
122
125
|
throw new errors.HumeError({
|
|
123
126
|
statusCode: _response.error.statusCode,
|
|
124
127
|
body: _response.error.body,
|
|
128
|
+
rawResponse: _response.rawResponse,
|
|
125
129
|
});
|
|
126
130
|
}
|
|
127
131
|
}
|
|
@@ -130,18 +134,22 @@ class Voices {
|
|
|
130
134
|
throw new errors.HumeError({
|
|
131
135
|
statusCode: _response.error.statusCode,
|
|
132
136
|
body: _response.error.rawBody,
|
|
137
|
+
rawResponse: _response.rawResponse,
|
|
133
138
|
});
|
|
134
139
|
case "timeout":
|
|
135
140
|
throw new errors.HumeTimeoutError("Timeout exceeded when calling GET /v0/tts/voices.");
|
|
136
141
|
case "unknown":
|
|
137
142
|
throw new errors.HumeError({
|
|
138
143
|
message: _response.error.errorMessage,
|
|
144
|
+
rawResponse: _response.rawResponse,
|
|
139
145
|
});
|
|
140
146
|
}
|
|
141
|
-
});
|
|
142
|
-
let _offset = (request === null || request === void 0 ? void 0 : request.pageNumber) != null ? request === null || request === void 0 ? void 0 : request.pageNumber :
|
|
147
|
+
}));
|
|
148
|
+
let _offset = (request === null || request === void 0 ? void 0 : request.pageNumber) != null ? request === null || request === void 0 ? void 0 : request.pageNumber : 0;
|
|
149
|
+
const dataWithRawResponse = yield list(request).withRawResponse();
|
|
143
150
|
return new core.Pageable({
|
|
144
|
-
response:
|
|
151
|
+
response: dataWithRawResponse.data,
|
|
152
|
+
rawResponse: dataWithRawResponse.rawResponse,
|
|
145
153
|
hasNextPage: (response) => { var _a; return ((_a = response === null || response === void 0 ? void 0 : response.voicesPage) !== null && _a !== void 0 ? _a : []).length > 0; },
|
|
146
154
|
getItems: (response) => { var _a; return (_a = response === null || response === void 0 ? void 0 : response.voicesPage) !== null && _a !== void 0 ? _a : []; },
|
|
147
155
|
loadPage: (_response) => {
|
|
@@ -152,7 +160,9 @@ class Voices {
|
|
|
152
160
|
});
|
|
153
161
|
}
|
|
154
162
|
/**
|
|
155
|
-
*
|
|
163
|
+
* Saves a new custom voice to your account using the specified TTS generation ID.
|
|
164
|
+
*
|
|
165
|
+
* Once saved, this voice can be reused in subsequent TTS requests, ensuring consistent speech style and prosody. For more details on voice creation, see the [Voices Guide](/docs/text-to-speech-tts/voices).
|
|
156
166
|
*
|
|
157
167
|
* @param {Hume.tts.PostedVoice} request
|
|
158
168
|
* @param {Voices.RequestOptions} requestOptions - Request-specific configuration.
|
|
@@ -166,12 +176,15 @@ class Voices {
|
|
|
166
176
|
* })
|
|
167
177
|
*/
|
|
168
178
|
create(request, requestOptions) {
|
|
179
|
+
return core.HttpResponsePromise.fromPromise(this.__create(request, requestOptions));
|
|
180
|
+
}
|
|
181
|
+
__create(request, requestOptions) {
|
|
169
182
|
return __awaiter(this, void 0, void 0, function* () {
|
|
170
183
|
var _a, _b, _c;
|
|
171
184
|
const _response = yield ((_a = this._options.fetcher) !== null && _a !== void 0 ? _a : core.fetcher)({
|
|
172
185
|
url: (0, url_join_1.default)((_c = (_b = (yield core.Supplier.get(this._options.baseUrl))) !== null && _b !== void 0 ? _b : (yield core.Supplier.get(this._options.environment))) !== null && _c !== void 0 ? _c : environments.HumeEnvironment.Production, "v0/tts/voices"),
|
|
173
186
|
method: "POST",
|
|
174
|
-
headers: Object.assign(Object.assign({ "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "hume", "X-Fern-SDK-Version": "0.
|
|
187
|
+
headers: Object.assign(Object.assign({ "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "hume", "X-Fern-SDK-Version": "0.11.2", "User-Agent": "hume/0.11.2", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version }, (yield this._getCustomAuthorizationHeaders())), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers),
|
|
175
188
|
contentType: "application/json",
|
|
176
189
|
requestType: "json",
|
|
177
190
|
body: serializers.tts.PostedVoice.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }),
|
|
@@ -180,12 +193,15 @@ class Voices {
|
|
|
180
193
|
abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
|
|
181
194
|
});
|
|
182
195
|
if (_response.ok) {
|
|
183
|
-
return
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
196
|
+
return {
|
|
197
|
+
data: serializers.tts.ReturnVoice.parseOrThrow(_response.body, {
|
|
198
|
+
unrecognizedObjectKeys: "passthrough",
|
|
199
|
+
allowUnrecognizedUnionMembers: true,
|
|
200
|
+
allowUnrecognizedEnumValues: true,
|
|
201
|
+
breadcrumbsPrefix: ["response"],
|
|
202
|
+
}),
|
|
203
|
+
rawResponse: _response.rawResponse,
|
|
204
|
+
};
|
|
189
205
|
}
|
|
190
206
|
if (_response.error.reason === "status-code") {
|
|
191
207
|
switch (_response.error.statusCode) {
|
|
@@ -195,11 +211,12 @@ class Voices {
|
|
|
195
211
|
allowUnrecognizedUnionMembers: true,
|
|
196
212
|
allowUnrecognizedEnumValues: true,
|
|
197
213
|
breadcrumbsPrefix: ["response"],
|
|
198
|
-
}));
|
|
214
|
+
}), _response.rawResponse);
|
|
199
215
|
default:
|
|
200
216
|
throw new errors.HumeError({
|
|
201
217
|
statusCode: _response.error.statusCode,
|
|
202
218
|
body: _response.error.body,
|
|
219
|
+
rawResponse: _response.rawResponse,
|
|
203
220
|
});
|
|
204
221
|
}
|
|
205
222
|
}
|
|
@@ -208,18 +225,20 @@ class Voices {
|
|
|
208
225
|
throw new errors.HumeError({
|
|
209
226
|
statusCode: _response.error.statusCode,
|
|
210
227
|
body: _response.error.rawBody,
|
|
228
|
+
rawResponse: _response.rawResponse,
|
|
211
229
|
});
|
|
212
230
|
case "timeout":
|
|
213
231
|
throw new errors.HumeTimeoutError("Timeout exceeded when calling POST /v0/tts/voices.");
|
|
214
232
|
case "unknown":
|
|
215
233
|
throw new errors.HumeError({
|
|
216
234
|
message: _response.error.errorMessage,
|
|
235
|
+
rawResponse: _response.rawResponse,
|
|
217
236
|
});
|
|
218
237
|
}
|
|
219
238
|
});
|
|
220
239
|
}
|
|
221
240
|
/**
|
|
222
|
-
*
|
|
241
|
+
* Deletes a previously generated custom voice.
|
|
223
242
|
*
|
|
224
243
|
* @param {Hume.tts.VoicesDeleteRequest} request
|
|
225
244
|
* @param {Voices.RequestOptions} requestOptions - Request-specific configuration.
|
|
@@ -232,6 +251,9 @@ class Voices {
|
|
|
232
251
|
* })
|
|
233
252
|
*/
|
|
234
253
|
delete(request, requestOptions) {
|
|
254
|
+
return core.HttpResponsePromise.fromPromise(this.__delete(request, requestOptions));
|
|
255
|
+
}
|
|
256
|
+
__delete(request, requestOptions) {
|
|
235
257
|
return __awaiter(this, void 0, void 0, function* () {
|
|
236
258
|
var _a, _b, _c;
|
|
237
259
|
const { name } = request;
|
|
@@ -240,7 +262,7 @@ class Voices {
|
|
|
240
262
|
const _response = yield ((_a = this._options.fetcher) !== null && _a !== void 0 ? _a : core.fetcher)({
|
|
241
263
|
url: (0, url_join_1.default)((_c = (_b = (yield core.Supplier.get(this._options.baseUrl))) !== null && _b !== void 0 ? _b : (yield core.Supplier.get(this._options.environment))) !== null && _c !== void 0 ? _c : environments.HumeEnvironment.Production, "v0/tts/voices"),
|
|
242
264
|
method: "DELETE",
|
|
243
|
-
headers: Object.assign(Object.assign({ "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "hume", "X-Fern-SDK-Version": "0.
|
|
265
|
+
headers: Object.assign(Object.assign({ "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "hume", "X-Fern-SDK-Version": "0.11.2", "User-Agent": "hume/0.11.2", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version }, (yield this._getCustomAuthorizationHeaders())), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers),
|
|
244
266
|
contentType: "application/json",
|
|
245
267
|
queryParameters: _queryParams,
|
|
246
268
|
requestType: "json",
|
|
@@ -249,7 +271,7 @@ class Voices {
|
|
|
249
271
|
abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
|
|
250
272
|
});
|
|
251
273
|
if (_response.ok) {
|
|
252
|
-
return;
|
|
274
|
+
return { data: undefined, rawResponse: _response.rawResponse };
|
|
253
275
|
}
|
|
254
276
|
if (_response.error.reason === "status-code") {
|
|
255
277
|
switch (_response.error.statusCode) {
|
|
@@ -259,11 +281,12 @@ class Voices {
|
|
|
259
281
|
allowUnrecognizedUnionMembers: true,
|
|
260
282
|
allowUnrecognizedEnumValues: true,
|
|
261
283
|
breadcrumbsPrefix: ["response"],
|
|
262
|
-
}));
|
|
284
|
+
}), _response.rawResponse);
|
|
263
285
|
default:
|
|
264
286
|
throw new errors.HumeError({
|
|
265
287
|
statusCode: _response.error.statusCode,
|
|
266
288
|
body: _response.error.body,
|
|
289
|
+
rawResponse: _response.rawResponse,
|
|
267
290
|
});
|
|
268
291
|
}
|
|
269
292
|
}
|
|
@@ -272,12 +295,14 @@ class Voices {
|
|
|
272
295
|
throw new errors.HumeError({
|
|
273
296
|
statusCode: _response.error.statusCode,
|
|
274
297
|
body: _response.error.rawBody,
|
|
298
|
+
rawResponse: _response.rawResponse,
|
|
275
299
|
});
|
|
276
300
|
case "timeout":
|
|
277
301
|
throw new errors.HumeTimeoutError("Timeout exceeded when calling DELETE /v0/tts/voices.");
|
|
278
302
|
case "unknown":
|
|
279
303
|
throw new errors.HumeError({
|
|
280
304
|
message: _response.error.errorMessage,
|
|
305
|
+
rawResponse: _response.rawResponse,
|
|
281
306
|
});
|
|
282
307
|
}
|
|
283
308
|
});
|
|
@@ -10,7 +10,10 @@ import * as Hume from "../../../../../../index";
|
|
|
10
10
|
*/
|
|
11
11
|
export interface VoicesListRequest {
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
13
|
+
* Specify the voice provider to filter voices returned by the endpoint:
|
|
14
|
+
*
|
|
15
|
+
* - **`HUME_AI`**: Lists preset, shared voices from Hume's [Voice Library](https://platform.hume.ai/tts/voice-library).
|
|
16
|
+
* - **`CUSTOM_VOICE`**: Lists custom voices created and saved to your account.
|
|
14
17
|
*/
|
|
15
18
|
provider: Hume.tts.VoiceProvider;
|
|
16
19
|
/**
|
|
@@ -12,11 +12,11 @@ export interface PostedTts {
|
|
|
12
12
|
/**
|
|
13
13
|
* Controls how audio output is segmented in the response.
|
|
14
14
|
*
|
|
15
|
-
* - When **enabled** (`true`),
|
|
15
|
+
* - When **enabled** (`true`), input utterances are automatically split into natural-sounding speech segments.
|
|
16
16
|
*
|
|
17
|
-
* - When **disabled**
|
|
17
|
+
* - When **disabled** (`false`), the response maintains a strict one-to-one mapping between input utterances and output snippets.
|
|
18
18
|
*
|
|
19
|
-
* This setting affects how the `snippets` array is structured in the response, which may be important
|
|
19
|
+
* This setting affects how the `snippets` array is structured in the response, which may be important for applications that need to track the relationship between input text and generated audio segments. When setting to `false`, avoid including utterances with long `text`, as this can result in distorted output.
|
|
20
20
|
*/
|
|
21
21
|
splitUtterances?: boolean;
|
|
22
22
|
/** If enabled, the audio for all the chunks of a generation, once concatenated together, will constitute a single audio file. Otherwise, if disabled, each chunk's audio will be its own audio file, each with its own headers (if applicable). */
|
|
@@ -24,13 +24,13 @@ export interface PostedTts {
|
|
|
24
24
|
/**
|
|
25
25
|
* A list of **Utterances** to be converted to speech output.
|
|
26
26
|
*
|
|
27
|
-
* An **Utterance** is a unit of
|
|
27
|
+
* An **Utterance** is a unit of input for [Octave](/docs/text-to-speech-tts/overview), and includes input `text`, an optional `description` to serve as the prompt for how the speech should be delivered, an optional `voice` specification, and additional controls to guide delivery for `speed` and `trailing_silence`.
|
|
28
28
|
*/
|
|
29
29
|
utterances: Hume.tts.PostedUtterance[];
|
|
30
30
|
/**
|
|
31
31
|
* Enables ultra-low latency streaming, significantly reducing the time until the first audio chunk is received. Recommended for real-time applications requiring immediate audio playback. For further details, see our documentation on [instant mode](/docs/text-to-speech-tts/overview#ultra-low-latency-streaming-instant-mode).
|
|
32
|
-
* - Dynamic voice generation is not supported with this mode; a predefined
|
|
33
|
-
* - This mode is only supported for streaming endpoints (e.g.,
|
|
32
|
+
* - Dynamic voice generation is not supported with this mode; a predefined [voice](/reference/text-to-speech-tts/synthesize-json-streaming#request.body.utterances.voice) must be specified in your request.
|
|
33
|
+
* - This mode is only supported for streaming endpoints (e.g., [/v0/tts/stream/json](/reference/text-to-speech-tts/synthesize-json-streaming), [/v0/tts/stream/file](/reference/text-to-speech-tts/synthesize-file-streaming)).
|
|
34
34
|
* - Ensure only a single generation is requested ([num_generations](/reference/text-to-speech-tts/synthesize-json-streaming#request.body.num_generations) must be `1` or omitted).
|
|
35
35
|
* - With `instant_mode` enabled, **requests incur a 10% higher cost** due to increased compute and resource requirements.
|
|
36
36
|
*/
|
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
import * as Hume from "../../../index";
|
|
5
5
|
export interface PostedUtterance {
|
|
6
6
|
/**
|
|
7
|
-
* Natural language instructions describing how the synthesized speech should sound, including
|
|
8
|
-
* - If a Voice is specified in the request, this description serves as acting instructions. For
|
|
9
|
-
* - If no Voice is specified, a new voice is generated based on this description. See our [prompting guide](/docs/text-to-speech-tts/prompting)
|
|
7
|
+
* Natural language instructions describing how the synthesized speech should sound, including but not limited to tone, intonation, pacing, and accent (e.g., 'a soft, gentle voice with a strong British accent').
|
|
8
|
+
* - If a Voice is specified in the request, this description serves as acting instructions. For tips on how to effectively guide speech delivery, see our guide on [Acting instructions](/docs/text-to-speech-tts/acting-instructions).
|
|
9
|
+
* - If no Voice is specified, a new voice is generated based on this description. See our [prompting guide](/docs/text-to-speech-tts/prompting) for tips on designing a voice.
|
|
10
10
|
*/
|
|
11
11
|
description?: string;
|
|
12
12
|
/** Speed multiplier for the synthesized speech. */
|
|
@@ -16,9 +16,9 @@ export interface PostedUtterance {
|
|
|
16
16
|
/** Duration of trailing silence (in seconds) to add to this utterance */
|
|
17
17
|
trailingSilence?: number;
|
|
18
18
|
/**
|
|
19
|
-
* The `name` or `id` associated with a **Voice** from the **Voice Library** to be used as the
|
|
19
|
+
* The `name` or `id` associated with a **Voice** from the **Voice Library** to be used as the speaker for this and all subsequent `utterances`, until the `voice` field is updated again.
|
|
20
20
|
*
|
|
21
|
-
* See our
|
|
21
|
+
* See our [voices guide](/docs/text-to-speech-tts/voices) for more details on generating and specifying **Voices**.
|
|
22
22
|
*/
|
|
23
23
|
voice?: Hume.tts.PostedUtteranceVoice;
|
|
24
24
|
}
|
|
@@ -3,18 +3,17 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import * as Hume from "../../../index";
|
|
5
5
|
export interface PostedUtteranceVoiceWithId {
|
|
6
|
-
/** The ID
|
|
6
|
+
/** The unique ID associated with the **Voice**. */
|
|
7
7
|
id: string;
|
|
8
8
|
/**
|
|
9
|
-
* Specifies the provider
|
|
9
|
+
* Specifies the source provider associated with the chosen voice.
|
|
10
10
|
*
|
|
11
|
-
*
|
|
11
|
+
* - **`HUME_AI`**: Select voices from Hume's [Voice Library](https://platform.hume.ai/tts/voice-library), containing a variety of preset, shared voices.
|
|
12
|
+
* - **`CUSTOM_VOICE`**: Select from voices you've personally generated and saved in your account.
|
|
12
13
|
*
|
|
13
|
-
*
|
|
14
|
+
* If no provider is explicitly set, the default provider is `CUSTOM_VOICE`. When using voices from Hume's **Voice Library**, you must explicitly set the provider to `HUME_AI`.
|
|
14
15
|
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* While Hume's preset voices are shared and usable by anyone, your custom voices are only available to calls made with your API key.
|
|
16
|
+
* Preset voices from Hume's **Voice Library** are accessible by all users. In contrast, your custom voices are private and accessible only via requests authenticated with your API key.
|
|
18
17
|
*/
|
|
19
18
|
provider?: Hume.tts.VoiceProvider;
|
|
20
19
|
}
|
|
@@ -3,18 +3,17 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import * as Hume from "../../../index";
|
|
5
5
|
export interface PostedUtteranceVoiceWithName {
|
|
6
|
-
/** The name of a **Voice
|
|
6
|
+
/** The name of a **Voice**. */
|
|
7
7
|
name: string;
|
|
8
8
|
/**
|
|
9
|
-
* Specifies the provider
|
|
9
|
+
* Specifies the source provider associated with the chosen voice.
|
|
10
10
|
*
|
|
11
|
-
*
|
|
11
|
+
* - **`HUME_AI`**: Select voices from Hume's [Voice Library](https://platform.hume.ai/tts/voice-library), containing a variety of preset, shared voices.
|
|
12
|
+
* - **`CUSTOM_VOICE`**: Select from voices you've personally generated and saved in your account.
|
|
12
13
|
*
|
|
13
|
-
*
|
|
14
|
+
* If no provider is explicitly set, the default provider is `CUSTOM_VOICE`. When using voices from Hume's **Voice Library**, you must explicitly set the provider to `HUME_AI`.
|
|
14
15
|
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* While Hume's preset voices are shared and usable by anyone, your custom voices are only available to calls made with your API key.
|
|
16
|
+
* Preset voices from Hume's **Voice Library** are accessible by all users. In contrast, your custom voices are private and accessible only via requests authenticated with your API key.
|
|
18
17
|
*/
|
|
19
18
|
provider?: Hume.tts.VoiceProvider;
|
|
20
19
|
}
|
|
@@ -12,6 +12,6 @@ export interface ReturnGeneration {
|
|
|
12
12
|
fileSize: number;
|
|
13
13
|
/** A unique ID associated with this TTS generation that can be used as context for generating consistent speech style and prosody across multiple requests. */
|
|
14
14
|
generationId: string;
|
|
15
|
-
/** A list of snippet groups where each group corresponds to an utterance in the request. Each
|
|
15
|
+
/** A list of snippet groups where each group corresponds to an utterance in the request. Each group contains segmented snippets that represent the original utterance divided into more natural-sounding units optimized for speech delivery. */
|
|
16
16
|
snippets: Hume.tts.Snippet[][];
|
|
17
17
|
}
|
|
@@ -4,6 +4,6 @@
|
|
|
4
4
|
import * as Hume from "../../../index";
|
|
5
5
|
export interface ReturnTts {
|
|
6
6
|
generations: Hume.tts.ReturnGeneration[];
|
|
7
|
-
/** A unique ID associated with this request for tracking and troubleshooting. Use this ID when
|
|
7
|
+
/** A unique ID associated with this request for tracking and troubleshooting. Use this ID when contacting [support](/support) for troubleshooting assistance. */
|
|
8
8
|
requestId?: string;
|
|
9
9
|
}
|
|
@@ -11,15 +11,9 @@ export interface ReturnVoice {
|
|
|
11
11
|
/** Name of the voice in the `Voice Library`. */
|
|
12
12
|
name?: string;
|
|
13
13
|
/**
|
|
14
|
-
*
|
|
14
|
+
* The provider associated with the created voice.
|
|
15
15
|
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
* - **CUSTOM_VOICE**: Voices you have generated and saved to your `Voice library`.
|
|
19
|
-
*
|
|
20
|
-
* If a provider is not specified, the provider will default to `CUSTOM_VOICE`.
|
|
21
|
-
*
|
|
22
|
-
* While Hume's preset voices are shared and usable by anyone, your custom voices are only available to calls made with your API key.
|
|
16
|
+
* Voices created through this endpoint will always have the provider set to `CUSTOM_VOICE`, indicating a custom voice stored in your account.
|
|
23
17
|
*/
|
|
24
18
|
provider?: Hume.tts.VoiceProvider;
|
|
25
19
|
}
|
|
@@ -10,6 +10,8 @@ export interface Snippet {
|
|
|
10
10
|
id: string;
|
|
11
11
|
/** The text for this **Snippet**. */
|
|
12
12
|
text: string;
|
|
13
|
+
/** The transcribed text of the generated audio. It is only present if `instant_mode` is set to `false`. */
|
|
14
|
+
transcribedText?: string;
|
|
13
15
|
/** The index of the utterance in the request this snippet corresponds to. */
|
|
14
16
|
utteranceIndex?: number;
|
|
15
17
|
}
|
|
@@ -14,6 +14,8 @@ export interface SnippetAudioChunk {
|
|
|
14
14
|
snippetId: string;
|
|
15
15
|
/** The text of the parent snippet that this chunk corresponds to. */
|
|
16
16
|
text: string;
|
|
17
|
+
/** The transcribed text of the generated audio of the parent snippet that this chunk corresponds to. It is only present if `instant_mode` is set to `false`. */
|
|
18
|
+
transcribedText?: string;
|
|
17
19
|
/** The index of the utterance in the request that the parent snippet of this chunk corresponds to. */
|
|
18
20
|
utteranceIndex?: number;
|
|
19
21
|
}
|
|
@@ -1,10 +1,20 @@
|
|
|
1
|
+
import { RawResponse } from "./RawResponse";
|
|
2
|
+
/**
|
|
3
|
+
* The response of an API call.
|
|
4
|
+
* It is a successful response or a failed response.
|
|
5
|
+
*/
|
|
1
6
|
export type APIResponse<Success, Failure> = SuccessfulResponse<Success> | FailedResponse<Failure>;
|
|
2
7
|
export interface SuccessfulResponse<T> {
|
|
3
8
|
ok: true;
|
|
4
9
|
body: T;
|
|
10
|
+
/**
|
|
11
|
+
* @deprecated Use `rawResponse` instead
|
|
12
|
+
*/
|
|
5
13
|
headers?: Record<string, any>;
|
|
14
|
+
rawResponse: RawResponse;
|
|
6
15
|
}
|
|
7
16
|
export interface FailedResponse<T> {
|
|
8
17
|
ok: false;
|
|
9
18
|
error: T;
|
|
19
|
+
rawResponse: RawResponse;
|
|
10
20
|
}
|
package/core/fetcher/Fetcher.js
CHANGED
|
@@ -12,6 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.fetcher = void 0;
|
|
13
13
|
exports.fetcherImpl = fetcherImpl;
|
|
14
14
|
const json_1 = require("../json");
|
|
15
|
+
const RawResponse_1 = require("./RawResponse");
|
|
15
16
|
const createRequestUrl_1 = require("./createRequestUrl");
|
|
16
17
|
const getFetchFn_1 = require("./getFetchFn");
|
|
17
18
|
const getRequestBody_1 = require("./getRequestBody");
|
|
@@ -47,6 +48,7 @@ function fetcherImpl(args) {
|
|
|
47
48
|
ok: true,
|
|
48
49
|
body: responseBody,
|
|
49
50
|
headers: response.headers,
|
|
51
|
+
rawResponse: (0, RawResponse_1.toRawResponse)(response),
|
|
50
52
|
};
|
|
51
53
|
}
|
|
52
54
|
else {
|
|
@@ -57,6 +59,7 @@ function fetcherImpl(args) {
|
|
|
57
59
|
statusCode: response.status,
|
|
58
60
|
body: responseBody,
|
|
59
61
|
},
|
|
62
|
+
rawResponse: (0, RawResponse_1.toRawResponse)(response),
|
|
60
63
|
};
|
|
61
64
|
}
|
|
62
65
|
}
|
|
@@ -68,6 +71,7 @@ function fetcherImpl(args) {
|
|
|
68
71
|
reason: "unknown",
|
|
69
72
|
errorMessage: "The user aborted a request",
|
|
70
73
|
},
|
|
74
|
+
rawResponse: RawResponse_1.abortRawResponse,
|
|
71
75
|
};
|
|
72
76
|
}
|
|
73
77
|
else if (error instanceof Error && error.name === "AbortError") {
|
|
@@ -76,6 +80,7 @@ function fetcherImpl(args) {
|
|
|
76
80
|
error: {
|
|
77
81
|
reason: "timeout",
|
|
78
82
|
},
|
|
83
|
+
rawResponse: RawResponse_1.abortRawResponse,
|
|
79
84
|
};
|
|
80
85
|
}
|
|
81
86
|
else if (error instanceof Error) {
|
|
@@ -85,6 +90,7 @@ function fetcherImpl(args) {
|
|
|
85
90
|
reason: "unknown",
|
|
86
91
|
errorMessage: error.message,
|
|
87
92
|
},
|
|
93
|
+
rawResponse: RawResponse_1.unknownRawResponse,
|
|
88
94
|
};
|
|
89
95
|
}
|
|
90
96
|
return {
|
|
@@ -93,6 +99,7 @@ function fetcherImpl(args) {
|
|
|
93
99
|
reason: "unknown",
|
|
94
100
|
errorMessage: (0, json_1.toJson)(error),
|
|
95
101
|
},
|
|
102
|
+
rawResponse: RawResponse_1.unknownRawResponse,
|
|
96
103
|
};
|
|
97
104
|
}
|
|
98
105
|
});
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Headers = void 0;
|
|
4
|
+
let Headers;
|
|
5
|
+
if (typeof globalThis.Headers !== "undefined") {
|
|
6
|
+
exports.Headers = Headers = globalThis.Headers;
|
|
7
|
+
}
|
|
8
|
+
else {
|
|
9
|
+
exports.Headers = Headers = class Headers {
|
|
10
|
+
constructor(init) {
|
|
11
|
+
this.headers = new Map();
|
|
12
|
+
if (init) {
|
|
13
|
+
if (init instanceof Headers) {
|
|
14
|
+
init.forEach((value, key) => this.append(key, value));
|
|
15
|
+
}
|
|
16
|
+
else if (Array.isArray(init)) {
|
|
17
|
+
for (const [key, value] of init) {
|
|
18
|
+
if (typeof key === "string" && typeof value === "string") {
|
|
19
|
+
this.append(key, value);
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
throw new TypeError("Each header entry must be a [string, string] tuple");
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
for (const [key, value] of Object.entries(init)) {
|
|
28
|
+
if (typeof value === "string") {
|
|
29
|
+
this.append(key, value);
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
throw new TypeError("Header values must be strings");
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
append(name, value) {
|
|
39
|
+
const key = name.toLowerCase();
|
|
40
|
+
const existing = this.headers.get(key) || [];
|
|
41
|
+
this.headers.set(key, [...existing, value]);
|
|
42
|
+
}
|
|
43
|
+
delete(name) {
|
|
44
|
+
const key = name.toLowerCase();
|
|
45
|
+
this.headers.delete(key);
|
|
46
|
+
}
|
|
47
|
+
get(name) {
|
|
48
|
+
const key = name.toLowerCase();
|
|
49
|
+
const values = this.headers.get(key);
|
|
50
|
+
return values ? values.join(", ") : null;
|
|
51
|
+
}
|
|
52
|
+
has(name) {
|
|
53
|
+
const key = name.toLowerCase();
|
|
54
|
+
return this.headers.has(key);
|
|
55
|
+
}
|
|
56
|
+
set(name, value) {
|
|
57
|
+
const key = name.toLowerCase();
|
|
58
|
+
this.headers.set(key, [value]);
|
|
59
|
+
}
|
|
60
|
+
forEach(callbackfn, thisArg) {
|
|
61
|
+
const boundCallback = thisArg ? callbackfn.bind(thisArg) : callbackfn;
|
|
62
|
+
this.headers.forEach((values, key) => boundCallback(values.join(", "), key, this));
|
|
63
|
+
}
|
|
64
|
+
getSetCookie() {
|
|
65
|
+
return this.headers.get("set-cookie") || [];
|
|
66
|
+
}
|
|
67
|
+
*entries() {
|
|
68
|
+
for (const [key, values] of this.headers.entries()) {
|
|
69
|
+
yield [key, values.join(", ")];
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
*keys() {
|
|
73
|
+
yield* this.headers.keys();
|
|
74
|
+
}
|
|
75
|
+
*values() {
|
|
76
|
+
for (const values of this.headers.values()) {
|
|
77
|
+
yield values.join(", ");
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
[Symbol.iterator]() {
|
|
81
|
+
return this.entries();
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { WithRawResponse } from "./RawResponse";
|
|
2
|
+
/**
|
|
3
|
+
* A promise that returns the parsed response and lets you retrieve the raw response too.
|
|
4
|
+
*/
|
|
5
|
+
export declare class HttpResponsePromise<T> extends Promise<T> {
|
|
6
|
+
private innerPromise;
|
|
7
|
+
private unwrappedPromise;
|
|
8
|
+
private constructor();
|
|
9
|
+
/**
|
|
10
|
+
* Creates an `HttpResponsePromise` from a function that returns a promise.
|
|
11
|
+
*
|
|
12
|
+
* @param fn - A function that returns a promise resolving to a `WithRawResponse` object.
|
|
13
|
+
* @param args - Arguments to pass to the function.
|
|
14
|
+
* @returns An `HttpResponsePromise` instance.
|
|
15
|
+
*/
|
|
16
|
+
static fromFunction<F extends (...args: never[]) => Promise<WithRawResponse<T>>, T>(fn: F, ...args: Parameters<F>): HttpResponsePromise<T>;
|
|
17
|
+
/**
|
|
18
|
+
* Creates a function that returns an `HttpResponsePromise` from a function that returns a promise.
|
|
19
|
+
*
|
|
20
|
+
* @param fn - A function that returns a promise resolving to a `WithRawResponse` object.
|
|
21
|
+
* @returns A function that returns an `HttpResponsePromise` instance.
|
|
22
|
+
*/
|
|
23
|
+
static interceptFunction<F extends (...args: never[]) => Promise<WithRawResponse<T>>, T = Awaited<ReturnType<F>>["data"]>(fn: F): (...args: Parameters<F>) => HttpResponsePromise<T>;
|
|
24
|
+
/**
|
|
25
|
+
* Creates an `HttpResponsePromise` from an existing promise.
|
|
26
|
+
*
|
|
27
|
+
* @param promise - A promise resolving to a `WithRawResponse` object.
|
|
28
|
+
* @returns An `HttpResponsePromise` instance.
|
|
29
|
+
*/
|
|
30
|
+
static fromPromise<T>(promise: Promise<WithRawResponse<T>>): HttpResponsePromise<T>;
|
|
31
|
+
/**
|
|
32
|
+
* Creates an `HttpResponsePromise` from an executor function.
|
|
33
|
+
*
|
|
34
|
+
* @param executor - A function that takes resolve and reject callbacks to create a promise.
|
|
35
|
+
* @returns An `HttpResponsePromise` instance.
|
|
36
|
+
*/
|
|
37
|
+
static fromExecutor<T>(executor: (resolve: (value: WithRawResponse<T>) => void, reject: (reason?: unknown) => void) => void): HttpResponsePromise<T>;
|
|
38
|
+
/**
|
|
39
|
+
* Creates an `HttpResponsePromise` from a resolved result.
|
|
40
|
+
*
|
|
41
|
+
* @param result - A `WithRawResponse` object to resolve immediately.
|
|
42
|
+
* @returns An `HttpResponsePromise` instance.
|
|
43
|
+
*/
|
|
44
|
+
static fromResult<T>(result: WithRawResponse<T>): HttpResponsePromise<T>;
|
|
45
|
+
private unwrap;
|
|
46
|
+
/** @inheritdoc */
|
|
47
|
+
then<TResult1 = T, TResult2 = never>(onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;
|
|
48
|
+
/** @inheritdoc */
|
|
49
|
+
catch<TResult = never>(onrejected?: ((reason: unknown) => TResult | PromiseLike<TResult>) | null): Promise<T | TResult>;
|
|
50
|
+
/** @inheritdoc */
|
|
51
|
+
finally(onfinally?: (() => void) | null): Promise<T>;
|
|
52
|
+
/**
|
|
53
|
+
* Retrieves the data and raw response.
|
|
54
|
+
*
|
|
55
|
+
* @returns A promise resolving to a `WithRawResponse` object.
|
|
56
|
+
*/
|
|
57
|
+
withRawResponse(): Promise<WithRawResponse<T>>;
|
|
58
|
+
}
|