@@ -29,13 +29,17 @@ function resolveToolParameterSchemaCacheKey(
2929) : string {
3030 const normalizedProvider = normalizeLowercaseStringOrEmpty ( options ?. modelProvider ) ;
3131 const normalizedModelId = normalizeLowercaseStringOrEmpty ( options ?. modelId ) ;
32+ const toolSchemaProfile = normalizeLowercaseStringOrEmpty (
33+ options ?. modelCompat ?. toolSchemaProfile ,
34+ ) ;
3235 const unsupportedKeywords = Array . from (
3336 resolveUnsupportedToolSchemaKeywords ( options ?. modelCompat ) ,
3437 ) . toSorted ( ) ;
3538 const omitEmptyArrayItems = shouldOmitEmptyArrayItems ( options ?. modelCompat ) ;
3639 return JSON . stringify ( [
3740 normalizedProvider ,
3841 normalizedModelId ,
42+ toolSchemaProfile ,
3943 unsupportedKeywords ,
4044 omitEmptyArrayItems ,
4145 ] ) ;
@@ -57,6 +61,10 @@ function rememberCachedToolParameterSchema(schema: object, key: string, value: T
5761 return value ;
5862}
5963
64+ function isGeminiModelId ( modelId : string ) : boolean {
65+ return / (?: ^ | [ / : ] ) g e m i n i (?: $ | [ - / : . ] ) / . test ( modelId ) ;
66+ }
67+
6068function extractEnumValues ( schema : unknown ) : unknown [ ] | undefined {
6169 if ( ! schema || typeof schema !== "object" ) {
6270 return undefined ;
@@ -769,8 +777,15 @@ function normalizeToolParameterSchemaUncached(
769777 //
770778 // Normalize once here so callers can always pass `tools` through unchanged.
771779 const normalizedProvider = normalizeLowercaseStringOrEmpty ( options ?. modelProvider ) ;
780+ const normalizedModelId = normalizeLowercaseStringOrEmpty ( options ?. modelId ) ;
781+ const normalizedToolSchemaProfile = normalizeLowercaseStringOrEmpty (
782+ options ?. modelCompat ?. toolSchemaProfile ,
783+ ) ;
772784 const isGeminiProvider =
773- normalizedProvider . includes ( "google" ) || normalizedProvider . includes ( "gemini" ) ;
785+ normalizedProvider . includes ( "google" ) ||
786+ normalizedProvider . includes ( "gemini" ) ||
787+ isGeminiModelId ( normalizedModelId ) ||
788+ normalizedToolSchemaProfile === "gemini" ;
774789 const isAnthropicProvider = normalizedProvider . includes ( "anthropic" ) ;
775790 const unsupportedToolSchemaKeywords = resolveUnsupportedToolSchemaKeywords ( options ?. modelCompat ) ;
776791 const omitEmptyArrayItems = shouldOmitEmptyArrayItems ( options ?. modelCompat ) ;
@@ -781,7 +796,13 @@ function normalizeToolParameterSchemaUncached(
781796 ? stripEmptyArrayItemsFromArraySchemas ( normalizedSchema )
782797 : normalizedSchema ;
783798 if ( isGeminiProvider && ! isAnthropicProvider ) {
784- return cleanSchemaForGemini ( arrayItemsCompatibleSchema ) ;
799+ const geminiCompatibleSchema = cleanSchemaForGemini ( arrayItemsCompatibleSchema ) ;
800+ return unsupportedToolSchemaKeywords . size > 0
801+ ? ( stripUnsupportedSchemaKeywords (
802+ geminiCompatibleSchema ,
803+ unsupportedToolSchemaKeywords ,
804+ ) as TSchema )
805+ : geminiCompatibleSchema ;
785806 }
786807 if ( unsupportedToolSchemaKeywords . size > 0 ) {
787808 return stripUnsupportedSchemaKeywords (
0 commit comments