@just-every/ensemble 0.2.182 → 0.2.183
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 +296 -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/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 +297 -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/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,45 @@ 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 includeThoughts = opts?.thinking?.include_thoughts === true;
|
|
1041
|
+
const requestedThinkingLevel = opts?.thinking?.level;
|
|
1042
|
+
const thinkingLevel = requestedThinkingLevel === 'high' ? 'High' : requestedThinkingLevel ? 'Minimal' : undefined;
|
|
1043
|
+
if (requestedThinkingLevel && !isGemini31FlashImageModel) {
|
|
1044
|
+
console.warn('[Gemini] thinking.level is currently supported for gemini-3.1-flash-image-preview only. Ignoring thinking level.');
|
|
1045
|
+
}
|
|
934
1046
|
let aspectRatio = '1:1';
|
|
935
1047
|
if (opts?.size === 'landscape')
|
|
936
1048
|
aspectRatio = '16:9';
|
|
937
1049
|
else if (opts?.size === 'portrait')
|
|
938
1050
|
aspectRatio = '9:16';
|
|
939
1051
|
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') ||
|
|
1052
|
+
if (model.includes('gemini-2.5-flash-image-preview') ||
|
|
1053
|
+
model.includes('gemini-3.1-flash-image-preview') ||
|
|
1054
|
+
model.includes('gemini-3-pro-image-preview')) {
|
|
1055
|
+
let aggregateMetadata = { model };
|
|
941
1056
|
const sizeMap = {
|
|
1057
|
+
'1:1': { ar: '1:1' },
|
|
1058
|
+
'1:4': { ar: '1:4' },
|
|
1059
|
+
'1:8': { ar: '1:8' },
|
|
1060
|
+
'2:3': { ar: '2:3' },
|
|
1061
|
+
'3:2': { ar: '3:2' },
|
|
1062
|
+
'3:4': { ar: '3:4' },
|
|
1063
|
+
'4:1': { ar: '4:1' },
|
|
1064
|
+
'4:3': { ar: '4:3' },
|
|
1065
|
+
'4:5': { ar: '4:5' },
|
|
1066
|
+
'5:4': { ar: '5:4' },
|
|
1067
|
+
'8:1': { ar: '8:1' },
|
|
1068
|
+
'9:16': { ar: '9:16' },
|
|
1069
|
+
'16:9': { ar: '16:9' },
|
|
1070
|
+
'21:9': { ar: '21:9' },
|
|
942
1071
|
square: { ar: '1:1' },
|
|
943
1072
|
landscape: { ar: '16:9' },
|
|
944
1073
|
portrait: { ar: '9:16' },
|
|
@@ -953,20 +1082,85 @@ class GeminiProvider extends base_provider_js_1.BaseModelProvider {
|
|
|
953
1082
|
'1024x1792': { ar: '9:16' },
|
|
954
1083
|
};
|
|
955
1084
|
const sm = opts?.size ? sizeMap[String(opts.size)] : undefined;
|
|
1085
|
+
const gemini3ProDimensionPreset = model.includes('gemini-3-pro-image-preview')
|
|
1086
|
+
? GEMINI_3_PRO_IMAGE_DIMENSION_PRESETS[String(opts?.size)]
|
|
1087
|
+
: undefined;
|
|
956
1088
|
const imageConfig = {};
|
|
957
1089
|
if (sm?.ar)
|
|
958
1090
|
imageConfig.aspectRatio = sm.ar;
|
|
1091
|
+
if (gemini3ProDimensionPreset?.ar)
|
|
1092
|
+
imageConfig.aspectRatio = gemini3ProDimensionPreset.ar;
|
|
959
1093
|
const qualityKey = typeof opts?.quality === 'string' ? opts.quality.toLowerCase() : '';
|
|
960
|
-
const imageSizeMap =
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
1094
|
+
const imageSizeMap = isGemini31FlashImageModel
|
|
1095
|
+
? {
|
|
1096
|
+
low: '0.5K',
|
|
1097
|
+
standard: '1K',
|
|
1098
|
+
medium: '2K',
|
|
1099
|
+
hd: '4K',
|
|
1100
|
+
high: '4K',
|
|
1101
|
+
}
|
|
1102
|
+
: {
|
|
1103
|
+
low: '1K',
|
|
1104
|
+
standard: '2K',
|
|
1105
|
+
medium: '2K',
|
|
1106
|
+
hd: '4K',
|
|
1107
|
+
high: '4K',
|
|
1108
|
+
};
|
|
1109
|
+
let imageSize = imageSizeMap[qualityKey];
|
|
1110
|
+
if (gemini3ProDimensionPreset?.imageSize) {
|
|
1111
|
+
imageSize = gemini3ProDimensionPreset.imageSize;
|
|
1112
|
+
}
|
|
1113
|
+
if (isGemini31FlashImageModel && opts?.size === '512x512') {
|
|
1114
|
+
imageSize = '0.5K';
|
|
1115
|
+
}
|
|
1116
|
+
const requestImageSize = imageSize === '0.5K' ? undefined : imageSize;
|
|
1117
|
+
if (requestImageSize)
|
|
1118
|
+
imageConfig.imageSize = requestImageSize;
|
|
1119
|
+
const thinkingConfig = {};
|
|
1120
|
+
if (opts?.thinking && 'include_thoughts' in opts.thinking) {
|
|
1121
|
+
thinkingConfig.includeThoughts = includeThoughts;
|
|
1122
|
+
}
|
|
1123
|
+
if (thinkingLevel && isGemini31FlashImageModel) {
|
|
1124
|
+
thinkingConfig.thinkingLevel = thinkingLevel;
|
|
1125
|
+
}
|
|
1126
|
+
const searchTypes = {};
|
|
1127
|
+
if (enableWebGrounding)
|
|
1128
|
+
searchTypes.webSearch = {};
|
|
1129
|
+
if (enableImageGrounding)
|
|
1130
|
+
searchTypes.imageSearch = {};
|
|
1131
|
+
const googleSearchTool = Object.keys(searchTypes).length > 0
|
|
1132
|
+
? {
|
|
1133
|
+
googleSearch: {
|
|
1134
|
+
searchTypes,
|
|
1135
|
+
},
|
|
1136
|
+
}
|
|
1137
|
+
: undefined;
|
|
1138
|
+
const halfKTargetDimensions = (() => {
|
|
1139
|
+
if (!isGemini31FlashImageModel || imageSize !== '0.5K')
|
|
1140
|
+
return undefined;
|
|
1141
|
+
const ar = imageConfig.aspectRatio || '1:1';
|
|
1142
|
+
const exactDimensions = GEMINI_31_FLASH_IMAGE_05K_DIMENSIONS[ar];
|
|
1143
|
+
if (exactDimensions)
|
|
1144
|
+
return exactDimensions;
|
|
1145
|
+
const match = /^(\d+):(\d+)$/.exec(ar);
|
|
1146
|
+
if (!match)
|
|
1147
|
+
return { width: 512, height: 512 };
|
|
1148
|
+
const wRatio = Number(match[1]);
|
|
1149
|
+
const hRatio = Number(match[2]);
|
|
1150
|
+
if (!Number.isFinite(wRatio) || !Number.isFinite(hRatio) || wRatio <= 0 || hRatio <= 0) {
|
|
1151
|
+
return { width: 512, height: 512 };
|
|
1152
|
+
}
|
|
1153
|
+
if (wRatio >= hRatio) {
|
|
1154
|
+
return {
|
|
1155
|
+
width: Math.max(1, Math.round((wRatio / hRatio) * 512)),
|
|
1156
|
+
height: 512,
|
|
1157
|
+
};
|
|
1158
|
+
}
|
|
1159
|
+
return {
|
|
1160
|
+
width: 512,
|
|
1161
|
+
height: Math.max(1, Math.round((hRatio / wRatio) * 512)),
|
|
1162
|
+
};
|
|
1163
|
+
})();
|
|
970
1164
|
const perImageCost = this.getImageCost(model, imageSize);
|
|
971
1165
|
const makeOne = async () => {
|
|
972
1166
|
const requestParams = {
|
|
@@ -1027,13 +1221,15 @@ class GeminiProvider extends base_provider_js_1.BaseModelProvider {
|
|
|
1027
1221
|
config: {
|
|
1028
1222
|
responseModalities: [genai_1.Modality.IMAGE, genai_1.Modality.TEXT],
|
|
1029
1223
|
...(Object.keys(imageConfig).length ? { imageConfig } : {}),
|
|
1030
|
-
...(
|
|
1224
|
+
...(googleSearchTool ? { tools: [googleSearchTool] } : {}),
|
|
1225
|
+
...(Object.keys(thinkingConfig).length ? { thinkingConfig: thinkingConfig } : {}),
|
|
1031
1226
|
},
|
|
1032
1227
|
};
|
|
1033
1228
|
const loggedRequestId = (0, llm_logger_js_1.log_llm_request)(agent.agent_id || 'default', 'gemini', model, requestParams, new Date(), requestId, agent.tags);
|
|
1034
1229
|
finalRequestId = loggedRequestId;
|
|
1035
1230
|
const response = await this.client.models.generateContentStream(requestParams);
|
|
1036
1231
|
const images = [];
|
|
1232
|
+
let metadata = { model };
|
|
1037
1233
|
let usageMetadata;
|
|
1038
1234
|
for await (const chunk of response) {
|
|
1039
1235
|
if (chunk.usageMetadata) {
|
|
@@ -1042,11 +1238,79 @@ class GeminiProvider extends base_provider_js_1.BaseModelProvider {
|
|
|
1042
1238
|
if (!chunk.candidates)
|
|
1043
1239
|
continue;
|
|
1044
1240
|
for (const cand of chunk.candidates) {
|
|
1241
|
+
const groundingMetadata = cand.groundingMetadata;
|
|
1242
|
+
if (groundingMetadata) {
|
|
1243
|
+
const chunks = Array.isArray(groundingMetadata.groundingChunks)
|
|
1244
|
+
? groundingMetadata.groundingChunks
|
|
1245
|
+
.map((c) => normalizeGroundingChunk(c))
|
|
1246
|
+
.filter((c) => !!c)
|
|
1247
|
+
: [];
|
|
1248
|
+
const searchEntryPoint = groundingMetadata.searchEntryPoint;
|
|
1249
|
+
const imageSearchQueries = Array.isArray(groundingMetadata.imageSearchQueries)
|
|
1250
|
+
? groundingMetadata.imageSearchQueries
|
|
1251
|
+
.map((q) => (typeof q === 'string' ? q : q?.query || q?.text))
|
|
1252
|
+
.filter((q) => typeof q === 'string' && q.length > 0)
|
|
1253
|
+
: [];
|
|
1254
|
+
const webSearchQueries = Array.isArray(groundingMetadata.webSearchQueries)
|
|
1255
|
+
? groundingMetadata.webSearchQueries
|
|
1256
|
+
.map((q) => (typeof q === 'string' ? q : q?.query || q?.text))
|
|
1257
|
+
.filter((q) => typeof q === 'string' && q.length > 0)
|
|
1258
|
+
: [];
|
|
1259
|
+
metadata = mergeImageMetadata(metadata, {
|
|
1260
|
+
model,
|
|
1261
|
+
grounding: {
|
|
1262
|
+
...(imageSearchQueries.length ? { imageSearchQueries } : {}),
|
|
1263
|
+
...(webSearchQueries.length ? { webSearchQueries } : {}),
|
|
1264
|
+
...(chunks.length ? { groundingChunks: chunks } : {}),
|
|
1265
|
+
...(Array.isArray(groundingMetadata.groundingSupports)
|
|
1266
|
+
? { groundingSupports: groundingMetadata.groundingSupports }
|
|
1267
|
+
: {}),
|
|
1268
|
+
...(searchEntryPoint ? { searchEntryPoint } : {}),
|
|
1269
|
+
},
|
|
1270
|
+
citations: chunks.filter(c => !!c.uri),
|
|
1271
|
+
});
|
|
1272
|
+
}
|
|
1045
1273
|
const parts = cand.content?.parts || [];
|
|
1046
1274
|
for (const part of parts) {
|
|
1275
|
+
const thoughtSignature = part.thoughtSignature || part.thought_signature;
|
|
1276
|
+
if (thoughtSignature) {
|
|
1277
|
+
metadata = mergeImageMetadata(metadata, {
|
|
1278
|
+
model,
|
|
1279
|
+
thought_signatures: [thoughtSignature],
|
|
1280
|
+
});
|
|
1281
|
+
}
|
|
1282
|
+
if (part.thought) {
|
|
1283
|
+
if (includeThoughts) {
|
|
1284
|
+
const thoughtPart = {
|
|
1285
|
+
thought: true,
|
|
1286
|
+
type: part.inlineData?.data ? 'image' : 'text',
|
|
1287
|
+
...(part.text ? { text: part.text } : {}),
|
|
1288
|
+
...(part.inlineData?.mimeType ? { mime_type: part.inlineData.mimeType } : {}),
|
|
1289
|
+
...(part.inlineData?.data ? { data: part.inlineData.data } : {}),
|
|
1290
|
+
...(thoughtSignature ? { thought_signature: thoughtSignature } : {}),
|
|
1291
|
+
};
|
|
1292
|
+
metadata = mergeImageMetadata(metadata, {
|
|
1293
|
+
model,
|
|
1294
|
+
thoughts: [thoughtPart],
|
|
1295
|
+
});
|
|
1296
|
+
}
|
|
1297
|
+
continue;
|
|
1298
|
+
}
|
|
1047
1299
|
if (part.inlineData?.data) {
|
|
1048
1300
|
const mime = part.inlineData.mimeType || 'image/png';
|
|
1049
|
-
|
|
1301
|
+
let imageData = `data:${mime};base64,${part.inlineData.data}`;
|
|
1302
|
+
if (halfKTargetDimensions) {
|
|
1303
|
+
try {
|
|
1304
|
+
imageData = await (0, image_utils_js_1.resizeDataUrl)(imageData, halfKTargetDimensions.width, halfKTargetDimensions.height, {
|
|
1305
|
+
fit: 'cover',
|
|
1306
|
+
});
|
|
1307
|
+
}
|
|
1308
|
+
catch (resizeError) {
|
|
1309
|
+
console.warn('[Gemini] Failed to resize image to 0.5K, returning original image.');
|
|
1310
|
+
console.warn((0, truncate_utils_js_1.truncateLargeValues)(resizeError));
|
|
1311
|
+
}
|
|
1312
|
+
}
|
|
1313
|
+
images.push(imageData);
|
|
1050
1314
|
}
|
|
1051
1315
|
}
|
|
1052
1316
|
}
|
|
@@ -1095,12 +1359,13 @@ class GeminiProvider extends base_provider_js_1.BaseModelProvider {
|
|
|
1095
1359
|
});
|
|
1096
1360
|
}
|
|
1097
1361
|
}
|
|
1098
|
-
return images;
|
|
1362
|
+
return { images, metadata };
|
|
1099
1363
|
};
|
|
1100
1364
|
const allImages = [];
|
|
1101
1365
|
const calls = Math.max(1, numberOfImages);
|
|
1102
1366
|
for (let i = 0; i < calls; i++) {
|
|
1103
|
-
const imgs = await makeOne();
|
|
1367
|
+
const { images: imgs, metadata } = await makeOne();
|
|
1368
|
+
aggregateMetadata = mergeImageMetadata(aggregateMetadata, metadata);
|
|
1104
1369
|
for (const img of imgs) {
|
|
1105
1370
|
if (allImages.length < numberOfImages)
|
|
1106
1371
|
allImages.push(img);
|
|
@@ -1108,6 +1373,12 @@ class GeminiProvider extends base_provider_js_1.BaseModelProvider {
|
|
|
1108
1373
|
if (allImages.length >= numberOfImages)
|
|
1109
1374
|
break;
|
|
1110
1375
|
}
|
|
1376
|
+
if (aggregateMetadata.grounding?.groundingChunks) {
|
|
1377
|
+
aggregateMetadata.citations = dedupeGroundingChunks(aggregateMetadata.grounding.groundingChunks.filter(c => !!c.uri));
|
|
1378
|
+
}
|
|
1379
|
+
if (opts?.on_metadata) {
|
|
1380
|
+
opts.on_metadata(aggregateMetadata);
|
|
1381
|
+
}
|
|
1111
1382
|
if (allImages.length === 0) {
|
|
1112
1383
|
throw new Error(`No images returned from ${model} model`);
|
|
1113
1384
|
}
|
|
@@ -1169,7 +1440,16 @@ class GeminiProvider extends base_provider_js_1.BaseModelProvider {
|
|
|
1169
1440
|
}
|
|
1170
1441
|
}
|
|
1171
1442
|
getImageCost(model, imageSize) {
|
|
1172
|
-
if (model.includes('gemini-
|
|
1443
|
+
if (model.includes('gemini-3.1-flash-image-preview')) {
|
|
1444
|
+
if (imageSize === '4K')
|
|
1445
|
+
return 0.151;
|
|
1446
|
+
if (imageSize === '2K')
|
|
1447
|
+
return 0.101;
|
|
1448
|
+
if (imageSize === '0.5K')
|
|
1449
|
+
return 0.045;
|
|
1450
|
+
return 0.067;
|
|
1451
|
+
}
|
|
1452
|
+
else if (model.includes('gemini-2.5-flash-image-preview')) {
|
|
1173
1453
|
return 0.039;
|
|
1174
1454
|
}
|
|
1175
1455
|
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,EACf,mBAAmB,
|
|
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,EACf,mBAAmB,EAInB,mBAAmB,EAEnB,iBAAiB,EACjB,wBAAwB,EACxB,kBAAkB,EAClB,UAAU,EACV,WAAW,EACX,WAAW,EAOd,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AA8NvD,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAO1D;AAmCD,wBAAgB,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAEzD;AAqVD,qBAAa,cAAe,SAAQ,iBAAiB;IACjD,OAAO,CAAC,OAAO,CAAC,CAAc;IAC9B,OAAO,CAAC,MAAM,CAAC,CAAS;gBAEZ,MAAM,CAAC,EAAE,MAAM;IAS3B,OAAO,KAAK,MAAM,GAejB;IASK,eAAe,CACjB,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,EACxB,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,eAAe,EACtB,IAAI,CAAC,EAAE,SAAS,GACjB,OAAO,CAAC,MAAM,EAAE,GAAG,MAAM,EAAE,EAAE,CAAC;YAmKlB,2BAA2B;IA+BnC,oBAAoB,CACvB,QAAQ,EAAE,aAAa,EACvB,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,eAAe,EACtB,SAAS,CAAC,EAAE,MAAM,GACnB,cAAc,CAAC,mBAAmB,CAAC;IAqchC,WAAW,CACb,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,eAAe,EACtB,IAAI,CAAC,EAAE,mBAAmB,GAC3B,OAAO,CAAC,MAAM,EAAE,CAAC;IA4gBpB,OAAO,CAAC,YAAY;IAmCd,WAAW,CACb,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,eAAe,EACtB,IAAI,CAAC,EAAE,mBAAmB,GAC3B,OAAO,CAAC,cAAc,CAAC,UAAU,CAAC,GAAG,WAAW,CAAC;IAgMpD,OAAO,CAAC,gBAAgB;IA6DjB,mBAAmB,CACtB,KAAK,EAAE,wBAAwB,EAC/B,KAAK,EAAE,eAAe,EACtB,KAAK,EAAE,MAAM,EACb,IAAI,CAAC,EAAE,iBAAiB,GACzB,cAAc,CAAC,kBAAkB,CAAC;IA6S/B,iBAAiB,CACnB,MAAM,EAAE,UAAU,EAClB,KAAK,EAAE,eAAe,EACtB,KAAK,EAAE,MAAM,EACb,IAAI,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,WAAW,CAAC;CAyB1B;AAyfD,eAAO,MAAM,cAAc,gBAAuB,CAAC"}
|