from django.contrib import admin
from django.urls import path, include
from django.conf import settings
from django.conf.urls.static import static
from django.urls.conf import re_path
from django.shortcuts import redirect
from django.views.generic.base import RedirectView
from drf_spectacular.views import (
    SpectacularAPIView, SpectacularSwaggerView, SpectacularRedocView
)
from config.account_views import (
    AccountAuthPopupCompleteView,
    AccountLoginModalView,
    AccountSignupModalView,
    PasswordResetBridgeConfirmView,
    PasswordResetBridgeContinueView,
    PasswordResetBridgeStartView,
)
from console.api_views import (
    LLMEndpointTestAPIView,
    ConsolePersistentAgentViewSet,
    AgentFsNodeDownloadAPIView,
    SignedAgentFsNodeDownloadAPIView,
    AgentFsNodeBulkDeleteAPIView,
    AgentFsNodeCreateDirAPIView,
    AgentFsNodeListAPIView,
    AgentFsNodeMoveAPIView,
    AgentFsNodeUploadAPIView,
    AgentMessageCreateAPIView,
    AgentLatestMessageReadAPIView,
    AgentHumanInputRequestBatchResponseAPIView,
    AgentHumanInputRequestDismissAPIView,
    AgentHumanInputRequestResponseAPIView,
    AgentPlanningSkipAPIView,
    AgentContactRequestListAPIView,
    AgentContactRequestResolveAPIView,
    AgentChatRosterAPIView,
    AgentQuickCreateAPIView,
    AgentSpawnIntentAPIView,
    AgentCollaboratorLeaveAPIView,
    AgentSuggestionsAPIView,
    AgentProcessingStatusAPIView,
    AgentStopAPIView,
    AgentDailyCreditsAPIView,
    AgentAddonsAPIView,
    AgentSettingsAPIView,
    AgentQuickSettingsAPIView,
    AgentReassignAPIView,
    AgentTemplateCloneAPIView,
    AgentSmsEnableAPIView,
    AgentTimelineAPIView,
    AgentSpawnRequestDecisionAPIView,
    AgentRequestedSecretsFulfillAPIView,
    AgentRequestedSecretsRemoveAPIView,
    UserProfileAPIView,
    UserPreferencesAPIView,
    UserPhoneAPIView,
    UserPhoneResendAPIView,
    UserPhoneVerifyAPIView,
    UserEmailResendVerificationAPIView,
    AgentWebSessionEndAPIView,
    AgentWebSessionHeartbeatAPIView,
    AgentWebSessionStartAPIView,
    BillingInitialDataAPIView,
    ConsoleSessionAPIView,
    ConsoleLLMOverviewAPIView,
    SystemStatusAPIView,
    SystemSettingsListAPIView,
    SystemSettingDetailAPIView,
    LLMPerformanceTestAPIView,
    LLMProviderListCreateAPIView,
    LLMProviderDetailAPIView,
    PersistentEndpointListCreateAPIView,
    PersistentEndpointDetailAPIView,
    PersistentTokenRangeListCreateAPIView,
    PersistentTokenRangeDetailAPIView,
    PersistentTierListCreateAPIView,
    PersistentTierDetailAPIView,
    PersistentTierEndpointListCreateAPIView,
    PersistentTierEndpointDetailAPIView,
    BrowserEndpointListCreateAPIView,
    BrowserEndpointDetailAPIView,
    BrowserTierListCreateAPIView,
    BrowserTierDetailAPIView,
    BrowserTierEndpointListCreateAPIView,
    BrowserTierEndpointDetailAPIView,
    EmbeddingEndpointListCreateAPIView,
    EmbeddingEndpointDetailAPIView,
    EmbeddingTierListCreateAPIView,
    EmbeddingTierDetailAPIView,
    EmbeddingTierEndpointListCreateAPIView,
    EmbeddingTierEndpointDetailAPIView,
    FileHandlerEndpointListCreateAPIView,
    FileHandlerEndpointDetailAPIView,
    FileHandlerTierListCreateAPIView,
    FileHandlerTierDetailAPIView,
    FileHandlerTierEndpointListCreateAPIView,
    FileHandlerTierEndpointDetailAPIView,
    ImageGenerationEndpointListCreateAPIView,
    ImageGenerationEndpointDetailAPIView,
    ImageGenerationTierListCreateAPIView,
    ImageGenerationTierDetailAPIView,
    ImageGenerationTierEndpointListCreateAPIView,
    ImageGenerationTierEndpointDetailAPIView,
    VideoGenerationEndpointListCreateAPIView,
    VideoGenerationEndpointDetailAPIView,
    VideoGenerationTierListCreateAPIView,
    VideoGenerationTierDetailAPIView,
    VideoGenerationTierEndpointListCreateAPIView,
    VideoGenerationTierEndpointDetailAPIView,
    StaffAgentSearchAPIView,
    StaffUserSearchAPIView,
    StaffUserDetailAPIView,
    StaffUserEmailVerifyAPIView,
    StaffUserEmailTriggerAPIView,
    StaffUserTaskCreditGrantAPIView,
    LLMRoutingProfileListCreateAPIView,
    LLMRoutingProfileDetailAPIView,
    LLMRoutingProfileActivateAPIView,
    LLMRoutingProfileCloneAPIView,
    ProfileTokenRangeListCreateAPIView,
    ProfileTokenRangeDetailAPIView,
    ProfilePersistentTierListCreateAPIView,
    ProfilePersistentTierDetailAPIView,
    ProfilePersistentTierEndpointListCreateAPIView,
    ProfilePersistentTierEndpointDetailAPIView,
    ProfileBrowserTierListCreateAPIView,
    ProfileBrowserTierDetailAPIView,
    ProfileBrowserTierEndpointListCreateAPIView,
    ProfileBrowserTierEndpointDetailAPIView,
    ProfileEmbeddingsTierListCreateAPIView,
    ProfileEmbeddingsTierDetailAPIView,
    ProfileEmbeddingsTierEndpointListCreateAPIView,
    ProfileEmbeddingsTierEndpointDetailAPIView,
    MCPServerListAPIView,
    MCPServerDetailAPIView,
    MCPServerTestAPIView,
    PlatformMCPServerListAPIView,
    PlatformMCPServerDetailAPIView,
    PlatformMCPServerTestAPIView,
    MCPServerAssignmentsAPIView,
    MCPOAuthCallbackView,
    MCPOAuthMetadataProxyView,
    MCPOAuthRevokeView,
    MCPOAuthSessionVerifierView,
    MCPOAuthStartView,
    MCPOAuthStatusView,
    AgentEmailOAuthCallbackView,
    AgentEmailOAuthRevokeView,
    AgentEmailOAuthSessionVerifierView,
    AgentEmailOAuthStartView,
    AgentEmailOAuthStatusView,
    StaffAgentAuditAPIView,
    StaffAgentAuditExportAPIView,
    StaffAgentAuditTimelineAPIView,
    StaffAgentAuditDayDebugAPIView,
    StaffAgentJudgeSuggestionDecisionAPIView,
    StaffAgentProcessEventsAPIView,
    StaffAgentRunJudgeAPIView,
    StaffAgentSystemMessageAPIView,
    StaffAgentSystemMessageDetailAPIView,
    StaffPromptArchiveAPIView,
    EvalSuiteListAPIView,
    GlobalSkillEvalLauncherAPIView,
    GlobalSkillEvalRunCreateAPIView,
    EvalSuiteRunCreateAPIView,
    EvalSuiteRunDetailAPIView,
    EvalSuiteRunListAPIView,
    EvalSuiteRunRunTypeAPIView,
    EvalRunDetailAPIView,
    EvalRunCompareAPIView,
    EvalSuiteRunCompareAPIView,
)
from console.pipedream_apps_api import (
    AgentPipedreamAppAPIView,
    AgentPipedreamAppsAPIView,
    AgentPipedreamAppConnectAPIView,
    AgentPipedreamAppConnectionAPIView,
    PipedreamAppAgentConnectionsAPIView,
    PipedreamAppsAPIView,
    PipedreamAppSearchAPIView,
)
from console.secrets_api_views import (
    GlobalSecretListAPIView,
    GlobalSecretDetailAPIView,
    AgentSecretListAPIView,
    AgentSecretDetailAPIView,
    AgentSecretPromoteAPIView,
)
from console.system_skill_profiles_api_views import (
    SystemSkillProfileListAPIView,
    SystemSkillProfileDetailAPIView,
    SystemSkillProfileSetDefaultAPIView,
)
from console.email_settings.views import (
    AgentEmailSettingsAPIView,
    AgentEmailSettingsEnsureAccountAPIView,
    AgentEmailSettingsTestAPIView,
)
from console.discord_api import DiscordOAuthCallbackView, DiscordOAuthStartView
from console.usage_views import (
    UsageSummaryAPIView,
    UsageBurnRateSnapshotAPIView,
    UsageTrendAPIView,
    UsageToolBreakdownAPIView,
    UsageAgentLeaderboardAPIView,
    UsageAgentsAPIView,
)
from console.insight_views import AgentInsightsAPIView
from console.views import (
    ConsoleHome,
    ApiKeyListView,
    ApiKeyDetailView,
    ApiKeyTableView,
    ApiKeyBlankFormView,
    ApiKeyCreateModalView,
    BillingView,
    BillingPortalView,
    PersistentAgentsView,
    ConsoleDiagnosticsView,
    ConsoleStatusView,
    LegacyConsoleStatusRedirectView,
    ConsoleUsageView,
    SystemSettingsView,
    ConsoleLLMConfigView,
    MCPServerManagementView,
    PlatformMCPServerManagementView,
    GlobalSecretsView,
    SystemSkillProfilesView,
    MCPOAuthCallbackPageView,
    AgentEmailOAuthCallbackPageView,
    PersistentAgentChatShellView,
    AgentAvatarProxyView,
    AgentAvatarThumbnailProxyView,
    PublicAgentAvatarThumbnailView,
    AgentCreateContactView,
    AgentQuickSpawnView,
    AgentDetailView,
    AgentEnableSmsView,
    AgentDailyLimitEmailActionView,
    AgentDeleteView,
    AgentSecretsView,
    AgentSecretsAddView,
    AgentSecretsAddFormView,
    AgentSecretsEditView,
    AgentSecretsDeleteView,
    ProfileView,
    AgentSecretsRequestView,
    AgentSecretsRequestThanksView,
    AgentSecretRerequestView,
    AgentWelcomeView,
    ConsoleEvalsView,
    ConsoleEvalsDetailView,
    StaffAgentAuditView,
    StaffUsersView,
    AgentContactRequestsView,
    AgentContactRequestsThanksView,
    AgentAllowlistView,
    AgentTransferInviteRespondView,
    AgentAllowlistInviteAcceptView,
    AgentAllowlistInviteRejectView,
    AgentCollaboratorInviteAcceptView,
    AgentCollaboratorInviteRejectView,
    OrganizationListView,
    OrganizationCreateView,
    OrganizationDetailView,
    OrganizationInviteModalView,
    OrganizationInviteAcceptView,
    OrganizationInviteRejectView,
    OrganizationInviteRevokeOrgView,
    OrganizationInviteResendOrgView,
    OrganizationMemberRemoveOrgView,
    OrganizationLeaveOrgView,
    OrganizationMemberRoleUpdateOrgView,
    OrganizationSeatCheckoutView,
    OrganizationSeatScheduleView,
    OrganizationSeatScheduleCancelView,
    OrganizationSeatPortalView,
    update_task_pack_quantity,
    update_contact_pack_quantity,
    update_addons,
    add_dedicated_ip_quantity,
    remove_dedicated_ip,
    remove_all_dedicated_ip,
    update_billing_settings,
    get_billing_settings,
    get_user_plan_api,
    cancel_subscription,
    sync_billing_subscription_state,
    resume_subscription,
    tasks_view,
    task_result_view,
    task_cancel_view,
    task_detail_view,
    grant_credits,
    task_detail_view,
    AgentEmailSettingsView,
    AgentFilesView,
    console_billing_update,
)
from console.context_views import SwitchContextView
from pages.views import PaidPlanLanding
from api.views import LinkShortenerRedirectView, PipedreamConnectRedirectView

