mirror of
https://github.com/simstudioai/sim.git
synced 2026-01-26 15:28:03 -05:00
fix(kb): workspace id required for creation
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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(
|
||||
{
|
||||
|
||||
@@ -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(),
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user