@ai-sdk/hume 3.0.0-beta.3 → 3.0.0-beta.31

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/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/hume-provider.ts","../src/hume-speech-model.ts","../src/hume-error.ts","../src/version.ts"],"sourcesContent":["export { createHume, hume } from './hume-provider';\nexport type { HumeProvider, HumeProviderSettings } from './hume-provider';\nexport type { HumeSpeechModelOptions } from './hume-speech-model';\nexport { VERSION } from './version';\n","import { SpeechModelV3, ProviderV3 } from '@ai-sdk/provider';\nimport {\n FetchFunction,\n loadApiKey,\n withUserAgentSuffix,\n} from '@ai-sdk/provider-utils';\nimport { HumeSpeechModel } from './hume-speech-model';\nimport { VERSION } from './version';\n\nexport interface HumeProvider extends Pick<ProviderV3, 'speechModel'> {\n (settings?: {}): {\n speech: HumeSpeechModel;\n };\n\n /**\n * Creates a model for speech synthesis.\n */\n speech(): SpeechModelV3;\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.speech = createSpeechModel;\n provider.speechModel = createSpeechModel;\n\n return provider satisfies HumeProvider;\n}\n\n/**\n * Default Hume provider instance.\n */\nexport const hume = createHume();\n","import { SpeechModelV3, SharedV3Warning } from '@ai-sdk/provider';\nimport {\n combineHeaders,\n createBinaryResponseHandler,\n parseProviderOptions,\n postJsonToApi,\n} from '@ai-sdk/provider-utils';\nimport { z } from 'zod/v4';\nimport { HumeConfig } from './hume-config';\nimport { humeFailedResponseHandler } from './hume-error';\nimport { HumeSpeechAPITypes } from './hume-api-types';\n\n// https://dev.hume.ai/reference/text-to-speech-tts/synthesize-file\nconst 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\ninterface HumeSpeechModelConfig extends HumeConfig {\n _internal?: {\n currentDate?: () => Date;\n };\n}\n\nexport class HumeSpeechModel implements SpeechModelV3 {\n readonly specificationVersion = 'v3';\n\n get provider(): string {\n return this.config.provider;\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<SpeechModelV3['doGenerate']>[0]) {\n const warnings: SharedV3Warning[] = [];\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<SpeechModelV3['doGenerate']>[0],\n ): Promise<Awaited<ReturnType<SpeechModelV3['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","// 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;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCA,IAAAA,yBAIO;;;ACJP,IAAAC,yBAKO;AACP,IAAAC,aAAkB;;;ACPlB,gBAAkB;AAClB,4BAA+C;AAExC,IAAM,sBAAsB,Y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AS,WAAW,UAAgC,CAAC,GAAiB;AAC3E,QAAM,aAAa,UACjB;AAAA,IACE;AAAA,MACE,sBAAkB,mCAAW;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,SAAS;AAClB,WAAS,cAAc;AAEvB,SAAO;AACT;AAKO,IAAM,OAAO,WAAW;","names":["import_provider_utils","import_provider_utils","import_v4"]}
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;AACr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AAM;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACF;;;AGlLO,IAAM,UACX,OACI,kBACA;;;AJwCC,SAAS,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"]}
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@ai-sdk/hume",
3
- "version": "3.0.0-beta.3",
3
+ "version": "3.0.0-beta.31",
4
+ "type": "module",
4
5
  "license": "Apache-2.0",
5
6
  "sideEffects": false,
6
7
  "main": "./dist/index.js",
7
- "module": "./dist/index.mjs",
8
8
  "types": "./dist/index.d.ts",
9
9
  "files": [
10
10
  "dist/**/*",
@@ -24,20 +24,20 @@
24
24
  "./package.json": "./package.json",
25
25
  ".": {
26
26
  "types": "./dist/index.d.ts",
27
- "import": "./dist/index.mjs",
28
- "require": "./dist/index.js"
27
+ "import": "./dist/index.js",
28
+ "default": "./dist/index.js"
29
29
  }
30
30
  },
31
31
  "dependencies": {
32
- "@ai-sdk/provider": "4.0.0-beta.2",
33
- "@ai-sdk/provider-utils": "5.0.0-beta.3"
32
+ "@ai-sdk/provider": "4.0.0-beta.14",
33
+ "@ai-sdk/provider-utils": "5.0.0-beta.30"
34
34
  },
