MCPcopy Index your code
hub / github.com/simstudioai/sim / resolveKnowledgeBase

Function resolveKnowledgeBase

apps/sim/app/api/v1/knowledge/utils.ts:14–32  ·  view source on GitHub ↗
(
  id: string,
  workspaceId: string,
  userId: string,
  rateLimit: RateLimitResult,
  level: 'read' | 'write' = 'read'
)

Source from the content-addressed store, hash-verified

12 * and the user has permission. Returns the KB or a NextResponse error.
13 */
14export 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.

Callers 3

route.tsFile · 0.90
route.tsFile · 0.90
route.tsFile · 0.90

Calls 2

validateWorkspaceAccessFunction · 0.90
getKnowledgeBaseByIdFunction · 0.90

Tested by

no test coverage detected