From 3f36ca11b30904c8f82dd3e7e3b59eff3bde6a3b Mon Sep 17 00:00:00 2001 From: Wanlin Du Date: Mon, 13 Apr 2026 17:36:10 -0700 Subject: [PATCH] fix: Refactor Webhook types in GenAI SDKs for easier useage PiperOrigin-RevId: 899265239 --- .../genai/_interactions/resources/webhooks.py | 28 +++--- google/genai/_interactions/types/__init__.py | 5 +- .../_interactions/types/signing_secret.py | 33 +++++++ ...{webhook_create_response.py => webhook.py} | 15 +--- .../types/webhook_list_response.py | 71 +-------------- .../types/webhook_retrieve_response.py | 88 ------------------- .../types/webhook_update_response.py | 88 ------------------- 7 files changed, 54 insertions(+), 274 deletions(-) create mode 100644 google/genai/_interactions/types/signing_secret.py rename google/genai/_interactions/types/{webhook_create_response.py => webhook.py} (85%) delete mode 100644 google/genai/_interactions/types/webhook_retrieve_response.py delete mode 100644 google/genai/_interactions/types/webhook_update_response.py diff --git a/google/genai/_interactions/resources/webhooks.py b/google/genai/_interactions/resources/webhooks.py index a3f4e2c91..04c647b19 100644 --- a/google/genai/_interactions/resources/webhooks.py +++ b/google/genai/_interactions/resources/webhooks.py @@ -40,12 +40,10 @@ async_to_streamed_response_wrapper, ) from .._base_client import make_request_options +from ..types.webhook import Webhook from ..types.webhook_list_response import WebhookListResponse from ..types.webhook_ping_response import WebhookPingResponse -from ..types.webhook_create_response import WebhookCreateResponse from ..types.webhook_delete_response import WebhookDeleteResponse -from ..types.webhook_update_response import WebhookUpdateResponse -from ..types.webhook_retrieve_response import WebhookRetrieveResponse from ..types.webhook_rotate_signing_secret_response import WebhookRotateSigningSecretResponse __all__ = ["WebhooksResource", "AsyncWebhooksResource"] @@ -101,7 +99,7 @@ def create( extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, - ) -> WebhookCreateResponse: + ) -> Webhook: """Creates a new Webhook. Args: @@ -159,7 +157,7 @@ def create( timeout=timeout, query=maybe_transform({"webhook_id": webhook_id}, webhook_create_params.WebhookCreateParams), ), - cast_to=WebhookCreateResponse, + cast_to=Webhook, ) def retrieve( @@ -173,7 +171,7 @@ def retrieve( extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, - ) -> WebhookRetrieveResponse: + ) -> Webhook: """ Gets a specific Webhook. @@ -197,7 +195,7 @@ def retrieve( options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), - cast_to=WebhookRetrieveResponse, + cast_to=Webhook, ) def update( @@ -231,7 +229,7 @@ def update( extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, - ) -> WebhookUpdateResponse: + ) -> Webhook: """Updates an existing Webhook. Args: @@ -290,7 +288,7 @@ def update( timeout=timeout, query=maybe_transform({"update_mask": update_mask}, webhook_update_params.WebhookUpdateParams), ), - cast_to=WebhookUpdateResponse, + cast_to=Webhook, ) def list( @@ -525,7 +523,7 @@ async def create( extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, - ) -> WebhookCreateResponse: + ) -> Webhook: """Creates a new Webhook. Args: @@ -585,7 +583,7 @@ async def create( {"webhook_id": webhook_id}, webhook_create_params.WebhookCreateParams ), ), - cast_to=WebhookCreateResponse, + cast_to=Webhook, ) async def retrieve( @@ -599,7 +597,7 @@ async def retrieve( extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, - ) -> WebhookRetrieveResponse: + ) -> Webhook: """ Gets a specific Webhook. @@ -623,7 +621,7 @@ async def retrieve( options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), - cast_to=WebhookRetrieveResponse, + cast_to=Webhook, ) async def update( @@ -657,7 +655,7 @@ async def update( extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, - ) -> WebhookUpdateResponse: + ) -> Webhook: """Updates an existing Webhook. Args: @@ -718,7 +716,7 @@ async def update( {"update_mask": update_mask}, webhook_update_params.WebhookUpdateParams ), ), - cast_to=WebhookUpdateResponse, + cast_to=Webhook, ) async def list( diff --git a/google/genai/_interactions/types/__init__.py b/google/genai/_interactions/types/__init__.py index c7dad2ea7..5606758fe 100644 --- a/google/genai/_interactions/types/__init__.py +++ b/google/genai/_interactions/types/__init__.py @@ -22,6 +22,7 @@ from .model import Model as Model from .usage import Usage as Usage from .content import Content as Content +from .webhook import Webhook as Webhook from .function import Function as Function from .annotation import Annotation as Annotation from .tool_param import ToolParam as ToolParam @@ -45,6 +46,7 @@ from .video_content import VideoContent as VideoContent from .function_param import FunctionParam as FunctionParam from .place_citation import PlaceCitation as PlaceCitation +from .signing_secret import SigningSecret as SigningSecret from .thinking_level import ThinkingLevel as ThinkingLevel from .webhook_config import WebhookConfig as WebhookConfig from .thought_content import ThoughtContent as ThoughtContent @@ -82,9 +84,7 @@ from .function_result_content import FunctionResultContent as FunctionResultContent from .generation_config_param import GenerationConfigParam as GenerationConfigParam from .interaction_start_event import InteractionStartEvent as InteractionStartEvent -from .webhook_create_response import WebhookCreateResponse as WebhookCreateResponse from .webhook_delete_response import WebhookDeleteResponse as WebhookDeleteResponse -from .webhook_update_response import WebhookUpdateResponse as WebhookUpdateResponse from .file_search_call_content import FileSearchCallContent as FileSearchCallContent from .google_maps_call_content import GoogleMapsCallContent as GoogleMapsCallContent from .google_maps_result_param import GoogleMapsResultParam as GoogleMapsResultParam @@ -93,7 +93,6 @@ from .url_context_result_param import URLContextResultParam as URLContextResultParam from .interaction_create_params import InteractionCreateParams as InteractionCreateParams from .interaction_status_update import InteractionStatusUpdate as InteractionStatusUpdate -from .webhook_retrieve_response import WebhookRetrieveResponse as WebhookRetrieveResponse from .deep_research_agent_config import DeepResearchAgentConfig as DeepResearchAgentConfig from .dynamic_agent_config_param import DynamicAgentConfigParam as DynamicAgentConfigParam from .file_search_result_content import FileSearchResultContent as FileSearchResultContent diff --git a/google/genai/_interactions/types/signing_secret.py b/google/genai/_interactions/types/signing_secret.py new file mode 100644 index 000000000..81742069a --- /dev/null +++ b/google/genai/_interactions/types/signing_secret.py @@ -0,0 +1,33 @@ +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from typing import Optional +from datetime import datetime + +from .._models import BaseModel + +__all__ = ["SigningSecret"] + + +class SigningSecret(BaseModel): + """Represents a signing secret used to verify webhook payloads.""" + + expire_time: Optional[datetime] = None + """Output only. The expiration date of the signing secret.""" + + truncated_secret: Optional[str] = None + """Output only. The truncated version of the signing secret.""" diff --git a/google/genai/_interactions/types/webhook_create_response.py b/google/genai/_interactions/types/webhook.py similarity index 85% rename from google/genai/_interactions/types/webhook_create_response.py rename to google/genai/_interactions/types/webhook.py index f677e1ff1..6ede43548 100644 --- a/google/genai/_interactions/types/webhook_create_response.py +++ b/google/genai/_interactions/types/webhook.py @@ -20,21 +20,12 @@ from typing_extensions import Literal from .._models import BaseModel +from .signing_secret import SigningSecret -__all__ = ["WebhookCreateResponse", "SigningSecret"] +__all__ = ["Webhook"] -class SigningSecret(BaseModel): - """Represents a signing secret used to verify webhook payloads.""" - - expire_time: Optional[datetime] = None - """Output only. The expiration date of the signing secret.""" - - truncated_secret: Optional[str] = None - """Output only. The truncated version of the signing secret.""" - - -class WebhookCreateResponse(BaseModel): +class Webhook(BaseModel): """A Webhook resource.""" subscribed_events: List[ diff --git a/google/genai/_interactions/types/webhook_list_response.py b/google/genai/_interactions/types/webhook_list_response.py index c52c75fc8..a102ade3a 100644 --- a/google/genai/_interactions/types/webhook_list_response.py +++ b/google/genai/_interactions/types/webhook_list_response.py @@ -15,77 +15,12 @@ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -from typing import List, Union, Optional -from datetime import datetime -from typing_extensions import Literal +from typing import List, Optional +from .webhook import Webhook from .._models import BaseModel -__all__ = ["WebhookListResponse", "Webhook", "WebhookSigningSecret"] - - -class WebhookSigningSecret(BaseModel): - """Represents a signing secret used to verify webhook payloads.""" - - expire_time: Optional[datetime] = None - """Output only. The expiration date of the signing secret.""" - - truncated_secret: Optional[str] = None - """Output only. The truncated version of the signing secret.""" - - -class Webhook(BaseModel): - """A Webhook resource.""" - - subscribed_events: List[ - Union[ - Literal[ - "batch.succeeded", - "batch.cancelled", - "batch.expired", - "batch.failed", - "interaction.requires_action", - "interaction.completed", - "interaction.failed", - "interaction.cancelled", - "video.generated", - ], - str, - ] - ] - """Required. The events that the webhook is subscribed to. Available events: - - - batch.succeeded - - batch.cancelled - - batch.expired - - batch.failed - - interaction.requires_action - - interaction.completed - - interaction.failed - - interaction.cancelled - - video.generated - """ - - uri: str - """Required. The URI to which webhook events will be sent.""" - - create_time: Optional[datetime] = None - """Output only. The timestamp when the webhook was created.""" - - name: Optional[str] = None - """Identifier. The name of the webhook. Format: `webhooks/{webhook_id}`""" - - new_signing_secret: Optional[str] = None - """Output only. The new signing secret for the webhook. Only populated on create.""" - - signing_secrets: Optional[List[WebhookSigningSecret]] = None - """Output only. The signing secrets associated with this webhook.""" - - state: Optional[Literal["enabled", "disabled", "disabled_due_to_failed_deliveries"]] = None - """The state of the webhook.""" - - update_time: Optional[datetime] = None - """Output only. The timestamp when the webhook was last updated.""" +__all__ = ["WebhookListResponse"] class WebhookListResponse(BaseModel): diff --git a/google/genai/_interactions/types/webhook_retrieve_response.py b/google/genai/_interactions/types/webhook_retrieve_response.py deleted file mode 100644 index a8016498d..000000000 --- a/google/genai/_interactions/types/webhook_retrieve_response.py +++ /dev/null @@ -1,88 +0,0 @@ -# Copyright 2025 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. - -from typing import List, Union, Optional -from datetime import datetime -from typing_extensions import Literal - -from .._models import BaseModel - -__all__ = ["WebhookRetrieveResponse", "SigningSecret"] - - -class SigningSecret(BaseModel): - """Represents a signing secret used to verify webhook payloads.""" - - expire_time: Optional[datetime] = None - """Output only. The expiration date of the signing secret.""" - - truncated_secret: Optional[str] = None - """Output only. The truncated version of the signing secret.""" - - -class WebhookRetrieveResponse(BaseModel): - """A Webhook resource.""" - - subscribed_events: List[ - Union[ - Literal[ - "batch.succeeded", - "batch.cancelled", - "batch.expired", - "batch.failed", - "interaction.requires_action", - "interaction.completed", - "interaction.failed", - "interaction.cancelled", - "video.generated", - ], - str, - ] - ] - """Required. The events that the webhook is subscribed to. Available events: - - - batch.succeeded - - batch.cancelled - - batch.expired - - batch.failed - - interaction.requires_action - - interaction.completed - - interaction.failed - - interaction.cancelled - - video.generated - """ - - uri: str - """Required. The URI to which webhook events will be sent.""" - - create_time: Optional[datetime] = None - """Output only. The timestamp when the webhook was created.""" - - name: Optional[str] = None - """Identifier. The name of the webhook. Format: `webhooks/{webhook_id}`""" - - new_signing_secret: Optional[str] = None - """Output only. The new signing secret for the webhook. Only populated on create.""" - - signing_secrets: Optional[List[SigningSecret]] = None - """Output only. The signing secrets associated with this webhook.""" - - state: Optional[Literal["enabled", "disabled", "disabled_due_to_failed_deliveries"]] = None - """The state of the webhook.""" - - update_time: Optional[datetime] = None - """Output only. The timestamp when the webhook was last updated.""" diff --git a/google/genai/_interactions/types/webhook_update_response.py b/google/genai/_interactions/types/webhook_update_response.py deleted file mode 100644 index 1c4e07928..000000000 --- a/google/genai/_interactions/types/webhook_update_response.py +++ /dev/null @@ -1,88 +0,0 @@ -# Copyright 2025 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. - -from typing import List, Union, Optional -from datetime import datetime -from typing_extensions import Literal - -from .._models import BaseModel - -__all__ = ["WebhookUpdateResponse", "SigningSecret"] - - -class SigningSecret(BaseModel): - """Represents a signing secret used to verify webhook payloads.""" - - expire_time: Optional[datetime] = None - """Output only. The expiration date of the signing secret.""" - - truncated_secret: Optional[str] = None - """Output only. The truncated version of the signing secret.""" - - -class WebhookUpdateResponse(BaseModel): - """A Webhook resource.""" - - subscribed_events: List[ - Union[ - Literal[ - "batch.succeeded", - "batch.cancelled", - "batch.expired", - "batch.failed", - "interaction.requires_action", - "interaction.completed", - "interaction.failed", - "interaction.cancelled", - "video.generated", - ], - str, - ] - ] - """Required. The events that the webhook is subscribed to. Available events: - - - batch.succeeded - - batch.cancelled - - batch.expired - - batch.failed - - interaction.requires_action - - interaction.completed - - interaction.failed - - interaction.cancelled - - video.generated - """ - - uri: str - """Required. The URI to which webhook events will be sent.""" - - create_time: Optional[datetime] = None - """Output only. The timestamp when the webhook was created.""" - - name: Optional[str] = None - """Identifier. The name of the webhook. Format: `webhooks/{webhook_id}`""" - - new_signing_secret: Optional[str] = None - """Output only. The new signing secret for the webhook. Only populated on create.""" - - signing_secrets: Optional[List[SigningSecret]] = None - """Output only. The signing secrets associated with this webhook.""" - - state: Optional[Literal["enabled", "disabled", "disabled_due_to_failed_deliveries"]] = None - """The state of the webhook.""" - - update_time: Optional[datetime] = None - """Output only. The timestamp when the webhook was last updated."""