vibefast-cli 1.2.1 → 1.3.1
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.
- package/README.md +30 -95
- package/dist/__tests__/recipes.test.js +94 -91
- package/dist/__tests__/recipes.test.js.map +1 -1
- package/dist/commands/add.d.ts.map +1 -1
- package/dist/commands/add.js +301 -125
- package/dist/commands/add.js.map +1 -1
- package/dist/commands/checklist.d.ts.map +1 -1
- package/dist/commands/checklist.js +85 -44
- package/dist/commands/checklist.js.map +1 -1
- package/dist/commands/health.d.ts.map +1 -1
- package/dist/commands/health.js +13 -4
- package/dist/commands/health.js.map +1 -1
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +118 -26
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/migrate.d.ts +3 -0
- package/dist/commands/migrate.d.ts.map +1 -0
- package/dist/commands/migrate.js +202 -0
- package/dist/commands/migrate.js.map +1 -0
- package/dist/commands/remove.d.ts.map +1 -1
- package/dist/commands/remove.js +61 -3
- package/dist/commands/remove.js.map +1 -1
- package/dist/core/auth.d.ts.map +1 -1
- package/dist/core/auth.js +20 -18
- package/dist/core/auth.js.map +1 -1
- package/dist/core/codemod.d.ts +33 -0
- package/dist/core/codemod.d.ts.map +1 -1
- package/dist/core/codemod.js +116 -0
- package/dist/core/codemod.js.map +1 -1
- package/dist/core/detect.d.ts.map +1 -1
- package/dist/core/detect.js +24 -7
- package/dist/core/detect.js.map +1 -1
- package/dist/core/journal.d.ts +1 -0
- package/dist/core/journal.d.ts.map +1 -1
- package/dist/core/journal.js.map +1 -1
- package/dist/core/recipes.d.ts.map +1 -1
- package/dist/core/recipes.js +25 -7
- package/dist/core/recipes.js.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/docs/architecture.md +50 -0
- package/docs/commands.md +78 -0
- package/docs/contributing.md +27 -0
- package/docs/quickstart.md +50 -0
- package/docs/recipes.md +57 -0
- package/docs/troubleshooting.md +31 -0
- package/package.json +2 -2
- package/recipes/0/apps/native/src/components/advanced-ui/timeline/demo.tsx +445 -0
- package/recipes/0/apps/native/src/components/advanced-ui/timeline/timeline-view.tsx +355 -0
- package/recipes/0/apps/native/src/components/advanced-ui/timeline/types.ts +31 -0
- package/recipes/0/recipe.json +18 -0
- package/recipes/animated-chip/apps/native/src/components/advanced-ui/chip/demo.tsx +2 -1
- package/recipes/animated-chip/recipe.json +5 -2
- package/recipes/animated-chip-native@latest.zip +0 -0
- package/recipes/animated-chip@latest.zip +0 -0
- package/recipes/animated-switch/apps/native/src/components/advanced-ui/switch/demo.tsx +1 -1
- package/recipes/animated-switch/recipe.json +5 -2
- package/recipes/animated-switch-native@latest.zip +0 -0
- package/recipes/animated-switch@latest.zip +0 -0
- package/recipes/audio-recorder/apps/native/src/features/audio-recorder/components/audio-recorder.tsx +2 -1
- package/recipes/audio-recorder/apps/native/src/features/audio-recorder/demo/with-recording-list-demo.tsx +2 -2
- package/recipes/audio-recorder/recipe.json +7 -2
- package/recipes/audio-recorder-native@latest.zip +0 -0
- package/recipes/audio-recorder-supabase/apps/native/src/features/audio-recorder/components/audio-recorder.tsx +2 -1
- package/recipes/audio-recorder-supabase/apps/native/src/features/audio-recorder/demo/with-recording-list-demo.tsx +2 -1
- package/recipes/audio-recorder-supabase/recipe.json +12 -16
- package/recipes/audio-recorder-supabase-native@latest.zip +0 -0
- package/recipes/audio-recorder-supabase@latest.zip +0 -0
- package/recipes/audio-recorder@latest.zip +0 -0
- package/recipes/charts/apps/native/src/app/charts/index.tsx +3 -0
- package/recipes/charts/apps/native/src/features/charts/components/bar-chart.tsx +3 -1
- package/recipes/charts/apps/native/src/features/charts/components/candlestick-chart.tsx +3 -1
- package/recipes/charts/apps/native/src/features/charts/components/column-chart.tsx +3 -1
- package/recipes/charts/apps/native/src/features/charts/components/doughnut-chart.tsx +3 -1
- package/recipes/charts/apps/native/src/features/charts/components/line-chart.tsx +3 -1
- package/recipes/charts/apps/native/src/features/charts/components/radar-chart.tsx +3 -1
- package/recipes/charts/apps/native/src/features/charts/components/stacked-bar-chart.tsx +3 -1
- package/recipes/charts/recipe.json +13 -4
- package/recipes/charts-native@latest.zip +0 -0
- package/recipes/charts@latest.zip +0 -0
- package/recipes/chatbot/apps/native/src/features/chatbot/components/chat-markdown.tsx +86 -86
- package/recipes/chatbot/apps/native/src/features/chatbot/components/markdown/code-block.tsx +4 -4
- package/recipes/chatbot/recipe.json +3 -40
- package/recipes/chatbot-native@latest.zip +0 -0
- package/recipes/chatbot-supabase/apps/native/src/features/chatbot/components/chat-markdown.tsx +4 -1
- package/recipes/chatbot-supabase/apps/native/src/features/chatbot/components/markdown/code-block.tsx +86 -53
- package/recipes/chatbot-supabase/recipe.json +3 -42
- package/recipes/chatbot-supabase-native@latest.zip +0 -0
- package/recipes/chatbot-supabase@latest.zip +0 -0
- package/recipes/chatbot@latest.zip +0 -0
- package/recipes/glowing-button/recipe.json +6 -2
- package/recipes/glowing-button-native@latest.zip +0 -0
- package/recipes/glowing-button@latest.zip +0 -0
- package/recipes/image-analysis/apps/native/src/app/analysis/[type]/_layout.tsx +5 -0
- package/recipes/image-analysis/apps/native/src/app/analysis/[type]/analysis-options.tsx +50 -0
- package/recipes/image-analysis/apps/native/src/app/analysis/[type]/camera.tsx +2 -0
- package/recipes/image-analysis/apps/native/src/app/analysis/[type]/index.tsx +50 -0
- package/recipes/image-analysis/apps/native/src/app/analysis/[type]/loading.tsx +50 -0
- package/recipes/image-analysis/apps/native/src/app/analysis/[type]/results.tsx +2 -0
- package/recipes/image-analysis/apps/native/src/app/analysis/[type]/trait-details.tsx +3 -0
- package/recipes/image-analysis/apps/native/src/features/image-analyzer/app/analysis-options-screen.tsx +2 -2
- package/recipes/image-analysis/apps/native/src/features/image-analyzer/app/camera.tsx +72 -65
- package/recipes/image-analysis/apps/native/src/features/image-analyzer/app/image-capture-screen.tsx +65 -47
- package/recipes/image-analysis/apps/native/src/features/image-analyzer/app/loading-screen.tsx +43 -2
- package/recipes/image-analysis/apps/native/src/features/image-analyzer/app/loading.tsx +34 -1
- package/recipes/image-analysis/apps/native/src/features/image-analyzer/hooks/use-image-analysis.ts +83 -2
- package/recipes/image-analysis/recipe.json +11 -19
- package/recipes/image-analysis-native@latest.zip +0 -0
- package/recipes/image-analysis-supabase/apps/native/src/app/analysis/[type]/_layout.tsx +5 -0
- package/recipes/image-analysis-supabase/apps/native/src/app/analysis/[type]/analysis-options.tsx +50 -0
- package/recipes/image-analysis-supabase/apps/native/src/app/analysis/[type]/camera.tsx +2 -0
- package/recipes/image-analysis-supabase/apps/native/src/app/analysis/[type]/index.tsx +50 -0
- package/recipes/image-analysis-supabase/apps/native/src/app/analysis/[type]/loading.tsx +50 -0
- package/recipes/image-analysis-supabase/apps/native/src/app/analysis/[type]/results.tsx +2 -0
- package/recipes/image-analysis-supabase/apps/native/src/app/analysis/[type]/trait-details.tsx +3 -0
- package/recipes/image-analysis-supabase/recipe.json +10 -37
- package/recipes/image-analysis-supabase-native@latest.zip +0 -0
- package/recipes/image-analysis-supabase@latest.zip +0 -0
- package/recipes/image-analysis@latest.zip +0 -0
- package/recipes/image-analyzer/apps/native/src/app/(root)/(protected)/image-analyzer/index.tsx +2 -0
- package/recipes/image-generator/apps/native/src/app/image-generator/gallery.tsx +3 -0
- package/recipes/image-generator/apps/native/src/app/image-generator/index.tsx +3 -0
- package/recipes/image-generator/recipe.json +8 -18
- package/recipes/image-generator-native@latest.zip +0 -0
- package/recipes/image-generator-supabase/recipe.json +6 -35
- package/recipes/image-generator-supabase-native@latest.zip +0 -0
- package/recipes/image-generator-supabase@latest.zip +0 -0
- package/recipes/image-generator@latest.zip +0 -0
- package/recipes/ios-widget/recipe.json +18 -119
- package/recipes/ios-widget-native@latest.zip +0 -0
- package/recipes/ios-widget@latest.zip +0 -0
- package/recipes/number-stepper/apps/native/src/components/advanced-ui/stepper/demo.tsx +1 -1
- package/recipes/number-stepper/recipe.json +5 -2
- package/recipes/number-stepper-native@latest.zip +0 -0
- package/recipes/number-stepper@latest.zip +0 -0
- package/recipes/onboarding/apps/native/src/features/onboarding/expense-tracker/components/interactive-onboarding.tsx +11 -18
- package/recipes/onboarding/apps/native/src/features/onboarding/expense-tracker/components/steps/ai-tone-step.tsx +5 -7
- package/recipes/onboarding/apps/native/src/features/onboarding/expense-tracker/components/steps/currency-step.tsx +9 -7
- package/recipes/onboarding/apps/native/src/features/onboarding/expense-tracker/components/steps/feature-ai-step.tsx +8 -7
- package/recipes/onboarding/apps/native/src/features/onboarding/expense-tracker/components/steps/feature-chatbot-step.tsx +6 -5
- package/recipes/onboarding/apps/native/src/features/onboarding/expense-tracker/components/steps/feature-manual-step.tsx +4 -3
- package/recipes/onboarding/apps/native/src/features/onboarding/expense-tracker/components/steps/feature-scan-step.tsx +6 -5
- package/recipes/onboarding/apps/native/src/features/onboarding/expense-tracker/components/steps/main-reason-step.tsx +5 -7
- package/recipes/onboarding/apps/native/src/features/onboarding/expense-tracker/components/steps/notification-step.tsx +7 -6
- package/recipes/onboarding/apps/native/src/features/onboarding/expense-tracker/components/steps/overspend-step.tsx +5 -7
- package/recipes/onboarding/apps/native/src/features/onboarding/expense-tracker/components/steps/personalizing-step.tsx +8 -7
- package/recipes/onboarding/apps/native/src/features/onboarding/expense-tracker/components/steps/rating-step.tsx +6 -5
- package/recipes/onboarding/apps/native/src/features/onboarding/expense-tracker/components/steps/reminder-step.tsx +5 -6
- package/recipes/onboarding/apps/native/src/features/onboarding/expense-tracker/components/steps/safety-step.tsx +5 -4
- package/recipes/onboarding/apps/native/src/features/onboarding/expense-tracker/components/steps/struggle-step.tsx +5 -7
- package/recipes/onboarding/apps/native/src/features/onboarding/expense-tracker/components/steps/welcome-step.tsx +7 -6
- package/recipes/onboarding/apps/native/src/features/onboarding/expense-tracker/components/ui/onboarding-header.tsx +4 -3
- package/recipes/onboarding/recipe.json +9 -6
- package/recipes/onboarding-native@latest.zip +0 -0
- package/recipes/onboarding@latest.zip +0 -0
- package/recipes/payments/apps/native/src/app/paywall/index.tsx +74 -0
- package/recipes/payments/apps/native/src/app/paywall/local.tsx +25 -0
- package/recipes/payments/apps/native/src/app/paywall/remote.tsx +23 -0
- package/recipes/payments/packages/backend/convex/payments.ts +21 -3
- package/recipes/payments/recipe.json +14 -34
- package/recipes/payments-native@latest.zip +0 -0
- package/recipes/payments-supabase/apps/native/src/app/paywall/index.tsx +74 -0
- package/recipes/payments-supabase/apps/native/src/app/paywall/local.tsx +25 -0
- package/recipes/payments-supabase/apps/native/src/app/paywall/remote.tsx +23 -0
- package/recipes/payments-supabase/recipe.json +16 -23
- package/recipes/payments-supabase-native@latest.zip +0 -0
- package/recipes/payments-supabase@latest.zip +0 -0
- package/recipes/payments@latest.zip +0 -0
- package/recipes/posthog/apps/native/src/components/analytics/navigation-tracker.tsx +14 -0
- package/recipes/posthog/apps/native/src/lib/hooks/use-navigation-analytics.ts +44 -0
- package/recipes/posthog/apps/native/src/providers/posthog-provider.tsx +51 -0
- package/recipes/posthog/recipe.json +60 -0
- package/recipes/posthog-native@latest.zip +0 -0
- package/recipes/progress-circle/apps/native/src/components/advanced-ui/progress-bars/progress-circle-page.tsx +1 -1
- package/recipes/progress-circle/recipe.json +5 -2
- package/recipes/progress-circle-native@latest.zip +0 -0
- package/recipes/progress-circle@latest.zip +0 -0
- package/recipes/quiz/apps/native/src/app/quiz/index.tsx +47 -0
- package/recipes/quiz/recipe.json +9 -6
- package/recipes/quiz-native@latest.zip +0 -0
- package/recipes/quiz@latest.zip +0 -0
- package/recipes/screen-kits/apps/native/src/app/screen-kits/_layout.tsx +12 -0
- package/recipes/screen-kits/apps/native/src/app/screen-kits/index.tsx +114 -0
- package/recipes/screen-kits/apps/native/src/features/screen-kits/index.ts +1 -0
- package/recipes/screen-kits/apps/native/src/features/screen-kits/types.ts +28 -0
- package/recipes/screen-kits/recipe.json +26 -0
- package/recipes/screen-kits-duolingo/apps/native/src/app/screen-kits/duolingo/_layout.tsx +12 -0
- package/recipes/screen-kits-duolingo/apps/native/src/app/screen-kits/duolingo/home.tsx +5 -0
- package/recipes/screen-kits-duolingo/apps/native/src/app/screen-kits/duolingo/index.tsx +5 -0
- package/recipes/screen-kits-duolingo/apps/native/src/app/screen-kits/duolingo/lesson-complete.tsx +5 -0
- package/recipes/screen-kits-duolingo/apps/native/src/app/screen-kits/duolingo/lesson-fail.tsx +5 -0
- package/recipes/screen-kits-duolingo/apps/native/src/app/screen-kits/duolingo/lesson.tsx +5 -0
- package/recipes/screen-kits-duolingo/apps/native/src/app/screen-kits/duolingo/skill-tree.tsx +5 -0
- package/recipes/screen-kits-duolingo/apps/native/src/features/screen-kits/duolingo/components/duo-button.tsx +174 -0
- package/recipes/screen-kits-duolingo/apps/native/src/features/screen-kits/duolingo/components/skill-button.tsx +186 -0
- package/recipes/screen-kits-duolingo/apps/native/src/features/screen-kits/duolingo/components/xp-header.tsx +115 -0
- package/recipes/screen-kits-duolingo/apps/native/src/features/screen-kits/duolingo/constants.ts +89 -0
- package/recipes/screen-kits-duolingo/apps/native/src/features/screen-kits/duolingo/index.ts +3 -0
- package/recipes/screen-kits-duolingo/apps/native/src/features/screen-kits/duolingo/screens/home-screen.tsx +225 -0
- package/recipes/screen-kits-duolingo/apps/native/src/features/screen-kits/duolingo/screens/lesson-complete-screen.tsx +485 -0
- package/recipes/screen-kits-duolingo/apps/native/src/features/screen-kits/duolingo/screens/lesson-fail-screen.tsx +105 -0
- package/recipes/screen-kits-duolingo/apps/native/src/features/screen-kits/duolingo/screens/lesson-screen.tsx +384 -0
- package/recipes/screen-kits-duolingo/recipe.json +58 -0
- package/recipes/screen-kits-duolingo-native@latest.zip +0 -0
- package/recipes/screen-kits-finance/apps/native/src/app/screen-kits/finance/_layout.tsx +45 -0
- package/recipes/screen-kits-finance/apps/native/src/app/screen-kits/finance/asset-detail.tsx +3 -0
- package/recipes/screen-kits-finance/apps/native/src/app/screen-kits/finance/notifications.tsx +3 -0
- package/recipes/screen-kits-finance/apps/native/src/app/screen-kits/finance/receive.tsx +3 -0
- package/recipes/screen-kits-finance/apps/native/src/app/screen-kits/finance/send.tsx +3 -0
- package/recipes/screen-kits-finance/apps/native/src/app/screen-kits/finance/swap.tsx +3 -0
- package/recipes/screen-kits-finance/apps/native/src/app/screen-kits/finance/wallet.tsx +3 -0
- package/recipes/screen-kits-finance/apps/native/src/features/screen-kits/finance/components/ActionButtons.tsx +78 -0
- package/recipes/screen-kits-finance/apps/native/src/features/screen-kits/finance/components/AssetRow.tsx +94 -0
- package/recipes/screen-kits-finance/apps/native/src/features/screen-kits/finance/components/BalanceCard.tsx +118 -0
- package/recipes/screen-kits-finance/apps/native/src/features/screen-kits/finance/constants.ts +85 -0
- package/recipes/screen-kits-finance/apps/native/src/features/screen-kits/finance/screens/asset-detail.tsx +378 -0
- package/recipes/screen-kits-finance/apps/native/src/features/screen-kits/finance/screens/notifications.tsx +210 -0
- package/recipes/screen-kits-finance/apps/native/src/features/screen-kits/finance/screens/receive-modal.tsx +317 -0
- package/recipes/screen-kits-finance/apps/native/src/features/screen-kits/finance/screens/send-modal.tsx +420 -0
- package/recipes/screen-kits-finance/apps/native/src/features/screen-kits/finance/screens/swap-modal.tsx +363 -0
- package/recipes/screen-kits-finance/apps/native/src/features/screen-kits/finance/screens/wallet-dashboard.tsx +281 -0
- package/recipes/screen-kits-finance/recipe.json +46 -0
- package/recipes/screen-kits-finance-native@latest.zip +0 -0
- package/recipes/screen-kits-fitness/apps/native/assets/sounds/timer-beep.wav +0 -0
- package/recipes/screen-kits-fitness/apps/native/src/app/screen-kits/fitness/_layout.tsx +10 -0
- package/recipes/screen-kits-fitness/apps/native/src/app/screen-kits/fitness/index.tsx +6 -0
- package/recipes/screen-kits-fitness/apps/native/src/app/screen-kits/fitness/timer.tsx +3 -0
- package/recipes/screen-kits-fitness/apps/native/src/app/screen-kits/fitness/workout.tsx +3 -0
- package/recipes/screen-kits-fitness/apps/native/src/features/screen-kits/fitness/components/timer-components.tsx +500 -0
- package/recipes/screen-kits-fitness/apps/native/src/features/screen-kits/fitness/components/timer-settings-modal.tsx +352 -0
- package/recipes/screen-kits-fitness/apps/native/src/features/screen-kits/fitness/components/workout-card.tsx +105 -0
- package/recipes/screen-kits-fitness/apps/native/src/features/screen-kits/fitness/constants.ts +189 -0
- package/recipes/screen-kits-fitness/apps/native/src/features/screen-kits/fitness/hooks/use-timer.ts +307 -0
- package/recipes/screen-kits-fitness/apps/native/src/features/screen-kits/fitness/index.ts +1 -0
- package/recipes/screen-kits-fitness/apps/native/src/features/screen-kits/fitness/screens/timer-screen.tsx +278 -0
- package/recipes/screen-kits-fitness/apps/native/src/features/screen-kits/fitness/screens/workout-dashboard.tsx +350 -0
- package/recipes/screen-kits-fitness/recipe.json +63 -0
- package/recipes/screen-kits-fitness-native@latest.zip +0 -0
- package/recipes/screen-kits-habits/apps/native/src/app/screen-kits/productivity/habits.tsx +1 -0
- package/recipes/screen-kits-habits/apps/native/src/app/screen-kits/productivity/kanban.tsx +1 -0
- package/recipes/screen-kits-habits/apps/native/src/app/screen-kits/productivity/routes.ts +4 -0
- package/recipes/screen-kits-habits/apps/native/src/features/screen-kits/productivity/components/AddTaskModal.tsx +246 -0
- package/recipes/screen-kits-habits/apps/native/src/features/screen-kits/productivity/components/DraggableTaskCard.tsx +92 -0
- package/recipes/screen-kits-habits/apps/native/src/features/screen-kits/productivity/components/KanbanColumn.tsx +238 -0
- package/recipes/screen-kits-habits/apps/native/src/features/screen-kits/productivity/components/TaskCard.tsx +144 -0
- package/recipes/screen-kits-habits/apps/native/src/features/screen-kits/productivity/components/add-habit-modal.tsx +271 -0
- package/recipes/screen-kits-habits/apps/native/src/features/screen-kits/productivity/constants.ts +295 -0
- package/recipes/screen-kits-habits/apps/native/src/features/screen-kits/productivity/kanban-utils.ts +62 -0
- package/recipes/screen-kits-habits/apps/native/src/features/screen-kits/productivity/screens/habit-tracker.tsx +1160 -0
- package/recipes/screen-kits-habits/apps/native/src/features/screen-kits/productivity/screens/kanban-board.tsx +432 -0
- package/recipes/screen-kits-habits/recipe.json +52 -0
- package/recipes/screen-kits-habits-native@latest.zip +0 -0
- package/recipes/screen-kits-native@latest.zip +0 -0
- package/recipes/sentry/apps/native/src/providers/sentry-provider.tsx +64 -0
- package/recipes/sentry/recipe.json +39 -0
- package/recipes/sentry-native@latest.zip +0 -0
- package/recipes/swipe-slider/apps/native/src/components/advanced-ui/sliders/swipe-slider-page.tsx +1 -1
- package/recipes/swipe-slider/recipe.json +5 -2
- package/recipes/swipe-slider-native@latest.zip +0 -0
- package/recipes/swipe-slider@latest.zip +0 -0
- package/recipes/timeline/apps/native/src/components/advanced-ui/timeline/demo.tsx +2 -1
- package/recipes/timeline/recipe.json +5 -2
- package/recipes/timeline-native@latest.zip +0 -0
- package/recipes/timeline@latest.zip +0 -0
- package/recipes/tracker-app/apps/native/src/app/tracker-app/index.tsx +1 -0
- package/recipes/tracker-app/recipe.json +10 -7
- package/recipes/tracker-app-native@latest.zip +0 -0
- package/recipes/tracker-app@latest.zip +0 -0
- package/recipes/upload-all.sh +8 -31
- package/recipes/voice-bot/apps/native/src/app/voice-bot/index.tsx +56 -0
- package/recipes/voice-bot/recipe.json +31 -7
- package/recipes/voice-bot-native@latest.zip +0 -0
- package/recipes/voice-bot@latest.zip +0 -0
- package/recipes/wake-word/apps/native/src/app/{(root)/(protected)/test-wake-word.tsx → test-wake-word.tsx} +43 -4
- package/recipes/wake-word/recipe.json +16 -26
- package/recipes/wake-word-native@latest.zip +0 -0
- package/recipes/wake-word@latest.zip +0 -0
- package/scripts/create-advanced-ui-recipes.sh +46 -19
- package/scripts/create-recipes.mjs +471 -117
- package/scripts/package-recipes.mjs +76 -0
- package/scripts/publish-all.sh +6 -2
- package/CHANGELOG.md +0 -198
- package/docs/archive/AUTO-DETECT-DEPS.md +0 -607
- package/docs/archive/FINAL-PACKAGE-STRATEGY.md +0 -583
- package/docs/archive/FINAL-SIMPLE-PLAN.md +0 -487
- package/docs/archive/FINAL-STATUS.md +0 -144
- package/docs/archive/FLOW-DIAGRAM.md +0 -1629
- package/docs/archive/GOTCHAS-AND-RISKS.md +0 -801
- package/docs/archive/IMPLEMENTATION-PLAN.md +0 -1360
- package/docs/archive/PLAN.md +0 -453
- package/docs/archive/PRODUCTION-READINESS.md +0 -684
- package/docs/archive/PRODUCTION-TEST-RESULTS.md +0 -465
- package/docs/archive/SIMPLIFIED-PLAN.md +0 -578
- package/docs/archive/STATUS.md +0 -199
- package/docs/archive/SUCCESS.md +0 -259
- package/docs/archive/TEST-SUMMARY.md +0 -261
- package/docs/archive/TESTING-CHECKLIST.md +0 -450
- package/docs/archive/USER-MODIFICATIONS.md +0 -448
- package/docs/decisions.md +0 -55
- package/docs/manual-testing.md +0 -91
- package/docs/next-steps.md +0 -12
- package/recipes/README.md +0 -156
- package/recipes/audio-recorder-supabase/packages/backend/src/services/recordings.ts +0 -369
- package/recipes/chatbot/apps/native/src/api-client/chatbot.ts +0 -83
- package/recipes/chatbot/packages/backend/convex/agents.ts +0 -115
- package/recipes/chatbot/packages/backend/convex/tools/index.ts +0 -18
- package/recipes/chatbot/packages/backend/convex/tools/knowledgeRetrieval.ts +0 -97
- package/recipes/chatbot/packages/backend/convex/tools/tavilySearch.ts +0 -83
- package/recipes/chatbot/packages/backend/convex/tools/userProfile.ts +0 -72
- package/recipes/chatbot-supabase/apps/native/src/api-client/supabase/chatbot.ts +0 -515
- package/recipes/chatbot-supabase/packages/backend/src/services/conversations.ts +0 -243
- package/recipes/chatbot-supabase/packages/backend/src/services/messages.ts +0 -327
- package/recipes/image-analysis/apps/native/src/api-client/image-analyzer.ts +0 -62
- package/recipes/image-analysis-supabase/packages/backend/src/services/image-analyses.ts +0 -132
- package/recipes/image-generator/apps/native/src/api-client/image-generator.ts +0 -34
- package/recipes/payments/apps/native/src/api-client/payments.ts +0 -44
- package/recipes/payments-supabase/packages/backend/src/services/payments.ts +0 -201
- package/recipes/posthog.json +0 -47
- package/recipes/revenuecat.json +0 -43
- package/recipes/sentry.json +0 -47
- package/recipes/wake-word/apps/native/assets/vosk-model/README.md +0 -103
- package/recipes/wake-word/apps/native/scripts/download-vosk-model.mjs +0 -127
- /package/recipes/{audio-recorder/apps/native/src/app/(root)/(protected) → audio-recorder-supabase/apps/native/src/app}/audio-recorder/index.tsx +0 -0
- /package/recipes/ios-widget/{targets → apps/native/targets}/widget/AppIntent.swift +0 -0
- /package/recipes/ios-widget/{targets → apps/native/targets}/widget/Assets.xcassets/AppIcon.appiconset/App-Icon-20x20@1x.png +0 -0
- /package/recipes/ios-widget/{targets → apps/native/targets}/widget/Assets.xcassets/AppIcon.appiconset/App-Icon-20x20@2x.png +0 -0
- /package/recipes/ios-widget/{targets → apps/native/targets}/widget/Assets.xcassets/AppIcon.appiconset/App-Icon-20x20@3x.png +0 -0
- /package/recipes/ios-widget/{targets → apps/native/targets}/widget/Assets.xcassets/AppIcon.appiconset/App-Icon-29x29@1x.png +0 -0
- /package/recipes/ios-widget/{targets → apps/native/targets}/widget/Assets.xcassets/AppIcon.appiconset/App-Icon-29x29@2x.png +0 -0
- /package/recipes/ios-widget/{targets → apps/native/targets}/widget/Assets.xcassets/AppIcon.appiconset/App-Icon-29x29@3x.png +0 -0
- /package/recipes/ios-widget/{targets → apps/native/targets}/widget/Assets.xcassets/AppIcon.appiconset/App-Icon-40x40@1x.png +0 -0
- /package/recipes/ios-widget/{targets → apps/native/targets}/widget/Assets.xcassets/AppIcon.appiconset/App-Icon-40x40@2x.png +0 -0
- /package/recipes/ios-widget/{targets → apps/native/targets}/widget/Assets.xcassets/AppIcon.appiconset/App-Icon-40x40@3x.png +0 -0
- /package/recipes/ios-widget/{targets → apps/native/targets}/widget/Assets.xcassets/AppIcon.appiconset/App-Icon-60x60@2x.png +0 -0
- /package/recipes/ios-widget/{targets → apps/native/targets}/widget/Assets.xcassets/AppIcon.appiconset/App-Icon-60x60@3x.png +0 -0
- /package/recipes/ios-widget/{targets → apps/native/targets}/widget/Assets.xcassets/AppIcon.appiconset/App-Icon-76x76@1x.png +0 -0
- /package/recipes/ios-widget/{targets → apps/native/targets}/widget/Assets.xcassets/AppIcon.appiconset/App-Icon-76x76@2x.png +0 -0
- /package/recipes/ios-widget/{targets → apps/native/targets}/widget/Assets.xcassets/AppIcon.appiconset/App-Icon-83.5x83.5@2x.png +0 -0
- /package/recipes/ios-widget/{targets → apps/native/targets}/widget/Assets.xcassets/AppIcon.appiconset/Contents.json +0 -0
- /package/recipes/ios-widget/{targets → apps/native/targets}/widget/Assets.xcassets/AppIcon.appiconset/ItunesArtwork@2x.png +0 -0
- /package/recipes/ios-widget/{targets → apps/native/targets}/widget/CalorieTrackerWidget.swift +0 -0
- /package/recipes/ios-widget/{targets → apps/native/targets}/widget/HabitTrackerWidget.swift +0 -0
- /package/recipes/ios-widget/{targets → apps/native/targets}/widget/Info.plist +0 -0
- /package/recipes/ios-widget/{targets → apps/native/targets}/widget/WidgetLiveActivity.swift +0 -0
- /package/recipes/ios-widget/{targets → apps/native/targets}/widget/expo-target.config.js +0 -0
- /package/recipes/ios-widget/{targets → apps/native/targets}/widget/generated.entitlements +0 -0
- /package/recipes/ios-widget/{targets → apps/native/targets}/widget/index.swift +0 -0
- /package/recipes/ios-widget/{targets → apps/native/targets}/widget/widgets.swift +0 -0
|
@@ -1,515 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Supabase Chatbot API Hooks
|
|
3
|
-
*
|
|
4
|
-
* This module provides React hooks for chatbot operations
|
|
5
|
-
* including conversations, messages, and AI chat streaming.
|
|
6
|
-
*
|
|
7
|
-
* Requirements: 13.3
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import { Env } from '@env';
|
|
11
|
-
import {
|
|
12
|
-
useInfiniteQuery,
|
|
13
|
-
useMutation,
|
|
14
|
-
useQuery,
|
|
15
|
-
useQueryClient,
|
|
16
|
-
} from '@tanstack/react-query';
|
|
17
|
-
import {
|
|
18
|
-
clearConversationMessages,
|
|
19
|
-
createConversation,
|
|
20
|
-
deleteConversation,
|
|
21
|
-
deleteUserMessage,
|
|
22
|
-
getOrCreateDefault,
|
|
23
|
-
listConversations,
|
|
24
|
-
listMessages,
|
|
25
|
-
storeMessage,
|
|
26
|
-
type StoreMessageInput,
|
|
27
|
-
} from '@vibefast/backend';
|
|
28
|
-
import { useCallback, useRef, useState } from 'react';
|
|
29
|
-
|
|
30
|
-
import { getSupabase } from './client';
|
|
31
|
-
|
|
32
|
-
// Query keys for cache management
|
|
33
|
-
export const chatbotQueryKeys = {
|
|
34
|
-
conversations: ['chatbot', 'conversations'] as const,
|
|
35
|
-
conversation: (id: string) => ['chatbot', 'conversation', id] as const,
|
|
36
|
-
messages: (conversationId: string) =>
|
|
37
|
-
['chatbot', 'messages', conversationId] as const,
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Hook to get or create the default conversation
|
|
42
|
-
*/
|
|
43
|
-
export function useGetOrCreateConversation() {
|
|
44
|
-
const queryClient = useQueryClient();
|
|
45
|
-
|
|
46
|
-
return useMutation({
|
|
47
|
-
mutationFn: async () => {
|
|
48
|
-
const supabase = getSupabase();
|
|
49
|
-
const result = await getOrCreateDefault(supabase);
|
|
50
|
-
|
|
51
|
-
if (!result.success) {
|
|
52
|
-
throw new Error(result.error || 'Failed to get or create conversation');
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
return result.conversation;
|
|
56
|
-
},
|
|
57
|
-
onSuccess: (data) => {
|
|
58
|
-
if (data) {
|
|
59
|
-
queryClient.setQueryData(chatbotQueryKeys.conversation(data.id), data);
|
|
60
|
-
queryClient.invalidateQueries({
|
|
61
|
-
queryKey: chatbotQueryKeys.conversations,
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
},
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Hook to create a new conversation
|
|
70
|
-
*/
|
|
71
|
-
export function useCreateConversation() {
|
|
72
|
-
const queryClient = useQueryClient();
|
|
73
|
-
|
|
74
|
-
return useMutation({
|
|
75
|
-
mutationFn: async ({ name }: { name?: string } = {}) => {
|
|
76
|
-
const supabase = getSupabase();
|
|
77
|
-
const result = await createConversation(supabase, name);
|
|
78
|
-
|
|
79
|
-
if (!result.success) {
|
|
80
|
-
throw new Error(result.error || 'Failed to create conversation');
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
return result.conversation;
|
|
84
|
-
},
|
|
85
|
-
onSuccess: () => {
|
|
86
|
-
queryClient.invalidateQueries({
|
|
87
|
-
queryKey: chatbotQueryKeys.conversations,
|
|
88
|
-
});
|
|
89
|
-
},
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Hook to list all conversations
|
|
95
|
-
*/
|
|
96
|
-
export function useListConversations() {
|
|
97
|
-
return useQuery({
|
|
98
|
-
queryKey: chatbotQueryKeys.conversations,
|
|
99
|
-
queryFn: async () => {
|
|
100
|
-
const supabase = getSupabase();
|
|
101
|
-
const result = await listConversations(supabase);
|
|
102
|
-
|
|
103
|
-
if (!result.success) {
|
|
104
|
-
throw new Error(result.error || 'Failed to list conversations');
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
return result.conversations;
|
|
108
|
-
},
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Hook to delete a conversation
|
|
114
|
-
*/
|
|
115
|
-
export function useDeleteConversation() {
|
|
116
|
-
const queryClient = useQueryClient();
|
|
117
|
-
|
|
118
|
-
return useMutation({
|
|
119
|
-
mutationFn: async ({ conversationId }: { conversationId: string }) => {
|
|
120
|
-
const supabase = getSupabase();
|
|
121
|
-
const result = await deleteConversation(supabase, conversationId);
|
|
122
|
-
|
|
123
|
-
if (!result.success) {
|
|
124
|
-
throw new Error(result.error || 'Failed to delete conversation');
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
return { success: true };
|
|
128
|
-
},
|
|
129
|
-
onSuccess: (_, { conversationId }) => {
|
|
130
|
-
queryClient.removeQueries({
|
|
131
|
-
queryKey: chatbotQueryKeys.conversation(conversationId),
|
|
132
|
-
});
|
|
133
|
-
queryClient.removeQueries({
|
|
134
|
-
queryKey: chatbotQueryKeys.messages(conversationId),
|
|
135
|
-
});
|
|
136
|
-
queryClient.invalidateQueries({
|
|
137
|
-
queryKey: chatbotQueryKeys.conversations,
|
|
138
|
-
});
|
|
139
|
-
},
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* Hook to list messages for a conversation with pagination
|
|
145
|
-
*/
|
|
146
|
-
export function useListMessages(conversationId: string | null | undefined) {
|
|
147
|
-
return useInfiniteQuery({
|
|
148
|
-
queryKey: chatbotQueryKeys.messages(conversationId || ''),
|
|
149
|
-
queryFn: async ({ pageParam }) => {
|
|
150
|
-
if (!conversationId) {
|
|
151
|
-
return { messages: [], hasMore: false };
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
const supabase = getSupabase();
|
|
155
|
-
const result = await listMessages(supabase, conversationId, {
|
|
156
|
-
limit: 50,
|
|
157
|
-
cursor: pageParam,
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
if (!result.success) {
|
|
161
|
-
throw new Error(result.error || 'Failed to list messages');
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
return { messages: result.messages, hasMore: result.hasMore };
|
|
165
|
-
},
|
|
166
|
-
initialPageParam: undefined as string | undefined,
|
|
167
|
-
getNextPageParam: (lastPage) =>
|
|
168
|
-
lastPage?.hasMore
|
|
169
|
-
? lastPage.messages?.[lastPage.messages.length - 1]?.created_at
|
|
170
|
-
: undefined,
|
|
171
|
-
enabled: !!conversationId,
|
|
172
|
-
});
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
/**
|
|
176
|
-
* Hook to store a message
|
|
177
|
-
*/
|
|
178
|
-
export function useStoreMessage() {
|
|
179
|
-
const queryClient = useQueryClient();
|
|
180
|
-
|
|
181
|
-
return useMutation({
|
|
182
|
-
mutationFn: async (input: StoreMessageInput) => {
|
|
183
|
-
const supabase = getSupabase();
|
|
184
|
-
const result = await storeMessage(supabase, input);
|
|
185
|
-
|
|
186
|
-
if (!result.success) {
|
|
187
|
-
throw new Error(result.error || 'Failed to store message');
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
return result.message;
|
|
191
|
-
},
|
|
192
|
-
onSuccess: (_, input) => {
|
|
193
|
-
queryClient.invalidateQueries({
|
|
194
|
-
queryKey: chatbotQueryKeys.messages(input.conversationId),
|
|
195
|
-
});
|
|
196
|
-
},
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
/**
|
|
201
|
-
* Hook to delete a user message
|
|
202
|
-
*/
|
|
203
|
-
export function useDeleteUserMessage() {
|
|
204
|
-
const queryClient = useQueryClient();
|
|
205
|
-
|
|
206
|
-
return useMutation({
|
|
207
|
-
mutationFn: async ({
|
|
208
|
-
messageId,
|
|
209
|
-
conversationId,
|
|
210
|
-
}: {
|
|
211
|
-
messageId: string;
|
|
212
|
-
conversationId: string;
|
|
213
|
-
}) => {
|
|
214
|
-
const supabase = getSupabase();
|
|
215
|
-
const result = await deleteUserMessage(supabase, messageId);
|
|
216
|
-
|
|
217
|
-
if (!result.success) {
|
|
218
|
-
throw new Error(result.error || 'Failed to delete message');
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
return { success: true, conversationId };
|
|
222
|
-
},
|
|
223
|
-
onSuccess: (data) => {
|
|
224
|
-
queryClient.invalidateQueries({
|
|
225
|
-
queryKey: chatbotQueryKeys.messages(data.conversationId),
|
|
226
|
-
});
|
|
227
|
-
},
|
|
228
|
-
});
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
/**
|
|
232
|
-
* Hook to clear all messages in a conversation
|
|
233
|
-
*/
|
|
234
|
-
export function useClearConversation() {
|
|
235
|
-
const queryClient = useQueryClient();
|
|
236
|
-
|
|
237
|
-
return useMutation({
|
|
238
|
-
mutationFn: async ({ conversationId }: { conversationId: string }) => {
|
|
239
|
-
const supabase = getSupabase();
|
|
240
|
-
const result = await clearConversationMessages(supabase, conversationId);
|
|
241
|
-
|
|
242
|
-
if (!result.success) {
|
|
243
|
-
throw new Error(result.error || 'Failed to clear conversation');
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
return { success: true, conversationId };
|
|
247
|
-
},
|
|
248
|
-
onSuccess: (data) => {
|
|
249
|
-
queryClient.invalidateQueries({
|
|
250
|
-
queryKey: chatbotQueryKeys.messages(data.conversationId),
|
|
251
|
-
});
|
|
252
|
-
},
|
|
253
|
-
});
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
// Chat stream types
|
|
257
|
-
interface ChatStreamOptions {
|
|
258
|
-
conversationId: string;
|
|
259
|
-
message: string;
|
|
260
|
-
attachments?: {
|
|
261
|
-
type: string;
|
|
262
|
-
url: string;
|
|
263
|
-
name?: string;
|
|
264
|
-
}[];
|
|
265
|
-
preferredModel?: string;
|
|
266
|
-
onText?: (text: string) => void;
|
|
267
|
-
onToolCall?: (toolCall: {
|
|
268
|
-
name: string;
|
|
269
|
-
args: Record<string, unknown>;
|
|
270
|
-
}) => void;
|
|
271
|
-
onDone?: (messageId: string) => void;
|
|
272
|
-
onError?: (error: Error) => void;
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
/**
|
|
276
|
-
* Hook for chat streaming using Supabase Realtime Broadcast
|
|
277
|
-
*
|
|
278
|
-
* Flow:
|
|
279
|
-
* 1. Generate unique stream ID
|
|
280
|
-
* 2. Subscribe to broadcast channel
|
|
281
|
-
* 3. Call edge function with stream ID
|
|
282
|
-
* 4. Receive chunks via broadcast
|
|
283
|
-
* 5. Complete when 'done' event received
|
|
284
|
-
*/
|
|
285
|
-
export function useChatStream() {
|
|
286
|
-
const [isStreaming, setIsStreaming] = useState(false);
|
|
287
|
-
const [streamingText, setStreamingText] = useState('');
|
|
288
|
-
const abortControllerRef = useRef<AbortController | null>(null);
|
|
289
|
-
const channelRef = useRef<ReturnType<
|
|
290
|
-
ReturnType<typeof getSupabase>['channel']
|
|
291
|
-
> | null>(null);
|
|
292
|
-
const queryClient = useQueryClient();
|
|
293
|
-
|
|
294
|
-
const startStream = useCallback(
|
|
295
|
-
async (options: ChatStreamOptions) => {
|
|
296
|
-
const {
|
|
297
|
-
conversationId,
|
|
298
|
-
message,
|
|
299
|
-
attachments,
|
|
300
|
-
preferredModel,
|
|
301
|
-
onText,
|
|
302
|
-
onDone,
|
|
303
|
-
onError,
|
|
304
|
-
} = options;
|
|
305
|
-
|
|
306
|
-
// Cleanup previous
|
|
307
|
-
if (channelRef.current) {
|
|
308
|
-
const supabase = getSupabase();
|
|
309
|
-
supabase.removeChannel(channelRef.current);
|
|
310
|
-
channelRef.current = null;
|
|
311
|
-
}
|
|
312
|
-
if (abortControllerRef.current) {
|
|
313
|
-
abortControllerRef.current.abort();
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
const abortController = new AbortController();
|
|
317
|
-
abortControllerRef.current = abortController;
|
|
318
|
-
|
|
319
|
-
setIsStreaming(true);
|
|
320
|
-
setStreamingText('');
|
|
321
|
-
|
|
322
|
-
// Generate unique stream ID
|
|
323
|
-
const streamId = `${conversationId}-${Date.now()}`;
|
|
324
|
-
let receivedDone = false;
|
|
325
|
-
|
|
326
|
-
try {
|
|
327
|
-
const supabase = getSupabase();
|
|
328
|
-
const {
|
|
329
|
-
data: { session },
|
|
330
|
-
} = await supabase.auth.getSession();
|
|
331
|
-
|
|
332
|
-
if (!session?.access_token) {
|
|
333
|
-
throw new Error('Not authenticated');
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
// Subscribe to broadcast channel BEFORE calling edge function
|
|
337
|
-
const channelName = `stream:${streamId}`;
|
|
338
|
-
console.log('[ChatStream] Subscribing to channel:', channelName);
|
|
339
|
-
|
|
340
|
-
const channel = supabase.channel(channelName);
|
|
341
|
-
channelRef.current = channel;
|
|
342
|
-
|
|
343
|
-
// Set up event handlers
|
|
344
|
-
channel
|
|
345
|
-
.on('broadcast', { event: 'chunk' }, (payload) => {
|
|
346
|
-
const { accumulated } = payload.payload as {
|
|
347
|
-
chunk: string;
|
|
348
|
-
accumulated: string;
|
|
349
|
-
};
|
|
350
|
-
console.log(
|
|
351
|
-
'[ChatStream] Received chunk, total length:',
|
|
352
|
-
accumulated.length,
|
|
353
|
-
);
|
|
354
|
-
setStreamingText(accumulated);
|
|
355
|
-
onText?.(accumulated);
|
|
356
|
-
})
|
|
357
|
-
.on('broadcast', { event: 'done' }, (payload) => {
|
|
358
|
-
const { content, msgId } = payload.payload as {
|
|
359
|
-
content: string;
|
|
360
|
-
msgId: string;
|
|
361
|
-
};
|
|
362
|
-
console.log('[ChatStream] Stream done, messageId:', msgId);
|
|
363
|
-
receivedDone = true;
|
|
364
|
-
setStreamingText(content);
|
|
365
|
-
onText?.(content);
|
|
366
|
-
onDone?.(msgId);
|
|
367
|
-
setIsStreaming(false);
|
|
368
|
-
|
|
369
|
-
// Cleanup
|
|
370
|
-
supabase.removeChannel(channel);
|
|
371
|
-
channelRef.current = null;
|
|
372
|
-
|
|
373
|
-
// Invalidate cache
|
|
374
|
-
queryClient.invalidateQueries({
|
|
375
|
-
queryKey: chatbotQueryKeys.messages(conversationId),
|
|
376
|
-
});
|
|
377
|
-
})
|
|
378
|
-
.on('broadcast', { event: 'error' }, (payload) => {
|
|
379
|
-
const { error } = payload.payload as { error: string };
|
|
380
|
-
console.error('[ChatStream] Received error:', error);
|
|
381
|
-
onError?.(new Error(error));
|
|
382
|
-
setIsStreaming(false);
|
|
383
|
-
supabase.removeChannel(channel);
|
|
384
|
-
channelRef.current = null;
|
|
385
|
-
});
|
|
386
|
-
|
|
387
|
-
// Wait for subscription to be ready
|
|
388
|
-
await new Promise<void>((resolve, reject) => {
|
|
389
|
-
const timeout = setTimeout(
|
|
390
|
-
() => reject(new Error('Channel subscription timeout')),
|
|
391
|
-
5000,
|
|
392
|
-
);
|
|
393
|
-
channel.subscribe((status) => {
|
|
394
|
-
if (status === 'SUBSCRIBED') {
|
|
395
|
-
clearTimeout(timeout);
|
|
396
|
-
console.log('[ChatStream] Channel subscribed');
|
|
397
|
-
resolve();
|
|
398
|
-
} else if (status === 'CHANNEL_ERROR') {
|
|
399
|
-
clearTimeout(timeout);
|
|
400
|
-
reject(new Error('Channel subscription failed'));
|
|
401
|
-
}
|
|
402
|
-
});
|
|
403
|
-
});
|
|
404
|
-
|
|
405
|
-
// Now call edge function with streamId
|
|
406
|
-
const streamUrl = `${Env.SUPABASE_URL}/functions/v1/chat-stream`;
|
|
407
|
-
console.log(
|
|
408
|
-
'[ChatStream] Calling edge function with streamId:',
|
|
409
|
-
streamId,
|
|
410
|
-
);
|
|
411
|
-
|
|
412
|
-
const response = await fetch(streamUrl, {
|
|
413
|
-
method: 'POST',
|
|
414
|
-
headers: {
|
|
415
|
-
'Content-Type': 'application/json',
|
|
416
|
-
Authorization: `Bearer ${session.access_token}`,
|
|
417
|
-
},
|
|
418
|
-
body: JSON.stringify({
|
|
419
|
-
conversationId,
|
|
420
|
-
message,
|
|
421
|
-
attachments,
|
|
422
|
-
preferredModel,
|
|
423
|
-
streamId, // Pass streamId so edge function knows which channel to use
|
|
424
|
-
}),
|
|
425
|
-
signal: abortController.signal,
|
|
426
|
-
});
|
|
427
|
-
|
|
428
|
-
const result = await response.json();
|
|
429
|
-
console.log('[ChatStream] Edge function returned:', {
|
|
430
|
-
success: result.success,
|
|
431
|
-
messageId: result.messageId,
|
|
432
|
-
});
|
|
433
|
-
|
|
434
|
-
// If we didn't receive done event via broadcast, handle it here
|
|
435
|
-
if (!receivedDone && result.success) {
|
|
436
|
-
const content = result.content || '';
|
|
437
|
-
setStreamingText(content);
|
|
438
|
-
onText?.(content);
|
|
439
|
-
onDone?.(result.messageId || 'unknown');
|
|
440
|
-
setIsStreaming(false);
|
|
441
|
-
|
|
442
|
-
if (channelRef.current) {
|
|
443
|
-
supabase.removeChannel(channelRef.current);
|
|
444
|
-
channelRef.current = null;
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
queryClient.invalidateQueries({
|
|
448
|
-
queryKey: chatbotQueryKeys.messages(conversationId),
|
|
449
|
-
});
|
|
450
|
-
}
|
|
451
|
-
|
|
452
|
-
if (!result.success) {
|
|
453
|
-
throw new Error(result.error || 'Failed to generate response');
|
|
454
|
-
}
|
|
455
|
-
} catch (error) {
|
|
456
|
-
if (error instanceof Error && error.name === 'AbortError') {
|
|
457
|
-
return;
|
|
458
|
-
}
|
|
459
|
-
|
|
460
|
-
const err = error instanceof Error ? error : new Error(String(error));
|
|
461
|
-
console.error('[ChatStream] Error:', err);
|
|
462
|
-
onError?.(err);
|
|
463
|
-
setIsStreaming(false);
|
|
464
|
-
|
|
465
|
-
// Cleanup
|
|
466
|
-
if (channelRef.current) {
|
|
467
|
-
const supabase = getSupabase();
|
|
468
|
-
supabase.removeChannel(channelRef.current);
|
|
469
|
-
channelRef.current = null;
|
|
470
|
-
}
|
|
471
|
-
|
|
472
|
-
throw err;
|
|
473
|
-
}
|
|
474
|
-
},
|
|
475
|
-
[queryClient],
|
|
476
|
-
);
|
|
477
|
-
|
|
478
|
-
const stopStream = useCallback(() => {
|
|
479
|
-
if (channelRef.current) {
|
|
480
|
-
const supabase = getSupabase();
|
|
481
|
-
supabase.removeChannel(channelRef.current);
|
|
482
|
-
channelRef.current = null;
|
|
483
|
-
}
|
|
484
|
-
if (abortControllerRef.current) {
|
|
485
|
-
abortControllerRef.current.abort();
|
|
486
|
-
abortControllerRef.current = null;
|
|
487
|
-
}
|
|
488
|
-
setIsStreaming(false);
|
|
489
|
-
}, []);
|
|
490
|
-
|
|
491
|
-
return {
|
|
492
|
-
startStream,
|
|
493
|
-
stopStream,
|
|
494
|
-
isStreaming,
|
|
495
|
-
streamingText,
|
|
496
|
-
};
|
|
497
|
-
}
|
|
498
|
-
|
|
499
|
-
/**
|
|
500
|
-
* Supabase Chatbot API object for consistent access pattern
|
|
501
|
-
*/
|
|
502
|
-
export const supabaseChatbotApi = {
|
|
503
|
-
useGetOrCreateConversation,
|
|
504
|
-
useCreateConversation,
|
|
505
|
-
useListConversations,
|
|
506
|
-
useDeleteConversation,
|
|
507
|
-
useListMessages,
|
|
508
|
-
useStoreMessage,
|
|
509
|
-
useDeleteUserMessage,
|
|
510
|
-
useClearConversation,
|
|
511
|
-
useChatStream,
|
|
512
|
-
queryKeys: chatbotQueryKeys,
|
|
513
|
-
};
|
|
514
|
-
|
|
515
|
-
export type SupabaseChatbotApi = typeof supabaseChatbotApi;
|