Skip to content

Commit 2156f49

Browse files
committed
Folder vfs
1 parent 5b94db6 commit 2156f49

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

apps/sim/lib/copilot/chat/workspace-context.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
userTableDefinitions,
77
userTableRows,
88
workflow,
9+
workflowFolder,
910
workflowSchedule,
1011
} from '@sim/db/schema'
1112
import { createLogger } from '@sim/logger'
@@ -237,6 +238,7 @@ export async function generateWorkspaceContext(
237238
const [
238239
members,
239240
workflows,
241+
folderRows,
240242
kbs,
241243
tables,
242244
files,
@@ -255,10 +257,20 @@ export async function generateWorkspaceContext(
255257
description: workflow.description,
256258
isDeployed: workflow.isDeployed,
257259
lastRunAt: workflow.lastRunAt,
260+
folderId: workflow.folderId,
258261
})
259262
.from(workflow)
260263
.where(and(eq(workflow.workspaceId, workspaceId), isNull(workflow.archivedAt))),
261264

265+
db
266+
.select({
267+
id: workflowFolder.id,
268+
name: workflowFolder.name,
269+
parentId: workflowFolder.parentId,
270+
})
271+
.from(workflowFolder)
272+
.where(and(eq(workflowFolder.workspaceId, workspaceId), isNull(workflowFolder.archivedAt))),
273+
262274
db
263275
.select({
264276
id: knowledgeBase.id,
@@ -359,10 +371,26 @@ export async function generateWorkspaceContext(
359371
connectorTypesByKb.set(row.knowledgeBaseId, types)
360372
}
361373

374+
const folderPathMap = new Map<string, string>()
375+
const folderById = new Map(folderRows.map((f) => [f.id, f]))
376+
function resolveFolderPath(id: string): string {
377+
const cached = folderPathMap.get(id)
378+
if (cached !== undefined) return cached
379+
const folder = folderById.get(id)
380+
if (!folder) return id
381+
const parentPath = folder.parentId ? resolveFolderPath(folder.parentId) : ''
382+
const path = parentPath ? `${parentPath}/${folder.name}` : folder.name
383+
folderPathMap.set(id, path)
384+
return path
385+
}
386+
362387
return buildWorkspaceMd({
363388
workspace: wsRow,
364389
members,
365-
workflows,
390+
workflows: workflows.map((wf) => ({
391+
...wf,
392+
folderPath: wf.folderId ? resolveFolderPath(wf.folderId) : null,
393+
})),
366394
knowledgeBases: kbs.map((kb) => ({
367395
...kb,
368396
connectorTypes: connectorTypesByKb.get(kb.id),

0 commit comments

Comments
 (0)