Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions apps/sim/app/workspace/[workspaceId]/home/hooks/use-chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,10 @@ function extractResourceFromReadResult(
): MothershipResource | null {
if (!path) return null

const segments = path.split('/')
const segments = path
.split('/')
.map((segment) => segment.trim())
.filter(Boolean)
const resourceType = VFS_DIR_TO_RESOURCE[segments[0]]
if (!resourceType || !segments[1]) return null

Expand All @@ -693,8 +696,22 @@ function extractResourceFromReadResult(
}
}

const fallbackTitle =
resourceType === 'workflow'
? resolveLeafWorkflowPathSegment(segments)
: segments[1] || segments[segments.length - 1]

if (!id) return null
return { type: resourceType, id, title: name || segments[1] }
return { type: resourceType, id, title: name || fallbackTitle || id }
}

function resolveLeafWorkflowPathSegment(segments: string[]): string | undefined {
const lastSegment = segments[segments.length - 1]
if (!lastSegment) return undefined
if (/\.[^/.]+$/.test(lastSegment) && segments.length > 1) {
return segments[segments.length - 2]
}
return lastSegment
}

export interface UseChatOptions {
Expand Down
6 changes: 6 additions & 0 deletions apps/sim/lib/copilot/tools/client/store-utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ describe('resolveToolDisplay', () => {
path: 'workflows/My Workflow/meta.json',
})?.text
).toBe('Read My Workflow')

expect(
resolveToolDisplay(ReadTool.id, ClientToolCallState.success, {
path: 'workflows/Folder 1/RET XYZ/state.json',
})?.text
).toBe('Read RET XYZ')
})

it('falls back to a humanized tool label for generic tools', () => {
Expand Down
16 changes: 16 additions & 0 deletions apps/sim/lib/copilot/tools/client/store-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,26 @@ function describeReadTarget(path: string | undefined): string | undefined {
return segments.slice(1).join('/') || segments[segments.length - 1]
}

if (resourceType === 'workflow') {
return stripExtension(getLeafResourceSegment(segments))
}

const resourceName = segments[1] || segments[segments.length - 1]
return stripExtension(resourceName)
}

function getLeafResourceSegment(segments: string[]): string {
const lastSegment = segments[segments.length - 1] || ''
if (hasFileExtension(lastSegment) && segments.length > 1) {
return segments[segments.length - 2] || lastSegment
}
return lastSegment
}

function hasFileExtension(value: string): boolean {
return /\.[^/.]+$/.test(value)
}

function stripExtension(value: string): string {
return value.replace(/\.[^/.]+$/, '')
}
Expand Down
Loading