@ai-sdk/google 3.0.66 → 3.0.68
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/CHANGELOG.md +13 -0
- package/dist/index.d.mts +90 -1
- package/dist/index.d.ts +90 -1
- package/dist/index.js +2383 -49
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2353 -1
- package/dist/index.mjs.map +1 -1
- package/docs/15-google-generative-ai.mdx +396 -0
- package/package.json +2 -2
- package/src/google-provider.ts +34 -0
- package/src/index.ts +6 -0
- package/src/interactions/build-google-interactions-stream-transform.ts +711 -0
- package/src/interactions/convert-google-interactions-usage.ts +47 -0
- package/src/interactions/convert-to-google-interactions-input.ts +630 -0
- package/src/interactions/extract-google-interactions-sources.ts +245 -0
- package/src/interactions/google-interactions-agent.ts +16 -0
- package/src/interactions/google-interactions-api.ts +466 -0
- package/src/interactions/google-interactions-language-model-options.ts +136 -0
- package/src/interactions/google-interactions-language-model.ts +609 -0
- package/src/interactions/google-interactions-prompt.ts +457 -0
- package/src/interactions/google-interactions-provider-metadata.ts +23 -0
- package/src/interactions/map-google-interactions-finish-reason.ts +33 -0
- package/src/interactions/parse-google-interactions-outputs.ts +257 -0
- package/src/interactions/poll-google-interactions.ts +110 -0
- package/src/interactions/prepare-google-interactions-tools.ts +245 -0
- package/src/interactions/synthesize-google-interactions-agent-stream.ts +185 -0
|
@@ -0,0 +1,457 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal TypeScript types for the Gemini Interactions API wire format.
|
|
3
|
+
*
|
|
4
|
+
* Mirrors the public types in `googleapis/js-genai`:
|
|
5
|
+
* `src/interactions/resources/interactions.ts`. Kept minimal for TASK-1 (text +
|
|
6
|
+
* thought happy path); further content/tool block variants are scaffolded as
|
|
7
|
+
* `unknown` here and populated in subsequent tasks.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
export type GoogleInteractionsTextContent = {
|
|
11
|
+
type: 'text';
|
|
12
|
+
text: string;
|
|
13
|
+
annotations?: Array<unknown>;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export type GoogleInteractionsImageContent = {
|
|
17
|
+
type: 'image';
|
|
18
|
+
data?: string;
|
|
19
|
+
mime_type?: string;
|
|
20
|
+
uri?: string;
|
|
21
|
+
resolution?: 'low' | 'medium' | 'high' | 'ultra_high';
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export type GoogleInteractionsAudioContent = {
|
|
25
|
+
type: 'audio';
|
|
26
|
+
data?: string;
|
|
27
|
+
mime_type?: string;
|
|
28
|
+
uri?: string;
|
|
29
|
+
channels?: number;
|
|
30
|
+
sample_rate?: number;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export type GoogleInteractionsDocumentContent = {
|
|
34
|
+
type: 'document';
|
|
35
|
+
data?: string;
|
|
36
|
+
mime_type?: string;
|
|
37
|
+
uri?: string;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export type GoogleInteractionsVideoContent = {
|
|
41
|
+
type: 'video';
|
|
42
|
+
data?: string;
|
|
43
|
+
mime_type?: string;
|
|
44
|
+
uri?: string;
|
|
45
|
+
resolution?: 'low' | 'medium' | 'high' | 'ultra_high';
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export type GoogleInteractionsThoughtSummaryItem =
|
|
49
|
+
| GoogleInteractionsTextContent
|
|
50
|
+
| GoogleInteractionsImageContent;
|
|
51
|
+
|
|
52
|
+
export type GoogleInteractionsThoughtContent = {
|
|
53
|
+
type: 'thought';
|
|
54
|
+
signature?: string;
|
|
55
|
+
summary?: Array<GoogleInteractionsThoughtSummaryItem>;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export type GoogleInteractionsFunctionCallContent = {
|
|
59
|
+
type: 'function_call';
|
|
60
|
+
id: string;
|
|
61
|
+
name: string;
|
|
62
|
+
arguments: Record<string, unknown>;
|
|
63
|
+
signature?: string;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
export type GoogleInteractionsFunctionResultContent = {
|
|
67
|
+
type: 'function_result';
|
|
68
|
+
call_id: string;
|
|
69
|
+
result:
|
|
70
|
+
| string
|
|
71
|
+
| Array<GoogleInteractionsTextContent | GoogleInteractionsImageContent>
|
|
72
|
+
| unknown;
|
|
73
|
+
name?: string;
|
|
74
|
+
is_error?: boolean;
|
|
75
|
+
signature?: string;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* URL citation annotation for `text` content blocks.
|
|
80
|
+
* Mirrors `Annotation.URLCitation` in `googleapis/js-genai`
|
|
81
|
+
* `src/interactions/resources/interactions.ts`.
|
|
82
|
+
*/
|
|
83
|
+
export type GoogleInteractionsURLCitation = {
|
|
84
|
+
type: 'url_citation';
|
|
85
|
+
url?: string;
|
|
86
|
+
title?: string;
|
|
87
|
+
start_index?: number;
|
|
88
|
+
end_index?: number;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* File citation annotation for `text` content blocks.
|
|
93
|
+
*/
|
|
94
|
+
export type GoogleInteractionsFileCitation = {
|
|
95
|
+
type: 'file_citation';
|
|
96
|
+
file_name?: string;
|
|
97
|
+
document_uri?: string;
|
|
98
|
+
source?: string;
|
|
99
|
+
page_number?: number;
|
|
100
|
+
media_id?: string;
|
|
101
|
+
start_index?: number;
|
|
102
|
+
end_index?: number;
|
|
103
|
+
custom_metadata?: Record<string, unknown>;
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Place citation annotation for Google Maps grounding.
|
|
108
|
+
*/
|
|
109
|
+
export type GoogleInteractionsPlaceCitation = {
|
|
110
|
+
type: 'place_citation';
|
|
111
|
+
name?: string;
|
|
112
|
+
url?: string;
|
|
113
|
+
place_id?: string;
|
|
114
|
+
start_index?: number;
|
|
115
|
+
end_index?: number;
|
|
116
|
+
review_snippets?: Array<{
|
|
117
|
+
review_id?: string;
|
|
118
|
+
title?: string;
|
|
119
|
+
url?: string;
|
|
120
|
+
}>;
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
export type GoogleInteractionsAnnotation =
|
|
124
|
+
| GoogleInteractionsURLCitation
|
|
125
|
+
| GoogleInteractionsFileCitation
|
|
126
|
+
| GoogleInteractionsPlaceCitation;
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Built-in tool call content blocks. The Interactions API exposes server-side
|
|
130
|
+
* tool invocations via paired `*_call`/`*_result` blocks (as opposed to
|
|
131
|
+
* `function_call`/`function_result` for client-executed tools).
|
|
132
|
+
*/
|
|
133
|
+
export type GoogleInteractionsCodeExecutionCallContent = {
|
|
134
|
+
type: 'code_execution_call';
|
|
135
|
+
id: string;
|
|
136
|
+
arguments?: { code?: string; language?: string };
|
|
137
|
+
signature?: string;
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
export type GoogleInteractionsCodeExecutionResultContent = {
|
|
141
|
+
type: 'code_execution_result';
|
|
142
|
+
call_id: string;
|
|
143
|
+
result?: string;
|
|
144
|
+
is_error?: boolean;
|
|
145
|
+
signature?: string;
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
export type GoogleInteractionsURLContextCallContent = {
|
|
149
|
+
type: 'url_context_call';
|
|
150
|
+
id: string;
|
|
151
|
+
arguments?: { urls?: Array<string> };
|
|
152
|
+
signature?: string;
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
export type GoogleInteractionsURLContextResultEntry = {
|
|
156
|
+
url?: string;
|
|
157
|
+
status?: 'success' | 'error' | 'paywall' | 'unsafe' | string;
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
export type GoogleInteractionsURLContextResultContent = {
|
|
161
|
+
type: 'url_context_result';
|
|
162
|
+
call_id: string;
|
|
163
|
+
result?: Array<GoogleInteractionsURLContextResultEntry>;
|
|
164
|
+
is_error?: boolean;
|
|
165
|
+
signature?: string;
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
export type GoogleInteractionsGoogleSearchCallContent = {
|
|
169
|
+
type: 'google_search_call';
|
|
170
|
+
id: string;
|
|
171
|
+
arguments?: { queries?: Array<string> };
|
|
172
|
+
search_type?: 'web_search' | 'image_search' | 'enterprise_web_search';
|
|
173
|
+
signature?: string;
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
export type GoogleInteractionsGoogleSearchResultEntry = {
|
|
177
|
+
search_suggestions?: string;
|
|
178
|
+
url?: string;
|
|
179
|
+
title?: string;
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
export type GoogleInteractionsGoogleSearchResultContent = {
|
|
183
|
+
type: 'google_search_result';
|
|
184
|
+
call_id: string;
|
|
185
|
+
result?: Array<GoogleInteractionsGoogleSearchResultEntry>;
|
|
186
|
+
is_error?: boolean;
|
|
187
|
+
signature?: string;
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
export type GoogleInteractionsFileSearchCallContent = {
|
|
191
|
+
type: 'file_search_call';
|
|
192
|
+
id: string;
|
|
193
|
+
signature?: string;
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
export type GoogleInteractionsFileSearchResultEntry = {
|
|
197
|
+
file_name?: string;
|
|
198
|
+
document_uri?: string;
|
|
199
|
+
title?: string;
|
|
200
|
+
source?: string;
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
export type GoogleInteractionsFileSearchResultContent = {
|
|
204
|
+
type: 'file_search_result';
|
|
205
|
+
call_id: string;
|
|
206
|
+
result?: Array<unknown>;
|
|
207
|
+
signature?: string;
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
export type GoogleInteractionsGoogleMapsCallContent = {
|
|
211
|
+
type: 'google_maps_call';
|
|
212
|
+
id: string;
|
|
213
|
+
arguments?: { queries?: Array<string> };
|
|
214
|
+
signature?: string;
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
export type GoogleInteractionsGoogleMapsResultPlace = {
|
|
218
|
+
name?: string;
|
|
219
|
+
place_id?: string;
|
|
220
|
+
url?: string;
|
|
221
|
+
review_snippets?: Array<{
|
|
222
|
+
review_id?: string;
|
|
223
|
+
title?: string;
|
|
224
|
+
url?: string;
|
|
225
|
+
}>;
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
export type GoogleInteractionsGoogleMapsResultEntry = {
|
|
229
|
+
places?: Array<GoogleInteractionsGoogleMapsResultPlace>;
|
|
230
|
+
widget_context_token?: string;
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
export type GoogleInteractionsGoogleMapsResultContent = {
|
|
234
|
+
type: 'google_maps_result';
|
|
235
|
+
call_id: string;
|
|
236
|
+
result?: Array<GoogleInteractionsGoogleMapsResultEntry>;
|
|
237
|
+
signature?: string;
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
export type GoogleInteractionsMCPServerToolCallContent = {
|
|
241
|
+
type: 'mcp_server_tool_call';
|
|
242
|
+
id: string;
|
|
243
|
+
name: string;
|
|
244
|
+
server_name: string;
|
|
245
|
+
arguments?: Record<string, unknown>;
|
|
246
|
+
signature?: string;
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
export type GoogleInteractionsMCPServerToolResultContent = {
|
|
250
|
+
type: 'mcp_server_tool_result';
|
|
251
|
+
call_id: string;
|
|
252
|
+
result?: unknown;
|
|
253
|
+
name?: string;
|
|
254
|
+
server_name?: string;
|
|
255
|
+
signature?: string;
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
export type GoogleInteractionsBuiltinToolCallContent =
|
|
259
|
+
| GoogleInteractionsCodeExecutionCallContent
|
|
260
|
+
| GoogleInteractionsURLContextCallContent
|
|
261
|
+
| GoogleInteractionsGoogleSearchCallContent
|
|
262
|
+
| GoogleInteractionsFileSearchCallContent
|
|
263
|
+
| GoogleInteractionsGoogleMapsCallContent
|
|
264
|
+
| GoogleInteractionsMCPServerToolCallContent;
|
|
265
|
+
|
|
266
|
+
export type GoogleInteractionsBuiltinToolResultContent =
|
|
267
|
+
| GoogleInteractionsCodeExecutionResultContent
|
|
268
|
+
| GoogleInteractionsURLContextResultContent
|
|
269
|
+
| GoogleInteractionsGoogleSearchResultContent
|
|
270
|
+
| GoogleInteractionsFileSearchResultContent
|
|
271
|
+
| GoogleInteractionsGoogleMapsResultContent
|
|
272
|
+
| GoogleInteractionsMCPServerToolResultContent;
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* Discriminated union of every content block kind the API supports. For
|
|
276
|
+
* TASK-1, only `text` and `thought` are exercised end-to-end; the remaining
|
|
277
|
+
* variants are listed for type completeness so subsequent tasks can extend the
|
|
278
|
+
* parser/converter without widening the type.
|
|
279
|
+
*/
|
|
280
|
+
export type GoogleInteractionsContent =
|
|
281
|
+
| GoogleInteractionsTextContent
|
|
282
|
+
| GoogleInteractionsImageContent
|
|
283
|
+
| GoogleInteractionsAudioContent
|
|
284
|
+
| GoogleInteractionsDocumentContent
|
|
285
|
+
| GoogleInteractionsVideoContent
|
|
286
|
+
| GoogleInteractionsThoughtContent
|
|
287
|
+
| GoogleInteractionsFunctionCallContent
|
|
288
|
+
| GoogleInteractionsFunctionResultContent
|
|
289
|
+
| { type: string; [k: string]: unknown };
|
|
290
|
+
|
|
291
|
+
export type GoogleInteractionsTurn = {
|
|
292
|
+
role: 'user' | 'model' | string;
|
|
293
|
+
content?: string | Array<GoogleInteractionsContent>;
|
|
294
|
+
};
|
|
295
|
+
|
|
296
|
+
export type GoogleInteractionsInput =
|
|
297
|
+
| string
|
|
298
|
+
| GoogleInteractionsContent
|
|
299
|
+
| Array<GoogleInteractionsContent>
|
|
300
|
+
| Array<GoogleInteractionsTurn>;
|
|
301
|
+
|
|
302
|
+
export type GoogleInteractionsTool =
|
|
303
|
+
| {
|
|
304
|
+
type: 'function';
|
|
305
|
+
name?: string;
|
|
306
|
+
description?: string;
|
|
307
|
+
parameters?: unknown;
|
|
308
|
+
}
|
|
309
|
+
| { type: 'code_execution' }
|
|
310
|
+
| { type: 'url_context' }
|
|
311
|
+
| {
|
|
312
|
+
type: 'computer_use';
|
|
313
|
+
environment?: 'browser';
|
|
314
|
+
excludedPredefinedFunctions?: Array<string>;
|
|
315
|
+
}
|
|
316
|
+
| {
|
|
317
|
+
type: 'mcp_server';
|
|
318
|
+
name?: string;
|
|
319
|
+
url?: string;
|
|
320
|
+
headers?: Record<string, string>;
|
|
321
|
+
allowed_tools?: Array<unknown>;
|
|
322
|
+
}
|
|
323
|
+
| {
|
|
324
|
+
type: 'google_search';
|
|
325
|
+
search_types?: Array<
|
|
326
|
+
'web_search' | 'image_search' | 'enterprise_web_search'
|
|
327
|
+
>;
|
|
328
|
+
}
|
|
329
|
+
| {
|
|
330
|
+
type: 'file_search';
|
|
331
|
+
file_search_store_names?: Array<string>;
|
|
332
|
+
metadata_filter?: string;
|
|
333
|
+
top_k?: number;
|
|
334
|
+
}
|
|
335
|
+
| {
|
|
336
|
+
type: 'google_maps';
|
|
337
|
+
enable_widget?: boolean;
|
|
338
|
+
latitude?: number;
|
|
339
|
+
longitude?: number;
|
|
340
|
+
}
|
|
341
|
+
| {
|
|
342
|
+
type: 'retrieval';
|
|
343
|
+
retrieval_types?: Array<'vertex_ai_search'>;
|
|
344
|
+
vertex_ai_search_config?: {
|
|
345
|
+
datastores?: Array<string>;
|
|
346
|
+
engine?: string;
|
|
347
|
+
};
|
|
348
|
+
};
|
|
349
|
+
|
|
350
|
+
export type GoogleInteractionsToolChoiceType =
|
|
351
|
+
| 'auto'
|
|
352
|
+
| 'any'
|
|
353
|
+
| 'none'
|
|
354
|
+
| 'validated';
|
|
355
|
+
|
|
356
|
+
export type GoogleInteractionsAllowedToolsConfig = {
|
|
357
|
+
allowed_tools?: {
|
|
358
|
+
mode?: GoogleInteractionsToolChoiceType;
|
|
359
|
+
tools?: Array<string>;
|
|
360
|
+
};
|
|
361
|
+
};
|
|
362
|
+
|
|
363
|
+
export type GoogleInteractionsToolChoice =
|
|
364
|
+
| GoogleInteractionsToolChoiceType
|
|
365
|
+
| GoogleInteractionsAllowedToolsConfig;
|
|
366
|
+
|
|
367
|
+
export type GoogleInteractionsThinkingLevel =
|
|
368
|
+
| 'minimal'
|
|
369
|
+
| 'low'
|
|
370
|
+
| 'medium'
|
|
371
|
+
| 'high';
|
|
372
|
+
|
|
373
|
+
export type GoogleInteractionsThinkingSummaries = 'auto' | 'none';
|
|
374
|
+
|
|
375
|
+
export type GoogleInteractionsResponseModality =
|
|
376
|
+
| 'text'
|
|
377
|
+
| 'image'
|
|
378
|
+
| 'audio'
|
|
379
|
+
| 'video'
|
|
380
|
+
| 'document';
|
|
381
|
+
|
|
382
|
+
export type GoogleInteractionsServiceTier = 'flex' | 'standard' | 'priority';
|
|
383
|
+
|
|
384
|
+
export type GoogleInteractionsImageConfig = {
|
|
385
|
+
aspect_ratio?:
|
|
386
|
+
| '1:1'
|
|
387
|
+
| '2:3'
|
|
388
|
+
| '3:2'
|
|
389
|
+
| '3:4'
|
|
390
|
+
| '4:3'
|
|
391
|
+
| '4:5'
|
|
392
|
+
| '5:4'
|
|
393
|
+
| '9:16'
|
|
394
|
+
| '16:9'
|
|
395
|
+
| '21:9'
|
|
396
|
+
| '1:8'
|
|
397
|
+
| '8:1'
|
|
398
|
+
| '1:4'
|
|
399
|
+
| '4:1';
|
|
400
|
+
image_size?: '1K' | '2K' | '4K' | '512';
|
|
401
|
+
};
|
|
402
|
+
|
|
403
|
+
export type GoogleInteractionsGenerationConfig = {
|
|
404
|
+
temperature?: number;
|
|
405
|
+
top_p?: number;
|
|
406
|
+
seed?: number;
|
|
407
|
+
stop_sequences?: Array<string>;
|
|
408
|
+
max_output_tokens?: number;
|
|
409
|
+
thinking_level?: GoogleInteractionsThinkingLevel;
|
|
410
|
+
thinking_summaries?: GoogleInteractionsThinkingSummaries;
|
|
411
|
+
image_config?: GoogleInteractionsImageConfig;
|
|
412
|
+
tool_choice?: GoogleInteractionsToolChoice;
|
|
413
|
+
};
|
|
414
|
+
|
|
415
|
+
export type GoogleInteractionsAgentConfig =
|
|
416
|
+
| { type: 'dynamic'; [k: string]: unknown }
|
|
417
|
+
| {
|
|
418
|
+
type: 'deep-research';
|
|
419
|
+
thinking_summaries?: GoogleInteractionsThinkingSummaries;
|
|
420
|
+
visualization?: 'off' | 'auto';
|
|
421
|
+
collaborative_planning?: boolean;
|
|
422
|
+
};
|
|
423
|
+
|
|
424
|
+
export type GoogleInteractionsRequestBody = {
|
|
425
|
+
model?: string;
|
|
426
|
+
agent?: string;
|
|
427
|
+
input: GoogleInteractionsInput;
|
|
428
|
+
system_instruction?: string;
|
|
429
|
+
tools?: Array<GoogleInteractionsTool>;
|
|
430
|
+
response_format?: unknown;
|
|
431
|
+
response_mime_type?: string;
|
|
432
|
+
response_modalities?: Array<GoogleInteractionsResponseModality>;
|
|
433
|
+
generation_config?: GoogleInteractionsGenerationConfig;
|
|
434
|
+
agent_config?: GoogleInteractionsAgentConfig;
|
|
435
|
+
previous_interaction_id?: string;
|
|
436
|
+
service_tier?: GoogleInteractionsServiceTier;
|
|
437
|
+
store?: boolean;
|
|
438
|
+
stream?: boolean;
|
|
439
|
+
/**
|
|
440
|
+
* Run the interaction in the background. The POST returns immediately with a
|
|
441
|
+
* non-terminal status (`in_progress` / `requires_action`); the client must
|
|
442
|
+
* poll `GET /interactions/{id}` until terminal.
|
|
443
|
+
*
|
|
444
|
+
* Required for agent calls -- the API returns
|
|
445
|
+
* `background=true is required for agent interactions.` otherwise. Not used
|
|
446
|
+
* for model-id calls.
|
|
447
|
+
*/
|
|
448
|
+
background?: boolean;
|
|
449
|
+
};
|
|
450
|
+
|
|
451
|
+
export type GoogleInteractionsStatus =
|
|
452
|
+
| 'in_progress'
|
|
453
|
+
| 'requires_action'
|
|
454
|
+
| 'completed'
|
|
455
|
+
| 'failed'
|
|
456
|
+
| 'cancelled'
|
|
457
|
+
| 'incomplete';
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provider-metadata shape that the Gemini Interactions language model writes
|
|
3
|
+
* onto `result.providerMetadata.google` (and reads back from input messages on
|
|
4
|
+
* the next turn for stateful chaining and signature round-trip).
|
|
5
|
+
*/
|
|
6
|
+
export type GoogleInteractionsProviderMetadata = {
|
|
7
|
+
/**
|
|
8
|
+
* Gemini-server-side interaction id (`Interaction.id`). Pass back in
|
|
9
|
+
* `providerOptions.google.previousInteractionId` to chain stateful turns.
|
|
10
|
+
*/
|
|
11
|
+
interactionId?: string;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Service tier used for this interaction (passthrough for observability).
|
|
15
|
+
*/
|
|
16
|
+
serviceTier?: string;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Per-block signature hash for backend validation. Set by the SDK on output
|
|
20
|
+
* reasoning / tool-call parts and round-tripped on input parts.
|
|
21
|
+
*/
|
|
22
|
+
signature?: string;
|
|
23
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { LanguageModelV3FinishReason } from '@ai-sdk/provider';
|
|
2
|
+
import type { GoogleInteractionsStatus } from './google-interactions-prompt';
|
|
3
|
+
|
|
4
|
+
/*
|
|
5
|
+
* Mapping is intentionally conservative for TASK-1; later tasks may refine the
|
|
6
|
+
* `incomplete` and `cancelled` cases once we observe their wire-format
|
|
7
|
+
* companions. `tool-calls` is selected when the response includes a
|
|
8
|
+
* client-side function call (the API itself signals this via `requires_action`,
|
|
9
|
+
* but `completed + hasFunctionCall` also occurs in practice).
|
|
10
|
+
*/
|
|
11
|
+
export function mapGoogleInteractionsFinishReason({
|
|
12
|
+
status,
|
|
13
|
+
hasFunctionCall,
|
|
14
|
+
}: {
|
|
15
|
+
status: GoogleInteractionsStatus | string | null | undefined;
|
|
16
|
+
hasFunctionCall: boolean;
|
|
17
|
+
}): LanguageModelV3FinishReason['unified'] {
|
|
18
|
+
switch (status) {
|
|
19
|
+
case 'completed':
|
|
20
|
+
return hasFunctionCall ? 'tool-calls' : 'stop';
|
|
21
|
+
case 'requires_action':
|
|
22
|
+
return 'tool-calls';
|
|
23
|
+
case 'failed':
|
|
24
|
+
return 'error';
|
|
25
|
+
case 'incomplete':
|
|
26
|
+
return 'length';
|
|
27
|
+
case 'cancelled':
|
|
28
|
+
return 'other';
|
|
29
|
+
case 'in_progress':
|
|
30
|
+
default:
|
|
31
|
+
return 'other';
|
|
32
|
+
}
|
|
33
|
+
}
|