Skip to content

Commit 9b44951

Browse files
google-genai-botcopybara-github
authored andcommitted
feat(python): preserve unknown fields and open-union variants in Interactions models
Enable `preserveUnknownFields` and `modelSerializationMethods` in the Python SDK. Unknown fields are kept at every nesting level, in responses and in requests: unknown request fields are forwarded instead of silently dropped, so unsupported options such as `transcription_config.diarization` are rejected by the API rather than ignored (#3162), and fields missing from the SDK schema reach the API. Unknown steps, content blocks and annotations round-trip as the payload the server sent, including stateless multi-turn history sent back as SDK objects or as stored dicts; known variants with invalid payloads still raise locally. FUTURE_COPYBARA_INTEGRATE_REVIEW=#3209 from googleapis:release-please--branches--main 39c95f2 PiperOrigin-RevId: 1009673588
1 parent 0dc788c commit 9b44951

225 files changed

Lines changed: 8040 additions & 1117 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/workflows/mypy.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ on:
1010
- main
1111

1212
env:
13-
SPEAKEASY_VERSION: v2.952.4
13+
SPEAKEASY_VERSION: v2.955.0
1414

1515
jobs:
1616
mypy:

‎google/genai/_gaos/credentials.py‎

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ def create(
237237
:param refresh_token: Required. Input only. OAuth2 refresh token. Write-only; never returned in responses.
238238
:param scopes: Optional. List of OAuth2 scopes.
239239
:param token_url: Required. OAuth2 token endpoint URL for refreshing access tokens.
240-
:param type:
240+
:param type_:
241241
:param extra_headers: Additional headers to set or replace on requests.
242242
:param extra_query: Additional query parameters to append to requests.
243243
:param extra_body: Additional JSON object fields to merge into request bodies.
@@ -268,7 +268,7 @@ def create(
268268
Accepts either a single location (e.g. \"header\") or an array of locations.
269269
:param trusted_domains: Optional. List of domains allowed to receive this environment variable
270270
value in HTTP requests.
271-
:param type:
271+
:param type_:
272272
:param value: Required. Input only. Secret value of the environment variable. Write-only; never
273273
returned in responses.
274274
:param extra_headers: Additional headers to set or replace on requests.
@@ -301,7 +301,7 @@ def create(
301301
:param prefix: Optional. Prefix to prepend to the token. Defaults to 'Bearer'. Set to ''
302302
for no prefix.
303303
:param token: Required. Input only. The static bearer token. Write-only; never returned in responses.
304-
:param type:
304+
:param type_:
305305
:param extra_headers: Additional headers to set or replace on requests.
306306
:param extra_query: Additional query parameters to append to requests.
307307
:param extra_body: Additional JSON object fields to merge into request bodies.
@@ -331,7 +331,7 @@ def create(
331331
:param refresh_token: Required. Input only. OAuth2 refresh token. Write-only; never returned in responses.
332332
:param scopes: Optional. List of OAuth2 scopes.
333333
:param token_url: Required. OAuth2 token endpoint URL for refreshing access tokens.
334-
:param type:
334+
:param type_:
335335
:param injection_location: Required. Locations where the environment variable can be injected in
336336
outgoing HTTP requests. Must contain at least one location.
337337
Accepts either a single location (e.g. \"header\") or an array of locations.
@@ -372,7 +372,7 @@ def create(
372372
:param refresh_token: Required. Input only. OAuth2 refresh token. Write-only; never returned in responses.
373373
:param scopes: Optional. List of OAuth2 scopes.
374374
:param token_url: Required. OAuth2 token endpoint URL for refreshing access tokens.
375-
:param type:
375+
:param type_:
376376
:param injection_location: Required. Locations where the environment variable can be injected in
377377
outgoing HTTP requests. Must contain at least one location.
378378
Accepts either a single location (e.g. \"header\") or an array of locations.
@@ -991,7 +991,7 @@ def update(
991991
:param refresh_token: Optional. Input only. OAuth2 refresh token. Write-only; never returned in responses.
992992
:param scopes: Optional. List of OAuth2 scopes.
993993
:param token_url: Optional. OAuth2 token endpoint URL for refreshing access tokens.
994-
:param type:
994+
:param type_:
995995
:param extra_headers: Additional headers to set or replace on requests.
996996
:param extra_query: Additional query parameters to append to requests.
997997
:param extra_body: Additional JSON object fields to merge into request bodies.
@@ -1023,7 +1023,7 @@ def update(
10231023
Accepts either a single location (e.g. \"header\") or an array of locations.
10241024
:param trusted_domains: Optional. List of domains allowed to receive this environment variable
10251025
value in HTTP requests.
1026-
:param type:
1026+
:param type_:
10271027
:param value: Optional. Input only. Secret value of the environment variable. Write-only; never
10281028
returned in responses.
10291029
:param extra_headers: Additional headers to set or replace on requests.
@@ -1057,7 +1057,7 @@ def update(
10571057
:param prefix: Optional. Prefix to prepend to the token. Defaults to 'Bearer'. Set to ''
10581058
for no prefix.
10591059
:param token: Optional. Input only. The static bearer token. Write-only; never returned in responses.
1060-
:param type:
1060+
:param type_:
10611061
:param extra_headers: Additional headers to set or replace on requests.
10621062
:param extra_query: Additional query parameters to append to requests.
10631063
:param extra_body: Additional JSON object fields to merge into request bodies.
@@ -1089,7 +1089,7 @@ def update(
10891089
:param refresh_token: Optional. Input only. OAuth2 refresh token. Write-only; never returned in responses.
10901090
:param scopes: Optional. List of OAuth2 scopes.
10911091
:param token_url: Optional. OAuth2 token endpoint URL for refreshing access tokens.
1092-
:param type:
1092+
:param type_:
10931093
:param injection_location: Optional. Locations where the environment variable can be injected in
10941094
outgoing HTTP requests.
10951095
Accepts either a single location (e.g. \"header\") or an array of locations.
@@ -1132,7 +1132,7 @@ def update(
11321132
:param refresh_token: Optional. Input only. OAuth2 refresh token. Write-only; never returned in responses.
11331133
:param scopes: Optional. List of OAuth2 scopes.
11341134
:param token_url: Optional. OAuth2 token endpoint URL for refreshing access tokens.
1135-
:param type:
1135+
:param type_:
11361136
:param injection_location: Optional. Locations where the environment variable can be injected in
11371137
outgoing HTTP requests.
11381138
Accepts either a single location (e.g. \"header\") or an array of locations.
@@ -1650,7 +1650,7 @@ async def create(
16501650
:param refresh_token: Required. Input only. OAuth2 refresh token. Write-only; never returned in responses.
16511651
:param scopes: Optional. List of OAuth2 scopes.
16521652
:param token_url: Required. OAuth2 token endpoint URL for refreshing access tokens.
1653-
:param type:
1653+
:param type_:
16541654
:param extra_headers: Additional headers to set or replace on requests.
16551655
:param extra_query: Additional query parameters to append to requests.
16561656
:param extra_body: Additional JSON object fields to merge into request bodies.
@@ -1681,7 +1681,7 @@ async def create(
16811681
Accepts either a single location (e.g. \"header\") or an array of locations.
16821682
:param trusted_domains: Optional. List of domains allowed to receive this environment variable
16831683
value in HTTP requests.
1684-
:param type:
1684+
:param type_:
16851685
:param value: Required. Input only. Secret value of the environment variable. Write-only; never
16861686
returned in responses.
16871687
:param extra_headers: Additional headers to set or replace on requests.
@@ -1714,7 +1714,7 @@ async def create(
17141714
:param prefix: Optional. Prefix to prepend to the token. Defaults to 'Bearer'. Set to ''
17151715
for no prefix.
17161716
:param token: Required. Input only. The static bearer token. Write-only; never returned in responses.
1717-
:param type:
1717+
:param type_:
17181718
:param extra_headers: Additional headers to set or replace on requests.
17191719
:param extra_query: Additional query parameters to append to requests.
17201720
:param extra_body: Additional JSON object fields to merge into request bodies.
@@ -1744,7 +1744,7 @@ async def create(
17441744
:param refresh_token: Required. Input only. OAuth2 refresh token. Write-only; never returned in responses.
17451745
:param scopes: Optional. List of OAuth2 scopes.
17461746
:param token_url: Required. OAuth2 token endpoint URL for refreshing access tokens.
1747-
:param type:
1747+
:param type_:
17481748
:param injection_location: Required. Locations where the environment variable can be injected in
17491749
outgoing HTTP requests. Must contain at least one location.
17501750
Accepts either a single location (e.g. \"header\") or an array of locations.
@@ -1785,7 +1785,7 @@ async def create(
17851785
:param refresh_token: Required. Input only. OAuth2 refresh token. Write-only; never returned in responses.
17861786
:param scopes: Optional. List of OAuth2 scopes.
17871787
:param token_url: Required. OAuth2 token endpoint URL for refreshing access tokens.
1788-
:param type:
1788+
:param type_:
17891789
:param injection_location: Required. Locations where the environment variable can be injected in
17901790
outgoing HTTP requests. Must contain at least one location.
17911791
Accepts either a single location (e.g. \"header\") or an array of locations.
@@ -2413,7 +2413,7 @@ async def update(
24132413
:param refresh_token: Optional. Input only. OAuth2 refresh token. Write-only; never returned in responses.
24142414
:param scopes: Optional. List of OAuth2 scopes.
24152415
:param token_url: Optional. OAuth2 token endpoint URL for refreshing access tokens.
2416-
:param type:
2416+
:param type_:
24172417
:param extra_headers: Additional headers to set or replace on requests.
24182418
:param extra_query: Additional query parameters to append to requests.
24192419
:param extra_body: Additional JSON object fields to merge into request bodies.
@@ -2445,7 +2445,7 @@ async def update(
24452445
Accepts either a single location (e.g. \"header\") or an array of locations.
24462446
:param trusted_domains: Optional. List of domains allowed to receive this environment variable
24472447
value in HTTP requests.
2448-
:param type:
2448+
:param type_:
24492449
:param value: Optional. Input only. Secret value of the environment variable. Write-only; never
24502450
returned in responses.
24512451
:param extra_headers: Additional headers to set or replace on requests.
@@ -2479,7 +2479,7 @@ async def update(
24792479
:param prefix: Optional. Prefix to prepend to the token. Defaults to 'Bearer'. Set to ''
24802480
for no prefix.
24812481
:param token: Optional. Input only. The static bearer token. Write-only; never returned in responses.
2482-
:param type:
2482+
:param type_:
24832483
:param extra_headers: Additional headers to set or replace on requests.
24842484
:param extra_query: Additional query parameters to append to requests.
24852485
:param extra_body: Additional JSON object fields to merge into request bodies.
@@ -2511,7 +2511,7 @@ async def update(
25112511
:param refresh_token: Optional. Input only. OAuth2 refresh token. Write-only; never returned in responses.
25122512
:param scopes: Optional. List of OAuth2 scopes.
25132513
:param token_url: Optional. OAuth2 token endpoint URL for refreshing access tokens.
2514-
:param type:
2514+
:param type_:
25152515
:param injection_location: Optional. Locations where the environment variable can be injected in
25162516
outgoing HTTP requests.
25172517
Accepts either a single location (e.g. \"header\") or an array of locations.
@@ -2554,7 +2554,7 @@ async def update(
25542554
:param refresh_token: Optional. Input only. OAuth2 refresh token. Write-only; never returned in responses.
25552555
:param scopes: Optional. List of OAuth2 scopes.
25562556
:param token_url: Optional. OAuth2 token endpoint URL for refreshing access tokens.
2557-
:param type:
2557+
:param type_:
25582558
:param injection_location: Optional. Locations where the environment variable can be injected in
25592559
outgoing HTTP requests.
25602560
Accepts either a single location (e.g. \"header\") or an array of locations.

‎google/genai/_gaos/models/cancelinteractionbyid.py‎

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,12 @@
1818
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
1919

2020
from __future__ import annotations
21-
from ..types import BaseModel, UNSET_SENTINEL
21+
from ..types import BaseModel, UNSET_SENTINEL, current_exclude_none, serialize_with_info
22+
from ..types.basemodel import (
23+
current_by_alias,
24+
current_filtered_dump,
25+
current_serialization_methods_dump,
26+
)
2227
from ..utils import FieldMetadata, PathParamMetadata
2328
import pydantic
2429
from pydantic import model_serializer
@@ -39,18 +44,35 @@ class CancelInteractionByIDGlobals(BaseModel):
3944
r"""API version for request routing."""
4045

4146
@model_serializer(mode="wrap")
47+
def _serialize_model_with_info(self, handler, info):
48+
return serialize_with_info(self.serialize_model, handler, info)
49+
4250
def serialize_model(self, handler):
4351
optional_fields = set(["api_version"])
52+
exclude_none = current_exclude_none()
53+
by_alias = current_by_alias()
54+
use_field_names = by_alias is False
55+
serialization_methods_dump = current_serialization_methods_dump()
56+
skip_filtered = (
57+
serialization_methods_dump
58+
or exclude_none is False
59+
or current_filtered_dump()
60+
)
4461
serialized = handler(self)
4562
m = {}
4663

4764
for n, f in type(self).model_fields.items():
48-
k = f.alias or n
49-
val = serialized.get(k, serialized.get(n))
65+
k = f.alias if f.alias is not None else n
66+
key = k if by_alias or k in serialized else n
67+
if key not in serialized and skip_filtered:
68+
continue
69+
val = serialized.pop(key, None)
5070

5171
if val != UNSET_SENTINEL:
5272
if val is not None or k not in optional_fields:
53-
m[k] = val
73+
m[n if use_field_names else k] = val
74+
for k, v in serialized.items():
75+
m[k] = v
5476

5577
return m
5678

@@ -77,17 +99,34 @@ class CancelInteractionByIDRequest(BaseModel):
7799
r"""API version for request routing."""
78100

79101
@model_serializer(mode="wrap")
102+
def _serialize_model_with_info(self, handler, info):
103+
return serialize_with_info(self.serialize_model, handler, info)
104+
80105
def serialize_model(self, handler):
81106
optional_fields = set(["api_version"])
107+
exclude_none = current_exclude_none()
108+
by_alias = current_by_alias()
109+
use_field_names = by_alias is False
110+
serialization_methods_dump = current_serialization_methods_dump()
111+
skip_filtered = (
112+
serialization_methods_dump
113+
or exclude_none is False
114+
or current_filtered_dump()
115+
)
82116
serialized = handler(self)
83117
m = {}
84118

85119
for n, f in type(self).model_fields.items():
86-
k = f.alias or n
87-
val = serialized.get(k, serialized.get(n))
120+
k = f.alias if f.alias is not None else n
121+
key = k if by_alias or k in serialized else n
122+
if key not in serialized and skip_filtered:
123+
continue
124+
val = serialized.pop(key, None)
88125

89126
if val != UNSET_SENTINEL:
90127
if val is not None or k not in optional_fields:
91-
m[k] = val
128+
m[n if use_field_names else k] = val
129+
for k, v in serialized.items():
130+
m[k] = v
92131

93132
return m

‎google/genai/_gaos/models/createagent.py‎

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,13 @@
1818
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
1919

2020
from __future__ import annotations
21-
from ..types import BaseModel, UNSET_SENTINEL
21+
from ..types import BaseModel, UNSET_SENTINEL, current_exclude_none, serialize_with_info
2222
from ..types.agents import agent as agents_agent
23+
from ..types.basemodel import (
24+
current_by_alias,
25+
current_filtered_dump,
26+
current_serialization_methods_dump,
27+
)
2328
from ..utils import FieldMetadata, PathParamMetadata, RequestMetadata
2429
from pydantic import model_serializer
2530
from typing import Optional
@@ -39,18 +44,35 @@ class CreateAgentGlobals(BaseModel):
3944
r"""API version for request routing."""
4045

4146
@model_serializer(mode="wrap")
47+
def _serialize_model_with_info(self, handler, info):
48+
return serialize_with_info(self.serialize_model, handler, info)
49+
4250
def serialize_model(self, handler):
4351
optional_fields = set(["api_version"])
52+
exclude_none = current_exclude_none()
53+
by_alias = current_by_alias()
54+
use_field_names = by_alias is False
55+
serialization_methods_dump = current_serialization_methods_dump()
56+
skip_filtered = (
57+
serialization_methods_dump
58+
or exclude_none is False
59+
or current_filtered_dump()
60+
)
4461
serialized = handler(self)
4562
m = {}
4663

4764
for n, f in type(self).model_fields.items():
48-
k = f.alias or n
49-
val = serialized.get(k, serialized.get(n))
65+
k = f.alias if f.alias is not None else n
66+
key = k if by_alias or k in serialized else n
67+
if key not in serialized and skip_filtered:
68+
continue
69+
val = serialized.pop(key, None)
5070

5171
if val != UNSET_SENTINEL:
5272
if val is not None or k not in optional_fields:
53-
m[k] = val
73+
m[n if use_field_names else k] = val
74+
for k, v in serialized.items():
75+
m[k] = v
5476

5577
return m
5678

@@ -76,17 +98,34 @@ class CreateAgentRequest(BaseModel):
7698
r"""API version for request routing."""
7799

78100
@model_serializer(mode="wrap")
101+
def _serialize_model_with_info(self, handler, info):
102+
return serialize_with_info(self.serialize_model, handler, info)
103+
79104
def serialize_model(self, handler):
80105
optional_fields = set(["api_version"])
106+
exclude_none = current_exclude_none()
107+
by_alias = current_by_alias()
108+
use_field_names = by_alias is False
109+
serialization_methods_dump = current_serialization_methods_dump()
110+
skip_filtered = (
111+
serialization_methods_dump
112+
or exclude_none is False
113+
or current_filtered_dump()
114+
)
81115
serialized = handler(self)
82116
m = {}
83117

84118
for n, f in type(self).model_fields.items():
85-
k = f.alias or n
86-
val = serialized.get(k, serialized.get(n))
119+
k = f.alias if f.alias is not None else n
120+
key = k if by_alias or k in serialized else n
121+
if key not in serialized and skip_filtered:
122+
continue
123+
val = serialized.pop(key, None)
87124

88125
if val != UNSET_SENTINEL:
89126
if val is not None or k not in optional_fields:
90-
m[k] = val
127+
m[n if use_field_names else k] = val
128+
for k, v in serialized.items():
129+
m[k] = v
91130

92131
return m

0 commit comments

Comments
 (0)