Skip to content

Conversation

@cte
Copy link
Collaborator

@cte cte commented Feb 15, 2025

Description

Composable + reusable chat interface using @shadcn/ui and Tailwind, with Markdown support + VSCode theme syntax highlighting. Based on https://github.com/run-llama/chat-ui.

Screenshot 2025-02-15 at 2 10 09 AM Screenshot 2025-02-15 at 2 25 28 AM

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Checklist:

  • My code follows the patterns of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation

Additional context

Related Issues

Reviewers


Important

Introduces a new chat UI component with markdown support and syntax highlighting, including various chat-related components, providers, hooks, and Storybook integration.

  • New Feature:
    • Adds a composable and reusable chat interface in webview-ui/src/components/ui/chat/Chat.tsx.
    • Supports markdown rendering with syntax highlighting using react-markdown, remark-gfm, and shiki.
    • Includes components for chat input, messages, and message actions.
  • Components:
    • ChatInput.tsx: Handles user input with autosizing textarea and submit button.
    • ChatMessage.tsx: Displays individual chat messages with optional badges and copy-to-clipboard functionality.
    • ChatMessages.tsx: Manages the list of chat messages with smooth scrolling.
  • Providers and Hooks:
    • ChatProvider.ts: Context provider for chat state management.
    • useChatUI.ts, useChatInput.ts, useChatMessage.ts: Custom hooks for accessing chat context.
  • Markdown Support:
    • Markdown.tsx: Renders markdown content with custom components for blockquotes and code blocks.
    • CodeBlock.tsx: Highlights code using shiki and provides copy functionality.
  • Dependencies:
    • Adds react-markdown, remark-gfm, and shiki to package.json for markdown and syntax highlighting.
  • Styling:
    • Updates index.css for custom markdown styles and VSCode theme integration.
  • Storybook:
    • Adds Chat.stories.tsx for Storybook integration to demonstrate the chat component.

This description was created by Ellipsis for 81565ec. It will automatically update as commits are pushed.

@changeset-bot
Copy link

changeset-bot bot commented Feb 15, 2025

⚠️ No Changeset found

Latest commit: 81565ec

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

timeout?: number
}

export function useClipboard({ timeout = 2000 }: UseClipboardProps = {}) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have a similar hook that I'll deprecate in favor of this.

timeout?: number
}

export function useClipboard({ timeout = 2000 }: UseClipboardProps = {}) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This hook duplicates existing functionality. Consider using the existing useCopyToClipboard hook instead.

const { input, setInput, append, isLoading } = useChatUI()
const isDisabled = isLoading || !input.trim()

const submit = async () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding try/catch error handling for the async 'submit' function to manage possible rejections from append. This ensures errors are handled gracefully.

return
}

navigator.clipboard.writeText(value).then(() => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider handling errors in the navigator.clipboard.writeText promise. Adding a catch block can help ensure clipboard failures are gracefully managed.

*/

.custom-markdown > pre {
background-color: transparent !important;
Copy link
Collaborator Author

@cte cte Feb 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VSCode webviews automatically add a background color to all pre tags, but we don't want this when rendering code snippets without our Markdown component.

},
define: {
"process.platform": JSON.stringify(process.platform),
"process.env.VSCODE_TEXTMATE_DEBUG": JSON.stringify(process.env.VSCODE_TEXTMATE_DEBUG),
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shiki (https://github.com/shikijs/shiki) uses this ENV var for debugging, so we need pass it through or it complains.

Base automatically changed from cte/additional-shadcn-components to main February 15, 2025 16:36
@cte cte merged commit 567130b into main Feb 16, 2025
6 checks passed
@cte cte deleted the cte/chat-ui branch February 16, 2025 18:56
refactorthis pushed a commit to refactorthis/Roo-Code that referenced this pull request Mar 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants