tina4-python 3.13.50__tar.gz → 3.13.52__tar.gz

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.
Files changed (160) hide show
  1. {tina4_python-3.13.50 → tina4_python-3.13.52}/PKG-INFO +1 -1
  2. {tina4_python-3.13.50 → tina4_python-3.13.52}/pyproject.toml +1 -1
  3. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/__init__.py +1 -1
  4. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/core/server.py +6 -0
  5. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/database/connection.py +1 -0
  6. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/dev_admin/__init__.py +93 -31
  7. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/frond/FROND.md +79 -0
  8. tina4_python-3.13.52/tina4_python/frond/__init__.py +85 -0
  9. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/frond/engine.py +109 -0
  10. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/mcp/__init__.py +173 -34
  11. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/public/js/frond.js +138 -1
  12. tina4_python-3.13.52/tina4_python/public/js/frond.min.js +2 -0
  13. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/scss/__init__.py +49 -1
  14. tina4_python-3.13.50/tina4_python/frond/__init__.py +0 -12
  15. tina4_python-3.13.50/tina4_python/public/js/frond.min.js +0 -2
  16. {tina4_python-3.13.50 → tina4_python-3.13.52}/.gitignore +0 -0
  17. {tina4_python-3.13.50 → tina4_python-3.13.52}/README.md +0 -0
  18. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/CLAUDE.md +0 -0
  19. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/HtmlElement.py +0 -0
  20. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/Testing.py +0 -0
  21. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/ai/__init__.py +0 -0
  22. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/api/__init__.py +0 -0
  23. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/auth/__init__.py +0 -0
  24. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/cache/__init__.py +0 -0
  25. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/cli/__init__.py +0 -0
  26. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/container/__init__.py +0 -0
  27. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/core/__init__.py +0 -0
  28. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/core/cache.py +0 -0
  29. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/core/constants.py +0 -0
  30. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/core/events.py +0 -0
  31. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/core/middleware.py +0 -0
  32. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/core/rate_limiter.py +0 -0
  33. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/core/request.py +0 -0
  34. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/core/response.py +0 -0
  35. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/core/router.py +0 -0
  36. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/crud/__init__.py +0 -0
  37. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/database/__init__.py +0 -0
  38. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/database/adapter.py +0 -0
  39. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/database/firebird.py +0 -0
  40. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/database/mongodb.py +0 -0
  41. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/database/mssql.py +0 -0
  42. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/database/mysql.py +0 -0
  43. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/database/odbc.py +0 -0
  44. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/database/postgres.py +0 -0
  45. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/database/sqlite.py +0 -0
  46. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/debug/__init__.py +0 -0
  47. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/debug/error_overlay.py +0 -0
  48. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/dev_admin/metrics.py +0 -0
  49. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/dev_admin/plan.py +0 -0
  50. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/dev_admin/project_index.py +0 -0
  51. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/docs.py +0 -0
  52. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/docstore/__init__.py +0 -0
  53. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/dotenv/__init__.py +0 -0
  54. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/env.py +0 -0
  55. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/gallery/auth/meta.json +0 -0
  56. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/gallery/auth/src/routes/api/gallery_auth.py +0 -0
  57. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/gallery/database/meta.json +0 -0
  58. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/gallery/database/src/routes/api/gallery_db.py +0 -0
  59. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/gallery/error-overlay/meta.json +0 -0
  60. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/gallery/error-overlay/src/routes/api/gallery_crash.py +0 -0
  61. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/gallery/orm/meta.json +0 -0
  62. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/gallery/orm/src/orm/Product.py +0 -0
  63. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/gallery/orm/src/routes/api/gallery_products.py +0 -0
  64. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/gallery/queue/meta.json +0 -0
  65. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/gallery/queue/src/routes/api/gallery_queue.py +0 -0
  66. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/gallery/rest-api/meta.json +0 -0
  67. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/gallery/rest-api/src/routes/api/gallery_hello.py +0 -0
  68. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/gallery/templates/meta.json +0 -0
  69. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/gallery/templates/src/routes/gallery_page.py +0 -0
  70. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/gallery/templates/src/templates/gallery_page.twig +0 -0
  71. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/graphql/__init__.py +0 -0
  72. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/i18n/__init__.py +0 -0
  73. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/mcp/protocol.py +0 -0
  74. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/mcp/tools.py +0 -0
  75. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/messenger/__init__.py +0 -0
  76. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/migration/__init__.py +0 -0
  77. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/migration/runner.py +0 -0
  78. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/orm/__init__.py +0 -0
  79. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/orm/fields.py +0 -0
  80. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/orm/model.py +0 -0
  81. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/public/__feedback/widget.js +0 -0
  82. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/public/css/tina4.css +0 -0
  83. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/public/css/tina4.min.css +0 -0
  84. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/public/favicon.ico +0 -0
  85. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/public/images/logo.svg +0 -0
  86. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/public/images/tina4-logo-icon.webp +0 -0
  87. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/public/js/tina4-dev-admin.js +0 -0
  88. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/public/js/tina4-dev-admin.min.js +0 -0
  89. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/public/js/tina4.min.js +0 -0
  90. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/public/js/tina4js.min.js +0 -0
  91. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/public/swagger/index.html +0 -0
  92. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/public/swagger/oauth2-redirect.html +0 -0
  93. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/query_builder/__init__.py +0 -0
  94. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/queue/__init__.py +0 -0
  95. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/queue/job.py +0 -0
  96. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/queue/kafka_backend.py +0 -0
  97. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/queue/lite_backend.py +0 -0
  98. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/queue/mongo_backend.py +0 -0
  99. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/queue/rabbitmq_backend.py +0 -0
  100. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/queue_backends/__init__.py +0 -0
  101. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/queue_backends/kafka_backend.py +0 -0
  102. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/queue_backends/mongo_backend.py +0 -0
  103. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/queue_backends/rabbitmq_backend.py +0 -0
  104. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/scss/tina4css/_alerts.scss +0 -0
  105. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/scss/tina4css/_badges.scss +0 -0
  106. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/scss/tina4css/_buttons.scss +0 -0
  107. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/scss/tina4css/_cards.scss +0 -0
  108. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/scss/tina4css/_forms.scss +0 -0
  109. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/scss/tina4css/_grid.scss +0 -0
  110. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/scss/tina4css/_modals.scss +0 -0
  111. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/scss/tina4css/_nav.scss +0 -0
  112. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/scss/tina4css/_reset.scss +0 -0
  113. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/scss/tina4css/_tables.scss +0 -0
  114. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/scss/tina4css/_typography.scss +0 -0
  115. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/scss/tina4css/_utilities.scss +0 -0
  116. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/scss/tina4css/_variables.scss +0 -0
  117. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/scss/tina4css/base.scss +0 -0
  118. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/scss/tina4css/colors.scss +0 -0
  119. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/scss/tina4css/tina4.scss +0 -0
  120. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/seeder/__init__.py +0 -0
  121. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/service/__init__.py +0 -0
  122. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/session/__init__.py +0 -0
  123. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/session_handlers/__init__.py +0 -0
  124. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/session_handlers/mongodb_handler.py +0 -0
  125. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/session_handlers/redis_handler.py +0 -0
  126. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/session_handlers/valkey_handler.py +0 -0
  127. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/swagger/__init__.py +0 -0
  128. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/templates/components/crud.twig +0 -0
  129. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/templates/docker/distroless/Dockerfile +0 -0
  130. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/templates/docker/poetry/Dockerfile +0 -0
  131. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/templates/docker/python/Dockerfile +0 -0
  132. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/templates/docker/uv/Dockerfile +0 -0
  133. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/templates/errors/302.twig +0 -0
  134. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/templates/errors/401.twig +0 -0
  135. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/templates/errors/403.twig +0 -0
  136. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/templates/errors/404.twig +0 -0
  137. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/templates/errors/500.twig +0 -0
  138. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/templates/errors/502.twig +0 -0
  139. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/templates/errors/503.twig +0 -0
  140. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/templates/errors/base.twig +0 -0
  141. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/templates/frontend/README.md +0 -0
  142. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/templates/readme.md +0 -0
  143. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/test/__init__.py +0 -0
  144. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/test_client/__init__.py +0 -0
  145. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/translations/af/LC_MESSAGES/messages.mo +0 -0
  146. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/translations/af/LC_MESSAGES/messages.po +0 -0
  147. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/translations/en/LC_MESSAGES/messages.mo +0 -0
  148. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/translations/en/LC_MESSAGES/messages.po +0 -0
  149. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/translations/es/LC_MESSAGES/messages.mo +0 -0
  150. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/translations/es/LC_MESSAGES/messages.po +0 -0
  151. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/translations/fr/LC_MESSAGES/messages.mo +0 -0
  152. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/translations/fr/LC_MESSAGES/messages.po +0 -0
  153. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/translations/ja/LC_MESSAGES/messages.mo +0 -0
  154. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/translations/ja/LC_MESSAGES/messages.po +0 -0
  155. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/translations/zh/LC_MESSAGES/messages.mo +0 -0
  156. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/translations/zh/LC_MESSAGES/messages.po +0 -0
  157. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/validator/__init__.py +0 -0
  158. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/websocket/__init__.py +0 -0
  159. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/websocket/backplane.py +0 -0
  160. {tina4_python-3.13.50 → tina4_python-3.13.52}/tina4_python/wsdl/__init__.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: tina4-python
