@ai-sdk/google 4.0.0-beta.8 → 4.0.0-beta.82

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.
Files changed (71) hide show
  1. package/CHANGELOG.md +608 -5
  2. package/README.md +6 -4
  3. package/dist/index.d.ts +297 -54
  4. package/dist/index.js +5409 -640
  5. package/dist/index.js.map +1 -1
  6. package/dist/internal/index.d.ts +97 -26
  7. package/dist/internal/index.js +1653 -453
  8. package/dist/internal/index.js.map +1 -1
  9. package/docs/{15-google-generative-ai.mdx → 15-google.mdx} +784 -69
  10. package/package.json +16 -17
  11. package/src/{convert-google-generative-ai-usage.ts → convert-google-usage.ts} +13 -5
  12. package/src/convert-json-schema-to-openapi-schema.ts +1 -1
  13. package/src/convert-to-google-messages.ts +647 -0
  14. package/src/{google-generative-ai-embedding-options.ts → google-embedding-model-options.ts} +9 -2
  15. package/src/{google-generative-ai-embedding-model.ts → google-embedding-model.ts} +31 -18
  16. package/src/google-error.ts +1 -1
  17. package/src/google-files.ts +225 -0
  18. package/src/google-image-model-options.ts +35 -0
  19. package/src/{google-generative-ai-image-model.ts → google-image-model.ts} +116 -65
  20. package/src/{google-generative-ai-image-settings.ts → google-image-settings.ts} +2 -2
  21. package/src/google-json-accumulator.ts +371 -0
  22. package/src/{google-generative-ai-options.ts → google-language-model-options.ts} +50 -5
  23. package/src/{google-generative-ai-language-model.ts → google-language-model.ts} +691 -217
  24. package/src/google-prepare-tools.ts +72 -12
  25. package/src/google-prompt.ts +86 -0
  26. package/src/google-provider.ts +157 -53
  27. package/src/google-speech-api.ts +36 -0
  28. package/src/google-speech-model-options.ts +48 -0
  29. package/src/google-speech-model.ts +311 -0
  30. package/src/google-video-model-options.ts +43 -0
  31. package/src/{google-generative-ai-video-model.ts → google-video-model.ts} +25 -60
  32. package/src/{google-generative-ai-video-settings.ts → google-video-settings.ts} +2 -1
  33. package/src/index.ts +40 -9
  34. package/src/interactions/build-google-interactions-stream-transform.ts +818 -0
  35. package/src/interactions/cancel-google-interaction.ts +60 -0
  36. package/src/interactions/convert-google-interactions-usage.ts +47 -0
  37. package/src/interactions/convert-to-google-interactions-input.ts +557 -0
  38. package/src/interactions/extract-google-interactions-sources.ts +252 -0
  39. package/src/interactions/google-interactions-agent.ts +15 -0
  40. package/src/interactions/google-interactions-api.ts +530 -0
  41. package/src/interactions/google-interactions-language-model-options.ts +262 -0
  42. package/src/interactions/google-interactions-language-model.ts +776 -0
  43. package/src/interactions/google-interactions-prompt.ts +582 -0
  44. package/src/interactions/google-interactions-provider-metadata.ts +23 -0
  45. package/src/interactions/map-google-interactions-finish-reason.ts +31 -0
  46. package/src/interactions/parse-google-interactions-outputs.ts +252 -0
  47. package/src/interactions/poll-google-interactions.ts +129 -0
  48. package/src/interactions/prepare-google-interactions-tools.ts +245 -0
  49. package/src/interactions/stream-google-interactions.ts +242 -0
  50. package/src/interactions/synthesize-google-interactions-agent-stream.ts +185 -0
  51. package/src/internal/index.ts +3 -2
  52. package/src/{map-google-generative-ai-finish-reason.ts → map-google-finish-reason.ts} +3 -3
  53. package/src/realtime/google-realtime-event-mapper.ts +383 -0
  54. package/src/realtime/google-realtime-model-options.ts +3 -0
  55. package/src/realtime/google-realtime-model.ts +160 -0
  56. package/src/realtime/index.ts +2 -0
  57. package/src/tool/code-execution.ts +2 -2
  58. package/src/tool/enterprise-web-search.ts +9 -3
  59. package/src/tool/file-search.ts +5 -7
  60. package/src/tool/google-maps.ts +3 -2
  61. package/src/tool/google-search.ts +11 -12
  62. package/src/tool/url-context.ts +4 -2
  63. package/src/tool/vertex-rag-store.ts +9 -6
  64. package/dist/index.d.mts +0 -384
  65. package/dist/index.mjs +0 -2519
  66. package/dist/index.mjs.map +0 -1
  67. package/dist/internal/index.d.mts +0 -287
  68. package/dist/internal/index.mjs +0 -1708
  69. package/dist/internal/index.mjs.map +0 -1
  70. package/src/convert-to-google-generative-ai-messages.ts +0 -239
  71. package/src/google-generative-ai-prompt.ts +0 -47
