@goscribe/server 1.3.3 → 1.5.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/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 +47 -0
- package/dist/lib/ai/index.js +28 -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 +6 -0
- package/dist/lib/ai/llm-client.js +19 -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 +528 -33
- 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 +36 -421
- 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 +5 -5
- 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 +3 -2
- 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 +0 -4
- package/dist/routers/workspace.js +28 -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 +55 -0
- package/dist/services/billing/payment.service.js +368 -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 +27 -0
- package/dist/services/billing/usage.service.js +77 -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 +453 -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 +140 -0
- package/dist/services/content/flashcard.service.js +326 -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 +307 -0
- package/dist/services/workspace/workspace.service.js +394 -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.js +2 -2
- 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/lib/ai/config.ts +34 -0
- package/src/lib/ai/embedding-client.ts +47 -0
- package/src/lib/ai/index.ts +62 -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 +31 -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 +81 -519
- 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 +138 -1109
- 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 +436 -0
- package/src/{lib/subscription_service.ts → services/billing/subscription.service.ts} +5 -5
- package/src/{lib/usage_service.ts → services/billing/usage.service.ts} +32 -12
- package/src/services/content/copilot.service.ts +596 -0
- package/src/services/{flashcard-progress.service.ts → content/flashcard-progress.service.ts} +6 -3
- package/src/services/content/flashcard.service.ts +394 -0
- package/src/services/content/media-analysis.service.ts +556 -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} +1 -1
- 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 +481 -0
- package/src/trpc.ts +2 -2
- package/src/lib/ai-session.ts +0 -704
- 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,348 @@
|
|
|
1
|
+
import { TRPCError } from '@trpc/server';
|
|
2
|
+
import { BaseService } from './base.service.js';
|
|
3
|
+
import { sendInvitationEmail } from '../lib/email.js';
|
|
4
|
+
import PusherService from '../lib/pusher.js';
|
|
5
|
+
import { notifyInviteAccepted, notifyInviteRecipient, } from './notification.service.js';
|
|
6
|
+
export class InvitationService extends BaseService {
|
|
7
|
+
constructor(db) {
|
|
8
|
+
super(db);
|
|
9
|
+
}
|
|
10
|
+
async inviteMember(userId, input) {
|
|
11
|
+
const workspace = await this.db.workspace.findFirst({
|
|
12
|
+
where: { id: input.workspaceId, ownerId: userId },
|
|
13
|
+
});
|
|
14
|
+
if (!workspace) {
|
|
15
|
+
throw new TRPCError({
|
|
16
|
+
code: 'NOT_FOUND',
|
|
17
|
+
message: 'Workspace not found or insufficient permissions',
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
const existingMember = await this.db.user.findFirst({
|
|
21
|
+
where: {
|
|
22
|
+
email: input.email,
|
|
23
|
+
OR: [
|
|
24
|
+
{ id: workspace.ownerId },
|
|
25
|
+
{ workspaceMemberships: { some: { workspaceId: input.workspaceId } } },
|
|
26
|
+
],
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
if (existingMember) {
|
|
30
|
+
throw new TRPCError({
|
|
31
|
+
code: 'BAD_REQUEST',
|
|
32
|
+
message: 'User is already a member of this workspace',
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
const existingInvitation = await this.db.workspaceInvitation.findFirst({
|
|
36
|
+
where: {
|
|
37
|
+
workspaceId: input.workspaceId,
|
|
38
|
+
email: input.email,
|
|
39
|
+
acceptedAt: null,
|
|
40
|
+
expiresAt: { gt: new Date() },
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
if (existingInvitation) {
|
|
44
|
+
throw new TRPCError({
|
|
45
|
+
code: 'BAD_REQUEST',
|
|
46
|
+
message: 'Invitation already sent to this email',
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
const invitation = await this.db.workspaceInvitation.create({
|
|
50
|
+
data: {
|
|
51
|
+
workspaceId: input.workspaceId,
|
|
52
|
+
email: input.email,
|
|
53
|
+
role: input.role,
|
|
54
|
+
invitedById: userId,
|
|
55
|
+
},
|
|
56
|
+
include: {
|
|
57
|
+
workspace: {
|
|
58
|
+
select: {
|
|
59
|
+
title: true,
|
|
60
|
+
owner: { select: { name: true, email: true } },
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
const invitedExistingUser = await this.db.user.findUnique({
|
|
66
|
+
where: { email: input.email },
|
|
67
|
+
select: { id: true, name: true },
|
|
68
|
+
});
|
|
69
|
+
if (invitedExistingUser) {
|
|
70
|
+
await notifyInviteRecipient(this.db, {
|
|
71
|
+
invitedUserId: invitedExistingUser.id,
|
|
72
|
+
inviterUserId: userId,
|
|
73
|
+
workspaceId: input.workspaceId,
|
|
74
|
+
workspaceTitle: invitation.workspace.title,
|
|
75
|
+
invitationId: invitation.id,
|
|
76
|
+
invitationToken: invitation.token,
|
|
77
|
+
inviterName: invitation.workspace.owner.name || invitation.workspace.owner.email,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
this.logger.info(`🎫 Invitation created for ${input.email} to workspace ${input.workspaceId} with role ${input.role}`, 'WORKSPACE', {
|
|
81
|
+
invitationId: invitation.id,
|
|
82
|
+
workspaceId: input.workspaceId,
|
|
83
|
+
email: input.email,
|
|
84
|
+
role: input.role,
|
|
85
|
+
invitedBy: userId,
|
|
86
|
+
});
|
|
87
|
+
await sendInvitationEmail({
|
|
88
|
+
email: invitation.email,
|
|
89
|
+
token: invitation.token,
|
|
90
|
+
role: invitation.role,
|
|
91
|
+
workspaceTitle: invitation.workspace.title,
|
|
92
|
+
invitedByName: invitation.workspace.owner.name || invitation.workspace.owner.email || 'Someone',
|
|
93
|
+
});
|
|
94
|
+
return {
|
|
95
|
+
invitationId: invitation.id,
|
|
96
|
+
token: invitation.token,
|
|
97
|
+
email: invitation.email,
|
|
98
|
+
role: invitation.role,
|
|
99
|
+
expiresAt: invitation.expiresAt,
|
|
100
|
+
workspaceTitle: invitation.workspace.title,
|
|
101
|
+
invitedByName: invitation.workspace.owner.name || invitation.workspace.owner.email,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
async getInvitations(workspaceId) {
|
|
105
|
+
return this.db.workspaceInvitation.findMany({
|
|
106
|
+
where: { workspaceId },
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
async acceptInvite(sessionUserId, token) {
|
|
110
|
+
const invitation = await this.db.workspaceInvitation.findFirst({
|
|
111
|
+
where: {
|
|
112
|
+
token,
|
|
113
|
+
acceptedAt: null,
|
|
114
|
+
expiresAt: { gt: new Date() },
|
|
115
|
+
},
|
|
116
|
+
include: {
|
|
117
|
+
workspace: {
|
|
118
|
+
select: {
|
|
119
|
+
id: true,
|
|
120
|
+
title: true,
|
|
121
|
+
ownerId: true,
|
|
122
|
+
owner: { select: { name: true, email: true } },
|
|
123
|
+
},
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
});
|
|
127
|
+
if (!invitation) {
|
|
128
|
+
throw new TRPCError({
|
|
129
|
+
code: 'NOT_FOUND',
|
|
130
|
+
message: 'Invalid or expired invitation',
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
if (!sessionUserId) {
|
|
134
|
+
throw new TRPCError({
|
|
135
|
+
code: 'UNAUTHORIZED',
|
|
136
|
+
message: 'Please log in to accept this invitation',
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
const user = await this.db.user.findFirst({ where: { id: sessionUserId } });
|
|
140
|
+
if (!user || !user.email)
|
|
141
|
+
throw new TRPCError({ code: 'NOT_FOUND' });
|
|
142
|
+
this.logger.info(`🔍 Verification check for ${user.email} accepting invite for ${invitation.email}`, 'WORKSPACE');
|
|
143
|
+
if (user.email.toLowerCase() !== invitation.email.toLowerCase()) {
|
|
144
|
+
this.logger.warn(`❌ Invitation email mismatch: user ${user.email} vs invite ${invitation.email}`, 'WORKSPACE');
|
|
145
|
+
throw new TRPCError({
|
|
146
|
+
code: 'BAD_REQUEST',
|
|
147
|
+
message: 'This invitation was sent to a different email address',
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
const isAlreadyMember = await this.db.workspace.findFirst({
|
|
151
|
+
where: {
|
|
152
|
+
id: invitation.workspaceId,
|
|
153
|
+
OR: [
|
|
154
|
+
{ ownerId: sessionUserId },
|
|
155
|
+
{ members: { some: { userId: sessionUserId } } },
|
|
156
|
+
],
|
|
157
|
+
},
|
|
158
|
+
});
|
|
159
|
+
if (isAlreadyMember) {
|
|
160
|
+
this.logger.info(`ℹ️ User ${sessionUserId} is already a member of workspace ${invitation.workspaceId}. Marking invite as accepted.`, 'WORKSPACE');
|
|
161
|
+
await this.db.workspaceInvitation.update({
|
|
162
|
+
where: { id: invitation.id },
|
|
163
|
+
data: { acceptedAt: new Date() },
|
|
164
|
+
});
|
|
165
|
+
return {
|
|
166
|
+
workspaceId: invitation.workspaceId,
|
|
167
|
+
workspaceTitle: invitation.workspace.title,
|
|
168
|
+
role: invitation.role,
|
|
169
|
+
ownerName: invitation.workspace.owner.name || invitation.workspace.owner.email,
|
|
170
|
+
message: 'You are already a member of this workspace',
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
let memberAdded = false;
|
|
174
|
+
try {
|
|
175
|
+
await this.db.workspaceMember.create({
|
|
176
|
+
data: {
|
|
177
|
+
workspaceId: invitation.workspaceId,
|
|
178
|
+
userId: sessionUserId,
|
|
179
|
+
role: invitation.role,
|
|
180
|
+
},
|
|
181
|
+
});
|
|
182
|
+
memberAdded = true;
|
|
183
|
+
}
|
|
184
|
+
catch (error) {
|
|
185
|
+
if (error?.code !== 'P2002') {
|
|
186
|
+
throw error;
|
|
187
|
+
}
|
|
188
|
+
this.logger.info(`ℹ️ Duplicate invite accept handled for user ${sessionUserId} in workspace ${invitation.workspaceId}`, 'WORKSPACE');
|
|
189
|
+
}
|
|
190
|
+
await this.db.workspaceInvitation.update({
|
|
191
|
+
where: { id: invitation.id },
|
|
192
|
+
data: { acceptedAt: new Date() },
|
|
193
|
+
});
|
|
194
|
+
if (memberAdded) {
|
|
195
|
+
await notifyInviteAccepted(this.db, {
|
|
196
|
+
recipientUserIds: [invitation.invitedById, invitation.workspace.ownerId],
|
|
197
|
+
actorUserId: sessionUserId,
|
|
198
|
+
workspaceId: invitation.workspaceId,
|
|
199
|
+
workspaceTitle: invitation.workspace.title,
|
|
200
|
+
memberName: user.name || user.email,
|
|
201
|
+
invitationId: invitation.id,
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
this.logger.info(`✅ Invitation accepted by ${sessionUserId} (${user.email}) for workspace ${invitation.workspaceId}`, 'WORKSPACE', {
|
|
205
|
+
invitationId: invitation.id,
|
|
206
|
+
workspaceId: invitation.workspaceId,
|
|
207
|
+
userId: sessionUserId,
|
|
208
|
+
email: invitation.email,
|
|
209
|
+
});
|
|
210
|
+
try {
|
|
211
|
+
if (memberAdded) {
|
|
212
|
+
await PusherService.emitMemberJoined(invitation.workspaceId, {
|
|
213
|
+
id: sessionUserId,
|
|
214
|
+
name: user.name || 'Member',
|
|
215
|
+
email: user.email,
|
|
216
|
+
role: invitation.role,
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
catch (e) {
|
|
221
|
+
this.logger.error('Failed to emit member joined event', e);
|
|
222
|
+
}
|
|
223
|
+
return {
|
|
224
|
+
workspaceId: invitation.workspaceId,
|
|
225
|
+
workspaceTitle: invitation.workspace.title,
|
|
226
|
+
role: invitation.role,
|
|
227
|
+
ownerName: invitation.workspace.owner.name || invitation.workspace.owner.email,
|
|
228
|
+
...(memberAdded ? {} : { message: 'You are already a member of this workspace' }),
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
async getPendingInvitations(userId, workspaceId) {
|
|
232
|
+
const workspace = await this.db.workspace.findFirst({
|
|
233
|
+
where: { id: workspaceId, ownerId: userId },
|
|
234
|
+
});
|
|
235
|
+
if (!workspace) {
|
|
236
|
+
throw new TRPCError({
|
|
237
|
+
code: 'NOT_FOUND',
|
|
238
|
+
message: 'Workspace not found or insufficient permissions',
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
const invitations = await this.db.workspaceInvitation.findMany({
|
|
242
|
+
where: {
|
|
243
|
+
workspaceId,
|
|
244
|
+
acceptedAt: null,
|
|
245
|
+
expiresAt: { gt: new Date() },
|
|
246
|
+
},
|
|
247
|
+
include: {
|
|
248
|
+
invitedBy: { select: { name: true, email: true } },
|
|
249
|
+
},
|
|
250
|
+
orderBy: { createdAt: 'desc' },
|
|
251
|
+
});
|
|
252
|
+
return invitations.map((invitation) => ({
|
|
253
|
+
id: invitation.id,
|
|
254
|
+
email: invitation.email,
|
|
255
|
+
role: invitation.role,
|
|
256
|
+
token: invitation.token,
|
|
257
|
+
expiresAt: invitation.expiresAt,
|
|
258
|
+
createdAt: invitation.createdAt,
|
|
259
|
+
invitedByName: invitation.invitedBy.name || invitation.invitedBy.email,
|
|
260
|
+
}));
|
|
261
|
+
}
|
|
262
|
+
async cancelInvitation(userId, invitationId) {
|
|
263
|
+
const invitation = await this.db.workspaceInvitation.findFirst({
|
|
264
|
+
where: {
|
|
265
|
+
id: invitationId,
|
|
266
|
+
acceptedAt: null,
|
|
267
|
+
workspace: { ownerId: userId },
|
|
268
|
+
},
|
|
269
|
+
});
|
|
270
|
+
if (!invitation) {
|
|
271
|
+
throw new TRPCError({
|
|
272
|
+
code: 'NOT_FOUND',
|
|
273
|
+
message: 'Invitation not found or insufficient permissions',
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
await this.db.workspaceInvitation.delete({ where: { id: invitationId } });
|
|
277
|
+
this.logger.info(`❌ Invitation cancelled for ${invitation.email} to workspace ${invitation.workspaceId}`, 'WORKSPACE', {
|
|
278
|
+
invitationId,
|
|
279
|
+
workspaceId: invitation.workspaceId,
|
|
280
|
+
email: invitation.email,
|
|
281
|
+
cancelledBy: userId,
|
|
282
|
+
});
|
|
283
|
+
return {
|
|
284
|
+
invitationId,
|
|
285
|
+
message: 'Invitation cancelled successfully',
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
async resendInvitation(userId, invitationId) {
|
|
289
|
+
const invitation = await this.db.workspaceInvitation.findFirst({
|
|
290
|
+
where: {
|
|
291
|
+
id: invitationId,
|
|
292
|
+
acceptedAt: null,
|
|
293
|
+
workspace: { ownerId: userId },
|
|
294
|
+
},
|
|
295
|
+
include: {
|
|
296
|
+
workspace: {
|
|
297
|
+
select: {
|
|
298
|
+
title: true,
|
|
299
|
+
owner: { select: { name: true, email: true } },
|
|
300
|
+
},
|
|
301
|
+
},
|
|
302
|
+
},
|
|
303
|
+
});
|
|
304
|
+
if (!invitation) {
|
|
305
|
+
throw new TRPCError({
|
|
306
|
+
code: 'NOT_FOUND',
|
|
307
|
+
message: 'Invitation not found or insufficient permissions',
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
if (invitation.expiresAt < new Date()) {
|
|
311
|
+
const newExpiry = new Date();
|
|
312
|
+
newExpiry.setDate(newExpiry.getDate() + 7);
|
|
313
|
+
await this.db.workspaceInvitation.update({
|
|
314
|
+
where: { id: invitation.id },
|
|
315
|
+
data: { expiresAt: newExpiry },
|
|
316
|
+
});
|
|
317
|
+
invitation.expiresAt = newExpiry;
|
|
318
|
+
}
|
|
319
|
+
await sendInvitationEmail({
|
|
320
|
+
email: invitation.email,
|
|
321
|
+
token: invitation.token,
|
|
322
|
+
role: invitation.role,
|
|
323
|
+
workspaceTitle: invitation.workspace.title,
|
|
324
|
+
invitedByName: invitation.workspace.owner.name || invitation.workspace.owner.email || 'Someone',
|
|
325
|
+
});
|
|
326
|
+
this.logger.info(`📧 Invitation resent to ${invitation.email} for workspace ${invitation.workspaceId}`, 'WORKSPACE', {
|
|
327
|
+
invitationId: invitation.id,
|
|
328
|
+
workspaceId: invitation.workspaceId,
|
|
329
|
+
email: invitation.email,
|
|
330
|
+
resentBy: userId,
|
|
331
|
+
});
|
|
332
|
+
return {
|
|
333
|
+
invitationId: invitation.id,
|
|
334
|
+
message: 'Invitation email resent successfully',
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
async getAllInvitationsDebug(userId, workspaceId) {
|
|
338
|
+
const workspace = await this.db.workspace.findFirst({
|
|
339
|
+
where: { id: workspaceId, ownerId: userId },
|
|
340
|
+
});
|
|
341
|
+
if (!workspace)
|
|
342
|
+
throw new TRPCError({ code: 'UNAUTHORIZED' });
|
|
343
|
+
return this.db.workspaceInvitation.findMany({
|
|
344
|
+
where: { workspaceId },
|
|
345
|
+
orderBy: { createdAt: 'desc' },
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
}
|
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
import type { PrismaClient } from '@prisma/client';
|
|
2
|
+
import { BaseService } from '../base.service.js';
|
|
3
|
+
interface AdminCreateInput {
|
|
4
|
+
name: string;
|
|
5
|
+
description?: string;
|
|
6
|
+
isCurated?: boolean;
|
|
7
|
+
}
|
|
8
|
+
interface AdminUpdateInput {
|
|
9
|
+
id: string;
|
|
10
|
+
name?: string;
|
|
11
|
+
description?: string | null;
|
|
12
|
+
isCurated?: boolean;
|
|
13
|
+
}
|
|
14
|
+
interface RequestUploadUrlInput {
|
|
15
|
+
knowledgeBaseId: string;
|
|
16
|
+
filename: string;
|
|
17
|
+
contentType: string;
|
|
18
|
+
size: number;
|
|
19
|
+
}
|
|
20
|
+
interface ProcessDocumentInput {
|
|
21
|
+
knowledgeBaseId: string;
|
|
22
|
+
documentId: string;
|
|
23
|
+
}
|
|
24
|
+
interface QueryInput {
|
|
25
|
+
knowledgeBaseId: string;
|
|
26
|
+
query: string;
|
|
27
|
+
topK?: number;
|
|
28
|
+
generateAnswer?: boolean;
|
|
29
|
+
}
|
|
30
|
+
export declare class KnowledgeBaseService extends BaseService {
|
|
31
|
+
constructor(db: PrismaClient);
|
|
32
|
+
private assertWorkspaceAccess;
|
|
33
|
+
/**
|
|
34
|
+
* Loads a knowledge base only if it's reachable to the calling user, i.e.
|
|
35
|
+
* either curated (visible in catalog) or attached to one of their accessible
|
|
36
|
+
* workspaces.
|
|
37
|
+
*/
|
|
38
|
+
private loadKbForUser;
|
|
39
|
+
/** Admin-only: load by id without membership/curation checks. */
|
|
40
|
+
private loadKbAsAdmin;
|
|
41
|
+
/**
|
|
42
|
+
* KBs attached to a given workspace (the user's "library" for that
|
|
43
|
+
* workspace).
|
|
44
|
+
*/
|
|
45
|
+
listForWorkspace(userId: string, workspaceId: string): Promise<{
|
|
46
|
+
attachmentId: string;
|
|
47
|
+
attachedAt: Date;
|
|
48
|
+
attachedById: string | null;
|
|
49
|
+
_count: {
|
|
50
|
+
documents: number;
|
|
51
|
+
};
|
|
52
|
+
meta: import("@prisma/client/runtime/library").JsonValue | null;
|
|
53
|
+
name: string;
|
|
54
|
+
id: string;
|
|
55
|
+
createdAt: Date;
|
|
56
|
+
updatedAt: Date;
|
|
57
|
+
createdById: string | null;
|
|
58
|
+
description: string | null;
|
|
59
|
+
status: import("@prisma/client").$Enums.KnowledgeBaseStatus;
|
|
60
|
+
isCurated: boolean;
|
|
61
|
+
embeddingModel: string;
|
|
62
|
+
embeddingDim: number;
|
|
63
|
+
}[]>;
|
|
64
|
+
/**
|
|
65
|
+
* Search the curated catalog. Optionally pass a workspaceId to also tag
|
|
66
|
+
* each result with whether the workspace already has it attached.
|
|
67
|
+
*/
|
|
68
|
+
searchCatalog(userId: string, input: {
|
|
69
|
+
query?: string;
|
|
70
|
+
workspaceId?: string;
|
|
71
|
+
limit?: number;
|
|
72
|
+
}): Promise<{
|
|
73
|
+
attached: boolean;
|
|
74
|
+
_count: {
|
|
75
|
+
documents: number;
|
|
76
|
+
};
|
|
77
|
+
meta: import("@prisma/client/runtime/library").JsonValue | null;
|
|
78
|
+
name: string;
|
|
79
|
+
id: string;
|
|
80
|
+
createdAt: Date;
|
|
81
|
+
updatedAt: Date;
|
|
82
|
+
createdById: string | null;
|
|
83
|
+
description: string | null;
|
|
84
|
+
status: import("@prisma/client").$Enums.KnowledgeBaseStatus;
|
|
85
|
+
isCurated: boolean;
|
|
86
|
+
embeddingModel: string;
|
|
87
|
+
embeddingDim: number;
|
|
88
|
+
}[]>;
|
|
89
|
+
get(userId: string, id: string): Promise<{
|
|
90
|
+
documents: {
|
|
91
|
+
meta: import("@prisma/client/runtime/library").JsonValue | null;
|
|
92
|
+
name: string;
|
|
93
|
+
id: string;
|
|
94
|
+
createdAt: Date;
|
|
95
|
+
updatedAt: Date;
|
|
96
|
+
mimeType: string;
|
|
97
|
+
size: number;
|
|
98
|
+
bucket: string | null;
|
|
99
|
+
objectKey: string | null;
|
|
100
|
+
status: import("@prisma/client").$Enums.KnowledgeBaseDocumentStatus;
|
|
101
|
+
knowledgeBaseId: string;
|
|
102
|
+
errorMessage: string | null;
|
|
103
|
+
numChunks: number;
|
|
104
|
+
numPages: number | null;
|
|
105
|
+
}[];
|
|
106
|
+
meta: import("@prisma/client/runtime/library").JsonValue | null;
|
|
107
|
+
name: string;
|
|
108
|
+
id: string;
|
|
109
|
+
createdAt: Date;
|
|
110
|
+
updatedAt: Date;
|
|
111
|
+
createdById: string | null;
|
|
112
|
+
description: string | null;
|
|
113
|
+
status: import("@prisma/client").$Enums.KnowledgeBaseStatus;
|
|
114
|
+
isCurated: boolean;
|
|
115
|
+
embeddingModel: string;
|
|
116
|
+
embeddingDim: number;
|
|
117
|
+
}>;
|
|
118
|
+
listDocuments(userId: string, knowledgeBaseId: string): Promise<{
|
|
119
|
+
meta: import("@prisma/client/runtime/library").JsonValue | null;
|
|
120
|
+
name: string;
|
|
121
|
+
id: string;
|
|
122
|
+
createdAt: Date;
|
|
123
|
+
updatedAt: Date;
|
|
124
|
+
mimeType: string;
|
|
125
|
+
size: number;
|
|
126
|
+
bucket: string | null;
|
|
127
|
+
objectKey: string | null;
|
|
128
|
+
status: import("@prisma/client").$Enums.KnowledgeBaseDocumentStatus;
|
|
129
|
+
knowledgeBaseId: string;
|
|
130
|
+
errorMessage: string | null;
|
|
131
|
+
numChunks: number;
|
|
132
|
+
numPages: number | null;
|
|
133
|
+
}[]>;
|
|
134
|
+
/** Attach a curated KB to one of the user's workspaces. */
|
|
135
|
+
addToWorkspace(userId: string, input: {
|
|
136
|
+
workspaceId: string;
|
|
137
|
+
knowledgeBaseId: string;
|
|
138
|
+
}): Promise<{
|
|
139
|
+
id: string;
|
|
140
|
+
createdAt: Date;
|
|
141
|
+
workspaceId: string;
|
|
142
|
+
knowledgeBaseId: string;
|
|
143
|
+
addedById: string | null;
|
|
144
|
+
}>;
|
|
145
|
+
/** Detach a KB from one of the user's workspaces. */
|
|
146
|
+
removeFromWorkspace(userId: string, input: {
|
|
147
|
+
workspaceId: string;
|
|
148
|
+
knowledgeBaseId: string;
|
|
149
|
+
}): Promise<boolean>;
|
|
150
|
+
query(userId: string, input: QueryInput): Promise<{
|
|
151
|
+
matches: {
|
|
152
|
+
chunkId: string;
|
|
153
|
+
documentId: string;
|
|
154
|
+
documentName: string;
|
|
155
|
+
chunkIndex: number;
|
|
156
|
+
content: string;
|
|
157
|
+
score: number;
|
|
158
|
+
}[];
|
|
159
|
+
answer: string | null;
|
|
160
|
+
}>;
|
|
161
|
+
private queryForKb;
|
|
162
|
+
private processDocumentForKb;
|
|
163
|
+
adminListAll(): Promise<({
|
|
164
|
+
_count: {
|
|
165
|
+
workspaces: number;
|
|
166
|
+
documents: number;
|
|
167
|
+
};
|
|
168
|
+
} & {
|
|
169
|
+
meta: import("@prisma/client/runtime/library").JsonValue | null;
|
|
170
|
+
name: string;
|
|
171
|
+
id: string;
|
|
172
|
+
createdAt: Date;
|
|
173
|
+
updatedAt: Date;
|
|
174
|
+
createdById: string | null;
|
|
175
|
+
description: string | null;
|
|
176
|
+
status: import("@prisma/client").$Enums.KnowledgeBaseStatus;
|
|
177
|
+
isCurated: boolean;
|
|
178
|
+
embeddingModel: string;
|
|
179
|
+
embeddingDim: number;
|
|
180
|
+
})[]>;
|
|
181
|
+
adminGet(id: string): Promise<{
|
|
182
|
+
documents: {
|
|
183
|
+
meta: import("@prisma/client/runtime/library").JsonValue | null;
|
|
184
|
+
name: string;
|
|
185
|
+
id: string;
|
|
186
|
+
createdAt: Date;
|
|
187
|
+
updatedAt: Date;
|
|
188
|
+
mimeType: string;
|
|
189
|
+
size: number;
|
|
190
|
+
bucket: string | null;
|
|
191
|
+
objectKey: string | null;
|
|
192
|
+
status: import("@prisma/client").$Enums.KnowledgeBaseDocumentStatus;
|
|
193
|
+
knowledgeBaseId: string;
|
|
194
|
+
errorMessage: string | null;
|
|
195
|
+
numChunks: number;
|
|
196
|
+
numPages: number | null;
|
|
197
|
+
}[];
|
|
198
|
+
workspaces: ({
|
|
199
|
+
workspace: {
|
|
200
|
+
id: string;
|
|
201
|
+
title: string;
|
|
202
|
+
icon: string;
|
|
203
|
+
};
|
|
204
|
+
} & {
|
|
205
|
+
id: string;
|
|
206
|
+
createdAt: Date;
|
|
207
|
+
workspaceId: string;
|
|
208
|
+
knowledgeBaseId: string;
|
|
209
|
+
addedById: string | null;
|
|
210
|
+
})[];
|
|
211
|
+
meta: import("@prisma/client/runtime/library").JsonValue | null;
|
|
212
|
+
name: string;
|
|
213
|
+
id: string;
|
|
214
|
+
createdAt: Date;
|
|
215
|
+
updatedAt: Date;
|
|
216
|
+
createdById: string | null;
|
|
217
|
+
description: string | null;
|
|
218
|
+
status: import("@prisma/client").$Enums.KnowledgeBaseStatus;
|
|
219
|
+
isCurated: boolean;
|
|
220
|
+
embeddingModel: string;
|
|
221
|
+
embeddingDim: number;
|
|
222
|
+
}>;
|
|
223
|
+
adminListDocuments(knowledgeBaseId: string): Promise<{
|
|
224
|
+
meta: import("@prisma/client/runtime/library").JsonValue | null;
|
|
225
|
+
name: string;
|
|
226
|
+
id: string;
|
|
227
|
+
createdAt: Date;
|
|
228
|
+
updatedAt: Date;
|
|
229
|
+
mimeType: string;
|
|
230
|
+
size: number;
|
|
231
|
+
bucket: string | null;
|
|
232
|
+
objectKey: string | null;
|
|
233
|
+
status: import("@prisma/client").$Enums.KnowledgeBaseDocumentStatus;
|
|
234
|
+
knowledgeBaseId: string;
|
|
235
|
+
errorMessage: string | null;
|
|
236
|
+
numChunks: number;
|
|
237
|
+
numPages: number | null;
|
|
238
|
+
}[]>;
|
|
239
|
+
adminCreate(actorUserId: string, input: AdminCreateInput): Promise<{
|
|
240
|
+
meta: import("@prisma/client/runtime/library").JsonValue | null;
|
|
241
|
+
name: string;
|
|
242
|
+
id: string;
|
|
243
|
+
createdAt: Date;
|
|
244
|
+
updatedAt: Date;
|
|
245
|
+
createdById: string | null;
|
|
246
|
+
description: string | null;
|
|
247
|
+
status: import("@prisma/client").$Enums.KnowledgeBaseStatus;
|
|
248
|
+
isCurated: boolean;
|
|
249
|
+
embeddingModel: string;
|
|
250
|
+
embeddingDim: number;
|
|
251
|
+
}>;
|
|
252
|
+
adminUpdate(input: AdminUpdateInput): Promise<{
|
|
253
|
+
meta: import("@prisma/client/runtime/library").JsonValue | null;
|
|
254
|
+
name: string;
|
|
255
|
+
id: string;
|
|
256
|
+
createdAt: Date;
|
|
257
|
+
updatedAt: Date;
|
|
258
|
+
createdById: string | null;
|
|
259
|
+
description: string | null;
|
|
260
|
+
status: import("@prisma/client").$Enums.KnowledgeBaseStatus;
|
|
261
|
+
isCurated: boolean;
|
|
262
|
+
embeddingModel: string;
|
|
263
|
+
embeddingDim: number;
|
|
264
|
+
}>;
|
|
265
|
+
adminDelete(id: string): Promise<boolean>;
|
|
266
|
+
/** Admin-only: attach a KB to a workspace (curated or not). */
|
|
267
|
+
adminAttachToWorkspace(actorUserId: string, input: {
|
|
268
|
+
workspaceId: string;
|
|
269
|
+
knowledgeBaseId: string;
|
|
270
|
+
}): Promise<{
|
|
271
|
+
id: string;
|
|
272
|
+
createdAt: Date;
|
|
273
|
+
workspaceId: string;
|
|
274
|
+
knowledgeBaseId: string;
|
|
275
|
+
addedById: string | null;
|
|
276
|
+
}>;
|
|
277
|
+
adminDetachFromWorkspace(input: {
|
|
278
|
+
workspaceId: string;
|
|
279
|
+
knowledgeBaseId: string;
|
|
280
|
+
}): Promise<boolean>;
|
|
281
|
+
adminRequestUploadUrl(input: RequestUploadUrlInput): Promise<{
|
|
282
|
+
documentId: string;
|
|
283
|
+
uploadUrl: string;
|
|
284
|
+
bucket: string;
|
|
285
|
+
objectKey: string;
|
|
286
|
+
}>;
|
|
287
|
+
adminProcessDocument(input: ProcessDocumentInput): Promise<{
|
|
288
|
+
meta: import("@prisma/client/runtime/library").JsonValue | null;
|
|
289
|
+
name: string;
|
|
290
|
+
id: string;
|
|
291
|
+
createdAt: Date;
|
|
292
|
+
updatedAt: Date;
|
|
293
|
+
mimeType: string;
|
|
294
|
+
size: number;
|
|
295
|
+
bucket: string | null;
|
|
296
|
+
objectKey: string | null;
|
|
297
|
+
status: import("@prisma/client").$Enums.KnowledgeBaseDocumentStatus;
|
|
298
|
+
knowledgeBaseId: string;
|
|
299
|
+
errorMessage: string | null;
|
|
300
|
+
numChunks: number;
|
|
301
|
+
numPages: number | null;
|
|
302
|
+
} | null>;
|
|
303
|
+
adminDeleteDocument(documentId: string): Promise<boolean>;
|
|
304
|
+
adminQuery(input: QueryInput): Promise<{
|
|
305
|
+
matches: {
|
|
306
|
+
chunkId: string;
|
|
307
|
+
documentId: string;
|
|
308
|
+
documentName: string;
|
|
309
|
+
chunkIndex: number;
|
|
310
|
+
content: string;
|
|
311
|
+
score: number;
|
|
312
|
+
}[];
|
|
313
|
+
answer: string | null;
|
|
314
|
+
}>;
|
|
315
|
+
}
|
|
316
|
+
export {};
|