Skip to content

Commit 41d4eec

Browse files
Merge pull request #184 from coolsky99/feature/agentstudio-webhooks
feat(agentstudio): add webhook endpoint APIs
2 parents 6f7fd0d + 5c826c4 commit 41d4eec

9 files changed

Lines changed: 558 additions & 0 deletions

File tree

‎dashscope/agentstudio/__init__.py‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,15 @@
7070
DeploymentCreateParams,
7171
DeploymentUpdateParams,
7272
SessionEventSendParams,
73+
WebhookEndpointCreateParams,
74+
WebhookEndpointUpdateParams,
75+
WebhookEventListParams,
76+
)
77+
from .constants import (
78+
WebhookDeliveryStatus,
79+
WebhookDisabledReason,
80+
WebhookEventType,
81+
WebhookStatus,
7382
)
7483

7584
__all__ = [
@@ -119,4 +128,11 @@
119128
"DeploymentCreateParams",
120129
"DeploymentUpdateParams",
121130
"SessionEventSendParams",
131+
"WebhookEndpointCreateParams",
132+
"WebhookEndpointUpdateParams",
133+
"WebhookEventListParams",
134+
"WebhookStatus",
135+
"WebhookDisabledReason",
136+
"WebhookDeliveryStatus",
137+
"WebhookEventType",
122138
]

