( id: string, workspaceId: string, userId: string, rateLimit: RateLimitResult, level: 'read' | 'write' = 'read' )
| 12 | * and the user has permission. Returns the KB or a NextResponse error. |
| 13 | */ |
| 14 | export async function resolveKnowledgeBase( |
| 15 | id: string, |
| 16 | workspaceId: string, |
| 17 | userId: string, |
| 18 | rateLimit: RateLimitResult, |
| 19 | level: 'read' | 'write' = 'read' |
| 20 | ): Promise<{ kb: KnowledgeBaseWithCounts } | NextResponse> { |
| 21 | const accessError = await validateWorkspaceAccess(rateLimit, userId, workspaceId, level) |
| 22 | if (accessError) return accessError |
| 23 | |
| 24 | const kb = await getKnowledgeBaseById(id) |
| 25 | if (!kb) { |
| 26 | return NextResponse.json({ error: 'Knowledge base not found' }, { status: 404 }) |
| 27 | } |
| 28 | if (kb.workspaceId !== workspaceId) { |
| 29 | return NextResponse.json({ error: 'Knowledge base not found' }, { status: 404 }) |
| 30 | } |
| 31 | return { kb } |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * Serializes a date value for JSON responses. |
no test coverage detected