@ai-sdk/google 3.0.137 → 3.0.139

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.
@@ -219,6 +219,11 @@ function convertJSONSchemaDefinition(jsonSchema, isRoot, referenceContext) {
219
219
  const nonNullTypes = type.filter((t) => t !== "null");
220
220
  if (nonNullTypes.length === 0) {
221
221
  result.type = "null";
222
+ } else if (nonNullTypes.length === 1) {
223
+ result.type = nonNullTypes[0];
224
+ if (hasNull) {
225
+ result.nullable = true;
226
+ }
222
227
  } else {
223
228
  result.anyOf = nonNullTypes.map((t) => ({ type: t }));
224
229
  if (hasNull) {
@@ -1420,8 +1425,10 @@ var GoogleJSONAccumulator = class {
1420
1425
  processPartialArgs(partialArgs) {
1421
1426
  let delta = "";
1422
1427
  for (const arg of partialArgs) {
1423
- const rawPath = arg.jsonPath.replace(/^\$\./, "");
1424
- if (!rawPath) continue;
1428
+ const isArrayTerminator = arg.jsonPath.endsWith("[]");
1429
+ const jsonPath = isArrayTerminator ? arg.jsonPath.slice(0, -2) : arg.jsonPath;
1430
+ const rawPath = jsonPath.replace(/^\$\./, "");
1431
+ if (!rawPath || rawPath === "$") continue;
1425
1432
  const segments = parsePath(rawPath);
1426
1433
  const existingValue = getNestedValue(this.accumulatedArgs, segments);
1427
1434
  const isStringContinuation = arg.stringValue != null && existingValue !== void 0;
@@ -1436,7 +1443,16 @@ var GoogleJSONAccumulator = class {
1436
1443
  continue;
1437
1444
  }
1438
1445
  const resolved = resolvePartialArgValue(arg);
1439
- if (resolved == null) continue;
1446
+ if (resolved == null) {
1447
+ if (existingValue !== void 0 || arg.willContinue === true) continue;
1448
+ setNestedValue(
1449
+ this.accumulatedArgs,
1450
+ segments,
1451
+ isArrayTerminator ? [] : {}
1452
+ );
1453
+ delta += this.emitContainer(segments, isArrayTerminator);
1454
+ continue;
1455
+ }
1440
1456
  setNestedValue(this.accumulatedArgs, segments, resolved.value);
1441
1457
  delta += this.emitNavigationTo(segments, arg, resolved.json);
1442
1458
  }
@@ -1488,6 +1504,26 @@ var GoogleJSONAccumulator = class {
1488
1504
  fragment += this.emitLeaf(leafSegment, arg, valueJson);
1489
1505
  return fragment;
1490
1506
  }
1507
+ /**
1508
+ * Navigates to `targetSegments` and opens a container there. The container
1509
+ * stays open so later entries for its children continue inside it; it is
1510
+ * closed by subsequent navigation or by `finalize()`.
1511
+ *
1512
+ * Input: targetSegments=["nested","tags"], isArray=true
1513
+ * Output: '{"nested":{"tags":['
1514
+ */
1515
+ emitContainer(targetSegments, isArray) {
1516
+ let fragment = "";
1517
+ if (this.stringOpen) {
1518
+ fragment += '"';
1519
+ this.stringOpen = false;
1520
+ }
1521
+ fragment += this.ensureRoot();
1522
+ const commonDepth = this.findCommonStackDepth(targetSegments);
1523
+ fragment += this.closeDownTo(commonDepth);
1524
+ fragment += this.openDownTo(targetSegments, isArray ? 0 : "");
1525
+ return fragment;
1526
+ }
1491
1527
  /**
1492
1528
  * Returns the stack depth to preserve when navigating to a new target
1493
1529
  * container path. Always >= 1 (the root is never popped).