django-agentweb 0.0.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- agentweb/__init__.py +17 -0
- agentweb/apps.py +15 -0
- agentweb/commerce/__init__.py +15 -0
- agentweb/commerce/cap_lite.py +59 -0
- agentweb/commerce/urls.py +15 -0
- agentweb/commerce/views.py +35 -0
- agentweb/conf.py +131 -0
- agentweb/discovery/__init__.py +7 -0
- agentweb/discovery/descriptors.py +249 -0
- agentweb/discovery/middleware.py +54 -0
- agentweb/discovery/urls.py +25 -0
- agentweb/discovery/views.py +55 -0
- agentweb/jsonld/__init__.py +35 -0
- agentweb/jsonld/builders.py +498 -0
- agentweb/jsonld/graph.py +80 -0
- agentweb/jsonld/profiles.py +260 -0
- agentweb/llms/__init__.py +7 -0
- agentweb/llms/sections.py +61 -0
- agentweb/llms/urls.py +72 -0
- agentweb/llms/validate.py +47 -0
- agentweb/llms/views.py +64 -0
- agentweb/management/__init__.py +0 -0
- agentweb/management/commands/__init__.py +0 -0
- agentweb/management/commands/generate_llms_txt.py +65 -0
- agentweb/sdf/__init__.py +6 -0
- agentweb/sdf/urls.py +15 -0
- agentweb/sdf/views.py +23 -0
- agentweb/static/agentweb/webmcp.js +109 -0
- agentweb/templates/agentweb/llms-full.txt +12 -0
- agentweb/templates/agentweb/llms.txt +11 -0
- agentweb/templatetags/__init__.py +0 -0
- agentweb/templatetags/agentweb_jsonld.py +38 -0
- agentweb/templatetags/agentweb_webmcp.py +63 -0
- agentweb/templatetags/agentweb_webmcp_decl.py +36 -0
- agentweb/urls.py +31 -0
- agentweb/webmcp/__init__.py +13 -0
- agentweb/webmcp/tools.py +99 -0
- agentweb/webmcp/urls.py +20 -0
- agentweb/webmcp/views.py +87 -0
- django_agentweb-0.0.1.data/data/share/django-agentweb/requirements/py310-django42.txt +22 -0
- django_agentweb-0.0.1.data/data/share/django-agentweb/requirements/py310-django52.txt +22 -0
- django_agentweb-0.0.1.data/data/share/django-agentweb/requirements/py311-django42.txt +18 -0
- django_agentweb-0.0.1.data/data/share/django-agentweb/requirements/py311-django52.txt +18 -0
- django_agentweb-0.0.1.data/data/share/django-agentweb/requirements/py312-django42.txt +18 -0
- django_agentweb-0.0.1.data/data/share/django-agentweb/requirements/py312-django52.txt +18 -0
- django_agentweb-0.0.1.data/data/share/django-agentweb/requirements/py313-django52.txt +18 -0
- django_agentweb-0.0.1.data/data/share/django-agentweb/requirements/py314-django52.txt +18 -0
- django_agentweb-0.0.1.dist-info/METADATA +172 -0
- django_agentweb-0.0.1.dist-info/RECORD +52 -0
- django_agentweb-0.0.1.dist-info/WHEEL +5 -0
- django_agentweb-0.0.1.dist-info/licenses/LICENSE +21 -0
- django_agentweb-0.0.1.dist-info/top_level.txt +1 -0
agentweb/__init__.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"""django-agentweb — make Django sites first-class citizens of the agentic web.
|
|
2
|
+
|
|
3
|
+
See PEP 386 (https://peps.python.org/pep-0386/).
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
__version__ = "0.0.1"
|
|
7
|
+
__version_info__ = tuple(
|
|
8
|
+
int(i) if i.isdigit() else i for i in __version__.split(".")
|
|
9
|
+
)
|
|
10
|
+
__license__ = "MIT"
|
|
11
|
+
__title__ = "django-agentweb"
|
|
12
|
+
|
|
13
|
+
__author__ = "DLRSP"
|
|
14
|
+
__copyright__ = "Copyright 2010-present DLRSP"
|
|
15
|
+
|
|
16
|
+
# Version synonym
|
|
17
|
+
VERSION = __version_info__
|
agentweb/apps.py
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"""Application configuration for django-agentweb."""
|
|
2
|
+
|
|
3
|
+
from django.apps import AppConfig
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class AgentwebConfig(AppConfig):
|
|
7
|
+
"""Single Django app exposing the five agent-web domains.
|
|
8
|
+
|
|
9
|
+
Domains are sub-packages (``llms``, ``jsonld``, ``discovery``, ``webmcp``,
|
|
10
|
+
``commerce``, ``sdf``) activated per site via the ``AGENTWEB`` setting.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
name = "agentweb"
|
|
14
|
+
verbose_name = "Agentic Web"
|
|
15
|
+
default_auto_field = "django.db.models.BigAutoField"
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"""Commerce / booking domain — agentic commerce discovery + hooks.
|
|
2
|
+
|
|
3
|
+
Provides the discovery surface for agentic commerce/booking (CAP / UCP for
|
|
4
|
+
Lodging / AP2) and integration hooks. Transactional flows (real reservations,
|
|
5
|
+
payments) are delegated to a booking-engine vendor configured via
|
|
6
|
+
``COMMERCE.VENDOR``; this module does not process payments itself.
|
|
7
|
+
|
|
8
|
+
Priority use cases (e.g. an independent hotel): expose enough for an agent to
|
|
9
|
+
check availability, simulate a booking price and start a **direct** reservation,
|
|
10
|
+
reducing OTA dependence. Off by default.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from .cap_lite import build_cap_lite_catalog, build_cap_lite_product
|
|
14
|
+
|
|
15
|
+
__all__ = ["build_cap_lite_catalog", "build_cap_lite_product"]
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"""CAP Lite helpers — Product/Offer JSON-LD for agentic commerce discovery."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Any, Dict, List, Optional, Sequence
|
|
6
|
+
|
|
7
|
+
from agentweb.jsonld import builders
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def build_cap_lite_product(
|
|
11
|
+
*,
|
|
12
|
+
name: str,
|
|
13
|
+
price: Any,
|
|
14
|
+
currency: str = "EUR",
|
|
15
|
+
description: Optional[str] = None,
|
|
16
|
+
url: Optional[str] = None,
|
|
17
|
+
sku: Optional[str] = None,
|
|
18
|
+
availability: str = "https://schema.org/InStock",
|
|
19
|
+
) -> Dict[str, Any]:
|
|
20
|
+
"""Build a Product+Offer graph suitable for CAP Lite surfaces."""
|
|
21
|
+
offer = builders.build_offer(
|
|
22
|
+
price=price,
|
|
23
|
+
currency=currency,
|
|
24
|
+
availability=availability,
|
|
25
|
+
url=url,
|
|
26
|
+
)
|
|
27
|
+
return builders.build_product(
|
|
28
|
+
name=name,
|
|
29
|
+
description=description,
|
|
30
|
+
sku=sku,
|
|
31
|
+
offers=offer,
|
|
32
|
+
context=True,
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def build_cap_lite_catalog(
|
|
37
|
+
products: Sequence[Dict[str, Any]],
|
|
38
|
+
) -> Dict[str, Any]:
|
|
39
|
+
"""Wrap product nodes in a single ``@graph`` document."""
|
|
40
|
+
from agentweb.jsonld.graph import build_graph
|
|
41
|
+
|
|
42
|
+
nodes: List[Dict[str, Any]] = []
|
|
43
|
+
for item in products:
|
|
44
|
+
nodes.append(
|
|
45
|
+
build_cap_lite_product(
|
|
46
|
+
name=item["name"],
|
|
47
|
+
price=item["price"],
|
|
48
|
+
currency=item.get("currency", "EUR"),
|
|
49
|
+
description=item.get("description"),
|
|
50
|
+
url=item.get("url"),
|
|
51
|
+
sku=item.get("sku"),
|
|
52
|
+
availability=item.get(
|
|
53
|
+
"availability", "https://schema.org/InStock"
|
|
54
|
+
),
|
|
55
|
+
)
|
|
56
|
+
)
|
|
57
|
+
# Strip per-node @context before graphing.
|
|
58
|
+
stripped = [{k: v for k, v in n.items() if k != "@context"} for n in nodes]
|
|
59
|
+
return build_graph(*stripped)
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"""URLs for the commerce / booking domain."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from django.urls import path
|
|
6
|
+
|
|
7
|
+
from .views import CommerceDescriptorView
|
|
8
|
+
|
|
9
|
+
urlpatterns = [
|
|
10
|
+
path(
|
|
11
|
+
".well-known/commerce.json",
|
|
12
|
+
CommerceDescriptorView.as_view(),
|
|
13
|
+
name="agentweb-commerce-descriptor",
|
|
14
|
+
),
|
|
15
|
+
]
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"""Views for the commerce / booking domain."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from django.http import HttpRequest, JsonResponse
|
|
6
|
+
from django.views import View
|
|
7
|
+
|
|
8
|
+
from .. import conf
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class CommerceDescriptorView(View):
|
|
12
|
+
"""Serve a discovery document for agentic commerce/booking.
|
|
13
|
+
|
|
14
|
+
Describes how an agent can interact (availability, price simulation, direct
|
|
15
|
+
booking) and which vendor backs the transactional flow. Actual transactions
|
|
16
|
+
are delegated to the vendor — see ``COMMERCE.VENDOR``.
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
def get(self, request: HttpRequest, *args, **kwargs) -> JsonResponse:
|
|
20
|
+
cfg = conf.get_domain("COMMERCE")
|
|
21
|
+
return JsonResponse(
|
|
22
|
+
{
|
|
23
|
+
"schemaVersion": "0.1",
|
|
24
|
+
"vendor": cfg.get("VENDOR"),
|
|
25
|
+
"operations": [
|
|
26
|
+
"checkAvailability",
|
|
27
|
+
"simulateBookingCost",
|
|
28
|
+
"startDirectBooking",
|
|
29
|
+
],
|
|
30
|
+
# Booking is a state-changing action: agents must route through
|
|
31
|
+
# a human-in-the-loop confirmation, never auto-commit.
|
|
32
|
+
"requiresHumanConfirmation": True,
|
|
33
|
+
"untrustedContentHint": True,
|
|
34
|
+
}
|
|
35
|
+
)
|
agentweb/conf.py
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"""Settings access layer for django-agentweb.
|
|
2
|
+
|
|
3
|
+
All behaviour is driven by a single ``AGENTWEB`` dict in Django settings. Every
|
|
4
|
+
domain is **off by default**; a site opts in explicitly. Reading config through
|
|
5
|
+
this module (rather than ``settings.AGENTWEB`` directly) guarantees defaults are
|
|
6
|
+
always applied and keeps the activation contract in one place.
|
|
7
|
+
|
|
8
|
+
Example::
|
|
9
|
+
|
|
10
|
+
AGENTWEB = {
|
|
11
|
+
"LLMS": {
|
|
12
|
+
"ENABLED": True,
|
|
13
|
+
"TITLE": "Example Hotel",
|
|
14
|
+
"DESCRIPTION": "Independent hotel on the Italian coast.",
|
|
15
|
+
"SECTIONS": [
|
|
16
|
+
{
|
|
17
|
+
"heading": "Book",
|
|
18
|
+
"links": [
|
|
19
|
+
{
|
|
20
|
+
"title": "Rooms",
|
|
21
|
+
"url": "https://example.com/rooms/",
|
|
22
|
+
"notes": "Room types and amenities",
|
|
23
|
+
},
|
|
24
|
+
],
|
|
25
|
+
},
|
|
26
|
+
],
|
|
27
|
+
},
|
|
28
|
+
"JSONLD": {"ENABLED": True},
|
|
29
|
+
"DISCOVERY": {"ENABLED": True},
|
|
30
|
+
"WEBMCP": {"ENABLED": False},
|
|
31
|
+
"COMMERCE": {"ENABLED": False},
|
|
32
|
+
"SDF": {"ENABLED": False},
|
|
33
|
+
}
|
|
34
|
+
"""
|
|
35
|
+
|
|
36
|
+
from __future__ import annotations
|
|
37
|
+
|
|
38
|
+
from typing import Any, Dict
|
|
39
|
+
|
|
40
|
+
from django.conf import settings
|
|
41
|
+
|
|
42
|
+
SETTING_NAME = "AGENTWEB"
|
|
43
|
+
|
|
44
|
+
#: Default configuration for every domain. Merged shallowly with user config.
|
|
45
|
+
DEFAULTS: Dict[str, Dict[str, Any]] = {
|
|
46
|
+
# Domain 1 — Readability (llms.txt / llms-full.txt).
|
|
47
|
+
"LLMS": {
|
|
48
|
+
"ENABLED": False,
|
|
49
|
+
"TITLE": "",
|
|
50
|
+
"DESCRIPTION": "",
|
|
51
|
+
# Cache timeout (seconds) for the dynamic view; 0 disables caching.
|
|
52
|
+
"CACHE_TIMEOUT": 3600,
|
|
53
|
+
# Per-language variants at /{lang}/llms.txt plus root /llms.txt index.
|
|
54
|
+
"I18N_VARIANTS": True,
|
|
55
|
+
# Curated H2 sections: [{heading, links: [{title, url, notes?}]}]
|
|
56
|
+
"SECTIONS": [],
|
|
57
|
+
# Optional body paragraphs (Markdown) between summary and sections.
|
|
58
|
+
"BODY": "",
|
|
59
|
+
# URL substrings / path prefixes never emitted into llms.txt.
|
|
60
|
+
"EXCLUDE_PATTERNS": [
|
|
61
|
+
"/admin/",
|
|
62
|
+
"/accounts/",
|
|
63
|
+
"/private/",
|
|
64
|
+
"/api/",
|
|
65
|
+
"secret",
|
|
66
|
+
],
|
|
67
|
+
# When True and SECTIONS empty, emit a minimal Docs section from
|
|
68
|
+
# TITLE/DESCRIPTION only (no auto-crawl of the site in v1).
|
|
69
|
+
"AUTO_SECTIONS": False,
|
|
70
|
+
},
|
|
71
|
+
# Domain 2 — Structured data (Schema.org / JSON-LD).
|
|
72
|
+
"JSONLD": {
|
|
73
|
+
"ENABLED": False,
|
|
74
|
+
# Profile names resolved by agentweb.jsonld.profiles.
|
|
75
|
+
"PROFILES": [],
|
|
76
|
+
},
|
|
77
|
+
# Domain 3 — Discovery (/.well-known agent descriptors + ai-catalog).
|
|
78
|
+
"DISCOVERY": {
|
|
79
|
+
"ENABLED": False,
|
|
80
|
+
# Optional Web Bot Auth (RFC 9421) enforcement — requires the
|
|
81
|
+
# ``webbotauth`` extra. Off by default.
|
|
82
|
+
"WEB_BOT_AUTH": False,
|
|
83
|
+
# Host display name / identifier for ai-catalog.json (ARD).
|
|
84
|
+
"HOST_DISPLAY_NAME": "",
|
|
85
|
+
"HOST_IDENTIFIER": "",
|
|
86
|
+
},
|
|
87
|
+
# Domain 4 — WebMCP (browser-native) + optional remote tool bridge.
|
|
88
|
+
"WEBMCP": {
|
|
89
|
+
"ENABLED": False,
|
|
90
|
+
# "proxy" -> reach vendors server-side (recommended; needs ``webmcp``
|
|
91
|
+
# extra). "client" -> agent calls vendor directly (not recommended).
|
|
92
|
+
"DATA_SOURCE": "proxy",
|
|
93
|
+
# When True, also expose the optional HTTP tool-invoke bridge for
|
|
94
|
+
# headless/remote agents. Browser WebMCP does not need this.
|
|
95
|
+
"REMOTE_BRIDGE": False,
|
|
96
|
+
},
|
|
97
|
+
# Domain 5a — Agentic commerce / booking.
|
|
98
|
+
"COMMERCE": {
|
|
99
|
+
"ENABLED": False,
|
|
100
|
+
# Transactional flows delegated to a booking-engine vendor; this module
|
|
101
|
+
# provides discovery + hooks only.
|
|
102
|
+
"VENDOR": None,
|
|
103
|
+
},
|
|
104
|
+
# Domain 5b — SDF (single-promoter; behind flag, off by default).
|
|
105
|
+
"SDF": {
|
|
106
|
+
"ENABLED": False,
|
|
107
|
+
},
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
#: Domains that expose URL modules (``jsonld`` is template-only).
|
|
111
|
+
URL_DOMAINS = ("LLMS", "DISCOVERY", "WEBMCP", "COMMERCE", "SDF")
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def get_config() -> Dict[str, Dict[str, Any]]:
|
|
115
|
+
"""Return the full merged configuration (defaults + user overrides)."""
|
|
116
|
+
user_config = getattr(settings, SETTING_NAME, None) or {}
|
|
117
|
+
merged: Dict[str, Dict[str, Any]] = {}
|
|
118
|
+
for domain, defaults in DEFAULTS.items():
|
|
119
|
+
overrides = user_config.get(domain, {}) or {}
|
|
120
|
+
merged[domain] = {**defaults, **overrides}
|
|
121
|
+
return merged
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def get_domain(domain: str) -> Dict[str, Any]:
|
|
125
|
+
"""Return the merged config dict for a single domain."""
|
|
126
|
+
return get_config().get(domain.upper(), {})
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
def is_enabled(domain: str) -> bool:
|
|
130
|
+
"""Return ``True`` if ``domain`` is opted in for the current site."""
|
|
131
|
+
return bool(get_domain(domain).get("ENABLED", False))
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"""Discovery domain — ``/.well-known`` agent descriptors.
|
|
2
|
+
|
|
3
|
+
Publishes a machine-readable capability descriptor so agents can discover which
|
|
4
|
+
agent-web features the site exposes (llms.txt, WebMCP manifest, commerce
|
|
5
|
+
endpoints, …). Optional Web Bot Auth (RFC 9421) enforcement lives behind the
|
|
6
|
+
``webbotauth`` extra and the ``DISCOVERY.WEB_BOT_AUTH`` flag.
|
|
7
|
+
"""
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
"""Build discovery documents: legacy agent.json + ARD ai-catalog.json."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Any, Dict, List
|
|
6
|
+
|
|
7
|
+
from django.conf import settings
|
|
8
|
+
from django.contrib.sites.models import Site
|
|
9
|
+
from django.urls import NoReverseMatch, reverse
|
|
10
|
+
|
|
11
|
+
from .. import __version__, conf
|
|
12
|
+
|
|
13
|
+
SERVER_CARD_SCHEMA = (
|
|
14
|
+
"https://static.modelcontextprotocol.io/schemas/v1/server-card.schema.json"
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def _safe_reverse(name: str) -> str | None:
|
|
19
|
+
try:
|
|
20
|
+
return reverse(name)
|
|
21
|
+
except NoReverseMatch:
|
|
22
|
+
return None
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def _absolute(request, path: str | None) -> str | None:
|
|
26
|
+
if not path:
|
|
27
|
+
return None
|
|
28
|
+
return request.build_absolute_uri(path)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def _host_meta() -> Dict[str, str]:
|
|
32
|
+
cfg = conf.get_domain("DISCOVERY")
|
|
33
|
+
display = (cfg.get("HOST_DISPLAY_NAME") or "").strip()
|
|
34
|
+
identifier = (cfg.get("HOST_IDENTIFIER") or "").strip()
|
|
35
|
+
try:
|
|
36
|
+
site = Site.objects.get_current()
|
|
37
|
+
if not display:
|
|
38
|
+
display = site.name or site.domain
|
|
39
|
+
if not identifier:
|
|
40
|
+
identifier = f"https://{site.domain}"
|
|
41
|
+
except Exception:
|
|
42
|
+
if not display:
|
|
43
|
+
display = "site"
|
|
44
|
+
if not identifier:
|
|
45
|
+
identifier = getattr(settings, "SITE_ID", "site")
|
|
46
|
+
return {"displayName": display, "identifier": str(identifier)}
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def build_descriptor(request) -> Dict[str, Any]:
|
|
50
|
+
"""Return the ``/.well-known/agent.json`` payload for the current site.
|
|
51
|
+
|
|
52
|
+
Soft-deprecated in favour of :func:`build_ai_catalog` /
|
|
53
|
+
``/.well-known/ai-catalog.json`` (ARD). Kept for one minor as a compact
|
|
54
|
+
capability map for early integrators; new consumers should prefer
|
|
55
|
+
``ai-catalog.json``.
|
|
56
|
+
"""
|
|
57
|
+
capabilities: Dict[str, Any] = {}
|
|
58
|
+
|
|
59
|
+
if conf.is_enabled("LLMS"):
|
|
60
|
+
url = _safe_reverse("agentweb-llms-txt")
|
|
61
|
+
capabilities["llmsTxt"] = {"url": _absolute(request, url)}
|
|
62
|
+
|
|
63
|
+
if conf.is_enabled("WEBMCP"):
|
|
64
|
+
url = _safe_reverse("agentweb-webmcp-manifest")
|
|
65
|
+
capabilities["webmcp"] = {
|
|
66
|
+
"manifest": _absolute(request, url),
|
|
67
|
+
"note": (
|
|
68
|
+
"Browser WebMCP uses navigator.modelContext; the manifest "
|
|
69
|
+
"lists tool descriptors for page registration."
|
|
70
|
+
),
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if conf.is_enabled("COMMERCE"):
|
|
74
|
+
url = _safe_reverse("agentweb-commerce-descriptor")
|
|
75
|
+
capabilities["commerce"] = {
|
|
76
|
+
"descriptor": _absolute(request, url),
|
|
77
|
+
"vendor": conf.get_domain("COMMERCE").get("VENDOR"),
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
descriptor: Dict[str, Any] = {
|
|
81
|
+
"schemaVersion": "0.1",
|
|
82
|
+
"name": "agentweb",
|
|
83
|
+
"deprecated": True,
|
|
84
|
+
"successor": "/.well-known/ai-catalog.json",
|
|
85
|
+
"capabilities": capabilities,
|
|
86
|
+
"untrustedContentHint": True,
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if conf.get_domain("DISCOVERY").get("WEB_BOT_AUTH"):
|
|
90
|
+
descriptor["webBotAuth"] = {"required": True, "spec": "RFC9421"}
|
|
91
|
+
|
|
92
|
+
return descriptor
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def build_ai_catalog(request) -> Dict[str, Any]:
|
|
96
|
+
"""Return ``/.well-known/ai-catalog.json`` (Agentic Resource Discovery).
|
|
97
|
+
|
|
98
|
+
Spec: https://agenticresourcediscovery.org/ai_catalog_spec/
|
|
99
|
+
Publishes only enabled agent-web surfaces. CORS is set on the view.
|
|
100
|
+
"""
|
|
101
|
+
host = _host_meta()
|
|
102
|
+
domain = ""
|
|
103
|
+
try:
|
|
104
|
+
domain = Site.objects.get_current().domain
|
|
105
|
+
except Exception:
|
|
106
|
+
domain = "example.com"
|
|
107
|
+
|
|
108
|
+
entries: List[Dict[str, Any]] = []
|
|
109
|
+
|
|
110
|
+
if conf.is_enabled("LLMS"):
|
|
111
|
+
llms_url = _absolute(request, _safe_reverse("agentweb-llms-txt"))
|
|
112
|
+
if llms_url:
|
|
113
|
+
entries.append(
|
|
114
|
+
{
|
|
115
|
+
"identifier": f"urn:air:{domain}:llms:root",
|
|
116
|
+
"displayName": "llms.txt",
|
|
117
|
+
"type": "text/plain",
|
|
118
|
+
"url": llms_url,
|
|
119
|
+
"description": "Curated Markdown index for AI agents.",
|
|
120
|
+
"representativeQueries": [
|
|
121
|
+
"what does this site offer",
|
|
122
|
+
"summarize this website for an agent",
|
|
123
|
+
],
|
|
124
|
+
}
|
|
125
|
+
)
|
|
126
|
+
|
|
127
|
+
if conf.is_enabled("WEBMCP"):
|
|
128
|
+
manifest = _absolute(request, _safe_reverse("agentweb-webmcp-manifest"))
|
|
129
|
+
if manifest:
|
|
130
|
+
entries.append(
|
|
131
|
+
{
|
|
132
|
+
"identifier": f"urn:air:{domain}:webmcp:tools",
|
|
133
|
+
"displayName": "WebMCP tool descriptors",
|
|
134
|
+
"type": "application/json",
|
|
135
|
+
"url": manifest,
|
|
136
|
+
"description": (
|
|
137
|
+
"Tool descriptors for in-page WebMCP registration "
|
|
138
|
+
"(navigator.modelContext)."
|
|
139
|
+
),
|
|
140
|
+
"representativeQueries": [
|
|
141
|
+
"what tools can an agent call on this page",
|
|
142
|
+
"check availability or simulate a booking cost",
|
|
143
|
+
],
|
|
144
|
+
}
|
|
145
|
+
)
|
|
146
|
+
|
|
147
|
+
if conf.is_enabled("COMMERCE"):
|
|
148
|
+
commerce = _absolute(
|
|
149
|
+
request, _safe_reverse("agentweb-commerce-descriptor")
|
|
150
|
+
)
|
|
151
|
+
if commerce:
|
|
152
|
+
entries.append(
|
|
153
|
+
{
|
|
154
|
+
"identifier": f"urn:air:{domain}:commerce:descriptor",
|
|
155
|
+
"displayName": "Agentic commerce descriptor",
|
|
156
|
+
"type": "application/json",
|
|
157
|
+
"url": commerce,
|
|
158
|
+
"description": (
|
|
159
|
+
"Discovery for availability, price simulation, and "
|
|
160
|
+
"direct booking hooks."
|
|
161
|
+
),
|
|
162
|
+
"representativeQueries": [
|
|
163
|
+
"simulate booking cost",
|
|
164
|
+
"start a direct reservation",
|
|
165
|
+
],
|
|
166
|
+
}
|
|
167
|
+
)
|
|
168
|
+
|
|
169
|
+
if conf.is_enabled("WEBMCP"):
|
|
170
|
+
card = _absolute(request, _safe_reverse("agentweb-mcp-server-card"))
|
|
171
|
+
if card:
|
|
172
|
+
entries.append(
|
|
173
|
+
{
|
|
174
|
+
"identifier": f"urn:air:{domain}:mcp:server-card",
|
|
175
|
+
"displayName": "MCP server card",
|
|
176
|
+
"type": "application/mcp-server-card+json",
|
|
177
|
+
"url": card,
|
|
178
|
+
"description": (
|
|
179
|
+
"MCP Server Card for agentweb WebMCP discovery."
|
|
180
|
+
),
|
|
181
|
+
"representativeQueries": [
|
|
182
|
+
"how do agents connect to this site's tools",
|
|
183
|
+
],
|
|
184
|
+
}
|
|
185
|
+
)
|
|
186
|
+
|
|
187
|
+
return {
|
|
188
|
+
"specVersion": "1.0",
|
|
189
|
+
"host": host,
|
|
190
|
+
"entries": entries,
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
def build_mcp_server_card(request) -> Dict[str, Any]:
|
|
195
|
+
"""Return ``/.well-known/mcp/server-card.json`` (MCP Server Card v1).
|
|
196
|
+
|
|
197
|
+
Describes the site's agentweb WebMCP surface. A Streamable HTTP remote is
|
|
198
|
+
included only when ``WEBMCP.REMOTE_BRIDGE`` is enabled; otherwise the card
|
|
199
|
+
advertises browser WebMCP via the tool-descriptor manifest in ``_meta``.
|
|
200
|
+
"""
|
|
201
|
+
host = _host_meta()
|
|
202
|
+
manifest = _absolute(request, _safe_reverse("agentweb-webmcp-manifest"))
|
|
203
|
+
card: Dict[str, Any] = {
|
|
204
|
+
"$schema": SERVER_CARD_SCHEMA,
|
|
205
|
+
"name": "io.github.dlrsp/agentweb",
|
|
206
|
+
"version": __version__,
|
|
207
|
+
"title": "django-agentweb WebMCP",
|
|
208
|
+
"description": (
|
|
209
|
+
"In-page WebMCP tools for this Django site (opt-in per domain)."
|
|
210
|
+
),
|
|
211
|
+
"websiteUrl": host.get("identifier") or None,
|
|
212
|
+
}
|
|
213
|
+
# Drop empty optional URI fields (schema wants format:uri when present).
|
|
214
|
+
if not card.get("websiteUrl"):
|
|
215
|
+
card.pop("websiteUrl", None)
|
|
216
|
+
|
|
217
|
+
remotes: List[Dict[str, Any]] = []
|
|
218
|
+
if conf.is_enabled("WEBMCP") and conf.get_domain("WEBMCP").get(
|
|
219
|
+
"REMOTE_BRIDGE"
|
|
220
|
+
):
|
|
221
|
+
# Bridge invoke base (clients append /<tool>); not a full MCP session.
|
|
222
|
+
try:
|
|
223
|
+
bridge_path = reverse(
|
|
224
|
+
"agentweb-webmcp-tool", kwargs={"name": "_"}
|
|
225
|
+
).rsplit("/", 1)[0]
|
|
226
|
+
except NoReverseMatch:
|
|
227
|
+
bridge_path = None
|
|
228
|
+
bridge = _absolute(request, bridge_path)
|
|
229
|
+
if bridge:
|
|
230
|
+
remotes.append(
|
|
231
|
+
{
|
|
232
|
+
"type": "streamable-http",
|
|
233
|
+
"url": bridge,
|
|
234
|
+
}
|
|
235
|
+
)
|
|
236
|
+
if remotes:
|
|
237
|
+
card["remotes"] = remotes
|
|
238
|
+
|
|
239
|
+
card["_meta"] = {
|
|
240
|
+
"io.github.dlrsp/agentweb": {
|
|
241
|
+
"protocol": "webmcp-browser",
|
|
242
|
+
"manifestUrl": manifest,
|
|
243
|
+
"remoteBridge": bool(
|
|
244
|
+
conf.is_enabled("WEBMCP")
|
|
245
|
+
and conf.get_domain("WEBMCP").get("REMOTE_BRIDGE")
|
|
246
|
+
),
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
return card
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"""HTTP middleware for agent-discovery headers."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from django.http import HttpRequest, HttpResponse
|
|
6
|
+
from django.urls import NoReverseMatch, reverse
|
|
7
|
+
|
|
8
|
+
from .. import conf
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class AgentwebDiscoveryMiddleware:
|
|
12
|
+
"""Attach AI-oriented discovery headers when DISCOVERY is enabled.
|
|
13
|
+
|
|
14
|
+
* ``Link`` — points at ``ai-catalog.json`` (ARD) when available
|
|
15
|
+
* ``Permissions-Policy: tools=(self)`` — when WEBMCP is enabled
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
def __init__(self, get_response):
|
|
19
|
+
self.get_response = get_response
|
|
20
|
+
|
|
21
|
+
def __call__(self, request: HttpRequest) -> HttpResponse:
|
|
22
|
+
response = self.get_response(request)
|
|
23
|
+
if not conf.is_enabled("DISCOVERY"):
|
|
24
|
+
return response
|
|
25
|
+
|
|
26
|
+
links = []
|
|
27
|
+
try:
|
|
28
|
+
catalog = reverse("agentweb-ai-catalog")
|
|
29
|
+
links.append(f'<{catalog}>; rel="ai-catalog"')
|
|
30
|
+
except NoReverseMatch:
|
|
31
|
+
pass
|
|
32
|
+
try:
|
|
33
|
+
agent = reverse("agentweb-agent-descriptor")
|
|
34
|
+
links.append(f'<{agent}>; rel="agent-descriptor"')
|
|
35
|
+
except NoReverseMatch:
|
|
36
|
+
pass
|
|
37
|
+
if links:
|
|
38
|
+
existing = response.get("Link", "")
|
|
39
|
+
combined = ", ".join([p for p in (existing, ", ".join(links)) if p])
|
|
40
|
+
response["Link"] = combined
|
|
41
|
+
|
|
42
|
+
if conf.is_enabled("WEBMCP"):
|
|
43
|
+
# Allow same-origin WebMCP tool registration (Chrome Permissions-Policy).
|
|
44
|
+
existing_pp = response.get("Permissions-Policy", "")
|
|
45
|
+
tools_clause = "tools=(self)"
|
|
46
|
+
if "tools=" not in existing_pp:
|
|
47
|
+
response["Permissions-Policy"] = (
|
|
48
|
+
f"{existing_pp}, {tools_clause}".strip(", ")
|
|
49
|
+
if existing_pp
|
|
50
|
+
else tools_clause
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
response["X-Agentweb-Discovery"] = "1"
|
|
54
|
+
return response
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"""URLs for the discovery domain."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from django.urls import path
|
|
6
|
+
|
|
7
|
+
from .views import AgentDescriptorView, AiCatalogView, McpServerCardView
|
|
8
|
+
|
|
9
|
+
urlpatterns = [
|
|
10
|
+
path(
|
|
11
|
+
".well-known/agent.json",
|
|
12
|
+
AgentDescriptorView.as_view(),
|
|
13
|
+
name="agentweb-agent-descriptor",
|
|
14
|
+
),
|
|
15
|
+
path(
|
|
16
|
+
".well-known/ai-catalog.json",
|
|
17
|
+
AiCatalogView.as_view(),
|
|
18
|
+
name="agentweb-ai-catalog",
|
|
19
|
+
),
|
|
20
|
+
path(
|
|
21
|
+
".well-known/mcp/server-card.json",
|
|
22
|
+
McpServerCardView.as_view(),
|
|
23
|
+
name="agentweb-mcp-server-card",
|
|
24
|
+
),
|
|
25
|
+
]
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"""Views for the discovery domain."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from django.http import HttpRequest, JsonResponse
|
|
6
|
+
from django.views import View
|
|
7
|
+
|
|
8
|
+
from .descriptors import (
|
|
9
|
+
build_ai_catalog,
|
|
10
|
+
build_descriptor,
|
|
11
|
+
build_mcp_server_card,
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class AgentDescriptorView(View):
|
|
16
|
+
"""Serve ``/.well-known/agent.json`` describing enabled capabilities."""
|
|
17
|
+
|
|
18
|
+
def get(self, request: HttpRequest, *args, **kwargs) -> JsonResponse:
|
|
19
|
+
return JsonResponse(build_descriptor(request))
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class AiCatalogView(View):
|
|
23
|
+
"""Serve ``/.well-known/ai-catalog.json`` (ARD / ai-catalog 1.0)."""
|
|
24
|
+
|
|
25
|
+
def get(self, request: HttpRequest, *args, **kwargs) -> JsonResponse:
|
|
26
|
+
response = JsonResponse(build_ai_catalog(request))
|
|
27
|
+
# Required for cross-origin registry crawlers.
|
|
28
|
+
response["Access-Control-Allow-Origin"] = "*"
|
|
29
|
+
response["Access-Control-Allow-Methods"] = "GET, OPTIONS"
|
|
30
|
+
return response
|
|
31
|
+
|
|
32
|
+
def options(self, request: HttpRequest, *args, **kwargs) -> JsonResponse:
|
|
33
|
+
response = JsonResponse({})
|
|
34
|
+
response["Access-Control-Allow-Origin"] = "*"
|
|
35
|
+
response["Access-Control-Allow-Methods"] = "GET, OPTIONS"
|
|
36
|
+
return response
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class McpServerCardView(View):
|
|
40
|
+
"""Serve ``/.well-known/mcp/server-card.json`` (MCP Server Card v1)."""
|
|
41
|
+
|
|
42
|
+
def get(self, request: HttpRequest, *args, **kwargs) -> JsonResponse:
|
|
43
|
+
response = JsonResponse(
|
|
44
|
+
build_mcp_server_card(request),
|
|
45
|
+
content_type="application/mcp-server-card+json",
|
|
46
|
+
)
|
|
47
|
+
response["Access-Control-Allow-Origin"] = "*"
|
|
48
|
+
response["Access-Control-Allow-Methods"] = "GET, OPTIONS"
|
|
49
|
+
return response
|
|
50
|
+
|
|
51
|
+
def options(self, request: HttpRequest, *args, **kwargs) -> JsonResponse:
|
|
52
|
+
response = JsonResponse({})
|
|
53
|
+
response["Access-Control-Allow-Origin"] = "*"
|
|
54
|
+
response["Access-Control-Allow-Methods"] = "GET, OPTIONS"
|
|
55
|
+
return response
|