fix(kb): workspace id required for creation

This commit is contained in:
Vikhyath Mondreti
2026-01-25 14:40:25 -08:00
parent d83c418111
commit 974f3b9eff
5 changed files with 15 additions and 10 deletions

View File

@@ -19,7 +19,7 @@ const logger = createLogger('KnowledgeBaseAPI')
const CreateKnowledgeBaseSchema = z.object({
name: z.string().min(1, 'Name is required'),
description: z.string().optional(),
workspaceId: z.string().optional(),
workspaceId: z.string().min(1, 'Workspace ID is required'),
embeddingModel: z.literal('text-embedding-3-small').default('text-embedding-3-small'),
embeddingDimension: z.literal(1536).default(1536),
chunkingConfig: z

View File

@@ -37,6 +37,13 @@ export const knowledgeBaseServerTool: BaseServerTool<KnowledgeBaseArgs, Knowledg
}
}
if (!args.workspaceId) {
return {
success: false,
message: 'Workspace ID is required for creating a knowledge base',
}
}
const requestId = crypto.randomUUID().slice(0, 8)
const newKnowledgeBase = await createKnowledgeBase(
{

View File

@@ -79,7 +79,7 @@ export const KnowledgeBaseArgsSchema = z.object({
name: z.string().optional(),
/** Description of the knowledge base (optional for create) */
description: z.string().optional(),
/** Workspace ID to associate with (optional for create/list) */
/** Workspace ID to associate with (required for create, optional for list) */
workspaceId: z.string().optional(),
/** Knowledge base ID (required for get, query) */
knowledgeBaseId: z.string().optional(),

View File

@@ -86,18 +86,16 @@ export async function createKnowledgeBase(
const kbId = randomUUID()
const now = new Date()
if (data.workspaceId) {
const hasPermission = await getUserEntityPermissions(data.userId, 'workspace', data.workspaceId)
if (hasPermission === null) {
throw new Error('User does not have permission to create knowledge bases in this workspace')
}
const hasPermission = await getUserEntityPermissions(data.userId, 'workspace', data.workspaceId)
if (hasPermission === null) {
throw new Error('User does not have permission to create knowledge bases in this workspace')
}
const newKnowledgeBase = {
id: kbId,
name: data.name,
description: data.description ?? null,
workspaceId: data.workspaceId ?? null,
workspaceId: data.workspaceId,
userId: data.userId,
tokenCount: 0,
embeddingModel: data.embeddingModel,
@@ -122,7 +120,7 @@ export async function createKnowledgeBase(
chunkingConfig: data.chunkingConfig,
createdAt: now,
updatedAt: now,
workspaceId: data.workspaceId ?? null,
workspaceId: data.workspaceId,
docCount: 0,
}
}

View File

@@ -32,7 +32,7 @@ export interface KnowledgeBaseWithCounts {
export interface CreateKnowledgeBaseData {
name: string
description?: string
workspaceId?: string
workspaceId: string
embeddingModel: 'text-embedding-3-small'
embeddingDimension: 1536
chunkingConfig: ChunkingConfig