@ai-sdk/hume 3.0.51 → 3.0.53

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/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # @ai-sdk/hume
2
2
 
3
+ ## 3.0.53
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [8c65988]
8
+ - Updated dependencies [527a163]
9
+ - @ai-sdk/provider@4.0.21
10
+ - @ai-sdk/provider-utils@5.0.53
11
+
12
+ ## 3.0.52
13
+
14
+ ### Patch Changes
15
+
16
+ - ede5b89: chore: migrate package builds from tsup to tsdown
17
+ - Updated dependencies [ede5b89]
18
+ - @ai-sdk/provider@4.0.20
19
+ - @ai-sdk/provider-utils@5.0.52
20
+
3
21
  ## 3.0.51
4
22
 
5
23
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -1,102 +1,106 @@
1
- import * as _ai_sdk_provider from '@ai-sdk/provider';
2
- import { SpeechModelV4, ProviderV4 } from '@ai-sdk/provider';
3
- import { FetchFunction, WORKFLOW_SERIALIZE, WORKFLOW_DESERIALIZE } from '@ai-sdk/provider-utils';
4
- import { z } from 'zod/v4';
5
-
1
+ import { ProviderV4, SpeechModelV4 } from "@ai-sdk/provider";
2
+ import { FetchFunction, WORKFLOW_DESERIALIZE, WORKFLOW_SERIALIZE } from "@ai-sdk/provider-utils";
3
+ import { z } from "zod/v4";
4
+ //#region src/hume-config.d.ts
6
5
  type HumeConfig = {
7
- provider: string;
8
- url: (options: {
9
- modelId: string;
10
- path: string;
11
- }) => string;
12
- headers?: () => Record<string, string | undefined>;
13
- fetch?: FetchFunction;
14
- generateId?: () => string;
6
+ provider: string;
7
+ url: (options: {
8
+ modelId: string;
9
+ path: string;
10
+ }) => string;
11
+ headers?: () => Record<string, string | undefined>;
12
+ fetch?: FetchFunction;
13
+ generateId?: () => string;
15
14
  };
16
-
15
+ //#endregion
16
+ //#region src/hume-speech-model.d.ts
17
17
  interface HumeSpeechModelConfig extends HumeConfig {
18
- _internal?: {
19
- currentDate?: () => Date;
20
- };
18
+ _internal?: {
19
+ currentDate?: () => Date;
20
+ };
21
21
  }
22
22
  declare class HumeSpeechModel implements SpeechModelV4 {
23
- readonly modelId: '';
24
- private readonly config;
25
- readonly specificationVersion = "v4";
26
- get provider(): string;
27
- static [WORKFLOW_SERIALIZE](model: HumeSpeechModel): {
28
- modelId: string;
29
- config: _ai_sdk_provider.JSONObject;
30
- };
31
- static [WORKFLOW_DESERIALIZE](options: {
32
- modelId: '';
33
- config: HumeSpeechModelConfig;
34
- }): HumeSpeechModel;
35
- constructor(modelId: '', config: HumeSpeechModelConfig);
36
- private getArgs;
37
- doGenerate(options: Parameters<SpeechModelV4['doGenerate']>[0]): Promise<Awaited<ReturnType<SpeechModelV4['doGenerate']>>>;
23
+ readonly modelId: '';
24
+ private readonly config;
25
+ readonly specificationVersion = "v4";
26
+ get provider(): string;
27
+ static [WORKFLOW_SERIALIZE](model: HumeSpeechModel): {
28
+ modelId: string;
29
+ config: import("@ai-sdk/provider").JSONObject;
30
+ };
31
+ static [WORKFLOW_DESERIALIZE](options: {
32
+ modelId: '';
33
+ config: HumeSpeechModelConfig;
34
+ }): HumeSpeechModel;
35
+ constructor(modelId: '', config: HumeSpeechModelConfig);
36
+ private getArgs;
37
+ doGenerate(options: Parameters<SpeechModelV4['doGenerate']>[0]): Promise<Awaited<ReturnType<SpeechModelV4['doGenerate']>>>;
38
38
  }
39
-
39
+ //#endregion
40
+ //#region src/hume-provider.d.ts
40
41
  interface HumeProvider extends ProviderV4 {
41
- (settings?: {}): {
42
- speech: HumeSpeechModel;
43
- };
44
- /**
45
- * Creates a model for speech synthesis.
46
- */
47
- speech(): SpeechModelV4;
42
+ (settings?: {}): {
43
+ speech: HumeSpeechModel;
44
+ };
45
+ /**
46
+ * Creates a model for speech synthesis.
47
+ */
48
+ speech(): SpeechModelV4;
48
49
  }
49
50
  interface HumeProviderSettings {
50
- /**
51
- * API key for authenticating requests.
52
- */
53
- apiKey?: string;
54
- /**
55
- * Custom headers to include in the requests.
56
- */
57
- headers?: Record<string, string>;
58
- /**
59
- * Custom fetch implementation. You can use it as a middleware to intercept requests,
60
- * or to provide a custom fetch implementation for e.g. testing.
61
- */
62
- fetch?: FetchFunction;
51
+ /**
52
+ * API key for authenticating requests.
53
+ */
54
+ apiKey?: string;
55
+ /**
56
+ * Custom headers to include in the requests.
57
+ */
58
+ headers?: Record<string, string>;
59
+ /**
60
+ * Custom fetch implementation. You can use it as a middleware to intercept requests,
61
+ * or to provide a custom fetch implementation for e.g. testing.
62
+ */
63
+ fetch?: FetchFunction;
63
64
  }
64
65
  /**
65
66
  * Create an Hume provider instance.
66
67
  */
67
- declare function createHume(options?: HumeProviderSettings): HumeProvider;
68
+ export declare function createHume(options?: HumeProviderSettings): HumeProvider;
68
69
  /**
69
70
  * Default Hume provider instance.
70
71
  */
