(
knowledgeBaseId: string,
updates: {
name?: string
description?: string
workspaceId?: string | null
chunkingConfig?: {
maxSize: number
minSize: number
overlap: number
}
},
requestId: string,
options?: { actorUserId?: string }
)
| 228 | * Update a knowledge base |
| 229 | */ |
| 230 | export async function updateKnowledgeBase( |
| 231 | knowledgeBaseId: string, |
| 232 | updates: { |
| 233 | name?: string |
| 234 | description?: string |
| 235 | workspaceId?: string | null |
| 236 | chunkingConfig?: { |
| 237 | maxSize: number |
| 238 | minSize: number |
| 239 | overlap: number |
| 240 | } |
| 241 | }, |
| 242 | requestId: string, |
| 243 | options?: { actorUserId?: string } |
| 244 | ): Promise<KnowledgeBaseWithCounts> { |
| 245 | const now = new Date() |
| 246 | const updateData: { |
| 247 | updatedAt: Date |
| 248 | name?: string |
| 249 | description?: string | null |
| 250 | workspaceId?: string | null |
| 251 | chunkingConfig?: { |
| 252 | maxSize: number |
| 253 | minSize: number |
| 254 | overlap: number |
| 255 | } |
| 256 | embeddingModel?: string |
| 257 | embeddingDimension?: number |
| 258 | } = { |
| 259 | updatedAt: now, |
| 260 | } |
| 261 | |
| 262 | if (updates.name !== undefined) updateData.name = updates.name |
| 263 | if (updates.description !== undefined) updateData.description = updates.description |
| 264 | if (updates.workspaceId !== undefined) updateData.workspaceId = updates.workspaceId |
| 265 | if (updates.chunkingConfig !== undefined) { |
| 266 | updateData.chunkingConfig = updates.chunkingConfig |
| 267 | } |
| 268 | |
| 269 | if (updates.workspaceId !== undefined && !options?.actorUserId) { |
| 270 | throw new KnowledgeBasePermissionError( |
| 271 | 'actorUserId is required to change a knowledge base workspace' |
| 272 | ) |
| 273 | } |
| 274 | |
| 275 | // Resolved before the transaction: the target workspace comes from the |
| 276 | // request input, so checking it inside the FOR UPDATE tx would only issue a |
| 277 | // second pooled-connection checkout while the first is held. |
| 278 | const targetWorkspacePermission = updates.workspaceId |
| 279 | ? await getUserEntityPermissions( |
| 280 | options?.actorUserId as string, |
| 281 | 'workspace', |
| 282 | updates.workspaceId |
| 283 | ) |
| 284 | : null |
| 285 | |
| 286 | try { |
| 287 | await db.transaction(async (tx) => { |
no test coverage detected