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

Function hasActiveKbDocumentForKey

apps/sim/app/api/files/authorization.ts:477–495  ·  view source on GitHub ↗

* Whether an active KB document (non-archived/excluded/deleted, in a * non-deleted KB) in the owning workspace references exactly `cloudKey`, matched * on the document's persisted canonical `storageKey`. This is an exact, indexed * lookup — no URL parsing or wildcard matching at read time. It is

(cloudKey: string, workspaceId: string)

Source from the content-addressed store, hash-verified

475 * owns it (ownership comes from the binding).
476 */
477async function hasActiveKbDocumentForKey(cloudKey: string, workspaceId: string): Promise<boolean> {
478 const rows = await db
479 .select({ id: document.id })
480 .from(document)
481 .innerJoin(knowledgeBase, eq(document.knowledgeBaseId, knowledgeBase.id))
482 .where(
483 and(
484 eq(knowledgeBase.workspaceId, workspaceId),
485 eq(document.storageKey, cloudKey),
486 eq(document.userExcluded, false),
487 isNull(document.archivedAt),
488 isNull(document.deletedAt),
489 isNull(knowledgeBase.deletedAt)
490 )
491 )
492 .limit(1)
493
494 return rows.length > 0
495}
496
497/**
498 * Verify access to KB files (`kb/<key>`).

Callers 1

verifyKBFileAccessFunction · 0.85

Calls 1

eqFunction · 0.50

Tested by

no test coverage detected