71
- declare const hume: HumeProvider;
72
-
72
+ export declare const hume: HumeProvider;
73
+ //#endregion
74
+ //#region src/hume-speech-model-options.d.ts
73
75
  declare const humeSpeechModelOptionsSchema: z.ZodObject<{
74
- context: z.ZodOptional<z.ZodNullable<z.ZodUnion<[z.ZodObject<{
75
- generationId: z.ZodString;
76
- }, z.core.$strip>, z.ZodObject<{
77
- utterances: z.ZodArray<z.ZodObject<{
78
- text: z.ZodString;
79
- description: z.ZodOptional<z.ZodString>;
80
- speed: z.ZodOptional<z.ZodNumber>;
81
- trailingSilence: z.ZodOptional<z.ZodNumber>;
82
- voice: z.ZodOptional<z.ZodUnion<[z.ZodObject<{
83
- id: z.ZodString;
84
- provider: z.ZodOptional<z.ZodEnum<{
85
- HUME_AI: "HUME_AI";
86
- CUSTOM_VOICE: "CUSTOM_VOICE";
87
- }>>;
88
- }, z.core.$strip>, z.ZodObject<{
89
- name: z.ZodString;
90
- provider: z.ZodOptional<z.ZodEnum<{
91
- HUME_AI: "HUME_AI";
92
- CUSTOM_VOICE: "CUSTOM_VOICE";
93
- }>>;
94
- }, z.core.$strip>]>>;
95
- }, z.core.$strip>>;
96
- }, z.core.$strip>]>>>;
76
+ context: z.ZodOptional<z.ZodNullable<z.ZodUnion<[z.ZodObject<{
77
+ generationId: z.ZodString;
78
+ }, z.core.$strip>, z.ZodObject<{
79
+ utterances: z.ZodArray<z.ZodObject<{
80
+ text: z.ZodString;
81
+ description: z.ZodOptional<z.ZodString>;
82
+ speed: z.ZodOptional<z.ZodNumber>;
83
+ trailingSilence: z.ZodOptional<z.ZodNumber>;
84
+ voice: z.ZodOptional<z.ZodUnion<[z.ZodObject<{
85
+ id: z.ZodString;
86
+ provider: z.ZodOptional<z.ZodEnum<{
87
+ HUME_AI: "HUME_AI";
88
+ CUSTOM_VOICE: "CUSTOM_VOICE";
89
+ }>>;
90
+ }, z.core.$strip>, z.ZodObject<{
91
+ name: z.ZodString;
92
+ provider: z.ZodOptional<z.ZodEnum<{
93
+ HUME_AI: "HUME_AI";
94
+ CUSTOM_VOICE: "CUSTOM_VOICE";
95
+ }>>;
96
+ }, z.core.$strip>]>>;
97
+ }, z.core.$strip>>;
98
+ }, z.core.$strip>]>>>;
97
99
  }, z.core.$strip>;
98
100
  type HumeSpeechModelOptions = z.infer<typeof humeSpeechModelOptionsSchema>;
99
-
100
- declare const VERSION: string;
101
-
102
- export { type HumeProvider, type HumeProviderSettings, type HumeSpeechModelOptions, VERSION, createHume, hume };
101
+ //#endregion
102
+ //#region src/version.d.ts
103
+ export declare const VERSION: string;
104
+ //#endregion
105
+ export type { HumeProvider, HumeProviderSettings, HumeSpeechModelOptions };
106
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/hume-config.ts","../src/hume-speech-model.ts","../src/hume-provider.ts","../src/hume-speech-model-options.ts","../src/version.ts"],"mappings":";;;;KAEY;EACV;EACA,MAAM;IAAW;IAAiB;;EAClC,gBAAgB;EAChB,QAAQ;EACR;;;;UCQQ,8BAA8B;EACtC;IACE,oBAAoB;;;cAIX,2BAA2B;WAsB3B;mBACQ;WAtBV;MAEL;UAII,oBAAoB,OAAO;;;;UAO3B,sBAAsB;IAC5B;IACA,QAAQ;MACT;EAKU,YAAA,aACQ,QAAQ;UAGb;EAgGR,WACJ,SAAS,WAAW,kCACnB,QAAQ,QAAQ,WAAW;;;;UCpIf,qBAAqB;GACnC;IACC,QAAQ;;;;;EAMV,UAAU;;UAGK;;;;EAIf;;;;EAKA,UAAU;;;;;EAMV,QAAQ;;;;;wBAMM,WAAW,UAAS,uBAA4B;;;;qBA8DnD,MAAI;;;cCxGJ,8BAA4B,EAAA;;;;;;;;;;;;;;;;;;;;;;;;GAqEvC,EAAA,KAAA;KAEU,yBAAyB,EAAE,aAC9B;;;qBCzEI"}
package/dist/index.js CHANGED
@@ -1,293 +1,235 @@
1
- // src/hume-provider.ts
2
- import {
3
- NoSuchModelError
4
- } from "@ai-sdk/provider";
5
- import {
6
- loadApiKey,
7
- withUserAgentSuffix
8
- } from "@ai-sdk/provider-utils";
9
-
10
- // src/hume-speech-model.ts
11
- import {
12
- combineHeaders,
13
- createBinaryResponseHandler,
14
- parseProviderOptions,
15
- postJsonToApi,
16
- serializeModelOptions,
17
- WORKFLOW_SERIALIZE,
18
- WORKFLOW_DESERIALIZE
19
- } from "@ai-sdk/provider-utils";
20
-
21
- // src/hume-error.ts
1
+ import { NoSuchModelError } from "@ai-sdk/provider";
2
+ import { WORKFLOW_DESERIALIZE, WORKFLOW_SERIALIZE, combineHeaders, createBinaryResponseHandler, createJsonErrorResponseHandler, loadApiKey, parseProviderOptions, postJsonToApi, serializeModelOptions, withUserAgentSuffix } from "@ai-sdk/provider-utils";
22
3
  import { z } from "zod/v4";