35
35
  "devDependencies": {
36
36
  "@types/node": "20.17.24",
37
37
  "tsup": "^8",
38
38
  "typescript": "5.6.3",
39
39
  "zod": "3.25.76",
40
- "@ai-sdk/test-server": "2.0.0-beta.0",
40
+ "@ai-sdk/test-server": "2.0.0-beta.3",
41
41
  "@vercel/ai-tsconfig": "0.0.0"
42
42
  },
43
43
  "peerDependencies": {
@@ -47,12 +47,14 @@
47
47
  "node": ">=18"
48
48
  },
49
49
  "publishConfig": {
50
- "access": "public"
50
+ "access": "public",
51
+ "provenance": true
51
52
  },
52
53
  "homepage": "https://ai-sdk.dev/docs",
53
54
  "repository": {
54
55
  "type": "git",
55
- "url": "git+https://github.com/vercel/ai.git"
56
+ "url": "https://github.com/vercel/ai",
57
+ "directory": "packages/hume"
56
58
  },
57
59
  "bugs": {
58
60
  "url": "https://github.com/vercel/ai/issues"
@@ -64,9 +66,7 @@
64
66
  "build": "tsup --tsconfig tsconfig.build.json",
65
67
  "build:watch": "tsup --tsconfig tsconfig.build.json --watch",
66
68
  "clean": "del-cli dist docs",
67
- "lint": "eslint \"./**/*.ts*\"",
68
69
  "type-check": "tsc --noEmit",
69
- "prettier-check": "prettier --check \"./**/*.ts*\"",
70
70
  "test": "pnpm test:node && pnpm test:edge",
71
71
  "test:watch": "vitest --config vitest.node.config.js --watch",
72
72
  "test:edge": "vitest --config vitest.edge.config.js --run",
@@ -1,9 +1,9 @@
1
- import { FetchFunction } from '@ai-sdk/provider-utils';
1
+ import type { FetchFunction } from '@ai-sdk/provider-utils';
2
2
 
3
3
  export type HumeConfig = {
4
4
  provider: string;
5
5
  url: (options: { modelId: string; path: string }) => string;
6
- headers: () => Record<string, string | undefined>;
6
+ headers?: () => Record<string, string | undefined>;
7
7
  fetch?: FetchFunction;
8
8
  generateId?: () => string;
9
9
  };
@@ -1,13 +1,17 @@
1
- import { SpeechModelV3, ProviderV3 } from '@ai-sdk/provider';
2
1
  import {
3
- FetchFunction,
2
+ NoSuchModelError,
3
+ type SpeechModelV4,
4
+ type ProviderV4,
5
+ } from '@ai-sdk/provider';
6
+ import {
4
7
  loadApiKey,
5
8
  withUserAgentSuffix,
9
+ type FetchFunction,
6
10
  } from '@ai-sdk/provider-utils';
7
11
  import { HumeSpeechModel } from './hume-speech-model';
8
12
  import { VERSION } from './version';
9
13
 
10
- export interface HumeProvider extends Pick<ProviderV3, 'speechModel'> {
14
+ export interface HumeProvider extends ProviderV4 {
11
15
  (settings?: {}): {
12
16
  speech: HumeSpeechModel;
13
17
  };
@@ -15,7 +19,7 @@ export interface HumeProvider extends Pick<ProviderV3, 'speechModel'> {
15
19
  /**
16
20
  * Creates a model for speech synthesis.
17
21
  */
18
- speech(): SpeechModelV3;
22
+ speech(): SpeechModelV4;
19
23
  }
20
24
 
21
25
  export interface HumeProviderSettings {
@@ -67,10 +71,35 @@ export function createHume(options: HumeProviderSettings = {}): HumeProvider {
67
71
  };
68
72
  };
69
73
 
74
+ provider.specificationVersion = 'v4' as const;
70
75
  provider.speech = createSpeechModel;
71
76
  provider.speechModel = createSpeechModel;
72
77
 
73
- return provider satisfies HumeProvider;
78
+ provider.languageModel = (modelId: string) => {
79
+ throw new NoSuchModelError({
80
+ modelId,
81
+ modelType: 'languageModel',
82
+ message: 'Hume does not provide language models',
83
+ });
84
+ };
85
+
86
+ provider.embeddingModel = (modelId: string) => {
87
+ throw new NoSuchModelError({
88
+ modelId,
89
+ modelType: 'embeddingModel',
90
+ message: 'Hume does not provide embedding models',
91
+ });
92
+ };
93
+
94
+ provider.imageModel = (modelId: string) => {
95
+ throw new NoSuchModelError({
96
+ modelId,
97
+ modelType: 'imageModel',
98
+ message: 'Hume does not provide image models',
99
+ });
100
+ };
101
+
102
+ return provider as HumeProvider;
74
103
  }
75
104
 
76
105
  /**
@@ -0,0 +1,77 @@
1
+ import { z } from 'zod/v4';
2
+
3
+ // https://dev.hume.ai/reference/text-to-speech-tts/synthesize-file
4
+ export const humeSpeechModelOptionsSchema = z.object({
5
+ /**
6
+ * Context for the speech synthesis request.
7
+ * Can be either a generationId for retrieving a previous generation,
8
+ * or a list of utterances to synthesize.
9
+ */
10
+ context: z
11
+ .object({
12
+ /**
13
+ * ID of a previously generated speech synthesis to retrieve.
14
+ */
15
+ generationId: z.string(),
16
+ })
17
+ .or(
18
+ z.object({
19
+ /**
20
+ * List of utterances to synthesize into speech.
21
+ */
22
+ utterances: z.array(
23
+ z.object({
24
+ /**
25
+ * The text content to convert to speech.
26
+ */
27
+ text: z.string(),
28
+ /**
29
+ * Optional description or instructions for how the text should be spoken.
30
+ */
31
+ description: z.string().optional(),
32
+ /**
33
+ * Optional speech rate multiplier.
34
+ */
35
+ speed: z.number().optional(),
36
+ /**
37
+ * Optional duration of silence to add after the utterance in seconds.
38
+ */
39
+ trailingSilence: z.number().optional(),
40
+ /**
41
+ * Voice configuration for the utterance.
42
+ * Can be specified by ID or name.
43
+ */
44
+ voice: z
45
+ .object({
46
+ /**
47
+ * ID of the voice to use.
48
+ */
49
+ id: z.string(),
50
+ /**
51
+ * Provider of the voice, either Hume's built-in voices or a custom voice.
52
+ */
53
+ provider: z.enum(['HUME_AI', 'CUSTOM_VOICE']).optional(),
54
+ })
55
+ .or(
56
+ z.object({
57
+ /**
58
+ * Name of the voice to use.
59
+ */
60
+ name: z.string(),
61
+ /**
62
+ * Provider of the voice, either Hume's built-in voices or a custom voice.
63
+ */
64
+ provider: z.enum(['HUME_AI', 'CUSTOM_VOICE']).optional(),
65
+ }),
66
+ )
67
+ .optional(),
68
+ }),
69
+ ),
70
+ }),
71
+ )
72
+ .nullish(),
73
+ });
74
+
75
+ export type HumeSpeechModelOptions = z.infer<
76
+ typeof humeSpeechModelOptionsSchema
77
+ >;
@@ -1,90 +1,17 @@
1
- import { SpeechModelV3, SharedV3Warning } from '@ai-sdk/provider';
1
+ import type { SpeechModelV4, SharedV4Warning } from '@ai-sdk/provider';
2
2
  import {
3
3
  combineHeaders,
4
4
  createBinaryResponseHandler,
5
5
  parseProviderOptions,
6
6
  postJsonToApi,
7
+ serializeModelOptions,
8
+ WORKFLOW_SERIALIZE,
9
+ WORKFLOW_DESERIALIZE,
7
10
  } from '@ai-sdk/provider-utils';
