@lastbrain/module-ai 2.0.26 → 2.0.30
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 +52 -1
- package/dist/ai.build.config.d.ts.map +1 -1
- package/dist/ai.build.config.js +508 -9
- package/dist/api/admin/ai-provider-models/[id].d.ts +18 -0
- package/dist/api/admin/ai-provider-models/[id].d.ts.map +1 -0
- package/dist/api/admin/ai-provider-models/[id].js +58 -0
- package/dist/api/admin/ai-provider-models.d.ts +20 -0
- package/dist/api/admin/ai-provider-models.d.ts.map +1 -0
- package/dist/api/admin/ai-provider-models.js +26 -0
- package/dist/api/admin/ai-providers/[key].d.ts +18 -0
- package/dist/api/admin/ai-providers/[key].d.ts.map +1 -0
- package/dist/api/admin/ai-providers/[key].js +55 -0
- package/dist/api/admin/ai-providers.d.ts +20 -0
- package/dist/api/admin/ai-providers.d.ts.map +1 -0
- package/dist/api/admin/ai-providers.js +26 -0
- package/dist/api/admin/billing-analytics.d.ts +43 -0
- package/dist/api/admin/billing-analytics.d.ts.map +1 -0
- package/dist/api/admin/billing-analytics.js +144 -0
- package/dist/api/admin/global-ai-settings.d.ts +14 -0
- package/dist/api/admin/global-ai-settings.d.ts.map +1 -0
- package/dist/api/admin/global-ai-settings.js +63 -0
- package/dist/api/admin/token-packs/[id].d.ts.map +1 -1
- package/dist/api/admin/token-packs/[id].js +3 -2
- package/dist/api/admin/token-packs.d.ts.map +1 -1
- package/dist/api/admin/token-packs.js +3 -2
- package/dist/api/admin/user-monthly-details.d.ts +49 -0
- package/dist/api/admin/user-monthly-details.d.ts.map +1 -0
- package/dist/api/admin/user-monthly-details.js +140 -0
- package/dist/api/admin/user-quota.d.ts +21 -0
- package/dist/api/admin/user-quota.d.ts.map +1 -0
- package/dist/api/admin/user-quota.js +59 -0
- package/dist/api/admin/user-token/[id].d.ts.map +1 -1
- package/dist/api/admin/user-token/[id].js +2 -1
- package/dist/api/admin/user-token.d.ts +5 -2
- package/dist/api/admin/user-token.d.ts.map +1 -1
- package/dist/api/admin/user-token.js +91 -17
- package/dist/api/admin/user-usage-by-model.d.ts +22 -0
- package/dist/api/admin/user-usage-by-model.d.ts.map +1 -0
- package/dist/api/admin/user-usage-by-model.js +78 -0
- package/dist/api/admin/user-wallet-analytics.d.ts +15 -0
- package/dist/api/admin/user-wallet-analytics.d.ts.map +1 -0
- package/dist/api/admin/user-wallet-analytics.js +67 -0
- package/dist/api/admin/wallet-repair/route.d.ts +30 -0
- package/dist/api/admin/wallet-repair/route.d.ts.map +1 -0
- package/dist/api/admin/wallet-repair/route.js +63 -0
- package/dist/api/auth/ai-model-settings.d.ts +21 -0
- package/dist/api/auth/ai-model-settings.d.ts.map +1 -0
- package/dist/api/auth/ai-model-settings.js +86 -0
- package/dist/api/auth/ai-settings.d.ts +17 -0
- package/dist/api/auth/ai-settings.d.ts.map +1 -0
- package/dist/api/auth/ai-settings.js +87 -0
- package/dist/api/auth/api-keys/[id].d.ts +17 -0
- package/dist/api/auth/api-keys/[id].d.ts.map +1 -0
- package/dist/api/auth/api-keys/[id].js +66 -0
- package/dist/api/auth/api-keys.d.ts +19 -0
- package/dist/api/auth/api-keys.d.ts.map +1 -0
- package/dist/api/auth/api-keys.js +94 -0
- package/dist/api/auth/create-checkout.d.ts +1 -1
- package/dist/api/auth/create-checkout.d.ts.map +1 -1
- package/dist/api/auth/create-checkout.js +8 -6
- package/dist/api/auth/generate-image.d.ts +2 -2
- package/dist/api/auth/generate-image.d.ts.map +1 -1
- package/dist/api/auth/generate-image.js +404 -104
- package/dist/api/auth/generate-text.d.ts +3 -2
- package/dist/api/auth/generate-text.d.ts.map +1 -1
- package/dist/api/auth/generate-text.js +130 -58
- package/dist/api/auth/process-ocr.d.ts +9 -0
- package/dist/api/auth/process-ocr.d.ts.map +1 -0
- package/dist/api/auth/process-ocr.js +43 -0
- package/dist/api/auth/prompts/stats.d.ts +14 -0
- package/dist/api/auth/prompts/stats.d.ts.map +1 -0
- package/dist/api/auth/prompts/stats.js +46 -0
- package/dist/api/auth/prompts.d.ts +26 -0
- package/dist/api/auth/prompts.d.ts.map +1 -0
- package/dist/api/auth/prompts.js +175 -0
- package/dist/api/auth/token-balance.d.ts +26 -0
- package/dist/api/auth/token-balance.d.ts.map +1 -0
- package/dist/api/auth/token-balance.js +47 -0
- package/dist/api/auth/token-checkout.d.ts.map +1 -1
- package/dist/api/auth/token-checkout.js +22 -4
- package/dist/api/auth/token-packs.d.ts.map +1 -1
- package/dist/api/auth/token-packs.js +2 -1
- package/dist/api/auth/usage-by-model.d.ts +25 -0
- package/dist/api/auth/usage-by-model.d.ts.map +1 -0
- package/dist/api/auth/usage-by-model.js +95 -0
- package/dist/api/auth/usage.d.ts +26 -0
- package/dist/api/auth/usage.d.ts.map +1 -0
- package/dist/api/auth/usage.js +127 -0
- package/dist/api/auth/user-tokens.d.ts.map +1 -1
- package/dist/api/auth/user-tokens.js +36 -2
- package/dist/api/auth/wallet/route.d.ts +17 -0
- package/dist/api/auth/wallet/route.d.ts.map +1 -0
- package/dist/api/auth/wallet/route.js +68 -0
- package/dist/api/auth/wallet.d.ts +16 -0
- package/dist/api/auth/wallet.d.ts.map +1 -0
- package/dist/api/auth/wallet.js +71 -0
- package/dist/api/public/gateway-models.d.ts +25 -0
- package/dist/api/public/gateway-models.d.ts.map +1 -0
- package/dist/api/public/gateway-models.js +49 -0
- package/dist/api/public/pricing-summary.d.ts +46 -0
- package/dist/api/public/pricing-summary.d.ts.map +1 -0
- package/dist/api/public/pricing-summary.js +70 -0
- package/dist/api/public/prompts/[id]/stats.d.ts +15 -0
- package/dist/api/public/prompts/[id]/stats.d.ts.map +1 -0
- package/dist/api/public/prompts/[id]/stats.js +37 -0
- package/dist/api/public/prompts/[id]/view.d.ts +15 -0
- package/dist/api/public/prompts/[id]/view.d.ts.map +1 -0
- package/dist/api/public/prompts/[id]/view.js +41 -0
- package/dist/api/public/prompts/slug/[slug].d.ts +15 -0
- package/dist/api/public/prompts/slug/[slug].d.ts.map +1 -0
- package/dist/api/public/prompts/slug/[slug].js +40 -0
- package/dist/api/public/prompts/user/[username].d.ts +17 -0
- package/dist/api/public/prompts/user/[username].d.ts.map +1 -0
- package/dist/api/public/prompts/user/[username].js +51 -0
- package/dist/api/public/prompts.d.ts +15 -0
- package/dist/api/public/prompts.d.ts.map +1 -0
- package/dist/api/public/prompts.js +45 -0
- package/dist/api/public/token-packs.d.ts +11 -0
- package/dist/api/public/token-packs.d.ts.map +1 -0
- package/dist/api/public/token-packs.js +25 -0
- package/dist/api/public/token-pricing.d.ts +44 -0
- package/dist/api/public/token-pricing.d.ts.map +1 -0
- package/dist/api/public/token-pricing.js +168 -0
- package/dist/api/public/v1/_lib/artifacts.d.ts +52 -0
- package/dist/api/public/v1/_lib/artifacts.d.ts.map +1 -0
- package/dist/api/public/v1/_lib/artifacts.js +217 -0
- package/dist/api/public/v1/_lib/auth.d.ts +43 -0
- package/dist/api/public/v1/_lib/auth.d.ts.map +1 -0
- package/dist/api/public/v1/_lib/auth.js +108 -0
- package/dist/api/public/v1/_lib/errors.d.ts +17 -0
- package/dist/api/public/v1/_lib/errors.d.ts.map +1 -0
- package/dist/api/public/v1/_lib/errors.js +16 -0
- package/dist/api/public/v1/_lib/log.d.ts +29 -0
- package/dist/api/public/v1/_lib/log.d.ts.map +1 -0
- package/dist/api/public/v1/_lib/log.js +68 -0
- package/dist/api/public/v1/_lib/quota.d.ts +24 -0
- package/dist/api/public/v1/_lib/quota.d.ts.map +1 -0
- package/dist/api/public/v1/_lib/quota.js +118 -0
- package/dist/api/public/v1/_lib/router.d.ts +54 -0
- package/dist/api/public/v1/_lib/router.d.ts.map +1 -0
- package/dist/api/public/v1/_lib/router.js +119 -0
- package/dist/api/public/v1/connect.d.ts +20 -0
- package/dist/api/public/v1/connect.d.ts.map +1 -0
- package/dist/api/public/v1/connect.js +119 -0
- package/dist/api/public/v1/doc.d.ts +239 -0
- package/dist/api/public/v1/doc.d.ts.map +1 -0
- package/dist/api/public/v1/doc.js +253 -0
- package/dist/api/public/v1/history/[id].d.ts +92 -0
- package/dist/api/public/v1/history/[id].d.ts.map +1 -0
- package/dist/api/public/v1/history/[id].js +176 -0
- package/dist/api/public/v1/history.d.ts +30 -0
- package/dist/api/public/v1/history.d.ts.map +1 -0
- package/dist/api/public/v1/history.js +142 -0
- package/dist/api/public/v1/image-ai.d.ts +24 -0
- package/dist/api/public/v1/image-ai.d.ts.map +1 -0
- package/dist/api/public/v1/image-ai.js +233 -0
- package/dist/api/public/v1/prompts.d.ts +19 -0
- package/dist/api/public/v1/prompts.d.ts.map +1 -0
- package/dist/api/public/v1/prompts.js +107 -0
- package/dist/api/public/v1/provider.d.ts +16 -0
- package/dist/api/public/v1/provider.d.ts.map +1 -0
- package/dist/api/public/v1/provider.js +130 -0
- package/dist/api/public/v1/purchase.d.ts +11 -0
- package/dist/api/public/v1/purchase.d.ts.map +1 -0
- package/dist/api/public/v1/purchase.js +18 -0
- package/dist/api/public/v1/status.d.ts +35 -0
- package/dist/api/public/v1/status.d.ts.map +1 -0
- package/dist/api/public/v1/status.js +163 -0
- package/dist/api/public/v1/text-ai.d.ts +26 -0
- package/dist/api/public/v1/text-ai.d.ts.map +1 -0
- package/dist/api/public/v1/text-ai.js +239 -0
- package/dist/api/public/webhook.d.ts.map +1 -1
- package/dist/api/public/webhook.js +50 -39
- package/dist/api/track-usage.d.ts +12 -0
- package/dist/api/track-usage.d.ts.map +1 -0
- package/dist/api/track-usage.js +37 -0
- package/dist/components/Doc.d.ts.map +1 -1
- package/dist/components/Doc.js +1 -1
- package/dist/components/DocUsageCustom.js +6 -6
- package/dist/components/admin/UserTokenTab.d.ts.map +1 -1
- package/dist/components/admin/UserTokenTab.js +170 -23
- package/dist/components/auth/AuthDashboardAi.d.ts +2 -0
- package/dist/components/auth/AuthDashboardAi.d.ts.map +1 -0
- package/dist/components/auth/AuthDashboardAi.js +53 -0
- package/dist/docs/REFACTORING_BILLING_GUIDE.d.ts +277 -0
- package/dist/docs/REFACTORING_BILLING_GUIDE.d.ts.map +1 -0
- package/dist/docs/REFACTORING_BILLING_GUIDE.js +276 -0
- package/dist/index.d.ts +15 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +18 -1
- package/dist/scripts/migrate-tokens-to-wallet.d.ts +13 -0
- package/dist/scripts/migrate-tokens-to-wallet.d.ts.map +1 -0
- package/dist/scripts/migrate-tokens-to-wallet.js +165 -0
- package/dist/server/__tests__/billing.test.d.ts +5 -0
- package/dist/server/__tests__/billing.test.d.ts.map +1 -0
- package/dist/server/__tests__/billing.test.js +223 -0
- package/dist/server/ai-client.d.ts +59 -0
- package/dist/server/ai-client.d.ts.map +1 -0
- package/dist/server/ai-client.js +111 -0
- package/dist/server/ai-generation-service.d.ts +66 -0
- package/dist/server/ai-generation-service.d.ts.map +1 -0
- package/dist/server/ai-generation-service.js +274 -0
- package/dist/server/billing.d.ts +200 -0
- package/dist/server/billing.d.ts.map +1 -0
- package/dist/server/billing.js +488 -0
- package/dist/server/gateway-service.d.ts +13 -0
- package/dist/server/gateway-service.d.ts.map +1 -0
- package/dist/server/gateway-service.js +161 -0
- package/dist/server/global-settings.d.ts +16 -0
- package/dist/server/global-settings.d.ts.map +1 -0
- package/dist/server/global-settings.js +42 -0
- package/dist/server/model-filter.d.ts +25 -0
- package/dist/server/model-filter.d.ts.map +1 -0
- package/dist/server/model-filter.js +240 -0
- package/dist/server/ocr.d.ts +39 -0
- package/dist/server/ocr.d.ts.map +1 -0
- package/dist/server/ocr.js +280 -0
- package/dist/server/openai-client.d.ts +19 -0
- package/dist/server/openai-client.d.ts.map +1 -0
- package/dist/server/openai-client.js +26 -0
- package/dist/server/pricing-config.d.ts +18 -0
- package/dist/server/pricing-config.d.ts.map +1 -0
- package/dist/server/pricing-config.js +94 -0
- package/dist/server/pricing-validator.d.ts +41 -0
- package/dist/server/pricing-validator.d.ts.map +1 -0
- package/dist/server/pricing-validator.js +113 -0
- package/dist/server/pricing.d.ts +121 -0
- package/dist/server/pricing.d.ts.map +1 -0
- package/dist/server/pricing.js +225 -0
- package/dist/server/quota.d.ts +66 -0
- package/dist/server/quota.d.ts.map +1 -0
- package/dist/server/quota.js +538 -0
- package/dist/server/wallet-repair.d.ts +32 -0
- package/dist/server/wallet-repair.d.ts.map +1 -0
- package/dist/server/wallet-repair.js +189 -0
- package/dist/server.d.ts +13 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +87 -16
- package/dist/sitemap/handlers/prompts.d.ts +6 -0
- package/dist/sitemap/handlers/prompts.d.ts.map +1 -0
- package/dist/sitemap/handlers/prompts.js +72 -0
- package/dist/sitemap/handlers/users.d.ts +6 -0
- package/dist/sitemap/handlers/users.d.ts.map +1 -0
- package/dist/sitemap/handlers/users.js +80 -0
- package/dist/sitemap/manifest.d.ts +8 -0
- package/dist/sitemap/manifest.d.ts.map +1 -0
- package/dist/sitemap/manifest.js +27 -0
- package/dist/types/gateway.d.ts +40 -0
- package/dist/types/gateway.d.ts.map +1 -0
- package/dist/types/gateway.js +4 -0
- package/dist/types/quota.d.ts +74 -0
- package/dist/types/quota.d.ts.map +1 -0
- package/dist/types/quota.js +11 -0
- package/dist/utils/date.d.ts +7 -0
- package/dist/utils/date.d.ts.map +1 -0
- package/dist/utils/date.js +17 -0
- package/dist/web/admin/AdminTokenPacksPage.js +1 -1
- package/dist/web/admin/BillingAnalyticsPage.d.ts +2 -0
- package/dist/web/admin/BillingAnalyticsPage.d.ts.map +1 -0
- package/dist/web/admin/BillingAnalyticsPage.js +141 -0
- package/dist/web/admin/GlobalAISettingsPage.d.ts +2 -0
- package/dist/web/admin/GlobalAISettingsPage.d.ts.map +1 -0
- package/dist/web/admin/GlobalAISettingsPage.js +93 -0
- package/dist/web/admin/UserTokenPage.d.ts.map +1 -1
- package/dist/web/admin/UserTokenPage.js +20 -7
- package/dist/web/auth/AISettingsPage.d.ts +2 -0
- package/dist/web/auth/AISettingsPage.d.ts.map +1 -0
- package/dist/web/auth/AISettingsPage.js +258 -0
- package/dist/web/auth/APIKeysPage.d.ts +2 -0
- package/dist/web/auth/APIKeysPage.d.ts.map +1 -0
- package/dist/web/auth/APIKeysPage.js +154 -0
- package/dist/web/auth/HistoryPage.d.ts +2 -0
- package/dist/web/auth/HistoryPage.d.ts.map +1 -0
- package/dist/web/auth/HistoryPage.js +279 -0
- package/dist/web/auth/PromptsPage.d.ts +5 -0
- package/dist/web/auth/PromptsPage.d.ts.map +1 -0
- package/dist/web/auth/PromptsPage.js +137 -0
- package/dist/web/auth/TokenPage.d.ts.map +1 -1
- package/dist/web/auth/TokenPage.js +88 -31
- package/dist/web/auth/UsageAndTokensPage.d.ts +2 -0
- package/dist/web/auth/UsageAndTokensPage.d.ts.map +1 -0
- package/dist/web/auth/UsageAndTokensPage.js +157 -0
- package/dist/web/auth/UsagePage.d.ts +2 -0
- package/dist/web/auth/UsagePage.d.ts.map +1 -0
- package/dist/web/auth/UsagePage.js +62 -0
- package/dist/web/auth/components/ApiKeyFilterSelect.d.ts +13 -0
- package/dist/web/auth/components/ApiKeyFilterSelect.d.ts.map +1 -0
- package/dist/web/auth/components/ApiKeyFilterSelect.js +16 -0
- package/dist/web/auth/components/ModelUsageTable.d.ts +19 -0
- package/dist/web/auth/components/ModelUsageTable.d.ts.map +1 -0
- package/dist/web/auth/components/ModelUsageTable.js +37 -0
- package/dist/web/auth/components/PurchaseButton.d.ts +7 -0
- package/dist/web/auth/components/PurchaseButton.d.ts.map +1 -0
- package/dist/web/auth/components/PurchaseButton.js +13 -0
- package/dist/web/auth/components/TokenHistoryCard.d.ts +20 -0
- package/dist/web/auth/components/TokenHistoryCard.d.ts.map +1 -0
- package/dist/web/auth/components/TokenHistoryCard.js +76 -0
- package/dist/web/auth/components/TokenKpiGrid.d.ts +24 -0
- package/dist/web/auth/components/TokenKpiGrid.d.ts.map +1 -0
- package/dist/web/auth/components/TokenKpiGrid.js +38 -0
- package/dist/web/auth/components/UsageByDayChart.d.ts +11 -0
- package/dist/web/auth/components/UsageByDayChart.d.ts.map +1 -0
- package/dist/web/auth/components/UsageByDayChart.js +32 -0
- package/dist/web/auth/components/UsageByModelBarChart.d.ts +12 -0
- package/dist/web/auth/components/UsageByModelBarChart.d.ts.map +1 -0
- package/dist/web/auth/components/UsageByModelBarChart.js +32 -0
- package/dist/web/auth/components/WalletStatusCard.d.ts +9 -0
- package/dist/web/auth/components/WalletStatusCard.d.ts.map +1 -0
- package/dist/web/auth/components/WalletStatusCard.js +50 -0
- package/dist/web/components/ImageGenerative.d.ts +3 -1
- package/dist/web/components/ImageGenerative.d.ts.map +1 -1
- package/dist/web/components/ImageGenerative.js +139 -52
- package/dist/web/components/TextareaGenerative.d.ts +3 -1
- package/dist/web/components/TextareaGenerative.d.ts.map +1 -1
- package/dist/web/components/TextareaGenerative.js +10 -5
- package/dist/web/public/PromptDetailPage.d.ts +25 -0
- package/dist/web/public/PromptDetailPage.d.ts.map +1 -0
- package/dist/web/public/PromptDetailPage.js +71 -0
- package/dist/web/public/PromptDetailPageServer.d.ts +15 -0
- package/dist/web/public/PromptDetailPageServer.d.ts.map +1 -0
- package/dist/web/public/PromptDetailPageServer.js +68 -0
- package/dist/web/public/PublicPromptsPage.d.ts +5 -0
- package/dist/web/public/PublicPromptsPage.d.ts.map +1 -0
- package/dist/web/public/PublicPromptsPage.js +110 -0
- package/dist/web/public/PurchaseTokensPage.d.ts +2 -0
- package/dist/web/public/PurchaseTokensPage.d.ts.map +1 -0
- package/dist/web/public/PurchaseTokensPage.js +98 -0
- package/dist/web/public/UserAvatar.d.ts +13 -0
- package/dist/web/public/UserAvatar.d.ts.map +1 -0
- package/dist/web/public/UserAvatar.js +13 -0
- package/dist/web/public/UserDetailPageServer.d.ts +15 -0
- package/dist/web/public/UserDetailPageServer.d.ts.map +1 -0
- package/dist/web/public/UserDetailPageServer.js +31 -0
- package/dist/web/public/UserPromptsPage.d.ts +9 -0
- package/dist/web/public/UserPromptsPage.d.ts.map +1 -0
- package/dist/web/public/UserPromptsPage.js +112 -0
- package/dist/web/public/UserPromptsPageServer.d.ts +15 -0
- package/dist/web/public/UserPromptsPageServer.d.ts.map +1 -0
- package/dist/web/public/UserPromptsPageServer.js +31 -0
- package/package.json +18 -9
- package/supabase/migrations/20251125000000_ai_tokens.sql +7 -0
- package/supabase/migrations/20260123100002_user_token_quota_monthly copy.sql +173 -0
- package/supabase/migrations/20260128100003_update_and_add_table.sql +368 -0
- package/supabase/migrations/20260128120000_seed_providers_models.sql +78 -0
- package/supabase/migrations/20260128131405_add_api_key_id_to_ledgers.sql +41 -0
- package/supabase/migrations/20260128140000_ai_artifacts_storage.sql +99 -0
- package/supabase/migrations/20260128140002_ai_user_settings.sql +57 -0
- package/supabase/migrations/20260128150000_drop_ai_user_settings.sql +21 -0
- package/supabase/migrations/20260128160000_wallet_billing_system.sql +192 -0
- package/supabase/migrations/20260128160001_wallet_rpc_functions.sql +165 -0
- package/supabase/migrations/20260128170000_add_pack_coef_to_token_packs.sql +30 -0
- package/supabase/migrations/20260129120000_wallet_view_rpc.sql +41 -0
- package/supabase/migrations/20260129220003_update_pack_margins.sql +31 -0
- package/supabase/migrations/20260129330004_ai_user_prompts.sql +151 -0
- package/supabase/migrations/20260129330005_ai_prompts_ip_tracking.sql +92 -0
- package/supabase/migrations/20260129330006_ai_prompts_slug.sql +64 -0
- package/supabase/migrations/20260129330007_ai_prompts_view_slug.sql +26 -0
- package/supabase/migrations/20260129440000_ai_prompts_view_username.sql +33 -0
- package/supabase/migrations/20260129450000_ai_prompts_add_lang.sql +40 -0
- package/supabase/migrations/20260131000000_extract_model_prompt_in_ledger.sql +92 -0
- package/supabase/migrations/20260131140000_fix_duplicate_purchases.sql +64 -0
- package/supabase/migrations/20260201120000_module-ai_default_models.sql +63 -0
- package/supabase/migrations/20260201130000_module-ai_remove_provider_tables.sql +17 -0
- package/supabase/migrations-down/20251217120000_user_token_quota_monthly.sql +34 -0
- package/supabase/migrations-down/20260128131405_add_api_key_id_to_ledgers.sql +25 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GET /api/ai/public/gateway-models
|
|
3
|
+
* Public route to list available AI models from Vercel AI Gateway
|
|
4
|
+
* No authentication required
|
|
5
|
+
*/
|
|
6
|
+
import { NextResponse } from "next/server";
|
|
7
|
+
import { logger } from "@lastbrain/core";
|
|
8
|
+
import { fetchGatewayModels } from "../../server/gateway-service";
|
|
9
|
+
export async function GET(request) {
|
|
10
|
+
try {
|
|
11
|
+
// Get query parameters
|
|
12
|
+
const searchParams = request.nextUrl.searchParams;
|
|
13
|
+
const kindFilter = searchParams.get("kind"); // "text" or "image"
|
|
14
|
+
// Fetch models from Vercel AI Gateway
|
|
15
|
+
const gatewayResponse = await fetchGatewayModels();
|
|
16
|
+
console.log("🚀 ~ GET ~ gatewayResponse:", gatewayResponse);
|
|
17
|
+
let filteredProviders = gatewayResponse.providers;
|
|
18
|
+
// Apply kind filter if specified
|
|
19
|
+
if (kindFilter) {
|
|
20
|
+
filteredProviders = filteredProviders
|
|
21
|
+
.map((provider) => ({
|
|
22
|
+
...provider,
|
|
23
|
+
models: provider.models.filter((m) => m.type === kindFilter),
|
|
24
|
+
}))
|
|
25
|
+
.filter((p) => p.models.length > 0);
|
|
26
|
+
}
|
|
27
|
+
// Remove pricing from public response (keep it internal only)
|
|
28
|
+
const providersWithoutPricing = filteredProviders.map((provider) => ({
|
|
29
|
+
...provider,
|
|
30
|
+
models: provider.models.map((model) => ({
|
|
31
|
+
id: model.id,
|
|
32
|
+
name: model.name,
|
|
33
|
+
type: model.type,
|
|
34
|
+
provider: model.provider,
|
|
35
|
+
max_tokens: model.max_tokens,
|
|
36
|
+
tags: model.tags,
|
|
37
|
+
})),
|
|
38
|
+
}));
|
|
39
|
+
return NextResponse.json({
|
|
40
|
+
providers: providersWithoutPricing,
|
|
41
|
+
stale: gatewayResponse.stale,
|
|
42
|
+
cached_at: gatewayResponse.cached_at,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
logger.error("[public/gateway-models] Error:", error);
|
|
47
|
+
return NextResponse.json({ error: error.message || "Internal server error" }, { status: 500 });
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GET /api/ai/public/pricing-summary
|
|
3
|
+
* Returns pricing estimates for common actions based on wallet billing rules
|
|
4
|
+
*/
|
|
5
|
+
import { NextResponse } from "next/server";
|
|
6
|
+
export declare function GET(request: Request): Promise<NextResponse<{
|
|
7
|
+
pack: {
|
|
8
|
+
name: string;
|
|
9
|
+
priceUsd: number;
|
|
10
|
+
tokens: number;
|
|
11
|
+
providerBudgetUsd: number;
|
|
12
|
+
sellValueUsd: number;
|
|
13
|
+
marginPercent: string;
|
|
14
|
+
};
|
|
15
|
+
estimates: {
|
|
16
|
+
"generate-recipe-text": {
|
|
17
|
+
label: string;
|
|
18
|
+
minCostUsd: number;
|
|
19
|
+
typicalCostUsd: number;
|
|
20
|
+
percentOfPack: number;
|
|
21
|
+
estimatedCount: number;
|
|
22
|
+
};
|
|
23
|
+
"generate-image": {
|
|
24
|
+
label: string;
|
|
25
|
+
minCostUsd: number;
|
|
26
|
+
typicalCostUsd: number;
|
|
27
|
+
percentOfPack: number;
|
|
28
|
+
estimatedCount: number;
|
|
29
|
+
};
|
|
30
|
+
"generate-text": {
|
|
31
|
+
label: string;
|
|
32
|
+
minCostUsd: number;
|
|
33
|
+
typicalCostUsd: number;
|
|
34
|
+
percentOfPack: number;
|
|
35
|
+
estimatedCount: number;
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
info: {
|
|
39
|
+
margin_model: string;
|
|
40
|
+
min_costs_enforced: boolean;
|
|
41
|
+
never_at_loss: boolean;
|
|
42
|
+
};
|
|
43
|
+
}> | NextResponse<{
|
|
44
|
+
error: any;
|
|
45
|
+
}>>;
|
|
46
|
+
//# sourceMappingURL=pricing-summary.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pricing-summary.d.ts","sourceRoot":"","sources":["../../../src/api/public/pricing-summary.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAG3C,wBAAsB,GAAG,CAAC,OAAO,EAAE,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAsEzC"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GET /api/ai/public/pricing-summary
|
|
3
|
+
* Returns pricing estimates for common actions based on wallet billing rules
|
|
4
|
+
*/
|
|
5
|
+
import { NextResponse } from "next/server";
|
|
6
|
+
import { logger } from "@lastbrain/core";
|
|
7
|
+
export async function GET(request) {
|
|
8
|
+
try {
|
|
9
|
+
const { searchParams } = new URL(request.url);
|
|
10
|
+
const packId = searchParams.get("packId");
|
|
11
|
+
// Default pack for estimation (can be overridden)
|
|
12
|
+
const DEFAULT_PACK = {
|
|
13
|
+
tokens: 100000,
|
|
14
|
+
price_usd: 5.0,
|
|
15
|
+
coef: 2.5, // 60% margin
|
|
16
|
+
};
|
|
17
|
+
// For now, use default pack (TODO: fetch from database if packId provided)
|
|
18
|
+
const pack = DEFAULT_PACK;
|
|
19
|
+
// Calculate wallet values for this pack
|
|
20
|
+
const providerBudgetUsd = pack.price_usd / pack.coef;
|
|
21
|
+
const sellValueUsd = pack.price_usd;
|
|
22
|
+
// Common action estimates
|
|
23
|
+
const estimates = {
|
|
24
|
+
// Generate recipe text (high value action)
|
|
25
|
+
"generate-recipe-text": {
|
|
26
|
+
label: "Génération de recette (texte complet)",
|
|
27
|
+
minCostUsd: 0.2,
|
|
28
|
+
typicalCostUsd: 0.25,
|
|
29
|
+
percentOfPack: (0.25 / sellValueUsd) * 100,
|
|
30
|
+
estimatedCount: Math.floor(sellValueUsd / 0.25),
|
|
31
|
+
},
|
|
32
|
+
// Generate image
|
|
33
|
+
"generate-image": {
|
|
34
|
+
label: "Génération d'image",
|
|
35
|
+
minCostUsd: 0.05,
|
|
36
|
+
typicalCostUsd: 0.08,
|
|
37
|
+
percentOfPack: (0.08 / sellValueUsd) * 100,
|
|
38
|
+
estimatedCount: Math.floor(sellValueUsd / 0.08),
|
|
39
|
+
},
|
|
40
|
+
// Generate text (generic)
|
|
41
|
+
"generate-text": {
|
|
42
|
+
label: "Génération de texte (court)",
|
|
43
|
+
minCostUsd: 0.0,
|
|
44
|
+
typicalCostUsd: 0.01,
|
|
45
|
+
percentOfPack: (0.01 / sellValueUsd) * 100,
|
|
46
|
+
estimatedCount: Math.floor(sellValueUsd / 0.01),
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
return NextResponse.json({
|
|
50
|
+
pack: {
|
|
51
|
+
name: "Starter Pack",
|
|
52
|
+
priceUsd: pack.price_usd,
|
|
53
|
+
tokens: pack.tokens,
|
|
54
|
+
providerBudgetUsd,
|
|
55
|
+
sellValueUsd,
|
|
56
|
+
marginPercent: ((1 - 1 / pack.coef) * 100).toFixed(1),
|
|
57
|
+
},
|
|
58
|
+
estimates,
|
|
59
|
+
info: {
|
|
60
|
+
margin_model: "60% margin on sell price",
|
|
61
|
+
min_costs_enforced: true,
|
|
62
|
+
never_at_loss: true,
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
logger.error("[Pricing Summary] Error:", error);
|
|
68
|
+
return NextResponse.json({ error: error.message || "Failed to compute pricing summary" }, { status: 500 });
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* POST /api/ai/public/prompts/:id/stats
|
|
3
|
+
* Increment prompt stats (picked, used) based on IP tracking
|
|
4
|
+
*/
|
|
5
|
+
import { NextRequest, NextResponse } from "next/server";
|
|
6
|
+
export declare function POST(request: NextRequest, { params }: {
|
|
7
|
+
params: Promise<{
|
|
8
|
+
id: string;
|
|
9
|
+
}>;
|
|
10
|
+
}): Promise<NextResponse<{
|
|
11
|
+
success: boolean;
|
|
12
|
+
}> | NextResponse<{
|
|
13
|
+
error: any;
|
|
14
|
+
}>>;
|
|
15
|
+
//# sourceMappingURL=stats.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stats.d.ts","sourceRoot":"","sources":["../../../../../src/api/public/prompts/[id]/stats.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAIxD,wBAAsB,IAAI,CACxB,OAAO,EAAE,WAAW,EACpB,EAAE,MAAM,EAAE,EAAE;IAAE,MAAM,EAAE,OAAO,CAAC;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;CAAE;;;;IAuChD"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* POST /api/ai/public/prompts/:id/stats
|
|
3
|
+
* Increment prompt stats (picked, used) based on IP tracking
|
|
4
|
+
*/
|
|
5
|
+
import { NextResponse } from "next/server";
|
|
6
|
+
import { getSupabaseServiceClient } from "@lastbrain/core/server";
|
|
7
|
+
import { logger } from "@lastbrain/core";
|
|
8
|
+
export async function POST(request, { params }) {
|
|
9
|
+
try {
|
|
10
|
+
const { id } = await params;
|
|
11
|
+
const body = await request.json();
|
|
12
|
+
const { stat_type } = body;
|
|
13
|
+
if (!["picked", "used"].includes(stat_type)) {
|
|
14
|
+
return NextResponse.json({ error: "Invalid stat_type. Must be 'picked' or 'used'" }, { status: 400 });
|
|
15
|
+
}
|
|
16
|
+
const supabase = getSupabaseServiceClient();
|
|
17
|
+
// Get IP address
|
|
18
|
+
const ip = request.headers.get("x-forwarded-for") ||
|
|
19
|
+
request.headers.get("x-real-ip") ||
|
|
20
|
+
"unknown";
|
|
21
|
+
// Increment stat with IP tracking
|
|
22
|
+
const { error } = await supabase.rpc("increment_prompt_stat_with_ip", {
|
|
23
|
+
p_prompt_id: id,
|
|
24
|
+
p_stat_type: stat_type,
|
|
25
|
+
p_ip_address: ip,
|
|
26
|
+
});
|
|
27
|
+
if (error) {
|
|
28
|
+
logger.error("[prompt-stats] Error incrementing stat:", error);
|
|
29
|
+
return NextResponse.json({ error: error.message }, { status: 500 });
|
|
30
|
+
}
|
|
31
|
+
return NextResponse.json({ success: true });
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
logger.error("[prompt-stats] POST unexpected error:", error);
|
|
35
|
+
return NextResponse.json({ error: error.message }, { status: 500 });
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GET /api/ai/public/prompts/:id/view
|
|
3
|
+
* View a single public prompt and increment view count (tracked by IP)
|
|
4
|
+
*/
|
|
5
|
+
import { NextRequest, NextResponse } from "next/server";
|
|
6
|
+
export declare function GET(request: NextRequest, { params }: {
|
|
7
|
+
params: Promise<{
|
|
8
|
+
id: string;
|
|
9
|
+
}>;
|
|
10
|
+
}): Promise<NextResponse<{
|
|
11
|
+
prompt: any;
|
|
12
|
+
}> | NextResponse<{
|
|
13
|
+
error: any;
|
|
14
|
+
}>>;
|
|
15
|
+
//# sourceMappingURL=view.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"view.d.ts","sourceRoot":"","sources":["../../../../../src/api/public/prompts/[id]/view.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAIxD,wBAAsB,GAAG,CACvB,OAAO,EAAE,WAAW,EACpB,EAAE,MAAM,EAAE,EAAE;IAAE,MAAM,EAAE,OAAO,CAAC;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;CAAE;;;;IA2ChD"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GET /api/ai/public/prompts/:id/view
|
|
3
|
+
* View a single public prompt and increment view count (tracked by IP)
|
|
4
|
+
*/
|
|
5
|
+
import { NextResponse } from "next/server";
|
|
6
|
+
import { getSupabaseServiceClient } from "@lastbrain/core/server";
|
|
7
|
+
import { logger } from "@lastbrain/core";
|
|
8
|
+
export async function GET(request, { params }) {
|
|
9
|
+
try {
|
|
10
|
+
const { id } = await params;
|
|
11
|
+
const supabase = getSupabaseServiceClient();
|
|
12
|
+
// Get prompt with stats
|
|
13
|
+
const { data: prompt, error } = await supabase
|
|
14
|
+
.from("public_prompts_with_stats")
|
|
15
|
+
.select("*")
|
|
16
|
+
.eq("id", id)
|
|
17
|
+
.eq("is_public", true)
|
|
18
|
+
.single();
|
|
19
|
+
if (error || !prompt) {
|
|
20
|
+
return NextResponse.json({ error: "Prompt not found" }, { status: 404 });
|
|
21
|
+
}
|
|
22
|
+
// Increment view count based on IP
|
|
23
|
+
const ip = request.headers.get("x-forwarded-for") ||
|
|
24
|
+
request.headers.get("x-real-ip") ||
|
|
25
|
+
"unknown";
|
|
26
|
+
// Call increment function with IP tracking
|
|
27
|
+
const { error: statError } = await supabase.rpc("increment_prompt_stat_with_ip", {
|
|
28
|
+
p_prompt_id: id,
|
|
29
|
+
p_stat_type: "views",
|
|
30
|
+
p_ip_address: ip,
|
|
31
|
+
});
|
|
32
|
+
if (statError) {
|
|
33
|
+
logger.error("[prompt-view] Error incrementing stat:", statError);
|
|
34
|
+
}
|
|
35
|
+
return NextResponse.json({ prompt });
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
logger.error("[prompt-view] GET unexpected error:", error);
|
|
39
|
+
return NextResponse.json({ error: error.message }, { status: 500 });
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GET /api/ai/public/prompts/slug/:slug
|
|
3
|
+
* View a single public prompt by slug and increment view count (tracked by IP)
|
|
4
|
+
*/
|
|
5
|
+
import { NextRequest, NextResponse } from "next/server";
|
|
6
|
+
export declare function GET(request: NextRequest, { params }: {
|
|
7
|
+
params: Promise<{
|
|
8
|
+
slug: string;
|
|
9
|
+
}>;
|
|
10
|
+
}): Promise<NextResponse<{
|
|
11
|
+
prompt: any;
|
|
12
|
+
}> | NextResponse<{
|
|
13
|
+
error: any;
|
|
14
|
+
}>>;
|
|
15
|
+
//# sourceMappingURL=%5Bslug%5D.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"[slug].d.ts","sourceRoot":"","sources":["../../../../../src/api/public/prompts/slug/[slug].ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAIxD,wBAAsB,GAAG,CACvB,OAAO,EAAE,WAAW,EACpB,EAAE,MAAM,EAAE,EAAE;IAAE,MAAM,EAAE,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;CAAE;;;;IA0ClD"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GET /api/ai/public/prompts/slug/:slug
|
|
3
|
+
* View a single public prompt by slug and increment view count (tracked by IP)
|
|
4
|
+
*/
|
|
5
|
+
import { NextResponse } from "next/server";
|
|
6
|
+
import { getSupabaseServiceClient } from "@lastbrain/core/server";
|
|
7
|
+
import { logger } from "@lastbrain/core";
|
|
8
|
+
export async function GET(request, { params }) {
|
|
9
|
+
try {
|
|
10
|
+
const { slug } = await params;
|
|
11
|
+
const supabase = getSupabaseServiceClient();
|
|
12
|
+
// Get prompt with stats by slug
|
|
13
|
+
const { data: prompt, error } = await supabase
|
|
14
|
+
.from("public_prompts_with_stats")
|
|
15
|
+
.select("*")
|
|
16
|
+
.eq("slug", slug)
|
|
17
|
+
.single();
|
|
18
|
+
if (error || !prompt) {
|
|
19
|
+
return NextResponse.json({ error: "Prompt not found" }, { status: 404 });
|
|
20
|
+
}
|
|
21
|
+
// Increment view count based on IP
|
|
22
|
+
const ip = request.headers.get("x-forwarded-for") ||
|
|
23
|
+
request.headers.get("x-real-ip") ||
|
|
24
|
+
"unknown";
|
|
25
|
+
// Call increment function with IP tracking
|
|
26
|
+
const { error: statError } = await supabase.rpc("increment_prompt_stat_with_ip", {
|
|
27
|
+
p_prompt_id: prompt.id,
|
|
28
|
+
p_stat_type: "views",
|
|
29
|
+
p_ip_address: ip,
|
|
30
|
+
});
|
|
31
|
+
if (statError) {
|
|
32
|
+
logger.error("[prompt-view-slug] Error incrementing stat:", statError);
|
|
33
|
+
}
|
|
34
|
+
return NextResponse.json({ prompt });
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
logger.error("[prompt-view-slug] GET unexpected error:", error);
|
|
38
|
+
return NextResponse.json({ error: error.message }, { status: 500 });
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GET /api/ai/public/prompts/user/:username
|
|
3
|
+
* Get public prompts by username
|
|
4
|
+
*/
|
|
5
|
+
import { NextRequest, NextResponse } from "next/server";
|
|
6
|
+
export declare function GET(req: NextRequest, { params }: {
|
|
7
|
+
params: Promise<{
|
|
8
|
+
username: string;
|
|
9
|
+
}>;
|
|
10
|
+
}): Promise<NextResponse<{
|
|
11
|
+
error: string;
|
|
12
|
+
}> | NextResponse<{
|
|
13
|
+
success: boolean;
|
|
14
|
+
prompts: any[];
|
|
15
|
+
username: string;
|
|
16
|
+
}>>;
|
|
17
|
+
//# sourceMappingURL=%5Busername%5D.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"[username].d.ts","sourceRoot":"","sources":["../../../../../src/api/public/prompts/user/[username].ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAIxD,wBAAsB,GAAG,CACvB,GAAG,EAAE,WAAW,EAChB,EAAE,MAAM,EAAE,EAAE;IAAE,MAAM,EAAE,OAAO,CAAC;QAAE,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;CAAE;;;;;;IAyDtD"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GET /api/ai/public/prompts/user/:username
|
|
3
|
+
* Get public prompts by username
|
|
4
|
+
*/
|
|
5
|
+
import { NextResponse } from "next/server";
|
|
6
|
+
import { getSupabaseServiceClient } from "@lastbrain/core/server";
|
|
7
|
+
import { logger } from "@lastbrain/core";
|
|
8
|
+
export async function GET(req, { params }) {
|
|
9
|
+
try {
|
|
10
|
+
const { username } = await params;
|
|
11
|
+
const { searchParams } = new URL(req.url);
|
|
12
|
+
const search = searchParams.get("search");
|
|
13
|
+
const limit = Math.min(parseInt(searchParams.get("limit") || "12"), 100);
|
|
14
|
+
const offset = parseInt(searchParams.get("offset") || "0");
|
|
15
|
+
const supabase = getSupabaseServiceClient();
|
|
16
|
+
// Get user_id from username
|
|
17
|
+
const { data: profileData, error: profileError } = await supabase
|
|
18
|
+
.from("user_profil")
|
|
19
|
+
.select("owner_id")
|
|
20
|
+
.ilike("username", username)
|
|
21
|
+
.single();
|
|
22
|
+
if (profileError || !profileData) {
|
|
23
|
+
return NextResponse.json({ error: "User not found" }, { status: 404 });
|
|
24
|
+
}
|
|
25
|
+
// Get prompts with stats and pagination
|
|
26
|
+
let query = supabase
|
|
27
|
+
.from("public_prompts_with_stats")
|
|
28
|
+
.select("*")
|
|
29
|
+
.eq("owner_id", profileData.owner_id)
|
|
30
|
+
.order("created_at", { ascending: false })
|
|
31
|
+
.range(offset, offset + limit - 1);
|
|
32
|
+
// Search in title or content if provided
|
|
33
|
+
if (search) {
|
|
34
|
+
query = query.or(`title.ilike.%${search}%,content.ilike.%${search}%`);
|
|
35
|
+
}
|
|
36
|
+
const { data: prompts, error } = await query;
|
|
37
|
+
if (error) {
|
|
38
|
+
logger.error("Failed to fetch user prompts:", error);
|
|
39
|
+
return NextResponse.json({ error: "Failed to fetch prompts" }, { status: 500 });
|
|
40
|
+
}
|
|
41
|
+
return NextResponse.json({
|
|
42
|
+
success: true,
|
|
43
|
+
prompts: prompts || [],
|
|
44
|
+
username,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
logger.error("User prompts error:", error);
|
|
49
|
+
return NextResponse.json({ error: "Internal server error" }, { status: 500 });
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public prompts route - No auth required
|
|
3
|
+
* GET /api/ai/public/prompts
|
|
4
|
+
*/
|
|
5
|
+
import type { NextRequest } from "next/server";
|
|
6
|
+
import { NextResponse } from "next/server";
|
|
7
|
+
export declare function GET(req: NextRequest): Promise<NextResponse<{
|
|
8
|
+
success: boolean;
|
|
9
|
+
error: string;
|
|
10
|
+
}> | NextResponse<{
|
|
11
|
+
success: boolean;
|
|
12
|
+
prompts: any[];
|
|
13
|
+
count: number;
|
|
14
|
+
}>>;
|
|
15
|
+
//# sourceMappingURL=prompts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompts.d.ts","sourceRoot":"","sources":["../../../src/api/public/prompts.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAI3C,wBAAsB,GAAG,CAAC,GAAG,EAAE,WAAW;;;;;;;IAiDzC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public prompts route - No auth required
|
|
3
|
+
* GET /api/ai/public/prompts
|
|
4
|
+
*/
|
|
5
|
+
import { NextResponse } from "next/server";
|
|
6
|
+
import { getSupabaseServiceClient } from "@lastbrain/core/server";
|
|
7
|
+
import { logger } from "@lastbrain/core";
|
|
8
|
+
export async function GET(req) {
|
|
9
|
+
try {
|
|
10
|
+
const supabase = getSupabaseServiceClient();
|
|
11
|
+
const { searchParams } = new URL(req.url);
|
|
12
|
+
const type = searchParams.get("type");
|
|
13
|
+
const search = searchParams.get("search");
|
|
14
|
+
const limit = Math.min(parseInt(searchParams.get("limit") || "12"), 100);
|
|
15
|
+
const offset = parseInt(searchParams.get("offset") || "0");
|
|
16
|
+
// Use the view that includes stats
|
|
17
|
+
let query = supabase
|
|
18
|
+
.from("public_prompts_with_stats")
|
|
19
|
+
.select("*")
|
|
20
|
+
.order("created_at", { ascending: false })
|
|
21
|
+
.range(offset, offset + limit - 1);
|
|
22
|
+
// Filter by type if provided
|
|
23
|
+
if (type && (type === "text" || type === "image")) {
|
|
24
|
+
query = query.eq("type", type);
|
|
25
|
+
}
|
|
26
|
+
// Search in title or content if provided
|
|
27
|
+
if (search) {
|
|
28
|
+
query = query.or(`title.ilike.%${search}%,content.ilike.%${search}%`);
|
|
29
|
+
}
|
|
30
|
+
const { data: prompts, error } = await query;
|
|
31
|
+
if (error) {
|
|
32
|
+
logger.error("Failed to fetch public prompts:", error);
|
|
33
|
+
return NextResponse.json({ success: false, error: "Failed to fetch prompts" }, { status: 500 });
|
|
34
|
+
}
|
|
35
|
+
return NextResponse.json({
|
|
36
|
+
success: true,
|
|
37
|
+
prompts: prompts || [],
|
|
38
|
+
count: prompts?.length || 0,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
logger.error("Public prompts error:", error);
|
|
43
|
+
return NextResponse.json({ success: false, error: "Internal server error" }, { status: 500 });
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { NextResponse } from "next/server";
|
|
2
|
+
/**
|
|
3
|
+
* GET /api/public/token-packs
|
|
4
|
+
* Get active token packs available for purchase (PUBLIC)
|
|
5
|
+
*/
|
|
6
|
+
export declare function GET(): Promise<NextResponse<{
|
|
7
|
+
data: any[];
|
|
8
|
+
}> | NextResponse<{
|
|
9
|
+
error: any;
|
|
10
|
+
}>>;
|
|
11
|
+
//# sourceMappingURL=token-packs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"token-packs.d.ts","sourceRoot":"","sources":["../../../src/api/public/token-packs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAI3C;;;GAGG;AACH,wBAAsB,GAAG;;;;IAqBxB"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { NextResponse } from "next/server";
|
|
2
|
+
import { getSupabaseServiceClient } from "@lastbrain/core/server";
|
|
3
|
+
import { logger } from "@lastbrain/core";
|
|
4
|
+
/**
|
|
5
|
+
* GET /api/public/token-packs
|
|
6
|
+
* Get active token packs available for purchase (PUBLIC)
|
|
7
|
+
*/
|
|
8
|
+
export async function GET() {
|
|
9
|
+
try {
|
|
10
|
+
const supabase = getSupabaseServiceClient();
|
|
11
|
+
// Get active packs (no authentication required)
|
|
12
|
+
const { data, error } = await supabase
|
|
13
|
+
.from("token_packs")
|
|
14
|
+
.select("*")
|
|
15
|
+
.eq("is_active", true)
|
|
16
|
+
.order("sort_order", { ascending: true });
|
|
17
|
+
if (error)
|
|
18
|
+
throw error;
|
|
19
|
+
return NextResponse.json({ data }, { status: 200 });
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
logger.error("[Public Token Packs] GET error:", error);
|
|
23
|
+
return NextResponse.json({ error: error.message || "Erreur lors de la récupération des packs" }, { status: 500 });
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GET /api/ai/public/token-pricing
|
|
3
|
+
* Returns token pricing information for all models
|
|
4
|
+
* Single source of truth for client-side pricing display
|
|
5
|
+
*/
|
|
6
|
+
import { NextRequest, NextResponse } from "next/server";
|
|
7
|
+
export declare function GET(request: NextRequest): Promise<NextResponse<{
|
|
8
|
+
config: {
|
|
9
|
+
packTokens: number;
|
|
10
|
+
packPriceUsd: number;
|
|
11
|
+
tokenPriceUsd: number;
|
|
12
|
+
markupCoef: number;
|
|
13
|
+
};
|
|
14
|
+
providers: {
|
|
15
|
+
name: string;
|
|
16
|
+
display_name: string;
|
|
17
|
+
models: ({
|
|
18
|
+
modelId: string;
|
|
19
|
+
modelName: string;
|
|
20
|
+
type: "audio" | "video" | "image" | "text" | "embedding" | "language";
|
|
21
|
+
provider: string;
|
|
22
|
+
estimatedTokens: null;
|
|
23
|
+
displayPrice: string;
|
|
24
|
+
available: boolean;
|
|
25
|
+
inputSellUsdPerMToken?: undefined;
|
|
26
|
+
outputSellUsdPerMToken?: undefined;
|
|
27
|
+
imageSellUsd?: undefined;
|
|
28
|
+
} | {
|
|
29
|
+
modelId: string;
|
|
30
|
+
modelName: string;
|
|
31
|
+
type: "audio" | "video" | "image" | "text" | "embedding" | "language";
|
|
32
|
+
provider: string;
|
|
33
|
+
estimatedTokens: number | null;
|
|
34
|
+
displayPrice: string;
|
|
35
|
+
available: boolean;
|
|
36
|
+
inputSellUsdPerMToken: number | undefined;
|
|
37
|
+
outputSellUsdPerMToken: number | undefined;
|
|
38
|
+
imageSellUsd: number | undefined;
|
|
39
|
+
})[];
|
|
40
|
+
}[];
|
|
41
|
+
}> | NextResponse<{
|
|
42
|
+
error: any;
|
|
43
|
+
}>>;
|
|
44
|
+
//# sourceMappingURL=token-pricing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"token-pricing.d.ts","sourceRoot":"","sources":["../../../src/api/public/token-pricing.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAWxD,wBAAsB,GAAG,CAAC,OAAO,EAAE,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IA6J7C"}
|