23
- import { createJsonErrorResponseHandler } from "@ai-sdk/provider-utils";
24
- var humeErrorDataSchema = z.object({
25
- error: z.object({
26
- message: z.string(),
27
- code: z.number()
28
- })
29
- });
30
- var humeFailedResponseHandler = createJsonErrorResponseHandler({
31
- errorSchema: humeErrorDataSchema,
32
- errorToMessage: (data) => data.error.message
33
- });
34
-
35
- // src/hume-speech-model-options.ts
36
- import { z as z2 } from "zod/v4";
37
- var humeSpeechModelOptionsSchema = z2.object({
38
- /**
39
- * Context for the speech synthesis request.
40
- * Can be either a generationId for retrieving a previous generation,
41
- * or a list of utterances to synthesize.
42
- */
43
- context: z2.object({
44
- /**
45
- * ID of a previously generated speech synthesis to retrieve.
46
- */
47
- generationId: z2.string()
48
- }).or(
49
- z2.object({
50
- /**
51
- * List of utterances to synthesize into speech.
52
- */
53
- utterances: z2.array(
54
- z2.object({
55
- /**
56
- * The text content to convert to speech.
57
- */
58
- text: z2.string(),
59
- /**
60
- * Optional description or instructions for how the text should be spoken.
61
- */
62
- description: z2.string().optional(),
63
- /**
64
- * Optional speech rate multiplier.
65
- */
66
- speed: z2.number().optional(),
67
- /**
68
- * Optional duration of silence to add after the utterance in seconds.
69
- */
70
- trailingSilence: z2.number().optional(),
71
- /**
72
- * Voice configuration for the utterance.
73
- * Can be specified by ID or name.
74
- */
75
- voice: z2.object({
76
- /**
77
- * ID of the voice to use.
78
- */
79
- id: z2.string(),
80
- /**
81
- * Provider of the voice, either Hume's built-in voices or a custom voice.
82
- */
83
- provider: z2.enum(["HUME_AI", "CUSTOM_VOICE"]).optional()
84
- }).or(
85
- z2.object({
86
- /**
87
- * Name of the voice to use.
88
- */
89
- name: z2.string(),
90
- /**
91
- * Provider of the voice, either Hume's built-in voices or a custom voice.
92
- */
93
- provider: z2.enum(["HUME_AI", "CUSTOM_VOICE"]).optional()
94
- })
95
- ).optional()
96
- })
97
- )
98
- })
99
- ).nullish()
4
+ //#region src/hume-error.ts
5
+ const humeErrorDataSchema = z.object({ error: z.object({
6
+ message: z.string(),
7
+ code: z.number()
8
+ }) });
9
+ const humeFailedResponseHandler = createJsonErrorResponseHandler({
10
+ errorSchema: humeErrorDataSchema,
11
+ errorToMessage: (data) => data.error.message
100
12
  });
101
-
102
- // src/hume-speech-model.ts
103
- var HumeSpeechModel = class _HumeSpeechModel {
104
- constructor(modelId, config) {
105
- this.modelId = modelId;
106
- this.config = config;
107
- this.specificationVersion = "v4";
108
- }
109
- get provider() {
110
- return this.config.provider;
111
- }
112
- static [WORKFLOW_SERIALIZE](model) {
113
- return serializeModelOptions({
114
- modelId: model.modelId,
115
- config: model.config
116
- });
117
- }
118
- static [WORKFLOW_DESERIALIZE](options) {
119
- return new _HumeSpeechModel(options.modelId, options.config);
120
- }
121
- async getArgs({
122
- text,
123
- voice = "d8ab67c6-953d-4bd8-9370-8fa53a0f1453",
124
- outputFormat = "mp3",
125
- speed,
126
- instructions,
127
- language,
128
- providerOptions
129
- }) {
130
- const warnings = [];
131
- const humeOptions = await parseProviderOptions({
132
- provider: "hume",
133
- providerOptions,
134
- schema: humeSpeechModelOptionsSchema
135
- });
136
- const requestBody = {
137
- utterances: [
138
- {
139
- text,
140
- speed,
141
- description: instructions,
142
- voice: {
143
- id: voice,
144
- provider: "HUME_AI"
145
- }
146
- }
147
- ],
148
- format: { type: "mp3" }
149
- };
150
- if (outputFormat) {
151
- if (["mp3", "pcm", "wav"].includes(outputFormat)) {
152
- requestBody.format = { type: outputFormat };
153
- } else {
154
- warnings.push({
155
- type: "unsupported",
156
- feature: "outputFormat",
157
- details: `Unsupported output format: ${outputFormat}. Using mp3 instead.`
158
- });
159
- }
160
- }
161
- if (humeOptions) {
162
- const speechModelOptions = {};
163
- if (humeOptions.context) {
164
- if ("generationId" in humeOptions.context) {
165
- speechModelOptions.context = {
166
- generation_id: humeOptions.context.generationId
167
- };
168
- } else {
169
- speechModelOptions.context = {
170
- utterances: humeOptions.context.utterances.map((utterance) => ({
171
- text: utterance.text,
172
- description: utterance.description,
173
- speed: utterance.speed,
174
- trailing_silence: utterance.trailingSilence,
175
- voice: utterance.voice
176
- }))
177
- };
178
- }
179
- }
180
- for (const key in speechModelOptions) {
181
- const value = speechModelOptions[key];
182
- if (value !== void 0) {
183
- requestBody[key] = value;
184
- }
185
- }
186
- }
187
- if (language) {
188
- warnings.push({
189
- type: "unsupported",
190
- feature: "language",
191
- details: `Hume speech models do not support language selection. Language parameter "${language}" was ignored.`
192
- });
193
- }
194
- return {
195
- requestBody,
196
- warnings
197
- };
198
- }
199
- async doGenerate(options) {
200
- const currentDate = this.config._internal?.currentDate?.() ?? /* @__PURE__ */ new Date();
201
- const { requestBody, warnings } = await this.getArgs(options);
202
- const {
203
- value: audio,
204
- responseHeaders,
205
- rawValue: rawResponse
206
- } = await postJsonToApi({
207
- url: this.config.url({
208
- path: "/v0/tts/file",
209
- modelId: this.modelId
210
- }),
211
- headers: combineHeaders(this.config.headers?.(), options.headers),
212
- body: requestBody,
213
- failedResponseHandler: humeFailedResponseHandler,
214
- successfulResponseHandler: createBinaryResponseHandler(),
215
- abortSignal: options.abortSignal,
216
- fetch: this.config.fetch
217
- });
218
- return {
219
- audio,
220
- warnings,
221
- request: {
222
- body: JSON.stringify(requestBody)
223
- },
224
- response: {
225
- timestamp: currentDate,
226
- modelId: this.modelId,
227
- headers: responseHeaders,
228
- body: rawResponse
229
- }
230
- };
231
- }
13
+ //#endregion
14
+ //#region src/hume-speech-model-options.ts
15
+ const humeSpeechModelOptionsSchema = z.object({
16
+ /**
17
+ * Context for the speech synthesis request.
18
+ * Can be either a generationId for retrieving a previous generation,
19
+ * or a list of utterances to synthesize.
20
+ */
21
+ context: z.object({
22
+ /**
23
+ * ID of a previously generated speech synthesis to retrieve.
24
+ */
25
+ generationId: z.string() }).or(z.object({
26
+ /**
27
+ * List of utterances to synthesize into speech.
28
+ */
29
+ utterances: z.array(z.object({
30
+ /**
31
+ * The text content to convert to speech.
32
+ */
33
+ text: z.string(),
34
+ /**
35
+ * Optional description or instructions for how the text should be spoken.
36
+ */
37
+ description: z.string().optional(),
38
+ /**
39
+ * Optional speech rate multiplier.
40
+ */
41
+ speed: z.number().optional(),
42
+ /**
43
+ * Optional duration of silence to add after the utterance in seconds.
44
+ */
45
+ trailingSilence: z.number().optional(),
46
+ /**
47
+ * Voice configuration for the utterance.
48
+ * Can be specified by ID or name.
49
+ */
50
+ voice: z.object({
51
+ /**
52
+ * ID of the voice to use.
53
+ */
54
+ id: z.string(),
55
+ /**
56
+ * Provider of the voice, either Hume's built-in voices or a custom voice.
57
+ */
58
+ provider: z.enum(["HUME_AI", "CUSTOM_VOICE"]).optional()
59
+ }).or(z.object({
60
+ /**
61
+ * Name of the voice to use.
62
+ */
63
+ name: z.string(),
64
+ /**
65
+ * Provider of the voice, either Hume's built-in voices or a custom voice.
66
+ */
67
+ provider: z.enum(["HUME_AI", "CUSTOM_VOICE"]).optional()
68
+ })).optional()
69
+ })) })).nullish() });
70
+ //#endregion
71
+ //#region src/hume-speech-model.ts
72
+ var HumeSpeechModel = class HumeSpeechModel {
73
+ get provider() {
74
+ return this.config.provider;
75
+ }
76
+ static [WORKFLOW_SERIALIZE](model) {
77
+ return serializeModelOptions({
78
+ modelId: model.modelId,
79
+ config: model.config
80
+ });
81
+ }
82
+ static [WORKFLOW_DESERIALIZE](options) {
83
+ return new HumeSpeechModel(options.modelId, options.config);
84
+ }
85
+ constructor(modelId, config) {
86
+ this.modelId = modelId;
87
+ this.config = config;
88
+ this.specificationVersion = "v4";
89
+ }
90
+ async getArgs({ text, voice = "d8ab67c6-953d-4bd8-9370-8fa53a0f1453", outputFormat = "mp3", speed, instructions, language, providerOptions }) {
91
+ const warnings = [];
92
+ const humeOptions = await parseProviderOptions({
93
+ provider: "hume",
94
+ providerOptions,
95
+ schema: humeSpeechModelOptionsSchema
96
+ });
97
+ const requestBody = {
98
+ utterances: [{
99
+ text,
100
+ speed,
101
+ description: instructions,
102
+ voice: {
103
+ id: voice,
104
+ provider: "HUME_AI"
105
+ }
106
+ }],
107
+ format: { type: "mp3" }
108
+ };
109
+ if (outputFormat) {
110
+ if ([
111
+ "mp3",
112
+ "pcm",
113
+ "wav"
114
+ ].includes(outputFormat)) requestBody.format = { type: outputFormat };
115
+ else warnings.push({
116
+ type: "unsupported",
117
+ feature: "outputFormat",
118
+ details: `Unsupported output format: ${outputFormat}. Using mp3 instead.`
119
+ });
120
+ }
121
+ if (humeOptions) {
122
+ const speechModelOptions = {};
123
+ if (humeOptions.context) {
124
+ if ("generationId" in humeOptions.context) speechModelOptions.context = { generation_id: humeOptions.context.generationId };
125
+ else speechModelOptions.context = { utterances: humeOptions.context.utterances.map((utterance) => ({
126
+ text: utterance.text,
127
+ description: utterance.description,
128
+ speed: utterance.speed,
129
+ trailing_silence: utterance.trailingSilence,
130
+ voice: utterance.voice
131
+ })) };
132
+ }
133
+ for (const key in speechModelOptions) {
134
+ const value = speechModelOptions[key];
135
+ if (value !== void 0) requestBody[key] = value;
136
+ }
137
+ }
138
+ if (language) warnings.push({
139
+ type: "unsupported",
140
+ feature: "language",
141
+ details: `Hume speech models do not support language selection. Language parameter "${language}" was ignored.`
142
+ });
143
+ return {
144
+ requestBody,
145
+ warnings
146
+ };
147
+ }
148
+ async doGenerate(options) {
149
+ const currentDate = this.config._internal?.currentDate?.() ?? /* @__PURE__ */ new Date();
150
+ const { requestBody, warnings } = await this.getArgs(options);
151
+ const { value: audio, responseHeaders, rawValue: rawResponse } = await postJsonToApi({
152
+ url: this.config.url({
153
+ path: "/v0/tts/file",
154
+ modelId: this.modelId
155
+ }),
156
+ headers: combineHeaders(this.config.headers?.(), options.headers),
157
+ body: requestBody,
158
+ failedResponseHandler: humeFailedResponseHandler,
159
+ successfulResponseHandler: createBinaryResponseHandler(),
160
+ abortSignal: options.abortSignal,
161
+ fetch: this.config.fetch
162
+ });
163
+ return {
164
+ audio,
165
+ warnings,
166
+ request: { body: JSON.stringify(requestBody) },
167
+ response: {
168
+ timestamp: currentDate,
169
+ modelId: this.modelId,
170
+ headers: responseHeaders,
171
+ body: rawResponse
172
+ }
173
+ };
174
+ }
232
175
  };
233
-
234
- // src/version.ts
235
- var VERSION = true ? "3.0.51" : "0.0.0-test";
236
-
237
- // src/hume-provider.ts
176
+ //#endregion
177
+ //#region src/version.ts
178
+ const VERSION = "3.0.53";
179
+ //#endregion
180
+ //#region src/hume-provider.ts
181
+ /**
182
+ * Create an Hume provider instance.
183
+ */
238
184
  function createHume(options = {}) {
239
- const getHeaders = () => withUserAgentSuffix(
240
- {
241
- "X-Hume-Api-Key": loadApiKey({
242
- apiKey: options.apiKey,
243
- environmentVariableName: "HUME_API_KEY",
244
- description: "Hume"
245
- }),
246
- ...options.headers
247
- },
248
- `ai-sdk-hume/${VERSION}`
249
- );
250
- const createSpeechModel = () => new HumeSpeechModel("", {
251
- provider: `hume.speech`,
252
- url: ({ path }) => `https://api.hume.ai${path}`,
253
- headers: getHeaders,
254
- fetch: options.fetch
255
- });
256
- const provider = function() {
257
- return {
258
- speech: createSpeechModel()
259
- };
260
- };
261
- provider.specificationVersion = "v4";
262
- provider.speech = createSpeechModel;
263
- provider.speechModel = createSpeechModel;
264
- provider.languageModel = (modelId) => {
265
- throw new NoSuchModelError({
266
- modelId,
267
- modelType: "languageModel",
268
- message: "Hume does not provide language models"
269
- });
270
- };
271
- provider.embeddingModel = (modelId) => {
272
- throw new NoSuchModelError({
273
- modelId,
274
- modelType: "embeddingModel",
275
- message: "Hume does not provide embedding models"
276
- });
277
- };
278
- provider.imageModel = (modelId) => {
279
- throw new NoSuchModelError({
280
- modelId,
281
- modelType: "imageModel",
282
- message: "Hume does not provide image models"
283
- });
284
- };
285
- return provider;
185
+ const getHeaders = () => withUserAgentSuffix({
186
+ "X-Hume-Api-Key": loadApiKey({
187
+ apiKey: options.apiKey,
188
+ environmentVariableName: "HUME_API_KEY",
189
+ description: "Hume"
190
+ }),
191
+ ...options.headers
192
+ }, `ai-sdk-hume/${VERSION}`);
193
+ const createSpeechModel = () => new HumeSpeechModel("", {
194
+ provider: `hume.speech`,
195
+ url: ({ path }) => `https://api.hume.ai${path}`,
196
+ headers: getHeaders,
197
+ fetch: options.fetch
198
+ });
199
+ const provider = function() {
200
+ return { speech: createSpeechModel() };
201
+ };
202
+ provider.specificationVersion = "v4";
203
+ provider.speech = createSpeechModel;
204
+ provider.speechModel = createSpeechModel;
205
+ provider.languageModel = (modelId) => {
206
+ throw new NoSuchModelError({
207
+ modelId,
208
+ modelType: "languageModel",
209
+ message: "Hume does not provide language models"
210
+ });
211
+ };
212
+ provider.embeddingModel = (modelId) => {
213
+ throw new NoSuchModelError({
214
+ modelId,
215
+ modelType: "embeddingModel",
216
+ message: "Hume does not provide embedding models"
217
+ });
218
+ };
219
+ provider.imageModel = (modelId) => {
220
+ throw new NoSuchModelError({
221
+ modelId,
222
+ modelType: "imageModel",
223
+ message: "Hume does not provide image models"
224
+ });
225
+ };
226
+ return provider;
286
227
  }
287
- var hume = createHume();
288
- export {
289
- VERSION,
290
- createHume,
291
- hume
292
- };
228
+ /**
229
+ * Default Hume provider instance.
230
+ */
231
+ const hume = createHume();
232
+ //#endregion
233
+ export { VERSION, createHume, hume };
234
+
293
235
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/hume-provider.ts","../src/hume-speech-model.ts","../src/hume-error.ts","../src/hume-speech-model-options.ts","../src/version.ts"],"sourcesContent":["import {\n NoSuchModelError,\n type SpeechModelV4,\n type ProviderV4,\n} from '@ai-sdk/provider';\nimport {\n loadApiKey,\n withUserAgentSuffix,\n type FetchFunction,\n} from '@ai-sdk/provider-utils';\nimport { HumeSpeechModel } from './hume-speech-model';\nimport { VERSION } from './version';\n\nexport interface HumeProvider extends ProviderV4 {\n (settings?: {}): {\n speech: HumeSpeechModel;\n };\n\n /**\n * Creates a model for speech synthesis.\n */\n speech(): SpeechModelV4;\n}\n\nexport interface HumeProviderSettings {\n /**\n * API key for authenticating requests.\n */\n apiKey?: string;\n\n /**\n * Custom headers to include in the requests.\n */\n headers?: Record<string, string>;\n\n /**\n * Custom fetch implementation. You can use it as a middleware to intercept requests,\n * or to provide a custom fetch implementation for e.g. testing.\n */\n fetch?: FetchFunction;\n}\n\n/**\n * Create an Hume provider instance.\n */\nexport function createHume(options: HumeProviderSettings = {}): HumeProvider {\n const getHeaders = () =>\n withUserAgentSuffix(\n {\n 'X-Hume-Api-Key': loadApiKey({\n apiKey: options.apiKey,\n environmentVariableName: 'HUME_API_KEY',\n description: 'Hume',\n }),\n ...options.headers,\n },\n `ai-sdk-hume/${VERSION}`,\n );\n\n const createSpeechModel = () =>\n new HumeSpeechModel('', {\n provider: `hume.speech`,\n url: ({ path }) => `https://api.hume.ai${path}`,\n headers: getHeaders,\n fetch: options.fetch,\n });\n\n const provider = function () {\n return {\n speech: createSpeechModel(),\n };\n };\n\n provider.specificationVersion = 'v4' as const;\n provider.speech = createSpeechModel;\n provider.speechModel = createSpeechModel;\n\n provider.languageModel = (modelId: string) => {\n throw new NoSuchModelError({\n modelId,\n modelType: 'languageModel',\n message: 'Hume does not provide language models',\n });\n };\n\n provider.embeddingModel = (modelId: string) => {\n throw new NoSuchModelError({\n modelId,\n modelType: 'embeddingModel',\n message: 'Hume does not provide embedding models',\n });\n };\n\n provider.imageModel = (modelId: string) => {\n throw new NoSuchModelError({\n modelId,\n modelType: 'imageModel',\n message: 'Hume does not provide image models',\n });\n };\n\n return provider as HumeProvider;\n}\n\n/**\n * Default Hume provider instance.\n */\nexport const hume = createHume();\n","import type { SpeechModelV4, SharedV4Warning } from '@ai-sdk/provider';\nimport {\n combineHeaders,\n createBinaryResponseHandler,\n parseProviderOptions,\n postJsonToApi,\n serializeModelOptions,\n WORKFLOW_SERIALIZE,\n WORKFLOW_DESERIALIZE,\n} from '@ai-sdk/provider-utils';\nimport type { HumeConfig } from './hume-config';\nimport { humeFailedResponseHandler } from './hume-error';\nimport { humeSpeechModelOptionsSchema } from './hume-speech-model-options';\nimport type { HumeSpeechAPITypes } from './hume-api-types';\n\ninterface HumeSpeechModelConfig extends HumeConfig {\n _internal?: {\n currentDate?: () => Date;\n };\n}\n\nexport class HumeSpeechModel implements SpeechModelV4 {\n readonly specificationVersion = 'v4';\n\n get provider(): string {\n return this.config.provider;\n }\n\n static [WORKFLOW_SERIALIZE](model: HumeSpeechModel) {\n return serializeModelOptions({\n modelId: model.modelId,\n config: model.config,\n });\n }\n\n static [WORKFLOW_DESERIALIZE](options: {\n modelId: '';\n config: HumeSpeechModelConfig;\n }) {\n return new HumeSpeechModel(options.modelId as '', options.config);\n }\n\n constructor(\n readonly modelId: '',\n private readonly config: HumeSpeechModelConfig,\n ) {}\n\n private async getArgs({\n text,\n voice = 'd8ab67c6-953d-4bd8-9370-8fa53a0f1453',\n outputFormat = 'mp3',\n speed,\n instructions,\n language,\n providerOptions,\n }: Parameters<SpeechModelV4['doGenerate']>[0]) {\n const warnings: SharedV4Warning[] = [];\n\n // Parse provider options\n const humeOptions = await parseProviderOptions({\n provider: 'hume',\n providerOptions,\n schema: humeSpeechModelOptionsSchema,\n });\n\n // Create request body\n const requestBody: HumeSpeechAPITypes = {\n utterances: [\n {\n text,\n speed,\n description: instructions,\n voice: {\n id: voice,\n provider: 'HUME_AI',\n },\n },\n ],\n format: { type: 'mp3' },\n };\n\n if (outputFormat) {\n if (['mp3', 'pcm', 'wav'].includes(outputFormat)) {\n requestBody.format = { type: outputFormat as 'mp3' | 'pcm' | 'wav' };\n } else {\n warnings.push({\n type: 'unsupported',\n feature: 'outputFormat',\n details: `Unsupported output format: ${outputFormat}. Using mp3 instead.`,\n });\n }\n }\n\n // Add provider-specific options\n if (humeOptions) {\n const speechModelOptions: Omit<\n HumeSpeechAPITypes,\n 'utterances' | 'format'\n > = {};\n\n if (humeOptions.context) {\n if ('generationId' in humeOptions.context) {\n speechModelOptions.context = {\n generation_id: humeOptions.context.generationId,\n };\n } else {\n speechModelOptions.context = {\n utterances: humeOptions.context.utterances.map(utterance => ({\n text: utterance.text,\n description: utterance.description,\n speed: utterance.speed,\n trailing_silence: utterance.trailingSilence,\n voice: utterance.voice,\n })),\n };\n }\n }\n\n for (const key in speechModelOptions) {\n const value =\n speechModelOptions[\n key as keyof Omit<HumeSpeechAPITypes, 'utterances' | 'format'>\n ];\n if (value !== undefined) {\n (requestBody as Record<string, unknown>)[key] = value;\n }\n }\n }\n\n if (language) {\n warnings.push({\n type: 'unsupported',\n feature: 'language',\n details: `Hume speech models do not support language selection. Language parameter \"${language}\" was ignored.`,\n });\n }\n\n return {\n requestBody,\n warnings,\n };\n }\n\n async doGenerate(\n options: Parameters<SpeechModelV4['doGenerate']>[0],\n ): Promise<Awaited<ReturnType<SpeechModelV4['doGenerate']>>> {\n const currentDate = this.config._internal?.currentDate?.() ?? new Date();\n const { requestBody, warnings } = await this.getArgs(options);\n\n const {\n value: audio,\n responseHeaders,\n rawValue: rawResponse,\n } = await postJsonToApi({\n url: this.config.url({\n path: '/v0/tts/file',\n modelId: this.modelId,\n }),\n headers: combineHeaders(this.config.headers?.(), options.headers),\n body: requestBody,\n failedResponseHandler: humeFailedResponseHandler,\n successfulResponseHandler: createBinaryResponseHandler(),\n abortSignal: options.abortSignal,\n fetch: this.config.fetch,\n });\n\n return {\n audio,\n warnings,\n request: {\n body: JSON.stringify(requestBody),\n },\n response: {\n timestamp: currentDate,\n modelId: this.modelId,\n headers: responseHeaders,\n body: rawResponse,\n },\n };\n }\n}\n","import { z } from 'zod/v4';\nimport { createJsonErrorResponseHandler } from '@ai-sdk/provider-utils';\n\nexport const humeErrorDataSchema = z.object({\n error: z.object({\n message: z.string(),\n code: z.number(),\n }),\n});\n\nexport type HumeErrorData = z.infer<typeof humeErrorDataSchema>;\n\nexport const humeFailedResponseHandler = createJsonErrorResponseHandler({\n errorSchema: humeErrorDataSchema,\n errorToMessage: data => data.error.message,\n});\n","import { z } from 'zod/v4';\n\n// https://dev.hume.ai/reference/text-to-speech-tts/synthesize-file\nexport const humeSpeechModelOptionsSchema = z.object({\n /**\n * Context for the speech synthesis request.\n * Can be either a generationId for retrieving a previous generation,\n * or a list of utterances to synthesize.\n */\n context: z\n .object({\n /**\n * ID of a previously generated speech synthesis to retrieve.\n */\n generationId: z.string(),\n })\n .or(\n z.object({\n /**\n * List of utterances to synthesize into speech.\n */\n utterances: z.array(\n z.object({\n /**\n * The text content to convert to speech.\n */\n text: z.string(),\n /**\n * Optional description or instructions for how the text should be spoken.\n */\n description: z.string().optional(),\n /**\n * Optional speech rate multiplier.\n */\n speed: z.number().optional(),\n /**\n * Optional duration of silence to add after the utterance in seconds.\n */\n trailingSilence: z.number().optional(),\n /**\n * Voice configuration for the utterance.\n * Can be specified by ID or name.\n */\n voice: z\n .object({\n /**\n * ID of the voice to use.\n */\n id: z.string(),\n /**\n * Provider of the voice, either Hume's built-in voices or a custom voice.\n */\n provider: z.enum(['HUME_AI', 'CUSTOM_VOICE']).optional(),\n })\n .or(\n z.object({\n /**\n * Name of the voice to use.\n */\n name: z.string(),\n /**\n * Provider of the voice, either Hume's built-in voices or a custom voice.\n */\n provider: z.enum(['HUME_AI', 'CUSTOM_VOICE']).optional(),\n }),\n )\n .optional(),\n }),\n ),\n }),\n )\n .nullish(),\n});\n\nexport type HumeSpeechModelOptions = z.infer<\n typeof humeSpeechModelOptionsSchema\n>;\n","// Version string of this package injected at build time.\ndeclare const __PACKAGE_VERSION__: string | undefined;\nexport const VERSION: string =\n typeof __PACKAGE_VERSION__ !== 'undefined'\n ? __PACKAGE_VERSION__\n : '0.0.0-test';\n"],"mappings":";AAAA;AAAA,EACE;AAAA,OAGK;AACP;AAAA,EACE;AAAA,EACA;AAAA,OAEK;;;ACRP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;;;ACTP,SAAS,SAAS;AAClB,SAAS,sCAAsC;AAExC,IAAM,sBAAsB,EAAE,OAAO;AAAA,EAC1C,OAAO,EAAE,OAAO;AAAA,IACd,SAAS,EAAE,OAAO;AAAA,IAClB,MAAM,EAAE,OAAO;AAAA,EACjB,CAAC;AACH,CAAC;AAIM,IAAM,4BAA4B,+BAA+B;AAAA,EACtE,aAAa;AAAA,EACb,gBAAgB,UAAQ,KAAK,MAAM;AACrC,CAAC;;;ACfD,SAAS,KAAAA,UAAS;AAGX,IAAM,+BAA+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S,WAAW,UAAgC,CAAC,GAAiB;AAC3E,QAAM,aAAa,MACjB;AAAA,IACE;AAAA,MACE,kBAAkB,WAAW;AAAA,QAC3B,QAAQ,QAAQ;AAAA,QAChB,yBAAyB;AAAA,QACzB,aAAa;AAAA,MACf,CAAC;AAAA,MACD,GAAG,QAAQ;AAAA,IACb;AAAA,IACA,eAAe,OAAO;AAAA,EACxB;AAEF,QAAM,oBAAoB,MACxB,IAAI,gBAAgB,IAAI;AAAA,IACtB,UAAU;AAAA,IACV,KAAK,CAAC,EAAE,KAAK,MAAM,sBAAsB,IAAI;AAAA,IAC7C,SAAS;AAAA,IACT,OAAO,QAAQ;AAAA,EACjB,CAAC;AAEH,QAAM,WAAW,WAAY;AAC3B,WAAO;AAAA,MACL,QAAQ,kBAAkB;AAAA,IAC5B;AAAA,EACF;AAEA,WAAS,uBAAuB;AAChC,WAAS,SAAS;AAClB,WAAS,cAAc;AAEvB,WAAS,gBAAgB,CAAC,YAAoB;AAC5C,UAAM,IAAI,iBAAiB;AAAA,MACzB;AAAA,MACA,WAAW;AAAA,MACX,SAAS;AAAA,IACX,CAAC;AAAA,EACH;AAEA,WAAS,iBAAiB,CAAC,YAAoB;AAC7C,UAAM,IAAI,iBAAiB;AAAA,MACzB;AAAA,MACA,WAAW;AAAA,MACX,SAAS;AAAA,IACX,CAAC;AAAA,EACH;AAEA,WAAS,aAAa,CAAC,YAAoB;AACzC,UAAM,IAAI,iBAAiB;AAAA,MACzB;AAAA,MACA,WAAW;AAAA,MACX,SAAS;AAAA,IACX,CAAC;AAAA,EACH;AAEA,SAAO;AACT;AAKO,IAAM,OAAO,WAAW;","names":["z"]}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/hume-error.ts","../src/hume-speech-model-options.ts","../src/hume-speech-model.ts","../src/version.ts","../src/hume-provider.ts"],"sourcesContent":["import { z } from 'zod/v4';\nimport { createJsonErrorResponseHandler } from '@ai-sdk/provider-utils';\n\nexport const humeErrorDataSchema = z.object({\n error: z.object({\n message: z.string(),\n code: z.number(),\n }),\n});\n\nexport type HumeErrorData = z.infer<typeof humeErrorDataSchema>;\n\nexport const humeFailedResponseHandler = createJsonErrorResponseHandler({\n errorSchema: humeErrorDataSchema,\n errorToMessage: data => data.error.message,\n});\n","import { z } from 'zod/v4';\n\n// https://dev.hume.ai/reference/text-to-speech-tts/synthesize-file\nexport const humeSpeechModelOptionsSchema = z.object({\n /**\n * Context for the speech synthesis request.\n * Can be either a generationId for retrieving a previous generation,\n * or a list of utterances to synthesize.\n */\n context: z\n .object({\n /**\n * ID of a previously generated speech synthesis to retrieve.\n */\n generationId: z.string(),\n })\n .or(\n z.object({\n /**\n * List of utterances to synthesize into speech.\n */\n utterances: z.array(\n z.object({\n /**\n * The text content to convert to speech.\n */\n text: z.string(),\n /**\n * Optional description or instructions for how the text should be spoken.\n */\n description: z.string().optional(),\n /**\n * Optional speech rate multiplier.\n */\n speed: z.number().optional(),\n /**\n * Optional duration of silence to add after the utterance in seconds.\n */\n trailingSilence: z.number().optional(),\n /**\n * Voice configuration for the utterance.\n * Can be specified by ID or name.\n */\n voice: z\n .object({\n /**\n * ID of the voice to use.\n */\n id: z.string(),\n /**\n * Provider of the voice, either Hume's built-in voices or a custom voice.\n */\n provider: z.enum(['HUME_AI', 'CUSTOM_VOICE']).optional(),\n })\n .or(\n z.object({\n /**\n * Name of the voice to use.\n */\n name: z.string(),\n /**\n * Provider of the voice, either Hume's built-in voices or a custom voice.\n */\n provider: z.enum(['HUME_AI', 'CUSTOM_VOICE']).optional(),\n }),\n )\n .optional(),\n }),\n ),\n }),\n )\n .nullish(),\n});\n\nexport type HumeSpeechModelOptions = z.infer<\n typeof humeSpeechModelOptionsSchema\n>;\n","import type { SpeechModelV4, SharedV4Warning } from '@ai-sdk/provider';\nimport {\n combineHeaders,\n createBinaryResponseHandler,\n parseProviderOptions,\n postJsonToApi,\n serializeModelOptions,\n WORKFLOW_SERIALIZE,\n WORKFLOW_DESERIALIZE,\n} from '@ai-sdk/provider-utils';\nimport type { HumeConfig } from './hume-config';\nimport { humeFailedResponseHandler } from './hume-error';\nimport { humeSpeechModelOptionsSchema } from './hume-speech-model-options';\nimport type { HumeSpeechAPITypes } from './hume-api-types';\n\ninterface HumeSpeechModelConfig extends HumeConfig {\n _internal?: {\n currentDate?: () => Date;\n };\n}\n\nexport class HumeSpeechModel implements SpeechModelV4 {\n readonly specificationVersion = 'v4';\n\n get provider(): string {\n return this.config.provider;\n }\n\n static [WORKFLOW_SERIALIZE](model: HumeSpeechModel) {\n return serializeModelOptions({\n modelId: model.modelId,\n config: model.config,\n });\n }\n\n static [WORKFLOW_DESERIALIZE](options: {\n modelId: '';\n config: HumeSpeechModelConfig;\n }) {\n return new HumeSpeechModel(options.modelId as '', options.config);\n }\n\n constructor(\n readonly modelId: '',\n private readonly config: HumeSpeechModelConfig,\n ) {}\n\n private async getArgs({\n text,\n voice = 'd8ab67c6-953d-4bd8-9370-8fa53a0f1453',\n outputFormat = 'mp3',\n speed,\n instructions,\n language,\n providerOptions,\n }: Parameters<SpeechModelV4['doGenerate']>[0]) {\n const warnings: SharedV4Warning[] = [];\n\n // Parse provider options\n const humeOptions = await parseProviderOptions({\n provider: 'hume',\n providerOptions,\n schema: humeSpeechModelOptionsSchema,\n });\n\n // Create request body\n const requestBody: HumeSpeechAPITypes = {\n utterances: [\n {\n text,\n speed,\n description: instructions,\n voice: {\n id: voice,\n provider: 'HUME_AI',\n },\n },\n ],\n format: { type: 'mp3' },\n };\n\n if (outputFormat) {\n if (['mp3', 'pcm', 'wav'].includes(outputFormat)) {\n requestBody.format = { type: outputFormat as 'mp3' | 'pcm' | 'wav' };\n } else {\n warnings.push({\n type: 'unsupported',\n feature: 'outputFormat',\n details: `Unsupported output format: ${outputFormat}. Using mp3 instead.`,\n });\n }\n }\n\n // Add provider-specific options\n if (humeOptions) {\n const speechModelOptions: Omit<\n HumeSpeechAPITypes,\n 'utterances' | 'format'\n > = {};\n\n if (humeOptions.context) {\n if ('generationId' in humeOptions.context) {\n speechModelOptions.context = {\n generation_id: humeOptions.context.generationId,\n };\n } else {\n speechModelOptions.context = {\n utterances: humeOptions.context.utterances.map(utterance => ({\n text: utterance.text,\n description: utterance.description,\n speed: utterance.speed,\n trailing_silence: utterance.trailingSilence,\n voice: utterance.voice,\n })),\n };\n }\n }\n\n for (const key in speechModelOptions) {\n const value =\n speechModelOptions[\n key as keyof Omit<HumeSpeechAPITypes, 'utterances' | 'format'>\n ];\n if (value !== undefined) {\n (requestBody as Record<string, unknown>)[key] = value;\n }\n }\n }\n\n if (language) {\n warnings.push({\n type: 'unsupported',\n feature: 'language',\n details: `Hume speech models do not support language selection. Language parameter \"${language}\" was ignored.`,\n });\n }\n\n return {\n requestBody,\n warnings,\n };\n }\n\n async doGenerate(\n options: Parameters<SpeechModelV4['doGenerate']>[0],\n ): Promise<Awaited<ReturnType<SpeechModelV4['doGenerate']>>> {\n const currentDate = this.config._internal?.currentDate?.() ?? new Date();\n const { requestBody, warnings } = await this.getArgs(options);\n\n const {\n value: audio,\n responseHeaders,\n rawValue: rawResponse,\n } = await postJsonToApi({\n url: this.config.url({\n path: '/v0/tts/file',\n modelId: this.modelId,\n }),\n headers: combineHeaders(this.config.headers?.(), options.headers),\n body: requestBody,\n failedResponseHandler: humeFailedResponseHandler,\n successfulResponseHandler: createBinaryResponseHandler(),\n abortSignal: options.abortSignal,\n fetch: this.config.fetch,\n });\n\n return {\n audio,\n warnings,\n request: {\n body: JSON.stringify(requestBody),\n },\n response: {\n timestamp: currentDate,\n modelId: this.modelId,\n headers: responseHeaders,\n body: rawResponse,\n },\n };\n }\n}\n","// Version string of this package injected at build time.\ndeclare const __PACKAGE_VERSION__: string | undefined;\nexport const VERSION: string =\n typeof __PACKAGE_VERSION__ !== 'undefined'\n ? __PACKAGE_VERSION__\n : '0.0.0-test';\n","import {\n NoSuchModelError,\n type SpeechModelV4,\n type ProviderV4,\n} from '@ai-sdk/provider';\nimport {\n loadApiKey,\n withUserAgentSuffix,\n type FetchFunction,\n} from '@ai-sdk/provider-utils';\nimport { HumeSpeechModel } from './hume-speech-model';\nimport { VERSION } from './version';\n\nexport interface HumeProvider extends ProviderV4 {\n (settings?: {}): {\n speech: HumeSpeechModel;\n };\n\n /**\n * Creates a model for speech synthesis.\n */\n speech(): SpeechModelV4;\n}\n\nexport interface HumeProviderSettings {\n /**\n * API key for authenticating requests.\n */\n apiKey?: string;\n\n /**\n * Custom headers to include in the requests.\n */\n headers?: Record<string, string>;\n\n /**\n * Custom fetch implementation. You can use it as a middleware to intercept requests,\n * or to provide a custom fetch implementation for e.g. testing.\n */\n fetch?: FetchFunction;\n}\n\n/**\n * Create an Hume provider instance.\n */\nexport function createHume(options: HumeProviderSettings = {}): HumeProvider {\n const getHeaders = () =>\n withUserAgentSuffix(\n {\n 'X-Hume-Api-Key': loadApiKey({\n apiKey: options.apiKey,\n environmentVariableName: 'HUME_API_KEY',\n description: 'Hume',\n }),\n ...options.headers,\n },\n `ai-sdk-hume/${VERSION}`,\n );\n\n const createSpeechModel = () =>\n new HumeSpeechModel('', {\n provider: `hume.speech`,\n url: ({ path }) => `https://api.hume.ai${path}`,\n headers: getHeaders,\n fetch: options.fetch,\n });\n\n const provider = function () {\n return {\n speech: createSpeechModel(),\n };\n };\n\n provider.specificationVersion = 'v4' as const;\n provider.speech = createSpeechModel;\n provider.speechModel = createSpeechModel;\n\n provider.languageModel = (modelId: string) => {\n throw new NoSuchModelError({\n modelId,\n modelType: 'languageModel',\n message: 'Hume does not provide language models',\n });\n };\n\n provider.embeddingModel = (modelId: string) => {\n throw new NoSuchModelError({\n modelId,\n modelType: 'embeddingModel',\n message: 'Hume does not provide embedding models',\n });\n };\n\n provider.imageModel = (modelId: string) => {\n throw new NoSuchModelError({\n modelId,\n modelType: 'imageModel',\n message: 'Hume does not provide image models',\n });\n };\n\n return provider as HumeProvider;\n}\n\n/**\n * Default Hume provider instance.\n */\nexport const hume = createHume();\n"],"mappings":";;;;AAGA,MAAa,sBAAsB,EAAE,OAA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Aa,OAAO,WAAW"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-sdk/hume",
3
- "version": "3.0.51",
3
+ "version": "3.0.53",
4
4
  "type": "module",
5
5
  "license": "Apache-2.0",
6
6
  "sideEffects": false,
@@ -29,14 +29,14 @@
29
29
  }
30
30
  },
31
31
  "dependencies": {
32
- "@ai-sdk/provider": "4.0.19",
33
- "@ai-sdk/provider-utils": "5.0.51"
32
+ "@ai-sdk/provider": "4.0.21",
33
+ "@ai-sdk/provider-utils": "5.0.53"
34
34
  },
35
35
  "devDependencies": {
36
- "@ai-sdk/test-server": "2.0.2",
36
+ "@ai-sdk/test-server": "2.0.3",
37
37
  "@types/node": "22.19.19",
38
38
  "@vercel/ai-tsconfig": "0.0.0",
39
- "tsup": "^8.5.1",
39
+ "tsdown": "^0.23.0",
40
40
  "typescript": "5.6.3",
41
41
  "zod": "3.25.76"
42
42
  },
@@ -63,9 +63,9 @@
63
63
  "ai"
64
64
  ],
65
65
  "scripts": {
66
- "build": "tsup --tsconfig tsconfig.build.json",
67
- "build:watch": "tsup --tsconfig tsconfig.build.json --watch",
68
- "clean": "del-cli dist docs",
66
+ "build": "tsdown",
67
+ "build:watch": "tsdown --watch",
68
+ "clean": "del-cli docs",
69
69
  "type-check": "tsc --noEmit",
70
70
  "test": "pnpm test:node && pnpm test:edge",
71
71
  "test:watch": "vitest --config vitest.node.config.js --watch",