mirror of
https://github.com/simstudioai/sim.git
synced 2026-09-24 15:45:35 +08:00
fix(mothership): tool path for nested folders (#4158)
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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', () => {
|
||||
|
||||
@@ -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(/\.[^/.]+$/, '')
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user