@@ -0,0 +1,582 @@
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`.
6
+ */
7
+
8
+ export type GoogleInteractionsTextContent = {
9
+ type: 'text';
10
+ text: string;
11
+ annotations?: Array<GoogleInteractionsAnnotation | { type: string }>;
12
+ };
13
+
14
+ export type GoogleInteractionsImageContent = {
15
+ type: 'image';
16
+ data?: string;
17
+ mime_type?: string;
18
+ uri?: string;
19
+ resolution?: 'low' | 'medium' | 'high' | 'ultra_high';
20
+ };
21
+
22
+ export type GoogleInteractionsAudioContent = {
23
+ type: 'audio';
24
+ data?: string;
25
+ mime_type?: string;
26
+ uri?: string;
27
+ channels?: number;
28
+ sample_rate?: number;
29
+ };
30
+
31
+ export type GoogleInteractionsDocumentContent = {
32
+ type: 'document';
33
+ data?: string;
34
+ mime_type?: string;
35
+ uri?: string;
36
+ };
37
+
38
+ export type GoogleInteractionsVideoContent = {
39
+ type: 'video';
40
+ data?: string;
41
+ mime_type?: string;
42
+ uri?: string;
43
+ resolution?: 'low' | 'medium' | 'high' | 'ultra_high';
44
+ };
45
+
46
+ export type GoogleInteractionsThoughtSummaryItem =
47
+ | GoogleInteractionsTextContent
48
+ | GoogleInteractionsImageContent;
49
+
50
+ export type GoogleInteractionsFunctionResultContent = {
51
+ type: 'function_result';
52
+ call_id: string;
53
+ result:
54
+ | string
55
+ | Array<GoogleInteractionsTextContent | GoogleInteractionsImageContent>
56
+ | unknown;
57
+ name?: string;
58
+ is_error?: boolean;
59
+ signature?: string;
60
+ };
61
+
62
+ /**
63
+ * Annotation types attached to a `text` content block:
64
+ * - `url_citation` (web) — `url` + optional `title`
65
+ * - `file_citation` — `url` for the citation target; optional `document_uri`
66
+ * / `file_name` for doc references
67
+ * - `place_citation` — Maps grounding, carries `url`
68
+ */
69
+ export type GoogleInteractionsURLCitation = {
70
+ type: 'url_citation';
71
+ url?: string;
72
+ title?: string;
73
+ start_index?: number;
74
+ end_index?: number;
75
+ };
76
+
77
+ export type GoogleInteractionsFileCitation = {
78
+ type: 'file_citation';
79
+ file_name?: string;
80
+ document_uri?: string;
81
+ url?: string;
82
+ page_number?: number;
83
+ media_id?: string;
84
+ start_index?: number;
85
+ end_index?: number;
86
+ custom_metadata?: Record<string, unknown>;
87
+ };
88
+
89
+ export type GoogleInteractionsPlaceCitation = {
90
+ type: 'place_citation';
91
+ name?: string;
92
+ url?: string;
93
+ place_id?: string;
94
+ start_index?: number;
95
+ end_index?: number;
96
+ review_snippets?: Array<{
97
+ review_id?: string;
98
+ title?: string;
99
+ url?: string;
100
+ }>;
101
+ };
102
+
103
+ export type GoogleInteractionsAnnotation =
104
+ | GoogleInteractionsURLCitation
105
+ | GoogleInteractionsFileCitation
106
+ | GoogleInteractionsPlaceCitation;
107
+
108
+ /*
109
+ * --- Step payload shapes ---
110
+ *
111
+ * `function_call`, `thought`, and the built-in `*_call`/`*_result` are
112
+ * top-level **step** types — their fields live directly on the step object
113
+ * (no `content` indirection). The types below model those payloads; the step
114
+ * wrapper (`type` discriminator + payload) is `GoogleInteractionsStep`
115
+ * further down.
116
+ */
117
+
118
+ export type GoogleInteractionsFunctionCallStepPayload = {
119
+ id: string;
120
+ name: string;
121
+ arguments: Record<string, unknown>;
122
+ signature?: string;
123
+ };
124
+
125
+ export type GoogleInteractionsThoughtStepPayload = {
126
+ signature?: string;
127
+ summary?: Array<GoogleInteractionsThoughtSummaryItem>;
128
+ };
129
+
130
+ export type GoogleInteractionsCodeExecutionCallStepPayload = {
131
+ id: string;
132
+ arguments?: { code?: string; language?: string };
133
+ signature?: string;
134
+ };
135
+
136
+ export type GoogleInteractionsCodeExecutionResultStepPayload = {
137
+ call_id: string;
138
+ result?: string;
139
+ is_error?: boolean;
140
+ signature?: string;
141
+ };
142
+
143
+ export type GoogleInteractionsURLContextCallStepPayload = {
144
+ id: string;
145
+ arguments?: { urls?: Array<string> };
146
+ signature?: string;
147
+ };
148
+
149
+ export type GoogleInteractionsURLContextResultEntry = {
150
+ url?: string;
151
+ status?: 'success' | 'error' | 'paywall' | 'unsafe' | string;
152
+ };
153
+
154
+ export type GoogleInteractionsURLContextResultStepPayload = {
155
+ call_id: string;
156
+ result?: Array<GoogleInteractionsURLContextResultEntry>;
157
+ is_error?: boolean;
158
+ signature?: string;
159
+ };
160
+
161
+ export type GoogleInteractionsGoogleSearchCallStepPayload = {
162
+ id: string;
163
+ arguments?: { queries?: Array<string> };
164
+ search_type?: 'web_search' | 'image_search' | 'enterprise_web_search';
165
+ signature?: string;
166
+ };
167
+
168
+ export type GoogleInteractionsGoogleSearchResultEntry = {
169
+ search_suggestions?: string;
170
+ url?: string;
171
+ title?: string;
172
+ };
173
+
174
+ export type GoogleInteractionsGoogleSearchResultStepPayload = {
175
+ call_id: string;
176
+ result?: Array<GoogleInteractionsGoogleSearchResultEntry>;
177
+ is_error?: boolean;
178
+ signature?: string;
179
+ };
180
+
181
+ export type GoogleInteractionsFileSearchCallStepPayload = {
182
+ id: string;
183
+ signature?: string;
184
+ };
185
+
186
+ export type GoogleInteractionsFileSearchResultStepPayload = {
187
+ call_id: string;
188
+ result?: Array<unknown>;
189
+ signature?: string;
190
+ };
191
+
192
+ export type GoogleInteractionsGoogleMapsCallStepPayload = {
193
+ id: string;
194
+ arguments?: { queries?: Array<string> };
195
+ signature?: string;
196
+ };
197
+
198
+ export type GoogleInteractionsGoogleMapsResultPlace = {
199
+ name?: string;
200
+ place_id?: string;
201
+ url?: string;
202
+ review_snippets?: Array<{
203
+ review_id?: string;
204
+ title?: string;
205
+ url?: string;
206
+ }>;
207
+ };
208
+
209
+ export type GoogleInteractionsGoogleMapsResultEntry = {
210
+ places?: Array<GoogleInteractionsGoogleMapsResultPlace>;
211
+ widget_context_token?: string;
212
+ };
213
+
214
+ export type GoogleInteractionsGoogleMapsResultStepPayload = {
215
+ call_id: string;
216
+ result?: Array<GoogleInteractionsGoogleMapsResultEntry>;
217
+ signature?: string;
218
+ };
219
+
220
+ export type GoogleInteractionsMCPServerToolCallStepPayload = {
221
+ id: string;
222
+ name: string;
223
+ server_name: string;
224
+ arguments?: Record<string, unknown>;
225
+ signature?: string;
226
+ };
227
+
228
+ export type GoogleInteractionsMCPServerToolResultStepPayload = {
229
+ call_id: string;
230
+ result?: unknown;
231
+ name?: string;
232
+ server_name?: string;
233
+ signature?: string;
234
+ };
235
+
236
+ /*
237
+ * Discriminated step union — the elements of `response.steps[]` and the
238
+ * `step` field on `step.start` SSE events.
239
+ */
240
+ export type GoogleInteractionsModelOutputStep = {
241
+ type: 'model_output';
242
+ content?: Array<GoogleInteractionsContentBlock>;
243
+ };
244
+
245
+ export type GoogleInteractionsUserInputStep = {
246
+ type: 'user_input';
247
+ content?: Array<GoogleInteractionsContentBlock>;
248
+ };
249
+
250
+ export type GoogleInteractionsFunctionCallStep = {
251
+ type: 'function_call';
252
+ } & GoogleInteractionsFunctionCallStepPayload;
253
+
254
+ export type GoogleInteractionsThoughtStep = {
255
+ type: 'thought';
256
+ } & GoogleInteractionsThoughtStepPayload;
257
+
258
+ export type GoogleInteractionsBuiltinToolCallStep =
259
+ | ({
260
+ type: 'google_search_call';
261
+ } & GoogleInteractionsGoogleSearchCallStepPayload)
262
+ | ({
263
+ type: 'code_execution_call';
264
+ } & GoogleInteractionsCodeExecutionCallStepPayload)
265
+ | ({ type: 'url_context_call' } & GoogleInteractionsURLContextCallStepPayload)
266
+ | ({ type: 'file_search_call' } & GoogleInteractionsFileSearchCallStepPayload)
267
+ | ({ type: 'google_maps_call' } & GoogleInteractionsGoogleMapsCallStepPayload)
268
+ | ({
269
+ type: 'mcp_server_tool_call';
270
+ } & GoogleInteractionsMCPServerToolCallStepPayload);
271
+
272
+ export type GoogleInteractionsBuiltinToolResultStep =
273
+ | ({
274
+ type: 'google_search_result';
275
+ } & GoogleInteractionsGoogleSearchResultStepPayload)
276
+ | ({
277
+ type: 'code_execution_result';
278
+ } & GoogleInteractionsCodeExecutionResultStepPayload)
279
+ | ({
280
+ type: 'url_context_result';
281
+ } & GoogleInteractionsURLContextResultStepPayload)
282
+ | ({
283
+ type: 'file_search_result';
284
+ } & GoogleInteractionsFileSearchResultStepPayload)
285
+ | ({
286
+ type: 'google_maps_result';
287
+ } & GoogleInteractionsGoogleMapsResultStepPayload)
288
+ | ({
289
+ type: 'mcp_server_tool_result';
290
+ } & GoogleInteractionsMCPServerToolResultStepPayload);
291
+
292
+ export type GoogleInteractionsStep =
293
+ | GoogleInteractionsUserInputStep
294
+ | GoogleInteractionsModelOutputStep
295
+ | GoogleInteractionsFunctionCallStep
296
+ | GoogleInteractionsThoughtStep
297
+ | GoogleInteractionsBuiltinToolCallStep
298
+ | GoogleInteractionsBuiltinToolResultStep
299
+ | { type: string; [k: string]: unknown };
300
+
301
+ /*
302
+ * Inner content-block types (what lives inside `model_output.content[]` and
303
+ * `user_input.content[]`). Function calls, thoughts, and built-in tool
304
+ * call/result blocks are steps, not content blocks.
305
+ */
306
+ export type GoogleInteractionsContentBlock =
307
+ | GoogleInteractionsTextContent
308
+ | GoogleInteractionsImageContent
309
+ | GoogleInteractionsAudioContent
310
+ | GoogleInteractionsDocumentContent
311
+ | GoogleInteractionsVideoContent
312
+ | GoogleInteractionsFunctionResultContent
313
+ | { type: string; [k: string]: unknown };
314
+
315
+ /**
316
+ * Alias kept for the file-part converter surface; identical to
317
+ * `GoogleInteractionsContentBlock`.
318
+ */
319
+ export type GoogleInteractionsContent = GoogleInteractionsContentBlock;
320
+
321
+ /*
322
+ * `input` is an array of steps. A single-turn user prompt is sent as
323
+ * `[{ type: 'user_input', content: [...] }]`.
324
+ */
325
+ export type GoogleInteractionsInput = Array<GoogleInteractionsStep>;
326
+
327
+ export type GoogleInteractionsTool =
328
+ | {
329
+ type: 'function';
330
+ name?: string;
331
+ description?: string;
332
+ parameters?: unknown;
333
+ }
334
+ | { type: 'code_execution' }
335
+ | { type: 'url_context' }
336
+ | {
337
+ type: 'computer_use';
338
+ environment?: 'browser';
339
+ excludedPredefinedFunctions?: Array<string>;
340
+ }
341
+ | {
342
+ type: 'mcp_server';
343
+ name?: string;
344
+ url?: string;
345
+ headers?: Record<string, string>;
346
+ allowed_tools?: Array<unknown>;
347
+ }
348
+ | {
349
+ type: 'google_search';
350
+ search_types?: Array<
351
+ 'web_search' | 'image_search' | 'enterprise_web_search'
352
+ >;
353
+ }
354
+ | {
355
+ type: 'file_search';
356
+ file_search_store_names?: Array<string>;
357
+ metadata_filter?: string;
358
+ top_k?: number;
359
+ }
360
+ | {
361
+ type: 'google_maps';
362
+ enable_widget?: boolean;
363
+ latitude?: number;
364
+ longitude?: number;
365
+ }
366
+ | {
367
+ type: 'retrieval';
368
+ retrieval_types?: Array<'vertex_ai_search'>;
369
+ vertex_ai_search_config?: {
370
+ datastores?: Array<string>;
371
+ engine?: string;
372
+ };
373
+ };
374
+
375
+ export type GoogleInteractionsToolChoiceType =
376
+ | 'auto'
377
+ | 'any'
378
+ | 'none'
379
+ | 'validated';
380
+
381
+ export type GoogleInteractionsAllowedToolsConfig = {
382
+ allowed_tools?: {
383
+ mode?: GoogleInteractionsToolChoiceType;
384
+ tools?: Array<string>;
385
+ };
386
+ };
387
+
388
+ export type GoogleInteractionsToolChoice =
389
+ | GoogleInteractionsToolChoiceType
390
+ | GoogleInteractionsAllowedToolsConfig;
391
+
392
+ export type GoogleInteractionsThinkingLevel =
393
+ | 'minimal'
394
+ | 'low'
395
+ | 'medium'
396
+ | 'high';
397
+
398
+ export type GoogleInteractionsThinkingSummaries = 'auto' | 'none';
399
+
400
+ export type GoogleInteractionsResponseModality =
401
+ | 'text'
402
+ | 'image'
403
+ | 'audio'
404
+ | 'video'
405
+ | 'document';
406
+
407
+ export type GoogleInteractionsServiceTier = 'flex' | 'standard' | 'priority';
408
+
409
+ export type GoogleInteractionsAspectRatio =
410
+ | '1:1'
411
+ | '2:3'
412
+ | '3:2'
413
+ | '3:4'
414
+ | '4:3'
415
+ | '4:5'
416
+ | '5:4'
417
+ | '9:16'
418
+ | '16:9'
419
+ | '21:9'
420
+ | '1:8'
421
+ | '8:1'
422
+ | '1:4'
423
+ | '4:1';
424
+
425
+ export type GoogleInteractionsImageSize = '1K' | '2K' | '4K' | '512';
426
+
427
+ /*
428
+ * `response_format` is a polymorphic entry. Multiple modalities are requested
429
+ * by sending an array of entries. Entries the SDK constructs:
430
+ *
431
+ * { type: 'text', mime_type: 'application/json', schema: <JSONSchema> }
432
+ * -- structured output (JSON mode). `mime_type` is required; `schema` is
433
+ * optional but recommended.
434
+ *
435
+ * { type: 'image', mime_type, aspect_ratio?, image_size? }
436
+ * -- image generation. `mime_type` defaults to `image/png`.
437
+ */
438
+ export type GoogleInteractionsResponseFormatTextEntry = {
439
+ type: 'text';
440
+ mime_type?: string;
441
+ schema?: unknown;
442
+ };
443
+
444
+ export type GoogleInteractionsResponseFormatImageEntry = {
445
+ type: 'image';
446
+ mime_type?: string;
447
+ aspect_ratio?: GoogleInteractionsAspectRatio;
448
+ image_size?: GoogleInteractionsImageSize;
449
+ };
450
+
451
+ export type GoogleInteractionsResponseFormatAudioEntry = {
452
+ type: 'audio';
453
+ mime_type?: string;
454
+ };
455
+
456
+ export type GoogleInteractionsResponseFormatEntry =
457
+ | GoogleInteractionsResponseFormatTextEntry
458
+ | GoogleInteractionsResponseFormatImageEntry
459
+ | GoogleInteractionsResponseFormatAudioEntry;
460
+
461
+ export type GoogleInteractionsGenerationConfig = {
462
+ temperature?: number;
463
+ top_p?: number;
464
+ seed?: number;
465
+ stop_sequences?: Array<string>;
466
+ max_output_tokens?: number;
467
+ thinking_level?: GoogleInteractionsThinkingLevel;
468
+ thinking_summaries?: GoogleInteractionsThinkingSummaries;
469
+ tool_choice?: GoogleInteractionsToolChoice;
470
+ };
471
+
472
+ export type GoogleInteractionsAgentConfig =
473
+ | { type: 'dynamic'; [k: string]: unknown }
474
+ | {
475
+ type: 'deep-research';
476
+ thinking_summaries?: GoogleInteractionsThinkingSummaries;
477
+ visualization?: 'off' | 'auto';
478
+ collaborative_planning?: boolean;
479
+ };
480
+
481
+ export type GoogleInteractionsGcsSource = {
482
+ type: 'gcs';
483
+ source: string;
484
+ target?: string;
485
+ };
486
+
487
+ export type GoogleInteractionsRepositorySource = {
488
+ type: 'repository';
489
+ source: string;
490
+ target?: string;
491
+ };
492
+
493
+ export type GoogleInteractionsInlineSource = {
494
+ type: 'inline';
495
+ content: string;
496
+ target: string;
497
+ };
498
+
499
+ export type GoogleInteractionsEnvironmentSource =
500
+ | GoogleInteractionsGcsSource
501
+ | GoogleInteractionsRepositorySource
502
+ | GoogleInteractionsInlineSource;
503
+
504
+ export type GoogleInteractionsNetworkAllowlistEntry = {
505
+ domain: string;
506
+ transform?: Array<Record<string, string>>;
507
+ };
508
+
509
+ export type GoogleInteractionsNetworkConfig =
510
+ | 'disabled'
511
+ | { allowlist: Array<GoogleInteractionsNetworkAllowlistEntry> };
512
+
513
+ /**
514
+ * Environment configuration for the agent sandbox.
515
+ *
516
+ * - `"remote"`: provision a fresh sandbox for this call.
517
+ * - any other string: an existing `environment_id` to reuse (forks the
518
+ * previous sandbox so its filesystem and installed packages persist).
519
+ * - object form: provision a fresh sandbox and preload it with `sources`
520
+ * and/or constrain outbound traffic via `network`.
521
+ */
522
+ export type GoogleInteractionsEnvironment =
523
+ | string
524
+ | {
525
+ type: 'remote';
526
+ sources?: Array<GoogleInteractionsEnvironmentSource>;
527
+ network?: GoogleInteractionsNetworkConfig;
528
+ };
529
+
530
+ export type GoogleInteractionsRequestBody = {
531
+ model?: string;
532
+ agent?: string;
533
+ input: GoogleInteractionsInput;
534
+ system_instruction?: string;
535
+ tools?: Array<GoogleInteractionsTool>;
536
+ response_format?: Array<GoogleInteractionsResponseFormatEntry>;
537
+ response_modalities?: Array<GoogleInteractionsResponseModality>;
538
+ generation_config?: GoogleInteractionsGenerationConfig;
539
+ agent_config?: GoogleInteractionsAgentConfig;
540
+ previous_interaction_id?: string;
541
+ service_tier?: GoogleInteractionsServiceTier;
542
+ store?: boolean;
543
+ stream?: boolean;
544
+ environment?: GoogleInteractionsEnvironment;
545
+ /**
546
+ * Run the interaction in the background. The POST returns immediately with a
547
+ * non-terminal status (`in_progress` / `requires_action`); the client must
548
+ * poll `GET /interactions/{id}` until terminal.
549
+ *
550
+ * Required for agent calls -- the API returns
551
+ * `background=true is required for agent interactions.` otherwise. Not used
552
+ * for model-id calls.
553
+ */
554
+ background?: boolean;
555
+ };
556
+
557
+ export type GoogleInteractionsStatus =
558
+ | 'in_progress'
559
+ | 'requires_action'
560
+ | 'completed'
561
+ | 'failed'
562
+ | 'cancelled'
563
+ | 'incomplete';
564
+
565
+ /*
566
+ * Aliases used by the source extractor; structurally equivalent to their
567
+ * step-payload counterparts.
568
+ */
569
+ export type GoogleInteractionsBuiltinToolResultContent =
570
+ GoogleInteractionsBuiltinToolResultStep;
571
+ export type GoogleInteractionsGoogleSearchResultContent = Extract<
572
+ GoogleInteractionsBuiltinToolResultStep,
573
+ { type: 'google_search_result' }
574
+ >;
575
+ export type GoogleInteractionsGoogleMapsResultContent = Extract<
576
+ GoogleInteractionsBuiltinToolResultStep,
577
+ { type: 'google_maps_result' }
578
+ >;
579
+ export type GoogleInteractionsURLContextResultContent = Extract<
580
+ GoogleInteractionsBuiltinToolResultStep,
581
+ { type: 'url_context_result' }
582
+ >;
@@ -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,31 @@
1
+ import type { LanguageModelV4FinishReason } from '@ai-sdk/provider';
2
+ import type { GoogleInteractionsStatus } from './google-interactions-prompt';
3
+
4
+ /*
5
+ * `tool-calls` is selected when the response includes a client-side function
6
+ * call. The API itself signals this via `requires_action`, but
7
+ * `completed + hasFunctionCall` also occurs in practice.
8
+ */
9
+ export function mapGoogleInteractionsFinishReason({
10
+ status,
11
+ hasFunctionCall,
12
+ }: {
13
+ status: GoogleInteractionsStatus | string | null | undefined;
14
+ hasFunctionCall: boolean;
15
+ }): LanguageModelV4FinishReason['unified'] {
16
+ switch (status) {
17
+ case 'completed':
18
+ return hasFunctionCall ? 'tool-calls' : 'stop';
19
+ case 'requires_action':
20
+ return 'tool-calls';
21
+ case 'failed':
22
+ return 'error';
23
+ case 'incomplete':
24
+ return 'length';
25
+ case 'cancelled':
26
+ return 'other';
27
+ case 'in_progress':
28
+ default:
29
+ return 'other';
30
+ }
31
+ }