‎dashscope/agentstudio/client.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
from dashscope.agentstudio.resources.sessions import Sessions, AsyncSessions
2525
from dashscope.agentstudio.resources.skills import Skills, AsyncSkills
2626
from dashscope.agentstudio.resources.vaults import Vaults, AsyncVaults
27+
from dashscope.agentstudio.resources.webhook_endpoints import (
28+
AsyncWebhookEndpoints,
29+
WebhookEndpoints,
30+
)
2731
from dashscope.agentstudio.constants import (
2832
AGENTSTUDIO_BASE_URL_TEMPLATE,
2933
AGENTSTUDIO_DEFAULT_REGION,
@@ -129,6 +133,7 @@ def __init__(
129133
self.files = Files(self)
130134
self.skills = Skills(self)
131135
self.vaults = Vaults(self)
136+
self.webhook_endpoints = WebhookEndpoints(self)
132137

133138
def close(self) -> None:
134139
self.transport.close()
@@ -201,6 +206,7 @@ def __init__(
201206
self.files = AsyncFiles(self)
202207
self.skills = AsyncSkills(self)
203208
self.vaults = AsyncVaults(self)
209+
self.webhook_endpoints = AsyncWebhookEndpoints(self)
204210

205211
async def aclose(self) -> None:
206212
await self.transport.aclose()

‎dashscope/agentstudio/constants.py‎

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,113 @@ class SessionStatus(StrEnum):
9393
RUNNING = "running"
9494
RESCHEDULING = "rescheduling"
9595
TERMINATED = "terminated"
96+
97+
98+
class WebhookStatus(StrEnum):
99+
"""Webhook endpoint activation status."""
100+
101+
# The endpoint can receive webhook deliveries.
102+
ACTIVE = "ACTIVE"
103+
# The endpoint does not receive webhook deliveries.
104+
DISABLED = "DISABLED"
105+
106+
107+
class WebhookDisabledReason(StrEnum):
108+
"""Reason why a webhook endpoint was disabled."""
109+
110+
# The endpoint was disabled manually.
111+
MANUAL = "MANUAL"
112+
# The endpoint reached the consecutive delivery failure threshold.
113+
CONSECUTIVE_DELIVERY_FAILURES = "CONSECUTIVE_DELIVERY_FAILURES"
114+
# The endpoint returned an HTTP redirect response.
115+
REDIRECT_RESPONSE = "REDIRECT_RESPONSE"
116+
# The endpoint failed server-side request forgery validation.
117+
SSRF_VALIDATION_FAILED = "SSRF_VALIDATION_FAILED"
118+
# The endpoint failed Transport Layer Security validation.
119+
TLS_VALIDATION_FAILED = "TLS_VALIDATION_FAILED"
120+
121+
122+
class WebhookDeliveryStatus(StrEnum):
123+
"""Webhook delivery status."""
124+
125+
# The delivery is waiting to start.
126+
PENDING = "PENDING"
127+
# The delivery is currently being sent.
128+
DELIVERING = "DELIVERING"
129+
# The delivery is waiting for its next retry.
130+
WAITING_RETRY = "WAITING_RETRY"
131+
# The delivery completed successfully.
132+
SUCCEEDED = "SUCCEEDED"
133+
# The delivery exhausted all attempts.
134+
FAILED = "FAILED"
135+
# The delivery was canceled because its endpoint was disabled or deleted.
136+
CANCELED = "CANCELED"
137+
138+
139+
class WebhookEventType(StrEnum):
140+
"""Event types accepted by webhook endpoint subscriptions."""
141+
142+
# A session was created.
143+
SESSION_CREATED = "session.created"
144+
# A session was updated.
145+
SESSION_UPDATED = "session.updated"
146+
# A session was archived.
147+
SESSION_ARCHIVED = "session.archived"
148+
# A session was deleted.
149+
SESSION_DELETED = "session.deleted"
150+
# A session run started.
151+
SESSION_STATUS_RUN_STARTED = "session.status_run_started"
152+
# A session entered the idle state.
153+
SESSION_STATUS_IDLED = "session.status_idled"
154+
# A session entered the terminated state.
155+
SESSION_STATUS_TERMINATED = "session.status_terminated"
156+
# A session thread was created.
157+
SESSION_THREAD_CREATED = "session.thread_created"
158+
# A session thread run started.
159+
SESSION_THREAD_RUN_STARTED = "session.thread_run_started"
160+
# A session thread entered the idle state.
161+
SESSION_THREAD_IDLED = "session.thread_idled"
162+
# A session thread entered the terminated state.
163+
SESSION_THREAD_TERMINATED = "session.thread_terminated"
164+
# An agent was created.
165+
AGENT_CREATED = "agent.created"
166+
# An agent was updated.
167+
AGENT_UPDATED = "agent.updated"
168+
# An agent was archived.
169+
AGENT_ARCHIVED = "agent.archived"
170+
# A deployment was created.
171+
DEPLOYMENT_CREATED = "deployment.created"
172+
# A deployment was updated.
173+
DEPLOYMENT_UPDATED = "deployment.updated"
174+
# A deployment was archived.
175+
DEPLOYMENT_ARCHIVED = "deployment.archived"
176+
# A deployment was paused.
177+
DEPLOYMENT_PAUSED = "deployment.paused"
178+
# A deployment was resumed.
179+
DEPLOYMENT_UNPAUSED = "deployment.unpaused"
180+
# A deployment run started.
181+
DEPLOYMENT_RUN_STARTED = "deployment_run.started"
182+
# A deployment run failed.
183+
DEPLOYMENT_RUN_FAILED = "deployment_run.failed"
184+
# A deployment run succeeded.
185+
DEPLOYMENT_RUN_SUCCEEDED = "deployment_run.succeeded"
186+
# An environment was created.
187+
ENVIRONMENT_CREATED = "environment.created"
188+
# An environment was updated.
189+
ENVIRONMENT_UPDATED = "environment.updated"
190+
# An environment was archived.
191+
ENVIRONMENT_ARCHIVED = "environment.archived"
192+
# An environment was deleted.
193+
ENVIRONMENT_DELETED = "environment.deleted"
194+
# A vault was created.
195+
VAULT_CREATED = "vault.created"
196+
# A vault was archived.
197+
VAULT_ARCHIVED = "vault.archived"
198+
# A vault was deleted.
199+
VAULT_DELETED = "vault.deleted"
200+
# A vault credential was created.
201+
VAULT_CREDENTIAL_CREATED = "vault_credential.created"
202+
# A vault credential was archived.
203+
VAULT_CREDENTIAL_ARCHIVED = "vault_credential.archived"
204+
# A vault credential was deleted.
205+
VAULT_CREDENTIAL_DELETED = "vault_credential.deleted"

‎dashscope/agentstudio/resources/__init__.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@
4646
Credentials,
4747
Vaults,
4848
)
49+
from dashscope.agentstudio.resources.webhook_endpoints import (
50+
AsyncWebhookEndpoints,
51+
WebhookEndpoints,
52+
)
4953

5054
__all__ = [
5155
"Agents",
@@ -70,6 +74,8 @@
7074
"AsyncSessionEvents",
7175
"Vaults",
7276
"AsyncVaults",
77+
"WebhookEndpoints",
78+
"AsyncWebhookEndpoints",
7379
"_TypedEventStream",
7480
"_AioTypedEventStream",
7581
]

‎dashscope/agentstudio/resources/_helpers.py‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
Skill,
2020
SkillVersion,
2121
Vault,
22+
WebhookEndpoint,
23+
WebhookEvent,
24+
WebhookSecretReset,
2225
parse_server_event,
2326
)
2427

@@ -68,6 +71,20 @@ def _coerce_credential(payload: Mapping[str, Any]) -> Credential:
6871
return Credential(**dict(payload))
6972

7073

74+
def _coerce_webhook_endpoint(payload: Mapping[str, Any]) -> WebhookEndpoint:
75+
return WebhookEndpoint(**dict(payload))
76+
77+
78+
def _coerce_webhook_event(payload: Mapping[str, Any]) -> WebhookEvent:
79+
return WebhookEvent(**dict(payload))
80+
81+
82+
def _coerce_webhook_secret_reset(
83+
payload: Mapping[str, Any],
84+
) -> WebhookSecretReset:
85+
return WebhookSecretReset(**dict(payload))
86+
87+
7188
def _coerce_deployment(payload: Mapping[str, Any]) -> Deployment:
7289
return Deployment(**dict(payload))
7390

0 commit comments

Comments
 (0)