API_REFERENCE_DOCS_URL = "https://docs.gobii.ai/api-reference"
BELUGA_TRACKING_REDIRECT_URL = "https://go.trybeluga.ai/%(code)s"

_schema_swagger_view = SpectacularSwaggerView.as_view(url_name="schema")
_schema_redoc_view = SpectacularRedocView.as_view(url_name="schema")
_beluga_tracking_redirect_view = RedirectView.as_view(
    url=BELUGA_TRACKING_REDIRECT_URL,
    permanent=False,
    query_string=True,
)


def _with_noindex_follow_header(response):
    response["X-Robots-Tag"] = "noindex, follow"
    return response


def schema_swagger_view(request, *args, **kwargs):
    if settings.GOBII_PROPRIETARY_MODE:
        return _with_noindex_follow_header(redirect(API_REFERENCE_DOCS_URL))
    return _with_noindex_follow_header(_schema_swagger_view(request, *args, **kwargs))


def schema_redoc_view(request, *args, **kwargs):
    if settings.GOBII_PROPRIETARY_MODE:
        return redirect(API_REFERENCE_DOCS_URL)
    return _schema_redoc_view(request, *args, **kwargs)

urlpatterns = [
    path("setup/", include("setup.urls")),

    path("r/<slug:code>/", _beluga_tracking_redirect_view, name="beluga_tracking_redirect"),
    path("r/<slug:code>", _beluga_tracking_redirect_view, name="beluga_tracking_redirect_no_slash"),
    path("m/<slug:code>/", LinkShortenerRedirectView.as_view(), name="short_link"),
    path("d/<str:token>/", SignedAgentFsNodeDownloadAPIView.as_view(), name="signed_agent_fs_download"),

    # Pipedream JIT connect redirect - generates fresh auth links on-demand
    path("connect/pipedream/<uuid:agent_id>/<slug:app_slug>/", PipedreamConnectRedirectView.as_view(), name="pipedream_jit_connect"),
    path("console/api/discord/oauth/start/", DiscordOAuthStartView.as_view(), name="discord_oauth_start"),
    path("console/api/discord/oauth/callback/", DiscordOAuthCallbackView.as_view(), name="discord_oauth_callback"),

    # Plan landing pages (must be before console to avoid conflict)
    path("plans/<slug:plan>/", PaidPlanLanding.as_view(), name="plan_landing"),
    
    # system settings
    path("evals/", ConsoleEvalsView.as_view(), name="evals"),
    path("evals/<uuid:suite_run_id>/", ConsoleEvalsDetailView.as_view(), name="evals-detail"),
    path("llm-config/", ConsoleLLMConfigView.as_view(), name="llm-config"),
    path("system-settings/", SystemSettingsView.as_view(), name="system-settings"),

    # console
    path("console/", ConsoleHome.as_view(), name="console-home"),
    path("console/diagnostics/", ConsoleDiagnosticsView.as_view(), name="console_diagnostics"),
    path("staff/status/", ConsoleStatusView.as_view(), name="console-status"),
    path("console/status/", LegacyConsoleStatusRedirectView.as_view(), name="console-status-legacy"),
    path("staff/mcp/", PlatformMCPServerManagementView.as_view(), name="staff-platform-mcp"),
    path("staff/users/", StaffUsersView.as_view(), name="staff-users"),
    path("staff/users/<int:user_id>/", StaffUsersView.as_view(), name="staff-user-detail"),
    path("console/usage/", ConsoleUsageView.as_view(), name="usage"),
    path("console/staff/agents/<uuid:agent_id>/audit/", StaffAgentAuditView.as_view(), name="console-agent-audit"),
    path("console/secrets/", GlobalSecretsView.as_view(), name="console-secrets"),
    path(
        "console/system-skills/<slug:skill_key>/profiles/",
        SystemSkillProfilesView.as_view(),
        name="console-system-skill-profiles",
    ),
    path("console/advanced/mcp-servers/", MCPServerManagementView.as_view(), name="console-mcp-servers"),
    path("console/mcp/oauth/callback/", MCPOAuthCallbackPageView.as_view(), name="console-mcp-oauth-callback-view"),
    path("console/email/oauth/callback/", AgentEmailOAuthCallbackPageView.as_view(), name="console-email-oauth-callback-view"),
    path("console/switch-context/", SwitchContextView.as_view(), name="switch_context"),
    path("console/api-keys/", ApiKeyListView.as_view(), name="api_keys"),
    path("console/api-keys/blank-form/", ApiKeyBlankFormView.as_view(), name="api_key_blank_form"),
    path("console/api-keys/table/", ApiKeyTableView.as_view(), name="api_keys_table"),
    path("console/api-keys/<uuid:pk>/", ApiKeyDetailView.as_view(), name="api_key_detail"),
    path(
        "console/api-keys/create-modal/",
        ApiKeyCreateModalView.as_view(),
        name="api_key_create_modal",
    ),

    path("console/billing/", BillingView.as_view(), name="billing"),
    path("console/billing/portal/", BillingPortalView.as_view(), name="billing_portal"),
    path("console/api/billing/update/", console_billing_update, name="console_billing_update"),
    path("console/profile/", ProfileView.as_view(), name="profile"),

    path("console/agents/", PersistentAgentsView.as_view(), name="agents"),
    path("console/agents/<uuid:pk>/chat/", PersistentAgentChatShellView.as_view(), name="agent_chat_shell"),
    path("console/agents/<uuid:pk>/chat/settings/", PersistentAgentChatShellView.as_view(), name="agent_chat_shell_settings"),
    path("console/agents/<uuid:pk>/chat/secrets/", PersistentAgentChatShellView.as_view(), name="agent_chat_shell_secrets"),
    path("console/agents/<uuid:pk>/chat/email/", PersistentAgentChatShellView.as_view(), name="agent_chat_shell_email"),
    path("console/agents/<uuid:pk>/chat/files/", PersistentAgentChatShellView.as_view(), name="agent_chat_shell_files"),
    path("console/agents/<uuid:pk>/chat/contact-requests/", PersistentAgentChatShellView.as_view(), name="agent_chat_shell_contact_requests"),
    path("console/agents/<uuid:pk>/avatar/thumb/", AgentAvatarThumbnailProxyView.as_view(), name="agent_avatar_thumbnail"),
    path("console/agents/<uuid:pk>/avatar/", AgentAvatarProxyView.as_view(), name="agent_avatar"),
    path("public/agents/<uuid:pk>/avatar/thumb/", PublicAgentAvatarThumbnailView.as_view(), name="agent_avatar_public_thumbnail"),
    path("console/api/agents/roster/", AgentChatRosterAPIView.as_view(), name="console_agent_roster"),
    path("console/api/agents/create/", AgentQuickCreateAPIView.as_view(), name="console_agent_quick_create"),
    path("console/api/agents/spawn-intent/", AgentSpawnIntentAPIView.as_view(), name="console_agent_spawn_intent"),
    path("console/api/agents/<uuid:agent_id>/collaboration/leave/", AgentCollaboratorLeaveAPIView.as_view(), name="console_agent_collaborator_leave"),
    path("console/api/agents/<uuid:agent_id>/timeline/", AgentTimelineAPIView.as_view(), name="console_agent_timeline"),
    path("console/api/agents/<uuid:agent_id>/planning/skip/", AgentPlanningSkipAPIView.as_view(), name="console_agent_planning_skip"),
    path("console/api/agents/<uuid:agent_id>/suggestions/", AgentSuggestionsAPIView.as_view(), name="console_agent_suggestions"),
    path(
        "console/api/agents/<uuid:agent_id>/human-input-requests/respond-batch/",
        AgentHumanInputRequestBatchResponseAPIView.as_view(),
        name="console_agent_human_input_request_batch_respond",
    ),
    path(
        "console/api/agents/<uuid:agent_id>/human-input-requests/<uuid:request_id>/respond/",
        AgentHumanInputRequestResponseAPIView.as_view(),
        name="console_agent_human_input_request_respond",
    ),
    path(
        "console/api/agents/<uuid:agent_id>/human-input-requests/<uuid:request_id>/dismiss/",
        AgentHumanInputRequestDismissAPIView.as_view(),
        name="console_agent_human_input_request_dismiss",
    ),
    path(
        "console/api/agents/<uuid:agent_id>/spawn-requests/<uuid:spawn_request_id>/decision/",
        AgentSpawnRequestDecisionAPIView.as_view(),
        name="console_agent_spawn_request_decision",
    ),
    path(
        "console/api/agents/<uuid:agent_id>/requested-secrets/fulfill/",
        AgentRequestedSecretsFulfillAPIView.as_view(),
        name="console_agent_requested_secrets_fulfill",
    ),
    path(
        "console/api/agents/<uuid:agent_id>/requested-secrets/remove/",
        AgentRequestedSecretsRemoveAPIView.as_view(),
        name="console_agent_requested_secrets_remove_api",
    ),
    path(
        "console/api/agents/<uuid:agent_id>/contact-requests/",
        AgentContactRequestListAPIView.as_view(),
        name="console_agent_contact_requests_api",
    ),
    path(
        "console/api/agents/<uuid:agent_id>/contact-requests/resolve/",
        AgentContactRequestResolveAPIView.as_view(),
        name="console_agent_contact_requests_resolve",
    ),
    path("console/api/agents/<uuid:agent_id>/messages/", AgentMessageCreateAPIView.as_view(), name="console_agent_message_create"),
    path("console/api/agents/<uuid:agent_id>/messages/latest/read/", AgentLatestMessageReadAPIView.as_view(), name="console_agent_latest_message_read"),
    path("console/api/agents/<uuid:agent_id>/files/", AgentFsNodeListAPIView.as_view(), name="console_agent_fs_list"),
    path("console/api/agents/<uuid:agent_id>/files/upload/", AgentFsNodeUploadAPIView.as_view(), name="console_agent_fs_upload"),
    path("console/api/agents/<uuid:agent_id>/files/delete/", AgentFsNodeBulkDeleteAPIView.as_view(), name="console_agent_fs_delete"),
    path("console/api/agents/<uuid:agent_id>/files/download/", AgentFsNodeDownloadAPIView.as_view(), name="console_agent_fs_download"),
    path("console/api/agents/<uuid:agent_id>/files/folders/", AgentFsNodeCreateDirAPIView.as_view(), name="console_agent_fs_create_folder"),
    path("console/api/agents/<uuid:agent_id>/files/move/", AgentFsNodeMoveAPIView.as_view(), name="console_agent_fs_move"),
    path("console/api/agents/<uuid:agent_id>/processing/", AgentProcessingStatusAPIView.as_view(), name="console_agent_processing_status"),
    path("console/api/agents/<uuid:agent_id>/stop/", AgentStopAPIView.as_view(), name="console_agent_stop"),
    path("console/api/agents/<uuid:agent_id>/daily-credits/", AgentDailyCreditsAPIView.as_view(), name="console_agent_daily_credits"),
    path("console/api/agents/<uuid:agent_id>/email-settings/", AgentEmailSettingsAPIView.as_view(), name="console_agent_email_settings"),
    path(
        "console/api/agents/<uuid:agent_id>/email-settings/ensure-account/",
        AgentEmailSettingsEnsureAccountAPIView.as_view(),
        name="console_agent_email_settings_ensure_account",
    ),
    path(
        "console/api/agents/<uuid:agent_id>/email-settings/test/",
        AgentEmailSettingsTestAPIView.as_view(),
        name="console_agent_email_settings_test",
    ),
    path("console/api/agents/<uuid:agent_id>/addons/", AgentAddonsAPIView.as_view(), name="console_agent_addons"),
    path("console/api/agents/<uuid:agent_id>/quick-settings/", AgentQuickSettingsAPIView.as_view(), name="console_agent_quick_settings"),
    path("console/api/agents/<uuid:agent_id>/settings/", AgentSettingsAPIView.as_view(), name="console_agent_settings"),
    path("console/api/agents/<uuid:agent_id>/insights/", AgentInsightsAPIView.as_view(), name="console_agent_insights"),
    path("console/api/agents/<uuid:agent_id>/sms/enable/", AgentSmsEnableAPIView.as_view(), name="console_agent_sms_enable"),
    path("console/api/agents/<uuid:agent_id>/reassign/", AgentReassignAPIView.as_view(), name="console_agent_reassign"),
    path("console/api/agents/<uuid:agent_id>/templates/clone/", AgentTemplateCloneAPIView.as_view(), name="console_agent_template_clone"),
    path("console/api/user/preferences/", UserPreferencesAPIView.as_view(), name="console_user_preferences"),
    path("console/api/user/profile/", UserProfileAPIView.as_view(), name="console_user_profile"),
    path("console/api/user/phone/", UserPhoneAPIView.as_view(), name="console_user_phone"),
    path("console/api/user/phone/verify/", UserPhoneVerifyAPIView.as_view(), name="console_user_phone_verify"),
    path("console/api/user/phone/resend/", UserPhoneResendAPIView.as_view(), name="console_user_phone_resend"),
    path("console/api/user/email/resend-verification/", UserEmailResendVerificationAPIView.as_view(), name="console_user_email_resend_verification"),
    path("console/api/staff/agents/search/", StaffAgentSearchAPIView.as_view(), name="console_agent_search"),
    path("console/api/staff/users/search/", StaffUserSearchAPIView.as_view(), name="staff-user-search"),
    path("console/api/staff/agents/<uuid:agent_id>/audit/", StaffAgentAuditAPIView.as_view(), name="console_agent_audit"),
    path("console/api/staff/agents/<uuid:agent_id>/audit/export/", StaffAgentAuditExportAPIView.as_view(), name="console_agent_audit_export"),
    path("console/api/staff/agents/<uuid:agent_id>/audit/timeline/", StaffAgentAuditTimelineAPIView.as_view(), name="console_agent_audit_timeline"),
    path("console/api/staff/agents/<uuid:agent_id>/audit/day/", StaffAgentAuditDayDebugAPIView.as_view(), name="console_agent_audit_day_debug"),
    path("console/api/staff/agents/<uuid:agent_id>/audit/process/", StaffAgentProcessEventsAPIView.as_view(), name="console_agent_audit_process"),
    path("console/api/staff/agents/<uuid:agent_id>/audit/judge/", StaffAgentRunJudgeAPIView.as_view(), name="console_agent_audit_judge"),
    path(
        "console/api/staff/agents/<uuid:agent_id>/audit/judge-suggestions/<uuid:suggestion_id>/decision/",
        StaffAgentJudgeSuggestionDecisionAPIView.as_view(),
        name="console_agent_audit_judge_suggestion_decision",
    ),
    path("console/api/staff/agents/<uuid:agent_id>/system-messages/", StaffAgentSystemMessageAPIView.as_view(), name="console_agent_system_message"),
    path("console/api/staff/agents/<uuid:agent_id>/system-messages/<uuid:message_id>/", StaffAgentSystemMessageDetailAPIView.as_view(), name="console_agent_system_message_detail"),
    path("console/api/staff/prompt-archives/<uuid:archive_id>/", StaffPromptArchiveAPIView.as_view(), name="console_prompt_archive_fetch"),
    path(
        "console/api/agents/<uuid:id>/",
        ConsolePersistentAgentViewSet.as_view({'get': 'retrieve', 'patch': 'partial_update'}),
        name="console_agent_detail",
    ),
    path("system-settings/api/", SystemSettingsListAPIView.as_view(), name="system_settings_list"),
    path("system-settings/api/<slug:key>/", SystemSettingDetailAPIView.as_view(), name="system_setting_detail"),
    path("console/api/status/", SystemStatusAPIView.as_view(), name="console-api-status"),
    path("console/api/staff/users/<int:user_id>/", StaffUserDetailAPIView.as_view(), name="staff-user-detail-api"),
    path("console/api/staff/users/<int:user_id>/email/verify/", StaffUserEmailVerifyAPIView.as_view(), name="staff-user-email-verify"),
    path("console/api/staff/users/<int:user_id>/user-emails/<int:user_email_id>/send/", StaffUserEmailTriggerAPIView.as_view(), name="staff-user-email-trigger-send"),
    path("console/api/staff/users/<int:user_id>/task-credits/", StaffUserTaskCreditGrantAPIView.as_view(), name="staff-user-task-credit-grant"),
    path("console/api/llm/overview/", ConsoleLLMOverviewAPIView.as_view(), name="console_llm_overview"),
    path("console/api/llm/providers/", LLMProviderListCreateAPIView.as_view(), name="console_llm_providers"),
    path("console/api/llm/providers/<uuid:provider_id>/", LLMProviderDetailAPIView.as_view(), name="console_llm_provider_detail"),
    path("console/api/llm/test-endpoint/", LLMEndpointTestAPIView.as_view(), name="console_llm_test_endpoint"),
    path("console/api/llm/performance-test/", LLMPerformanceTestAPIView.as_view(), name="console_llm_performance_test"),
    path("console/api/llm/persistent/endpoints/", PersistentEndpointListCreateAPIView.as_view(), name="console_llm_persistent_endpoints"),
    path("console/api/llm/persistent/endpoints/<uuid:endpoint_id>/", PersistentEndpointDetailAPIView.as_view(), name="console_llm_persistent_endpoint_detail"),
    path("console/api/llm/persistent/ranges/", PersistentTokenRangeListCreateAPIView.as_view(), name="console_llm_ranges"),
    path("console/api/llm/persistent/ranges/<uuid:range_id>/", PersistentTokenRangeDetailAPIView.as_view(), name="console_llm_range_detail"),
    path("console/api/llm/persistent/ranges/<uuid:range_id>/tiers/", PersistentTierListCreateAPIView.as_view(), name="console_llm_range_tiers"),
    path("console/api/llm/persistent/tiers/<uuid:tier_id>/", PersistentTierDetailAPIView.as_view(), name="console_llm_tier_detail"),
    path("console/api/llm/persistent/tiers/<uuid:tier_id>/endpoints/", PersistentTierEndpointListCreateAPIView.as_view(), name="console_llm_tier_endpoints"),
    path("console/api/llm/persistent/tier-endpoints/<uuid:tier_endpoint_id>/", PersistentTierEndpointDetailAPIView.as_view(), name="console_llm_tier_endpoint_detail"),
    path("console/api/llm/browser/endpoints/", BrowserEndpointListCreateAPIView.as_view(), name="console_llm_browser_endpoints"),
    path("console/api/llm/browser/endpoints/<uuid:endpoint_id>/", BrowserEndpointDetailAPIView.as_view(), name="console_llm_browser_endpoint_detail"),
    path("console/api/llm/browser/tiers/", BrowserTierListCreateAPIView.as_view(), name="console_llm_browser_tiers"),
    path("console/api/llm/browser/tiers/<uuid:tier_id>/", BrowserTierDetailAPIView.as_view(), name="console_llm_browser_tier_detail"),
    path("console/api/llm/browser/tiers/<uuid:tier_id>/endpoints/", BrowserTierEndpointListCreateAPIView.as_view(), name="console_llm_browser_tier_endpoints"),
    path("console/api/llm/browser/tier-endpoints/<uuid:tier_endpoint_id>/", BrowserTierEndpointDetailAPIView.as_view(), name="console_llm_browser_tier_endpoint_detail"),
    path("console/api/llm/embeddings/endpoints/", EmbeddingEndpointListCreateAPIView.as_view(), name="console_llm_embedding_endpoints"),
    path("console/api/llm/embeddings/endpoints/<uuid:endpoint_id>/", EmbeddingEndpointDetailAPIView.as_view(), name="console_llm_embedding_endpoint_detail"),
    path("console/api/llm/embeddings/tiers/", EmbeddingTierListCreateAPIView.as_view(), name="console_llm_embedding_tiers"),
    path("console/api/llm/embeddings/tiers/<uuid:tier_id>/", EmbeddingTierDetailAPIView.as_view(), name="console_llm_embedding_tier_detail"),
    path("console/api/llm/embeddings/tiers/<uuid:tier_id>/endpoints/", EmbeddingTierEndpointListCreateAPIView.as_view(), name="console_llm_embedding_tier_endpoints"),
    path("console/api/llm/embeddings/tier-endpoints/<uuid:tier_endpoint_id>/", EmbeddingTierEndpointDetailAPIView.as_view(), name="console_llm_embedding_tier_endpoint_detail"),
    path("console/api/llm/file-handlers/endpoints/", FileHandlerEndpointListCreateAPIView.as_view(), name="console_llm_file_handler_endpoints"),
    path("console/api/llm/file-handlers/endpoints/<uuid:endpoint_id>/", FileHandlerEndpointDetailAPIView.as_view(), name="console_llm_file_handler_endpoint_detail"),
    path("console/api/llm/file-handlers/tiers/", FileHandlerTierListCreateAPIView.as_view(), name="console_llm_file_handler_tiers"),
    path("console/api/llm/file-handlers/tiers/<uuid:tier_id>/", FileHandlerTierDetailAPIView.as_view(), name="console_llm_file_handler_tier_detail"),
    path("console/api/llm/file-handlers/tiers/<uuid:tier_id>/endpoints/", FileHandlerTierEndpointListCreateAPIView.as_view(), name="console_llm_file_handler_tier_endpoints"),
    path("console/api/llm/file-handlers/tier-endpoints/<uuid:tier_endpoint_id>/", FileHandlerTierEndpointDetailAPIView.as_view(), name="console_llm_file_handler_tier_endpoint_detail"),
    path("console/api/llm/image-generations/endpoints/", ImageGenerationEndpointListCreateAPIView.as_view(), name="console_llm_image_generation_endpoints"),
    path("console/api/llm/image-generations/endpoints/<uuid:endpoint_id>/", ImageGenerationEndpointDetailAPIView.as_view(), name="console_llm_image_generation_endpoint_detail"),
    path("console/api/llm/image-generations/tiers/", ImageGenerationTierListCreateAPIView.as_view(), name="console_llm_image_generation_tiers"),
    path("console/api/llm/image-generations/tiers/<uuid:tier_id>/", ImageGenerationTierDetailAPIView.as_view(), name="console_llm_image_generation_tier_detail"),
    path("console/api/llm/image-generations/tiers/<uuid:tier_id>/endpoints/", ImageGenerationTierEndpointListCreateAPIView.as_view(), name="console_llm_image_generation_tier_endpoints"),
    path("console/api/llm/image-generations/tier-endpoints/<uuid:tier_endpoint_id>/", ImageGenerationTierEndpointDetailAPIView.as_view(), name="console_llm_image_generation_tier_endpoint_detail"),
    # Video Generation
    path("console/api/llm/video-generations/endpoints/", VideoGenerationEndpointListCreateAPIView.as_view(), name="console_llm_video_generation_endpoints"),
    path("console/api/llm/video-generations/endpoints/<uuid:endpoint_id>/", VideoGenerationEndpointDetailAPIView.as_view(), name="console_llm_video_generation_endpoint_detail"),
    path("console/api/llm/video-generations/tiers/", VideoGenerationTierListCreateAPIView.as_view(), name="console_llm_video_generation_tiers"),
    path("console/api/llm/video-generations/tiers/<uuid:tier_id>/", VideoGenerationTierDetailAPIView.as_view(), name="console_llm_video_generation_tier_detail"),
    path("console/api/llm/video-generations/tiers/<uuid:tier_id>/endpoints/", VideoGenerationTierEndpointListCreateAPIView.as_view(), name="console_llm_video_generation_tier_endpoints"),
    path("console/api/llm/video-generations/tier-endpoints/<uuid:tier_endpoint_id>/", VideoGenerationTierEndpointDetailAPIView.as_view(), name="console_llm_video_generation_tier_endpoint_detail"),
    # LLM Routing Profiles
    path("console/api/llm/routing-profiles/", LLMRoutingProfileListCreateAPIView.as_view(), name="console_llm_routing_profiles"),
    path("console/api/llm/routing-profiles/<uuid:profile_id>/", LLMRoutingProfileDetailAPIView.as_view(), name="console_llm_routing_profile_detail"),
    path("console/api/llm/routing-profiles/<uuid:profile_id>/activate/", LLMRoutingProfileActivateAPIView.as_view(), name="console_llm_routing_profile_activate"),
    path("console/api/llm/routing-profiles/<uuid:profile_id>/clone/", LLMRoutingProfileCloneAPIView.as_view(), name="console_llm_routing_profile_clone"),
    # Profile persistent config
    path("console/api/llm/routing-profiles/<uuid:profile_id>/token-ranges/", ProfileTokenRangeListCreateAPIView.as_view(), name="console_llm_profile_token_ranges"),
    path("console/api/llm/routing-profiles/token-ranges/<uuid:range_id>/", ProfileTokenRangeDetailAPIView.as_view(), name="console_llm_profile_token_range_detail"),
    path("console/api/llm/routing-profiles/token-ranges/<uuid:range_id>/tiers/", ProfilePersistentTierListCreateAPIView.as_view(), name="console_llm_profile_persistent_tiers"),
    path("console/api/llm/routing-profiles/persistent-tiers/<uuid:tier_id>/", ProfilePersistentTierDetailAPIView.as_view(), name="console_llm_profile_persistent_tier_detail"),
    path("console/api/llm/routing-profiles/persistent-tiers/<uuid:tier_id>/endpoints/", ProfilePersistentTierEndpointListCreateAPIView.as_view(), name="console_llm_profile_persistent_tier_endpoints"),
    path("console/api/llm/routing-profiles/persistent-tier-endpoints/<uuid:tier_endpoint_id>/", ProfilePersistentTierEndpointDetailAPIView.as_view(), name="console_llm_profile_persistent_tier_endpoint_detail"),
    # Profile browser config
    path("console/api/llm/routing-profiles/<uuid:profile_id>/browser-tiers/", ProfileBrowserTierListCreateAPIView.as_view(), name="console_llm_profile_browser_tiers"),
    path("console/api/llm/routing-profiles/browser-tiers/<uuid:tier_id>/", ProfileBrowserTierDetailAPIView.as_view(), name="console_llm_profile_browser_tier_detail"),
    path("console/api/llm/routing-profiles/browser-tiers/<uuid:tier_id>/endpoints/", ProfileBrowserTierEndpointListCreateAPIView.as_view(), name="console_llm_profile_browser_tier_endpoints"),
    path("console/api/llm/routing-profiles/browser-tier-endpoints/<uuid:tier_endpoint_id>/", ProfileBrowserTierEndpointDetailAPIView.as_view(), name="console_llm_profile_browser_tier_endpoint_detail"),
    # Profile embeddings config
    path("console/api/llm/routing-profiles/<uuid:profile_id>/embeddings-tiers/", ProfileEmbeddingsTierListCreateAPIView.as_view(), name="console_llm_profile_embeddings_tiers"),
    path("console/api/llm/routing-profiles/embeddings-tiers/<uuid:tier_id>/", ProfileEmbeddingsTierDetailAPIView.as_view(), name="console_llm_profile_embeddings_tier_detail"),
    path("console/api/llm/routing-profiles/embeddings-tiers/<uuid:tier_id>/endpoints/", ProfileEmbeddingsTierEndpointListCreateAPIView.as_view(), name="console_llm_profile_embeddings_tier_endpoints"),
    path("console/api/llm/routing-profiles/embeddings-tier-endpoints/<uuid:tier_endpoint_id>/", ProfileEmbeddingsTierEndpointDetailAPIView.as_view(), name="console_llm_profile_embeddings_tier_endpoint_detail"),
    path("console/api/agents/<uuid:agent_id>/web-sessions/start/", AgentWebSessionStartAPIView.as_view(), name="console_agent_web_session_start"),
    path("console/api/agents/<uuid:agent_id>/web-sessions/heartbeat/", AgentWebSessionHeartbeatAPIView.as_view(), name="console_agent_web_session_heartbeat"),
    path("console/api/agents/<uuid:agent_id>/web-sessions/end/", AgentWebSessionEndAPIView.as_view(), name="console_agent_web_session_end"),
    path("console/api/agents/<uuid:agent_id>/pipedream/apps/", AgentPipedreamAppsAPIView.as_view(), name="console-agent-pipedream-apps"),
    path("console/api/agents/<uuid:agent_id>/pipedream/apps/<slug:app_slug>/", AgentPipedreamAppAPIView.as_view(), name="console-agent-pipedream-app"),
    path("console/api/agents/<uuid:agent_id>/pipedream/apps/<slug:app_slug>/connect/", AgentPipedreamAppConnectAPIView.as_view(), name="console-agent-pipedream-app-connect"),
    path("console/api/agents/<uuid:agent_id>/pipedream/apps/<slug:app_slug>/connection/", AgentPipedreamAppConnectionAPIView.as_view(), name="console-agent-pipedream-app-connection"),
    path("console/api/session/", ConsoleSessionAPIView.as_view(), name="console_session"),
    path("console/api/billing/initial/", BillingInitialDataAPIView.as_view(), name="console_billing_initial_data"),
    path("console/api/usage/summary/", UsageSummaryAPIView.as_view(), name="console_usage_summary"),
    path("console/api/usage/burn-rate/", UsageBurnRateSnapshotAPIView.as_view(), name="console_usage_burn_rate"),
    path("console/api/usage/trends/", UsageTrendAPIView.as_view(), name="console_usage_trends"),
    path("console/api/usage/tools/", UsageToolBreakdownAPIView.as_view(), name="console_usage_tools"),
    path("console/api/usage/agents/leaderboard/", UsageAgentLeaderboardAPIView.as_view(), name="console_usage_agents_leaderboard"),
    path("console/api/evals/suites/", EvalSuiteListAPIView.as_view(), name="console_evals_suites"),
    path("console/api/evals/global-skill-launcher/", GlobalSkillEvalLauncherAPIView.as_view(), name="console_evals_global_skill_launcher"),
    path("console/api/evals/global-skill-runs/create/", GlobalSkillEvalRunCreateAPIView.as_view(), name="console_evals_global_skill_runs_create"),
    path("console/api/evals/suite-runs/", EvalSuiteRunListAPIView.as_view(), name="console_evals_suite_runs"),
    path("console/api/evals/suite-runs/create/", EvalSuiteRunCreateAPIView.as_view(), name="console_evals_suite_runs_create"),
    path("console/api/evals/suite-runs/<uuid:suite_run_id>/", EvalSuiteRunDetailAPIView.as_view(), name="console_evals_suite_run_detail"),
    path("console/api/evals/suite-runs/<uuid:suite_run_id>/run-type/", EvalSuiteRunRunTypeAPIView.as_view(), name="console_evals_suite_run_run_type"),
    path("console/api/evals/suite-runs/<uuid:suite_run_id>/compare/", EvalSuiteRunCompareAPIView.as_view(), name="console_evals_suite_run_compare"),
    path("console/api/evals/runs/<uuid:run_id>/", EvalRunDetailAPIView.as_view(), name="console_evals_run_detail"),
    path("console/api/evals/runs/<uuid:run_id>/compare/", EvalRunCompareAPIView.as_view(), name="console_evals_run_compare"),
    path("console/api/mcp/servers/", MCPServerListAPIView.as_view(), name="console-mcp-server-list"),
    path("console/api/mcp/servers/<uuid:server_id>/", MCPServerDetailAPIView.as_view(), name="console-mcp-server-detail"),
    path("console/api/mcp/servers/<uuid:server_id>/test/", MCPServerTestAPIView.as_view(), name="console-mcp-server-test"),
    path("console/api/mcp/servers/<uuid:server_id>/assignments/", MCPServerAssignmentsAPIView.as_view(), name="console-mcp-server-assignments"),
    path("console/api/staff/mcp/servers/", PlatformMCPServerListAPIView.as_view(), name="staff-platform-mcp-server-list"),
    path("console/api/staff/mcp/servers/<uuid:server_id>/", PlatformMCPServerDetailAPIView.as_view(), name="staff-platform-mcp-server-detail"),
    path("console/api/staff/mcp/servers/<uuid:server_id>/test/", PlatformMCPServerTestAPIView.as_view(), name="staff-platform-mcp-server-test"),
    path("console/api/mcp/pipedream/apps/", PipedreamAppsAPIView.as_view(), name="console-pipedream-apps"),
    path("console/api/mcp/pipedream/apps/<slug:app_slug>/agents/", PipedreamAppAgentConnectionsAPIView.as_view(), name="console-pipedream-app-agent-connections"),
    path("console/api/mcp/pipedream/apps/search/", PipedreamAppSearchAPIView.as_view(), name="console-pipedream-app-search"),
    path("console/api/mcp/oauth/start/", MCPOAuthStartView.as_view(), name="console-mcp-oauth-start"),
    path("console/api/mcp/oauth/metadata/", MCPOAuthMetadataProxyView.as_view(), name="console-mcp-oauth-metadata"),
    path("console/api/mcp/oauth/session/<uuid:session_id>/verifier/", MCPOAuthSessionVerifierView.as_view(), name="console-mcp-oauth-session-verifier"),
    path("console/api/mcp/oauth/callback/", MCPOAuthCallbackView.as_view(), name="console-mcp-oauth-callback"),
    path("console/api/mcp/oauth/status/<uuid:server_config_id>/", MCPOAuthStatusView.as_view(), name="console-mcp-oauth-status"),
    path("console/api/mcp/oauth/revoke/<uuid:server_config_id>/", MCPOAuthRevokeView.as_view(), name="console-mcp-oauth-revoke"),
    path("console/api/email/oauth/start/", AgentEmailOAuthStartView.as_view(), name="console-email-oauth-start"),
    path("console/api/email/oauth/session/<uuid:session_id>/verifier/", AgentEmailOAuthSessionVerifierView.as_view(), name="console-email-oauth-session-verifier"),
    path("console/api/email/oauth/callback/", AgentEmailOAuthCallbackView.as_view(), name="console-email-oauth-callback"),
    path("console/api/email/oauth/status/<uuid:account_id>/", AgentEmailOAuthStatusView.as_view(), name="console-email-oauth-status"),
    path("console/api/email/oauth/revoke/<uuid:account_id>/", AgentEmailOAuthRevokeView.as_view(), name="console-email-oauth-revoke"),
    # Global + agent secrets API
    path("console/api/secrets/", GlobalSecretListAPIView.as_view(), name="console-global-secret-list"),
    path("console/api/secrets/<uuid:secret_id>/", GlobalSecretDetailAPIView.as_view(), name="console-global-secret-detail"),
    path(
        "console/api/system-skills/<slug:skill_key>/profiles/",
        SystemSkillProfileListAPIView.as_view(),
        name="console-system-skill-profile-list",
    ),
    path(
        "console/api/system-skills/<slug:skill_key>/profiles/<uuid:profile_id>/",
        SystemSkillProfileDetailAPIView.as_view(),
        name="console-system-skill-profile-detail",
    ),
    path(
        "console/api/system-skills/<slug:skill_key>/profiles/<uuid:profile_id>/default/",
        SystemSkillProfileSetDefaultAPIView.as_view(),
        name="console-system-skill-profile-set-default",
    ),
    path("console/api/agents/<uuid:agent_id>/secrets/", AgentSecretListAPIView.as_view(), name="console-agent-secret-list"),
    path("console/api/agents/<uuid:agent_id>/secrets/<uuid:secret_id>/", AgentSecretDetailAPIView.as_view(), name="console-agent-secret-detail"),
    path("console/api/agents/<uuid:agent_id>/secrets/<uuid:secret_id>/promote/", AgentSecretPromoteAPIView.as_view(), name="console-agent-secret-promote"),
    path("console/api/usage/agents/", UsageAgentsAPIView.as_view(), name="console_usage_agents"),
    path("console/agents/create/contact/", AgentCreateContactView.as_view(), name="agent_create_contact"),
    path("console/agents/create/quick/", AgentQuickSpawnView.as_view(), name="agent_quick_spawn"),
    path("console/agents/<uuid:pk>/", AgentDetailView.as_view(), name="agent_detail"),
    path(
        "console/agents/<uuid:pk>/daily-limit/<str:action>/",
        AgentDailyLimitEmailActionView.as_view(),
        name="agent_daily_limit_action",
    ),
    path("console/agents/<uuid:pk>/welcome/", AgentWelcomeView.as_view(), name="agent_welcome"),
    path("console/agents/<uuid:pk>/enable-sms/", AgentEnableSmsView.as_view(), name="agent_enable_sms"),
    path("console/agents/<uuid:pk>/delete/", AgentDeleteView.as_view(), name="agent_delete"),
    path("console/agents/<uuid:pk>/email/", AgentEmailSettingsView.as_view(), name="agent_email_settings"),
    path("console/agents/<uuid:pk>/files/", AgentFilesView.as_view(), name="agent_files"),
    # Agent secrets management
    path("console/agents/<uuid:pk>/secrets/", AgentSecretsView.as_view(), name="agent_secrets"),
    path("console/agents/<uuid:pk>/secrets/add/", AgentSecretsAddView.as_view(), name="agent_secrets_add"),
    path("console/agents/<uuid:pk>/secrets/add/form/", AgentSecretsAddFormView.as_view(), name="agent_secrets_add_form"),
    path("console/agents/<uuid:pk>/secrets/edit/<uuid:secret_id>/", AgentSecretsEditView.as_view(), name="agent_secrets_edit"),
    path("console/agents/<uuid:pk>/secrets/delete/<uuid:secret_id>/", AgentSecretsDeleteView.as_view(), name="agent_secrets_delete"),
    path("console/agents/<uuid:pk>/secrets/request/", AgentSecretsRequestView.as_view(), name="agent_secrets_request"),
    path("console/agents/<uuid:pk>/secrets/request/thanks/", AgentSecretsRequestThanksView.as_view(), name="agent_secrets_request_thanks"),
    path("console/agents/<uuid:pk>/secrets/request/remove/", AgentSecretsRequestView.as_view(), name="agent_requested_secrets_remove"),
    path("console/agents/<uuid:pk>/secrets/request/remove/<uuid:secret_id>/", AgentSecretsRequestView.as_view(), name="agent_requested_secret_remove"),
    path("console/agents/<uuid:pk>/secrets/rerequest/<uuid:secret_id>/", AgentSecretRerequestView.as_view(), name="agent_secret_rerequest"),
    path("console/agents/<uuid:pk>/contact-requests/", AgentContactRequestsView.as_view(), name="agent_contact_requests"),
    path("console/agents/<uuid:pk>/contact-requests/thanks/", AgentContactRequestsThanksView.as_view(), name="agent_contact_requests_thanks"),
    path("console/agents/<uuid:pk>/allowlist/", AgentAllowlistView.as_view(), name="agent_allowlist"),
    path("console/agent-transfer-invites/<uuid:invite_id>/<str:action>/", AgentTransferInviteRespondView.as_view(), name="console-agent-transfer-invite"),
    path("console/agent-allowlist-invite/<str:token>/accept/", AgentAllowlistInviteAcceptView.as_view(), name="agent_allowlist_invite_accept"),
    path("console/agent-allowlist-invite/<str:token>/reject/", AgentAllowlistInviteRejectView.as_view(), name="agent_allowlist_invite_reject"),
    path("console/agent-collaborator-invite/<str:token>/accept/", AgentCollaboratorInviteAcceptView.as_view(), name="agent_collaborator_invite_accept"),
    path("console/agent-collaborator-invite/<str:token>/reject/", AgentCollaboratorInviteRejectView.as_view(), name="agent_collaborator_invite_reject"),

    path("console/organizations/", OrganizationListView.as_view(), name="organizations"),
    path("console/organizations/add/", OrganizationCreateView.as_view(), name="organization_add"),
    path("console/organizations/<uuid:org_id>/", OrganizationDetailView.as_view(), name="organization_detail"),
    path(
        "console/organizations/<uuid:org_id>/invite-modal/",
        OrganizationInviteModalView.as_view(),
        name="org_invite_modal",
    ),
    path("console/organizations/invites/<str:token>/accept/", OrganizationInviteAcceptView.as_view(), name="org_invite_accept"),
    path("console/organizations/invites/<str:token>/reject/", OrganizationInviteRejectView.as_view(), name="org_invite_reject"),
    path("console/organizations/<uuid:org_id>/invites/<str:token>/revoke/", OrganizationInviteRevokeOrgView.as_view(), name="org_invite_revoke_org"),
    path("console/organizations/<uuid:org_id>/invites/<str:token>/resend/", OrganizationInviteResendOrgView.as_view(), name="org_invite_resend_org"),
    path("console/organizations/<uuid:org_id>/members/<int:user_id>/remove/", OrganizationMemberRemoveOrgView.as_view(), name="org_member_remove_org"),
    path("console/organizations/<uuid:org_id>/members/<int:user_id>/role/", OrganizationMemberRoleUpdateOrgView.as_view(), name="org_member_role_update_org"),
    path("console/organizations/<uuid:org_id>/leave/", OrganizationLeaveOrgView.as_view(), name="org_leave_org"),
    path("console/organizations/<uuid:org_id>/seats/checkout/", OrganizationSeatCheckoutView.as_view(), name="organization_seat_checkout"),
    path("console/organizations/<uuid:org_id>/seats/schedule/", OrganizationSeatScheduleView.as_view(), name="organization_seat_schedule"),
    path("console/organizations/<uuid:org_id>/seats/schedule/cancel/", OrganizationSeatScheduleCancelView.as_view(), name="organization_seat_schedule_cancel"),
    path("console/organizations/<uuid:org_id>/seats/portal/", OrganizationSeatPortalView.as_view(), name="organization_seat_portal"),

    # Task management views
    path("console/tasks/", tasks_view, name="tasks"),
    # Add these to your urlpatterns in urls.py
    path("console/tasks/<uuid:task_id>/", task_detail_view, name="task_detail"),
    path("console/tasks/<uuid:task_id>/cancel/", task_cancel_view, name="task_cancel"),
    path("console/tasks/<uuid:task_id>/result/", task_result_view, name="task_result"),

    # Admin actions
    path("console/grant-credits/", grant_credits, name="grant_credits"),

    path('billing/settings/update/', update_billing_settings, name='update_billing_settings'),
    path('billing/settings/cancel-subscription/', cancel_subscription, name='cancel_subscription'),
    path('billing/settings/sync-subscription-state/', sync_billing_subscription_state, name='sync_billing_subscription_state'),
    path('billing/settings/resume-subscription/', resume_subscription, name='resume_subscription'),
    path('billing/addons/task-packs/', update_task_pack_quantity, name='update_task_pack_quantity'),
    path('billing/addons/contact-packs/', update_contact_pack_quantity, name='update_contact_pack_quantity'),
    path('billing/addons/', update_addons, name='update_addons'),
    path('billing/dedicated-ip/add/', add_dedicated_ip_quantity, name='add_dedicated_ip_quantity'),
    path('billing/dedicated-ip/remove/', remove_dedicated_ip, name='remove_dedicated_ip'),
    path('billing/dedicated-ip/remove-all/', remove_all_dedicated_ip, name='remove_all_dedicated_ip'),

    path('api/v1/user/billing-settings/', get_billing_settings, name='get_billing_settings'),
    path('api/v1/user/plan/', get_user_plan_api, name='get_user_plan'),

    # admin & auth
    path("admin/", admin.site.urls),
    path(
        "accounts/password/reset/link/confirm/",
        PasswordResetBridgeConfirmView.as_view(),
        name="account_reset_password_bridge_confirm",
    ),
    path(
        "accounts/password/reset/link/continue/",
        PasswordResetBridgeContinueView.as_view(),
        name="account_reset_password_bridge_continue",
    ),
    path(
        "accounts/password/reset/link/<str:key>/",
        PasswordResetBridgeStartView.as_view(),
        name="account_reset_password_bridge_start",
    ),
    path(
        "accounts/modal/signup/",
        AccountSignupModalView.as_view(),
        name="account_signup_modal",
    ),
    path(
        "accounts/modal/login/",
        AccountLoginModalView.as_view(),
        name="account_login_modal",
    ),
    path(
        "accounts/popup-complete/",
        AccountAuthPopupCompleteView.as_view(),
        name="account_auth_popup_complete",
    ),
    path("accounts/", include("allauth.urls")),

    # API docs
    path("api/schema/", SpectacularAPIView.as_view(), name="schema"),
    path("api/schema/swagger-ui/", schema_swagger_view, name="schema-swagger-ui"),
    path("api/schema/redoc/", schema_redoc_view, name="schema-redoc"),
    
    # Legacy API docs URL (keeping for backward compatibility)
    path("api/docs/", schema_swagger_view, name="api_docs"),

    # Evals & Simulations
    path("eval/", include("api.evals.urls", namespace="evals")),

    # API
    path("api/v1/", include("api.urls")),

    # Stripe integration
    path("stripe/", include("djstripe.urls", namespace="djstripe")),

    # Pages app includes homepage, health check, and documentation
    path("", include("pages.urls")),
]

# Proprietary routes (views enforce the feature flag but namespace is always available)
urlpatterns.insert(1, path("", include(("proprietary.urls", "proprietary"), namespace="proprietary")))

# Serve static files in development
if settings.DEBUG:
    urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
    urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
