Skip to content

Commit 8aeff0b

Browse files
wanlin31copybara-github
authored andcommitted
fix: Refactor Webhook types in GenAI SDKs for easier useage
PiperOrigin-RevId: 899164237
1 parent acd3767 commit 8aeff0b

7 files changed

Lines changed: 54 additions & 274 deletions

File tree

google/genai/_interactions/resources/webhooks.py

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,10 @@
4040
async_to_streamed_response_wrapper,
4141
)
4242
from .._base_client import make_request_options
43+
from ..types.webhook import Webhook
4344
from ..types.webhook_list_response import WebhookListResponse
4445
from ..types.webhook_ping_response import WebhookPingResponse
45-
from ..types.webhook_create_response import WebhookCreateResponse
4646
from ..types.webhook_delete_response import WebhookDeleteResponse
47-
from ..types.webhook_update_response import WebhookUpdateResponse
48-
from ..types.webhook_retrieve_response import WebhookRetrieveResponse
4947
from ..types.webhook_rotate_signing_secret_response import WebhookRotateSigningSecretResponse
5048

5149
__all__ = ["WebhooksResource", "AsyncWebhooksResource"]
@@ -101,7 +99,7 @@ def create(
10199
extra_query: Query | None = None,
102100
extra_body: Body | None = None,
103101
timeout: float | httpx.Timeout | None | NotGiven = not_given,
104-
) -> WebhookCreateResponse:
102+
) -> Webhook:
105103
"""Creates a new Webhook.
106104
107105
Args:
@@ -159,7 +157,7 @@ def create(
159157
timeout=timeout,
160158
query=maybe_transform({"webhook_id": webhook_id}, webhook_create_params.WebhookCreateParams),
161159
),
162-
cast_to=WebhookCreateResponse,
160+
cast_to=Webhook,
163161
)
164162

165163
def retrieve(
@@ -173,7 +171,7 @@ def retrieve(
173171
extra_query: Query | None = None,
174172
extra_body: Body | None = None,
175173
timeout: float | httpx.Timeout | None | NotGiven = not_given,
176-
) -> WebhookRetrieveResponse:
174+
) -> Webhook:
177175
"""
178176
Gets a specific Webhook.
179177
@@ -197,7 +195,7 @@ def retrieve(
197195
options=make_request_options(
198196
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
199197
),
200-
cast_to=WebhookRetrieveResponse,
198+
cast_to=Webhook,
201199
)
202200

203201
def update(
@@ -231,7 +229,7 @@ def update(
231229
extra_query: Query | None = None,
232230
extra_body: Body | None = None,
233231
timeout: float | httpx.Timeout | None | NotGiven = not_given,
234-
) -> WebhookUpdateResponse:
232+
) -> Webhook:
235233
"""Updates an existing Webhook.
236234
237235
Args:
@@ -290,7 +288,7 @@ def update(
290288
timeout=timeout,
291289
query=maybe_transform({"update_mask": update_mask}, webhook_update_params.WebhookUpdateParams),
292290
),
293-
cast_to=WebhookUpdateResponse,
291+
cast_to=Webhook,
294292
)
295293

296294
def list(
@@ -525,7 +523,7 @@ async def create(
525523
extra_query: Query | None = None,
526524
extra_body: Body | None = None,
527525
timeout: float | httpx.Timeout | None | NotGiven = not_given,
528-
) -> WebhookCreateResponse:
526+
) -> Webhook:
529527
"""Creates a new Webhook.
530528
531529
Args:
@@ -585,7 +583,7 @@ async def create(
585583
{"webhook_id": webhook_id}, webhook_create_params.WebhookCreateParams
586584
),
587585
),
588-
cast_to=WebhookCreateResponse,
586+
cast_to=Webhook,
589587
)
590588

