Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 3.8k
improvement(chat): show resource-type icons on inline workspace resource links#5669
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
467fbba
improvement(chat): show resource-type icons on inline workspace resou…
waleedlatif1 9b97c16
fix(chat): derive wsres click title from markdown label, not DOM text…
waleedlatif1 0c43b41
fix(chat): keep dashed-underline affordance for unmapped wsres link t…
waleedlatif1 7134521
fix(chat): parse wsres links once, derive file icons from the VFS path
waleedlatif1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
71 changes: 55 additions & 16 deletions
71 ...ce/[workspaceId]/home/components/message-content/components/chat-content/chat-content.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -12,14 +12,16 @@ import 'prismjs/components/prism-css' | ||
| import 'prismjs/components/prism-markup' | ||
| import '@sim/emcn/components/code/code.css' | ||
| import { Checkbox, CopyCodeButton, cn, highlight, languages } from '@sim/emcn' | ||
| import { decodeVfsSegmentSafe } from '@/lib/copilot/vfs/path-utils' | ||
| import { extractTextContent } from '@/lib/core/utils/react-node-text' | ||
| import { ContextMentionIcon } from '@/app/workspace/[workspaceId]/home/components/context-mention-icon' | ||
| import { | ||
| type ContentSegment, | ||
| PendingTagIndicator, | ||
| parseSpecialTags, | ||
| SpecialTags, | ||
| } from '@/app/workspace/[workspaceId]/home/components/message-content/components/special-tags' | ||
| import type { MothershipResource } from '@/app/workspace/[workspaceId]/home/types' | ||
| import type { ChatContextKind, MothershipResource } from '@/app/workspace/[workspaceId]/home/types' | ||
| import { useSmoothText } from '@/hooks/use-smooth-text' | ||
| import { sanitizeChatDisplayContent } from './chat-sanitize' | ||
| @@ -132,6 +134,31 @@ function appendInlineReferenceMarkdown( | ||
| type TdProps = ComponentPropsWithoutRef<'td'> | ||
| type ThProps = ComponentPropsWithoutRef<'th'> | ||
| /** | ||
| * Maps a `#wsres-{type}-{ref}` link's resource type to the chat-context kind | ||
| * whose icon represents it, so inline resource references render the same | ||
| * type icon as the user-input context chips. | ||
| */ | ||
| const WSRES_LINK_KINDS: Record<string, ChatContextKind | undefined> = { | ||
| workflow: 'workflow', | ||
| table: 'table', | ||
| file: 'file', | ||
| } | ||
| /** | ||
| * Label used to pick a file link's extension-aware document icon. The visible | ||
| * link text can be a custom title without an extension, so prefer the file | ||
| * name carried in the link's VFS path (its last extension-bearing segment). | ||
| */ | ||
| function fileIconLabel(ref: string, fallback: string): string { | ||
| const segments = ref.split('/').filter(Boolean) | ||
| for (let i = segments.length - 1; i >= 0; i--) { | ||
| const decoded = decodeVfsSegmentSafe(segments[i]) | ||
| if (decoded.includes('.')) return decoded | ||
| } | ||
| return fallback | ||
| } | ||
| const MARKDOWN_COMPONENTS = { | ||
| table({ children }: { children?: React.ReactNode }) { | ||
| return ( | ||
| @@ -202,28 +229,40 @@ const MARKDOWN_COMPONENTS = { | ||
| }, | ||
| a({ children, href }: { children?: React.ReactNode; href?: string }) { | ||
| if (href?.startsWith('#wsres-')) { | ||
| const match = href.match(/^#wsres-(\w+)-(.+)$/) | ||
| const type = match?.[1] | ||
| const ref = match?.[2] | ||
| const kind = type ? WSRES_LINK_KINDS[type] : undefined | ||
| const label = extractTextContent(children) | ||
| return ( | ||
| <a | ||
| href={href} | ||
| className='text-[var(--text-primary)] underline decoration-dashed underline-offset-4' | ||
| className={cn( | ||
| 'text-[var(--text-primary)]', | ||
| kind | ||
| ? 'not-prose inline-flex items-center gap-[5px] no-underline' | ||
| : 'underline decoration-dashed underline-offset-4' | ||
| )} | ||
| onClick={(e) => { | ||
| e.preventDefault() | ||
| const match = href.match(/^#wsres-(\w+)-(.+)$/) | ||
| if (match) { | ||
| const type = match[1] | ||
| const ref = match[2] | ||
| const linkText = e.currentTarget.textContent || ref | ||
| window.dispatchEvent( | ||
| new CustomEvent('wsres-click', { | ||
| detail: | ||
| type === 'file' | ||
| ? { type, path: ref, title: linkText } | ||
| : { type, id: ref, title: linkText }, | ||
| }) | ||
| ) | ||
| } | ||
| if (!type || !ref) return | ||
| const linkText = label || ref | ||
| window.dispatchEvent( | ||
| new CustomEvent('wsres-click', { | ||
| detail: | ||
| type === 'file' | ||
| ? { type, path: ref, title: linkText } | ||
| : { type, id: ref, title: linkText }, | ||
| }) | ||
| ) | ||
| }} | ||
| > | ||
| {kind && ref && ( | ||
| <ContextMentionIcon | ||
| context={{ kind, label: kind === 'file' ? fileIconLabel(ref, label) : label }} | ||
| className='size-[14px] flex-shrink-0 text-[var(--text-icon)]' | ||
waleedlatif1 marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| /> | ||
| )} | ||
| {children} | ||
| </a> | ||
| ) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.