@ai-sdk/google 4.0.46 → 4.0.48

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 CHANGED
@@ -1,5 +1,19 @@
1
1
  # @ai-sdk/google
2
2
 
3
+ ## 4.0.48
4
+
5
+ ### Patch Changes
6
+
7
+ - 6c5a1ed: Inline local JSON Schema references in Google tool and structured-output schemas.
8
+
9
+ ## 4.0.47
10
+
11
+ ### Patch Changes
12
+
13
+ - e6087c9: fix: handle empty string tool call IDs
14
+ - Updated dependencies [e6087c9]
15
+ - @ai-sdk/provider-utils@5.0.28
16
+
3
17
  ## 4.0.46
4
18
 
5
19
  ### Patch Changes
package/dist/index.js CHANGED
@@ -7,7 +7,7 @@ import {
7
7
  } from "@ai-sdk/provider-utils";
8
8
 
9
9
  // src/version.ts
10
- var VERSION = true ? "4.0.46" : "0.0.0-test";
10
+ var VERSION = true ? "4.0.48" : "0.0.0-test";
11
11
 
12
12
  // src/google-embedding-model.ts
13
13
  import {
@@ -303,21 +303,37 @@ import {
303
303
  UnsupportedFunctionalityError
304
304
  } from "@ai-sdk/provider";
305
305
  function convertJSONSchemaToOpenAPISchema(jsonSchema, isRoot = true) {
306
+ const rootSchema = typeof jsonSchema === "object" ? jsonSchema : void 0;
307
+ return convertJSONSchemaDefinition(jsonSchema, isRoot, {
308
+ definitions: rootSchema == null ? void 0 : rootSchema.definitions,
309
+ dollarDefinitions: rootSchema == null ? void 0 : rootSchema.$defs,
310
+ resolvingReferences: /* @__PURE__ */ new Set()
311
+ });
312
+ }
313
+ function convertJSONSchemaDefinition(jsonSchema, isRoot, referenceContext) {
306
314
  if (jsonSchema == null) {
307
315
  return void 0;
308
316
  }
317
+ if (typeof jsonSchema === "boolean") {
318
+ return { type: "boolean", properties: {} };
319
+ }
320
+ if (jsonSchema.$ref != null) {
321
+ return convertJSONSchemaReference({
322
+ jsonSchema,
323
+ reference: jsonSchema.$ref,
324
+ isRoot,
325
+ referenceContext
326
+ });
327
+ }
309
328
  if (isEmptyObjectSchema(jsonSchema)) {
310
329
  if (isRoot) {
311
330
  return void 0;
312
331
  }
313
- if (typeof jsonSchema === "object" && jsonSchema.description) {
332
+ if (jsonSchema.description) {
314
333
  return { type: "object", description: jsonSchema.description };
315
334
  }
316
335
  return { type: "object" };
317
336
  }
318
- if (typeof jsonSchema === "boolean") {
319
- return { type: "boolean", properties: {} };
320
- }
321
337
  const {
322
338
  type,
323
339
  description,
@@ -359,18 +375,20 @@ function convertJSONSchemaToOpenAPISchema(jsonSchema, isRoot = true) {
359
375
  if (properties != null) {
360
376
  result.properties = Object.entries(properties).reduce(
361
377
  (acc, [key, value]) => {
362
- acc[key] = convertJSONSchemaToOpenAPISchema(value, false);
378
+ acc[key] = convertJSONSchemaDefinition(value, false, referenceContext);
363
379
  return acc;
364
380
  },
365
381
  {}
366
382
  );
367
383
  }
368
384
  if (items) {
369
- result.items = Array.isArray(items) ? items.map((item) => convertJSONSchemaToOpenAPISchema(item, false)) : convertJSONSchemaToOpenAPISchema(items, false);
385
+ result.items = Array.isArray(items) ? items.map(
386
+ (item) => convertJSONSchemaDefinition(item, false, referenceContext)
387
+ ) : convertJSONSchemaDefinition(items, false, referenceContext);
370
388
  }
371
389
  if (allOf) {
372
390
  result.allOf = allOf.map(
373
- (item) => convertJSONSchemaToOpenAPISchema(item, false)
391
+ (item) => convertJSONSchemaDefinition(item, false, referenceContext)
374
392
  );
375
393
  }
376
394
  if (anyOf) {
@@ -381,9 +399,10 @@ function convertJSONSchemaToOpenAPISchema(jsonSchema, isRoot = true) {
381
399
  (schema) => !(typeof schema === "object" && (schema == null ? void 0 : schema.type) === "null")
382
400
  );
383
401
  if (nonNullSchemas.length === 1) {
384
- const converted = convertJSONSchemaToOpenAPISchema(
402
+ const converted = convertJSONSchemaDefinition(
385
403
  nonNullSchemas[0],
386
- false
404
+ false,
405
+ referenceContext
387
406
  );
388
407
  if (typeof converted === "object") {
389
408
  result.nullable = true;
@@ -391,19 +410,19 @@ function convertJSONSchemaToOpenAPISchema(jsonSchema, isRoot = true) {
391
410
  }
392
411
  } else {
393
412
  result.anyOf = nonNullSchemas.map(
394
- (item) => convertJSONSchemaToOpenAPISchema(item, false)
413
+ (item) => convertJSONSchemaDefinition(item, false, referenceContext)
395
414
  );
396
415
  result.nullable = true;
397
416
  }
398
417
  } else {
399
418
  result.anyOf = anyOf.map(
400
- (item) => convertJSONSchemaToOpenAPISchema(item, false)
419
+ (item) => convertJSONSchemaDefinition(item, false, referenceContext)
401
420
  );
402
421
  }
403
422
  }
404
423
  if (oneOf) {
405
424
  result.oneOf = oneOf.map(
406
- (item) => convertJSONSchemaToOpenAPISchema(item, false)
425
+ (item) => convertJSONSchemaDefinition(item, false, referenceContext)
407
426
  );
408
427
  }
409
428
  if (minLength !== void 0) {
@@ -411,6 +430,76 @@ function convertJSONSchemaToOpenAPISchema(jsonSchema, isRoot = true) {
411
430
  }
412
431
  return result;
413
432
  }
433
+ function convertJSONSchemaReference({
434
+ jsonSchema,
435
+ reference,
436
+ isRoot,
437
+ referenceContext
438
+ }) {
439
+ const { definition, referenceKey } = getReferencedDefinition(
440
+ reference,
441
+ referenceContext
442
+ );
443
+ if (referenceContext.resolvingReferences.has(referenceKey)) {
444
+ throw new UnsupportedFunctionalityError({
445
+ functionality: `recursive JSON Schema reference: ${reference}`,
446
+ message: "Google schema conversion does not support recursive JSON Schema references."
447
+ });
448
+ }
449
+ const resolvingReferences = new Set(referenceContext.resolvingReferences);
450
+ resolvingReferences.add(referenceKey);
451
+ const { $ref: _reference, ...siblingSchema } = jsonSchema;
452
+ const resolvedSchema = typeof definition === "boolean" ? definition ? siblingSchema : false : { ...definition, ...siblingSchema };
453
+ return convertJSONSchemaDefinition(resolvedSchema, isRoot, {
454
+ ...referenceContext,
455
+ resolvingReferences
456
+ });
457
+ }
458
+ function getReferencedDefinition(reference, referenceContext) {
459
+ const definitionSources = [
460
+ {
461
+ prefix: "#/$defs/",
462
+ definitions: referenceContext.dollarDefinitions
463
+ },
464
+ {
465
+ prefix: "#/definitions/",
466
+ definitions: referenceContext.definitions
467
+ }
468
+ ];
469
+ const source = definitionSources.find(
470
+ ({ prefix }) => reference.startsWith(prefix)
471
+ );
472
+ const encodedDefinitionName = source ? reference.slice(source.prefix.length) : void 0;
473
+ if (source == null || encodedDefinitionName == null || encodedDefinitionName.length === 0 || encodedDefinitionName.includes("/")) {
474
+ throwUnsupportedReference(reference);
475
+ }
476
+ let decodedDefinitionName;
477
+ try {
478
+ decodedDefinitionName = decodeURIComponent(encodedDefinitionName);
479
+ } catch (e) {
480
+ throwUnsupportedReference(reference);
481
+ }
482
+ if (decodedDefinitionName.includes("/") || /~(?![01])/u.test(decodedDefinitionName) || source.definitions == null) {
483
+ throwUnsupportedReference(reference);
484
+ }
485
+ const definitionName = decodedDefinitionName.replace(
486
+ /~[01]/g,
487
+ (match) => match === "~1" ? "/" : "~"
488
+ );
489
+ if (!Object.prototype.hasOwnProperty.call(source.definitions, definitionName)) {
490
+ throwUnsupportedReference(reference);
491
+ }
492
+ return {
493
+ definition: source.definitions[definitionName],
494
+ referenceKey: `${source.prefix}${definitionName}`
495
+ };
496
+ }
497
+ function throwUnsupportedReference(reference) {
498
+ throw new UnsupportedFunctionalityError({
499
+ functionality: `JSON Schema reference: ${reference}`,
500
+ message: "Google schema conversion only supports references to direct children of root-level $defs or definitions."
501
+ });
502
+ }
414
503
  function addEnumToSchema({
415
504
  values,
416
505
  type,
@@ -1881,7 +1970,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1881
1970
  };
1882
1971
  }
1883
1972
  async doGenerate(options) {
1884
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s;
1973
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
1885
1974
  const { args, warnings, providerOptionsNames, extraHeaders } = await this.getArgs(options);
1886
1975
  const wrapProviderMetadata = (payload) => Object.fromEntries(
1887
1976
  providerOptionsNames.map((name) => [name, payload])
@@ -1953,9 +2042,9 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1953
2042
  } else if ("functionCall" in part && part.functionCall.name != null) {
1954
2043
  content.push({
1955
2044
  type: "tool-call",
1956
- toolCallId: (_e = part.functionCall.id) != null ? _e : this.config.generateId(),
2045
+ toolCallId: part.functionCall.id || this.config.generateId(),
1957
2046
  toolName: part.functionCall.name,
1958
- input: JSON.stringify((_f = part.functionCall.args) != null ? _f : {}),
2047
+ input: JSON.stringify((_e = part.functionCall.args) != null ? _e : {}),
1959
2048
  providerMetadata: part.thoughtSignature ? wrapProviderMetadata({
1960
2049
  thoughtSignature: part.thoughtSignature
1961
2050
  }) : void 0
@@ -1972,13 +2061,13 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1972
2061
  }) : void 0
1973
2062
  });
1974
2063
  } else if ("toolCall" in part && part.toolCall) {
1975
- const toolCallId = (_g = part.toolCall.id) != null ? _g : this.config.generateId();
2064
+ const toolCallId = part.toolCall.id || this.config.generateId();
1976
2065
  lastServerToolCallId = toolCallId;
1977
2066
  content.push({
1978
2067
  type: "tool-call",
1979
2068
  toolCallId,
1980
2069
  toolName: `server:${part.toolCall.toolType}`,
1981
- input: JSON.stringify((_h = part.toolCall.args) != null ? _h : {}),
2070
+ input: JSON.stringify((_f = part.toolCall.args) != null ? _f : {}),
1982
2071
  providerExecuted: true,
1983
2072
  dynamic: true,
1984
2073
  providerMetadata: part.thoughtSignature ? wrapProviderMetadata({
@@ -1991,12 +2080,12 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1991
2080
  })
1992
2081
  });
1993
2082
  } else if ("toolResponse" in part && part.toolResponse) {
1994
- const responseToolCallId = (_i = lastServerToolCallId != null ? lastServerToolCallId : part.toolResponse.id) != null ? _i : this.config.generateId();
2083
+ const responseToolCallId = lastServerToolCallId || part.toolResponse.id || this.config.generateId();
1995
2084
  content.push({
1996
2085
  type: "tool-result",
1997
2086
  toolCallId: responseToolCallId,
1998
2087
  toolName: `server:${part.toolResponse.toolType}`,
1999
- result: (_j = part.toolResponse.response) != null ? _j : {},
2088
+ result: (_g = part.toolResponse.response) != null ? _g : {},
2000
2089
  providerMetadata: part.thoughtSignature ? wrapProviderMetadata({
2001
2090
  thoughtSignature: part.thoughtSignature,
2002
2091
  serverToolCallId: responseToolCallId,
@@ -2009,10 +2098,10 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
2009
2098
  lastServerToolCallId = void 0;
2010
2099
  }
2011
2100
  }
2012
- const sources = (_k = extractSources({
2101
+ const sources = (_h = extractSources({
2013
2102
  groundingMetadata: candidate.groundingMetadata,
2014
2103
  generateId: this.config.generateId
2015
- })) != null ? _k : [];
2104
+ })) != null ? _h : [];
2016
2105
  for (const source of sources) {
2017
2106
  content.push(source);
2018
2107
  }
@@ -2026,23 +2115,23 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
2026
2115
  (part) => part.type === "tool-call" && !part.providerExecuted
2027
2116
  )
2028
2117
  }),
2029
- raw: (_l = candidate.finishReason) != null ? _l : void 0
2118
+ raw: (_i = candidate.finishReason) != null ? _i : void 0
2030
2119
  },
2031
2120
  usage: convertGoogleUsage(usageMetadata),
2032
2121
  warnings,
2033
2122
  providerMetadata: wrapProviderMetadata({
2034
- promptFeedback: (_m = response.promptFeedback) != null ? _m : null,
2035
- groundingMetadata: (_n = candidate.groundingMetadata) != null ? _n : null,
2036
- urlContextMetadata: (_o = candidate.urlContextMetadata) != null ? _o : null,
2037
- safetyRatings: (_p = candidate.safetyRatings) != null ? _p : null,
2123
+ promptFeedback: (_j = response.promptFeedback) != null ? _j : null,
2124
+ groundingMetadata: (_k = candidate.groundingMetadata) != null ? _k : null,
2125
+ urlContextMetadata: (_l = candidate.urlContextMetadata) != null ? _l : null,
2126
+ safetyRatings: (_m = candidate.safetyRatings) != null ? _m : null,
2038
2127
  usageMetadata: usageMetadata != null ? usageMetadata : null,
2039
- finishMessage: (_q = candidate.finishMessage) != null ? _q : null,
2040
- serviceTier: (_r = usageMetadata == null ? void 0 : usageMetadata.serviceTier) != null ? _r : null
2128
+ finishMessage: (_n = candidate.finishMessage) != null ? _n : null,
2129
+ serviceTier: (_o = usageMetadata == null ? void 0 : usageMetadata.serviceTier) != null ? _o : null
2041
2130
  }),
2042
2131
  request: { body: args },
2043
2132
  response: {
2044
2133
  // TODO timestamp, model id
2045
- id: (_s = response.responseId) != null ? _s : void 0,
2134
+ id: (_p = response.responseId) != null ? _p : void 0,
2046
2135
  headers: responseHeaders,
2047
2136
  body: rawResponse
2048
2137
  }
@@ -2122,7 +2211,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
2122
2211
  controller.enqueue({ type: "stream-start", warnings });
2123
2212
  },
2124
2213
  transform(chunk, controller) {
2125
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
2214
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
2126
2215
  if (options.includeRawChunks) {
2127
2216
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
2128
2217
  }
@@ -2276,7 +2365,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
2276
2365
  providerMetadata: fileMeta
2277
2366
  });
2278
2367
  } else if ("toolCall" in part && part.toolCall) {
2279
- const toolCallId = (_e = part.toolCall.id) != null ? _e : generateId3();
2368
+ const toolCallId = part.toolCall.id || generateId3();
2280
2369
  lastServerToolCallId = toolCallId;
2281
2370
  const serverMeta = wrapProviderMetadata({
2282
2371
  ...part.thoughtSignature ? { thoughtSignature: part.thoughtSignature } : {},
@@ -2287,13 +2376,13 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
2287
2376
  type: "tool-call",
2288
2377
  toolCallId,
2289
2378
  toolName: `server:${part.toolCall.toolType}`,
2290
- input: JSON.stringify((_f = part.toolCall.args) != null ? _f : {}),
2379
+ input: JSON.stringify((_e = part.toolCall.args) != null ? _e : {}),
2291
2380
  providerExecuted: true,
2292
2381
  dynamic: true,
2293
2382
  providerMetadata: serverMeta
2294
2383
  });
2295
2384
  } else if ("toolResponse" in part && part.toolResponse) {
2296
- const responseToolCallId = (_g = lastServerToolCallId != null ? lastServerToolCallId : part.toolResponse.id) != null ? _g : generateId3();
2385
+ const responseToolCallId = lastServerToolCallId || part.toolResponse.id || generateId3();
2297
2386
  const serverMeta = wrapProviderMetadata({
2298
2387
  ...part.thoughtSignature ? { thoughtSignature: part.thoughtSignature } : {},
2299
2388
  serverToolCallId: responseToolCallId,
@@ -2303,7 +2392,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
2303
2392
  type: "tool-result",
2304
2393
  toolCallId: responseToolCallId,
2305
2394
  toolName: `server:${part.toolResponse.toolType}`,
2306
- result: (_h = part.toolResponse.response) != null ? _h : {},
2395
+ result: (_f = part.toolResponse.response) != null ? _f : {},
2307
2396
  providerMetadata: serverMeta
2308
2397
  });
2309
2398
  lastServerToolCallId = void 0;
@@ -2320,7 +2409,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
2320
2409
  const isNoArgsCompleteCall = part.functionCall.name != null && part.functionCall.args == null && part.functionCall.partialArgs == null && part.functionCall.willContinue !== true;
2321
2410
  if (isStreamingChunk) {
2322
2411
  if (part.functionCall.name != null) {
2323
- const toolCallId = (_i = part.functionCall.id) != null ? _i : generateId3();
2412
+ const toolCallId = part.functionCall.id || generateId3();
2324
2413
  const accumulator = new GoogleJSONAccumulator();
2325
2414
  activeStreamingToolCalls.push({
2326
2415
  toolCallId,
@@ -2368,9 +2457,9 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
2368
2457
  } else if (isTerminalChunk && activeStreamingToolCalls.length > 0) {
2369
2458
  finishActiveStreamingToolCall(controller);
2370
2459
  } else if (isCompleteCall) {
2371
- const toolCallId = (_j = part.functionCall.id) != null ? _j : generateId3();
2460
+ const toolCallId = part.functionCall.id || generateId3();
2372
2461
  const toolName = part.functionCall.name;
2373
- const args2 = typeof part.functionCall.args === "string" ? part.functionCall.args : JSON.stringify((_k = part.functionCall.args) != null ? _k : {});
2462
+ const args2 = typeof part.functionCall.args === "string" ? part.functionCall.args : JSON.stringify((_g = part.functionCall.args) != null ? _g : {});
2374
2463
  controller.enqueue({
2375
2464
  type: "tool-input-start",
2376
2465
  id: toolCallId,
@@ -2397,7 +2486,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
2397
2486
  });
2398
2487
  hasToolCalls = true;
2399
2488
  } else if (isNoArgsCompleteCall) {
2400
- const toolCallId = (_l = part.functionCall.id) != null ? _l : generateId3();
2489
+ const toolCallId = part.functionCall.id || generateId3();
2401
2490
  const toolName = part.functionCall.name;
2402
2491
  controller.enqueue({
2403
2492
  type: "tool-input-start",
@@ -2430,13 +2519,13 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
2430
2519
  raw: candidate.finishReason
2431
2520
  };
2432
2521
  providerMetadata = wrapProviderMetadata({
2433
- promptFeedback: (_m = value.promptFeedback) != null ? _m : null,
2522
+ promptFeedback: (_h = value.promptFeedback) != null ? _h : null,
2434
2523
  groundingMetadata: lastGroundingMetadata,
2435
2524
  urlContextMetadata: lastUrlContextMetadata,
2436
- safetyRatings: (_n = candidate.safetyRatings) != null ? _n : null,
2525
+ safetyRatings: (_i = candidate.safetyRatings) != null ? _i : null,
2437
2526
  usageMetadata: usageMetadata != null ? usageMetadata : null,
2438
- finishMessage: (_o = candidate.finishMessage) != null ? _o : null,
2439
- serviceTier: (_p = usage == null ? void 0 : usage.serviceTier) != null ? _p : null
2527
+ finishMessage: (_j = candidate.finishMessage) != null ? _j : null,
2528
+ serviceTier: (_k = usage == null ? void 0 : usage.serviceTier) != null ? _k : null
2440
2529
  });
2441
2530
  }
2442
2531
  },
@@ -4417,7 +4506,7 @@ function buildGoogleInteractionsStreamTransform({
4417
4506
  controller.enqueue({ type: "stream-start", warnings });
4418
4507
  },
4419
4508
  transform(chunk, controller) {
4420
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t;
4509
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
4421
4510
  if (includeRawChunks) {
4422
4511
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
4423
4512
  }
@@ -4508,8 +4597,8 @@ function buildGoogleInteractionsStreamTransform({
4508
4597
  }
4509
4598
  }
4510
4599
  } else if (stepType === "function_call") {
4511
- const toolCallId = (_b = step == null ? void 0 : step.id) != null ? _b : blockId;
4512
- const toolName = (_c = step == null ? void 0 : step.name) != null ? _c : "unknown";
4600
+ const toolCallId = (step == null ? void 0 : step.id) || blockId;
4601
+ const toolName = (_b = step == null ? void 0 : step.name) != null ? _b : "unknown";
4513
4602
  hasFunctionCall = true;
4514
4603
  const state = {
4515
4604
  kind: "function_call",
@@ -4526,28 +4615,28 @@ function buildGoogleInteractionsStreamTransform({
4526
4615
  toolName
4527
4616
  });
4528
4617
  } else if (stepType != null && BUILTIN_TOOL_CALL_TYPES.has(stepType)) {
4529
- const toolName = stepType === "mcp_server_tool_call" ? (_d = step == null ? void 0 : step.name) != null ? _d : "mcp_server_tool" : builtinToolNameFromCallType(stepType);
4530
- const toolCallId = (_e = step == null ? void 0 : step.id) != null ? _e : blockId;
4618
+ const toolName = stepType === "mcp_server_tool_call" ? (_c = step == null ? void 0 : step.name) != null ? _c : "mcp_server_tool" : builtinToolNameFromCallType(stepType);
4619
+ const toolCallId = (step == null ? void 0 : step.id) || blockId;
4531
4620
  const state = {
4532
4621
  kind: "builtin_tool_call",
4533
4622
  id: blockId,
4534
4623
  blockType: stepType,
4535
4624
  toolCallId,
4536
4625
  toolName,
4537
- arguments: (_f = step == null ? void 0 : step.arguments) != null ? _f : {},
4626
+ arguments: (_d = step == null ? void 0 : step.arguments) != null ? _d : {},
4538
4627
  callEmitted: false
4539
4628
  };
4540
4629
  openBlocks.set(index, state);
4541
4630
  } else if (stepType != null && BUILTIN_TOOL_RESULT_TYPES.has(stepType)) {
4542
- const toolName = stepType === "mcp_server_tool_result" ? (_g = step == null ? void 0 : step.name) != null ? _g : "mcp_server_tool" : builtinToolNameFromResultType(stepType);
4543
- const callId = (_h = step == null ? void 0 : step.call_id) != null ? _h : blockId;
4631
+ const toolName = stepType === "mcp_server_tool_result" ? (_e = step == null ? void 0 : step.name) != null ? _e : "mcp_server_tool" : builtinToolNameFromResultType(stepType);
4632
+ const callId = (step == null ? void 0 : step.call_id) || blockId;
4544
4633
  const state = {
4545
4634
  kind: "builtin_tool_result",
4546
4635
  id: blockId,
4547
4636
  blockType: stepType,
4548
4637
  callId,
4549
4638
  toolName,
4550
- result: (_i = step == null ? void 0 : step.result) != null ? _i : null,
4639
+ result: (_f = step == null ? void 0 : step.result) != null ? _f : null,
4551
4640
  ...(step == null ? void 0 : step.is_error) != null ? { isError: step.is_error } : {},
4552
4641
  resultEmitted: false
4553
4642
  };
@@ -4561,7 +4650,7 @@ function buildGoogleInteractionsStreamTransform({
4561
4650
  const event = value;
4562
4651
  let open = openBlocks.get(event.index);
4563
4652
  if (open == null) break;
4564
- const dtype = (_j = event.delta) == null ? void 0 : _j.type;
4653
+ const dtype = (_g = event.delta) == null ? void 0 : _g.type;
4565
4654
  if (open.kind === "pending_model_output") {
4566
4655
  if (dtype === "text" || dtype === "text_annotation" || dtype === "text_annotation_delta") {
4567
4656
  const promoted = {
@@ -4582,14 +4671,14 @@ function buildGoogleInteractionsStreamTransform({
4582
4671
  if ((imageDelta == null ? void 0 : imageDelta.data) != null && imageDelta.data.length > 0) {
4583
4672
  controller.enqueue({
4584
4673
  type: "file",
4585
- mediaType: (_k = imageDelta.mime_type) != null ? _k : "image/png",
4674
+ mediaType: (_h = imageDelta.mime_type) != null ? _h : "image/png",
4586
4675
  data: { type: "data", data: imageDelta.data },
4587
4676
  ...providerMetadata ? { providerMetadata } : {}
4588
4677
  });
4589
4678
  } else if ((imageDelta == null ? void 0 : imageDelta.uri) != null && imageDelta.uri.length > 0) {
4590
4679
  controller.enqueue({
4591
4680
  type: "file",
4592
- mediaType: (_l = imageDelta.mime_type) != null ? _l : "image/png",
4681
+ mediaType: (_i = imageDelta.mime_type) != null ? _i : "image/png",
4593
4682
  data: { type: "url", url: new URL(imageDelta.uri) },
4594
4683
  ...providerMetadata ? { providerMetadata } : {}
4595
4684
  });
@@ -4608,14 +4697,14 @@ function buildGoogleInteractionsStreamTransform({
4608
4697
  if ((videoDelta == null ? void 0 : videoDelta.data) != null && videoDelta.data.length > 0) {
4609
4698
  controller.enqueue({
4610
4699
  type: "file",
4611
- mediaType: (_m = videoDelta.mime_type) != null ? _m : "video/mp4",
4700
+ mediaType: (_j = videoDelta.mime_type) != null ? _j : "video/mp4",
4612
4701
  data: { type: "data", data: videoDelta.data },
4613
4702
  ...providerMetadata ? { providerMetadata } : {}
4614
4703
  });
4615
4704
  } else if ((videoDelta == null ? void 0 : videoDelta.uri) != null && videoDelta.uri.length > 0) {
4616
4705
  controller.enqueue({
4617
4706
  type: "file",
4618
- mediaType: (_n = videoDelta.mime_type) != null ? _n : "video/mp4",
4707
+ mediaType: (_k = videoDelta.mime_type) != null ? _k : "video/mp4",
4619
4708
  data: { type: "url", url: new URL(videoDelta.uri) },
4620
4709
  ...providerMetadata ? { providerMetadata } : {}
4621
4710
  });
@@ -4624,7 +4713,7 @@ function buildGoogleInteractionsStreamTransform({
4624
4713
  }
4625
4714
  const delta = event.delta;
4626
4715
  if (open.kind === "text" && (delta == null ? void 0 : delta.type) === "text") {
4627
- const text = (_o = delta.text) != null ? _o : "";
4716
+ const text = (_l = delta.text) != null ? _l : "";
4628
4717
  if (text.length > 0) {
4629
4718
  controller.enqueue({
4630
4719
  type: "text-delta",
@@ -4674,7 +4763,7 @@ function buildGoogleInteractionsStreamTransform({
4674
4763
  delta: slice
4675
4764
  });
4676
4765
  }
4677
- if (delta.id != null) {
4766
+ if (delta.id != null && delta.id.length > 0) {
4678
4767
  open.toolCallId = delta.id;
4679
4768
  }
4680
4769
  if (delta.signature != null) {
@@ -4682,7 +4771,9 @@ function buildGoogleInteractionsStreamTransform({
4682
4771
  }
4683
4772
  hasFunctionCall = true;
4684
4773
  } else if (open.kind === "builtin_tool_call" && (delta == null ? void 0 : delta.type) === open.blockType) {
4685
- if (delta.id != null) open.toolCallId = delta.id;
4774
+ if (delta.id != null && delta.id.length > 0) {
4775
+ open.toolCallId = delta.id;
4776
+ }
4686
4777
  if (delta.arguments != null && typeof delta.arguments === "object") {
4687
4778
  open.arguments = delta.arguments;
4688
4779
  }
@@ -4690,7 +4781,9 @@ function buildGoogleInteractionsStreamTransform({
4690
4781
  open.toolName = delta.name;
4691
4782
  }
4692
4783
  } else if (open.kind === "builtin_tool_result" && (delta == null ? void 0 : delta.type) === open.blockType) {
4693
- if (delta.call_id != null) open.callId = delta.call_id;
4784
+ if (delta.call_id != null && delta.call_id.length > 0) {
4785
+ open.callId = delta.call_id;
4786
+ }
4694
4787
  if (delta.result !== void 0) open.result = delta.result;
4695
4788
  if (delta.is_error != null) open.isError = delta.is_error;
4696
4789
  if (delta.name != null && open.blockType === "mcp_server_tool_result") {
@@ -4727,14 +4820,14 @@ function buildGoogleInteractionsStreamTransform({
4727
4820
  if (open.data != null && open.data.length > 0) {
4728
4821
  controller.enqueue({
4729
4822
  type: "file",
4730
- mediaType: (_p = open.mimeType) != null ? _p : "image/png",
4823
+ mediaType: (_m = open.mimeType) != null ? _m : "image/png",
4731
4824
  data: { type: "data", data: open.data },
4732
4825
  ...providerMetadata ? { providerMetadata } : {}
4733
4826
  });
4734
4827
  } else if (open.uri != null && open.uri.length > 0) {
4735
4828
  controller.enqueue({
4736
4829
  type: "file",
4737
- mediaType: (_q = open.mimeType) != null ? _q : "image/png",
4830
+ mediaType: (_n = open.mimeType) != null ? _n : "image/png",
4738
4831
  data: { type: "url", url: new URL(open.uri) },
4739
4832
  ...providerMetadata ? { providerMetadata } : {}
4740
4833
  });
@@ -4761,7 +4854,7 @@ function buildGoogleInteractionsStreamTransform({
4761
4854
  type: "tool-call",
4762
4855
  toolCallId: open.toolCallId,
4763
4856
  toolName: open.toolName,
4764
- input: JSON.stringify((_r = open.arguments) != null ? _r : {}),
4857
+ input: JSON.stringify((_o = open.arguments) != null ? _o : {}),
4765
4858
  providerExecuted: true
4766
4859
  });
4767
4860
  open.callEmitted = true;
@@ -4770,7 +4863,7 @@ function buildGoogleInteractionsStreamTransform({
4770
4863
  type: "tool-result",
4771
4864
  toolCallId: open.callId,
4772
4865
  toolName: open.toolName,
4773
- result: (_s = open.result) != null ? _s : null
4866
+ result: (_p = open.result) != null ? _p : null
4774
4867
  });
4775
4868
  open.resultEmitted = true;
4776
4869
  const sources = builtinToolResultToSources({
@@ -4824,7 +4917,7 @@ function buildGoogleInteractionsStreamTransform({
4824
4917
  case "error": {
4825
4918
  const event = value;
4826
4919
  finishStatus = "failed";
4827
- const errorPayload = (_t = event.error) != null ? _t : {
4920
+ const errorPayload = (_q = event.error) != null ? _q : {
4828
4921
  message: "Unknown interaction error"
4829
4922
  };
4830
4923
  controller.enqueue({ type: "error", error: errorPayload });
@@ -5812,7 +5905,7 @@ function parseGoogleInteractionsOutputs({
5812
5905
  generateId: generateId3,
5813
5906
  interactionId
5814
5907
  }) {
5815
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
5908
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
5816
5909
  const content = [];
5817
5910
  let hasFunctionCall = false;
5818
5911
  if (steps == null) {
@@ -5919,19 +6012,19 @@ function parseGoogleInteractionsOutputs({
5919
6012
  const input = JSON.stringify((_i = call.arguments) != null ? _i : {});
5920
6013
  content.push({
5921
6014
  type: "tool-call",
5922
- toolCallId: (_j = call.id) != null ? _j : generateId3(),
6015
+ toolCallId: call.id || generateId3(),
5923
6016
  toolName,
5924
6017
  input,
5925
6018
  providerExecuted: true
5926
6019
  });
5927
6020
  } else if (BUILTIN_TOOL_RESULT_TYPES2.has(type)) {
5928
6021
  const result = step;
5929
- const toolName = type === "mcp_server_tool_result" ? (_k = result.name) != null ? _k : "mcp_server_tool" : builtinToolNameFromResultType2(type);
6022
+ const toolName = type === "mcp_server_tool_result" ? (_j = result.name) != null ? _j : "mcp_server_tool" : builtinToolNameFromResultType2(type);
5930
6023
  content.push({
5931
6024
  type: "tool-result",
5932
- toolCallId: (_l = result.call_id) != null ? _l : generateId3(),
6025
+ toolCallId: result.call_id || generateId3(),
5933
6026
  toolName,
5934
- result: (_m = result.result) != null ? _m : null
6027
+ result: (_k = result.result) != null ? _k : null
5935
6028
  });
5936
6029
  const sources = builtinToolResultToSources({
5937
6030
  block: step,