@goscribe/server 1.3.4 → 1.6.0
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/.env.example +12 -0
- package/.vscode/settings.json +3 -0
- package/REFACTOR_NOTES.md +60 -0
- package/TESTING_PROMPT.md +225 -0
- package/dist/context.d.ts +14 -1
- package/dist/context.js +23 -2
- package/dist/controllers/admin.controller.d.ts +715 -0
- package/dist/controllers/admin.controller.js +9 -0
- package/dist/controllers/annotations.controller.d.ts +439 -0
- package/dist/controllers/annotations.controller.js +9 -0
- package/dist/controllers/app-router.controller.d.ts +3011 -0
- package/dist/controllers/app-router.controller.js +38 -0
- package/dist/controllers/app-router.controller.test.d.ts +1 -0
- package/dist/controllers/app-router.controller.test.js +36 -0
- package/dist/controllers/auth.controller.d.ts +323 -0
- package/dist/controllers/auth.controller.js +9 -0
- package/dist/controllers/base.controller.d.ts +4 -0
- package/dist/controllers/base.controller.js +5 -0
- package/dist/controllers/chat.controller.d.ts +341 -0
- package/dist/controllers/chat.controller.js +9 -0
- package/dist/controllers/copilot.controller.d.ts +397 -0
- package/dist/controllers/copilot.controller.js +9 -0
- package/dist/controllers/flashcards.controller.d.ts +651 -0
- package/dist/controllers/flashcards.controller.js +9 -0
- package/dist/controllers/members.controller.d.ts +339 -0
- package/dist/controllers/members.controller.js +9 -0
- package/dist/controllers/notifications.controller.d.ts +199 -0
- package/dist/controllers/notifications.controller.js +9 -0
- package/dist/controllers/payment.controller.d.ts +181 -0
- package/dist/controllers/payment.controller.js +9 -0
- package/dist/controllers/podcast.controller.d.ts +575 -0
- package/dist/controllers/podcast.controller.js +9 -0
- package/dist/controllers/router-module.controller.d.ts +5 -0
- package/dist/controllers/router-module.controller.js +6 -0
- package/dist/controllers/studyguide.controller.d.ts +73 -0
- package/dist/controllers/studyguide.controller.js +9 -0
- package/dist/controllers/worksheets.controller.d.ts +829 -0
- package/dist/controllers/worksheets.controller.js +9 -0
- package/dist/controllers/workspace.controller.d.ts +1207 -0
- package/dist/controllers/workspace.controller.js +9 -0
- package/dist/lib/activity_human_description.test.js +16 -15
- package/dist/lib/activity_log_service.test.js +28 -23
- package/dist/lib/ai/config.d.ts +20 -0
- package/dist/lib/ai/config.js +31 -0
- package/dist/lib/ai/embedding-client.d.ts +8 -0
- package/dist/lib/ai/embedding-client.js +30 -0
- package/dist/lib/ai/index.d.ts +48 -0
- package/dist/lib/ai/index.js +29 -0
- package/dist/lib/ai/inference-backend/client.d.ts +28 -0
- package/dist/lib/ai/inference-backend/client.js +301 -0
- package/dist/lib/ai/inference-backend/mocks.d.ts +12 -0
- package/dist/lib/ai/inference-backend/mocks.js +133 -0
- package/dist/lib/ai/inference-backend/types.d.ts +44 -0
- package/dist/lib/ai/inference-backend/types.js +1 -0
- package/dist/lib/ai/json-parse.d.ts +2 -0
- package/dist/lib/ai/json-parse.js +34 -0
- package/dist/lib/ai/llm-client.d.ts +7 -0
- package/dist/lib/ai/llm-client.js +36 -0
- package/dist/lib/ai/mock.d.ts +2 -0
- package/dist/lib/ai/mock.js +10 -0
- package/dist/lib/ai/types.d.ts +9 -0
- package/dist/lib/ai/types.js +1 -0
- package/dist/lib/chunking.d.ts +19 -0
- package/dist/lib/chunking.js +47 -0
- package/dist/lib/curated-kb-seed.d.ts +12 -0
- package/dist/lib/curated-kb-seed.js +155 -0
- package/dist/lib/email.js +67 -108
- package/dist/lib/embeddings.d.ts +2 -0
- package/dist/lib/embeddings.js +1 -0
- package/dist/lib/ensure-curated-kb-catalog.d.ts +6 -0
- package/dist/lib/ensure-curated-kb-catalog.js +53 -0
- package/dist/lib/env.d.ts +1 -5
- package/dist/lib/env.js +2 -7
- package/dist/lib/inference.d.ts +1 -8
- package/dist/lib/inference.js +1 -19
- package/dist/lib/kb-meta.d.ts +8 -0
- package/dist/lib/kb-meta.js +77 -0
- package/dist/lib/note-text.d.ts +1 -0
- package/dist/lib/note-text.js +47 -0
- package/dist/lib/notification-service.test.js +37 -36
- package/dist/lib/pdf.d.ts +11 -0
- package/dist/lib/pdf.js +11 -0
- package/dist/lib/usage_service.d.ts +2 -1
- package/dist/lib/usage_service.js +30 -12
- package/dist/lib/worksheet-generation.js +4 -4
- package/dist/lib/worksheet-generation.test.js +32 -17
- package/dist/lib/workspace-kb.d.ts +5 -0
- package/dist/lib/workspace-kb.js +7 -0
- package/dist/models/controller-context.model.d.ts +8 -0
- package/dist/models/controller-context.model.js +1 -0
- package/dist/repositories/artifact.repository.d.ts +60 -0
- package/dist/repositories/artifact.repository.js +40 -0
- package/dist/repositories/base.repository.d.ts +14 -0
- package/dist/repositories/base.repository.js +14 -0
- package/dist/repositories/invitation.repository.d.ts +94 -0
- package/dist/repositories/invitation.repository.js +44 -0
- package/dist/repositories/notification.repository.d.ts +72 -0
- package/dist/repositories/notification.repository.js +44 -0
- package/dist/repositories/router-module.repository.d.ts +10 -0
- package/dist/repositories/router-module.repository.js +14 -0
- package/dist/repositories/user.repository.d.ts +74 -0
- package/dist/repositories/user.repository.js +37 -0
- package/dist/repositories/workspace-member.repository.d.ts +31 -0
- package/dist/repositories/workspace-member.repository.js +31 -0
- package/dist/repositories/workspace.repository.d.ts +97 -0
- package/dist/repositories/workspace.repository.js +79 -0
- package/dist/routers/_app.d.ts +566 -111
- package/dist/routers/_app.js +4 -0
- package/dist/routers/admin.d.ts +0 -4
- package/dist/routers/admin.js +21 -549
- package/dist/routers/annotations.js +12 -170
- package/dist/routers/artifactVersions.d.ts +65 -0
- package/dist/routers/artifactVersions.js +14 -0
- package/dist/routers/auth.d.ts +0 -6
- package/dist/routers/auth.js +37 -422
- package/dist/routers/chat.js +15 -229
- package/dist/routers/copilot.d.ts +14 -13
- package/dist/routers/copilot.js +13 -532
- package/dist/routers/flashcards.d.ts +17 -6
- package/dist/routers/flashcards.js +23 -349
- package/dist/routers/knowledgeBase.d.ts +421 -0
- package/dist/routers/knowledgeBase.js +118 -0
- package/dist/routers/members.d.ts +0 -41
- package/dist/routers/members.js +22 -710
- package/dist/routers/notes.d.ts +94 -0
- package/dist/routers/notes.js +37 -0
- package/dist/routers/notifications.js +7 -109
- package/dist/routers/payment.d.ts +2 -12
- package/dist/routers/payment.js +11 -393
- package/dist/routers/podcast.d.ts +1 -1
- package/dist/routers/podcast.js +11 -784
- package/dist/routers/studyguide.js +3 -129
- package/dist/routers/worksheets.d.ts +29 -14
- package/dist/routers/worksheets.js +49 -628
- package/dist/routers/workspace.d.ts +27 -71
- package/dist/routers/workspace.js +29 -922
- package/dist/scripts/purge-deleted-users.js +2 -2
- package/dist/server.js +10 -3
- package/dist/services/activity/activity-human-description.service.d.ts +13 -0
- package/dist/services/activity/activity-human-description.service.js +221 -0
- package/dist/services/activity/activity-human-description.service.test.d.ts +1 -0
- package/dist/services/activity/activity-human-description.service.test.js +16 -0
- package/dist/services/activity/activity-log.service.d.ts +87 -0
- package/dist/services/activity/activity-log.service.js +276 -0
- package/dist/services/activity/activity-log.service.test.d.ts +1 -0
- package/dist/services/activity/activity-log.service.test.js +27 -0
- package/dist/services/activity-human-description.service.d.ts +13 -0
- package/dist/services/activity-human-description.service.js +221 -0
- package/dist/services/activity-human-description.service.test.d.ts +1 -0
- package/dist/services/activity-human-description.service.test.js +16 -0
- package/dist/services/activity-log.service.d.ts +87 -0
- package/dist/services/activity-log.service.js +276 -0
- package/dist/services/activity-log.service.test.d.ts +1 -0
- package/dist/services/activity-log.service.test.js +27 -0
- package/dist/services/admin/admin.service.d.ts +270 -0
- package/dist/services/admin/admin.service.js +476 -0
- package/dist/services/admin.service.d.ts +270 -0
- package/dist/services/admin.service.js +476 -0
- package/dist/services/ai/ai-session.service.d.ts +5 -0
- package/dist/services/ai/ai-session.service.js +4 -0
- package/dist/services/ai-session.service.d.ts +60 -0
- package/dist/services/ai-session.service.js +561 -0
- package/dist/services/annotation.service.d.ts +177 -0
- package/dist/services/annotation.service.js +154 -0
- package/dist/services/artifact-notification.service.d.ts +14 -0
- package/dist/services/artifact-notification.service.js +20 -0
- package/dist/services/artifact-version.service.d.ts +38 -0
- package/dist/services/artifact-version.service.js +129 -0
- package/dist/services/artifacts/annotation.service.d.ts +177 -0
- package/dist/services/artifacts/annotation.service.js +154 -0
- package/dist/services/artifacts/artifact-version.service.d.ts +38 -0
- package/dist/services/artifacts/artifact-version.service.js +129 -0
- package/dist/services/artifacts/chat.service.d.ts +127 -0
- package/dist/services/artifacts/chat.service.js +182 -0
- package/dist/services/artifacts/study-guide.service.d.ts +18 -0
- package/dist/services/artifacts/study-guide.service.js +65 -0
- package/dist/services/auth/auth.service.d.ts +94 -0
- package/dist/services/auth/auth.service.js +368 -0
- package/dist/services/auth.service.d.ts +94 -0
- package/dist/services/auth.service.js +368 -0
- package/dist/services/base.service.d.ts +14 -0
- package/dist/services/base.service.js +14 -0
- package/dist/services/billing/payment.service.d.ts +44 -0
- package/dist/services/billing/payment.service.js +365 -0
- package/dist/services/billing/subscription.service.d.ts +37 -0
- package/dist/services/billing/subscription.service.js +654 -0
- package/dist/services/billing/usage.service.d.ts +47 -0
- package/dist/services/billing/usage.service.js +149 -0
- package/dist/services/chat.service.d.ts +127 -0
- package/dist/services/chat.service.js +182 -0
- package/dist/services/content/copilot.service.d.ts +113 -0
- package/dist/services/content/copilot.service.js +439 -0
- package/dist/services/content/flashcard-progress.service.d.ts +159 -0
- package/dist/services/content/flashcard-progress.service.js +432 -0
- package/dist/services/content/flashcard.service.d.ts +184 -0
- package/dist/services/content/flashcard.service.js +339 -0
- package/dist/services/content/media-analysis.service.d.ts +23 -0
- package/dist/services/content/media-analysis.service.js +404 -0
- package/dist/services/content/podcast.service.d.ts +267 -0
- package/dist/services/content/podcast.service.js +653 -0
- package/dist/services/content/worksheet-content.service.d.ts +37 -0
- package/dist/services/content/worksheet-content.service.js +84 -0
- package/dist/services/content/worksheet-content.service.test.d.ts +1 -0
- package/dist/services/content/worksheet-content.service.test.js +69 -0
- package/dist/services/content/worksheet-generation.service.d.ts +91 -0
- package/dist/services/content/worksheet-generation.service.js +95 -0
- package/dist/services/content/worksheet-generation.service.test.d.ts +1 -0
- package/dist/services/content/worksheet-generation.service.test.js +20 -0
- package/dist/services/content/worksheet.service.d.ts +347 -0
- package/dist/services/content/worksheet.service.js +599 -0
- package/dist/services/copilot.service.d.ts +116 -0
- package/dist/services/copilot.service.js +447 -0
- package/dist/services/flashcard-progress.service.d.ts +2 -2
- package/dist/services/flashcard-progress.service.js +3 -2
- package/dist/services/flashcard.service.d.ts +140 -0
- package/dist/services/flashcard.service.js +325 -0
- package/dist/services/invitation.service.d.ts +66 -0
- package/dist/services/invitation.service.js +348 -0
- package/dist/services/knowledge/knowledge-base.service.d.ts +316 -0
- package/dist/services/knowledge/knowledge-base.service.js +544 -0
- package/dist/services/knowledge-base.service.d.ts +316 -0
- package/dist/services/knowledge-base.service.js +536 -0
- package/dist/services/media-analysis.service.d.ts +23 -0
- package/dist/services/media-analysis.service.js +384 -0
- package/dist/services/member.service.d.ts +36 -0
- package/dist/services/member.service.js +193 -0
- package/dist/services/members/invitation.service.d.ts +66 -0
- package/dist/services/members/invitation.service.js +348 -0
- package/dist/services/members/member.service.d.ts +36 -0
- package/dist/services/members/member.service.js +193 -0
- package/dist/services/note.service.d.ts +55 -0
- package/dist/services/note.service.js +111 -0
- package/dist/services/notification.service.d.ts +214 -0
- package/dist/services/notification.service.js +550 -0
- package/dist/services/notification.service.test.d.ts +1 -0
- package/dist/services/notification.service.test.js +87 -0
- package/dist/services/notifications/notification.service.d.ts +214 -0
- package/dist/services/notifications/notification.service.js +550 -0
- package/dist/services/notifications/notification.service.test.d.ts +1 -0
- package/dist/services/notifications/notification.service.test.js +87 -0
- package/dist/services/payment.service.d.ts +55 -0
- package/dist/services/payment.service.js +368 -0
- package/dist/services/podcast.service.d.ts +267 -0
- package/dist/services/podcast.service.js +654 -0
- package/dist/services/router-module.service.d.ts +7 -0
- package/dist/services/router-module.service.js +10 -0
- package/dist/services/study-guide.service.d.ts +18 -0
- package/dist/services/study-guide.service.js +65 -0
- package/dist/services/subscription.service.d.ts +37 -0
- package/dist/services/subscription.service.js +654 -0
- package/dist/services/usage-limit-policy.service.d.ts +12 -0
- package/dist/services/usage-limit-policy.service.js +22 -0
- package/dist/services/usage-limit-policy.service.test.d.ts +1 -0
- package/dist/services/usage-limit-policy.service.test.js +46 -0
- package/dist/services/usage.service.d.ts +27 -0
- package/dist/services/usage.service.js +77 -0
- package/dist/services/worksheet-content.service.d.ts +42 -0
- package/dist/services/worksheet-content.service.js +84 -0
- package/dist/services/worksheet-content.service.test.d.ts +1 -0
- package/dist/services/worksheet-content.service.test.js +69 -0
- package/dist/services/worksheet-generation.service.d.ts +91 -0
- package/dist/services/worksheet-generation.service.js +95 -0
- package/dist/services/worksheet-generation.service.test.d.ts +1 -0
- package/dist/services/worksheet-generation.service.test.js +20 -0
- package/dist/services/worksheet.service.d.ts +385 -0
- package/dist/services/worksheet.service.js +596 -0
- package/dist/services/workspace/workspace-analytics.service.d.ts +24 -0
- package/dist/services/workspace/workspace-analytics.service.js +95 -0
- package/dist/services/workspace/workspace-kb.service.d.ts +40 -0
- package/dist/services/workspace/workspace-kb.service.js +184 -0
- package/dist/services/workspace/workspace.service.d.ts +263 -0
- package/dist/services/workspace/workspace.service.js +401 -0
- package/dist/services/workspace-analytics.service.d.ts +24 -0
- package/dist/services/workspace-analytics.service.js +95 -0
- package/dist/services/workspace-kb.service.d.ts +40 -0
- package/dist/services/workspace-kb.service.js +184 -0
- package/dist/services/workspace-progress.service.d.ts +27 -0
- package/dist/services/workspace-progress.service.js +56 -0
- package/dist/services/workspace-progress.service.test.d.ts +1 -0
- package/dist/services/workspace-progress.service.test.js +49 -0
- package/dist/services/workspace.service.d.ts +307 -0
- package/dist/services/workspace.service.js +390 -0
- package/dist/trpc.d.ts +12 -4
- package/dist/trpc.js +7 -13
- package/package.json +5 -6
- package/prisma/migrations/20260509000001_add_knowledge_base/migration.sql +99 -0
- package/prisma/migrations/20260509000002_curate_knowledge_base/migration.sql +52 -0
- package/prisma/migrations/20260522000000_add_notes/migration.sql +27 -0
- package/prisma/migrations/20260524000000_remove_notes/migration.sql +3 -0
- package/prisma/schema.prisma +150 -48
- package/prisma/seed.mjs +67 -0
- package/scripts/debug/README.md +4 -0
- package/src/README.md +63 -0
- package/src/context.ts +33 -3
- package/src/lib/ai/config.ts +34 -0
- package/src/lib/ai/embedding-client.ts +47 -0
- package/src/lib/ai/index.ts +65 -0
- package/src/lib/ai/inference-backend/client.ts +479 -0
- package/src/lib/ai/inference-backend/mocks.ts +171 -0
- package/src/lib/ai/inference-backend/types.ts +50 -0
- package/src/lib/ai/json-parse.ts +35 -0
- package/src/lib/ai/llm-client.ts +54 -0
- package/src/lib/ai/mock.ts +12 -0
- package/src/lib/ai/types.ts +11 -0
- package/src/lib/chunking.ts +81 -0
- package/src/lib/curated-kb-seed.ts +164 -0
- package/src/lib/email.ts +77 -115
- package/src/lib/embeddings.ts +9 -0
- package/src/lib/ensure-curated-kb-catalog.ts +60 -0
- package/src/lib/env.ts +2 -7
- package/src/lib/inference.ts +1 -21
- package/src/lib/kb-meta.ts +81 -0
- package/src/lib/pdf.ts +23 -0
- package/src/lib/workspace-kb.ts +7 -0
- package/src/repositories/artifact.repository.ts +55 -0
- package/src/repositories/base.repository.ts +19 -0
- package/src/repositories/invitation.repository.ts +53 -0
- package/src/repositories/notification.repository.ts +53 -0
- package/src/repositories/user.repository.ts +44 -0
- package/src/repositories/workspace-member.repository.ts +38 -0
- package/src/repositories/workspace.repository.ts +89 -0
- package/src/routers/_app.ts +4 -0
- package/src/routers/admin.ts +124 -692
- package/src/routers/annotations.ts +25 -203
- package/src/routers/artifactVersions.ts +32 -0
- package/src/routers/auth.ts +82 -520
- package/src/routers/chat.ts +42 -245
- package/src/routers/copilot.ts +41 -666
- package/src/routers/flashcards.ts +108 -404
- package/src/routers/knowledgeBase.ts +216 -0
- package/src/routers/members.ts +60 -782
- package/src/routers/notifications.ts +15 -117
- package/src/routers/payment.ts +37 -446
- package/src/routers/podcast.ts +36 -898
- package/src/routers/studyguide.ts +5 -144
- package/src/routers/worksheets.ts +171 -735
- package/src/routers/workspace.ts +141 -1108
- package/src/scripts/purge-deleted-users.ts +2 -2
- package/src/server.ts +10 -3
- package/src/{lib/activity_human_description.test.ts → services/activity/activity-human-description.service.test.ts} +1 -1
- package/src/{lib/activity_log_service.test.ts → services/activity/activity-log.service.test.ts} +1 -1
- package/src/{lib/activity_log_service.ts → services/activity/activity-log.service.ts} +2 -2
- package/src/services/admin/admin.service.ts +612 -0
- package/src/services/ai/ai-session.service.ts +5 -0
- package/src/services/artifacts/annotation.service.ts +189 -0
- package/src/services/artifacts/artifact-version.service.ts +151 -0
- package/src/services/artifacts/chat.service.ts +197 -0
- package/src/services/artifacts/study-guide.service.ts +72 -0
- package/src/services/auth/auth.service.ts +473 -0
- package/src/services/base.service.ts +19 -0
- package/src/services/billing/payment.service.ts +433 -0
- package/src/{lib/subscription_service.ts → services/billing/subscription.service.ts} +5 -5
- package/src/services/billing/usage.service.ts +207 -0
- package/src/services/content/copilot.service.ts +587 -0
- package/src/services/{flashcard-progress.service.ts → content/flashcard-progress.service.ts} +18 -12
- package/src/services/content/flashcard.service.ts +417 -0
- package/src/services/content/media-analysis.service.ts +561 -0
- package/src/services/content/podcast.service.ts +777 -0
- package/src/services/content/worksheet-content.service.test.ts +83 -0
- package/src/services/content/worksheet-content.service.ts +117 -0
- package/src/{lib/worksheet-generation.test.ts → services/content/worksheet-generation.service.test.ts} +3 -3
- package/src/services/content/worksheet.service.ts +751 -0
- package/src/services/knowledge/knowledge-base.service.ts +705 -0
- package/src/services/members/invitation.service.ts +427 -0
- package/src/services/members/member.service.ts +241 -0
- package/src/{lib/notification-service.test.ts → services/notifications/notification.service.test.ts} +2 -2
- package/src/{lib/notification-service.ts → services/notifications/notification.service.ts} +102 -1
- package/src/services/workspace/workspace-analytics.service.ts +107 -0
- package/src/services/workspace/workspace-kb.service.ts +273 -0
- package/src/services/workspace/workspace.service.ts +488 -0
- package/src/trpc.ts +7 -15
- package/src/lib/ai-session.ts +0 -704
- package/src/lib/usage_service.ts +0 -74
- package/src/lib/workspace-access.ts +0 -13
- /package/{check-difficulty.cjs → scripts/debug/check-difficulty.cjs} +0 -0
- /package/{check-questions.cjs → scripts/debug/check-questions.cjs} +0 -0
- /package/{db-summary.cjs → scripts/debug/db-summary.cjs} +0 -0
- /package/{mcq-test.cjs → scripts/debug/mcq-test.cjs} +0 -0
- /package/{test-generate.js → scripts/debug/test-generate.js} +0 -0
- /package/{test-ratio.cjs → scripts/debug/test-ratio.cjs} +0 -0
- /package/{zod-test.cjs → scripts/debug/zod-test.cjs} +0 -0
- /package/src/{lib/activity_human_description.ts → services/activity/activity-human-description.service.ts} +0 -0
- /package/src/{lib/worksheet-generation.ts → services/content/worksheet-generation.service.ts} +0 -0
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { prisma } from '../../lib/prisma.js';
|
|
2
|
+
import { workspaceAccessWhere } from '../../repositories/workspace.repository.js';
|
|
3
|
+
const FALLBACK_PLAN_LIMITS = {
|
|
4
|
+
id: 'fallback-free',
|
|
5
|
+
planId: 'fallback-free',
|
|
6
|
+
maxStorageBytes: BigInt(1024 * 1024 * 1024), // 1GB
|
|
7
|
+
maxWorksheets: 3,
|
|
8
|
+
maxFlashcards: 20,
|
|
9
|
+
maxPodcasts: 0,
|
|
10
|
+
maxStudyGuides: 1,
|
|
11
|
+
};
|
|
12
|
+
const CACHE_TTL_MS = 30000;
|
|
13
|
+
const usageCache = new Map();
|
|
14
|
+
const limitsCache = new Map();
|
|
15
|
+
const accountSummaryCache = new Map();
|
|
16
|
+
function readCache(map, userId) {
|
|
17
|
+
const entry = map.get(userId);
|
|
18
|
+
if (!entry || entry.expiresAt <= Date.now()) {
|
|
19
|
+
map.delete(userId);
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
return entry.value;
|
|
23
|
+
}
|
|
24
|
+
function writeCache(map, userId, value) {
|
|
25
|
+
map.set(userId, { value, expiresAt: Date.now() + CACHE_TTL_MS });
|
|
26
|
+
}
|
|
27
|
+
/** Bust cached usage/limit reads after creates, deletes, or billing changes. */
|
|
28
|
+
export function invalidateUserBillingCache(userId) {
|
|
29
|
+
usageCache.delete(userId);
|
|
30
|
+
limitsCache.delete(userId);
|
|
31
|
+
accountSummaryCache.delete(userId);
|
|
32
|
+
}
|
|
33
|
+
function workspaceAccessFilter(userId) {
|
|
34
|
+
return workspaceAccessWhere(userId);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Counts all resources consumed by a user across the platform.
|
|
38
|
+
*/
|
|
39
|
+
export async function getUserUsage(userId) {
|
|
40
|
+
const cached = readCache(usageCache, userId);
|
|
41
|
+
if (cached)
|
|
42
|
+
return cached;
|
|
43
|
+
const [flashcards, worksheets, studyGuides, podcasts, storageResult] = await Promise.all([
|
|
44
|
+
prisma.artifact.count({ where: { createdById: userId, type: 'FLASHCARD_SET' } }),
|
|
45
|
+
prisma.artifact.count({ where: { createdById: userId, type: 'WORKSHEET' } }),
|
|
46
|
+
prisma.artifact.count({ where: { createdById: userId, type: 'STUDY_GUIDE' } }),
|
|
47
|
+
prisma.artifact.count({ where: { createdById: userId, type: 'PODCAST_EPISODE' } }),
|
|
48
|
+
prisma.fileAsset.aggregate({
|
|
49
|
+
_sum: { size: true },
|
|
50
|
+
where: { userId },
|
|
51
|
+
}),
|
|
52
|
+
]);
|
|
53
|
+
const usage = {
|
|
54
|
+
flashcards,
|
|
55
|
+
worksheets,
|
|
56
|
+
studyGuides,
|
|
57
|
+
podcasts,
|
|
58
|
+
storageBytes: Number(storageResult._sum.size || 0),
|
|
59
|
+
};
|
|
60
|
+
writeCache(usageCache, userId, usage);
|
|
61
|
+
return usage;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Retrieves the specific plan limits for a user based on their active subscription
|
|
65
|
+
* PLUS any extra credits purchased.
|
|
66
|
+
*/
|
|
67
|
+
export async function getUserPlanLimits(userId) {
|
|
68
|
+
const cached = readCache(limitsCache, userId);
|
|
69
|
+
if (cached)
|
|
70
|
+
return cached;
|
|
71
|
+
const [activeSub, freePlan, userCredits] = await Promise.all([
|
|
72
|
+
prisma.subscription.findFirst({
|
|
73
|
+
where: { userId, status: 'active' },
|
|
74
|
+
include: { plan: { include: { limit: true } } },
|
|
75
|
+
orderBy: { createdAt: 'desc' },
|
|
76
|
+
}),
|
|
77
|
+
prisma.plan.findFirst({
|
|
78
|
+
where: {
|
|
79
|
+
active: true,
|
|
80
|
+
price: 0,
|
|
81
|
+
limit: { isNot: null },
|
|
82
|
+
},
|
|
83
|
+
include: { limit: true },
|
|
84
|
+
orderBy: { createdAt: 'asc' },
|
|
85
|
+
}),
|
|
86
|
+
prisma.userCredit.groupBy({
|
|
87
|
+
by: ['resourceType'],
|
|
88
|
+
where: { userId },
|
|
89
|
+
_sum: { amount: true },
|
|
90
|
+
}),
|
|
91
|
+
]);
|
|
92
|
+
const baseLimit = activeSub?.plan?.limit ?? freePlan?.limit;
|
|
93
|
+
const base = baseLimit ?? FALLBACK_PLAN_LIMITS;
|
|
94
|
+
const getCreditSum = (type) => userCredits.find((c) => c.resourceType === type)?._sum.amount || 0;
|
|
95
|
+
const limits = {
|
|
96
|
+
id: base.id,
|
|
97
|
+
planId: base.planId,
|
|
98
|
+
maxStorageBytes: BigInt(Number(base.maxStorageBytes) + getCreditSum('STORAGE') * 1024 * 1024),
|
|
99
|
+
maxWorksheets: base.maxWorksheets + getCreditSum('WORKSHEET'),
|
|
100
|
+
maxFlashcards: base.maxFlashcards + getCreditSum('FLASHCARD_SET'),
|
|
101
|
+
maxPodcasts: base.maxPodcasts + getCreditSum('PODCAST_EPISODE'),
|
|
102
|
+
maxStudyGuides: base.maxStudyGuides + getCreditSum('STUDY_GUIDE'),
|
|
103
|
+
createdAt: baseLimit?.createdAt || new Date(),
|
|
104
|
+
updatedAt: baseLimit?.updatedAt || new Date(),
|
|
105
|
+
isFallbackPlan: !baseLimit,
|
|
106
|
+
};
|
|
107
|
+
writeCache(limitsCache, userId, limits);
|
|
108
|
+
return limits;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Sidebar/dashboard summary: stats + usage + limits in one parallel DB round-trip batch.
|
|
112
|
+
*/
|
|
113
|
+
export async function getAccountSummary(userId) {
|
|
114
|
+
const cached = readCache(accountSummaryCache, userId);
|
|
115
|
+
if (cached)
|
|
116
|
+
return cached;
|
|
117
|
+
const workspaceWhere = workspaceAccessFilter(userId);
|
|
118
|
+
const [workspaceMeta, folderCount, usage, limits, storageUsed] = await Promise.all([
|
|
119
|
+
prisma.workspace.aggregate({
|
|
120
|
+
where: workspaceWhere,
|
|
121
|
+
_count: { _all: true },
|
|
122
|
+
_max: { updatedAt: true },
|
|
123
|
+
}),
|
|
124
|
+
prisma.folder.count({ where: { ownerId: userId } }),
|
|
125
|
+
getUserUsage(userId),
|
|
126
|
+
getUserPlanLimits(userId),
|
|
127
|
+
prisma.fileAsset.aggregate({
|
|
128
|
+
where: {
|
|
129
|
+
userId,
|
|
130
|
+
workspace: workspaceWhere,
|
|
131
|
+
},
|
|
132
|
+
_sum: { size: true },
|
|
133
|
+
}),
|
|
134
|
+
]);
|
|
135
|
+
const summary = {
|
|
136
|
+
stats: {
|
|
137
|
+
workspaces: workspaceMeta._count._all,
|
|
138
|
+
folders: folderCount,
|
|
139
|
+
lastUpdated: workspaceMeta._max.updatedAt,
|
|
140
|
+
spaceUsed: Number(storageUsed._sum.size ?? 0),
|
|
141
|
+
spaceTotal: Number(limits.maxStorageBytes),
|
|
142
|
+
},
|
|
143
|
+
usage,
|
|
144
|
+
limits,
|
|
145
|
+
hasActivePlan: !limits.isFallbackPlan,
|
|
146
|
+
};
|
|
147
|
+
writeCache(accountSummaryCache, userId, summary);
|
|
148
|
+
return summary;
|
|
149
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import type { PrismaClient } from '@prisma/client';
|
|
2
|
+
import { BaseService } from './base.service.js';
|
|
3
|
+
/**
|
|
4
|
+
* NOTE: These procedures currently do not verify that the caller belongs to
|
|
5
|
+
* the target workspace or channel. That's pre-existing behavior and is
|
|
6
|
+
* listed in REFACTOR_NOTES.md as a follow-up.
|
|
7
|
+
*/
|
|
8
|
+
export declare class ChatService extends BaseService {
|
|
9
|
+
constructor(db: PrismaClient);
|
|
10
|
+
getChannels(workspaceId: string): Promise<{
|
|
11
|
+
name: string;
|
|
12
|
+
id: string;
|
|
13
|
+
createdAt: Date;
|
|
14
|
+
workspaceId: string;
|
|
15
|
+
}[]>;
|
|
16
|
+
getChannel(input: {
|
|
17
|
+
workspaceId?: string;
|
|
18
|
+
channelId?: string;
|
|
19
|
+
}): Promise<{
|
|
20
|
+
chats: ({
|
|
21
|
+
user: {
|
|
22
|
+
name: string | null;
|
|
23
|
+
id: string;
|
|
24
|
+
} | null;
|
|
25
|
+
} & {
|
|
26
|
+
id: string;
|
|
27
|
+
createdAt: Date;
|
|
28
|
+
updatedAt: Date;
|
|
29
|
+
channelId: string;
|
|
30
|
+
userId: string | null;
|
|
31
|
+
message: string;
|
|
32
|
+
})[];
|
|
33
|
+
} & {
|
|
34
|
+
name: string;
|
|
35
|
+
id: string;
|
|
36
|
+
createdAt: Date;
|
|
37
|
+
workspaceId: string;
|
|
38
|
+
}>;
|
|
39
|
+
removeChannel(input: {
|
|
40
|
+
workspaceId: string;
|
|
41
|
+
channelId: string;
|
|
42
|
+
}): Promise<{
|
|
43
|
+
success: boolean;
|
|
44
|
+
}>;
|
|
45
|
+
editChannel(input: {
|
|
46
|
+
workspaceId: string;
|
|
47
|
+
channelId: string;
|
|
48
|
+
name: string;
|
|
49
|
+
}): Promise<{
|
|
50
|
+
chats: ({
|
|
51
|
+
user: {
|
|
52
|
+
name: string | null;
|
|
53
|
+
id: string;
|
|
54
|
+
} | null;
|
|
55
|
+
} & {
|
|
56
|
+
id: string;
|
|
57
|
+
createdAt: Date;
|
|
58
|
+
updatedAt: Date;
|
|
59
|
+
channelId: string;
|
|
60
|
+
userId: string | null;
|
|
61
|
+
message: string;
|
|
62
|
+
})[];
|
|
63
|
+
} & {
|
|
64
|
+
name: string;
|
|
65
|
+
id: string;
|
|
66
|
+
createdAt: Date;
|
|
67
|
+
workspaceId: string;
|
|
68
|
+
}>;
|
|
69
|
+
createChannel(input: {
|
|
70
|
+
workspaceId: string;
|
|
71
|
+
name: string;
|
|
72
|
+
}): Promise<{
|
|
73
|
+
chats: ({
|
|
74
|
+
user: {
|
|
75
|
+
name: string | null;
|
|
76
|
+
id: string;
|
|
77
|
+
} | null;
|
|
78
|
+
} & {
|
|
79
|
+
id: string;
|
|
80
|
+
createdAt: Date;
|
|
81
|
+
updatedAt: Date;
|
|
82
|
+
channelId: string;
|
|
83
|
+
userId: string | null;
|
|
84
|
+
message: string;
|
|
85
|
+
})[];
|
|
86
|
+
} & {
|
|
87
|
+
name: string;
|
|
88
|
+
id: string;
|
|
89
|
+
createdAt: Date;
|
|
90
|
+
workspaceId: string;
|
|
91
|
+
}>;
|
|
92
|
+
postMessage(userId: string, input: {
|
|
93
|
+
channelId: string;
|
|
94
|
+
message: string;
|
|
95
|
+
}): Promise<{
|
|
96
|
+
user: {
|
|
97
|
+
name: string | null;
|
|
98
|
+
id: string;
|
|
99
|
+
} | null;
|
|
100
|
+
} & {
|
|
101
|
+
id: string;
|
|
102
|
+
createdAt: Date;
|
|
103
|
+
updatedAt: Date;
|
|
104
|
+
channelId: string;
|
|
105
|
+
userId: string | null;
|
|
106
|
+
message: string;
|
|
107
|
+
}>;
|
|
108
|
+
editMessage(userId: string, input: {
|
|
109
|
+
chatId: string;
|
|
110
|
+
message: string;
|
|
111
|
+
}): Promise<{
|
|
112
|
+
user: {
|
|
113
|
+
name: string | null;
|
|
114
|
+
id: string;
|
|
115
|
+
} | null;
|
|
116
|
+
} & {
|
|
117
|
+
id: string;
|
|
118
|
+
createdAt: Date;
|
|
119
|
+
updatedAt: Date;
|
|
120
|
+
channelId: string;
|
|
121
|
+
userId: string | null;
|
|
122
|
+
message: string;
|
|
123
|
+
}>;
|
|
124
|
+
deleteMessage(userId: string, chatId: string): Promise<{
|
|
125
|
+
success: boolean;
|
|
126
|
+
}>;
|
|
127
|
+
}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { TRPCError } from '@trpc/server';
|
|
2
|
+
import { BaseService } from './base.service.js';
|
|
3
|
+
import PusherService from '../lib/pusher.js';
|
|
4
|
+
/**
|
|
5
|
+
* NOTE: These procedures currently do not verify that the caller belongs to
|
|
6
|
+
* the target workspace or channel. That's pre-existing behavior and is
|
|
7
|
+
* listed in REFACTOR_NOTES.md as a follow-up.
|
|
8
|
+
*/
|
|
9
|
+
export class ChatService extends BaseService {
|
|
10
|
+
constructor(db) {
|
|
11
|
+
super(db);
|
|
12
|
+
}
|
|
13
|
+
async getChannels(workspaceId) {
|
|
14
|
+
const channels = await this.db.channel.findMany({
|
|
15
|
+
where: { workspaceId },
|
|
16
|
+
include: {
|
|
17
|
+
chats: {
|
|
18
|
+
include: {
|
|
19
|
+
user: {
|
|
20
|
+
select: {
|
|
21
|
+
id: true,
|
|
22
|
+
name: true,
|
|
23
|
+
profilePicture: {
|
|
24
|
+
select: { id: true, name: true, url: true },
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
if (!channels) {
|
|
33
|
+
const defaultChannel = await this.db.channel.create({
|
|
34
|
+
data: { workspaceId, name: 'General' },
|
|
35
|
+
});
|
|
36
|
+
return [defaultChannel];
|
|
37
|
+
}
|
|
38
|
+
return channels;
|
|
39
|
+
}
|
|
40
|
+
async getChannel(input) {
|
|
41
|
+
if (!input.channelId && input.workspaceId) {
|
|
42
|
+
const defaultChannel = await this.db.channel.create({
|
|
43
|
+
data: { workspaceId: input.workspaceId, name: 'General' },
|
|
44
|
+
include: {
|
|
45
|
+
chats: {
|
|
46
|
+
include: {
|
|
47
|
+
user: { select: { id: true, name: true } },
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
await PusherService.emitTaskComplete(input.workspaceId, 'new_channel', {
|
|
53
|
+
channelId: defaultChannel.id,
|
|
54
|
+
workspaceId: input.workspaceId,
|
|
55
|
+
name: 'General',
|
|
56
|
+
createdAt: defaultChannel.createdAt,
|
|
57
|
+
});
|
|
58
|
+
return defaultChannel;
|
|
59
|
+
}
|
|
60
|
+
const channel = await this.db.channel.findUnique({
|
|
61
|
+
where: { id: input.channelId },
|
|
62
|
+
include: {
|
|
63
|
+
chats: {
|
|
64
|
+
include: {
|
|
65
|
+
user: { select: { id: true, name: true } },
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
if (!channel) {
|
|
71
|
+
throw new TRPCError({ code: 'NOT_FOUND', message: 'Channel not found' });
|
|
72
|
+
}
|
|
73
|
+
return channel;
|
|
74
|
+
}
|
|
75
|
+
async removeChannel(input) {
|
|
76
|
+
await this.db.channel.delete({ where: { id: input.channelId } });
|
|
77
|
+
await PusherService.emitTaskComplete(input.workspaceId, 'remove_channel', {
|
|
78
|
+
channelId: input.channelId,
|
|
79
|
+
deletedAt: new Date().toISOString(),
|
|
80
|
+
});
|
|
81
|
+
return { success: true };
|
|
82
|
+
}
|
|
83
|
+
async editChannel(input) {
|
|
84
|
+
const channel = await this.db.channel.update({
|
|
85
|
+
where: { id: input.channelId },
|
|
86
|
+
data: { name: input.name },
|
|
87
|
+
include: {
|
|
88
|
+
chats: {
|
|
89
|
+
include: {
|
|
90
|
+
user: { select: { id: true, name: true } },
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
});
|
|
95
|
+
await PusherService.emitTaskComplete(input.workspaceId, 'edit_channel', {
|
|
96
|
+
channelId: input.channelId,
|
|
97
|
+
workspaceId: input.workspaceId,
|
|
98
|
+
name: input.name,
|
|
99
|
+
});
|
|
100
|
+
return channel;
|
|
101
|
+
}
|
|
102
|
+
async createChannel(input) {
|
|
103
|
+
const channel = await this.db.channel.create({
|
|
104
|
+
data: { workspaceId: input.workspaceId, name: input.name },
|
|
105
|
+
include: {
|
|
106
|
+
chats: {
|
|
107
|
+
include: {
|
|
108
|
+
user: { select: { id: true, name: true } },
|
|
109
|
+
},
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
});
|
|
113
|
+
await PusherService.emitTaskComplete(input.workspaceId, 'new_channel', {
|
|
114
|
+
channelId: channel.id,
|
|
115
|
+
workspaceId: input.workspaceId,
|
|
116
|
+
name: input.name,
|
|
117
|
+
createdAt: channel.createdAt,
|
|
118
|
+
});
|
|
119
|
+
return channel;
|
|
120
|
+
}
|
|
121
|
+
async postMessage(userId, input) {
|
|
122
|
+
const channel = await this.db.channel.findUnique({
|
|
123
|
+
where: { id: input.channelId },
|
|
124
|
+
include: {
|
|
125
|
+
chats: {
|
|
126
|
+
include: {
|
|
127
|
+
user: { select: { id: true, name: true } },
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
});
|
|
132
|
+
if (!channel) {
|
|
133
|
+
throw new TRPCError({ code: 'NOT_FOUND', message: 'Channel not found' });
|
|
134
|
+
}
|
|
135
|
+
const chat = await this.db.chat.create({
|
|
136
|
+
data: {
|
|
137
|
+
channelId: input.channelId,
|
|
138
|
+
userId,
|
|
139
|
+
message: input.message,
|
|
140
|
+
},
|
|
141
|
+
include: {
|
|
142
|
+
user: { select: { id: true, name: true } },
|
|
143
|
+
},
|
|
144
|
+
});
|
|
145
|
+
await PusherService.emitChannelEvent(input.channelId, 'new_message', chat);
|
|
146
|
+
return chat;
|
|
147
|
+
}
|
|
148
|
+
async editMessage(userId, input) {
|
|
149
|
+
const chat = await this.db.chat.findUnique({
|
|
150
|
+
where: { id: input.chatId },
|
|
151
|
+
include: { user: { select: { id: true, name: true } } },
|
|
152
|
+
});
|
|
153
|
+
if (!chat) {
|
|
154
|
+
throw new TRPCError({ code: 'NOT_FOUND', message: 'Chat message not found' });
|
|
155
|
+
}
|
|
156
|
+
if (chat.userId !== userId) {
|
|
157
|
+
throw new TRPCError({ code: 'FORBIDDEN', message: 'Not your message to edit' });
|
|
158
|
+
}
|
|
159
|
+
const updatedChat = await this.db.chat.update({
|
|
160
|
+
where: { id: input.chatId },
|
|
161
|
+
data: { message: input.message },
|
|
162
|
+
include: { user: { select: { id: true, name: true } } },
|
|
163
|
+
});
|
|
164
|
+
await PusherService.emitChannelEvent(chat.channelId, 'edit_message', updatedChat);
|
|
165
|
+
return updatedChat;
|
|
166
|
+
}
|
|
167
|
+
async deleteMessage(userId, chatId) {
|
|
168
|
+
const chat = await this.db.chat.findUnique({
|
|
169
|
+
where: { id: chatId },
|
|
170
|
+
include: { user: { select: { id: true, name: true } } },
|
|
171
|
+
});
|
|
172
|
+
if (!chat) {
|
|
173
|
+
throw new TRPCError({ code: 'NOT_FOUND', message: 'Chat message not found' });
|
|
174
|
+
}
|
|
175
|
+
if (chat.userId !== userId) {
|
|
176
|
+
throw new TRPCError({ code: 'FORBIDDEN', message: 'Not your message to delete' });
|
|
177
|
+
}
|
|
178
|
+
await this.db.chat.delete({ where: { id: chatId } });
|
|
179
|
+
await PusherService.emitChannelEvent(chat.channelId, 'delete_message', chat);
|
|
180
|
+
return { success: true };
|
|
181
|
+
}
|
|
182
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import type { PrismaClient } from '@prisma/client';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { BaseService } from '../base.service.js';
|
|
4
|
+
export declare const copilotArtifactType: z.ZodEnum<{
|
|
5
|
+
flashcards: "flashcards";
|
|
6
|
+
worksheet: "worksheet";
|
|
7
|
+
"study-guide": "study-guide";
|
|
8
|
+
}>;
|
|
9
|
+
export declare const copilotContextSchema: z.ZodObject<{
|
|
10
|
+
workspaceId: z.ZodString;
|
|
11
|
+
artifactId: z.ZodString;
|
|
12
|
+
artifactType: z.ZodEnum<{
|
|
13
|
+
flashcards: "flashcards";
|
|
14
|
+
worksheet: "worksheet";
|
|
15
|
+
"study-guide": "study-guide";
|
|
16
|
+
}>;
|
|
17
|
+
documentContent: z.ZodString;
|
|
18
|
+
documentPlainText: z.ZodOptional<z.ZodString>;
|
|
19
|
+
selectedText: z.ZodOptional<z.ZodString>;
|
|
20
|
+
viewportText: z.ZodOptional<z.ZodString>;
|
|
21
|
+
cursorPosition: z.ZodOptional<z.ZodObject<{
|
|
22
|
+
start: z.ZodNumber;
|
|
23
|
+
end: z.ZodNumber;
|
|
24
|
+
}, z.core.$strip>>;
|
|
25
|
+
metadata: z.ZodOptional<z.ZodObject<{
|
|
26
|
+
flashcardId: z.ZodOptional<z.ZodString>;
|
|
27
|
+
questionId: z.ZodOptional<z.ZodString>;
|
|
28
|
+
documentId: z.ZodOptional<z.ZodString>;
|
|
29
|
+
}, z.core.$strip>>;
|
|
30
|
+
}, z.core.$strip>;
|
|
31
|
+
export type CopilotContextInput = z.infer<typeof copilotContextSchema>;
|
|
32
|
+
export declare class CopilotService extends BaseService {
|
|
33
|
+
constructor(db: PrismaClient);
|
|
34
|
+
private assertWorkspaceAccess;
|
|
35
|
+
private assertConversationAccess;
|
|
36
|
+
private loadHistory;
|
|
37
|
+
private persistConversationExchange;
|
|
38
|
+
listConversations(userId: string, workspaceId: string): Promise<{
|
|
39
|
+
id: string;
|
|
40
|
+
title: string;
|
|
41
|
+
updatedAt: Date;
|
|
42
|
+
preview: string;
|
|
43
|
+
}[]>;
|
|
44
|
+
getConversation(userId: string, workspaceId: string, conversationId: string): Promise<{
|
|
45
|
+
id: string;
|
|
46
|
+
title: string;
|
|
47
|
+
messages: {
|
|
48
|
+
id: string;
|
|
49
|
+
role: string;
|
|
50
|
+
content: string;
|
|
51
|
+
createdAt: Date;
|
|
52
|
+
}[];
|
|
53
|
+
}>;
|
|
54
|
+
createConversation(userId: string, input: {
|
|
55
|
+
workspaceId: string;
|
|
56
|
+
title?: string;
|
|
57
|
+
}): Promise<{
|
|
58
|
+
id: string;
|
|
59
|
+
title: string;
|
|
60
|
+
updatedAt: Date;
|
|
61
|
+
}>;
|
|
62
|
+
deleteConversation(userId: string, workspaceId: string, conversationId: string): Promise<{
|
|
63
|
+
success: boolean;
|
|
64
|
+
}>;
|
|
65
|
+
ask(userId: string, input: {
|
|
66
|
+
context: CopilotContextInput;
|
|
67
|
+
message: string;
|
|
68
|
+
conversationId?: string;
|
|
69
|
+
}): Promise<{
|
|
70
|
+
answer: string;
|
|
71
|
+
highlights: {
|
|
72
|
+
text: string;
|
|
73
|
+
label?: string;
|
|
74
|
+
}[];
|
|
75
|
+
}>;
|
|
76
|
+
explainSelection(userId: string, input: {
|
|
77
|
+
context: CopilotContextInput;
|
|
78
|
+
message?: string;
|
|
79
|
+
conversationId?: string;
|
|
80
|
+
}): Promise<{
|
|
81
|
+
answer: string;
|
|
82
|
+
}>;
|
|
83
|
+
suggestHighlights(userId: string, input: {
|
|
84
|
+
context: CopilotContextInput;
|
|
85
|
+
message?: string;
|
|
86
|
+
conversationId?: string;
|
|
87
|
+
}): Promise<{
|
|
88
|
+
answer: string;
|
|
89
|
+
highlights: {
|
|
90
|
+
text: string;
|
|
91
|
+
label?: string;
|
|
92
|
+
}[];
|
|
93
|
+
}>;
|
|
94
|
+
generateFlashcards(userId: string, input: {
|
|
95
|
+
context: CopilotContextInput;
|
|
96
|
+
message?: string;
|
|
97
|
+
numCards: number;
|
|
98
|
+
conversationId?: string;
|
|
99
|
+
}): Promise<{
|
|
100
|
+
answer: string;
|
|
101
|
+
artifactId: string;
|
|
102
|
+
flashcards: {
|
|
103
|
+
id: string;
|
|
104
|
+
createdAt: Date;
|
|
105
|
+
artifactId: string;
|
|
106
|
+
tags: string[];
|
|
107
|
+
order: number;
|
|
108
|
+
front: string;
|
|
109
|
+
back: string;
|
|
110
|
+
acceptedAnswers: string[];
|
|
111
|
+
}[];
|
|
112
|
+
}>;
|
|
113
|
+
}
|