mirror of
https://github.com/langgenius/dify.git
synced 2026-02-14 06:54:50 +08:00
- Refactor trigger provider classes to improve naming consistency and clarity - Introduce new methods for managing trigger subscriptions, including validation and dispatching - Update API endpoints to reflect changes in subscription handling - Implement logging and request management for endpoint interactions - Enhance data models to support subscription attributes and lifecycle management Co-authored-by: Claude <noreply@anthropic.com>
67 lines
2.4 KiB
Python
67 lines
2.4 KiB
Python
from collections.abc import Mapping
|
|
from typing import Any, Optional
|
|
|
|
from pydantic import BaseModel, Field
|
|
|
|
from core.entities.provider_entities import ProviderConfig
|
|
from core.plugin.entities.plugin_daemon import CredentialType
|
|
from core.trigger.entities.entities import (
|
|
OAuthSchema,
|
|
Subscription,
|
|
SubscriptionSchema,
|
|
TriggerDescription,
|
|
TriggerEntity,
|
|
TriggerParameter,
|
|
TriggerProviderIdentity,
|
|
)
|
|
|
|
|
|
class TriggerProviderSubscriptionApiEntity(BaseModel):
|
|
id: str = Field(description="The unique id of the subscription")
|
|
name: str = Field(description="The name of the subscription")
|
|
provider: str = Field(description="The provider id of the subscription")
|
|
credential_type: CredentialType = Field(description="The type of the credential")
|
|
credentials: dict = Field(description="The credentials of the subscription")
|
|
|
|
|
|
class TriggerProviderApiEntity(BaseModel):
|
|
identity: TriggerProviderIdentity = Field(description="The identity of the trigger provider")
|
|
credentials_schema: list[ProviderConfig] = Field(description="The credentials schema of the trigger provider")
|
|
oauth_schema: Optional[OAuthSchema] = Field(description="The OAuth schema of the trigger provider")
|
|
subscription_schema: Optional[SubscriptionSchema] = Field(
|
|
description="The subscription schema of the trigger provider"
|
|
)
|
|
triggers: list[TriggerEntity] = Field(description="The triggers of the trigger provider")
|
|
|
|
|
|
class TriggerApiEntity(BaseModel):
|
|
name: str = Field(description="The name of the trigger")
|
|
description: TriggerDescription = Field(description="The description of the trigger")
|
|
parameters: list[TriggerParameter] = Field(description="The parameters of the trigger")
|
|
output_schema: Optional[Mapping[str, Any]] = Field(description="The output schema of the trigger")
|
|
|
|
class SubscriptionValidation(BaseModel):
|
|
id: str
|
|
name: str
|
|
tenant_id: str
|
|
user_id: str
|
|
provider_id: str
|
|
endpoint: str
|
|
parameters: dict
|
|
properties: dict
|
|
credentials: dict
|
|
credential_type: str
|
|
credential_expires_at: int
|
|
expires_at: int
|
|
|
|
def to_subscription(self) -> Subscription:
|
|
return Subscription(
|
|
expires_at=self.expires_at,
|
|
endpoint=self.endpoint,
|
|
parameters=self.parameters,
|
|
properties=self.properties,
|
|
)
|
|
|
|
|
|
__all__ = ["TriggerApiEntity", "TriggerProviderApiEntity", "TriggerProviderSubscriptionApiEntity"]
|