fastapi-fullstack 0.1.7__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.1.7.dist-info/METADATA +739 -0
- fastapi_fullstack-0.1.7.dist-info/RECORD +241 -0
- fastapi_fullstack-0.1.7.dist-info/WHEEL +4 -0
- fastapi_fullstack-0.1.7.dist-info/entry_points.txt +2 -0
- fastapi_fullstack-0.1.7.dist-info/licenses/LICENSE +21 -0
- fastapi_gen/__init__.py +3 -0
- fastapi_gen/cli.py +442 -0
- fastapi_gen/config.py +356 -0
- fastapi_gen/generator.py +207 -0
- fastapi_gen/prompts.py +874 -0
- fastapi_gen/template/VARIABLES.md +276 -0
- fastapi_gen/template/cookiecutter.json +93 -0
- fastapi_gen/template/hooks/post_gen_project.py +355 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/.env.prod.example +56 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/.github/workflows/ci.yml +150 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/.gitignore +109 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/AGENTS.md +55 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/CLAUDE.md +99 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/Makefile +315 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/README.md +768 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/.dockerignore +60 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/.env.example +155 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/.pre-commit-config.yaml +32 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/Dockerfile +56 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/alembic/env.py +76 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/alembic/script.py.mako +30 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/alembic/versions/.gitkeep +0 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/alembic.ini +48 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/__init__.py +3 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/admin.py +447 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/agents/__init__.py +23 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/agents/assistant.py +226 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/agents/langchain_assistant.py +226 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/agents/prompts.py +10 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/agents/tools/__init__.py +13 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/agents/tools/datetime_tool.py +17 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/api/__init__.py +1 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/api/deps.py +541 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/api/exception_handlers.py +98 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/api/router.py +10 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/api/routes/__init__.py +9 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/api/routes/v1/__init__.py +87 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/api/routes/v1/agent.py +902 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/api/routes/v1/auth.py +395 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/api/routes/v1/conversations.py +498 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/api/routes/v1/health.py +227 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/api/routes/v1/items.py +275 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/api/routes/v1/oauth.py +205 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/api/routes/v1/sessions.py +168 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/api/routes/v1/users.py +333 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/api/routes/v1/webhooks.py +477 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/api/routes/v1/ws.py +46 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/api/versioning.py +221 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/clients/__init__.py +14 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/clients/redis.py +88 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/commands/__init__.py +117 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/commands/cleanup.py +75 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/commands/example.py +28 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/commands/seed.py +266 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/core/__init__.py +5 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/core/cache.py +23 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/core/config.py +267 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/core/csrf.py +153 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/core/exceptions.py +122 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/core/logfire_setup.py +101 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/core/middleware.py +99 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/core/oauth.py +23 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/core/rate_limit.py +58 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/core/sanitize.py +271 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/core/security.py +102 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/db/__init__.py +7 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/db/base.py +41 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/db/models/__init__.py +31 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/db/models/conversation.py +319 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/db/models/item.py +96 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/db/models/session.py +126 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/db/models/user.py +218 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/db/models/webhook.py +244 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/db/session.py +130 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/main.py +334 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/pipelines/__init__.py +9 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/pipelines/base.py +73 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/repositories/__init__.py +49 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/repositories/base.py +154 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/repositories/conversation.py +838 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/repositories/item.py +222 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/repositories/session.py +318 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/repositories/user.py +322 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/repositories/webhook.py +358 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/schemas/__init__.py +50 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/schemas/base.py +57 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/schemas/conversation.py +192 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/schemas/item.py +52 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/schemas/session.py +42 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/schemas/token.py +31 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/schemas/user.py +64 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/schemas/webhook.py +89 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/services/__init__.py +38 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/services/conversation.py +850 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/services/item.py +246 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/services/session.py +333 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/services/user.py +432 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/services/webhook.py +561 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/worker/__init__.py +5 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/worker/celery_app.py +64 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/worker/taskiq_app.py +38 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/worker/tasks/__init__.py +25 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/worker/tasks/examples.py +106 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/worker/tasks/schedules.py +29 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/app/worker/tasks/taskiq_examples.py +92 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/cli/__init__.py +1 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/cli/commands.py +438 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/pyproject.toml +180 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/scripts/.gitkeep +0 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/tests/__init__.py +1 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/tests/api/__init__.py +1 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/tests/api/test_auth.py +242 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/tests/api/test_exceptions.py +151 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/tests/api/test_health.py +113 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/tests/api/test_items.py +310 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/tests/api/test_users.py +253 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/tests/conftest.py +151 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/tests/test_admin.py +890 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/tests/test_agents.py +261 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/tests/test_clients.py +183 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/tests/test_commands.py +173 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/tests/test_core.py +143 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/tests/test_pipelines.py +118 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/tests/test_repositories.py +181 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/tests/test_security.py +124 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/tests/test_services.py +363 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/backend/tests/test_worker.py +85 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/docker-compose.dev.yml +242 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/docker-compose.frontend.yml +31 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/docker-compose.prod.yml +435 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/docker-compose.yml +241 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/docs/adding_features.md +132 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/docs/architecture.md +63 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/docs/patterns.md +161 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/docs/testing.md +120 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/frontend/.dockerignore +40 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/frontend/.env.example +12 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/frontend/.gitignore +45 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/frontend/.prettierignore +19 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/frontend/.prettierrc +11 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/frontend/Dockerfile +44 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/frontend/README.md +648 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/frontend/e2e/auth.setup.ts +49 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/frontend/e2e/auth.spec.ts +134 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/frontend/e2e/chat.spec.ts +207 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/frontend/e2e/home.spec.ts +73 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/frontend/instrumentation.ts +14 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/frontend/messages/en.json +84 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/frontend/messages/pl.json +84 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/frontend/next.config.ts +76 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/frontend/package.json +69 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/frontend/playwright.config.ts +101 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/frontend/postcss.config.mjs +7 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/frontend/src/app/[locale]/(auth)/layout.tsx +11 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/frontend/src/app/[locale]/(auth)/login/page.tsx +5 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/frontend/src/app/[locale]/(auth)/register/page.tsx +5 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/frontend/src/app/[locale]/(dashboard)/chat/page.tsx +48 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/frontend/src/app/[locale]/(dashboard)/dashboard/page.tsx +99 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/frontend/src/app/[locale]/(dashboard)/layout.tsx +17 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/frontend/src/app/[locale]/(dashboard)/profile/page.tsx +152 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/frontend/src/app/[locale]/auth/callback/page.tsx +113 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/frontend/src/app/[locale]/layout.tsx +46 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/frontend/src/app/[locale]/page.tsx +73 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/frontend/src/app/api/auth/login/route.ts +58 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/frontend/src/app/api/auth/logout/route.ts +24 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/frontend/src/app/api/auth/me/route.ts +39 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/frontend/src/app/api/auth/oauth-callback/route.ts +50 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/frontend/src/app/api/auth/refresh/route.ts +54 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/frontend/src/app/api/auth/register/route.ts +26 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/frontend/src/app/api/conversations/[id]/messages/route.ts +41 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/frontend/src/app/api/conversations/[id]/route.ts +108 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/frontend/src/app/api/conversations/route.ts +73 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/frontend/src/app/api/health/route.ts +21 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/frontend/src/app/globals.css +323 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/frontend/src/app/layout.tsx +22 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/frontend/src/app/providers.tsx +29 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/frontend/src/components/auth/index.ts +2 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/frontend/src/components/auth/login-form.tsx +120 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/frontend/src/components/auth/register-form.tsx +153 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/frontend/src/components/chat/chat-container.tsx +234 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/frontend/src/components/chat/chat-input.tsx +72 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/frontend/src/components/chat/conversation-sidebar.tsx +328 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/frontend/src/components/chat/copy-button.tsx +46 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/frontend/src/components/chat/index.ts +11 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/frontend/src/components/chat/local-conversation-sidebar.tsx +295 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/frontend/src/components/chat/markdown-content.tsx +167 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/frontend/src/components/chat/message-item.tsx +79 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/frontend/src/components/chat/message-list.tsx +18 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/frontend/src/components/chat/tool-call-card.tsx +79 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/frontend/src/components/icons/google-icon.tsx +32 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/frontend/src/components/icons/index.ts +3 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/frontend/src/components/language-switcher.tsx +97 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/frontend/src/components/layout/header.tsx +65 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/frontend/src/components/layout/index.ts +2 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/frontend/src/components/layout/sidebar.tsx +82 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/frontend/src/components/theme/index.ts +7 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/frontend/src/components/theme/theme-provider.tsx +53 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/frontend/src/components/theme/theme-toggle.tsx +105 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/frontend/src/components/ui/badge.tsx +35 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/frontend/src/components/ui/button.test.tsx +75 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/frontend/src/components/ui/button.tsx +56 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/frontend/src/components/ui/card.tsx +82 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/frontend/src/components/ui/index.ts +13 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/frontend/src/components/ui/input.tsx +21 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/frontend/src/components/ui/label.tsx +21 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/frontend/src/components/ui/sheet.tsx +109 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/frontend/src/hooks/index.ts +7 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/frontend/src/hooks/use-auth.ts +97 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/frontend/src/hooks/use-chat.ts +203 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/frontend/src/hooks/use-conversations.ts +181 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/frontend/src/hooks/use-local-chat.ts +165 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/frontend/src/hooks/use-websocket.ts +105 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/frontend/src/i18n.ts +37 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/frontend/src/lib/api-client.ts +90 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/frontend/src/lib/constants.ts +39 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/frontend/src/lib/server-api.ts +78 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/frontend/src/lib/utils.test.ts +44 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/frontend/src/lib/utils.ts +44 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/frontend/src/middleware.ts +31 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/frontend/src/stores/auth-store.test.ts +72 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/frontend/src/stores/auth-store.ts +64 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/frontend/src/stores/chat-sidebar-store.ts +17 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/frontend/src/stores/chat-store.ts +65 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/frontend/src/stores/conversation-store.ts +76 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/frontend/src/stores/index.ts +9 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/frontend/src/stores/local-chat-store.ts +255 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/frontend/src/stores/sidebar-store.ts +17 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/frontend/src/stores/theme-store.ts +44 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/frontend/src/types/api.ts +27 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/frontend/src/types/auth.ts +52 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/frontend/src/types/chat.ts +83 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/frontend/src/types/conversation.ts +49 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/frontend/src/types/index.ts +10 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/frontend/tsconfig.json +28 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/frontend/vitest.config.ts +36 -0
- fastapi_gen/template/{{cookiecutter.project_slug}}/frontend/vitest.setup.ts +56 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { cn } from "@/lib/utils";
|
|
3
|
+
|
|
4
|
+
const Input = React.forwardRef<HTMLInputElement, React.ComponentProps<"input">>(
|
|
5
|
+
({ className, type, ...props }, ref) => {
|
|
6
|
+
return (
|
|
7
|
+
<input
|
|
8
|
+
type={type}
|
|
9
|
+
className={cn(
|
|
10
|
+
"flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-base shadow-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",
|
|
11
|
+
className
|
|
12
|
+
)}
|
|
13
|
+
ref={ref}
|
|
14
|
+
{...props}
|
|
15
|
+
/>
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
);
|
|
19
|
+
Input.displayName = "Input";
|
|
20
|
+
|
|
21
|
+
export { Input };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { cn } from "@/lib/utils";
|
|
3
|
+
|
|
4
|
+
const Label = React.forwardRef<
|
|
5
|
+
HTMLLabelElement,
|
|
6
|
+
React.LabelHTMLAttributes<HTMLLabelElement>
|
|
7
|
+
>(({ className, ...props }, ref) => {
|
|
8
|
+
return (
|
|
9
|
+
<label
|
|
10
|
+
ref={ref}
|
|
11
|
+
className={cn(
|
|
12
|
+
"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",
|
|
13
|
+
className
|
|
14
|
+
)}
|
|
15
|
+
{...props}
|
|
16
|
+
/>
|
|
17
|
+
);
|
|
18
|
+
});
|
|
19
|
+
Label.displayName = "Label";
|
|
20
|
+
|
|
21
|
+
export { Label };
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { cn } from "@/lib/utils";
|
|
5
|
+
import { X } from "lucide-react";
|
|
6
|
+
|
|
7
|
+
interface SheetProps {
|
|
8
|
+
open: boolean;
|
|
9
|
+
onOpenChange: (open: boolean) => void;
|
|
10
|
+
children: React.ReactNode;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
interface SheetContentProps {
|
|
14
|
+
children: React.ReactNode;
|
|
15
|
+
className?: string;
|
|
16
|
+
side?: "left" | "right";
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function Sheet({ open, onOpenChange, children }: SheetProps) {
|
|
20
|
+
React.useEffect(() => {
|
|
21
|
+
if (open) {
|
|
22
|
+
document.body.style.overflow = "hidden";
|
|
23
|
+
} else {
|
|
24
|
+
document.body.style.overflow = "";
|
|
25
|
+
}
|
|
26
|
+
return () => {
|
|
27
|
+
document.body.style.overflow = "";
|
|
28
|
+
};
|
|
29
|
+
}, [open]);
|
|
30
|
+
|
|
31
|
+
if (!open) return null;
|
|
32
|
+
|
|
33
|
+
return (
|
|
34
|
+
<div className="fixed inset-0 z-50">
|
|
35
|
+
<div
|
|
36
|
+
className="fixed inset-0 bg-black/50 backdrop-blur-sm"
|
|
37
|
+
onClick={() => onOpenChange(false)}
|
|
38
|
+
aria-hidden="true"
|
|
39
|
+
/>
|
|
40
|
+
{children}
|
|
41
|
+
</div>
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function SheetContent({
|
|
46
|
+
children,
|
|
47
|
+
className,
|
|
48
|
+
side = "left",
|
|
49
|
+
}: SheetContentProps) {
|
|
50
|
+
return (
|
|
51
|
+
<div
|
|
52
|
+
className={cn(
|
|
53
|
+
"fixed inset-y-0 z-50 flex w-72 flex-col bg-background shadow-lg",
|
|
54
|
+
"animate-in duration-300",
|
|
55
|
+
side === "left" ? "left-0 slide-in-from-left" : "right-0 slide-in-from-right",
|
|
56
|
+
className
|
|
57
|
+
)}
|
|
58
|
+
>
|
|
59
|
+
{children}
|
|
60
|
+
</div>
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function SheetHeader({
|
|
65
|
+
children,
|
|
66
|
+
className,
|
|
67
|
+
}: {
|
|
68
|
+
children: React.ReactNode;
|
|
69
|
+
className?: string;
|
|
70
|
+
}) {
|
|
71
|
+
return (
|
|
72
|
+
<div className={cn("flex items-center justify-between border-b p-4", className)}>
|
|
73
|
+
{children}
|
|
74
|
+
</div>
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export function SheetTitle({
|
|
79
|
+
children,
|
|
80
|
+
className,
|
|
81
|
+
}: {
|
|
82
|
+
children: React.ReactNode;
|
|
83
|
+
className?: string;
|
|
84
|
+
}) {
|
|
85
|
+
return <h2 className={cn("text-lg font-semibold", className)}>{children}</h2>;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export function SheetClose({
|
|
89
|
+
onClick,
|
|
90
|
+
className,
|
|
91
|
+
}: {
|
|
92
|
+
onClick: () => void;
|
|
93
|
+
className?: string;
|
|
94
|
+
}) {
|
|
95
|
+
return (
|
|
96
|
+
<button
|
|
97
|
+
onClick={onClick}
|
|
98
|
+
className={cn(
|
|
99
|
+
"rounded-sm opacity-70 ring-offset-background transition-opacity",
|
|
100
|
+
"hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",
|
|
101
|
+
"h-10 w-10 flex items-center justify-center",
|
|
102
|
+
className
|
|
103
|
+
)}
|
|
104
|
+
>
|
|
105
|
+
<X className="h-5 w-5" />
|
|
106
|
+
<span className="sr-only">Close</span>
|
|
107
|
+
</button>
|
|
108
|
+
);
|
|
109
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { useAuth } from "./use-auth";
|
|
2
|
+
export { useWebSocket } from "./use-websocket";
|
|
3
|
+
export { useChat } from "./use-chat";
|
|
4
|
+
export { useLocalChat } from "./use-local-chat";
|
|
5
|
+
{%- if cookiecutter.enable_conversation_persistence and cookiecutter.use_database %}
|
|
6
|
+
export { useConversations } from "./use-conversations";
|
|
7
|
+
{%- endif %}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useCallback, useEffect } from "react";
|
|
4
|
+
import { useRouter } from "next/navigation";
|
|
5
|
+
import { useAuthStore } from "@/stores";
|
|
6
|
+
import { apiClient, ApiError } from "@/lib/api-client";
|
|
7
|
+
import type { User, LoginRequest, RegisterRequest } from "@/types";
|
|
8
|
+
import { ROUTES } from "@/lib/constants";
|
|
9
|
+
|
|
10
|
+
export function useAuth() {
|
|
11
|
+
const router = useRouter();
|
|
12
|
+
const { user, isAuthenticated, isLoading, setUser, setLoading, logout } =
|
|
13
|
+
useAuthStore();
|
|
14
|
+
|
|
15
|
+
// Check auth status on mount
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
const checkAuth = async () => {
|
|
18
|
+
try {
|
|
19
|
+
const userData = await apiClient.get<User>("/auth/me");
|
|
20
|
+
setUser(userData);
|
|
21
|
+
} catch {
|
|
22
|
+
setUser(null);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
if (isLoading) {
|
|
27
|
+
checkAuth();
|
|
28
|
+
}
|
|
29
|
+
}, [isLoading, setUser]);
|
|
30
|
+
|
|
31
|
+
const login = useCallback(
|
|
32
|
+
async (credentials: LoginRequest) => {
|
|
33
|
+
setLoading(true);
|
|
34
|
+
try {
|
|
35
|
+
const response = await apiClient.post<{ user: User; message: string }>(
|
|
36
|
+
"/auth/login",
|
|
37
|
+
credentials
|
|
38
|
+
);
|
|
39
|
+
setUser(response.user);
|
|
40
|
+
router.push(ROUTES.DASHBOARD);
|
|
41
|
+
return response;
|
|
42
|
+
} catch (error) {
|
|
43
|
+
setLoading(false);
|
|
44
|
+
throw error;
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
[router, setUser, setLoading]
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
const register = useCallback(
|
|
51
|
+
async (data: RegisterRequest) => {
|
|
52
|
+
const response = await apiClient.post<{ id: string; email: string }>(
|
|
53
|
+
"/auth/register",
|
|
54
|
+
data
|
|
55
|
+
);
|
|
56
|
+
return response;
|
|
57
|
+
},
|
|
58
|
+
[]
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
const handleLogout = useCallback(async () => {
|
|
62
|
+
try {
|
|
63
|
+
await apiClient.post("/auth/logout");
|
|
64
|
+
} catch {
|
|
65
|
+
// Ignore logout errors
|
|
66
|
+
} finally {
|
|
67
|
+
logout();
|
|
68
|
+
router.push(ROUTES.LOGIN);
|
|
69
|
+
}
|
|
70
|
+
}, [logout, router]);
|
|
71
|
+
|
|
72
|
+
const refreshToken = useCallback(async () => {
|
|
73
|
+
try {
|
|
74
|
+
await apiClient.post("/auth/refresh");
|
|
75
|
+
// Re-fetch user after token refresh
|
|
76
|
+
const userData = await apiClient.get<User>("/auth/me");
|
|
77
|
+
setUser(userData);
|
|
78
|
+
return true;
|
|
79
|
+
} catch (error) {
|
|
80
|
+
if (error instanceof ApiError && error.status === 401) {
|
|
81
|
+
logout();
|
|
82
|
+
router.push(ROUTES.LOGIN);
|
|
83
|
+
}
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
}, [logout, router, setUser]);
|
|
87
|
+
|
|
88
|
+
return {
|
|
89
|
+
user,
|
|
90
|
+
isAuthenticated,
|
|
91
|
+
isLoading,
|
|
92
|
+
login,
|
|
93
|
+
register,
|
|
94
|
+
logout: handleLogout,
|
|
95
|
+
refreshToken,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useCallback, useState } from "react";
|
|
4
|
+
import { nanoid } from "nanoid";
|
|
5
|
+
import { useWebSocket } from "./use-websocket";
|
|
6
|
+
import { useChatStore } from "@/stores";
|
|
7
|
+
import type { ChatMessage, ToolCall, WSEvent } from "@/types";
|
|
8
|
+
import { WS_URL } from "@/lib/constants";
|
|
9
|
+
{%- if cookiecutter.enable_conversation_persistence and cookiecutter.use_database %}
|
|
10
|
+
import { useConversationStore } from "@/stores";
|
|
11
|
+
{%- endif %}
|
|
12
|
+
|
|
13
|
+
{%- if cookiecutter.enable_conversation_persistence and cookiecutter.use_database %}
|
|
14
|
+
interface UseChatOptions {
|
|
15
|
+
conversationId?: string | null;
|
|
16
|
+
onConversationCreated?: (conversationId: string) => void;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function useChat(options: UseChatOptions = {}) {
|
|
20
|
+
const { conversationId, onConversationCreated } = options;
|
|
21
|
+
const { setCurrentConversationId } = useConversationStore();
|
|
22
|
+
{%- else %}
|
|
23
|
+
export function useChat() {
|
|
24
|
+
{%- endif %}
|
|
25
|
+
const {
|
|
26
|
+
messages,
|
|
27
|
+
addMessage,
|
|
28
|
+
updateMessage,
|
|
29
|
+
addToolCall,
|
|
30
|
+
updateToolCall,
|
|
31
|
+
clearMessages,
|
|
32
|
+
} = useChatStore();
|
|
33
|
+
|
|
34
|
+
const [isProcessing, setIsProcessing] = useState(false);
|
|
35
|
+
const [currentMessageId, setCurrentMessageId] = useState<string | null>(null);
|
|
36
|
+
|
|
37
|
+
const handleWebSocketMessage = useCallback(
|
|
38
|
+
(event: MessageEvent) => {
|
|
39
|
+
const wsEvent: WSEvent = JSON.parse(event.data);
|
|
40
|
+
|
|
41
|
+
switch (wsEvent.type) {
|
|
42
|
+
{%- if cookiecutter.enable_conversation_persistence and cookiecutter.use_database %}
|
|
43
|
+
case "conversation_created": {
|
|
44
|
+
// Handle new conversation created by backend
|
|
45
|
+
const { conversation_id } = wsEvent.data as { conversation_id: string };
|
|
46
|
+
setCurrentConversationId(conversation_id);
|
|
47
|
+
onConversationCreated?.(conversation_id);
|
|
48
|
+
break;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
case "message_saved": {
|
|
52
|
+
// Message was saved to database, update local ID if needed
|
|
53
|
+
// We don't need to do anything special here for now
|
|
54
|
+
break;
|
|
55
|
+
}
|
|
56
|
+
{%- endif %}
|
|
57
|
+
|
|
58
|
+
case "model_request_start": {
|
|
59
|
+
// Create new assistant message placeholder
|
|
60
|
+
const newMsgId = nanoid();
|
|
61
|
+
setCurrentMessageId(newMsgId);
|
|
62
|
+
addMessage({
|
|
63
|
+
id: newMsgId,
|
|
64
|
+
role: "assistant",
|
|
65
|
+
content: "",
|
|
66
|
+
timestamp: new Date(),
|
|
67
|
+
isStreaming: true,
|
|
68
|
+
toolCalls: [],
|
|
69
|
+
});
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
case "text_delta": {
|
|
74
|
+
// Append text delta to current message
|
|
75
|
+
if (currentMessageId) {
|
|
76
|
+
const content = (wsEvent.data as { index: number; content: string }).content;
|
|
77
|
+
updateMessage(currentMessageId, (msg) => ({
|
|
78
|
+
...msg,
|
|
79
|
+
content: msg.content + content,
|
|
80
|
+
}));
|
|
81
|
+
}
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
case "tool_call": {
|
|
86
|
+
// Add tool call to current message
|
|
87
|
+
if (currentMessageId) {
|
|
88
|
+
const { tool_name, args, tool_call_id } = wsEvent.data as {
|
|
89
|
+
tool_name: string;
|
|
90
|
+
args: Record<string, unknown>;
|
|
91
|
+
tool_call_id: string;
|
|
92
|
+
};
|
|
93
|
+
const toolCall: ToolCall = {
|
|
94
|
+
id: tool_call_id,
|
|
95
|
+
name: tool_name,
|
|
96
|
+
args,
|
|
97
|
+
status: "running",
|
|
98
|
+
};
|
|
99
|
+
addToolCall(currentMessageId, toolCall);
|
|
100
|
+
}
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
case "tool_result": {
|
|
105
|
+
// Update tool call with result
|
|
106
|
+
if (currentMessageId) {
|
|
107
|
+
const { tool_call_id, content } = wsEvent.data as {
|
|
108
|
+
tool_call_id: string;
|
|
109
|
+
content: string;
|
|
110
|
+
};
|
|
111
|
+
updateToolCall(currentMessageId, tool_call_id, {
|
|
112
|
+
result: content,
|
|
113
|
+
status: "completed",
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
break;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
case "final_result": {
|
|
120
|
+
// Finalize message
|
|
121
|
+
if (currentMessageId) {
|
|
122
|
+
updateMessage(currentMessageId, (msg) => ({
|
|
123
|
+
...msg,
|
|
124
|
+
isStreaming: false,
|
|
125
|
+
}));
|
|
126
|
+
}
|
|
127
|
+
setIsProcessing(false);
|
|
128
|
+
setCurrentMessageId(null);
|
|
129
|
+
break;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
case "error": {
|
|
133
|
+
// Handle error
|
|
134
|
+
if (currentMessageId) {
|
|
135
|
+
updateMessage(currentMessageId, (msg) => ({
|
|
136
|
+
...msg,
|
|
137
|
+
content: msg.content + "\n\n[Error occurred]",
|
|
138
|
+
isStreaming: false,
|
|
139
|
+
}));
|
|
140
|
+
}
|
|
141
|
+
setIsProcessing(false);
|
|
142
|
+
break;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
case "complete": {
|
|
146
|
+
setIsProcessing(false);
|
|
147
|
+
break;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
},
|
|
151
|
+
{%- if cookiecutter.enable_conversation_persistence and cookiecutter.use_database %}
|
|
152
|
+
[currentMessageId, addMessage, updateMessage, addToolCall, updateToolCall, setCurrentConversationId, onConversationCreated]
|
|
153
|
+
{%- else %}
|
|
154
|
+
[currentMessageId, addMessage, updateMessage, addToolCall, updateToolCall]
|
|
155
|
+
{%- endif %}
|
|
156
|
+
);
|
|
157
|
+
|
|
158
|
+
const wsUrl = `${WS_URL}/api/v1/ws/agent`;
|
|
159
|
+
|
|
160
|
+
const { isConnected, connect, disconnect, sendMessage } = useWebSocket({
|
|
161
|
+
url: wsUrl,
|
|
162
|
+
onMessage: handleWebSocketMessage,
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
const sendChatMessage = useCallback(
|
|
166
|
+
(content: string) => {
|
|
167
|
+
// Add user message
|
|
168
|
+
const userMessage: ChatMessage = {
|
|
169
|
+
id: nanoid(),
|
|
170
|
+
role: "user",
|
|
171
|
+
content,
|
|
172
|
+
timestamp: new Date(),
|
|
173
|
+
};
|
|
174
|
+
addMessage(userMessage);
|
|
175
|
+
|
|
176
|
+
// Send to WebSocket
|
|
177
|
+
setIsProcessing(true);
|
|
178
|
+
{%- if cookiecutter.enable_conversation_persistence and cookiecutter.use_database %}
|
|
179
|
+
sendMessage({
|
|
180
|
+
message: content,
|
|
181
|
+
conversation_id: conversationId || null,
|
|
182
|
+
});
|
|
183
|
+
{%- else %}
|
|
184
|
+
sendMessage({ message: content });
|
|
185
|
+
{%- endif %}
|
|
186
|
+
},
|
|
187
|
+
{%- if cookiecutter.enable_conversation_persistence and cookiecutter.use_database %}
|
|
188
|
+
[addMessage, sendMessage, conversationId]
|
|
189
|
+
{%- else %}
|
|
190
|
+
[addMessage, sendMessage]
|
|
191
|
+
{%- endif %}
|
|
192
|
+
);
|
|
193
|
+
|
|
194
|
+
return {
|
|
195
|
+
messages,
|
|
196
|
+
isConnected,
|
|
197
|
+
isProcessing,
|
|
198
|
+
connect,
|
|
199
|
+
disconnect,
|
|
200
|
+
sendMessage: sendChatMessage,
|
|
201
|
+
clearMessages,
|
|
202
|
+
};
|
|
203
|
+
}
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
{%- if cookiecutter.enable_conversation_persistence and cookiecutter.use_database %}
|
|
2
|
+
"use client";
|
|
3
|
+
|
|
4
|
+
import { useCallback } from "react";
|
|
5
|
+
import { apiClient } from "@/lib/api-client";
|
|
6
|
+
import { useConversationStore, useChatStore } from "@/stores";
|
|
7
|
+
import type {
|
|
8
|
+
Conversation,
|
|
9
|
+
ConversationMessage,
|
|
10
|
+
ConversationListResponse,
|
|
11
|
+
} from "@/types";
|
|
12
|
+
|
|
13
|
+
interface CreateConversationResponse {
|
|
14
|
+
id: string;
|
|
15
|
+
title?: string;
|
|
16
|
+
created_at: string;
|
|
17
|
+
updated_at: string;
|
|
18
|
+
is_archived: boolean;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
interface MessagesResponse {
|
|
22
|
+
items: ConversationMessage[];
|
|
23
|
+
total: number;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function useConversations() {
|
|
27
|
+
const {
|
|
28
|
+
conversations,
|
|
29
|
+
currentConversationId,
|
|
30
|
+
currentMessages,
|
|
31
|
+
isLoading,
|
|
32
|
+
error,
|
|
33
|
+
setConversations,
|
|
34
|
+
addConversation,
|
|
35
|
+
updateConversation,
|
|
36
|
+
removeConversation,
|
|
37
|
+
setCurrentConversationId,
|
|
38
|
+
setCurrentMessages,
|
|
39
|
+
setLoading,
|
|
40
|
+
setError,
|
|
41
|
+
} = useConversationStore();
|
|
42
|
+
const { clearMessages } = useChatStore();
|
|
43
|
+
|
|
44
|
+
const fetchConversations = useCallback(async () => {
|
|
45
|
+
setLoading(true);
|
|
46
|
+
setError(null);
|
|
47
|
+
try {
|
|
48
|
+
const response = await apiClient.get<ConversationListResponse>(
|
|
49
|
+
"/conversations"
|
|
50
|
+
);
|
|
51
|
+
setConversations(response.items);
|
|
52
|
+
} catch (err) {
|
|
53
|
+
const message =
|
|
54
|
+
err instanceof Error ? err.message : "Failed to fetch conversations";
|
|
55
|
+
setError(message);
|
|
56
|
+
} finally {
|
|
57
|
+
setLoading(false);
|
|
58
|
+
}
|
|
59
|
+
}, [setConversations, setLoading, setError]);
|
|
60
|
+
|
|
61
|
+
const createConversation = useCallback(
|
|
62
|
+
async (title?: string): Promise<Conversation | null> => {
|
|
63
|
+
setLoading(true);
|
|
64
|
+
setError(null);
|
|
65
|
+
try {
|
|
66
|
+
const response = await apiClient.post<CreateConversationResponse>(
|
|
67
|
+
"/conversations",
|
|
68
|
+
{ title }
|
|
69
|
+
);
|
|
70
|
+
const newConversation: Conversation = {
|
|
71
|
+
id: response.id,
|
|
72
|
+
title: response.title,
|
|
73
|
+
created_at: response.created_at,
|
|
74
|
+
updated_at: response.updated_at,
|
|
75
|
+
is_archived: response.is_archived,
|
|
76
|
+
};
|
|
77
|
+
addConversation(newConversation);
|
|
78
|
+
return newConversation;
|
|
79
|
+
} catch (err) {
|
|
80
|
+
const message =
|
|
81
|
+
err instanceof Error ? err.message : "Failed to create conversation";
|
|
82
|
+
setError(message);
|
|
83
|
+
return null;
|
|
84
|
+
} finally {
|
|
85
|
+
setLoading(false);
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
[addConversation, setLoading, setError]
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
const selectConversation = useCallback(
|
|
92
|
+
async (id: string) => {
|
|
93
|
+
setCurrentConversationId(id);
|
|
94
|
+
clearMessages();
|
|
95
|
+
setLoading(true);
|
|
96
|
+
setError(null);
|
|
97
|
+
try {
|
|
98
|
+
const response = await apiClient.get<MessagesResponse>(
|
|
99
|
+
`/conversations/${id}/messages`
|
|
100
|
+
);
|
|
101
|
+
setCurrentMessages(response.items);
|
|
102
|
+
} catch (err) {
|
|
103
|
+
const message =
|
|
104
|
+
err instanceof Error ? err.message : "Failed to fetch messages";
|
|
105
|
+
setError(message);
|
|
106
|
+
} finally {
|
|
107
|
+
setLoading(false);
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
[setCurrentConversationId, clearMessages, setCurrentMessages, setLoading, setError]
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
const archiveConversation = useCallback(
|
|
114
|
+
async (id: string) => {
|
|
115
|
+
try {
|
|
116
|
+
await apiClient.patch(`/conversations/${id}`, { is_archived: true });
|
|
117
|
+
updateConversation(id, { is_archived: true });
|
|
118
|
+
} catch (err) {
|
|
119
|
+
const message =
|
|
120
|
+
err instanceof Error ? err.message : "Failed to archive conversation";
|
|
121
|
+
setError(message);
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
[updateConversation, setError]
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
const deleteConversation = useCallback(
|
|
128
|
+
async (id: string) => {
|
|
129
|
+
try {
|
|
130
|
+
await apiClient.delete(`/conversations/${id}`);
|
|
131
|
+
removeConversation(id);
|
|
132
|
+
} catch (err) {
|
|
133
|
+
const message =
|
|
134
|
+
err instanceof Error ? err.message : "Failed to delete conversation";
|
|
135
|
+
setError(message);
|
|
136
|
+
}
|
|
137
|
+
},
|
|
138
|
+
[removeConversation, setError]
|
|
139
|
+
);
|
|
140
|
+
|
|
141
|
+
const renameConversation = useCallback(
|
|
142
|
+
async (id: string, title: string) => {
|
|
143
|
+
try {
|
|
144
|
+
await apiClient.patch(`/conversations/${id}`, { title });
|
|
145
|
+
updateConversation(id, { title });
|
|
146
|
+
} catch (err) {
|
|
147
|
+
const message =
|
|
148
|
+
err instanceof Error ? err.message : "Failed to rename conversation";
|
|
149
|
+
setError(message);
|
|
150
|
+
}
|
|
151
|
+
},
|
|
152
|
+
[updateConversation, setError]
|
|
153
|
+
);
|
|
154
|
+
|
|
155
|
+
const startNewChat = useCallback(async () => {
|
|
156
|
+
clearMessages();
|
|
157
|
+
setCurrentMessages([]);
|
|
158
|
+
const newConversation = await createConversation();
|
|
159
|
+
if (newConversation) {
|
|
160
|
+
setCurrentConversationId(newConversation.id);
|
|
161
|
+
}
|
|
162
|
+
}, [clearMessages, setCurrentMessages, createConversation, setCurrentConversationId]);
|
|
163
|
+
|
|
164
|
+
return {
|
|
165
|
+
conversations,
|
|
166
|
+
currentConversationId,
|
|
167
|
+
currentMessages,
|
|
168
|
+
isLoading,
|
|
169
|
+
error,
|
|
170
|
+
fetchConversations,
|
|
171
|
+
createConversation,
|
|
172
|
+
selectConversation,
|
|
173
|
+
archiveConversation,
|
|
174
|
+
deleteConversation,
|
|
175
|
+
renameConversation,
|
|
176
|
+
startNewChat,
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
{%- else %}
|
|
180
|
+
// Conversations hook - not configured (enable_conversation_persistence is false)
|
|
181
|
+
{%- endif %}
|