8
- import { z } from 'zod/v4';
9
- import { HumeConfig } from './hume-config';
11
+ import type { HumeConfig } from './hume-config';
10
12
  import { humeFailedResponseHandler } from './hume-error';
11
- import { HumeSpeechAPITypes } from './hume-api-types';
12
-
13
- // https://dev.hume.ai/reference/text-to-speech-tts/synthesize-file
14
- const humeSpeechModelOptionsSchema = z.object({
15
- /**
16
- * Context for the speech synthesis request.
17
- * Can be either a generationId for retrieving a previous generation,
18
- * or a list of utterances to synthesize.
19
- */
20
- context: z
21
- .object({
22
- /**
23
- * ID of a previously generated speech synthesis to retrieve.
24
- */
25
- generationId: z.string(),
26
- })
27
- .or(
28
- z.object({
29
- /**
30
- * List of utterances to synthesize into speech.
31
- */
32
- utterances: z.array(
33
- z.object({
34
- /**
35
- * The text content to convert to speech.
36
- */
37
- text: z.string(),
38
- /**
39
- * Optional description or instructions for how the text should be spoken.
40
- */
41
- description: z.string().optional(),
42
- /**
43
- * Optional speech rate multiplier.
44
- */
45
- speed: z.number().optional(),
46
- /**
47
- * Optional duration of silence to add after the utterance in seconds.
48
- */
49
- trailingSilence: z.number().optional(),
50
- /**
51
- * Voice configuration for the utterance.
52
- * Can be specified by ID or name.
53
- */
54
- voice: z
55
- .object({
56
- /**
57
- * ID of the voice to use.
58
- */
59
- id: z.string(),
60
- /**
61
- * Provider of the voice, either Hume's built-in voices or a custom voice.
62
- */
63
- provider: z.enum(['HUME_AI', 'CUSTOM_VOICE']).optional(),
64
- })
65
- .or(
66
- z.object({
67
- /**
68
- * Name of the voice to use.
69
- */
70
- name: z.string(),
71
- /**
72
- * Provider of the voice, either Hume's built-in voices or a custom voice.
73
- */
74
- provider: z.enum(['HUME_AI', 'CUSTOM_VOICE']).optional(),
75
- }),
76
- )
77
- .optional(),
78
- }),
79
- ),
80
- }),
81
- )
82
- .nullish(),
83
- });
84
-
85
- export type HumeSpeechModelOptions = z.infer<
86
- typeof humeSpeechModelOptionsSchema
87
- >;
13
+ import { humeSpeechModelOptionsSchema } from './hume-speech-model-options';
14
+ import type { HumeSpeechAPITypes } from './hume-api-types';
88
15
 
