Files
dify/api/controllers/service_api/__init__.py
T
672a627fa5 ci: enable Ruff E402 (#44123)
Co-authored-by: Codex <codex@openai.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2026-10-19 01:16:16 +00:00

136 lines
2.8 KiB
Python

from types import ModuleType
from flask import Blueprint
from flask_restx import Namespace
from controllers.common.errors import (
InternalServerError,
InvalidArgumentError,
NotFoundError,
UnauthorizedError,
register_permission_error_handler,
)
from libs.external_api import ExternalApi
bp = Blueprint("service_api", __name__, url_prefix="/v1")
api = ExternalApi(
bp,
version="1.0",
title="Service API",
description="API for application services",
register_default_root=False,
)
register_permission_error_handler(api)
# ``invalid_param`` is what the surface's ValueError handler already emits on any operation;
# ``not_found``, ``unauthorized`` and ``internal_server_error`` are the codes Werkzeug's own
# exceptions already produce on every operation.
api.document_generic_errors(InvalidArgumentError, NotFoundError, UnauthorizedError, InternalServerError)
service_api_ns = Namespace("service_api", description="Service operations", path="/")
def _register_controllers() -> tuple[ModuleType, ...]:
"""Load route modules after their namespaces and schema models exist."""
from . import index
from .app import (
annotation,
app,
audio,
completion,
conversation,
file,
file_preview,
human_input_form,
message,
site,
workflow,
workflow_events,
)
from .dataset import (
dataset,
document,
hit_testing,
metadata,
segment,
)
from .dataset.rag_pipeline import rag_pipeline_workflow
from .end_user import end_user
from .workspace import models
return (
index,
annotation,
app,
audio,
completion,
conversation,
file,
file_preview,
human_input_form,
message,
site,
workflow,
workflow_events,
dataset,
document,
hit_testing,
metadata,
segment,
rag_pipeline_workflow,
end_user,
models,
)
(
index,
annotation,
app,
audio,
completion,
conversation,
file,
file_preview,
human_input_form,
message,
site,
workflow,
workflow_events,
dataset,
document,
hit_testing,
metadata,
segment,
rag_pipeline_workflow,
end_user,
models,
) = _register_controllers()
__all__ = [
"annotation",
"app",
"audio",
"completion",
"conversation",
"dataset",
"document",
"end_user",
"file",
"file_preview",
"hit_testing",
"human_input_form",
"index",
"message",
"metadata",
"models",
"rag_pipeline_workflow",
"segment",
"site",
"workflow",
"workflow_events",
]
api.add_namespace(service_api_ns)