3
- Version: 3.13.50
3
+ Version: 3.13.52
4
4
  Summary: Tina4 Python v3 — Zero-dependency, lightweight web framework
5
5
  Author-email: Andre van Zuydam <andrevanzuydam@gmail.com>
6
6
  License: MIT
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "tina4-python"
3
- version = "3.13.50"
3
+ version = "3.13.52"
4
4
  description = "Tina4 Python v3 — Zero-dependency, lightweight web framework"
5
5
  authors = [
6
6
  {name = "Andre van Zuydam", email = "andrevanzuydam@gmail.com"}
@@ -8,7 +8,7 @@ Tina4 Python v3.0 — Zero-dependency, lightweight web framework.
8
8
 
9
9
  One import, everything works.
10
10
  """
11
- __version__ = "3.13.50"
11
+ __version__ = "3.13.51"
12
12
 
13
13
  # ── Route decorators ──
14
14
  from tina4_python.core.router import ( # noqa: E402, F401
@@ -276,6 +276,12 @@ Router.add("GET", _HEALTH_PATH, _health_handler)
276
276
  if _HEALTH_PATH != "/health":
277
277
  Router.add("GET", "/health", _health_handler)
278
278
 
279
+ # Frond live blocks: re-render a registered {% live %} fragment on demand.
280
+ # Always on (production too) - the poll/sse client fetches this; auth re-applies
281
+ # through the normal middleware chain on every refresh.
282
+ from tina4_python.frond import live_endpoint as _live_endpoint
283
+ Router.add("GET", "/__frond/live/{name}", _live_endpoint)
284
+
279
285
 
280
286
  def _render_error_page(status_code: int, path: str, request_id: str, error_message: str = "") -> str | None:
281
287
  """Render a styled error page using Frond engine.
@@ -110,6 +110,7 @@ except ImportError:
110
110
  from tina4_python.database.postgres import PostgreSQLAdapter
111
111
  register_driver("postgresql", PostgreSQLAdapter)
112
112
  register_driver("postgres", PostgreSQLAdapter)
113
+ register_driver("pgsql", PostgreSQLAdapter) # PDO / Laravel / Doctrine scheme name (issue #58)
113
114
 
114
115
  # Register MySQL (mysql-connector-python — optional)
115
116
  from tina4_python.database.mysql import MySQLAdapter
@@ -320,8 +320,9 @@ def write_mcp_discovery_file() -> None:
320
320
  expected = {
321
321
  "mcpServers": {
322
322
  "tina4-live-docs": {
323
- "url": f"http://localhost:{port}/__dev/api/mcp",
324
- "description": "Live API docs for this Tina4 project (framework + user code)",
323
+ "type": "http",
324
+ "url": f"http://localhost:{port}/__dev/mcp",
325
+ "description": "Live API docs + dev tools for this Tina4 project (framework + user code)",
325
326
  }
326
327
  }
327
328
  }
@@ -485,11 +486,13 @@ def get_api_handlers() -> dict:
485
486
  # @mcp_tool decorator appear in both immediately.
486
487
  "/__dev/api/mcp/tools": ("GET", _api_mcp_tools),
487
488
  "/__dev/api/mcp/call": ("POST", _api_mcp_call),
488
- # JSON-RPC + SSE surface for real MCP clients (Claude Desktop/Code).
489
- # Same registry as the REST shim above; this is what makes /__dev/mcp
490
- # actually reachable as an MCP server (previously defined but unmounted).
491
- "/__dev/mcp": ("POST", _api_mcp_rpc),
492
- "/__dev/mcp/message": ("POST", _api_mcp_rpc),
489
+ # MCP transport surface for real clients (Claude Code / Desktop).
490
+ # Same registry as the REST shim above. /__dev/mcp is the Streamable
491
+ # HTTP endpoint (POST message + DELETE session; "*" so one handler
492
+ # switches on the method); /message + /sse are the legacy HTTP+SSE
493
+ # transport, kept working for older SSE-only clients.
494
+ "/__dev/mcp": ("*", _api_mcp_endpoint),
495
+ "/__dev/mcp/message": ("POST", _api_mcp_message),
493
496
  "/__dev/mcp/sse": ("GET", _api_mcp_sse),
494
497
  # ── Scaffold REST shim ──
495
498
  # Wraps the tina4python CLI's `generate <kind> <name>` so the
@@ -2964,43 +2967,102 @@ async def _api_mcp_call(request, response):
2964
2967
  return response({"ok": False, "name": name, "error": str(exc)}, 500)
2965
2968
 
2966
2969
 
2967
- # ─── MCP JSON-RPC + SSE endpoint ───────────────────────────────────
2970
+ # ─── MCP transport endpoint ────────────────────────────────────────
2968
2971
  #
2969
- # The protocol surface real MCP clients (Claude Desktop/Code) speak
2970
- # JSON-RPC 2.0 over the HTTP+SSE transport. Mounted on the running dev
2971
- # server so each `tina4 serve`d project exposes its OWN endpoint, giving
2972
- # an AI agent live access scoped to that project. Shares the same
2973
- # `_default_server` tool registry as the REST shim above, so every
2974
- # @mcp_tool shows up on both surfaces.
2975
-
2976
- async def _api_mcp_rpc(request, response):
2977
- """POST the JSON-RPC endpoint. Mounted at /__dev/mcp and
2978
- /__dev/mcp/message. Forwards to the default MCP server's
2979
- handle_message() and returns the JSON-RPC response; notifications
2980
- (no id) yield an empty 204.
2981
- """
2972
+ # The protocol surface real MCP clients (Claude Code / Claude Desktop)
2973
+ # speak. Mounted on the running dev server so each `tina4 serve`d project
2974
+ # exposes its OWN endpoint, giving an AI agent live access scoped to that
2975
+ # project. Shares the same `_default_server` tool registry as the REST
2976
+ # shim above, so every @mcp_tool shows up on all surfaces.
2977
+ #
2978
+ # Two transports live here:
2979
+ # * Streamable HTTP (current) — POST /__dev/mcp with the JSON-RPC message;
2980
+ # the response comes back inline as application/json, and initialize
2981
+ # issues an Mcp-Session-Id header the client echoes on later requests.
2982
+ # GET is 405 (this server initiates no messages) and DELETE ends a
2983
+ # session.
2984
+ # * Legacy HTTP+SSE (2024-11-05) — GET /__dev/mcp/sse opens a persistent
2985
+ # stream that first names the POST endpoint, then delivers each JSON-RPC
2986
+ # response as an SSE `message` event; POST /__dev/mcp/message feeds it.
2987
+ # Kept working for older SSE-only clients.
2988
+
2989
+
2990
+ def _mcp_session_header(request) -> str:
2991
+ """Read the Mcp-Session-Id request header (empty string when absent)."""
2992
+ headers = getattr(request, "headers", None) or {}
2993
+ return headers.get("mcp-session-id", "") or ""
2994
+
2995
+
2996
+ def _mcp_apply(response, outcome):
2997
+ """Apply a dispatch_http/dispatch_sse_message result dict (status,
2998
+ headers, body) onto the dev-admin response."""
2982
2999
  import json as _json
3000
+ for name, value in outcome["headers"].items():
3001
+ response.header(name, value)
3002
+ body = outcome["body"]
3003
+ if not body:
3004
+ return response("", outcome["status"])
3005
+ return response(_json.loads(body), outcome["status"])
3006
+
3007
+
3008
+ async def _api_mcp_endpoint(request, response):
3009
+ """The Streamable HTTP endpoint at /__dev/mcp (method wildcard).
3010
+
3011
+ POST — a JSON-RPC message; response is inline application/json.
3012
+ GET — 405, this server pushes no unsolicited messages (use the
3013
+ legacy /sse stream if you need server-initiated framing).
3014
+ DELETE — terminate the session named by Mcp-Session-Id.
3015
+ """
2983
3016
  from tina4_python.mcp import _get_default_server
2984
3017
  if not _mcp_request_allowed(request):
2985
3018
  return response({"error": "MCP disabled"}, 404)
2986
3019
  server = _get_default_server()
2987
- body = request.body
2988
- raw = body if isinstance(body, (dict, str)) else str(body)
2989
- result = server.handle_message(raw)
2990
- if not result:
3020
+ method = (getattr(request, "method", "") or "GET").upper()
3021
+
3022
+ if method == "POST":
3023
+ outcome = server.dispatch_http(request.body, _mcp_session_header(request))
3024
+ return _mcp_apply(response, outcome)
3025
+
3026
+ if method == "DELETE":
3027
+ server.close_session(_mcp_session_header(request))
2991
3028
  return response("", 204)
2992
- return response(_json.loads(result))
3029
+
3030
+ # GET (and anything else): no server-initiated stream on this endpoint.
3031
+ response.header("Allow", "POST, DELETE")
3032
+ return response({"error": "method not allowed"}, 405)
3033
+
3034
+
3035
+ async def _api_mcp_message(request, response):
3036
+ """POST /__dev/mcp/message — legacy HTTP+SSE message sink.
3037
+
3038
+ Delivers the JSON-RPC response on the matching open SSE stream (202
3039
+ here); with no open stream it degrades to an inline Streamable HTTP
3040
+ response, so the path also serves a plain POST client.
3041
+ """
3042
+ from tina4_python.mcp import _get_default_server
3043
+ if not _mcp_request_allowed(request):
3044
+ return response({"error": "MCP disabled"}, 404)
3045
+ server = _get_default_server()
3046
+ params = getattr(request, "params", None) or {}
3047
+ session_id = params.get("sessionId") or _mcp_session_header(request)
3048
+ outcome = server.dispatch_sse_message(request.body, session_id)
3049
+ return _mcp_apply(response, outcome)
2993
3050
 
2994
3051
 
2995
3052
  async def _api_mcp_sse(request, response):
2996
- """GET — SSE handshake. Emits the `endpoint` event telling the client
2997
- where to POST JSON-RPC messages, per the MCP HTTP+SSE transport.
3053
+ """GET /__dev/mcp/sse legacy HTTP+SSE stream.
3054
+
3055
+ Opens a persistent SSE connection: first the `endpoint` event naming the
3056
+ POST target (session-tagged), then each JSON-RPC response as it arrives.
2998
3057
  """
3058
+ from tina4_python.mcp import _get_default_server
2999
3059
  if not _mcp_request_allowed(request):
3000
3060
  return response({"error": "MCP disabled"}, 404)
3001
- base = request.path.rsplit("/sse", 1)[0]
3002
- sse = f"event: endpoint\ndata: {base}/message\n\n"
3003
- return response(sse, 200, "text/event-stream")
3061
+ server = _get_default_server()
3062
+ session_id = server.open_session()
3063
+ base = getattr(request, "path", "/__dev/mcp/sse").rsplit("/sse", 1)[0]
3064
+ endpoint_url = f"{base}/message?sessionId={session_id}"
3065
+ return response.stream(server.sse_stream(session_id, endpoint_url))
3004
3066
 
3005
3067
 
3006
3068
  # ─── Scaffold REST shim ────────────────────────────────────────────
@@ -383,6 +383,85 @@ Macros don't inherit parent context — pass everything explicitly via parameter
383
383
 
384
384
  ---
385
385
 
386
+ ## Live Blocks
387
+
388
+ A live block renders on the server, then keeps itself fresh. The first paint ships with the
389
+ page, so there is no loading flash. After that, the block re-fetches its own HTML and swaps
390
+ it in place. You write server-side Frond and the block stays current, with no hand-written
391
+ JavaScript.
392
+
393
+ ```twig
394
+ {% live "cart" poll 5 %}
395
+ <strong>{{ count }}</strong> items - {{ total | number_format(2) }}
396
+ {% endlive %}
397
+ ```
398
+
399
+ That block paints once with the page, then re-renders every 5 seconds. `frond.js` (already
400
+ loaded from `/js/frond.js`) finds the marker, calls `GET /__frond/live/cart`, and morphs the
401
+ returned HTML into place. A focused input and its caret survive the swap.
402
+
403
+ ### Transports
404
+
405
+ Pick how the block refreshes:
406
+
407
+ ```twig
408
+ {% live "cart" poll 5 %}...{% endlive %} {# re-fetch every 5 seconds #}
409
+ {% live "feed" sse %}...{% endlive %} {# Server-Sent Events stream #}
410
+ {% live "chat" ws "/ws/chat" %}...{% endlive %} {# WebSocket on /ws/chat #}
411
+ ```
412
+
413
+ `poll N` pulls every `N` seconds. `sse` and `ws` push: the server decides when to send. All
414
+ three render the same server-side body. Only the delivery changes.
415
+
416
+ ### The data source
417
+
418
+ A live block needs data on every refresh, not just the first paint. Register a provider by
419
+ name with `@live_source`. It runs on each refresh with the live request, so the block
420
+ re-renders against fresh data and re-applies auth every time. An unauthenticated caller never
421
+ sees another user's numbers.
422
+
423
+ ```python
424
+ from tina4_python.frond import live_source
425
+
426
+ @live_source("cart")
427
+ def cart_data(request):
428
+ user = request.session.get("user_id")
429
+ return {"count": cart_count(user), "total": cart_total(user)}
430
+ ```
431
+
432
+ The provider feeds the always-on endpoint `GET /__frond/live/{name}`. There is no route to
433
+ write. The block name is the route.
434
+
435
+ ### Pushing updates
436
+
437
+ A `ws` block can update the moment data changes, without waiting for the next poll. Call
438
+ `push_live(name, data)`. It re-renders the block and broadcasts the new HTML to every client
439
+ connected on the block's WebSocket path.
440
+
441
+ ```python
442
+ from tina4_python.frond import push_live
443
+
444
+ # after an order lands:
445
+ push_live("cart", {"count": 3, "total": 59.97})
446
+ ```
447
+
448
+ ### Same-origin only
449
+
450
+ A block can point at your own route with `src` instead of the auto endpoint:
451
+
452
+ ```twig
453
+ {% live "cart" poll 5 src "/fragments/cart" %}...{% endlive %}
454
+ ```
455
+
456
+ `src` must be a same-origin path. An absolute URL is rejected at render time, so a live block
457
+ never fetches from a host you did not write. Nested live blocks are rejected too.
458
+
459
+ The marker element is byte-identical across Python, PHP, Ruby, and Node, so the shared
460
+ `frond.js` drives every backend the same way. Write the block once. It renders anywhere
461
+ Tina4 runs.
462
+
463
+ ---
464
+
386
465
  ## Comments
387
466
 
388
467
  ```twig
@@ -0,0 +1,85 @@
1
+ # Tina4 Frond — Zero-dependency template engine.
2
+ """
3
+ Twig-like template engine built from scratch.
4
+
5
+ from tina4_python.frond import Frond
6
+
7
+ engine = Frond(template_dir="src/templates")
8
+ output = engine.render("page.html", {"name": "World"})
9
+ """
10
+ import inspect
11
+
12
+ from tina4_python.frond.engine import Frond
13
+
14
+
15
+ async def live_endpoint(name, request, response):
16
+ """GET /__frond/live/{name} - re-render a registered {% live %} fragment.
17
+
18
+ Resolves the @live_source provider for <name>, runs it with the LIVE request
19
+ so auth and session scoping re-apply on every refresh (a live "my cart"
20
+ cannot leak another user's data), renders the registered fragment, and
21
+ returns the HTML. 404 when the name is unknown or its fragment has not been
22
+ registered yet (the page carrying the block has not rendered).
23
+ """
24
+ provider = Frond._class_live_sources.get(name)
25
+ if name not in Frond._class_live_fragments and provider is None:
26
+ return response("live block not found: " + str(name), 404)
27
+ context = {}
28
+ if provider is not None:
29
+ result = provider(request)
30
+ if inspect.isawaitable(result):
31
+ result = await result
32
+ context = result or {}
33
+ html = Frond.render_live(name, context)
34
+ if html is None:
35
+ return response("live fragment not registered yet: " + str(name), 404)
36
+ return response(html)
37
+
38
+
39
+ async def push_live(name, data=None):
40
+ """Re-render the '<name>' live fragment and push it to connected clients.
41
+
42
+ Renders via Frond.render_live(name, data) and broadcasts a {type, name, html}
43
+ envelope over WebSocket: to the ws path the block declared (data-ws), or to a
44
+ room named <name> if the block declared none. Apps call this after a state
45
+ change (a new chat message, an order update). Returns the rendered HTML, or
46
+ None when the fragment is not registered (its page has not rendered).
47
+ """
48
+ html = Frond.render_live(name, data or {})
49
+ if html is None:
50
+ return None
51
+ import json
52
+ envelope = json.dumps({"type": "live", "name": name, "html": html})
53
+ try:
54
+ from tina4_python.core.server import _ws_manager
55
+ ws_path = Frond._class_live_ws_paths.get(name)
56
+ if ws_path:
57
+ await _ws_manager.broadcast(envelope, path=ws_path)
58
+ else:
59
+ await _ws_manager.broadcast_to_room(name, envelope)
60
+ except Exception as exc:
61
+ try:
62
+ from tina4_python.debug import Log
63
+ Log.error("push_live(" + str(name) + ") broadcast failed: " + str(exc))
64
+ except Exception:
65
+ pass
66
+ return html
67
+
68
+
69
+ def live_source(name: str):
70
+ """Register a data provider for a {% live %} block.
71
+
72
+ The decorated function receives the request and returns the context dict
73
+ used to re-render the fragment on refresh:
74
+
75
+ @live_source("notifications")
76
+ async def notifications(request):
77
+ return {"items": Notification.where("user_id = ?", [request.session["uid"]])}
78
+ """
79
+ def _wrap(fn):
80
+ Frond._class_live_sources[name] = fn
81
+ return fn
82
+ return _wrap
83
+
84
+
85
+ __all__ = ["Frond", "live_source", "live_endpoint", "push_live"]
@@ -117,6 +117,15 @@ _FILTER_CMP_RE = re.compile(r"(\w+)\s*(!=|==|>=|<=|>|<)\s*(.+)")
117
117
  _FOR_RE = re.compile(r"for\s+(\w+)(?:\s*,\s*(\w+))?\s+in\s+(.+)")
118
118
  _SET_RE = re.compile(r"set\s+(\w+)\s*=\s*(.+)", re.DOTALL)
119
119
  _INCLUDE_RE = re.compile(r'include\s+["\'](.+?)["\'](?:\s+with\s+(.+))?')
120
+ _LIVE_RE = re.compile(r'live\s+["\'](?P<name>[^"\']+)["\'](?P<rest>.*)$', re.DOTALL)
121
+ _LIVE_WS_RE = re.compile(r'ws\s+["\']([^"\']+)["\']')
122
+ _LIVE_SRC_RE = re.compile(r'src\s+["\']([^"\']+)["\']')
123
+
124
+
125
+ def _live_attr(value) -> str:
126
+ """Escape a value for use inside an HTML attribute on a live marker."""
127
+ return (str(value).replace("&", "&amp;").replace('"', "&quot;")
128
+ .replace("<", "&lt;").replace(">", "&gt;"))
120
129
  _MACRO_RE = re.compile(r"macro\s+(\w+)\s*\(([^)]*)\)")
121
130
  _FROM_IMPORT_RE = re.compile(r'from\s+["\'](.+?)["\']\s+import\s+(.+)')
122
131
  _IMPORT_AS_RE = re.compile(r'import\s+["\'](.+?)["\']\s+as\s+(\w+)')
@@ -1309,6 +1318,11 @@ class Frond:
1309
1318
  _class_globals: dict = {}
1310
1319
  _class_filters: dict = {}
1311
1320
  _class_tests: dict = {}
1321
+ # Live blocks: name -> body template source (registered when a {% live %}
1322
+ # block renders); name -> data provider (registered via @live_source).
1323
+ _class_live_fragments: dict = {}
1324
+ _class_live_sources: dict = {}
1325
+ _class_live_ws_paths: dict = {}
1312
1326
 
1313
1327
  @classmethod
1314
1328
  def clear_registry(cls):
@@ -1320,6 +1334,9 @@ class Frond:
1320
1334
  cls._class_globals.clear()
1321
1335
  cls._class_filters.clear()
1322
1336
  cls._class_tests.clear()
1337
+ cls._class_live_fragments.clear()
1338
+ cls._class_live_sources.clear()
1339
+ cls._class_live_ws_paths.clear()
1323
1340
 
1324
1341
  def __init__(self, template_dir: str = "src/templates"):
1325
1342
  self.template_dir = Path(template_dir)
@@ -1766,6 +1783,11 @@ class Frond:
1766
1783
  output.append(result)
1767
1784
  i = skip
1768
1785
 
1786
+ elif tag == "live":
1787
+ result, skip = self._handle_live(tokens, i, context)
1788
+ output.append(result)
1789
+ i = skip
1790
+
1769
1791
  elif tag in ("block", "endblock", "extends"):
1770
1792
  i += 1 # Already handled
1771
1793
 
@@ -2396,6 +2418,93 @@ class Frond:
2396
2418
  self._fragment_cache[cache_key] = (rendered, time.time() + ttl)
2397
2419
  return rendered, i
2398
2420
 
2421
+ def _handle_live(self, tokens: list, start: int, context: dict) -> tuple[str, int]:
2422
+ """Handle {% live "name" poll N | sse | ws "path" [src "url"] %}...{% endlive %}.
2423
+
2424
+ Server-rendered live region. The body renders once for first paint, is
2425
+ registered under <name> so the /__frond/live/<name> endpoint (or a
2426
+ @live_source provider) can re-render it, and is wrapped in a marker
2427
+ element that frond.js wires to the chosen transport (poll / sse / ws).
2428
+ """
2429
+ content, _, _ = _strip_tag(tokens[start][1])
2430
+ m = _LIVE_RE.match(content)
2431
+ if not m:
2432
+ raise ValueError('live: expected {% live "name" poll N | sse | ws "path" %}')
2433
+ name = m.group("name")
2434
+ rest = (m.group("rest") or "").strip()
2435
+ parts = rest.split()
2436
+ mode = parts[0] if parts else ""
2437
+
2438
+ src = None
2439
+ sm = _LIVE_SRC_RE.search(rest)
2440
+ if sm:
2441
+ src = sm.group(1)
2442
+ if src and (src.startswith("http://") or src.startswith("https://") or src.startswith("//")):
2443
+ raise ValueError("live: src must be a same-origin path, not an absolute URL")
2444
+
2445
+ interval = None
2446
+ ws_path = None
2447
+ if mode == "poll":
2448
+ if len(parts) < 2 or not parts[1].isdigit():
2449
+ raise ValueError('live: poll requires seconds, e.g. {% live "x" poll 5 %}')
2450
+ interval = int(parts[1])
2451
+ elif mode == "sse":
2452
+ pass
2453
+ elif mode == "ws":
2454
+ wm = _LIVE_WS_RE.search(rest)
2455
+ if not wm:
2456
+ raise ValueError('live: ws requires a path, e.g. {% live "x" ws "/ws/x" %}')
2457
+ ws_path = wm.group(1)
2458
+ else:
2459
+ raise ValueError(f'live: unknown transport "{mode}" (use poll N, sse, or ws "path")')
2460
+
2461
+ # Collect body tokens up to {% endlive %}. Nested live is unsupported.
2462
+ body_tokens = []
2463
+ i = start + 1
2464
+ while i < len(tokens):
2465
+ if tokens[i][0] == BLOCK:
2466
+ tag_content, _, _ = _strip_tag(tokens[i][1])
2467
+ tag = tag_content.split()[0] if tag_content.split() else ""
2468
+ if tag == "live":
2469
+ raise ValueError("live: nested live blocks are not supported")
2470
+ if tag == "endlive":
2471
+ i += 1
2472
+ break
2473
+ body_tokens.append(tokens[i])
2474
+ else:
2475
+ body_tokens.append(tokens[i])
2476
+ i += 1
2477
+
2478
+ # Register the body source so the auto endpoint can re-render it.
2479
+ Frond._class_live_fragments[name] = "".join(raw for (_t, raw) in body_tokens)
2480
+
2481
+ endpoint = src or ("/__frond/live/" + name)
2482
+ attrs = [f'data-frond-live="{_live_attr(name)}"', f'id="live-{_live_attr(name)}"']
2483
+ if mode == "poll":
2484
+ attrs += ['data-mode="poll"', f'data-interval="{interval}"',
2485
+ f'data-src="{_live_attr(endpoint)}"']
2486
+ elif mode == "sse":
2487
+ attrs += ['data-mode="sse"', f'data-src="{_live_attr(endpoint)}"']
2488
+ elif mode == "ws":
2489
+ Frond._class_live_ws_paths[name] = ws_path
2490
+ attrs += ['data-mode="ws"', f'data-ws="{_live_attr(ws_path)}"']
2491
+
2492
+ first_paint = self._render_tokens(list(body_tokens), context)
2493
+ return f'<div {" ".join(attrs)}>{first_paint}</div>', i
2494
+
2495
+ @classmethod
2496
+ def render_live(cls, name: str, data: dict = None):
2497
+ """Re-render a registered {% live %} fragment by name.
2498
+
2499
+ Returns the rendered HTML fragment, or None if no fragment is registered
2500
+ under that name yet (the page carrying the block has not rendered). The
2501
+ /__frond/live/<name> endpoint calls this after resolving the provider data.
2502
+ """
2503
+ source = cls._class_live_fragments.get(name)
2504
+ if source is None:
2505
+ return None
2506
+ return cls().render_string(source, data or {})
2507
+
2399
2508
  def _handle_spaceless(self, tokens: list, start: int, context: dict) -> tuple[str, int]:
2400
2509
  """Handle {% spaceless %}...{% endspaceless %}.
2401
2510