Skip to content

Commit 8cae894

Browse files
committed
Fix nested folder display names
1 parent ff2e369 commit 8cae894

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

apps/sim/app/workspace/[workspaceId]/home/hooks/use-chat.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,10 @@ function extractResourceFromReadResult(
673673
): MothershipResource | null {
674674
if (!path) return null
675675

676-
const segments = path.split('/')
676+
const segments = path
677+
.split('/')
678+
.map((segment) => segment.trim())
679+
.filter(Boolean)
677680
const resourceType = VFS_DIR_TO_RESOURCE[segments[0]]
678681
if (!resourceType || !segments[1]) return null
679682

@@ -693,8 +696,22 @@ function extractResourceFromReadResult(
693696
}
694697
}
695698

699+
const fallbackTitle =
700+
resourceType === 'workflow'
701+
? resolveLeafWorkflowPathSegment(segments)
702+
: segments[1] || segments[segments.length - 1]
703+
696704
if (!id) return null
697-
return { type: resourceType, id, title: name || segments[1] }
705+
return { type: resourceType, id, title: name || fallbackTitle || id }
706+
}
707+
708+
function resolveLeafWorkflowPathSegment(segments: string[]): string | undefined {
709+
const lastSegment = segments[segments.length - 1]
710+
if (!lastSegment) return undefined
711+
if (/\.[^/.]+$/.test(lastSegment) && segments.length > 1) {
712+
return segments[segments.length - 2]
713+
}
714+
return lastSegment
698715
}
699716

700717
export interface UseChatOptions {

apps/sim/lib/copilot/tools/client/store-utils.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ describe('resolveToolDisplay', () => {
2929
path: 'workflows/My Workflow/meta.json',
3030
})?.text
3131
).toBe('Read My Workflow')
32+
33+
expect(
34+
resolveToolDisplay(ReadTool.id, ClientToolCallState.success, {
35+
path: 'workflows/Folder 1/RET XYZ/state.json',
36+
})?.text
37+
).toBe('Read RET XYZ')
3238
})
3339

3440
it('falls back to a humanized tool label for generic tools', () => {

apps/sim/lib/copilot/tools/client/store-utils.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,26 @@ function describeReadTarget(path: string | undefined): string | undefined {
9898
return segments.slice(1).join('/') || segments[segments.length - 1]
9999
}
100100

101+
if (resourceType === 'workflow') {
102+
return stripExtension(getLeafResourceSegment(segments))
103+
}
104+
101105
const resourceName = segments[1] || segments[segments.length - 1]
102106
return stripExtension(resourceName)
103107
}
104108

109+
function getLeafResourceSegment(segments: string[]): string {
110+
const lastSegment = segments[segments.length - 1] || ''
111+
if (hasFileExtension(lastSegment) && segments.length > 1) {
112+
return segments[segments.length - 2] || lastSegment
113+
}
114+
return lastSegment
115+
}
116+
117+
function hasFileExtension(value: string): boolean {
118+
return /\.[^/.]+$/.test(value)
119+
}
120+
105121
function stripExtension(value: string): string {
106122
return value.replace(/\.[^/.]+$/, '')
107123
}

0 commit comments

Comments
 (0)