MCPcopy
hub / github.com/simstudioai/sim / processKnowledgeFromDb

Function processKnowledgeFromDb

apps/sim/lib/copilot/chat/process-contents.ts:447–489  ·  view source on GitHub ↗
(
  knowledgeBaseId: string,
  userId: string | undefined,
  tag: string,
  currentWorkspaceId?: string
)

Source from the content-addressed store, hash-verified

445}
446
447async function processKnowledgeFromDb(
448 knowledgeBaseId: string,
449 userId: string | undefined,
450 tag: string,
451 currentWorkspaceId?: string
452): Promise<AgentContext | null> {
453 try {
454 if (userId) {
455 const accessCheck = await checkKnowledgeBaseAccess(knowledgeBaseId, userId)
456 if (!accessCheck.hasAccess) {
457 return null
458 }
459 if (currentWorkspaceId && accessCheck.knowledgeBase?.workspaceId !== currentWorkspaceId) {
460 return null
461 }
462 }
463
464 const conditions = [eq(knowledgeBase.id, knowledgeBaseId), isNull(knowledgeBase.deletedAt)]
465 if (currentWorkspaceId) {
466 conditions.push(eq(knowledgeBase.workspaceId, currentWorkspaceId))
467 }
468 const kbRows = await dbReplica
469 .select({
470 id: knowledgeBase.id,
471 name: knowledgeBase.name,
472 })
473 .from(knowledgeBase)
474 .where(and(...conditions))
475 .limit(1)
476 const kb = kbRows?.[0]
477 if (!kb) return null
478
479 return {
480 type: 'knowledge',
481 tag,
482 content: '',
483 path: `${canonicalKnowledgeBaseVfsDir(kb.name)}/meta.json`,
484 }
485 } catch (error) {
486 logger.error('Error processing knowledge context (db)', { knowledgeBaseId, error })
487 return null
488 }
489}
490
491async function processBlockMetadata(
492 blockId: string,

Callers 2

processContextsServerFunction · 0.85

Calls 5

checkKnowledgeBaseAccessFunction · 0.90
errorMethod · 0.80
eqFunction · 0.50
pushMethod · 0.45

Tested by

no test coverage detected