@ai-sdk/google
Advanced tools
| import { z } from 'zod/v4'; | ||
| export type GoogleTranscriptionModelId = | ||
| | 'gemini-3.5-transcribe' | ||
| | 'gemini-3.5-transcribe-live' | ||
| | (string & {}); | ||
| /** | ||
| * Speech recognition options for Gemini transcription models | ||
| * (`gemini-3.5-transcribe`). Maps onto Google's `AudioTranscriptionConfig`. | ||
| * The live variant (`gemini-3.5-transcribe-live`) requires streaming | ||
| * transcription, which is only available in AI SDK v7. | ||
| */ | ||
| export const googleTranscriptionModelOptions = z.object({ | ||
| /** | ||
| * BCP-47 language codes providing hints about the languages present in the | ||
| * audio. If omitted or empty, defaults to automatic language detection. | ||
| */ | ||
| languageCodes: z.array(z.string()).optional(), | ||
| /** | ||
| * Custom vocabulary phrases, which bias the speech recognition model | ||
| * toward recognizing specific terms. | ||
| */ | ||
| customVocabulary: z.array(z.string()).optional(), | ||
| /** | ||
| * Enables word-level timestamp generation. | ||
| */ | ||
| wordTimestamp: z.boolean().optional(), | ||
| /** | ||
| * Enables speaker diarization. | ||
| */ | ||
| diarization: z.boolean().optional(), | ||
| /** | ||
| * Transcription output formatting mode. | ||
| * | ||
| * - `VERBATIM` (default): exact literal transcript preserving filler | ||
| * words, repetitions, and false starts. | ||
| * - `SMART`: cleans up and structures the transcript in real time — | ||
| * disfluency removal, inline self-corrections, structured formatting | ||
| * (lists, numbers, dates, paragraph breaks), and grammar/casing polish. | ||
| */ | ||
| mode: z.enum(['SMART', 'VERBATIM']).optional(), | ||
| }); | ||
| export type GoogleTranscriptionModelOptions = z.infer< | ||
| typeof googleTranscriptionModelOptions | ||
| >; |
| import { | ||
| InvalidArgumentError, | ||
| type JSONObject, | ||
| type SharedV3Warning, | ||
| type TranscriptionModelV3, | ||
| } from '@ai-sdk/provider'; | ||
| import { | ||
| combineHeaders, | ||
| convertToBase64, | ||
| createJsonResponseHandler, | ||
| parseProviderOptions, | ||
| postJsonToApi, | ||
| resolve, | ||
| type FetchFunction, | ||
| type Resolvable, | ||
| } from '@ai-sdk/provider-utils'; | ||
| import { z } from 'zod/v4'; | ||
| import { googleFailedResponseHandler } from '../google-error'; | ||
| import { | ||
| googleTranscriptionModelOptions, | ||
| type GoogleTranscriptionModelId, | ||
| type GoogleTranscriptionModelOptions, | ||
| } from './google-transcription-model-options'; | ||
| /** | ||
| * Live transcription (`*-live` model variants) requires streaming support, | ||
| * which is only available in AI SDK v7 (transcription specification v4). | ||
| */ | ||
| function isLiveTranscriptionModelId(modelId: string): boolean { | ||
| return modelId.includes('-live'); | ||
| } | ||
| interface GoogleTranscriptionModelConfig { | ||
| provider: string; | ||
| baseURL: string; | ||
| headers?: Resolvable<Record<string, string | undefined>>; | ||
| fetch?: FetchFunction; | ||
| _internal?: { | ||
| currentDate?: () => Date; | ||
| }; | ||
| } | ||
| /** | ||
| * Gemini transcription (speech-to-text) via the Interactions API | ||
| * (e.g. `gemini-3.5-transcribe`). | ||
| * | ||
| * @see https://ai.google.dev/gemini-api/docs/transcribe | ||
| */ | ||
| export class GoogleTranscriptionModel implements TranscriptionModelV3 { | ||
| readonly specificationVersion = 'v3'; | ||
| get provider(): string { | ||
| return this.config.provider; | ||
| } | ||
| constructor( | ||
| readonly modelId: GoogleTranscriptionModelId, | ||
| private readonly config: GoogleTranscriptionModelConfig, | ||
| ) {} | ||
| private async parseOptions( | ||
| providerOptions: Record<string, unknown> | undefined, | ||
| ): Promise<GoogleTranscriptionModelOptions | undefined> { | ||
| return parseProviderOptions({ | ||
| provider: 'google', | ||
| providerOptions, | ||
| schema: googleTranscriptionModelOptions, | ||
| }); | ||
| } | ||
| async doGenerate( | ||
| options: Parameters<TranscriptionModelV3['doGenerate']>[0], | ||
| ): Promise<Awaited<ReturnType<TranscriptionModelV3['doGenerate']>>> { | ||
| if (isLiveTranscriptionModelId(this.modelId)) { | ||
| throw new InvalidArgumentError({ | ||
| argument: 'modelId', | ||
| message: | ||
| `Model '${this.modelId}' only supports streaming transcription, ` + | ||
| `which requires AI SDK v7. Use a unary model such as 'gemini-3.5-transcribe'.`, | ||
| }); | ||
| } | ||
| const currentDate = this.config._internal?.currentDate?.() ?? new Date(); | ||
| const warnings: SharedV3Warning[] = []; | ||
| const googleOptions = await this.parseOptions(options.providerOptions); | ||
| const transcriptionConfig = buildTranscriptionConfig(googleOptions); | ||
| // Unary transcription is served by the Interactions API | ||
| // (https://ai.google.dev/gemini-api/docs/transcribe). | ||
| const requestBody = { | ||
| model: this.modelId, | ||
| input: [ | ||
| { | ||
| type: 'audio', | ||
| data: convertToBase64(options.audio), | ||
| mime_type: options.mediaType, | ||
| }, | ||
| ], | ||
| ...(transcriptionConfig != null | ||
| ? { generation_config: { transcription_config: transcriptionConfig } } | ||
| : {}), | ||
| }; | ||
| const { | ||
| value: response, | ||
| responseHeaders, | ||
| rawValue: rawResponse, | ||
| } = await postJsonToApi({ | ||
| url: `${this.config.baseURL}/interactions`, | ||
| headers: combineHeaders( | ||
| this.config.headers ? await resolve(this.config.headers) : undefined, | ||
| options.headers, | ||
| ), | ||
| body: requestBody, | ||
| failedResponseHandler: googleFailedResponseHandler, | ||
| successfulResponseHandler: createJsonResponseHandler( | ||
| googleInteractionsTranscriptionResponseSchema, | ||
| ), | ||
| abortSignal: options.abortSignal, | ||
| fetch: this.config.fetch, | ||
| }); | ||
| let text = ''; | ||
| const segments: Array<{ | ||
| text: string; | ||
| startSecond: number; | ||
| endSecond: number; | ||
| }> = []; | ||
| for (const step of response.steps ?? []) { | ||
| for (const content of step.content ?? []) { | ||
| if (content.type !== 'text' || content.text == null) continue; | ||
| text += content.text; | ||
| for (const annotation of content.annotations ?? []) { | ||
| if (annotation.type !== 'word_info') continue; | ||
| const startSecond = parseOffsetSeconds(annotation.start_offset); | ||
| const endSecond = parseOffsetSeconds(annotation.end_offset); | ||
| if ( | ||
| annotation.text == null || | ||
| startSecond == null || | ||
| endSecond == null | ||
| ) { | ||
| continue; | ||
| } | ||
| segments.push({ text: annotation.text, startSecond, endSecond }); | ||
| } | ||
| } | ||
| } | ||
| return { | ||
| text, | ||
| segments, | ||
| language: undefined, | ||
| durationInSeconds: undefined, | ||
| warnings, | ||
| response: { | ||
| timestamp: currentDate, | ||
| modelId: this.modelId, | ||
| headers: responseHeaders, | ||
| body: rawResponse, | ||
| }, | ||
| ...(response.usage != null | ||
| ? { | ||
| providerMetadata: { | ||
| google: { usage: response.usage as JSONObject }, | ||
| }, | ||
| } | ||
| : {}), | ||
| }; | ||
| } | ||
| } | ||
| /** | ||
| * Builds the Interactions API `transcription_config` (snake_case wire) from | ||
| * provider options; returns undefined when no options are set. Diarization | ||
| * and word timestamps are expressed inside the `mode` object per | ||
| * https://ai.google.dev/gemini-api/docs/transcribe. | ||
| */ | ||
| function buildTranscriptionConfig( | ||
| options: GoogleTranscriptionModelOptions | undefined, | ||
| ): Record<string, unknown> | undefined { | ||
| if (options == null) return undefined; | ||
| const config: Record<string, unknown> = {}; | ||
| if (options.languageCodes != null) { | ||
| config.language_codes = options.languageCodes; | ||
| } | ||
| if (options.customVocabulary != null) { | ||
| config.custom_vocabulary = options.customVocabulary; | ||
| } | ||
| if ( | ||
| options.mode != null || | ||
| options.diarization === true || | ||
| options.wordTimestamp === true | ||
| ) { | ||
| config.mode = { | ||
| type: (options.mode ?? 'VERBATIM').toLowerCase(), | ||
| ...(options.diarization === true ? { diarization_mode: 'speaker' } : {}), | ||
| ...(options.wordTimestamp === true | ||
| ? { timestamp_granularities: ['word'] } | ||
| : {}), | ||
| }; | ||
| } | ||
| return Object.keys(config).length > 0 ? config : undefined; | ||
| } | ||
| /** Parses a Google duration offset such as `"1s"` or `"9.400s"` to seconds. */ | ||
| function parseOffsetSeconds( | ||
| offset: string | undefined | null, | ||
| ): number | undefined { | ||
| if (offset == null) return undefined; | ||
| const parsed = Number.parseFloat(offset); | ||
| return Number.isFinite(parsed) ? parsed : undefined; | ||
| } | ||
| const googleInteractionsWordAnnotationSchema = z.object({ | ||
| type: z.string().nullish(), | ||
| text: z.string().nullish(), | ||
| speaker: z.string().nullish(), | ||
| start_offset: z.string().nullish(), | ||
| end_offset: z.string().nullish(), | ||
| }); | ||
| const googleInteractionsTranscriptionResponseSchema = z.object({ | ||
| status: z.string().nullish(), | ||
| steps: z | ||
| .array( | ||
| z.object({ | ||
| type: z.string().nullish(), | ||
| content: z | ||
| .array( | ||
| z.object({ | ||
| type: z.string().nullish(), | ||
| text: z.string().nullish(), | ||
| annotations: z | ||
| .array(googleInteractionsWordAnnotationSchema) | ||
| .nullish(), | ||
| }), | ||
| ) | ||
| .nullish(), | ||
| }), | ||
| ) | ||
| .nullish(), | ||
| usage: z.record(z.string(), z.unknown()).nullish(), | ||
| }); |
+57
-3
| import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils'; | ||
| import { InferSchema, FetchFunction } from '@ai-sdk/provider-utils'; | ||
| import { ProviderV3, LanguageModelV3, ImageModelV3, EmbeddingModelV3, Experimental_VideoModelV3 } from '@ai-sdk/provider'; | ||
| import { InferSchema, Resolvable, FetchFunction } from '@ai-sdk/provider-utils'; | ||
| import { TranscriptionModelV3, ProviderV3, LanguageModelV3, ImageModelV3, EmbeddingModelV3, Experimental_VideoModelV3 } from '@ai-sdk/provider'; | ||
| import { z } from 'zod/v4'; | ||
@@ -409,2 +410,46 @@ declare const googleErrorDataSchema: _ai_sdk_provider_utils.LazySchema<{ | ||
| type GoogleTranscriptionModelId = 'gemini-3.5-transcribe' | 'gemini-3.5-transcribe-live' | (string & {}); | ||
| /** | ||
| * Speech recognition options for Gemini transcription models | ||
| * (`gemini-3.5-transcribe`). Maps onto Google's `AudioTranscriptionConfig`. | ||
| * The live variant (`gemini-3.5-transcribe-live`) requires streaming | ||
| * transcription, which is only available in AI SDK v7. | ||
| */ | ||
| declare const googleTranscriptionModelOptions: z.ZodObject<{ | ||
| languageCodes: z.ZodOptional<z.ZodArray<z.ZodString>>; | ||
| customVocabulary: z.ZodOptional<z.ZodArray<z.ZodString>>; | ||
| wordTimestamp: z.ZodOptional<z.ZodBoolean>; | ||
| diarization: z.ZodOptional<z.ZodBoolean>; | ||
| mode: z.ZodOptional<z.ZodEnum<{ | ||
| SMART: "SMART"; | ||
| VERBATIM: "VERBATIM"; | ||
| }>>; | ||
| }, z.core.$strip>; | ||
| type GoogleTranscriptionModelOptions = z.infer<typeof googleTranscriptionModelOptions>; | ||
| interface GoogleTranscriptionModelConfig { | ||
| provider: string; | ||
| baseURL: string; | ||
| headers?: Resolvable<Record<string, string | undefined>>; | ||
| fetch?: FetchFunction; | ||
| _internal?: { | ||
| currentDate?: () => Date; | ||
| }; | ||
| } | ||
| /** | ||
| * Gemini transcription (speech-to-text) via the Interactions API | ||
| * (e.g. `gemini-3.5-transcribe`). | ||
| * | ||
| * @see https://ai.google.dev/gemini-api/docs/transcribe | ||
| */ | ||
| declare class GoogleTranscriptionModel implements TranscriptionModelV3 { | ||
| readonly modelId: GoogleTranscriptionModelId; | ||
| private readonly config; | ||
| readonly specificationVersion = "v3"; | ||
| get provider(): string; | ||
| constructor(modelId: GoogleTranscriptionModelId, config: GoogleTranscriptionModelConfig); | ||
| private parseOptions; | ||
| doGenerate(options: Parameters<TranscriptionModelV3['doGenerate']>[0]): Promise<Awaited<ReturnType<TranscriptionModelV3['doGenerate']>>>; | ||
| } | ||
| declare const googleTools: { | ||
@@ -522,2 +567,11 @@ /** | ||
| /** | ||
| * Creates a model for transcription (speech-to-text), e.g. | ||
| * `gemini-3.5-transcribe`. | ||
| */ | ||
| transcription(modelId: GoogleTranscriptionModelId): TranscriptionModelV3; | ||
| /** | ||
| * Creates a model for transcription (speech-to-text). | ||
| */ | ||
| transcriptionModel(modelId: GoogleTranscriptionModelId): TranscriptionModelV3; | ||
| /** | ||
| * Creates a model for video generation. | ||
@@ -586,2 +640,2 @@ */ | ||
| export { type GoogleEmbeddingModelOptions, type GoogleErrorData, type GoogleEmbeddingModelOptions as GoogleGenerativeAIEmbeddingProviderOptions, type GoogleImageModelOptions as GoogleGenerativeAIImageProviderOptions, type GoogleGenerativeAIProvider, type GoogleGenerativeAIProviderMetadata, type GoogleLanguageModelOptions as GoogleGenerativeAIProviderOptions, type GoogleGenerativeAIProviderSettings, type GoogleGenerativeAIVideoModelId, type GoogleVideoModelOptions as GoogleGenerativeAIVideoProviderOptions, type GoogleImageModelOptions, type GoogleInteractionsAgentName, type GoogleInteractionsModelId, type GoogleInteractionsProviderMetadata, type GoogleLanguageModelInteractionsOptions, type GoogleLanguageModelOptions, type GoogleVideoModelOptions, VERSION, createGoogleGenerativeAI, google }; | ||
| export { type GoogleEmbeddingModelOptions, type GoogleErrorData, type GoogleEmbeddingModelOptions as GoogleGenerativeAIEmbeddingProviderOptions, type GoogleImageModelOptions as GoogleGenerativeAIImageProviderOptions, type GoogleGenerativeAIProvider, type GoogleGenerativeAIProviderMetadata, type GoogleLanguageModelOptions as GoogleGenerativeAIProviderOptions, type GoogleGenerativeAIProviderSettings, type GoogleGenerativeAIVideoModelId, type GoogleVideoModelOptions as GoogleGenerativeAIVideoProviderOptions, type GoogleImageModelOptions, type GoogleInteractionsAgentName, type GoogleInteractionsModelId, type GoogleInteractionsProviderMetadata, type GoogleLanguageModelInteractionsOptions, type GoogleLanguageModelOptions, GoogleTranscriptionModel, type GoogleTranscriptionModelId, type GoogleTranscriptionModelOptions, type GoogleVideoModelOptions, VERSION, createGoogleGenerativeAI, google }; |
+57
-3
| import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils'; | ||
| import { InferSchema, FetchFunction } from '@ai-sdk/provider-utils'; | ||
| import { ProviderV3, LanguageModelV3, ImageModelV3, EmbeddingModelV3, Experimental_VideoModelV3 } from '@ai-sdk/provider'; | ||
| import { InferSchema, Resolvable, FetchFunction } from '@ai-sdk/provider-utils'; | ||
| import { TranscriptionModelV3, ProviderV3, LanguageModelV3, ImageModelV3, EmbeddingModelV3, Experimental_VideoModelV3 } from '@ai-sdk/provider'; | ||
| import { z } from 'zod/v4'; | ||
@@ -409,2 +410,46 @@ declare const googleErrorDataSchema: _ai_sdk_provider_utils.LazySchema<{ | ||
| type GoogleTranscriptionModelId = 'gemini-3.5-transcribe' | 'gemini-3.5-transcribe-live' | (string & {}); | ||
| /** | ||
| * Speech recognition options for Gemini transcription models | ||
| * (`gemini-3.5-transcribe`). Maps onto Google's `AudioTranscriptionConfig`. | ||
| * The live variant (`gemini-3.5-transcribe-live`) requires streaming | ||
| * transcription, which is only available in AI SDK v7. | ||
| */ | ||
| declare const googleTranscriptionModelOptions: z.ZodObject<{ | ||
| languageCodes: z.ZodOptional<z.ZodArray<z.ZodString>>; | ||
| customVocabulary: z.ZodOptional<z.ZodArray<z.ZodString>>; | ||
| wordTimestamp: z.ZodOptional<z.ZodBoolean>; | ||
| diarization: z.ZodOptional<z.ZodBoolean>; | ||
| mode: z.ZodOptional<z.ZodEnum<{ | ||
| SMART: "SMART"; | ||
| VERBATIM: "VERBATIM"; | ||
| }>>; | ||
| }, z.core.$strip>; | ||
| type GoogleTranscriptionModelOptions = z.infer<typeof googleTranscriptionModelOptions>; | ||
| interface GoogleTranscriptionModelConfig { | ||
| provider: string; | ||
| baseURL: string; | ||
| headers?: Resolvable<Record<string, string | undefined>>; | ||
| fetch?: FetchFunction; | ||
| _internal?: { | ||
| currentDate?: () => Date; | ||
| }; | ||
| } | ||
| /** | ||
| * Gemini transcription (speech-to-text) via the Interactions API | ||
| * (e.g. `gemini-3.5-transcribe`). | ||
| * | ||
| * @see https://ai.google.dev/gemini-api/docs/transcribe | ||
| */ | ||
| declare class GoogleTranscriptionModel implements TranscriptionModelV3 { | ||
| readonly modelId: GoogleTranscriptionModelId; | ||
| private readonly config; | ||
| readonly specificationVersion = "v3"; | ||
| get provider(): string; | ||
| constructor(modelId: GoogleTranscriptionModelId, config: GoogleTranscriptionModelConfig); | ||
| private parseOptions; | ||
| doGenerate(options: Parameters<TranscriptionModelV3['doGenerate']>[0]): Promise<Awaited<ReturnType<TranscriptionModelV3['doGenerate']>>>; | ||
| } | ||
| declare const googleTools: { | ||
@@ -522,2 +567,11 @@ /** | ||
| /** | ||
| * Creates a model for transcription (speech-to-text), e.g. | ||
| * `gemini-3.5-transcribe`. | ||
| */ | ||
| transcription(modelId: GoogleTranscriptionModelId): TranscriptionModelV3; | ||
| /** | ||
| * Creates a model for transcription (speech-to-text). | ||
| */ | ||
| transcriptionModel(modelId: GoogleTranscriptionModelId): TranscriptionModelV3; | ||
| /** | ||
| * Creates a model for video generation. | ||
@@ -586,2 +640,2 @@ */ | ||
| export { type GoogleEmbeddingModelOptions, type GoogleErrorData, type GoogleEmbeddingModelOptions as GoogleGenerativeAIEmbeddingProviderOptions, type GoogleImageModelOptions as GoogleGenerativeAIImageProviderOptions, type GoogleGenerativeAIProvider, type GoogleGenerativeAIProviderMetadata, type GoogleLanguageModelOptions as GoogleGenerativeAIProviderOptions, type GoogleGenerativeAIProviderSettings, type GoogleGenerativeAIVideoModelId, type GoogleVideoModelOptions as GoogleGenerativeAIVideoProviderOptions, type GoogleImageModelOptions, type GoogleInteractionsAgentName, type GoogleInteractionsModelId, type GoogleInteractionsProviderMetadata, type GoogleLanguageModelInteractionsOptions, type GoogleLanguageModelOptions, type GoogleVideoModelOptions, VERSION, createGoogleGenerativeAI, google }; | ||
| export { type GoogleEmbeddingModelOptions, type GoogleErrorData, type GoogleEmbeddingModelOptions as GoogleGenerativeAIEmbeddingProviderOptions, type GoogleImageModelOptions as GoogleGenerativeAIImageProviderOptions, type GoogleGenerativeAIProvider, type GoogleGenerativeAIProviderMetadata, type GoogleLanguageModelOptions as GoogleGenerativeAIProviderOptions, type GoogleGenerativeAIProviderSettings, type GoogleGenerativeAIVideoModelId, type GoogleVideoModelOptions as GoogleGenerativeAIVideoProviderOptions, type GoogleImageModelOptions, type GoogleInteractionsAgentName, type GoogleInteractionsModelId, type GoogleInteractionsProviderMetadata, type GoogleLanguageModelInteractionsOptions, type GoogleLanguageModelOptions, GoogleTranscriptionModel, type GoogleTranscriptionModelId, type GoogleTranscriptionModelOptions, type GoogleVideoModelOptions, VERSION, createGoogleGenerativeAI, google }; |
+2
-2
| { | ||
| "name": "@ai-sdk/google", | ||
| "version": "3.0.114", | ||
| "version": "3.0.116", | ||
| "license": "Apache-2.0", | ||
@@ -40,3 +40,3 @@ "sideEffects": false, | ||
| "@ai-sdk/provider": "3.0.15", | ||
| "@ai-sdk/provider-utils": "4.0.48" | ||
| "@ai-sdk/provider-utils": "4.0.49" | ||
| }, | ||
@@ -43,0 +43,0 @@ "devDependencies": { |
@@ -103,6 +103,2 @@ import { | ||
| if (constValue !== undefined) { | ||
| result.enum = [constValue]; | ||
| } | ||
| // Handle type | ||
@@ -129,5 +125,7 @@ if (type) { | ||
| // Handle enum | ||
| if (enumValues !== undefined) { | ||
| result.enum = enumValues; | ||
| const values = | ||
| enumValues ?? (constValue !== undefined ? [constValue] : undefined); | ||
| if (values !== undefined) { | ||
| addEnumToSchema({ values, type, result }); | ||
| } | ||
@@ -206,2 +204,119 @@ | ||
| type EnumValues = NonNullable<JSONSchema7['enum']>; | ||
| type EnumType = 'string' | 'number' | 'integer' | 'boolean'; | ||
| type GoogleEnumSchema = { | ||
| type?: JSONSchema7['type']; | ||
| enum?: JSONSchema7['enum']; | ||
| format?: JSONSchema7['format']; | ||
| anyOf?: JSONSchema7['anyOf']; | ||
| nullable?: boolean; | ||
| }; | ||
| function addEnumToSchema({ | ||
| values, | ||
| type, | ||
| result, | ||
| }: { | ||
| values: EnumValues; | ||
| type: JSONSchema7['type']; | ||
| result: GoogleEnumSchema; | ||
| }) { | ||
| const nullable = | ||
| (Array.isArray(type) && type.includes('null')) || | ||
| (type === undefined && values.includes(null)); | ||
| // Gemini uses nullable instead of a null enum member. | ||
| const enumValues = nullable ? values.filter(value => value !== null) : values; | ||
| if (values.length > 0 && values.every(value => value === null)) { | ||
| const typeAllowsNull = | ||
| type === undefined || | ||
| type === 'null' || | ||
| (Array.isArray(type) && type.includes('null')); | ||
| if (typeAllowsNull) { | ||
| result.type = 'null'; | ||
| if (Array.isArray(type)) { | ||
| delete result.anyOf; | ||
| } | ||
| return; | ||
| } | ||
| } | ||
| const enumType = getEnumType({ values: enumValues, type }); | ||
| if (enumType === undefined) { | ||
| throw new UnsupportedFunctionalityError({ | ||
| functionality: 'JSON Schema enum with mixed or unsupported values', | ||
| message: | ||
| 'Google does not support this JSON Schema enum. Enum values must share one supported primitive type and match the schema type.', | ||
| }); | ||
| } | ||
| result.type = enumType; | ||
| // The earlier type-array conversion created anyOf. The enum gives us one | ||
| // concrete value type, so store that type directly. | ||
| if (Array.isArray(type)) { | ||
| delete result.anyOf; | ||
| } | ||
| if (nullable) { | ||
| result.nullable = true; | ||
| } | ||
| if (enumType === 'string') { | ||
| result.enum = enumValues; | ||
| } else { | ||
| result.format = 'enum'; | ||
| result.enum = enumValues.map(String); | ||
| } | ||
| } | ||
| function getEnumType({ | ||
| values, | ||
| type, | ||
| }: { | ||
| values: EnumValues; | ||
| type: JSONSchema7['type']; | ||
| }): EnumType | undefined { | ||
| if (values.length === 0) { | ||
| return undefined; | ||
| } | ||
| const typeAllows = (enumType: EnumType) => | ||
| type === undefined || | ||
| type === enumType || | ||
| (Array.isArray(type) && type.includes(enumType)); | ||
| if ( | ||
| typeAllows('string') && | ||
| values.every(value => typeof value === 'string') | ||
| ) { | ||
| return 'string'; | ||
| } | ||
| if ( | ||
| (typeAllows('number') || typeAllows('integer')) && | ||
| values.every(value => typeof value === 'number' && Number.isFinite(value)) | ||
| ) { | ||
| if (typeAllows('number')) { | ||
| return 'number'; | ||
| } | ||
| if (values.every(value => Number.isInteger(value))) { | ||
| return 'integer'; | ||
| } | ||
| } | ||
| if ( | ||
| typeAllows('boolean') && | ||
| values.every(value => typeof value === 'boolean') | ||
| ) { | ||
| return 'boolean'; | ||
| } | ||
| return undefined; | ||
| } | ||
| function convertJSONSchemaReference({ | ||
@@ -324,2 +439,3 @@ jsonSchema, | ||
| } | ||
| function isEmptyObjectSchema(jsonSchema: JSONSchema7Definition): boolean { | ||
@@ -326,0 +442,0 @@ return ( |
@@ -7,2 +7,3 @@ import type { | ||
| ProviderV3, | ||
| TranscriptionModelV3, | ||
| } from '@ai-sdk/provider'; | ||
@@ -36,2 +37,4 @@ import { | ||
| import type { GoogleInteractionsAgentName } from './interactions/google-interactions-agent'; | ||
| import { GoogleTranscriptionModel } from './transcription/google-transcription-model'; | ||
| import type { GoogleTranscriptionModelId } from './transcription/google-transcription-model-options'; | ||
@@ -81,2 +84,13 @@ export interface GoogleGenerativeAIProvider extends ProviderV3 { | ||
| /** | ||
| * Creates a model for transcription (speech-to-text), e.g. | ||
| * `gemini-3.5-transcribe`. | ||
| */ | ||
| transcription(modelId: GoogleTranscriptionModelId): TranscriptionModelV3; | ||
| /** | ||
| * Creates a model for transcription (speech-to-text). | ||
| */ | ||
| transcriptionModel(modelId: GoogleTranscriptionModelId): TranscriptionModelV3; | ||
| /** | ||
| * Creates a model for video generation. | ||
@@ -251,2 +265,10 @@ */ | ||
| const createTranscriptionModel = (modelId: GoogleTranscriptionModelId) => | ||
| new GoogleTranscriptionModel(modelId, { | ||
| provider: `${providerName}.transcription`, | ||
| baseURL, | ||
| headers: getHeaders, | ||
| fetch: options.fetch, | ||
| }); | ||
| const createVideoModel = (modelId: GoogleGenerativeAIVideoModelId) => | ||
@@ -298,2 +320,4 @@ new GoogleGenerativeAIVideoModel(modelId, { | ||
| provider.imageModel = createImageModel; | ||
| provider.transcription = createTranscriptionModel; | ||
| provider.transcriptionModel = createTranscriptionModel; | ||
| provider.video = createVideoModel; | ||
@@ -300,0 +324,0 @@ provider.videoModel = createVideoModel; |
+5
-0
@@ -30,2 +30,7 @@ export type { GoogleErrorData } from './google-error'; | ||
| export type { GoogleInteractionsAgentName } from './interactions/google-interactions-agent'; | ||
| export { GoogleTranscriptionModel } from './transcription/google-transcription-model'; | ||
| export type { | ||
| GoogleTranscriptionModelId, | ||
| GoogleTranscriptionModelOptions, | ||
| } from './transcription/google-transcription-model-options'; | ||
| export { createGoogleGenerativeAI, google } from './google-provider'; | ||
@@ -32,0 +37,0 @@ export type { |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
3277734
2.7%68
3.03%35968
3.09%211
7.65%+ Added
- Removed