Skip to content

Conversation

@gagik
Copy link
Contributor

@gagik gagik commented Aug 14, 2025

  • Refactor to let us get connection context from inside the drawer.
  • Provider-related tests.
  • Adjustment to the drawer height.

Copilot AI review requested due to automatic review settings August 14, 2025 11:08
@gagik gagik requested a review from a team as a code owner August 14, 2025 11:08
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Refactors the compass-assistant component architecture to separate the drawer implementation from the provider, enabling access to connection context from within the drawer component.

Key changes:

  • Split the CompassAssistantDrawer component out from the provider for better flexibility
  • Updated component interfaces to use Chat objects directly instead of message arrays and callbacks
  • Added the drawer component to both desktop and web workspace configurations

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
packages/compass/src/app/components/workspace.tsx Adds CompassAssistantDrawer component to desktop workspace
packages/compass-web/src/entrypoint.tsx Adds CompassAssistantDrawer component to web workspace
packages/compass-assistant/src/index.tsx Updates exports to include the new drawer component
packages/compass-assistant/src/compass-assistant-drawer.tsx New drawer component that wraps AssistantChat in a DrawerSection
packages/compass-assistant/src/assistant-provider.tsx Refactored to provide context instead of rendering drawer directly
packages/compass-assistant/src/assistant-chat.tsx Updated to accept Chat object and handle messaging internally
packages/compass-assistant/src/assistant-chat.spec.tsx Updated tests to work with new Chat-based interface

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.

chat,
isEnabled: enableAIAssistant,
});
assistantContext.current = {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

actually not sure this ref is doing much here

Copy link
Collaborator

@gribnoysup gribnoysup Aug 14, 2025

Choose a reason for hiding this comment

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

Not in the way it's currently defined, yeah. I'd suggest to leave only chat instance in this context to make sure that a stable instance is being passed here and instead of passing isEnabled with it, read it from preferences hook in the CompassAssistantDrawer component (or just using null as a value that indicates that chat is not enabled, I don't think we need to be too strict with differentiating)

Copy link
Contributor Author

@gagik gagik Aug 14, 2025

Choose a reason for hiding this comment

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

my worry with preferences was the drawer ending up rendering before the provider ends up passing context but I guess it'd be top-down so it'd be fine.

@gagik gagik force-pushed the gagik/compass-ai-plugin-refactor branch from b28047a to f65bcf6 Compare August 14, 2025 11:23
<CreateNamespacePlugin></CreateNamespacePlugin>
<DropNamespacePlugin></DropNamespacePlugin>
<RenameCollectionPlugin></RenameCollectionPlugin>
<CompassAssistantDrawer />
Copy link
Contributor Author

@gagik gagik Aug 14, 2025

Choose a reason for hiding this comment

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

I can add Plugin and turn this into an actual plugin if needed. This seemed like the most fitting place

Copy link
Collaborator

Choose a reason for hiding this comment

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

Not really required if we don't have a reason for it be a plugin, so all good here from my perspective

> = ({ chat, children }) => {
const enableAIAssistant = usePreference('enableAIAssistant');

const { messages, sendMessage } = useChat({
Copy link
Contributor Author

@gagik gagik Aug 14, 2025

Choose a reason for hiding this comment

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

the chat.sendMessage is basically the same as the one returned by the hook. The hook basically just subscribes to the chat for re-rendering based on chat so we can just use it as our context object

@gagik gagik marked this pull request as draft August 14, 2025 11:42
@gagik
Copy link
Contributor Author

gagik commented Aug 14, 2025

Going to adjust the structure a bit more to make it cleaner

@gagik gagik marked this pull request as ready for review August 14, 2025 13:27
Comment on lines 35 to 40
const assistantContext = useRef<AssistantContextType>({
chat,
});
assistantContext.current = {
chat,
};
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same issue as before: you're passing .current to provider and it's re-created every render due do this assignment. You can just directly pass chat from props to provider and completely drop this ref logic (chat being "stable" is guaranteed by us creating it once in "activate" method)

@gagik gagik merged commit 969326b into main Aug 15, 2025
56 of 58 checks passed
@gagik gagik deleted the gagik/compass-ai-plugin-refactor branch August 15, 2025 10:25
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