@just-every/ensemble 0.2.182 → 0.2.184
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/README.md +25 -2
- package/dist/cjs/data/model_data.cjs +38 -9
- package/dist/cjs/data/model_data.d.ts.map +1 -1
- package/dist/cjs/data/model_data.js.map +1 -1
- package/dist/cjs/model_providers/gemini.cjs +305 -16
- package/dist/cjs/model_providers/gemini.d.ts.map +1 -1
- package/dist/cjs/model_providers/gemini.js.map +1 -1
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/cjs/types/types.d.ts +39 -1
- package/dist/cjs/types/types.d.ts.map +1 -1
- package/dist/cjs/utils/image_utils.cjs +26 -1
- package/dist/cjs/utils/image_utils.d.ts.map +1 -1
- package/dist/cjs/utils/image_utils.js.map +1 -1
- package/dist/data/model_data.d.ts.map +1 -1
- package/dist/data/model_data.js +38 -9
- package/dist/data/model_data.js.map +1 -1
- package/dist/model_providers/gemini.d.ts.map +1 -1
- package/dist/model_providers/gemini.js +306 -17
- package/dist/model_providers/gemini.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/types.d.ts +39 -1
- package/dist/types/types.d.ts.map +1 -1
- package/dist/utils/image_utils.d.ts.map +1 -1
- package/dist/utils/image_utils.js +26 -1
- package/dist/utils/image_utils.js.map +1 -1
- package/package.json +1 -1
|
@@ -263,6 +263,56 @@ function formatGroundingChunks(chunks) {
|
|
|
263
263
|
.map((c, i) => `${i + 1}. ${c.web.title || 'Untitled'} – ${c.web.uri}`)
|
|
264
264
|
.join('\n');
|
|
265
265
|
}
|
|
266
|
+
function normalizeGroundingChunk(chunk) {
|
|
267
|
+
if (!chunk || typeof chunk !== 'object')
|
|
268
|
+
return null;
|
|
269
|
+
const webUri = chunk?.web?.uri;
|
|
270
|
+
const webTitle = chunk?.web?.title;
|
|
271
|
+
const imageUri = chunk?.image?.imageUri || chunk?.image?.image_uri || chunk?.image_uri;
|
|
272
|
+
const imageLandingUri = chunk?.image?.uri || chunk?.uri;
|
|
273
|
+
const uri = webUri || imageLandingUri;
|
|
274
|
+
if (!uri && !imageUri)
|
|
275
|
+
return null;
|
|
276
|
+
return {
|
|
277
|
+
...(uri ? { uri } : {}),
|
|
278
|
+
...(imageUri ? { image_uri: imageUri } : {}),
|
|
279
|
+
...(webTitle ? { title: webTitle } : {}),
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
function dedupeGroundingChunks(chunks) {
|
|
283
|
+
const seen = new Set();
|
|
284
|
+
const out = [];
|
|
285
|
+
for (const chunk of chunks) {
|
|
286
|
+
const key = `${chunk.uri || ''}|${chunk.image_uri || ''}|${chunk.title || ''}`;
|
|
287
|
+
if (seen.has(key))
|
|
288
|
+
continue;
|
|
289
|
+
seen.add(key);
|
|
290
|
+
out.push(chunk);
|
|
291
|
+
}
|
|
292
|
+
return out;
|
|
293
|
+
}
|
|
294
|
+
function mergeImageMetadata(target, source) {
|
|
295
|
+
const next = {
|
|
296
|
+
...target,
|
|
297
|
+
model: source.model || target.model,
|
|
298
|
+
};
|
|
299
|
+
if (source.grounding) {
|
|
300
|
+
const t = target.grounding || {};
|
|
301
|
+
const s = source.grounding;
|
|
302
|
+
next.grounding = {
|
|
303
|
+
...t,
|
|
304
|
+
...s,
|
|
305
|
+
imageSearchQueries: Array.from(new Set([...(t.imageSearchQueries || []), ...(s.imageSearchQueries || [])])),
|
|
306
|
+
webSearchQueries: Array.from(new Set([...(t.webSearchQueries || []), ...(s.webSearchQueries || [])])),
|
|
307
|
+
groundingChunks: dedupeGroundingChunks([...(t.groundingChunks || []), ...(s.groundingChunks || [])]),
|
|
308
|
+
groundingSupports: [...(t.groundingSupports || []), ...(s.groundingSupports || [])],
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
next.thought_signatures = Array.from(new Set([...(target.thought_signatures || []), ...(source.thought_signatures || [])]));
|
|
312
|
+
next.thoughts = [...(target.thoughts || []), ...(source.thoughts || [])];
|
|
313
|
+
next.citations = dedupeGroundingChunks([...(target.citations || []), ...(source.citations || [])]);
|
|
314
|
+
return next;
|
|
315
|
+
}
|
|
266
316
|
async function addImagesToInput(input, images, source) {
|
|
267
317
|
for (const [image_id, imageData] of Object.entries(images)) {
|
|
268
318
|
const processedImageData = await (0, image_utils_js_1.resizeAndTruncateForGemini)(imageData);
|
|
@@ -434,6 +484,54 @@ const THINKING_BUDGET_CONFIGS = {
|
|
|
434
484
|
'-high': 12288,
|
|
435
485
|
'-max': 24576,
|
|
436
486
|
};
|
|
487
|
+
const GEMINI_31_FLASH_IMAGE_05K_DIMENSIONS = {
|
|
488
|
+
'1:1': { width: 512, height: 512 },
|
|
489
|
+
'1:4': { width: 256, height: 1024 },
|
|
490
|
+
'1:8': { width: 192, height: 1536 },
|
|
491
|
+
'2:3': { width: 424, height: 632 },
|
|
492
|
+
'3:2': { width: 632, height: 424 },
|
|
493
|
+
'3:4': { width: 448, height: 600 },
|
|
494
|
+
'4:1': { width: 1024, height: 256 },
|
|
495
|
+
'4:3': { width: 600, height: 448 },
|
|
496
|
+
'4:5': { width: 464, height: 576 },
|
|
497
|
+
'5:4': { width: 576, height: 464 },
|
|
498
|
+
'8:1': { width: 1536, height: 192 },
|
|
499
|
+
'9:16': { width: 384, height: 688 },
|
|
500
|
+
'16:9': { width: 688, height: 384 },
|
|
501
|
+
'21:9': { width: 792, height: 168 },
|
|
502
|
+
};
|
|
503
|
+
const GEMINI_3_PRO_IMAGE_DIMENSION_PRESETS = {
|
|
504
|
+
'1024x1024': { ar: '1:1', imageSize: '1K' },
|
|
505
|
+
'848x1264': { ar: '2:3', imageSize: '1K' },
|
|
506
|
+
'1264x848': { ar: '3:2', imageSize: '1K' },
|
|
507
|
+
'896x1200': { ar: '3:4', imageSize: '1K' },
|
|
508
|
+
'1200x896': { ar: '4:3', imageSize: '1K' },
|
|
509
|
+
'928x1152': { ar: '4:5', imageSize: '1K' },
|
|
510
|
+
'1152x928': { ar: '5:4', imageSize: '1K' },
|
|
511
|
+
'768x1376': { ar: '9:16', imageSize: '1K' },
|
|
512
|
+
'1376x768': { ar: '16:9', imageSize: '1K' },
|
|
513
|
+
'1584x672': { ar: '21:9', imageSize: '1K' },
|
|
514
|
+
'2048x2048': { ar: '1:1', imageSize: '2K' },
|
|
515
|
+
'1696x2528': { ar: '2:3', imageSize: '2K' },
|
|
516
|
+
'2528x1696': { ar: '3:2', imageSize: '2K' },
|
|
517
|
+
'1792x2400': { ar: '3:4', imageSize: '2K' },
|
|
518
|
+
'2400x1792': { ar: '4:3', imageSize: '2K' },
|
|
519
|
+
'1856x2304': { ar: '4:5', imageSize: '2K' },
|
|
520
|
+
'2304x1856': { ar: '5:4', imageSize: '2K' },
|
|
521
|
+
'1536x2752': { ar: '9:16', imageSize: '2K' },
|
|
522
|
+
'2752x1536': { ar: '16:9', imageSize: '2K' },
|
|
523
|
+
'3168x1344': { ar: '21:9', imageSize: '2K' },
|
|
524
|
+
'4096x4096': { ar: '1:1', imageSize: '4K' },
|
|
525
|
+
'3392x5056': { ar: '2:3', imageSize: '4K' },
|
|
526
|
+
'5056x3392': { ar: '3:2', imageSize: '4K' },
|
|
527
|
+
'3584x4800': { ar: '3:4', imageSize: '4K' },
|
|
528
|
+
'4800x3584': { ar: '4:3', imageSize: '4K' },
|
|
529
|
+
'3712x4608': { ar: '4:5', imageSize: '4K' },
|
|
530
|
+
'4608x3712': { ar: '5:4', imageSize: '4K' },
|
|
531
|
+
'3072x5504': { ar: '9:16', imageSize: '4K' },
|
|
532
|
+
'5504x3072': { ar: '16:9', imageSize: '4K' },
|
|
533
|
+
'6336x2688': { ar: '21:9', imageSize: '4K' },
|
|
534
|
+
};
|
|
437
535
|
class GeminiProvider extends base_provider_js_1.BaseModelProvider {
|
|
438
536
|
_client;
|
|
439
537
|
apiKey;
|
|
@@ -931,14 +1029,54 @@ class GeminiProvider extends base_provider_js_1.BaseModelProvider {
|
|
|
931
1029
|
if (hasOtherTools) {
|
|
932
1030
|
console.warn('[Gemini] Image generation ignores function tools; only google_web_search is supported.');
|
|
933
1031
|
}
|
|
1032
|
+
const explicitWebGrounding = opts?.grounding?.web_search;
|
|
1033
|
+
const explicitImageGrounding = opts?.grounding?.image_search;
|
|
1034
|
+
const enableWebGrounding = explicitWebGrounding ?? hasGoogleWebSearch ?? false;
|
|
1035
|
+
const isGemini31FlashImageModel = model.includes('gemini-3.1-flash-image-preview');
|
|
1036
|
+
const enableImageGrounding = explicitImageGrounding === true && isGemini31FlashImageModel;
|
|
1037
|
+
if (explicitImageGrounding && !isGemini31FlashImageModel) {
|
|
1038
|
+
console.warn('[Gemini] Image Search grounding is only available for gemini-3.1-flash-image-preview. Ignoring image_search=true.');
|
|
1039
|
+
}
|
|
1040
|
+
const thinkingOptions = opts?.thinking;
|
|
1041
|
+
const hasThinkingOptionsObject = thinkingOptions !== null &&
|
|
1042
|
+
typeof thinkingOptions === 'object' &&
|
|
1043
|
+
!Array.isArray(thinkingOptions);
|
|
1044
|
+
const includeThoughts = hasThinkingOptionsObject && thinkingOptions.include_thoughts === true;
|
|
1045
|
+
const requestedThinkingLevel = hasThinkingOptionsObject
|
|
1046
|
+
? thinkingOptions.level
|
|
1047
|
+
: undefined;
|
|
1048
|
+
const thinkingLevel = requestedThinkingLevel === 'high' ? 'High' : requestedThinkingLevel ? 'Minimal' : undefined;
|
|
1049
|
+
if (requestedThinkingLevel && !isGemini31FlashImageModel) {
|
|
1050
|
+
console.warn('[Gemini] thinking.level is currently supported for gemini-3.1-flash-image-preview only. Ignoring thinking level.');
|
|
1051
|
+
}
|
|
1052
|
+
if (hasThinkingOptionsObject && 'include_thoughts' in thinkingOptions && !isGemini31FlashImageModel) {
|
|
1053
|
+
console.warn('[Gemini] thinking.include_thoughts is currently supported for gemini-3.1-flash-image-preview only. Ignoring include_thoughts.');
|
|
1054
|
+
}
|
|
934
1055
|
let aspectRatio = '1:1';
|
|
935
1056
|
if (opts?.size === 'landscape')
|
|
936
1057
|
aspectRatio = '16:9';
|
|
937
1058
|
else if (opts?.size === 'portrait')
|
|
938
1059
|
aspectRatio = '9:16';
|
|
939
1060
|
console.log(`[Gemini] Generating ${numberOfImages} image(s) with model ${model}, prompt: "${prompt.substring(0, 100)}${prompt.length > 100 ? '...' : ''}"`);
|
|
940
|
-
if (model.includes('gemini-2.5-flash-image-preview') ||
|
|
1061
|
+
if (model.includes('gemini-2.5-flash-image-preview') ||
|
|
1062
|
+
model.includes('gemini-3.1-flash-image-preview') ||
|
|
1063
|
+
model.includes('gemini-3-pro-image-preview')) {
|
|
1064
|
+
let aggregateMetadata = { model };
|
|
941
1065
|
const sizeMap = {
|
|
1066
|
+
'1:1': { ar: '1:1' },
|
|
1067
|
+
'1:4': { ar: '1:4' },
|
|
1068
|
+
'1:8': { ar: '1:8' },
|
|
1069
|
+
'2:3': { ar: '2:3' },
|
|
1070
|
+
'3:2': { ar: '3:2' },
|
|
1071
|
+
'3:4': { ar: '3:4' },
|
|
1072
|
+
'4:1': { ar: '4:1' },
|
|
1073
|
+
'4:3': { ar: '4:3' },
|
|
1074
|
+
'4:5': { ar: '4:5' },
|
|
1075
|
+
'5:4': { ar: '5:4' },
|
|
1076
|
+
'8:1': { ar: '8:1' },
|
|
1077
|
+
'9:16': { ar: '9:16' },
|
|
1078
|
+
'16:9': { ar: '16:9' },
|
|
1079
|
+
'21:9': { ar: '21:9' },
|
|
942
1080
|
square: { ar: '1:1' },
|
|
943
1081
|
landscape: { ar: '16:9' },
|
|
944
1082
|
portrait: { ar: '9:16' },
|
|
@@ -953,20 +1091,85 @@ class GeminiProvider extends base_provider_js_1.BaseModelProvider {
|
|
|
953
1091
|
'1024x1792': { ar: '9:16' },
|
|
954
1092
|
};
|
|
955
1093
|
const sm = opts?.size ? sizeMap[String(opts.size)] : undefined;
|
|
1094
|
+
const gemini3ProDimensionPreset = model.includes('gemini-3-pro-image-preview')
|
|
1095
|
+
? GEMINI_3_PRO_IMAGE_DIMENSION_PRESETS[String(opts?.size)]
|
|
1096
|
+
: undefined;
|
|
956
1097
|
const imageConfig = {};
|
|
957
1098
|
if (sm?.ar)
|
|
958
1099
|
imageConfig.aspectRatio = sm.ar;
|
|
1100
|
+
if (gemini3ProDimensionPreset?.ar)
|
|
1101
|
+
imageConfig.aspectRatio = gemini3ProDimensionPreset.ar;
|
|
959
1102
|
const qualityKey = typeof opts?.quality === 'string' ? opts.quality.toLowerCase() : '';
|
|
960
|
-
const imageSizeMap =
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
1103
|
+
const imageSizeMap = isGemini31FlashImageModel
|
|
1104
|
+
? {
|
|
1105
|
+
low: '0.5K',
|
|
1106
|
+
standard: '1K',
|
|
1107
|
+
medium: '2K',
|
|
1108
|
+
hd: '4K',
|
|
1109
|
+
high: '4K',
|
|
1110
|
+
}
|
|
1111
|
+
: {
|
|
1112
|
+
low: '1K',
|
|
1113
|
+
standard: '2K',
|
|
1114
|
+
medium: '2K',
|
|
1115
|
+
hd: '4K',
|
|
1116
|
+
high: '4K',
|
|
1117
|
+
};
|
|
1118
|
+
let imageSize = imageSizeMap[qualityKey];
|
|
1119
|
+
if (gemini3ProDimensionPreset?.imageSize) {
|
|
1120
|
+
imageSize = gemini3ProDimensionPreset.imageSize;
|
|
1121
|
+
}
|
|
1122
|
+
if (isGemini31FlashImageModel && opts?.size === '512x512') {
|
|
1123
|
+
imageSize = '0.5K';
|
|
1124
|
+
}
|
|
1125
|
+
const requestImageSize = imageSize === '0.5K' ? undefined : imageSize;
|
|
1126
|
+
if (requestImageSize)
|
|
1127
|
+
imageConfig.imageSize = requestImageSize;
|
|
1128
|
+
const thinkingConfig = {};
|
|
1129
|
+
if (hasThinkingOptionsObject && 'include_thoughts' in thinkingOptions && isGemini31FlashImageModel) {
|
|
1130
|
+
thinkingConfig.includeThoughts = includeThoughts;
|
|
1131
|
+
}
|
|
1132
|
+
if (thinkingLevel && isGemini31FlashImageModel) {
|
|
1133
|
+
thinkingConfig.thinkingLevel = thinkingLevel;
|
|
1134
|
+
}
|
|
1135
|
+
const searchTypes = {};
|
|
1136
|
+
if (enableWebGrounding)
|
|
1137
|
+
searchTypes.webSearch = {};
|
|
1138
|
+
if (enableImageGrounding)
|
|
1139
|
+
searchTypes.imageSearch = {};
|
|
1140
|
+
const googleSearchTool = Object.keys(searchTypes).length > 0
|
|
1141
|
+
? {
|
|
1142
|
+
googleSearch: {
|
|
1143
|
+
searchTypes,
|
|
1144
|
+
},
|
|
1145
|
+
}
|
|
1146
|
+
: undefined;
|
|
1147
|
+
const halfKTargetDimensions = (() => {
|
|
1148
|
+
if (!isGemini31FlashImageModel || imageSize !== '0.5K')
|
|
1149
|
+
return undefined;
|
|
1150
|
+
const ar = imageConfig.aspectRatio || '1:1';
|
|
1151
|
+
const exactDimensions = GEMINI_31_FLASH_IMAGE_05K_DIMENSIONS[ar];
|
|
1152
|
+
if (exactDimensions)
|
|
1153
|
+
return exactDimensions;
|
|
1154
|
+
const match = /^(\d+):(\d+)$/.exec(ar);
|
|
1155
|
+
if (!match)
|
|
1156
|
+
return { width: 512, height: 512 };
|
|
1157
|
+
const wRatio = Number(match[1]);
|
|
1158
|
+
const hRatio = Number(match[2]);
|
|
1159
|
+
if (!Number.isFinite(wRatio) || !Number.isFinite(hRatio) || wRatio <= 0 || hRatio <= 0) {
|
|
1160
|
+
return { width: 512, height: 512 };
|
|
1161
|
+
}
|
|
1162
|
+
if (wRatio >= hRatio) {
|
|
1163
|
+
return {
|
|
1164
|
+
width: Math.max(1, Math.round((wRatio / hRatio) * 512)),
|
|
1165
|
+
height: 512,
|
|
1166
|
+
};
|
|
1167
|
+
}
|
|
1168
|
+
return {
|
|
1169
|
+
width: 512,
|
|
1170
|
+
height: Math.max(1, Math.round((hRatio / wRatio) * 512)),
|
|
1171
|
+
};
|
|
1172
|
+
})();
|
|
970
1173
|
const perImageCost = this.getImageCost(model, imageSize);
|
|
971
1174
|
const makeOne = async () => {
|
|
972
1175
|
const requestParams = {
|
|
@@ -1027,13 +1230,15 @@ class GeminiProvider extends base_provider_js_1.BaseModelProvider {
|
|
|
1027
1230
|
config: {
|
|
1028
1231
|
responseModalities: [genai_1.Modality.IMAGE, genai_1.Modality.TEXT],
|
|
1029
1232
|
...(Object.keys(imageConfig).length ? { imageConfig } : {}),
|
|
1030
|
-
...(
|
|
1233
|
+
...(googleSearchTool ? { tools: [googleSearchTool] } : {}),
|
|
1234
|
+
...(Object.keys(thinkingConfig).length ? { thinkingConfig: thinkingConfig } : {}),
|
|
1031
1235
|
},
|
|
1032
1236
|
};
|
|
1033
1237
|
const loggedRequestId = (0, llm_logger_js_1.log_llm_request)(agent.agent_id || 'default', 'gemini', model, requestParams, new Date(), requestId, agent.tags);
|
|
1034
1238
|
finalRequestId = loggedRequestId;
|
|
1035
1239
|
const response = await this.client.models.generateContentStream(requestParams);
|
|
1036
1240
|
const images = [];
|
|
1241
|
+
let metadata = { model };
|
|
1037
1242
|
let usageMetadata;
|
|
1038
1243
|
for await (const chunk of response) {
|
|
1039
1244
|
if (chunk.usageMetadata) {
|
|
@@ -1042,11 +1247,79 @@ class GeminiProvider extends base_provider_js_1.BaseModelProvider {
|
|
|
1042
1247
|
if (!chunk.candidates)
|
|
1043
1248
|
continue;
|
|
1044
1249
|
for (const cand of chunk.candidates) {
|
|
1250
|
+
const groundingMetadata = cand.groundingMetadata;
|
|
1251
|
+
if (groundingMetadata) {
|
|
1252
|
+
const chunks = Array.isArray(groundingMetadata.groundingChunks)
|
|
1253
|
+
? groundingMetadata.groundingChunks
|
|
1254
|
+
.map((c) => normalizeGroundingChunk(c))
|
|
1255
|
+
.filter((c) => !!c)
|
|
1256
|
+
: [];
|
|
1257
|
+
const searchEntryPoint = groundingMetadata.searchEntryPoint;
|
|
1258
|
+
const imageSearchQueries = Array.isArray(groundingMetadata.imageSearchQueries)
|
|
1259
|
+
? groundingMetadata.imageSearchQueries
|
|
1260
|
+
.map((q) => (typeof q === 'string' ? q : q?.query || q?.text))
|
|
1261
|
+
.filter((q) => typeof q === 'string' && q.length > 0)
|
|
1262
|
+
: [];
|
|
1263
|
+
const webSearchQueries = Array.isArray(groundingMetadata.webSearchQueries)
|
|
1264
|
+
? groundingMetadata.webSearchQueries
|
|
1265
|
+
.map((q) => (typeof q === 'string' ? q : q?.query || q?.text))
|
|
1266
|
+
.filter((q) => typeof q === 'string' && q.length > 0)
|
|
1267
|
+
: [];
|
|
1268
|
+
metadata = mergeImageMetadata(metadata, {
|
|
1269
|
+
model,
|
|
1270
|
+
grounding: {
|
|
1271
|
+
...(imageSearchQueries.length ? { imageSearchQueries } : {}),
|
|
1272
|
+
...(webSearchQueries.length ? { webSearchQueries } : {}),
|
|
1273
|
+
...(chunks.length ? { groundingChunks: chunks } : {}),
|
|
1274
|
+
...(Array.isArray(groundingMetadata.groundingSupports)
|
|
1275
|
+
? { groundingSupports: groundingMetadata.groundingSupports }
|
|
1276
|
+
: {}),
|
|
1277
|
+
...(searchEntryPoint ? { searchEntryPoint } : {}),
|
|
1278
|
+
},
|
|
1279
|
+
citations: chunks.filter(c => !!c.uri),
|
|
1280
|
+
});
|
|
1281
|
+
}
|
|
1045
1282
|
const parts = cand.content?.parts || [];
|
|
1046
1283
|
for (const part of parts) {
|
|
1284
|
+
const thoughtSignature = part.thoughtSignature || part.thought_signature;
|
|
1285
|
+
if (thoughtSignature) {
|
|
1286
|
+
metadata = mergeImageMetadata(metadata, {
|
|
1287
|
+
model,
|
|
1288
|
+
thought_signatures: [thoughtSignature],
|
|
1289
|
+
});
|
|
1290
|
+
}
|
|
1291
|
+
if (part.thought) {
|
|
1292
|
+
if (includeThoughts) {
|
|
1293
|
+
const thoughtPart = {
|
|
1294
|
+
thought: true,
|
|
1295
|
+
type: part.inlineData?.data ? 'image' : 'text',
|
|
1296
|
+
...(part.text ? { text: part.text } : {}),
|
|
1297
|
+
...(part.inlineData?.mimeType ? { mime_type: part.inlineData.mimeType } : {}),
|
|
1298
|
+
...(part.inlineData?.data ? { data: part.inlineData.data } : {}),
|
|
1299
|
+
...(thoughtSignature ? { thought_signature: thoughtSignature } : {}),
|
|
1300
|
+
};
|
|
1301
|
+
metadata = mergeImageMetadata(metadata, {
|
|
1302
|
+
model,
|
|
1303
|
+
thoughts: [thoughtPart],
|
|
1304
|
+
});
|
|
1305
|
+
}
|
|
1306
|
+
continue;
|
|
1307
|
+
}
|
|
1047
1308
|
if (part.inlineData?.data) {
|
|
1048
1309
|
const mime = part.inlineData.mimeType || 'image/png';
|
|
1049
|
-
|
|
1310
|
+
let imageData = `data:${mime};base64,${part.inlineData.data}`;
|
|
1311
|
+
if (halfKTargetDimensions) {
|
|
1312
|
+
try {
|
|
1313
|
+
imageData = await (0, image_utils_js_1.resizeDataUrl)(imageData, halfKTargetDimensions.width, halfKTargetDimensions.height, {
|
|
1314
|
+
fit: 'cover',
|
|
1315
|
+
});
|
|
1316
|
+
}
|
|
1317
|
+
catch (resizeError) {
|
|
1318
|
+
console.warn('[Gemini] Failed to resize image to 0.5K, returning original image.');
|
|
1319
|
+
console.warn((0, truncate_utils_js_1.truncateLargeValues)(resizeError));
|
|
1320
|
+
}
|
|
1321
|
+
}
|
|
1322
|
+
images.push(imageData);
|
|
1050
1323
|
}
|
|
1051
1324
|
}
|
|
1052
1325
|
}
|
|
@@ -1095,12 +1368,13 @@ class GeminiProvider extends base_provider_js_1.BaseModelProvider {
|
|
|
1095
1368
|
});
|
|
1096
1369
|
}
|
|
1097
1370
|
}
|
|
1098
|
-
return images;
|
|
1371
|
+
return { images, metadata };
|
|
1099
1372
|
};
|
|
1100
1373
|
const allImages = [];
|
|
1101
1374
|
const calls = Math.max(1, numberOfImages);
|
|
1102
1375
|
for (let i = 0; i < calls; i++) {
|
|
1103
|
-
const imgs = await makeOne();
|
|
1376
|
+
const { images: imgs, metadata } = await makeOne();
|
|
1377
|
+
aggregateMetadata = mergeImageMetadata(aggregateMetadata, metadata);
|
|
1104
1378
|
for (const img of imgs) {
|
|
1105
1379
|
if (allImages.length < numberOfImages)
|
|
1106
1380
|
allImages.push(img);
|
|
@@ -1108,6 +1382,12 @@ class GeminiProvider extends base_provider_js_1.BaseModelProvider {
|
|
|
1108
1382
|
if (allImages.length >= numberOfImages)
|
|
1109
1383
|
break;
|
|
1110
1384
|
}
|
|
1385
|
+
if (aggregateMetadata.grounding?.groundingChunks) {
|
|
1386
|
+
aggregateMetadata.citations = dedupeGroundingChunks(aggregateMetadata.grounding.groundingChunks.filter(c => !!c.uri));
|
|
1387
|
+
}
|
|
1388
|
+
if (opts?.on_metadata) {
|
|
1389
|
+
opts.on_metadata(aggregateMetadata);
|
|
1390
|
+
}
|
|
1111
1391
|
if (allImages.length === 0) {
|
|
1112
1392
|
throw new Error(`No images returned from ${model} model`);
|
|
1113
1393
|
}
|
|
@@ -1169,7 +1449,16 @@ class GeminiProvider extends base_provider_js_1.BaseModelProvider {
|
|
|
1169
1449
|
}
|
|
1170
1450
|
}
|
|
1171
1451
|
getImageCost(model, imageSize) {
|
|
1172
|
-
if (model.includes('gemini-
|
|
1452
|
+
if (model.includes('gemini-3.1-flash-image-preview')) {
|
|
1453
|
+
if (imageSize === '4K')
|
|
1454
|
+
return 0.151;
|
|
1455
|
+
if (imageSize === '2K')
|
|
1456
|
+
return 0.101;
|
|
1457
|
+
if (imageSize === '0.5K')
|
|
1458
|
+
return 0.045;
|
|
1459
|
+
return 0.067;
|
|
1460
|
+
}
|
|
1461
|
+
else if (model.includes('gemini-2.5-flash-image-preview')) {
|
|
1173
1462
|
return 0.039;
|
|
1174
1463
|
}
|
|
1175
1464
|
else if (model.includes('gemini-3-pro-image-preview')) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gemini.d.ts","sourceRoot":"","sources":["../../../model_providers/gemini.ts"],"names":[],"mappings":"AA2BA,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAEhD,OAAO,EAGH,mBAAmB,EACnB,aAAa,EACb,eAAe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