89
16
  interface HumeSpeechModelConfig extends HumeConfig {
90
17
  _internal?: {
@@ -92,13 +19,27 @@ interface HumeSpeechModelConfig extends HumeConfig {
92
19
  };
93
20
  }
94
21
 
95
- export class HumeSpeechModel implements SpeechModelV3 {
96
- readonly specificationVersion = 'v3';
22
+ export class HumeSpeechModel implements SpeechModelV4 {
23
+ readonly specificationVersion = 'v4';
97
24
 
98
25
  get provider(): string {
99
26
  return this.config.provider;
100
27
  }
101
28
 
29
+ static [WORKFLOW_SERIALIZE](model: HumeSpeechModel) {
30
+ return serializeModelOptions({
31
+ modelId: model.modelId,
32
+ config: model.config,
33
+ });
34
+ }
35
+
36
+ static [WORKFLOW_DESERIALIZE](options: {
37
+ modelId: '';
38
+ config: HumeSpeechModelConfig;
39
+ }) {
40
+ return new HumeSpeechModel(options.modelId as '', options.config);
41
+ }
42
+
102
43
  constructor(
103
44
  readonly modelId: '',
104
45
  private readonly config: HumeSpeechModelConfig,
@@ -112,8 +53,8 @@ export class HumeSpeechModel implements SpeechModelV3 {
112
53
  instructions,
113
54
  language,
114
55
  providerOptions,
115
- }: Parameters<SpeechModelV3['doGenerate']>[0]) {
116
- const warnings: SharedV3Warning[] = [];
56
+ }: Parameters<SpeechModelV4['doGenerate']>[0]) {
57
+ const warnings: SharedV4Warning[] = [];
117
58
 
118
59
  // Parse provider options
119
60
  const humeOptions = await parseProviderOptions({
@@ -201,8 +142,8 @@ export class HumeSpeechModel implements SpeechModelV3 {
201
142
  }
202
143
 
203
144
  async doGenerate(
204
- options: Parameters<SpeechModelV3['doGenerate']>[0],
205
- ): Promise<Awaited<ReturnType<SpeechModelV3['doGenerate']>>> {
145
+ options: Parameters<SpeechModelV4['doGenerate']>[0],
146
+ ): Promise<Awaited<ReturnType<SpeechModelV4['doGenerate']>>> {
206
147
  const currentDate = this.config._internal?.currentDate?.() ?? new Date();
207
148
  const { requestBody, warnings } = await this.getArgs(options);
208
149
 
@@ -215,7 +156,7 @@ export class HumeSpeechModel implements SpeechModelV3 {
215
156
  path: '/v0/tts/file',
216
157
  modelId: this.modelId,
217
158
  }),
218
- headers: combineHeaders(this.config.headers(), options.headers),
159
+ headers: combineHeaders(this.config.headers?.(), options.headers),
219
160
  body: requestBody,
220
161
  failedResponseHandler: humeFailedResponseHandler,
221
162
  successfulResponseHandler: createBinaryResponseHandler(),
package/src/index.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  export { createHume, hume } from './hume-provider';
2
2
  export type { HumeProvider, HumeProviderSettings } from './hume-provider';
3
- export type { HumeSpeechModelOptions } from './hume-speech-model';
3
+ export type { HumeSpeechModelOptions } from './hume-speech-model-options';
4
4
  export { VERSION } from './version';
package/dist/index.d.mts DELETED
@@ -1,92 +0,0 @@
1
- import { SpeechModelV3, ProviderV3 } from '@ai-sdk/provider';
2
- import { FetchFunction } from '@ai-sdk/provider-utils';
3
- import { z } from 'zod/v4';
4
-
5
- type HumeConfig = {
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;
14
- };
15
-
16
- declare const humeSpeechModelOptionsSchema: z.ZodObject<{
17
- context: z.ZodOptional<z.ZodNullable<z.ZodUnion<[z.ZodObject<{
18
- generationId: z.ZodString;
19
- }, z.core.$strip>, z.ZodObject<{
20
- utterances: z.ZodArray<z.ZodObject<{
21
- text: z.ZodString;
22
- description: z.ZodOptional<z.ZodString>;
23
- speed: z.ZodOptional<z.ZodNumber>;
24
- trailingSilence: z.ZodOptional<z.ZodNumber>;
25
- voice: z.ZodOptional<z.ZodUnion<[z.ZodObject<{
26
- id: z.ZodString;
27
- provider: z.ZodOptional<z.ZodEnum<{
28
- HUME_AI: "HUME_AI";
29
- CUSTOM_VOICE: "CUSTOM_VOICE";
30
- }>>;
31
- }, z.core.$strip>, z.ZodObject<{
32
- name: z.ZodString;
33
- provider: z.ZodOptional<z.ZodEnum<{
34
- HUME_AI: "HUME_AI";
35
- CUSTOM_VOICE: "CUSTOM_VOICE";
36
- }>>;
37
- }, z.core.$strip>]>>;
38
- }, z.core.$strip>>;
39
- }, z.core.$strip>]>>>;
40
- }, z.core.$strip>;
41
- type HumeSpeechModelOptions = z.infer<typeof humeSpeechModelOptionsSchema>;
42
- interface HumeSpeechModelConfig extends HumeConfig {
43
- _internal?: {
44
- currentDate?: () => Date;
45
- };
46
- }
47
- declare class HumeSpeechModel implements SpeechModelV3 {
48
- readonly modelId: '';
49
- private readonly config;
50
- readonly specificationVersion = "v3";
51
- get provider(): string;
52
- constructor(modelId: '', config: HumeSpeechModelConfig);
53
- private getArgs;
54
- doGenerate(options: Parameters<SpeechModelV3['doGenerate']>[0]): Promise<Awaited<ReturnType<SpeechModelV3['doGenerate']>>>;
55
- }
56
-
57
- interface HumeProvider extends Pick<ProviderV3, 'speechModel'> {
58
- (settings?: {}): {
59
- speech: HumeSpeechModel;
60
- };
61
- /**
62
- * Creates a model for speech synthesis.
63
- */
64
- speech(): SpeechModelV3;
65
- }
66
- interface HumeProviderSettings {
67
- /**
68
- * API key for authenticating requests.
69
- */
70
- apiKey?: string;
71
- /**
72
- * Custom headers to include in the requests.
73
- */
74
- headers?: Record<string, string>;
75
- /**
76
- * Custom fetch implementation. You can use it as a middleware to intercept requests,
77
- * or to provide a custom fetch implementation for e.g. testing.
78
- */
79
- fetch?: FetchFunction;
80
- }
81
- /**
82
- * Create an Hume provider instance.
83
- */
84
- declare function createHume(options?: HumeProviderSettings): HumeProvider;
85
- /**
86
- * Default Hume provider instance.
87
- */
88
- declare const hume: HumeProvider;
89
-
90
- declare const VERSION: string;
91
-
92
- export { type HumeProvider, type HumeProviderSettings, type HumeSpeechModelOptions, VERSION, createHume, hume };