Files
林玮 (Jade Lin) 453439ab82 Merge remote-tracking branch 'origin/main' into linw/snp-911-end-user-auth
# Conflicts:
#	api/core/app/apps/advanced_chat/app_generator.py
#	api/core/app/apps/workflow/app_generator.py
#	api/core/app/task_pipeline/based_generate_task_pipeline.py
#	api/extensions/ext_application_services.py
#	api/openapi/markdown/console-openapi.md
#	api/openapi/markdown/web-openapi.md
#	api/repositories/conversation_lifecycle.py
#	api/services/conversation_service.py
#	api/services/workflow/node_defaults.py
#	packages/contracts/generated/api/console/apps/errors.gen.ts
#	packages/contracts/generated/api/console/errors.gen.ts
#	packages/contracts/generated/api/console/workspaces/errors.gen.ts
#	packages/contracts/generated/api/console/workspaces/orpc.gen.ts
#	packages/contracts/generated/api/web/types.gen.ts
#	packages/contracts/generated/api/web/zod.gen.ts
2026-11-18 15:03:10 +08:00

179 lines
4.0 KiB
Python

from types import ModuleType
from flask import Blueprint
from flask_restx import Namespace
from controllers.common.app_access_error import register_app_access_error_metadata
from controllers.common.errors import (
InternalServerError,
NotFoundError,
UnauthorizedError,
register_moderation_error_handlers,
)
from controllers.console.error import NotInitValidateError, NotSetupError
from controllers.web.error import (
WebAppAccessServiceUnavailableError,
WebAppAuthAccessDeniedError,
WebAppAuthRequiredError,
WebAppNotFoundError,
)
from libs.external_api import ExternalApi
bp = Blueprint("web", __name__, url_prefix="/api")
register_app_access_error_metadata(bp, surface="web")
api = ExternalApi(
bp,
version="1.0",
title="Web API",
description="Public APIs for web applications including file uploads, chat interactions, and app management",
)
register_moderation_error_handlers(api)
# The passport guard on every Web API resource raises these; the web client answers them
# centrally (sign-in redirect, access-denied and not-found pages), so no operation lists them.
# ``not_found``, ``unauthorized`` and ``internal_server_error`` are the codes Werkzeug's own
# exceptions already produce on every operation.
api.document_generic_errors(
NotSetupError,
NotInitValidateError,
WebAppNotFoundError,
WebAppAuthRequiredError,
WebAppAuthAccessDeniedError,
WebAppAccessServiceUnavailableError,
NotFoundError,
UnauthorizedError,
InternalServerError,
)
# Create namespace
web_ns = Namespace("web", description="Web application API operations", path="/")
def _register_controllers() -> tuple[ModuleType, ...]:
"""Load route modules after their namespaces and schema models exist."""
from . import (
account,
account_email,
app,
audio,
completion,
connection_oauth,
connection_preflight,
connections,
conversation,
feature,
files,
forgot_password,
human_input_file_upload,
human_input_form,
human_input_form_access_request,
human_input_v2,
human_input_v2_file_upload,
login,
me,
message,
migration,
passport,
remote_files,
saved_message,
site,
workflow,
workflow_events,
)
return (
account,
account_email,
app,
audio,
completion,
connection_oauth,
connection_preflight,
connections,
conversation,
feature,
files,
forgot_password,
human_input_file_upload,
human_input_form,
human_input_form_access_request,
human_input_v2,
human_input_v2_file_upload,
login,
me,
message,
migration,
passport,
remote_files,
saved_message,
site,
workflow,
workflow_events,
)
(
account,
account_email,
app,
audio,
completion,
connection_oauth,
connection_preflight,
connections,
conversation,
feature,
files,
forgot_password,
human_input_file_upload,
human_input_form,
human_input_form_access_request,
human_input_v2,
human_input_v2_file_upload,
login,
me,
message,
migration,
passport,
remote_files,
saved_message,
site,
workflow,
workflow_events,
) = _register_controllers()
api.add_namespace(web_ns)
__all__ = [
"account",
"account_email",
"api",
"app",
"audio",
"bp",
"completion",
"connection_oauth",
"connection_preflight",
"connections",
"conversation",
"feature",
"files",
"forgot_password",
"human_input_file_upload",
"human_input_form",
"human_input_form_access_request",
"human_input_v2",
"human_input_v2_file_upload",
"login",
"me",
"message",
"passport",
"remote_files",
"saved_message",
"site",
"web_ns",
"workflow",
"workflow_events",
]