fastapi-fullstack 0.2.20__py3-none-any.whl → 0.2.21__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.
- {fastapi_fullstack-0.2.20.dist-info → fastapi_fullstack-0.2.21.dist-info}/METADATA +1 -1
- {fastapi_fullstack-0.2.20.dist-info → fastapi_fullstack-0.2.21.dist-info}/RECORD +18 -16
- fastapi_gen/UPGRADES.yaml +4 -0
- fastapi_gen/template/hooks/post_gen_project.py +20 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/alembic/env.py +3 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/alembic/versions/0027_user_magic_link_epoch.py +4 -2
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/repositories/user.py +8 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/services/agent.py +35 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/services/agent_session.py +66 -9
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/services/user.py +10 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/tests/test_conversation_resume.py +177 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/tests/test_deep_research_streaming.py +85 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/tests/test_memory.py +25 -1
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/tests/test_migrations.py +19 -9
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/tests/test_pydantic_deep_history.py +2 -0
- {fastapi_fullstack-0.2.20.dist-info → fastapi_fullstack-0.2.21.dist-info}/WHEEL +0 -0
- {fastapi_fullstack-0.2.20.dist-info → fastapi_fullstack-0.2.21.dist-info}/entry_points.txt +0 -0
- {fastapi_fullstack-0.2.20.dist-info → fastapi_fullstack-0.2.21.dist-info}/licenses/LICENSE +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: fastapi-fullstack
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.21
|
|
4
4
|
Summary: Full-stack FastAPI + Next.js template generator with Pydantic AI/LangChain agents, WebSocket streaming, 20+ enterprise integrations, and Logfire/LangSmith observability. Ship AI apps fast.
|
|
5
5
|
Project-URL: Homepage, https://github.com/vstorm-co/full-stack-ai-agent-template
|
|
6
6
|
Project-URL: Documentation, https://vstorm-co.github.io/full-stack-ai-agent-template/
|
|
@@ -17,10 +17,10 @@ fastapi_gen/upgrade/rename_guard.py,sha256=ap0ds5k93Hh6hhQhOxrDPsh-utTE1BeBYysrT
|
|
|
17
17
|
fastapi_gen/upgrade/render.py,sha256=PmEm7BPmEfUK29RcVgPN9PttTX7oHeWnDgf_vgGja1s,5497
|
|
18
18
|
fastapi_gen/upgrade/report.py,sha256=49v9kq2tkbeqqbdH-kRIM3kccaFfPVfjhi7Tm5cCVvE,3802
|
|
19
19
|
fastapi_gen/upgrade/runner.py,sha256=msnj2RYii6low6gPeZ4TRMlL01Hq8a0zJyLBzPotxCI,19302
|
|
20
|
-
fastapi_gen/UPGRADES.yaml,sha256=
|
|
20
|
+
fastapi_gen/UPGRADES.yaml,sha256=KWHs_vnhxjjsYXVNZkIGwLPxZsJlVkxIzTBlAXkcal0,5718
|
|
21
21
|
fastapi_gen/template/VARIABLES.md,sha256=GEk5LqrItHC66PBYmmi5lokwzxDxGiLvnhlsZOw97JA,35410
|
|
22
22
|
fastapi_gen/template/cookiecutter.json,sha256=e1xSqG9i-CTsux-nnCUWf6v7So67_jAp_puf_siHMWs,6397
|
|
23
|
-
fastapi_gen/template/hooks/post_gen_project.py,sha256=
|
|
23
|
+
fastapi_gen/template/hooks/post_gen_project.py,sha256=jNj3O7jIQyZysbVGevtcEqzjHyYtlXRnyToPyO1x06g,61785
|
|
24
24
|
fastapi_gen/template/{{cookiecutter.project_slug}}/.gitignore,sha256=yC3ZUp8Txp_1TPDabDlz4pGa2p1cNwr49de0dCcctOw,1515
|
|
25
25
|
fastapi_gen/template/{{cookiecutter.project_slug}}/.gitlab-ci.yml,sha256=SYDjmai3eKIiz4MbiEBHm4hBA_Ksu3Pk4Enr7cGk46Y,4659
|
|
26
26
|
fastapi_gen/template/{{cookiecutter.project_slug}}/AGENTS.md,sha256=HqhXNdBq1ZXlFJCC4V3CY8DorTkZkwFJcvv2O77Pwk4,2454
|
|
@@ -61,7 +61,7 @@ fastapi_gen/template/{{cookiecutter.project_slug}}/backend/.pre-commit-config.ya
|
|
|
61
61
|
fastapi_gen/template/{{cookiecutter.project_slug}}/backend/Dockerfile,sha256=CKyuUKwt41LHIH9VB28TEzes5_TQkUEo9rIBjE3v8a8,2184
|
|
62
62
|
fastapi_gen/template/{{cookiecutter.project_slug}}/backend/alembic.ini,sha256=vncO8XHTAW1ospWsdvtXD5PyMhp91CJmdVfv-6TakAY,737
|
|
63
63
|
fastapi_gen/template/{{cookiecutter.project_slug}}/backend/pyproject.toml,sha256=sqvn2EcWc1Q1jxFK6680ZMPbz2wztpxBqbq0UMDmHCY,15908
|
|
64
|
-
fastapi_gen/template/{{cookiecutter.project_slug}}/backend/alembic/env.py,sha256=
|
|
64
|
+
fastapi_gen/template/{{cookiecutter.project_slug}}/backend/alembic/env.py,sha256=Zj7Sgd09NmvRvXDK4yqKf31cflg4n-uUGZRZL7lXS3k,3654
|
|
65
65
|
fastapi_gen/template/{{cookiecutter.project_slug}}/backend/alembic/script.py.mako,sha256=ZCfgWrEMJRDF_WF_GRGptwAIJI6YnAditBG1axwAP9Q,700
|
|
66
66
|
fastapi_gen/template/{{cookiecutter.project_slug}}/backend/alembic/versions/.gitkeep,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
67
67
|
fastapi_gen/template/{{cookiecutter.project_slug}}/backend/alembic/versions/0000_create_users.py,sha256=nbctAgtZhw4rX2LxlBcyXL398aYFI-8RFpEOkvVb88M,2048
|
|
@@ -91,7 +91,7 @@ fastapi_gen/template/{{cookiecutter.project_slug}}/backend/alembic/versions/0023
|
|
|
91
91
|
fastapi_gen/template/{{cookiecutter.project_slug}}/backend/alembic/versions/0024_create_webhook_tables.py,sha256=HExnIhQAJXNCe1vxhagIhUr0BeBBv2MTBadQEY4GtY8,3233
|
|
92
92
|
fastapi_gen/template/{{cookiecutter.project_slug}}/backend/alembic/versions/0025_message_thinking.py,sha256=8Wi3zcAXADP6WbjuB-Na_Y_OZTx6DDETkrZAVrNEdl8,727
|
|
93
93
|
fastapi_gen/template/{{cookiecutter.project_slug}}/backend/alembic/versions/0026_create_mcp_connections.py,sha256=ADbedBphmfFnRiZ7fssMjD2fgfqz6YIUf7F2DguKm68,3188
|
|
94
|
-
fastapi_gen/template/{{cookiecutter.project_slug}}/backend/alembic/versions/0027_user_magic_link_epoch.py,sha256=
|
|
94
|
+
fastapi_gen/template/{{cookiecutter.project_slug}}/backend/alembic/versions/0027_user_magic_link_epoch.py,sha256=M0mo6oM4b0KAJA9E_do670NFOtxH05J84zWaWp2F4Cg,1619
|
|
95
95
|
fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/__init__.py,sha256=vNnuyVXC5oZ3yq46meWLNhkUYlMgod70TgvWyvgNhBk,68
|
|
96
96
|
fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/admin.py,sha256=jK6iIS4OlsSBID2xZOYWZCEndpSAhxwclc_lceZKIUI,14043
|
|
97
97
|
fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/main.py,sha256=n0zgtG3bbJFFavlQv2_nG4ILdNglgYr7vIZq8uuIJIA,18931
|
|
@@ -230,7 +230,7 @@ fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/repositories/subs
|
|
|
230
230
|
fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/repositories/sync_log.py,sha256=OvRWm90MlfJ-lrljtU-71NoOVbqn4guHm99LMQe3qo4,2562
|
|
231
231
|
fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/repositories/sync_source.py,sha256=nCGKUgOUpCEBNEySqdKgZyf_GBKBgtYfFsCco_WykTc,3846
|
|
232
232
|
fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/repositories/usage_event.py,sha256=R9BqsRQTgqmxQOyKdr12dcrrkEWUoAMEy_4gWbfHJsE,5367
|
|
233
|
-
fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/repositories/user.py,sha256=
|
|
233
|
+
fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/repositories/user.py,sha256=UXpGdMKKScgC9yCHG_Hmlfhahk-b4taSydrZPG3AnyE,6172
|
|
234
234
|
fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/repositories/user_slash_command.py,sha256=85ANcoeRNFQE08t8-iuh9XJqpgVYB9fy-E2f5kt6QY0,2121
|
|
235
235
|
fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/repositories/webhook.py,sha256=gEjUe-xVHvUOTD4tTJxr0SDiHAaJ-DtUN_TZlqlIjXA,3969
|
|
236
236
|
fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/schemas/__init__.py,sha256=gAqdgjm0KBxNSEsFthF6URbtPjdEBuQpna_2q9wcMrQ,1996
|
|
@@ -260,9 +260,9 @@ fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/schemas/user_slas
|
|
|
260
260
|
fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/schemas/webhook.py,sha256=VRwBD9l_lBfnPjQxp8kg4DOLyd6FCAUj5BZjoXZN0oI,2166
|
|
261
261
|
fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/services/__init__.py,sha256=2eaFa3riNnh9BVf4A6i7ChK1yqCOA8VyTg1zeL2tYy0,523
|
|
262
262
|
fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/services/admin.py,sha256=FzwzW6FpIx1Ciwj_9lCbWMzi-EWv3v2-J8Sopi9LiZU,5576
|
|
263
|
-
fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/services/agent.py,sha256=
|
|
263
|
+
fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/services/agent.py,sha256=ifWh0ryiT8PpR0zyXGx-cnVr8fwa3wTKquEl85tZatA,14137
|
|
264
264
|
fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/services/agent_invocation.py,sha256=kh3KQA1mKg1AKnpf70hCdUCblqs4x_zdNyfMH7NjmhU,18321
|
|
265
|
-
fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/services/agent_session.py,sha256
|
|
265
|
+
fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/services/agent_session.py,sha256=-VOhjAGNJVZLKB0iozFac5WSOLz5o9nEwMT8eW-87ng,122375
|
|
266
266
|
fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/services/anomaly_detection.py,sha256=uKPCzzdeyDSUbgkD7VwFIubEHhoU1LEoOp3R1_F0SlE,3112
|
|
267
267
|
fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/services/channel_bot.py,sha256=R1tfQQcNxHKZ9C3yOD6Hh4TANY77FL4XNic4Rf40qWo,6383
|
|
268
268
|
fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/services/contact.py,sha256=AuML8RHIozZkchZlNMjHsZhLWpTMxukfy1xk6mak3Bk,1697
|
|
@@ -287,7 +287,7 @@ fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/services/research
|
|
|
287
287
|
fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/services/session.py,sha256=mABDVV3lMvmJsprr-y_XSMQ8hTb4PIEnK_bn5jasUUw,4103
|
|
288
288
|
fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/services/sync_source.py,sha256=geoKqmIjDgxAzS5Jmm2qW7fdAl9i_1ZgfiGFMNf951k,12199
|
|
289
289
|
fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/services/usage.py,sha256=SUNAEnnOZjXr_PXoFGjfkMjAw7aB5FvIHReeAVI4wx8,3756
|
|
290
|
-
fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/services/user.py,sha256=
|
|
290
|
+
fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/services/user.py,sha256=LCQKKAfhMHvqKVqofF5MnPgN1JrpHQMvE2i8aqttyvg,15966
|
|
291
291
|
fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/services/user_memory.py,sha256=Q-2qwUi945EMqmRrlRU4igwGd1M3cD0ZngQTgGldSlU,8198
|
|
292
292
|
fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/services/user_slash_command.py,sha256=t1-IIExupr-pvhCt_JjmiLrWfzMEzR2cDcLfhfPVRCQ,5427
|
|
293
293
|
fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/services/webhook.py,sha256=RCT96wAQDnr8CUG9_gzXYxi-Av3BXzjbl0BnxNY1qWw,7500
|
|
@@ -367,17 +367,19 @@ fastapi_gen/template/{{cookiecutter.project_slug}}/backend/tests/test_chart_tool
|
|
|
367
367
|
fastapi_gen/template/{{cookiecutter.project_slug}}/backend/tests/test_clients.py,sha256=qKU2z4YVQMWdnNE9aH5lnACsdzQ1G4fcE9_sK8x7K2U,6282
|
|
368
368
|
fastapi_gen/template/{{cookiecutter.project_slug}}/backend/tests/test_commands.py,sha256=G7pRJgk0pDQRBIFUIhi0bbDnujwKcWCjCP9Q1D9TzYA,4894
|
|
369
369
|
fastapi_gen/template/{{cookiecutter.project_slug}}/backend/tests/test_conversation_kb_toggle.py,sha256=ZDlX1lMuLl4q41g0f8IE0oPt3lbca4an_8c19Z1xyo8,3888
|
|
370
|
+
fastapi_gen/template/{{cookiecutter.project_slug}}/backend/tests/test_conversation_resume.py,sha256=593RkGdKXer2kX_-KaLSwuc_uQn2F1HRL29fI_SvH40,6139
|
|
370
371
|
fastapi_gen/template/{{cookiecutter.project_slug}}/backend/tests/test_conversation_write_access.py,sha256=1srJF_IkCMZxoSxnEqN7YW2LSZzDo0tkXQ-1i_RaesM,4561
|
|
371
372
|
fastapi_gen/template/{{cookiecutter.project_slug}}/backend/tests/test_core.py,sha256=dF_RgCNrHnI3PqhOVqqcYg_XgcDPCmkR_YWw6POCngw,5973
|
|
373
|
+
fastapi_gen/template/{{cookiecutter.project_slug}}/backend/tests/test_deep_research_streaming.py,sha256=5I5D3GcGTcvUU4a-3ohOegUlsQmuYQkkL4OB1FSNqoo,2772
|
|
372
374
|
fastapi_gen/template/{{cookiecutter.project_slug}}/backend/tests/test_fetch_url.py,sha256=ZnPxBUYH6KyAWcQf1MTEQEUvb7tpDhXcmbVKRLR2Xuw,3595
|
|
373
375
|
fastapi_gen/template/{{cookiecutter.project_slug}}/backend/tests/test_kb_scoping.py,sha256=fEV6jEaPtW5oNyRBDAA_S2jHS2QyxXWmOG-EKhYD7Hk,6573
|
|
374
376
|
fastapi_gen/template/{{cookiecutter.project_slug}}/backend/tests/test_mcp_connections.py,sha256=SuyqG3pLHx3GOzte48M09sp-Aes5ikd2kxwbMYE8xLA,34833
|
|
375
|
-
fastapi_gen/template/{{cookiecutter.project_slug}}/backend/tests/test_memory.py,sha256=
|
|
377
|
+
fastapi_gen/template/{{cookiecutter.project_slug}}/backend/tests/test_memory.py,sha256=nRh_rsqsDzS50XlKxiQ6b1A2JlKgX0dqHOgri15zC70,13667
|
|
376
378
|
fastapi_gen/template/{{cookiecutter.project_slug}}/backend/tests/test_memory_channels.py,sha256=NK_YcOGSaZwVY8f9vFGN_oSN62enAUa00zsXLakdTYE,1964
|
|
377
379
|
fastapi_gen/template/{{cookiecutter.project_slug}}/backend/tests/test_memory_postgres.py,sha256=aZcaCFkefQwqZiyioKF8Iot-TbC9IKu-ETZMeksGVsc,4868
|
|
378
|
-
fastapi_gen/template/{{cookiecutter.project_slug}}/backend/tests/test_migrations.py,sha256=
|
|
380
|
+
fastapi_gen/template/{{cookiecutter.project_slug}}/backend/tests/test_migrations.py,sha256=wf0DEAT8-WIe9YT7PZ6zUUN68OjLC1D8vQJZrfkLJ8Y,3946
|
|
379
381
|
fastapi_gen/template/{{cookiecutter.project_slug}}/backend/tests/test_openai_compatible.py,sha256=B2lxdMq6jp8s6vWGBqlIm-ZT7fFR1nmuSFtWRMnt0ak,2123
|
|
380
|
-
fastapi_gen/template/{{cookiecutter.project_slug}}/backend/tests/test_pydantic_deep_history.py,sha256=
|
|
382
|
+
fastapi_gen/template/{{cookiecutter.project_slug}}/backend/tests/test_pydantic_deep_history.py,sha256=8DVGxSYr98AzDA-bJcJZ-GuPEDu2ynpxUitB-TlVgyA,5833
|
|
381
383
|
fastapi_gen/template/{{cookiecutter.project_slug}}/backend/tests/test_rbac_teams.py,sha256=ryLOK_4YMtSBfRqeVFEnvcQXoGkQEpDrX0OAsCmm-v8,7037
|
|
382
384
|
fastapi_gen/template/{{cookiecutter.project_slug}}/backend/tests/test_repositories.py,sha256=uQHtc5I5OZpWnO7rC1Y8C7uw1WZWtG_HNWwxpI2OhtM,1286
|
|
383
385
|
fastapi_gen/template/{{cookiecutter.project_slug}}/backend/tests/test_repositories_teams.py,sha256=bIvtIATkynFWyvi81zXphiVyFf1cWu6qgRiB-EQzgMo,9675
|
|
@@ -942,8 +944,8 @@ fastapi_gen/template/{{cookiecutter.project_slug}}/kubernetes/service.yaml,sha25
|
|
|
942
944
|
fastapi_gen/template/{{cookiecutter.project_slug}}/nginx/nginx.conf,sha256=2bWaxnv_rN4driEdtWgVz9eVfoKhB_Ohd_G8eOC3P3M,7619
|
|
943
945
|
fastapi_gen/template/{{cookiecutter.project_slug}}/nginx/ssl/.gitkeep,sha256=o_WQQOgVGOLttT48x0EXSC4BbbDFemApFpmwhybcVUU,617
|
|
944
946
|
fastapi_gen/template/{{cookiecutter.project_slug}}/scripts/export_demo_html.py,sha256=H1tbIfr1xrh2pRuoy5NwvAOYEu0S2vgnw_XsKNMKXeM,10414
|
|
945
|
-
fastapi_fullstack-0.2.
|
|
946
|
-
fastapi_fullstack-0.2.
|
|
947
|
-
fastapi_fullstack-0.2.
|
|
948
|
-
fastapi_fullstack-0.2.
|
|
949
|
-
fastapi_fullstack-0.2.
|
|
947
|
+
fastapi_fullstack-0.2.21.dist-info/METADATA,sha256=dnLShNPQ-TzouakLsKIBenWSCX-EgLK2n7SfgeZklrE,62263
|
|
948
|
+
fastapi_fullstack-0.2.21.dist-info/WHEEL,sha256=W3fkpkm7-wf9vBI5Z-7s0eWkeM-spu78I8Neb98DeEg,87
|
|
949
|
+
fastapi_fullstack-0.2.21.dist-info/entry_points.txt,sha256=s9JXrISZp8LMYJGeVofOAd1wPTzpq-jwjSgSf4hWzjs,59
|
|
950
|
+
fastapi_fullstack-0.2.21.dist-info/licenses/LICENSE,sha256=bL4JuK_rcA8y__Gg7PEuTs3g2Qf6VvSz2w2Jajd6nVU,1063
|
|
951
|
+
fastapi_fullstack-0.2.21.dist-info/RECORD,,
|
fastapi_gen/UPGRADES.yaml
CHANGED
|
@@ -18,6 +18,10 @@
|
|
|
18
18
|
# manual_steps:
|
|
19
19
|
# - "Run `alembic upgrade head` (new billing tables)."
|
|
20
20
|
|
|
21
|
+
- version: "0.2.21"
|
|
22
|
+
manual_steps:
|
|
23
|
+
- "Run `alembic upgrade head`. Since 0.2.19, projects without --mcp-client could not migrate past 0025 (`KeyError: '0026_create_mcp_connections'`); with the corrected chain the pending migrations apply, including 0027 (users.magic_link_epoch, which magic-link sign-in reads when --email is on)."
|
|
24
|
+
|
|
21
25
|
- version: "0.2.20"
|
|
22
26
|
breaking:
|
|
23
27
|
- "Redis is replaced by Valkey (valkey/valkey:9-alpine) in the compose files and the generated CI. The protocol, the redis client, the REDIS_* settings and the `redis` service name are unchanged."
|
|
@@ -255,6 +255,8 @@ if not enable_subagents and use_frontend:
|
|
|
255
255
|
|
|
256
256
|
if not use_ai:
|
|
257
257
|
remove_dir(os.path.join(backend_app, "agents"))
|
|
258
|
+
# Its module goes below; a test left behind fails the whole run at collection.
|
|
259
|
+
remove_file(os.path.join(os.getcwd(), "backend", "tests", "test_services_conversation.py"))
|
|
258
260
|
remove_dir(os.path.join(os.getcwd(), ".claude", "skills", "agent-tool"))
|
|
259
261
|
remove_file(os.path.join(backend_app, "services", "agent.py"))
|
|
260
262
|
remove_file(os.path.join(backend_app, "services", "agent_session.py"))
|
|
@@ -516,6 +518,24 @@ if "{{ cookiecutter.use_pydantic_deep }}" != "True":
|
|
|
516
518
|
if not (use_slack or use_telegram):
|
|
517
519
|
remove_file(os.path.join(os.getcwd(), "backend", "tests", "test_channel_history.py"))
|
|
518
520
|
|
|
521
|
+
# The deep-research streaming tests render to a stub without it.
|
|
522
|
+
if not (
|
|
523
|
+
"{{ cookiecutter.use_pydantic_ai }}" == "True"
|
|
524
|
+
and "{{ cookiecutter.enable_deep_research }}" == "True"
|
|
525
|
+
):
|
|
526
|
+
remove_file(os.path.join(os.getcwd(), "backend", "tests", "test_deep_research_streaming.py"))
|
|
527
|
+
|
|
528
|
+
# The conversation-resume tests render to a stub without a database and a
|
|
529
|
+
# Pydantic AI-based agent.
|
|
530
|
+
if not (
|
|
531
|
+
"{{ cookiecutter.use_database }}" == "True"
|
|
532
|
+
and (
|
|
533
|
+
"{{ cookiecutter.use_pydantic_ai }}" == "True"
|
|
534
|
+
or "{{ cookiecutter.use_pydantic_deep }}" == "True"
|
|
535
|
+
)
|
|
536
|
+
):
|
|
537
|
+
remove_file(os.path.join(os.getcwd(), "backend", "tests", "test_conversation_resume.py"))
|
|
538
|
+
|
|
519
539
|
# Scan all .py files under backend/app — catches any template that rendered to
|
|
520
540
|
# a stub docstring because its feature gate was disabled.
|
|
521
541
|
for root, _dirs, files in os.walk(backend_app):
|
|
@@ -22,10 +22,13 @@ from app.db.base import Base
|
|
|
22
22
|
{%- if cookiecutter.use_jwt %}
|
|
23
23
|
from app.db.models.user import User # noqa: F401
|
|
24
24
|
{%- endif %}
|
|
25
|
+
{%- if cookiecutter.use_ai %}
|
|
26
|
+
# Generated only with an AI framework; the core-tables migration creates them regardless.
|
|
25
27
|
from app.db.models.conversation import Conversation, Message, ToolCall # noqa: F401
|
|
26
28
|
{%- if cookiecutter.use_jwt %}
|
|
27
29
|
from app.db.models.message_rating import MessageRating # noqa: F401
|
|
28
30
|
{%- endif %}
|
|
31
|
+
{%- endif %}
|
|
29
32
|
{%- if cookiecutter.enable_session_management and cookiecutter.use_jwt %}
|
|
30
33
|
from app.db.models.session import Session # noqa: F401
|
|
31
34
|
{%- endif %}
|
|
@@ -17,7 +17,8 @@ import sqlalchemy as sa
|
|
|
17
17
|
from alembic import op
|
|
18
18
|
|
|
19
19
|
revision = "0027_user_magic_link_epoch"
|
|
20
|
-
|
|
20
|
+
# 0026 exists only with the MCP client.
|
|
21
|
+
down_revision = "{% if cookiecutter.enable_mcp_client %}0026_create_mcp_connections{% else %}0025{% endif %}"
|
|
21
22
|
branch_labels = None
|
|
22
23
|
depends_on = None
|
|
23
24
|
|
|
@@ -41,7 +42,8 @@ magic-link sign-in) is disabled.
|
|
|
41
42
|
"""
|
|
42
43
|
|
|
43
44
|
revision = "0027_user_magic_link_epoch"
|
|
44
|
-
|
|
45
|
+
# 0026 exists only with the MCP client.
|
|
46
|
+
down_revision = "{% if cookiecutter.enable_mcp_client %}0026_create_mcp_connections{% else %}0025{% endif %}"
|
|
45
47
|
branch_labels = None
|
|
46
48
|
depends_on = None
|
|
47
49
|
|
|
@@ -143,6 +143,14 @@ async def delete(db: AsyncSession, user_id: UUID) -> User | None:
|
|
|
143
143
|
return user
|
|
144
144
|
|
|
145
145
|
|
|
146
|
+
{%- if cookiecutter.enable_memory %}
|
|
147
|
+
async def list_non_admin_ids(db: AsyncSession) -> list[UUID]:
|
|
148
|
+
"""Ids of the users without the admin role - those ``delete_non_admins`` removes."""
|
|
149
|
+
result = await db.execute(select(User.id).where(User.role != "admin"))
|
|
150
|
+
return list(result.scalars().all())
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
{%- endif %}
|
|
146
154
|
async def delete_non_admins(db: AsyncSession) -> int:
|
|
147
155
|
"""Bulk-delete users without the admin role. Returns affected row count."""
|
|
148
156
|
result = await db.execute(sql_delete(User).where(User.role != "admin"))
|
|
@@ -233,6 +233,41 @@ def normalize_tool_args(args: Any) -> dict[str, Any]:
|
|
|
233
233
|
return args
|
|
234
234
|
|
|
235
235
|
|
|
236
|
+
# How much of a stored conversation a resumed session replays to the model.
|
|
237
|
+
HISTORY_REPLAY_LIMIT = 100
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
async def load_conversation_history(
|
|
241
|
+
conversation_id: str, *, current_prompt: str
|
|
242
|
+
) -> list[dict[str, str]]:
|
|
243
|
+
"""A stored conversation's user and assistant messages, oldest first, to resume it.
|
|
244
|
+
|
|
245
|
+
A session holds the conversation in memory only while it lasts; reconnecting,
|
|
246
|
+
or switching to another conversation, would otherwise start the model from
|
|
247
|
+
nothing. The most recent ``HISTORY_REPLAY_LIMIT`` messages are replayed.
|
|
248
|
+
``persist_user_turn`` has already stored ``current_prompt`` as the last
|
|
249
|
+
message - it is this turn's prompt, so it is left out rather than sent twice.
|
|
250
|
+
|
|
251
|
+
The caller has already checked the user may access the conversation.
|
|
252
|
+
"""
|
|
253
|
+
async with get_db_context() as db:
|
|
254
|
+
conv_service = get_conversation_service(db)
|
|
255
|
+
_, total = await conv_service.list_messages(UUID(conversation_id), limit=1)
|
|
256
|
+
messages, _ = await conv_service.list_messages(
|
|
257
|
+
UUID(conversation_id),
|
|
258
|
+
skip=max(0, total - HISTORY_REPLAY_LIMIT - 1),
|
|
259
|
+
limit=HISTORY_REPLAY_LIMIT + 1,
|
|
260
|
+
)
|
|
261
|
+
history = [
|
|
262
|
+
{"role": m.role, "content": m.content}
|
|
263
|
+
for m in messages
|
|
264
|
+
if m.role in ("user", "assistant") and m.content
|
|
265
|
+
]
|
|
266
|
+
if history and history[-1] == {"role": "user", "content": current_prompt}:
|
|
267
|
+
history.pop()
|
|
268
|
+
return history[-HISTORY_REPLAY_LIMIT:]
|
|
269
|
+
|
|
270
|
+
|
|
236
271
|
async def persist_assistant_turn(
|
|
237
272
|
conversation_id: str,
|
|
238
273
|
output: str,
|
|
@@ -35,6 +35,7 @@ from app.core.exceptions import AuthorizationError, NotFoundError
|
|
|
35
35
|
from app.services.agent import (
|
|
36
36
|
build_message_history,
|
|
37
37
|
{%- if cookiecutter.use_database %}
|
|
38
|
+
load_conversation_history,
|
|
38
39
|
persist_assistant_turn,
|
|
39
40
|
persist_user_turn,
|
|
40
41
|
{%- endif %}
|
|
@@ -93,6 +94,8 @@ class AgentSession:
|
|
|
93
94
|
self.deps.ask_user = self._ask_user
|
|
94
95
|
{%- if cookiecutter.use_database %}
|
|
95
96
|
self.current_conversation_id: str | None = None
|
|
97
|
+
# The conversation ``conversation_history`` belongs to.
|
|
98
|
+
self._history_conversation_id: str | None = None
|
|
96
99
|
{%- endif %}
|
|
97
100
|
self._turn_task: asyncio.Task[None] | None = None
|
|
98
101
|
self._ask_user_future: asyncio.Future[list[dict[str, Any]]] | None = None
|
|
@@ -210,6 +213,17 @@ class AgentSession:
|
|
|
210
213
|
"conversation_created",
|
|
211
214
|
{"conversation_id": self.current_conversation_id},
|
|
212
215
|
)
|
|
216
|
+
if self.current_conversation_id != self._history_conversation_id:
|
|
217
|
+
# Another conversation, or this one resumed on a new connection: the
|
|
218
|
+
# model gets its stored history, not the previous conversation's.
|
|
219
|
+
self.conversation_history = (
|
|
220
|
+
await load_conversation_history(
|
|
221
|
+
self.current_conversation_id, current_prompt=user_message
|
|
222
|
+
)
|
|
223
|
+
if self.current_conversation_id and not newly_created
|
|
224
|
+
else []
|
|
225
|
+
)
|
|
226
|
+
self._history_conversation_id = self.current_conversation_id
|
|
213
227
|
{%- endif %}
|
|
214
228
|
|
|
215
229
|
await send_event(self.websocket, "user_prompt", {"content": user_message})
|
|
@@ -656,6 +670,10 @@ class AgentSession:
|
|
|
656
670
|
collected_thinking: list[str],
|
|
657
671
|
) -> None:
|
|
658
672
|
"""Drive the agent_run iterator, dispatching each node to its streaming helper."""
|
|
673
|
+
{%- if cookiecutter.enable_deep_research %}
|
|
674
|
+
# Text held back from the latest model request (see _stream_request_events).
|
|
675
|
+
withheld_text: list[tuple[int, str]] = []
|
|
676
|
+
{%- endif %}
|
|
659
677
|
async for node in agent_run:
|
|
660
678
|
if Agent.is_user_prompt_node(node):
|
|
661
679
|
prompt_text = (
|
|
@@ -667,28 +685,50 @@ class AgentSession:
|
|
|
667
685
|
elif Agent.is_model_request_node(node):
|
|
668
686
|
await send_event(self.websocket, "model_request_start", {})
|
|
669
687
|
async with node.stream(agent_run.ctx) as request_stream:
|
|
688
|
+
{%- if cookiecutter.enable_deep_research %}
|
|
689
|
+
withheld_text = await self._stream_request_events(
|
|
690
|
+
request_stream, collected_thinking
|
|
691
|
+
)
|
|
692
|
+
{%- else %}
|
|
670
693
|
await self._stream_request_events(request_stream, collected_thinking)
|
|
694
|
+
{%- endif %}
|
|
671
695
|
elif Agent.is_call_tools_node(node):
|
|
672
696
|
await send_event(self.websocket, "call_tools_start", {})
|
|
673
697
|
async with node.stream(agent_run.ctx) as handle_stream:
|
|
674
698
|
await self._stream_tool_events(handle_stream, collected_tool_calls)
|
|
675
699
|
elif Agent.is_end_node(node) and agent_run.result is not None:
|
|
700
|
+
{%- if cookiecutter.enable_deep_research %}
|
|
701
|
+
# A run that ends on a step whose text was withheld as narration
|
|
702
|
+
# ended on its answer: send it, rather than a final result the
|
|
703
|
+
# chat never showed.
|
|
704
|
+
for index, content in withheld_text:
|
|
705
|
+
await send_event(
|
|
706
|
+
self.websocket, "text_delta", {"index": index, "content": content}
|
|
707
|
+
)
|
|
708
|
+
{%- endif %}
|
|
676
709
|
await send_event(
|
|
677
710
|
self.websocket, "final_result", {"output": agent_run.result.output}
|
|
678
711
|
)
|
|
679
712
|
|
|
680
713
|
async def _stream_request_events(
|
|
681
714
|
self, request_stream: Any, collected_thinking: list[str]
|
|
715
|
+
{%- if cookiecutter.enable_deep_research %}
|
|
716
|
+
) -> list[tuple[int, str]]:
|
|
717
|
+
{%- else %}
|
|
682
718
|
) -> None:
|
|
719
|
+
{%- endif %}
|
|
683
720
|
"""Forward model-request events (text/thinking/tool deltas + final-result start).
|
|
684
721
|
{%- if cookiecutter.enable_deep_research %}
|
|
685
722
|
|
|
686
723
|
During a deep research turn the model narrates every delegation step.
|
|
687
724
|
A plain-text response ends a PydanticAI run, so a step that issues a
|
|
688
725
|
planning/delegation tool call (``RESEARCH_TOOL_NAMES``) is interstitial:
|
|
689
|
-
its text is
|
|
690
|
-
|
|
691
|
-
|
|
726
|
+
its text is withheld. A step with only content tools (charts, RAG) or no
|
|
727
|
+
tool calls is the final answer and its text is released. Reasoning and
|
|
728
|
+
tool events are always forwarded.
|
|
729
|
+
|
|
730
|
+
Returns the withheld text, for the caller to send should the run end on
|
|
731
|
+
this step after all.
|
|
692
732
|
{%- endif %}
|
|
693
733
|
"""
|
|
694
734
|
{%- if cookiecutter.enable_deep_research %}
|
|
@@ -776,11 +816,13 @@ class AgentSession:
|
|
|
776
816
|
{%- if cookiecutter.enable_deep_research %}
|
|
777
817
|
|
|
778
818
|
made_research_call = any(name in RESEARCH_TOOL_NAMES for name in tool_names.values())
|
|
779
|
-
if deep_research
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
819
|
+
if not deep_research or not buffered_text:
|
|
820
|
+
return []
|
|
821
|
+
if made_research_call:
|
|
822
|
+
return buffered_text
|
|
823
|
+
for index, content in buffered_text:
|
|
824
|
+
await send_event(self.websocket, "text_delta", {"index": index, "content": content})
|
|
825
|
+
return []
|
|
784
826
|
{%- endif %}
|
|
785
827
|
|
|
786
828
|
async def _stream_tool_events(
|
|
@@ -2445,12 +2487,13 @@ from pydantic_ai.messages import (
|
|
|
2445
2487
|
)
|
|
2446
2488
|
from pydantic_ai_backends import StateBackend
|
|
2447
2489
|
|
|
2448
|
-
from app.agents.pydantic_deep_assistant import PydanticDeepContext, get_agent
|
|
2490
|
+
from app.agents.pydantic_deep_assistant import PydanticDeepContext, get_agent, to_model_messages
|
|
2449
2491
|
{%- if cookiecutter.use_database %}
|
|
2450
2492
|
from app.core.exceptions import AuthorizationError, NotFoundError
|
|
2451
2493
|
{%- endif %}
|
|
2452
2494
|
from app.services.agent import (
|
|
2453
2495
|
{%- if cookiecutter.use_database %}
|
|
2496
|
+
load_conversation_history,
|
|
2454
2497
|
persist_assistant_turn,
|
|
2455
2498
|
persist_user_turn,
|
|
2456
2499
|
{%- endif %}
|
|
@@ -2614,7 +2657,21 @@ class AgentSession:
|
|
|
2614
2657
|
conversation_key = "default"
|
|
2615
2658
|
{%- endif %}
|
|
2616
2659
|
if conversation_key != self._history_key:
|
|
2660
|
+
{%- if cookiecutter.use_database %}
|
|
2661
|
+
# Another conversation, or this one resumed on a new connection:
|
|
2662
|
+
# its stored history, not the previous conversation's.
|
|
2663
|
+
self._message_history = (
|
|
2664
|
+
to_model_messages(
|
|
2665
|
+
await load_conversation_history(
|
|
2666
|
+
self.current_conversation_id, current_prompt=user_message
|
|
2667
|
+
)
|
|
2668
|
+
)
|
|
2669
|
+
if self.current_conversation_id and not newly_created
|
|
2670
|
+
else []
|
|
2671
|
+
)
|
|
2672
|
+
{%- else %}
|
|
2617
2673
|
self._message_history = []
|
|
2674
|
+
{%- endif %}
|
|
2618
2675
|
self._workspace_documents = {}
|
|
2619
2676
|
self._history_key = conversation_key
|
|
2620
2677
|
assistant = get_agent(
|
|
@@ -84,7 +84,17 @@ class UserService:
|
|
|
84
84
|
{%- endif %}
|
|
85
85
|
|
|
86
86
|
async def delete_non_admins(self) -> int:
|
|
87
|
+
{%- if cookiecutter.enable_memory %}
|
|
88
|
+
user_ids = await user_repo.list_non_admin_ids(self.db)
|
|
89
|
+
deleted = await user_repo.delete_non_admins(self.db)
|
|
90
|
+
# As in delete(): the memory store has no foreign key to users, and a
|
|
91
|
+
# failure to clear it rolls the request's transaction back too.
|
|
92
|
+
for user_id in user_ids:
|
|
93
|
+
await forget_user_memory(user_id)
|
|
94
|
+
return deleted
|
|
95
|
+
{%- else %}
|
|
87
96
|
return await user_repo.delete_non_admins(self.db)
|
|
97
|
+
{%- endif %}
|
|
88
98
|
|
|
89
99
|
async def has_any(self) -> bool:
|
|
90
100
|
return await user_repo.has_any(self.db)
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
{%- if cookiecutter.use_database and (cookiecutter.use_pydantic_ai or cookiecutter.use_pydantic_deep) %}
|
|
2
|
+
"""A conversation resumed on a new connection keeps its context.
|
|
3
|
+
|
|
4
|
+
The session holds the conversation in memory only while the WebSocket lasts, so
|
|
5
|
+
a reconnect - or switching to another conversation - loads that conversation's
|
|
6
|
+
stored messages instead of starting the model from nothing, or from the
|
|
7
|
+
previous conversation's.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from collections.abc import AsyncIterator
|
|
11
|
+
from contextlib import asynccontextmanager
|
|
12
|
+
from unittest.mock import AsyncMock, MagicMock, patch
|
|
13
|
+
from uuid import uuid4
|
|
14
|
+
|
|
15
|
+
import pytest
|
|
16
|
+
from pydantic_ai.messages import ModelMessage, ModelRequest, ModelResponse, TextPart, UserPromptPart
|
|
17
|
+
from pydantic_ai.models.function import AgentInfo, DeltaToolCalls, FunctionModel
|
|
18
|
+
|
|
19
|
+
from app.services import agent as agent_service
|
|
20
|
+
from app.services.agent import HISTORY_REPLAY_LIMIT, load_conversation_history
|
|
21
|
+
from app.services.agent_session import AgentSession
|
|
22
|
+
|
|
23
|
+
pytestmark = pytest.mark.anyio
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def _prompts(messages: list[ModelMessage]) -> list[str]:
|
|
27
|
+
return [
|
|
28
|
+
part.content
|
|
29
|
+
for message in messages
|
|
30
|
+
if isinstance(message, ModelRequest)
|
|
31
|
+
for part in message.parts
|
|
32
|
+
if isinstance(part, UserPromptPart) and isinstance(part.content, str)
|
|
33
|
+
]
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
class _Recorder:
|
|
37
|
+
"""A streaming model that records the prompts each request carried."""
|
|
38
|
+
|
|
39
|
+
def __init__(self) -> None:
|
|
40
|
+
self.seen: list[list[str]] = []
|
|
41
|
+
|
|
42
|
+
def respond(self, messages: list[ModelMessage], info: AgentInfo) -> ModelResponse:
|
|
43
|
+
self.seen.append(_prompts(messages))
|
|
44
|
+
return ModelResponse(parts=[TextPart(content="ok")])
|
|
45
|
+
|
|
46
|
+
async def stream(
|
|
47
|
+
self, messages: list[ModelMessage], info: AgentInfo
|
|
48
|
+
) -> AsyncIterator[str | DeltaToolCalls]:
|
|
49
|
+
self.respond(messages, info)
|
|
50
|
+
yield "ok"
|
|
51
|
+
|
|
52
|
+
def model(self) -> FunctionModel:
|
|
53
|
+
return FunctionModel(self.respond, stream_function=self.stream)
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def _session() -> AgentSession:
|
|
57
|
+
{%- if cookiecutter.websocket_auth_jwt %}
|
|
58
|
+
return AgentSession(MagicMock(), MagicMock(id=uuid4(), email="u@example.com"))
|
|
59
|
+
{%- else %}
|
|
60
|
+
return AgentSession(MagicMock())
|
|
61
|
+
{%- endif %}
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
async def _turn(
|
|
65
|
+
session: AgentSession,
|
|
66
|
+
model: _Recorder,
|
|
67
|
+
text: str,
|
|
68
|
+
conversation_id: str,
|
|
69
|
+
*,
|
|
70
|
+
stored: list[dict[str, str]],
|
|
71
|
+
newly_created: bool = False,
|
|
72
|
+
) -> None:
|
|
73
|
+
with (
|
|
74
|
+
{%- if cookiecutter.use_pydantic_ai %}
|
|
75
|
+
patch("app.agents.assistant._build_model", lambda _name: model.model()),
|
|
76
|
+
{%- else %}
|
|
77
|
+
patch(
|
|
78
|
+
"app.agents.pydantic_deep_assistant.PydanticDeepAssistant._get_model_string",
|
|
79
|
+
lambda self: model.model(),
|
|
80
|
+
),
|
|
81
|
+
{%- endif %}
|
|
82
|
+
patch(
|
|
83
|
+
"app.services.agent_session.persist_user_turn",
|
|
84
|
+
AsyncMock(return_value=(conversation_id, newly_created, None)),
|
|
85
|
+
),
|
|
86
|
+
patch(
|
|
87
|
+
"app.services.agent_session.load_conversation_history",
|
|
88
|
+
AsyncMock(return_value=list(stored)),
|
|
89
|
+
),
|
|
90
|
+
patch("app.services.agent_session.persist_assistant_turn", AsyncMock(return_value=None)),
|
|
91
|
+
{%- if cookiecutter.enable_teams and cookiecutter.enable_rag %}
|
|
92
|
+
patch("app.services.agent_session.resolve_kb_collections", AsyncMock(return_value=[])),
|
|
93
|
+
{%- endif %}
|
|
94
|
+
{%- if cookiecutter.enable_mcp_client %}
|
|
95
|
+
patch("app.services.agent_session.build_toolsets_for_user", AsyncMock(return_value=[])),
|
|
96
|
+
{%- endif %}
|
|
97
|
+
patch("app.services.agent_session.send_event", AsyncMock()),
|
|
98
|
+
):
|
|
99
|
+
await session.process_message({"message": text, "conversation_id": conversation_id})
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
STORED = [
|
|
103
|
+
{"role": "user", "content": "my name is Ada"},
|
|
104
|
+
{"role": "assistant", "content": "Hello Ada"},
|
|
105
|
+
]
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
async def test_a_resumed_conversation_starts_from_its_stored_history():
|
|
109
|
+
"""A new connection: nothing in memory, the conversation in the database."""
|
|
110
|
+
model = _Recorder()
|
|
111
|
+
|
|
112
|
+
await _turn(_session(), model, "what is my name?", str(uuid4()), stored=STORED)
|
|
113
|
+
|
|
114
|
+
assert model.seen[-1] == ["my name is Ada", "what is my name?"]
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
async def test_a_new_conversation_starts_empty():
|
|
118
|
+
model = _Recorder()
|
|
119
|
+
|
|
120
|
+
await _turn(_session(), model, "hello", str(uuid4()), stored=STORED, newly_created=True)
|
|
121
|
+
|
|
122
|
+
assert model.seen[-1] == ["hello"]
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
async def test_switching_conversations_does_not_carry_the_previous_one_over():
|
|
126
|
+
session, model = _session(), _Recorder()
|
|
127
|
+
first, second = str(uuid4()), str(uuid4())
|
|
128
|
+
|
|
129
|
+
await _turn(session, model, "the secret is 42", first, stored=[])
|
|
130
|
+
await _turn(session, model, "what is the secret?", second, stored=[])
|
|
131
|
+
|
|
132
|
+
assert model.seen[-1] == ["what is the secret?"]
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
def _stored_messages(count: int) -> list[MagicMock]:
|
|
136
|
+
return [
|
|
137
|
+
MagicMock(role="user" if i % 2 == 0 else "assistant", content=f"m{i}") for i in range(count)
|
|
138
|
+
]
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
@asynccontextmanager
|
|
142
|
+
async def _db():
|
|
143
|
+
yield MagicMock()
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
async def _load(messages: list[MagicMock], current_prompt: str) -> list[dict[str, str]]:
|
|
147
|
+
service = MagicMock()
|
|
148
|
+
|
|
149
|
+
async def list_messages(_conversation_id, *, skip: int = 0, limit: int = 100):
|
|
150
|
+
return messages[skip : skip + limit], len(messages)
|
|
151
|
+
|
|
152
|
+
service.list_messages = list_messages
|
|
153
|
+
with (
|
|
154
|
+
patch.object(agent_service, "get_db_context", _db),
|
|
155
|
+
patch.object(agent_service, "get_conversation_service", return_value=service),
|
|
156
|
+
):
|
|
157
|
+
return await load_conversation_history(str(uuid4()), current_prompt=current_prompt)
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
async def test_the_current_prompt_is_not_replayed_as_history():
|
|
161
|
+
messages = [*_stored_messages(2), MagicMock(role="user", content="now")]
|
|
162
|
+
|
|
163
|
+
history = await _load(messages, "now")
|
|
164
|
+
|
|
165
|
+
assert history == [{"role": "user", "content": "m0"}, {"role": "assistant", "content": "m1"}]
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
async def test_only_the_most_recent_messages_are_replayed():
|
|
169
|
+
messages = [*_stored_messages(HISTORY_REPLAY_LIMIT + 10), MagicMock(role="user", content="now")]
|
|
170
|
+
|
|
171
|
+
history = await _load(messages, "now")
|
|
172
|
+
|
|
173
|
+
assert len(history) == HISTORY_REPLAY_LIMIT
|
|
174
|
+
assert history[-1]["content"] == f"m{HISTORY_REPLAY_LIMIT + 9}"
|
|
175
|
+
{%- else %}
|
|
176
|
+
"""Conversation resume tests - not configured (needs a database and Pydantic AI or PydanticDeep)."""
|
|
177
|
+
{%- endif %}
|
fastapi_gen/template/{{cookiecutter.project_slug}}/backend/tests/test_deep_research_streaming.py
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
{%- if cookiecutter.use_pydantic_ai and cookiecutter.enable_deep_research %}
|
|
2
|
+
"""Deep research releases withheld narration when a run ends on it.
|
|
3
|
+
|
|
4
|
+
Text sent with a planning or delegation tool call is held back as narration.
|
|
5
|
+
Pydantic AI continues the run after such a step, so that text is normally not
|
|
6
|
+
the answer - but if a run does end there, it was, and must reach the chat
|
|
7
|
+
before ``final_result``.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from contextlib import asynccontextmanager
|
|
11
|
+
from types import SimpleNamespace
|
|
12
|
+
from unittest.mock import AsyncMock, MagicMock, patch
|
|
13
|
+
from uuid import uuid4
|
|
14
|
+
|
|
15
|
+
import pytest
|
|
16
|
+
|
|
17
|
+
from app.services.agent_session import AgentSession
|
|
18
|
+
|
|
19
|
+
pytestmark = pytest.mark.anyio
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class _Request:
|
|
23
|
+
@asynccontextmanager
|
|
24
|
+
async def stream(self, _ctx):
|
|
25
|
+
yield MagicMock()
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class _End:
|
|
29
|
+
pass
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class _Run:
|
|
33
|
+
"""An agent run of one model request followed by the end of the run."""
|
|
34
|
+
|
|
35
|
+
def __init__(self, output: str) -> None:
|
|
36
|
+
self.ctx = MagicMock()
|
|
37
|
+
self.result = SimpleNamespace(output=output)
|
|
38
|
+
|
|
39
|
+
async def __aiter__(self):
|
|
40
|
+
yield _Request()
|
|
41
|
+
yield _End()
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
async def _events_for(withheld: list[tuple[int, str]]) -> list[tuple[str, dict]]:
|
|
45
|
+
{%- if cookiecutter.websocket_auth_jwt %}
|
|
46
|
+
session = AgentSession(MagicMock(), MagicMock(id=uuid4(), email="u@example.com"))
|
|
47
|
+
{%- else %}
|
|
48
|
+
session = AgentSession(MagicMock())
|
|
49
|
+
{%- endif %}
|
|
50
|
+
events: list[tuple[str, dict]] = []
|
|
51
|
+
|
|
52
|
+
async def _send(_websocket, event_type, data):
|
|
53
|
+
events.append((event_type, data))
|
|
54
|
+
|
|
55
|
+
with (
|
|
56
|
+
patch("app.services.agent_session.send_event", _send),
|
|
57
|
+
patch.object(session, "_stream_request_events", AsyncMock(return_value=withheld)),
|
|
58
|
+
patch("app.services.agent_session.Agent.is_user_prompt_node", lambda node: False),
|
|
59
|
+
patch(
|
|
60
|
+
"app.services.agent_session.Agent.is_model_request_node",
|
|
61
|
+
lambda node: isinstance(node, _Request),
|
|
62
|
+
),
|
|
63
|
+
patch("app.services.agent_session.Agent.is_call_tools_node", lambda node: False),
|
|
64
|
+
patch("app.services.agent_session.Agent.is_end_node", lambda node: isinstance(node, _End)),
|
|
65
|
+
):
|
|
66
|
+
await session._stream_agent_run(_Run("the report"), "go", [], [])
|
|
67
|
+
return events
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
async def test_text_withheld_from_the_last_step_is_sent_before_the_result():
|
|
71
|
+
events = await _events_for([(0, "the report")])
|
|
72
|
+
|
|
73
|
+
assert events[-2:] == [
|
|
74
|
+
("text_delta", {"index": 0, "content": "the report"}),
|
|
75
|
+
("final_result", {"output": "the report"}),
|
|
76
|
+
]
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
async def test_nothing_extra_is_sent_when_nothing_was_withheld():
|
|
80
|
+
events = await _events_for([])
|
|
81
|
+
|
|
82
|
+
assert [event for event, _ in events] == ["model_request_start", "final_result"]
|
|
83
|
+
{%- else %}
|
|
84
|
+
"""Deep research streaming tests - not configured (needs Pydantic AI deep research)."""
|
|
85
|
+
{%- endif %}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"""Tests for the agent memory capability factory and the user memory service."""
|
|
2
2
|
|
|
3
|
-
from unittest.mock import patch
|
|
3
|
+
from unittest.mock import AsyncMock, MagicMock, patch
|
|
4
4
|
from uuid import uuid4
|
|
5
5
|
|
|
6
6
|
import pytest
|
|
@@ -295,3 +295,27 @@ class TestUserMemoryService:
|
|
|
295
295
|
|
|
296
296
|
assert listing.items == []
|
|
297
297
|
{%- endif %}
|
|
298
|
+
|
|
299
|
+
|
|
300
|
+
@pytest.mark.anyio
|
|
301
|
+
async def test_deleting_all_non_admins_forgets_their_memory():
|
|
302
|
+
"""The bulk reset removes rows the memory store has no foreign key to."""
|
|
303
|
+
from app.services.user import UserService
|
|
304
|
+
|
|
305
|
+
ids = [uuid4(), uuid4()]
|
|
306
|
+
forgotten: list = []
|
|
307
|
+
|
|
308
|
+
async def _forget(user_id):
|
|
309
|
+
forgotten.append(user_id)
|
|
310
|
+
return 1
|
|
311
|
+
|
|
312
|
+
with (
|
|
313
|
+
patch("app.services.user.user_repo.list_non_admin_ids", AsyncMock(return_value=ids)),
|
|
314
|
+
patch("app.services.user.user_repo.delete_non_admins", AsyncMock(return_value=2)),
|
|
315
|
+
patch("app.services.user.forget_user_memory", _forget),
|
|
316
|
+
):
|
|
317
|
+
deleted = await UserService(MagicMock()).delete_non_admins()
|
|
318
|
+
|
|
319
|
+
assert deleted == 2
|
|
320
|
+
assert forgotten == ids
|
|
321
|
+
|
|
@@ -13,15 +13,25 @@ import pytest
|
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
def _db_available() -> bool:
|
|
16
|
-
"""Return True if the database
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
16
|
+
"""Return True if the database answers a connection.
|
|
17
|
+
|
|
18
|
+
Checked directly rather than through `alembic current`: that also fails on
|
|
19
|
+
a broken migration chain, which would then skip these tests as "no
|
|
20
|
+
database" instead of failing them.
|
|
21
|
+
"""
|
|
22
|
+
from sqlalchemy import create_engine
|
|
23
|
+
from sqlalchemy.exc import OperationalError
|
|
24
|
+
|
|
25
|
+
from app.core.config import settings
|
|
26
|
+
|
|
27
|
+
engine = create_engine(settings.DATABASE_URL_SYNC, connect_args={"connect_timeout": 5})
|
|
28
|
+
try:
|
|
29
|
+
with engine.connect():
|
|
30
|
+
return True
|
|
31
|
+
except OperationalError:
|
|
32
|
+
return False
|
|
33
|
+
finally:
|
|
34
|
+
engine.dispose()
|
|
25
35
|
|
|
26
36
|
|
|
27
37
|
pytestmark = pytest.mark.skipif(
|
fastapi_gen/template/{{cookiecutter.project_slug}}/backend/tests/test_pydantic_deep_history.py
CHANGED
|
@@ -86,6 +86,8 @@ async def _turn(
|
|
|
86
86
|
AsyncMock(return_value=(conversation_id, False, None)),
|
|
87
87
|
),
|
|
88
88
|
patch("app.services.agent_session.persist_assistant_turn", AsyncMock()),
|
|
89
|
+
# A conversation with nothing stored yet: the session carries what follows.
|
|
90
|
+
patch("app.services.agent_session.load_conversation_history", AsyncMock(return_value=[])),
|
|
89
91
|
{%- endif %}
|
|
90
92
|
{%- if cookiecutter.enable_teams and cookiecutter.enable_rag %}
|
|
91
93
|
patch("app.services.agent_session.resolve_kb_collections", AsyncMock(return_value=[])),
|
|
File without changes
|
|
File without changes
|
|
File without changes
|