Skip to content

Commit 4fc9f43

Browse files
committed
chore: add feature flag and fix lint
1 parent d92a559 commit 4fc9f43

File tree

6 files changed

+43
-10
lines changed

6 files changed

+43
-10
lines changed

package-lock.json

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/compass-assistant/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@
5151
"dependencies": {
5252
"@ai-sdk/openai": "^2.0.4",
5353
"@mongodb-js/compass-components": "^1.30.5",
54+
"@mongodb-js/compass-logging": "^1.7.10",
5455
"ai": "^5.0.5",
56+
"compass-preferences-model": "^2.49.0",
5557
"react": "^17.0.2",
5658
"react-dom": "^17.0.2",
5759
"throttleit": "^2.1.0",

packages/compass-assistant/src/assistant-chat.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ interface AsisstantChatProps {
66
onSendMessage?: (message: string) => void;
77
}
88

9+
/**
10+
* This component is currently using placeholders as Leafygreen UI updates are not available yet.
11+
* Before release, we will replace this with the actual Leafygreen chat components.
12+
*/
913
export const AsisstantChat: React.FunctionComponent<AsisstantChatProps> = ({
1014
messages,
1115
onSendMessage,

packages/compass-assistant/src/assistant-provider.tsx

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import React, { type PropsWithChildren, useCallback, useRef } from 'react';
33
import { type UIMessage, useChat } from './@ai-sdk/react/use-chat';
44
import type { Chat } from './@ai-sdk/react/chat.react';
55
import { AsisstantChat } from './assistant-chat';
6+
import { usePreference } from 'compass-preferences-model/provider';
67

78
export const ASSISTANT_DRAWER_ID = 'compass-assistant-drawer';
89

@@ -22,6 +23,8 @@ export const AssistantProvider: React.FunctionComponent<
2223
chat?: Chat<UIMessage>;
2324
}>
2425
> = ({ chat, children }) => {
26+
const enableAIAssistant = usePreference('enableAIAssistant');
27+
2528
const { messages, sendMessage } = useChat({
2629
transport: docsProviderTransport,
2730
chat,
@@ -37,16 +40,25 @@ export const AssistantProvider: React.FunctionComponent<
3740
[sendMessage]
3841
);
3942

43+
if (!enableAIAssistant) {
44+
return <>{children}</>;
45+
}
46+
4047
return (
4148
<AssistantActionsContext.Provider value={contextActions.current}>
42-
<DrawerSection
43-
id={ASSISTANT_DRAWER_ID}
44-
title="MongoDB Assistant"
45-
label="MongoDB Assistant"
46-
glyph="Sparkle"
47-
>
48-
<AsisstantChat messages={messages} onSendMessage={handleMessageSend} />
49-
</DrawerSection>
49+
{enableAIAssistant && (
50+
<DrawerSection
51+
id={ASSISTANT_DRAWER_ID}
52+
title="MongoDB Assistant"
53+
label="MongoDB Assistant"
54+
glyph="Sparkle"
55+
>
56+
<AsisstantChat
57+
messages={messages}
58+
onSendMessage={handleMessageSend}
59+
/>
60+
</DrawerSection>
61+
)}
5062
{children}
5163
</AssistantActionsContext.Provider>
5264
);

packages/compass-assistant/src/index.spec.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import { render } from '@mongodb-js/testing-library-compass';
33
import { CompassAssistantProvider } from './index';
44

55
describe('Compass Assistant', function () {
6-
const Plugin = CompassAssistantProvider.withMockServices({});
6+
const CompassAssistant = CompassAssistantProvider.withMockServices({});
77

88
it('renders a Plugin', function () {
9-
render(<Plugin></Plugin>);
9+
render(<CompassAssistant></CompassAssistant>);
1010
});
1111
});

packages/compass-preferences-model/src/feature-flags.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export type FeatureFlags = {
2828
showIndexesGuidanceVariant: boolean;
2929
enableContextMenus: boolean;
3030
enableSearchActivationProgramP1: boolean;
31+
enableAIAssistant: boolean;
3132
};
3233

3334
export const featureFlags: Required<{
@@ -159,4 +160,14 @@ export const featureFlags: Required<{
159160
short: 'Enable interface to view and modify search indexes',
160161
},
161162
},
163+
164+
/**
165+
* Feature flag for AI Assistant.
166+
*/
167+
enableAIAssistant: {
168+
stage: 'development',
169+
description: {
170+
short: 'Enable AI Assistant',
171+
},
172+
},
162173
};

0 commit comments

Comments
 (0)