591589
async def retrieve(
@@ -599,7 +597,7 @@ async def retrieve(
599597
extra_query: Query | None = None,
600598
extra_body: Body | None = None,
601599
timeout: float | httpx.Timeout | None | NotGiven = not_given,
602-
) -> WebhookRetrieveResponse:
600+
) -> Webhook:
603601
"""
604602
Gets a specific Webhook.
605603
@@ -623,7 +621,7 @@ async def retrieve(
623621
options=make_request_options(
624622
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
625623
),
626-
cast_to=WebhookRetrieveResponse,
624+
cast_to=Webhook,
627625
)
628626

629627
async def update(
@@ -657,7 +655,7 @@ async def update(
657655
extra_query: Query | None = None,
658656
extra_body: Body | None = None,
659657
timeout: float | httpx.Timeout | None | NotGiven = not_given,
660-
) -> WebhookUpdateResponse:
658+
) -> Webhook:
661659
"""Updates an existing Webhook.
662660
663661
Args:
@@ -718,7 +716,7 @@ async def update(
718716
{"update_mask": update_mask}, webhook_update_params.WebhookUpdateParams
719717
),
720718
),
721-
cast_to=WebhookUpdateResponse,
719+
cast_to=Webhook,
722720
)
723721

724722
async def list(

google/genai/_interactions/types/__init__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from .model import Model as Model
2323
from .usage import Usage as Usage
2424
from .content import Content as Content
25+
from .webhook import Webhook as Webhook
2526
from .function import Function as Function
2627
from .annotation import Annotation as Annotation
2728
from .tool_param import ToolParam as ToolParam
@@ -45,6 +46,7 @@
4546
from .video_content import VideoContent as VideoContent
4647
from .function_param import FunctionParam as FunctionParam
4748
from .place_citation import PlaceCitation as PlaceCitation
49+
from .signing_secret import SigningSecret as SigningSecret
4850
from .thinking_level import ThinkingLevel as ThinkingLevel
4951
from .webhook_config import WebhookConfig as WebhookConfig
5052
from .thought_content import ThoughtContent as ThoughtContent
@@ -82,9 +84,7 @@
8284
from .function_result_content import FunctionResultContent as FunctionResultContent
8385
from .generation_config_param import GenerationConfigParam as GenerationConfigParam
8486
from .interaction_start_event import InteractionStartEvent as InteractionStartEvent
85-
from .webhook_create_response import WebhookCreateResponse as WebhookCreateResponse
8687
from .webhook_delete_response import WebhookDeleteResponse as WebhookDeleteResponse
87-
from .webhook_update_response import WebhookUpdateResponse as WebhookUpdateResponse
8888
from .file_search_call_content import FileSearchCallContent as FileSearchCallContent
8989
from .google_maps_call_content import GoogleMapsCallContent as GoogleMapsCallContent
9090
from .google_maps_result_param import GoogleMapsResultParam as GoogleMapsResultParam
@@ -93,7 +93,6 @@
9393
from .url_context_result_param import URLContextResultParam as URLContextResultParam
9494
from .interaction_create_params import InteractionCreateParams as InteractionCreateParams
9595
from .interaction_status_update import InteractionStatusUpdate as InteractionStatusUpdate
96-
from .webhook_retrieve_response import WebhookRetrieveResponse as WebhookRetrieveResponse
9796
from .deep_research_agent_config import DeepResearchAgentConfig as DeepResearchAgentConfig
9897
from .dynamic_agent_config_param import DynamicAgentConfigParam as DynamicAgentConfigParam
9998
from .file_search_result_content import FileSearchResultContent as FileSearchResultContent
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Copyright 2025 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
16+
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
17+
18+
from typing import Optional
19+
from datetime import datetime
20+
21+
from .._models import BaseModel
22+
23+
__all__ = ["SigningSecret"]
24+
25+
26+
class SigningSecret(BaseModel):
27+
"""Represents a signing secret used to verify webhook payloads."""
28+
29+
expire_time: Optional[datetime] = None
30+
"""Output only. The expiration date of the signing secret."""
31+
32+
truncated_secret: Optional[str] = None
33+
"""Output only. The truncated version of the signing secret."""

google/genai/_interactions/types/webhook_create_response.py renamed to google/genai/_interactions/types/webhook.py

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,12 @@
2020
from typing_extensions import Literal
2121

2222
from .._models import BaseModel
23+
from .signing_secret import SigningSecret
2324

24-
__all__ = ["WebhookCreateResponse", "SigningSecret"]
25+
__all__ = ["Webhook"]
2526

2627

27-
class SigningSecret(BaseModel):
28-
"""Represents a signing secret used to verify webhook payloads."""
29-
30-
expire_time: Optional[datetime] = None
31-
"""Output only. The expiration date of the signing secret."""
32-
33-
truncated_secret: Optional[str] = None
34-
"""Output only. The truncated version of the signing secret."""
35-
36-
37-
class WebhookCreateResponse(BaseModel):
28+
class Webhook(BaseModel):
3829
"""A Webhook resource."""
3930

4031
subscribed_events: List[

google/genai/_interactions/types/webhook_list_response.py

Lines changed: 3 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -15,77 +15,12 @@
1515

1616
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
1717

18-
from typing import List, Union, Optional
19-
from datetime import datetime
20-
from typing_extensions import Literal
18+
from typing import List, Optional
2119

20+
from .webhook import Webhook
2221
from .._models import BaseModel
2322

24-
__all__ = ["WebhookListResponse", "Webhook", "WebhookSigningSecret"]
25-
26-
27-
class WebhookSigningSecret(BaseModel):
28-
"""Represents a signing secret used to verify webhook payloads."""
29-
30-
expire_time: Optional[datetime] = None
31-
"""Output only. The expiration date of the signing secret."""
32-
33-
truncated_secret: Optional[str] = None
34-
"""Output only. The truncated version of the signing secret."""
35-
36-
37-
class Webhook(BaseModel):
38-
"""A Webhook resource."""
39-
40-
subscribed_events: List[
41-
Union[
42-
Literal[
43-
"batch.succeeded",
44-
"batch.cancelled",
45-
"batch.expired",
46-
"batch.failed",
47-
"interaction.requires_action",
48-
"interaction.completed",
49-
"interaction.failed",
50-
"interaction.cancelled",
51-
"video.generated",
52-
],
53-
str,
54-
]
55-
]
56-
"""Required. The events that the webhook is subscribed to. Available events:
57-
58-
- batch.succeeded
59-
- batch.cancelled
60-
- batch.expired
61-
- batch.failed
62-
- interaction.requires_action
63-
- interaction.completed
64-
- interaction.failed
65-
- interaction.cancelled
66-
- video.generated
67-
"""
68-
69-
uri: str
70-
"""Required. The URI to which webhook events will be sent."""
71-
72-
create_time: Optional[datetime] = None
73-
"""Output only. The timestamp when the webhook was created."""
74-
75-
name: Optional[str] = None
76-
"""Identifier. The name of the webhook. Format: `webhooks/{webhook_id}`"""
77-
78-
new_signing_secret: Optional[str] = None
79-
"""Output only. The new signing secret for the webhook. Only populated on create."""
80-
81-
signing_secrets: Optional[List[WebhookSigningSecret]] = None
82-
"""Output only. The signing secrets associated with this webhook."""
83-
84-
state: Optional[Literal["enabled", "disabled", "disabled_due_to_failed_deliveries"]] = None
85-
"""The state of the webhook."""
86-
87-
update_time: Optional[datetime] = None
88-
"""Output only. The timestamp when the webhook was last updated."""
23+
__all__ = ["WebhookListResponse"]
8924

9025

9126
class WebhookListResponse(BaseModel):

google/genai/_interactions/types/webhook_retrieve_response.py

Lines changed: 0 additions & 88 deletions
This file was deleted.

0 commit comments

Comments
 (0)