@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,252 @@
1
+ import type { LanguageModelV4Source } from '@ai-sdk/provider';
2
+ import type {
3
+ GoogleInteractionsAnnotation,
4
+ GoogleInteractionsBuiltinToolResultContent,
5
+ GoogleInteractionsFileCitation,
6
+ GoogleInteractionsGoogleMapsResultContent,
7
+ GoogleInteractionsGoogleSearchResultContent,
8
+ GoogleInteractionsPlaceCitation,
9
+ GoogleInteractionsURLCitation,
10
+ GoogleInteractionsURLContextResultContent,
11
+ } from './google-interactions-prompt';
12
+
13
+ const KNOWN_DOC_EXTENSIONS: Record<string, string> = {
14
+ pdf: 'application/pdf',
15
+ txt: 'text/plain',
16
+ md: 'text/markdown',
17
+ markdown: 'text/markdown',
18
+ doc: 'application/msword',
19
+ docx: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
20
+ };
21
+
22
+ function inferDocMediaType(uriOrName: string): string {
23
+ const lower = uriOrName.toLowerCase();
24
+ for (const [ext, media] of Object.entries(KNOWN_DOC_EXTENSIONS)) {
25
+ if (lower.endsWith(`.${ext}`)) return media;
26
+ }
27
+ return 'application/octet-stream';
28
+ }
29
+
30
+ function basename(uriOrName: string): string | undefined {
31
+ const parts = uriOrName.split('/');
32
+ const last = parts[parts.length - 1];
33
+ return last && last.length > 0 ? last : undefined;
34
+ }
35
+
36
+ /**
37
+ * Maps a single text-block annotation (`url_citation` / `file_citation` /
38
+ * `place_citation`) onto a `LanguageModelV4Source`. Returns `undefined` when
39
+ * the annotation lacks the minimum payload to form a source (e.g. a URL
40
+ * citation without a `url`).
41
+ */
42
+ export function annotationToSource({
43
+ annotation,
44
+ generateId,
45
+ }: {
46
+ annotation: GoogleInteractionsAnnotation | { type: string };
47
+ generateId: () => string;
48
+ }): LanguageModelV4Source | undefined {
49
+ switch (annotation.type) {
50
+ case 'url_citation': {
51
+ const urlCitation = annotation as GoogleInteractionsURLCitation;
52
+ if (urlCitation.url == null || urlCitation.url.length === 0) {
53
+ return undefined;
54
+ }
55
+ return {
56
+ type: 'source',
57
+ sourceType: 'url',
58
+ id: generateId(),
59
+ url: urlCitation.url,
60
+ ...(urlCitation.title != null ? { title: urlCitation.title } : {}),
61
+ };
62
+ }
63
+ case 'file_citation': {
64
+ const fileCitation = annotation as GoogleInteractionsFileCitation;
65
+ const uri =
66
+ fileCitation.url ?? fileCitation.document_uri ?? fileCitation.file_name;
67
+ if (uri == null || uri.length === 0) return undefined;
68
+ if (uri.startsWith('http://') || uri.startsWith('https://')) {
69
+ return {
70
+ type: 'source',
71
+ sourceType: 'url',
72
+ id: generateId(),
73
+ url: uri,
74
+ ...(fileCitation.file_name != null
75
+ ? { title: fileCitation.file_name }
76
+ : {}),
77
+ };
78
+ }
79
+ const filename = fileCitation.file_name ?? basename(uri);
80
+ const mediaType = inferDocMediaType(uri);
81
+ return {
82
+ type: 'source',
83
+ sourceType: 'document',
84
+ id: generateId(),
85
+ mediaType,
86
+ title: fileCitation.file_name ?? filename ?? uri,
87
+ ...(filename != null ? { filename } : {}),
88
+ };
89
+ }
90
+ case 'place_citation': {
91
+ const placeCitation = annotation as GoogleInteractionsPlaceCitation;
92
+ if (placeCitation.url == null || placeCitation.url.length === 0) {
93
+ return undefined;
94
+ }
95
+ return {
96
+ type: 'source',
97
+ sourceType: 'url',
98
+ id: generateId(),
99
+ url: placeCitation.url,
100
+ ...(placeCitation.name != null ? { title: placeCitation.name } : {}),
101
+ };
102
+ }
103
+ default:
104
+ return undefined;
105
+ }
106
+ }
107
+
108
+ /**
109
+ * Maps a built-in tool *result* content block to zero or more
110
+ * `LanguageModelV4Source` parts. The Interactions API exposes grounding
111
+ * sources both inline (via `text_annotation` deltas) and via tool-result
112
+ * content blocks; the latter is what this function consumes.
113
+ *
114
+ * Supported result kinds:
115
+ * - `url_context_result` -> URL sources for each fetched URL with `status: 'success'`
116
+ * - `google_search_result` -> URL sources (when `url` is present), search-suggestion
117
+ * entries are skipped (they are HTML widgets, not citations)
118
+ * - `google_maps_result` -> URL sources for each place with a `url`
119
+ * - `file_search_result` -> document sources (best-effort -- `result[]` is loosely typed)
120
+ */
121
+ export function builtinToolResultToSources({
122
+ block,
123
+ generateId,
124
+ }: {
125
+ block: GoogleInteractionsBuiltinToolResultContent;
126
+ generateId: () => string;
127
+ }): Array<LanguageModelV4Source> {
128
+ const sources: Array<LanguageModelV4Source> = [];
129
+
130
+ switch (block.type) {
131
+ case 'url_context_result': {
132
+ const result =
133
+ (block as GoogleInteractionsURLContextResultContent).result ?? [];
134
+ for (const entry of result) {
135
+ if (entry?.url == null || entry.url.length === 0) continue;
136
+ if (entry.status != null && entry.status !== 'success') continue;
137
+ sources.push({
138
+ type: 'source',
139
+ sourceType: 'url',
140
+ id: generateId(),
141
+ url: entry.url,
142
+ });
143
+ }
144
+ break;
145
+ }
146
+ case 'google_search_result': {
147
+ const result =
148
+ (block as GoogleInteractionsGoogleSearchResultContent).result ?? [];
149
+ for (const entry of result) {
150
+ const url = entry?.url;
151
+ if (url == null || url.length === 0) continue;
152
+ sources.push({
153
+ type: 'source',
154
+ sourceType: 'url',
155
+ id: generateId(),
156
+ url,
157
+ ...(entry.title != null ? { title: entry.title } : {}),
158
+ });
159
+ }
160
+ break;
161
+ }
162
+ case 'google_maps_result': {
163
+ const result =
164
+ (block as GoogleInteractionsGoogleMapsResultContent).result ?? [];
165
+ for (const entry of result) {
166
+ for (const place of entry.places ?? []) {
167
+ if (place.url == null || place.url.length === 0) continue;
168
+ sources.push({
169
+ type: 'source',
170
+ sourceType: 'url',
171
+ id: generateId(),
172
+ url: place.url,
173
+ ...(place.name != null ? { title: place.name } : {}),
174
+ });
175
+ }
176
+ }
177
+ break;
178
+ }
179
+ case 'file_search_result': {
180
+ const result = (block as { result?: Array<unknown> }).result ?? [];
181
+ for (const raw of result) {
182
+ if (raw == null || typeof raw !== 'object') continue;
183
+ const entry = raw as {
184
+ file_name?: string;
185
+ document_uri?: string;
186
+ url?: string;
187
+ title?: string;
188
+ };
189
+ const uri = entry.url ?? entry.document_uri ?? entry.file_name;
190
+ if (uri == null || uri.length === 0) continue;
191
+ if (uri.startsWith('http://') || uri.startsWith('https://')) {
192
+ sources.push({
193
+ type: 'source',
194
+ sourceType: 'url',
195
+ id: generateId(),
196
+ url: uri,
197
+ ...(entry.title != null ? { title: entry.title } : {}),
198
+ });
199
+ continue;
200
+ }
201
+ const filename = entry.file_name ?? basename(uri);
202
+ const mediaType = inferDocMediaType(uri);
203
+ sources.push({
204
+ type: 'source',
205
+ sourceType: 'document',
206
+ id: generateId(),
207
+ mediaType,
208
+ title: entry.title ?? entry.file_name ?? filename ?? uri,
209
+ ...(filename != null ? { filename } : {}),
210
+ });
211
+ }
212
+ break;
213
+ }
214
+ default:
215
+ break;
216
+ }
217
+
218
+ return sources;
219
+ }
220
+
221
+ /**
222
+ * Given a list of annotations attached to a single `text` content block,
223
+ * returns the corresponding `LanguageModelV4Source` parts (de-duplicated by
224
+ * URL/filename to avoid double-counting when the same citation reappears
225
+ * across deltas).
226
+ */
227
+ export function annotationsToSources({
228
+ annotations,
229
+ generateId,
230
+ }: {
231
+ annotations:
232
+ | Array<GoogleInteractionsAnnotation | { type: string }>
233
+ | null
234
+ | undefined;
235
+ generateId: () => string;
236
+ }): Array<LanguageModelV4Source> {
237
+ if (annotations == null) return [];
238
+ const seen = new Set<string>();
239
+ const sources: Array<LanguageModelV4Source> = [];
240
+ for (const annotation of annotations) {
241
+ const source = annotationToSource({ annotation, generateId });
242
+ if (source == null) continue;
243
+ const key =
244
+ source.sourceType === 'url'
245
+ ? `url:${source.url}`
246
+ : `doc:${source.filename ?? source.title}`;
247
+ if (seen.has(key)) continue;
248
+ seen.add(key);
249
+ sources.push(source);
250
+ }
251
+ return sources;
252
+ }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Type-only module: declares the union of supported Gemini Interactions agent
3
+ * names. Used by the `google.interactions({ agent })` factory branch.
4
+ *
5
+ * Strict string-literal union: unknown agent names are a compile-time error.
6
+ * User-defined agents (created via the `/agents` endpoint) are addressed by
7
+ * a separate `{ managedAgent: string }` factory shape — see
8
+ * `GoogleInteractionsModelInput`.
9
+ */
10
+
11
+ export type GoogleInteractionsAgentName =
12
+ | 'deep-research-pro-preview-12-2025'
13
+ | 'deep-research-preview-04-2026'
14
+ | 'deep-research-max-preview-04-2026'
15
+ | 'antigravity-preview-05-2026';