Skip to content

Commit 07e51ba

Browse files
committed
Wspace resource refs
1 parent 1110db1 commit 07e51ba

5 files changed

Lines changed: 126 additions & 107 deletions

File tree

apps/sim/app/workspace/[workspaceId]/home/components/message-content/components/chat-content/chat-content.tsx

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,15 @@ const MARKDOWN_COMPONENTS = {
169169
e.preventDefault()
170170
const match = href.match(/^#wsres-(\w+)-(.+)$/)
171171
if (match) {
172-
const linkText = e.currentTarget.textContent || match[2]
172+
const type = match[1]
173+
const ref = match[2]
174+
const linkText = e.currentTarget.textContent || ref
173175
window.dispatchEvent(
174176
new CustomEvent('wsres-click', {
175-
detail: { type: match[1], id: match[2], title: linkText },
177+
detail:
178+
type === 'file'
179+
? { type, path: ref, title: linkText }
180+
: { type, id: ref, title: linkText },
176181
})
177182
)
178183
}
@@ -275,8 +280,13 @@ function ChatContentInner({
275280

276281
useEffect(() => {
277282
const handler = (e: Event) => {
278-
const { type, id, title } = (e as CustomEvent).detail
279-
onWorkspaceResourceSelectRef.current?.({ type, id, title: title || id })
283+
const { type, id, path, title } = (e as CustomEvent).detail
284+
onWorkspaceResourceSelectRef.current?.({
285+
type,
286+
id: id ?? '',
287+
path,
288+
title: title || id || path || '',
289+
})
280290
}
281291
window.addEventListener('wsres-click', handler)
282292
return () => window.removeEventListener('wsres-click', handler)
@@ -311,10 +321,14 @@ function ChatContentInner({
311321
const s = parsed.segments[i]
312322
const nextSegment = parsed.segments[i + 1]
313323
if (s.type === 'workspace_resource') {
314-
const label = s.data.title || s.data.id
324+
// Files are addressed by their encoded VFS path (copied verbatim from the tag);
325+
// workflows/tables/KBs by id. The angle-bracket link destination keeps the path
326+
// intact through markdown parsing (tolerates parens) without re-encoding it.
327+
const ref = s.data.type === 'file' ? (s.data.path ?? s.data.id ?? '') : (s.data.id ?? '')
328+
const label = s.data.title || ref
315329
pendingMarkdown = appendInlineReferenceMarkdown(
316330
pendingMarkdown,
317-
`[${label}](#wsres-${s.data.type}-${s.data.id})`,
331+
`[${label}](<#wsres-${s.data.type}-${ref}>)`,
318332
nextSegment
319333
)
320334
} else if (s.type === 'text' || s.type === 'thinking') {

apps/sim/app/workspace/[workspaceId]/home/components/message-content/components/special-tags/special-tags.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ import {
99
ExpandableContent,
1010
SecretReveal,
1111
} from '@/components/emcn'
12+
import { canonicalWorkspaceFilePath } from '@/lib/copilot/vfs/path-utils'
1213
import { cn } from '@/lib/core/utils/cn'
1314
import { OAUTH_PROVIDERS } from '@/lib/oauth/oauth'
1415
import { ContextMentionIcon } from '@/app/workspace/[workspaceId]/home/components/context-mention-icon'
15-
import { canonicalWorkspaceFilePath } from '@/lib/copilot/vfs/path-utils'
1616
import type {
1717
ChatMessageContext,
1818
MothershipResource,
@@ -527,7 +527,8 @@ export function WorkspaceResourceDisplay({
527527
data.type === 'file' && data.path
528528
? files.find(
529529
(file) =>
530-
canonicalWorkspaceFilePath({ folderPath: file.folderPath, name: file.name }) === data.path
530+
canonicalWorkspaceFilePath({ folderPath: file.folderPath, name: file.name }) ===
531+
data.path
531532
)
532533
: undefined
533534
const title =

apps/sim/app/workspace/[workspaceId]/home/components/mothership-view/components/resource-content/resource-content.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ import {
1515
} from '@/components/emcn/icons'
1616
import { isApiClientError } from '@/lib/api/client/errors'
1717
import type { FilePreviewSession } from '@/lib/copilot/request/session'
18-
import { canonicalWorkspaceFilePath } from '@/lib/copilot/vfs/path-utils'
1918
import {
2019
cancelRunToolExecution,
2120
markRunToolManuallyStopped,
2221
reportManualRunToolStop,
2322
} from '@/lib/copilot/tools/client/run-tool-execution'
23+
import { canonicalWorkspaceFilePath } from '@/lib/copilot/vfs/path-utils'
2424
import { triggerFileDownload } from '@/lib/uploads/client/download'
2525
import { getFileExtension, getMimeTypeFromExtension } from '@/lib/uploads/utils/file-utils'
2626
import { workflowBorderColor } from '@/lib/workspaces/colors'
@@ -221,7 +221,11 @@ export function ResourceActions({ workspaceId, resource }: ResourceActionsProps)
221221
return <EmbeddedWorkflowActions workspaceId={workspaceId} workflowId={resource.id} />
222222
case 'file':
223223
return (
224-
<EmbeddedFileActions workspaceId={workspaceId} fileId={resource.id} filePath={resource.path} />
224+
<EmbeddedFileActions
225+
workspaceId={workspaceId}
226+
fileId={resource.id}
227+
filePath={resource.path}
228+
/>
225229
)
226230
case 'knowledgebase':
227231
return (

0 commit comments

Comments
 (0)