Source code for smarter.apps.api.v1.urls

"""
URL configuration for Smarter API v1.

This module defines the ``urlpatterns`` for the ``/api/v1/`` entry point and
delegates route handling to app-specific URL modules.

**Routes**

- ``accounts/``: User account management endpoints.
- ``llmclients/``: LLMClient CRUD and related operations.
- ``openapi.json``: The api's OpenAPI 3.1 document (public), :mod:`smarter.apps.api.v1.contract.views`.
- ``cli/``: Brokered services for CLI workflows.
- ``demos/``: Fictional data for the platform's example resources, e.g. the Stackademy course catalogue.
- ``mcp/``: The MCPServer's two endpoints: its public tools, which read the project's documentation
  and code, and its staff-only tools, which read the platform's health, logs and users.
- ``journal/``: Smarter Journal entries (superusers only).
- ``connections/``: External connection integration endpoints.
- ``doodles/``: The sign-in page's doodle of the day, and its artwork (public).
- ``plugins/``: Plugin management endpoints.
- ``prompts/``: Prompt and interaction endpoints.
- ``providers/``: Provider integration endpoints.
- ``secrets/``: Secret management endpoints.
- ``tests/``: Test-only endpoints.
- ``vectorstores/``: Vector store endpoints.

The SAM resource apps' endpoints (connections, guardrails, llm-clients, plugins, secrets, ...) are
mounted only if the app's ``SMARTER_ENABLE_<APP>`` flag is true, which it is by default. See
:mod:`smarter.lib.manifest.sam_apps`.

Each included URL set uses a namespace to avoid naming collisions and to keep
API components logically separated.

.. seealso::

        `Django URL dispatcher documentation <https://docs.djangoproject.com/en/5.0/topics/http/urls/>`_
"""

from django.urls import include, path

from smarter.apps.account.api.v1 import urls as account_urls
from smarter.apps.account.const import namespace as account_namespace
from smarter.apps.api.v1.cli import urls as cli_urls
from smarter.apps.api.v1.contract.views import ApiV1OpenApiJsonView
from smarter.apps.api.v1.demos import urls as demos_urls
from smarter.apps.api.v1.tests import urls as tests_urls
from smarter.apps.connection.api.v1 import urls as connection_urls
from smarter.apps.connection.const import namespace as connnection_namespace
from smarter.apps.doodle.api.v1 import urls as doodle_urls
from smarter.apps.doodle.const import namespace as doodle_namespace
from smarter.apps.guardrail.api.v1 import urls as guardrail_urls
from smarter.apps.guardrail.const import namespace as guardrail_namespace
from smarter.apps.llmclient.api.v1 import urls as llmclient_urls
from smarter.apps.llmclient.const import namespace as llmclient_namespace
from smarter.apps.llmhost.api.v1 import urls as llmhost_urls
from smarter.apps.llmhost.const import namespace as llmhost_namespace
from smarter.apps.llmtool.api.v1 import urls as llmtool_urls
from smarter.apps.llmtool.const import namespace as llmtool_namespace
from smarter.apps.llmtool.extension.api.v1 import urls as extension_urls
from smarter.apps.llmtool.extension.urls import namespace as extension_namespace
from smarter.apps.mcpclient.api.v1 import urls as mcpclient_urls
from smarter.apps.mcpclient.const import namespace as mcpclient_namespace
from smarter.apps.mcpserver import urls as mcpserver_urls
from smarter.apps.mcpserver.const import namespace as mcpserver_namespace
from smarter.apps.orchestrator.api.v1 import urls as orchestrator_urls
from smarter.apps.orchestrator.const import namespace as orchestrator_namespace
from smarter.apps.prompt.api.v1 import urls as prompt_urls
from smarter.apps.prompt.const import namespace as prompt_namespace
from smarter.apps.provider.api.v1 import urls as provider_urls
from smarter.apps.provider.const import namespace as provider_namespace
from smarter.apps.proxy.api.v1 import urls as proxy_urls
from smarter.apps.proxy.const import namespace as proxy_namespace
from smarter.apps.secret.api.v1 import urls as secret_urls
from smarter.apps.secret.const import namespace as secret_namespace
from smarter.apps.vectorsearch.api.v1 import urls as vectorsearch_urls
from smarter.apps.vectorsearch.const import namespace as vectorsearch_namespace
from smarter.apps.vectorstore.api.v1 import urls as vectorstore_urls
from smarter.common.conf import smarter_settings
from smarter.common.utils import to_snake_case
from smarter.lib.journal.api.v1 import urls as journal_urls
from smarter.lib.journal.const import namespace as journal_namespace
from smarter.lib.manifest.sam_apps import SamAppUrls, sam_app_urlpatterns

