Skip to content

Commit 851e2f0

Browse files
committed
fix(chat): preserve unresolved file links
1 parent 0ee0b5c commit 851e2f0

2 files changed

Lines changed: 22 additions & 4 deletions

File tree

apps/sim/app/workspace/[workspaceId]/home/components/mothership-chat/copyable-markdown.test.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ describe('toCopyableMarkdown', () => {
113113
'Read <workspace_resource>{"type":"file","path":"files/notes.md","title":"notes.md"}</workspace_resource>.'
114114

115115
expect(serializeCopyableMarkdown(message)).toEqual({
116-
markdown: 'Read notes.md.',
116+
markdown: 'Read [notes.md](sim:file/files/notes.md).',
117117
hasUnresolvedFile: true,
118118
})
119119
})
@@ -126,7 +126,18 @@ describe('toCopyableMarkdown', () => {
126126
const content = prepareCopyableMarkdown(message, [], refreshWorkspaceFiles)
127127
expect(content).not.toBeTypeOf('string')
128128
if (typeof content === 'string') throw new Error('Expected deferred clipboard content')
129-
expect(content.fallback).toBe('Read The Bell at Low Tide.md.')
129+
expect(content.fallback).toBe(
130+
'Read [The Bell at Low Tide.md](sim:file/files/The%20Bell%20at%20Low%20Tide.md).'
131+
)
132+
expect(parseChipLinks(content.fallback)).toEqual([
133+
{
134+
kind: 'file',
135+
id: 'files/The%20Bell%20at%20Low%20Tide.md',
136+
label: 'The Bell at Low Tide.md',
137+
start: 5,
138+
end: 78,
139+
},
140+
])
130141
await expect(content.prepare()).resolves.toBe(
131142
'Read [The Bell at Low Tide.md](sim:file/file_bell).'
132143
)
@@ -157,6 +168,8 @@ describe('toCopyableMarkdown', () => {
157168

158169
const content = getRenderableMessageText(contentBlocks, 'Fallback without the resource.')
159170

160-
expect(toCopyableMarkdown(content, WORKSPACE_FILES)).toBe('Read notes.md for details.')
171+
expect(toCopyableMarkdown(content, WORKSPACE_FILES)).toBe(
172+
'Read [notes.md](sim:file/files/notes.md) for details.'
173+
)
161174
})
162175
})

apps/sim/app/workspace/[workspaceId]/home/components/mothership-chat/copyable-markdown.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,13 @@ function portableWorkspaceResourceMarkdown(
2323
): PortableWorkspaceResourceMarkdown {
2424
const label = workspaceResourceLabel(data)
2525
const resource = resolveWorkspaceResourceRef({ ...data, title: label }, workspaceFiles)
26+
const unresolvedFileRef = data.type === 'file' ? (data.id ?? data.path) : undefined
2627
return {
27-
markdown: resource ? toSimMarkdownLink(resource.type, resource.id, label) : label,
28+
markdown: resource
29+
? toSimMarkdownLink(resource.type, resource.id, label)
30+
: unresolvedFileRef
31+
? toSimMarkdownLink('file', unresolvedFileRef, label)
32+
: label,
2833
hasUnresolvedFile: data.type === 'file' && !resource,
2934
}
3035
}

0 commit comments

Comments
 (0)