Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

1.7 KB
Raw Blame
from dataclasses import dataclass
from enum import StrEnum
from typing import Any

from pydantic import BaseModel

from core.mcp.session.base_session import BaseSession
from core.mcp.types import LATEST_PROTOCOL_VERSION, OAuthClientInformation, OAuthMetadata, RequestId, RequestParams

# 2025-06-18 stays explicit: it is no longer LATEST_PROTOCOL_VERSION, but servers still negotiate down to it.
SUPPORTED_PROTOCOL_VERSIONS: list[str] = ["2024-11-05", "2025-03-26", "2025-06-18", LATEST_PROTOCOL_VERSION]


@dataclass
class RequestContext[SessionT: BaseSession, LifespanContextT]:
    request_id: RequestId
    meta: RequestParams.Meta | None
    session: SessionT
    lifespan_context: LifespanContextT


class AuthActionType(StrEnum):
    """Types of actions that can be performed during auth flow."""

    SAVE_CLIENT_INFO = "save_client_info"
    SAVE_TOKENS = "save_tokens"
    SAVE_CODE_VERIFIER = "save_code_verifier"
    START_AUTHORIZATION = "start_authorization"
    SUCCESS = "success"


class AuthAction(BaseModel):
    """Represents an action that needs to be performed as a result of auth flow."""

    action_type: AuthActionType
    data: dict[str, Any]
    provider_id: str | None = None
    tenant_id: str | None = None


class AuthResult(BaseModel):
    """Result of auth function containing actions to be performed and response data."""

    actions: list[AuthAction]
    response: dict[str, str]


class OAuthCallbackState(BaseModel):
    """State data stored in Redis during OAuth callback flow."""

    provider_id: str
    tenant_id: str
    server_url: str
    metadata: OAuthMetadata | None = None
    client_information: OAuthClientInformation
    code_verifier: str
    redirect_uri: str