from .cli.const import namespace as cli_namespace
from .const import namespace
from .demos.const import namespace as demos_namespace

app_name = namespace


[docs] class ApiV1ReverseNames: """ The names of the routes at the root of ``/api/v1/``. e.g. ``reverse(ApiV1ReverseNames.namespace, ApiV1ReverseNames.openapi_json)``. """ namespace = f"api:{namespace}" openapi_json = to_snake_case(ApiV1OpenApiJsonView.__name__)
# /api/v1/ is the main entry point for the API urlpatterns = [ # for LLMClients of the form https://example.3141-5926-5359.alpha.api.example.com # path("", include(llmclient_urls)), # ------------------------------------------- # the api's OpenAPI document # ------------------------------------------- path("openapi.json", ApiV1OpenApiJsonView.as_view(), name=ApiV1ReverseNames.openapi_json), # ------------------------------------------- # the main API # ------------------------------------------- path("accounts/", include(account_urls, namespace=account_namespace)), path("mcp/", include(mcpserver_urls, namespace=mcpserver_namespace)), path("cli/", include(cli_urls, namespace=cli_namespace)), path("demos/", include(demos_urls, namespace=demos_namespace)), path("doodles/", include(doodle_urls, namespace=doodle_namespace)), path("journal/", include(journal_urls, namespace=journal_namespace)), path("prompts/", include(prompt_urls, namespace=prompt_namespace)), path("tests/", include(tests_urls, namespace="tests")), ] SAM_APP_API_URLS: list[SamAppUrls] = [ SamAppUrls("app_connection_enable", "Connection", "connections/", connection_urls, connnection_namespace), SamAppUrls("app_guardrail_enable", "Guardrail", "guardrails/", guardrail_urls, guardrail_namespace), SamAppUrls("app_llmclient_enable", "LLMClient", "llm-clients/", llmclient_urls, llmclient_namespace), SamAppUrls("app_llmhost_enable", "LLMHost", "llmhosts/", llmhost_urls, llmhost_namespace), SamAppUrls("app_llmtool_enable", "LLMTool", "plugins/", llmtool_urls, llmtool_namespace), SamAppUrls("app_llmtool_enable", "Extension", "extensions/", extension_urls, extension_namespace), SamAppUrls("app_mcpclient_enable", "MCPClient", "mcpclients/", mcpclient_urls, mcpclient_namespace), SamAppUrls("app_orchestrator_enable", "Orchestrator", "orchestrators/", orchestrator_urls, orchestrator_namespace), SamAppUrls("app_provider_enable", "Provider", "providers/", provider_urls, provider_namespace), SamAppUrls("app_proxy_enable", "Proxy", "proxy/", proxy_urls, proxy_namespace), SamAppUrls("app_secret_enable", "Secret", "secrets/", secret_urls, secret_namespace), SamAppUrls("app_vectorsearch_enable", "VectorSearch", "vectorsearches/", vectorsearch_urls, vectorsearch_namespace), SamAppUrls("app_vectorstore_enable", "Vectorstore", "vectorstores/", vectorstore_urls, "vectorstore"), ] """ The REST api endpoints of the SAM resource apps. Each app's endpoints are mounted only if its ``smarter_settings.enable_<app>`` flag is true. See :mod:`smarter.lib.manifest.sam_apps`. """ urlpatterns += sam_app_urlpatterns(smarter_settings, SAM_APP_API_URLS, "API")