@aeye/google 0.0.0-stage → 0.11.1
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 +118 -2
- package/aeye-google.md +123 -0
- package/dist/convert.d.ts +191 -0
- package/dist/convert.d.ts.map +1 -0
- package/dist/convert.js +539 -0
- package/dist/convert.js.map +1 -0
- package/dist/decisions.d.ts +97 -0
- package/dist/decisions.d.ts.map +1 -0
- package/dist/decisions.js +62 -0
- package/dist/decisions.js.map +1 -0
- package/dist/google.d.ts +494 -0
- package/dist/google.d.ts.map +1 -0
- package/dist/google.js +1366 -0
- package/dist/google.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/media.d.ts +56 -0
- package/dist/media.d.ts.map +1 -0
- package/dist/media.js +143 -0
- package/dist/media.js.map +1 -0
- package/dist/models.d.ts +133 -0
- package/dist/models.d.ts.map +1 -0
- package/dist/models.js +126 -0
- package/dist/models.js.map +1 -0
- package/dist/retry.d.ts +112 -0
- package/dist/retry.d.ts.map +1 -0
- package/dist/retry.js +234 -0
- package/dist/retry.js.map +1 -0
- package/dist/types.d.ts +63 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +76 -0
- package/dist/types.js.map +1 -0
- package/package.json +71 -4
package/dist/convert.js
ADDED
|
@@ -0,0 +1,539 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mapping between @aeye chat shapes and the Gemini API's `generateContent`.
|
|
3
|
+
*
|
|
4
|
+
* Output parts are mapped one candidate (or stream chunk) at a time into core
|
|
5
|
+
* `Chunk`s, so a complete response is its chunks folded together and a
|
|
6
|
+
* stream reuses the same mapping.
|
|
7
|
+
*/
|
|
8
|
+
import { clampReasoningEffort } from '@aeye/ai';
|
|
9
|
+
import { GoogleError } from './types.js';
|
|
10
|
+
/**
|
|
11
|
+
* The provider name, which marks the reasoning (thought signatures) Gemini
|
|
12
|
+
* produces so other providers don't replay it.
|
|
13
|
+
*/
|
|
14
|
+
export const GOOGLE_PROVIDER = 'google';
|
|
15
|
+
/**
|
|
16
|
+
* The `ReasoningDetail.format` thought summaries and signatures round-trip
|
|
17
|
+
* through.
|
|
18
|
+
*/
|
|
19
|
+
export const GEMINI_REASONING_FORMAT = 'google-gemini-v1';
|
|
20
|
+
/**
|
|
21
|
+
* The signature Gemini accepts on a function call it didn't produce (history
|
|
22
|
+
* from another model, or one whose signature was lost), per
|
|
23
|
+
* /docs/thought-signatures "FAQs".
|
|
24
|
+
*/
|
|
25
|
+
export const SKIP_SIGNATURE = 'skip_thought_signature_validator';
|
|
26
|
+
// ============================================================================
|
|
27
|
+
// MIME types
|
|
28
|
+
// ============================================================================
|
|
29
|
+
/**
|
|
30
|
+
* MIME types by format name or file extension.
|
|
31
|
+
*/
|
|
32
|
+
const MIME_TYPES = {
|
|
33
|
+
png: 'image/png', jpg: 'image/jpeg', jpeg: 'image/jpeg', webp: 'image/webp', gif: 'image/gif',
|
|
34
|
+
heic: 'image/heic', heif: 'image/heif', bmp: 'image/bmp', tif: 'image/tiff', tiff: 'image/tiff',
|
|
35
|
+
mp3: 'audio/mp3', mpeg: 'audio/mpeg', wav: 'audio/wav', aiff: 'audio/aiff', aac: 'audio/aac', ogg: 'audio/ogg',
|
|
36
|
+
flac: 'audio/flac', m4a: 'audio/m4a', opus: 'audio/opus', weba: 'audio/webm', pcm: 'audio/l16', l16: 'audio/l16',
|
|
37
|
+
mp4: 'video/mp4', mov: 'video/mov', avi: 'video/avi', webm: 'video/webm', wmv: 'video/wmv', flv: 'video/x-flv',
|
|
38
|
+
mpg: 'video/mpeg', '3gp': 'video/3gpp', mkv: 'video/x-matroska',
|
|
39
|
+
pdf: 'application/pdf', txt: 'text/plain', text: 'text/plain', md: 'text/markdown', markdown: 'text/markdown',
|
|
40
|
+
html: 'text/html', htm: 'text/html', csv: 'text/csv', xml: 'text/xml', json: 'application/json', rtf: 'text/rtf',
|
|
41
|
+
js: 'text/javascript', ts: 'text/plain', py: 'text/x-python', css: 'text/css',
|
|
42
|
+
doc: 'application/msword', docx: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
|
43
|
+
xls: 'application/vnd.ms-excel', xlsx: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
|
44
|
+
ppt: 'application/vnd.ms-powerpoint', pptx: 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
|
|
45
|
+
odt: 'application/vnd.oasis.opendocument.text', ods: 'application/vnd.oasis.opendocument.spreadsheet', odp: 'application/vnd.oasis.opendocument.presentation',
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* The MIME type a format name, extension, or MIME type names.
|
|
49
|
+
*/
|
|
50
|
+
export function mimeTypeOf(format) {
|
|
51
|
+
if (!format)
|
|
52
|
+
return undefined;
|
|
53
|
+
const name = format.toLowerCase().replace(/^\./, '');
|
|
54
|
+
return name.includes('/') ? name : MIME_TYPES[name];
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* The extension of a file name, path or URL, if any.
|
|
58
|
+
*/
|
|
59
|
+
export function extensionOf(path) {
|
|
60
|
+
return path ? /\.([a-z0-9]+)(?:[?#].*)?$/i.exec(path)?.[1]?.toLowerCase() : undefined;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* The first MIME type a list of candidates names, ignoring the generic
|
|
64
|
+
* octet-stream the API refuses.
|
|
65
|
+
*/
|
|
66
|
+
export function pickMimeType(...candidates) {
|
|
67
|
+
for (const candidate of candidates) {
|
|
68
|
+
const mime = mimeTypeOf(candidate);
|
|
69
|
+
if (mime && mime !== 'application/octet-stream')
|
|
70
|
+
return mime;
|
|
71
|
+
}
|
|
72
|
+
return undefined;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Whether a URL is one the Gemini API reads itself: a Files API file, a
|
|
76
|
+
* Cloud Storage object, or a YouTube video.
|
|
77
|
+
*/
|
|
78
|
+
export function isFileUri(uri) {
|
|
79
|
+
return /^gs:\/\//.test(uri)
|
|
80
|
+
|| /generativelanguage\.googleapis\.com\/.*files\//.test(uri)
|
|
81
|
+
|| /^https?:\/\/(www\.)?(youtube\.com\/watch|youtu\.be\/)/.test(uri);
|
|
82
|
+
}
|
|
83
|
+
// ============================================================================
|
|
84
|
+
// Thinking
|
|
85
|
+
// ============================================================================
|
|
86
|
+
/**
|
|
87
|
+
* Thinking budgets for budget models (Gemini 2.5), by effort.
|
|
88
|
+
*/
|
|
89
|
+
const EFFORT_BUDGETS = {
|
|
90
|
+
none: 0,
|
|
91
|
+
minimal: 512,
|
|
92
|
+
low: 2048,
|
|
93
|
+
medium: 8192,
|
|
94
|
+
high: 16384,
|
|
95
|
+
xhigh: 24576,
|
|
96
|
+
max: 32768,
|
|
97
|
+
};
|
|
98
|
+
/**
|
|
99
|
+
* The level a thinking budget is nearest to, for level models asked for a
|
|
100
|
+
* budget (Gemini 4 maps a lone budget the same way, with a warning).
|
|
101
|
+
*/
|
|
102
|
+
function budgetLevel(tokens) {
|
|
103
|
+
return tokens <= 0 ? 'none' : tokens <= 1024 ? 'minimal' : tokens <= 4096 ? 'low' : tokens <= 12288 ? 'medium' : tokens <= 32768 ? 'high' : 'xhigh';
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* `Request.reason` as a `thinkingConfig` for the model:
|
|
107
|
+
*
|
|
108
|
+
* - Level models (Gemini 3 and later) take `thinkingLevel`, the effort
|
|
109
|
+
* clamped to the levels the model accepts; a budget alone picks the
|
|
110
|
+
* nearest level. `none` goes to the lowest level, since Gemini 3 and 4
|
|
111
|
+
* can't turn thinking off.
|
|
112
|
+
* - Budget models (Gemini 2.5) take `thinkingBudget`: `maxTokens`, else the
|
|
113
|
+
* effort's budget, within the model's range; `none` is 0 where allowed.
|
|
114
|
+
* - Thought summaries are asked for (`includeThoughts`) unless `exclude`.
|
|
115
|
+
*
|
|
116
|
+
* Without `reason` nothing is sent and the model thinks by its default.
|
|
117
|
+
*
|
|
118
|
+
* @param thinking - How the model thinks (`providerOptions.google.thinking`; none: it doesn't)
|
|
119
|
+
* @param reason - The reasoning asked for
|
|
120
|
+
* @param accepted - The efforts the model accepts, when known
|
|
121
|
+
* @param maxTokens - The output limit, which a budget stays under
|
|
122
|
+
*/
|
|
123
|
+
export function toThinkingConfig(thinking, reason, accepted, maxTokens) {
|
|
124
|
+
if (!reason)
|
|
125
|
+
return undefined;
|
|
126
|
+
const style = thinking?.style ?? 'none';
|
|
127
|
+
if (style === 'none')
|
|
128
|
+
return undefined;
|
|
129
|
+
const includeThoughts = reason.exclude ? undefined : true;
|
|
130
|
+
if (style === 'level') {
|
|
131
|
+
const asked = reason.effort ?? (reason.maxTokens !== undefined ? budgetLevel(reason.maxTokens) : undefined);
|
|
132
|
+
if (!asked)
|
|
133
|
+
return includeThoughts ? { includeThoughts } : undefined;
|
|
134
|
+
const levels = (accepted ?? ['low', 'medium', 'high']).filter(e => e !== 'none');
|
|
135
|
+
// Thinking can't be turned off, so `none` is the lowest level there is
|
|
136
|
+
const effort = asked === 'none' ? levels[0] : clampReasoningEffort(asked, levels);
|
|
137
|
+
return { thinkingLevel: (effort ?? 'high').toUpperCase(), includeThoughts };
|
|
138
|
+
}
|
|
139
|
+
// A budget model whose range isn't known: Gemini's documented common range, never turned off
|
|
140
|
+
const range = thinking?.budget ?? { min: 1, max: 24576, off: false };
|
|
141
|
+
const off = reason.effort === 'none' || reason.maxTokens === 0;
|
|
142
|
+
let budget = off ? (range.off ? 0 : range.min) : reason.maxTokens ?? EFFORT_BUDGETS[reason.effort ?? 'medium'];
|
|
143
|
+
if (budget > 0) {
|
|
144
|
+
budget = Math.max(range.min, Math.min(range.max, budget, maxTokens ? maxTokens - 1 : Infinity));
|
|
145
|
+
}
|
|
146
|
+
return { thinkingBudget: budget, includeThoughts: budget === 0 ? undefined : includeThoughts };
|
|
147
|
+
}
|
|
148
|
+
// ============================================================================
|
|
149
|
+
// Hosted tools
|
|
150
|
+
// ============================================================================
|
|
151
|
+
/**
|
|
152
|
+
* A provider-run tool as a Gemini tool.
|
|
153
|
+
*
|
|
154
|
+
* - web_search: Grounding with Google Search (`blockedDomains` as
|
|
155
|
+
* `excludeDomains`, on Vertex AI only; Google Search can't limit itself to domains)
|
|
156
|
+
* - web_fetch: URL context
|
|
157
|
+
* - file_search: File Search over File Search stores (`vectorStoreIds` are
|
|
158
|
+
* store names, `fileSearchStores/...`)
|
|
159
|
+
* - code_interpreter: code execution
|
|
160
|
+
* - mcp: a remote MCP server over streamable HTTP
|
|
161
|
+
* - image_generation: not a Gemini tool; use an image model instead
|
|
162
|
+
*/
|
|
163
|
+
export function toHostedTool(tool, vertex = false) {
|
|
164
|
+
switch (tool.type) {
|
|
165
|
+
case 'web_search':
|
|
166
|
+
if (tool.allowedDomains?.length) {
|
|
167
|
+
throw new GoogleError('Google Search grounding can only exclude domains, not limit itself to them');
|
|
168
|
+
}
|
|
169
|
+
if (tool.blockedDomains?.length && !vertex) {
|
|
170
|
+
throw new GoogleError('Google Search grounding excludes domains on Vertex AI only');
|
|
171
|
+
}
|
|
172
|
+
return { googleSearch: tool.blockedDomains?.length ? { excludeDomains: tool.blockedDomains } : {} };
|
|
173
|
+
case 'web_fetch':
|
|
174
|
+
return { urlContext: {} };
|
|
175
|
+
case 'file_search':
|
|
176
|
+
return { fileSearch: { fileSearchStoreNames: tool.vectorStoreIds.map(id => id.startsWith('fileSearchStores/') ? id : `fileSearchStores/${id}`), topK: tool.maxResults } };
|
|
177
|
+
case 'code_interpreter':
|
|
178
|
+
return { codeExecution: {} };
|
|
179
|
+
case 'mcp':
|
|
180
|
+
if (tool.allowedTools?.length) {
|
|
181
|
+
throw new GoogleError('Gemini MCP servers can\'t be limited to some of their tools');
|
|
182
|
+
}
|
|
183
|
+
return { mcpServers: [{ name: tool.label, streamableHttpTransport: { url: tool.url, headers: tool.headers } }] };
|
|
184
|
+
case 'image_generation':
|
|
185
|
+
throw new GoogleError('Gemini has no image generation tool; ask an image model (e.g. gemini-nano-banana-2.1) with modalities ["image"]');
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
// ============================================================================
|
|
189
|
+
// Response
|
|
190
|
+
// ============================================================================
|
|
191
|
+
/**
|
|
192
|
+
* Finish reasons that mean a safety system stepped in.
|
|
193
|
+
*/
|
|
194
|
+
const FILTERED = new Set([
|
|
195
|
+
'SAFETY', 'RECITATION', 'BLOCKLIST', 'PROHIBITED_CONTENT', 'SPII', 'IMAGE_SAFETY', 'IMAGE_PROHIBITED_CONTENT',
|
|
196
|
+
'IMAGE_RECITATION', 'LANGUAGE', 'ESCALATION', 'PUP_LIMITED_DISABLED', 'MODEL_ARMOR',
|
|
197
|
+
]);
|
|
198
|
+
/**
|
|
199
|
+
* A Gemini finish reason as a @aeye finish reason. `CONTINUATION` (a long
|
|
200
|
+
* decode stopped at the per-request cap) counts as `length`; malformed calls
|
|
201
|
+
* and other failures end like a normal stop, with `finishMessage` kept as
|
|
202
|
+
* the refusal when it explains a filter.
|
|
203
|
+
*
|
|
204
|
+
* @param reason - The candidate's finish reason
|
|
205
|
+
* @param calledTools - Whether the candidate called tools
|
|
206
|
+
*/
|
|
207
|
+
export function toFinishReason(reason, calledTools) {
|
|
208
|
+
if (calledTools && (!reason || reason === 'STOP'))
|
|
209
|
+
return 'tool_calls';
|
|
210
|
+
if (!reason)
|
|
211
|
+
return 'stop';
|
|
212
|
+
if (reason === 'MAX_TOKENS' || reason === 'CONTINUATION')
|
|
213
|
+
return 'length';
|
|
214
|
+
if (FILTERED.has(reason))
|
|
215
|
+
return 'content_filter';
|
|
216
|
+
return calledTools ? 'tool_calls' : 'stop';
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* The count of one modality in a token count breakdown.
|
|
220
|
+
*/
|
|
221
|
+
function modality(details, name) {
|
|
222
|
+
return (details ?? []).filter(d => d.modality === name).reduce((sum, d) => sum + (d.tokenCount ?? 0), 0);
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Gemini usage as @aeye usage, each token counted once:
|
|
226
|
+
*
|
|
227
|
+
* - input: prompt tokens by modality (text, video and documents as text,
|
|
228
|
+
* images, audio), plus the prompt tokens of server-side tool use; tokens
|
|
229
|
+
* read from the cache come out of the text input
|
|
230
|
+
* - output: candidate tokens by modality (text, images, audio), with thought
|
|
231
|
+
* tokens as reasoning output
|
|
232
|
+
*/
|
|
233
|
+
export function toUsage(usage) {
|
|
234
|
+
if (!usage)
|
|
235
|
+
return undefined;
|
|
236
|
+
const nonZero = (n) => (n > 0 ? n : undefined);
|
|
237
|
+
const prompt = usage.promptTokensDetails;
|
|
238
|
+
const imageIn = modality(prompt, 'IMAGE');
|
|
239
|
+
const audioIn = modality(prompt, 'AUDIO');
|
|
240
|
+
const promptTotal = usage.promptTokenCount ?? 0;
|
|
241
|
+
const cached = usage.cachedContentTokenCount ?? 0;
|
|
242
|
+
const cachedAudio = modality(usage.cacheTokensDetails, 'AUDIO');
|
|
243
|
+
const cachedImage = modality(usage.cacheTokensDetails, 'IMAGE');
|
|
244
|
+
const textIn = promptTotal - imageIn - audioIn + (usage.toolUsePromptTokenCount ?? 0) - (cached - cachedAudio - cachedImage);
|
|
245
|
+
const candidates = usage.candidatesTokensDetails;
|
|
246
|
+
const imageOut = modality(candidates, 'IMAGE');
|
|
247
|
+
const audioOut = modality(candidates, 'AUDIO');
|
|
248
|
+
const textOut = (usage.candidatesTokenCount ?? 0) - imageOut - audioOut;
|
|
249
|
+
const result = {};
|
|
250
|
+
if (textIn > 0 || textOut > 0 || cached > 0) {
|
|
251
|
+
result.text = { input: nonZero(textIn), output: nonZero(textOut), cached: nonZero(cached) };
|
|
252
|
+
}
|
|
253
|
+
if (imageIn - cachedImage > 0 || imageOut > 0) {
|
|
254
|
+
result.image = { input: nonZero(imageIn - cachedImage), tokens: nonZero(imageOut) };
|
|
255
|
+
}
|
|
256
|
+
if (audioIn - cachedAudio > 0 || audioOut > 0) {
|
|
257
|
+
result.audio = { input: nonZero(audioIn - cachedAudio), output: nonZero(audioOut) };
|
|
258
|
+
}
|
|
259
|
+
if (usage.thoughtsTokenCount) {
|
|
260
|
+
result.reasoning = { output: usage.thoughtsTokenCount };
|
|
261
|
+
}
|
|
262
|
+
return result;
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Character index in `text` of a UTF-8 byte offset: grounding segments
|
|
266
|
+
* count bytes, @aeye citations count characters.
|
|
267
|
+
*/
|
|
268
|
+
export function charIndex(text, byteOffset) {
|
|
269
|
+
let bytes = 0;
|
|
270
|
+
let i = 0;
|
|
271
|
+
for (const char of text) {
|
|
272
|
+
if (bytes >= byteOffset)
|
|
273
|
+
return i;
|
|
274
|
+
const code = char.codePointAt(0);
|
|
275
|
+
bytes += code < 0x80 ? 1 : code < 0x800 ? 2 : code < 0x10000 ? 3 : 4;
|
|
276
|
+
i += char.length;
|
|
277
|
+
}
|
|
278
|
+
return i;
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* Sources the response was grounded on (Google Search, Maps, URL context,
|
|
282
|
+
* File Search), with the span of the answer each supports.
|
|
283
|
+
*
|
|
284
|
+
* @param metadata - The candidate's grounding metadata
|
|
285
|
+
* @param text - The whole answer, to turn byte offsets into characters
|
|
286
|
+
*/
|
|
287
|
+
export function toCitations(metadata, text) {
|
|
288
|
+
const chunks = metadata?.groundingChunks ?? [];
|
|
289
|
+
const source = (index) => {
|
|
290
|
+
const chunk = chunks[index];
|
|
291
|
+
const site = chunk?.web ?? chunk?.maps ?? chunk?.retrievedContext ?? chunk?.image;
|
|
292
|
+
const uri = site?.uri ?? site?.sourceUri;
|
|
293
|
+
return uri ? { url: uri, title: site?.title ?? chunk?.web?.domain } : undefined;
|
|
294
|
+
};
|
|
295
|
+
const cited = [];
|
|
296
|
+
const used = new Set();
|
|
297
|
+
for (const support of metadata?.groundingSupports ?? []) {
|
|
298
|
+
const segment = support.segment;
|
|
299
|
+
for (const index of support.groundingChunkIndices ?? []) {
|
|
300
|
+
const site = source(index);
|
|
301
|
+
if (!site)
|
|
302
|
+
continue;
|
|
303
|
+
used.add(index);
|
|
304
|
+
cited.push({
|
|
305
|
+
...site,
|
|
306
|
+
start: segment?.startIndex !== undefined ? charIndex(text, segment.startIndex) : undefined,
|
|
307
|
+
end: segment?.endIndex !== undefined ? charIndex(text, segment.endIndex) : undefined,
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
// Sources no span names are still sources
|
|
312
|
+
chunks.forEach((_, index) => {
|
|
313
|
+
const site = source(index);
|
|
314
|
+
if (site && !used.has(index))
|
|
315
|
+
cited.push(site);
|
|
316
|
+
});
|
|
317
|
+
return cited.length ? cited : undefined;
|
|
318
|
+
}
|
|
319
|
+
/**
|
|
320
|
+
* Hosted tool calls a candidate reports, by type: search queries (Gemini 3
|
|
321
|
+
* bills each one; earlier models one per grounded prompt), URL fetches,
|
|
322
|
+
* code runs, and File Search retrievals.
|
|
323
|
+
*/
|
|
324
|
+
export function hostedToolUsage(candidate, parts) {
|
|
325
|
+
const tools = {};
|
|
326
|
+
const grounding = candidate?.groundingMetadata;
|
|
327
|
+
if (grounding?.webSearchQueries?.length) {
|
|
328
|
+
tools.web_search = grounding.webSearchQueries.length;
|
|
329
|
+
}
|
|
330
|
+
else if (grounding?.groundingChunks?.some(chunk => chunk.web)) {
|
|
331
|
+
tools.web_search = 1;
|
|
332
|
+
}
|
|
333
|
+
const fetched = candidate?.urlContextMetadata?.urlMetadata?.length;
|
|
334
|
+
if (fetched)
|
|
335
|
+
tools.web_fetch = fetched;
|
|
336
|
+
const runs = parts.filter(part => part.executableCode).length;
|
|
337
|
+
if (runs)
|
|
338
|
+
tools.code_interpreter = runs;
|
|
339
|
+
if (grounding?.groundingChunks?.some(chunk => chunk.retrievedContext?.fileSearchStore))
|
|
340
|
+
tools.file_search = 1;
|
|
341
|
+
return Object.keys(tools).length ? tools : undefined;
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* State carried across the chunks of one response: generated tool call ids,
|
|
345
|
+
* how many signatures and server parts were seen, the text so far (for
|
|
346
|
+
* citations) and the last usage reported.
|
|
347
|
+
*/
|
|
348
|
+
export class ResponseState {
|
|
349
|
+
idPrefix;
|
|
350
|
+
/** Text of the answer so far */
|
|
351
|
+
text = '';
|
|
352
|
+
/** Signatures seen, to give each its own detail */
|
|
353
|
+
signatures = 0;
|
|
354
|
+
/** Server-side tool parts seen */
|
|
355
|
+
serverParts = 0;
|
|
356
|
+
/** Calls seen */
|
|
357
|
+
calls = 0;
|
|
358
|
+
/** Latest usage (stream chunks repeat it) */
|
|
359
|
+
usage;
|
|
360
|
+
/** Latest candidate with grounding */
|
|
361
|
+
grounding;
|
|
362
|
+
/** Finish reason, when one came */
|
|
363
|
+
finish;
|
|
364
|
+
/** Why it finished, in words, when the API said */
|
|
365
|
+
finishMessage;
|
|
366
|
+
/** Whether a tool was called */
|
|
367
|
+
calledTools = false;
|
|
368
|
+
/** Blocked prompt, when it was */
|
|
369
|
+
blocked;
|
|
370
|
+
/** Tier the response ran on */
|
|
371
|
+
serviceTier;
|
|
372
|
+
/** Hosted tool calls */
|
|
373
|
+
tools;
|
|
374
|
+
/** Audio encoding of spoken output */
|
|
375
|
+
audioFormat;
|
|
376
|
+
constructor(idPrefix = 'call') {
|
|
377
|
+
this.idPrefix = idPrefix;
|
|
378
|
+
}
|
|
379
|
+
/** An id for a call that came without one */
|
|
380
|
+
nextCallId() {
|
|
381
|
+
return `${this.idPrefix}_${Date.now().toString(36)}_${(this.calls++).toString(36)}`;
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
/**
|
|
385
|
+
* A reasoning detail holding one thought signature, keyed to where it goes
|
|
386
|
+
* back: a function call (`fc:<call id>`) or the text (`text:<n>`).
|
|
387
|
+
*/
|
|
388
|
+
function signatureDetail(key, signature) {
|
|
389
|
+
return { provider: GOOGLE_PROVIDER, details: [{ id: key, type: 'reasoning.encrypted', format: GEMINI_REASONING_FORMAT, data: signature }] };
|
|
390
|
+
}
|
|
391
|
+
/**
|
|
392
|
+
* The audio encoding of an audio MIME type the API returned.
|
|
393
|
+
*/
|
|
394
|
+
export function audioFormatOf(mimeType) {
|
|
395
|
+
if (!mimeType)
|
|
396
|
+
return undefined;
|
|
397
|
+
if (/wav/i.test(mimeType))
|
|
398
|
+
return 'wav';
|
|
399
|
+
if (/l16|pcm/i.test(mimeType))
|
|
400
|
+
return 'pcm';
|
|
401
|
+
if (/mp3|mpeg/i.test(mimeType))
|
|
402
|
+
return 'mp3';
|
|
403
|
+
if (/opus|ogg/i.test(mimeType))
|
|
404
|
+
return 'opus';
|
|
405
|
+
if (/aac/i.test(mimeType))
|
|
406
|
+
return 'aac';
|
|
407
|
+
if (/flac/i.test(mimeType))
|
|
408
|
+
return 'flac';
|
|
409
|
+
return undefined;
|
|
410
|
+
}
|
|
411
|
+
/**
|
|
412
|
+
* What one response (or stream chunk) contributes, as chunks: text,
|
|
413
|
+
* thought summaries, thought signatures, tool calls (named, argued and
|
|
414
|
+
* finished at once: Gemini sends each call whole), images, audio, and the
|
|
415
|
+
* server-side tool parts kept for replay. Usage, citations and the finish
|
|
416
|
+
* reason come from `endChunk` once the response is complete.
|
|
417
|
+
*/
|
|
418
|
+
export function responseChunks(response, state) {
|
|
419
|
+
const chunks = [];
|
|
420
|
+
if (response.usageMetadata)
|
|
421
|
+
state.usage = response.usageMetadata;
|
|
422
|
+
if (response.promptFeedback?.blockReason) {
|
|
423
|
+
state.blocked = response.promptFeedback.blockReasonMessage || `The prompt was blocked (${response.promptFeedback.blockReason})`;
|
|
424
|
+
}
|
|
425
|
+
const tier = response.usageMetadata?.serviceTier;
|
|
426
|
+
if (tier)
|
|
427
|
+
state.serviceTier = tier === 'priority' ? 'fast' : tier === 'flex' ? 'flex' : 'default';
|
|
428
|
+
const candidate = response.candidates?.[0];
|
|
429
|
+
if (!candidate)
|
|
430
|
+
return chunks;
|
|
431
|
+
if (candidate.finishReason)
|
|
432
|
+
state.finish = candidate.finishReason;
|
|
433
|
+
if (candidate.finishMessage)
|
|
434
|
+
state.finishMessage = candidate.finishMessage;
|
|
435
|
+
if (candidate.groundingMetadata || candidate.urlContextMetadata)
|
|
436
|
+
state.grounding = candidate;
|
|
437
|
+
const parts = candidate.content?.parts ?? [];
|
|
438
|
+
for (const part of parts) {
|
|
439
|
+
if (part.functionCall) {
|
|
440
|
+
const call = {
|
|
441
|
+
id: part.functionCall.id || state.nextCallId(),
|
|
442
|
+
name: part.functionCall.name ?? '',
|
|
443
|
+
arguments: JSON.stringify(part.functionCall.args ?? {}),
|
|
444
|
+
};
|
|
445
|
+
state.calledTools = true;
|
|
446
|
+
chunks.push({ toolCallNamed: call, toolCallArguments: call, toolCall: call });
|
|
447
|
+
if (part.thoughtSignature)
|
|
448
|
+
chunks.push({ reasoning: signatureDetail(`fc:${call.id}`, part.thoughtSignature) });
|
|
449
|
+
continue;
|
|
450
|
+
}
|
|
451
|
+
if (part.toolCall || part.toolResponse || part.executableCode || part.codeExecutionResult) {
|
|
452
|
+
// Server-side tool use the model needs back to keep its context
|
|
453
|
+
const index = state.serverParts++;
|
|
454
|
+
chunks.push({ reasoning: { provider: GOOGLE_PROVIDER, details: [{ id: `part:${index}`, type: 'google.part', format: GEMINI_REASONING_FORMAT, index, data: JSON.stringify(part) }] } });
|
|
455
|
+
continue;
|
|
456
|
+
}
|
|
457
|
+
if (part.thought) {
|
|
458
|
+
if (part.text) {
|
|
459
|
+
chunks.push({ reasoning: { content: part.text, provider: GOOGLE_PROVIDER, details: [{ type: 'reasoning.text', format: GEMINI_REASONING_FORMAT, index: 0, text: part.text }] } });
|
|
460
|
+
}
|
|
461
|
+
// Thought images (image models drafting) aren't the answer
|
|
462
|
+
}
|
|
463
|
+
else if (part.text !== undefined && part.text !== '') {
|
|
464
|
+
state.text += part.text;
|
|
465
|
+
chunks.push({ content: part.text });
|
|
466
|
+
}
|
|
467
|
+
else if (part.inlineData?.data) {
|
|
468
|
+
const mime = part.inlineData.mimeType ?? '';
|
|
469
|
+
if (mime.startsWith('image/')) {
|
|
470
|
+
chunks.push({ images: [{ b64_json: part.inlineData.data, url: `data:${mime};base64,${part.inlineData.data}` }] });
|
|
471
|
+
}
|
|
472
|
+
else if (mime.startsWith('audio/')) {
|
|
473
|
+
state.audioFormat = audioFormatOf(mime) ?? state.audioFormat;
|
|
474
|
+
chunks.push({ audio: { data: part.inlineData.data, format: state.audioFormat } });
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
else if (part.fileData?.fileUri && (part.fileData.mimeType ?? '').startsWith('image/')) {
|
|
478
|
+
chunks.push({ images: [{ url: part.fileData.fileUri }] });
|
|
479
|
+
}
|
|
480
|
+
if (part.thoughtSignature) {
|
|
481
|
+
chunks.push({ reasoning: signatureDetail(`text:${state.signatures++}`, part.thoughtSignature) });
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
return chunks;
|
|
485
|
+
}
|
|
486
|
+
/**
|
|
487
|
+
* What a finished response contributes beyond its parts: why it stopped
|
|
488
|
+
* (or that the prompt was blocked), usage, citations, hosted tool use and
|
|
489
|
+
* the tier it ran on.
|
|
490
|
+
*/
|
|
491
|
+
export function endChunk(state, parts = []) {
|
|
492
|
+
const usage = toUsage(state.usage);
|
|
493
|
+
const tools = hostedToolUsage(state.grounding, parts);
|
|
494
|
+
const merged = tools ? { ...usage, tools } : usage;
|
|
495
|
+
if (state.blocked) {
|
|
496
|
+
return { finishReason: 'content_filter', refusal: state.blocked, usage: merged, serviceTier: state.serviceTier };
|
|
497
|
+
}
|
|
498
|
+
const finishReason = toFinishReason(state.finish, state.calledTools);
|
|
499
|
+
return {
|
|
500
|
+
finishReason,
|
|
501
|
+
refusal: finishReason === 'content_filter' ? `The response was blocked (${state.finish})${state.finishMessage ? `: ${state.finishMessage}` : ''}` : undefined,
|
|
502
|
+
usage: merged,
|
|
503
|
+
citations: toCitations(state.grounding?.groundingMetadata, state.text),
|
|
504
|
+
serviceTier: state.serviceTier,
|
|
505
|
+
};
|
|
506
|
+
}
|
|
507
|
+
/**
|
|
508
|
+
* Every part of a response's first candidate, for counting hosted tool runs
|
|
509
|
+
* at the end of a stream.
|
|
510
|
+
*/
|
|
511
|
+
export function candidateParts(response) {
|
|
512
|
+
return response?.candidates?.[0]?.content?.parts ?? [];
|
|
513
|
+
}
|
|
514
|
+
/**
|
|
515
|
+
* The parts of an earlier turn's reasoning that go back to Gemini.
|
|
516
|
+
*/
|
|
517
|
+
export function replayReasoning(details) {
|
|
518
|
+
const replay = { calls: new Map(), serverParts: [] };
|
|
519
|
+
for (const detail of details ?? []) {
|
|
520
|
+
if (detail.format !== GEMINI_REASONING_FORMAT || !detail.data)
|
|
521
|
+
continue;
|
|
522
|
+
if (detail.type === 'google.part') {
|
|
523
|
+
try {
|
|
524
|
+
replay.serverParts.push(JSON.parse(detail.data));
|
|
525
|
+
}
|
|
526
|
+
catch {
|
|
527
|
+
// A damaged part is left out
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
else if (detail.id?.startsWith('fc:')) {
|
|
531
|
+
replay.calls.set(detail.id.slice(3), detail.data);
|
|
532
|
+
}
|
|
533
|
+
else if (detail.id?.startsWith('text:')) {
|
|
534
|
+
replay.text = detail.data;
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
return replay;
|
|
538
|
+
}
|
|
539
|
+
//# sourceMappingURL=convert.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convert.js","sourceRoot":"","sources":["../src/convert.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AA2BhD,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEzC;;;GAGG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,QAAQ,CAAC;AAExC;;;GAGG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,kBAAkB,CAAC;AAE1D;;;;GAIG;AACH,MAAM,CAAC,MAA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AC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;QACpD,CAAC;aAAM,IAAI,MAAM,CAAC,EAAE,EAAE,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;YAC1C,MAAM,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC;QAC5B,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mapping between @aeye decisions and the Gemini Decisions API
|
|
3
|
+
* (/docs/decisions-api): yes/no (`noul`), choice and score questions over a
|
|
4
|
+
* shared input, answered with calibrated probabilities and no output tokens.
|
|
5
|
+
*/
|
|
6
|
+
import type { DecisionAnswer, DecisionQuestion } from '@aeye/ai';
|
|
7
|
+
import type { Usage } from '@aeye/core';
|
|
8
|
+
/**
|
|
9
|
+
* A Decisions API question.
|
|
10
|
+
*/
|
|
11
|
+
export type GeminiDecisionQuestion = {
|
|
12
|
+
type: 'noul';
|
|
13
|
+
instructions: string;
|
|
14
|
+
} | {
|
|
15
|
+
type: 'choice';
|
|
16
|
+
instructions: string;
|
|
17
|
+
criteria: Record<string, string>;
|
|
18
|
+
} | {
|
|
19
|
+
type: 'score';
|
|
20
|
+
instructions: string;
|
|
21
|
+
criteria: string[];
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* A Decisions API input block (the Interactions content shape).
|
|
25
|
+
*/
|
|
26
|
+
export type GeminiDecisionInput = {
|
|
27
|
+
type: 'text';
|
|
28
|
+
text: string;
|
|
29
|
+
} | {
|
|
30
|
+
type: 'image' | 'audio' | 'video' | 'document';
|
|
31
|
+
data?: string;
|
|
32
|
+
uri?: string;
|
|
33
|
+
mime_type: string;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* A Decisions API answer.
|
|
37
|
+
*/
|
|
38
|
+
export type GeminiDecisionAnswer = {
|
|
39
|
+
type: 'noul';
|
|
40
|
+
noul: number;
|
|
41
|
+
confidence: number;
|
|
42
|
+
} | {
|
|
43
|
+
type: 'choice';
|
|
44
|
+
choice: string;
|
|
45
|
+
probabilities: Record<string, number>;
|
|
46
|
+
confidence: number;
|
|
47
|
+
} | {
|
|
48
|
+
type: 'score';
|
|
49
|
+
score: number;
|
|
50
|
+
probabilities: Record<string, number>;
|
|
51
|
+
legend?: Record<string, string>;
|
|
52
|
+
confidence: number;
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* The parameters of a decision request.
|
|
56
|
+
*/
|
|
57
|
+
export interface GeminiDecisionParams {
|
|
58
|
+
model: string;
|
|
59
|
+
input: string | GeminiDecisionInput[];
|
|
60
|
+
questions: Record<string, GeminiDecisionQuestion>;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* A decision response.
|
|
64
|
+
*/
|
|
65
|
+
export interface GeminiDecision {
|
|
66
|
+
answers?: Record<string, GeminiDecisionAnswer>;
|
|
67
|
+
prompt_feedback?: {
|
|
68
|
+
block_reason?: string;
|
|
69
|
+
block_reason_message?: string;
|
|
70
|
+
};
|
|
71
|
+
usage?: {
|
|
72
|
+
total_input_tokens?: number;
|
|
73
|
+
input_tokens_by_modality?: Array<{
|
|
74
|
+
modality: string;
|
|
75
|
+
tokens: number;
|
|
76
|
+
}>;
|
|
77
|
+
total_output_tokens?: number;
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* An @aeye question as a Decisions API question: a predicate is yes/no, a
|
|
82
|
+
* choice maps each value to when it applies, a score lists its levels.
|
|
83
|
+
*/
|
|
84
|
+
export declare function toDecisionQuestion(question: DecisionQuestion): GeminiDecisionQuestion;
|
|
85
|
+
/**
|
|
86
|
+
* A Decisions API answer as an @aeye answer. Score probabilities come keyed
|
|
87
|
+
* by level index and go back as an array in level order.
|
|
88
|
+
*
|
|
89
|
+
* @param answer - The answer
|
|
90
|
+
* @param levels - How many levels the score question had
|
|
91
|
+
*/
|
|
92
|
+
export declare function toDecisionAnswer(answer: GeminiDecisionAnswer | undefined, levels?: number): DecisionAnswer;
|
|
93
|
+
/**
|
|
94
|
+
* Decision usage: input tokens by modality, and no output.
|
|
95
|
+
*/
|
|
96
|
+
export declare function decisionUsage(usage: GeminiDecision['usage']): Usage | undefined;
|
|
97
|
+
//# sourceMappingURL=decisions.d.ts.map
|