Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,10 @@ const TestComponent: React.FunctionComponent<{
};

describe('useAssistantActions', function () {
const createWrapper = (chat: Chat<AssistantMessage>) => {
const createWrapper = (
chat: Chat<AssistantMessage>,
appNameForPrompt = 'MongoDB Compass'
) => {
function TestWrapper({ children }: { children: React.ReactNode }) {
const MockedProvider = createMockProvider();

Expand All @@ -156,7 +159,7 @@ describe('useAssistantActions', function () {
{/* eslint-disable-next-line react-hooks/static-components */}
<MockedProvider
originForPrompt="mongodb-compass"
appNameForPrompt="MongoDB Compass"
appNameForPrompt={appNameForPrompt}
chat={chat}
>
{children}
Expand Down Expand Up @@ -230,6 +233,26 @@ describe('useAssistantActions', function () {
expect(result.current.interpretConnectionError).to.be.a('function');
expect(result.current.tellMoreAboutInsight).to.be.a('function');
});

it('does not include interpretConnectionError when using Data Explorer', function () {
const { result } = renderHook(() => useAssistantActions(), {
wrapper: createWrapper(
createMockChat({ messages: [] }),
'MongoDB Atlas Data Explorer'
),
preferences: {
enableAIAssistant: true,
enableGenAIFeatures: true,
enableGenAIFeaturesAtlasOrg: true,
cloudFeatureRolloutAccess: { GEN_AI_COMPASS: true },
enableToolCalling: true,
},
});

expect(result.current.interpretExplainPlan).to.be.a('function');
expect(result.current.interpretConnectionError).to.be.undefined;
expect(result.current.tellMoreAboutInsight).to.be.a('function');
});
});

describe('CompassAssistantProvider', function () {
Expand Down
32 changes: 22 additions & 10 deletions packages/compass-assistant/src/compass-assistant-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
useInitialValue,
} from '@mongodb-js/compass-components';
import {
APP_NAMES_FOR_PROMPT,
buildConnectionErrorPrompt,
buildContextPrompt,
buildExplainPlanPrompt,
Expand Down Expand Up @@ -172,18 +173,18 @@ export const compassAssistantServiceLocator = createServiceLocator(() => {
getIsAssistantEnabledRef.current = actions.getIsAssistantEnabled;

return {
interpretConnectionError: (options: {
connectionInfo: ConnectionInfo;
error: Error;
}) => interpretConnectionErrorRef.current?.(options),
interpretConnectionError: interpretConnectionErrorRef.current
? (options: { connectionInfo: ConnectionInfo; error: Error }) =>
interpretConnectionErrorRef.current?.(options)
: undefined,
getIsAssistantEnabled: () => {
return getIsAssistantEnabledRef.current();
},
};
}, 'compassAssistantLocator');

export type CompassAssistantService = {
interpretConnectionError: (options: {
interpretConnectionError?: (options: {
connectionInfo: ConnectionInfo;
error: Error;
}) => void;
Expand All @@ -208,7 +209,14 @@ export const AssistantProvider: React.FunctionComponent<
toolsController: ToolsController;
preferences: PreferencesAccess;
}>
> = ({ chat, atlasAiService, toolsController, preferences, children }) => {
> = ({
appNameForPrompt,
chat,
atlasAiService,
toolsController,
preferences,
children,
}) => {
const { openDrawer } = useDrawerActions();
const track = useTelemetry();

Expand Down Expand Up @@ -337,10 +345,14 @@ export const AssistantProvider: React.FunctionComponent<
'explain plan',
buildExplainPlanPrompt
),
interpretConnectionError: createEntryPointHandler(
'connection error',
buildConnectionErrorPrompt
),
// interpretConnectionError is not available in Data Explorer
interpretConnectionError:
appNameForPrompt === APP_NAMES_FOR_PROMPT.DataExplorer
? undefined
: createEntryPointHandler(
Comment on lines +348 to +352
Copy link

Copilot AI Jan 13, 2026

Choose a reason for hiding this comment

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

The comment states 'Data Explorer' but the code checks against APP_NAMES_FOR_PROMPT.DataExplorer. Consider updating the comment to reference the constant for consistency and to make it clear which exact value is being checked.

Copilot uses AI. Check for mistakes.
'connection error',
buildConnectionErrorPrompt
),
tellMoreAboutInsight: createEntryPointHandler(
'performance insights',
buildProactiveInsightsPrompt
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1284,9 +1284,11 @@ const connectionAttemptError = (
}
: undefined,
onDebugClick:
compassAssistant.getIsAssistantEnabled() && connectionInfo
compassAssistant.getIsAssistantEnabled() &&
compassAssistant.interpretConnectionError &&
connectionInfo
? () => {
compassAssistant.interpretConnectionError({
compassAssistant.interpretConnectionError?.({
Copy link

Copilot AI Jan 13, 2026

Choose a reason for hiding this comment

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

This optional chaining is redundant since the condition on lines 1287-1289 already checks for interpretConnectionError existence. The function call is guaranteed to be defined at this point, so the ?. operator is unnecessary.

Suggested change
compassAssistant.interpretConnectionError?.({
compassAssistant.interpretConnectionError({

Copilot uses AI. Check for mistakes.
connectionInfo,
error: err,
});
Expand Down
5 changes: 5 additions & 0 deletions packages/compass-e2e-tests/tests/assistant.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
screenshotIfFailed,
DEFAULT_CONNECTION_NAME_1,
screenshotPathName,
skipForWeb,
} from '../helpers/compass';
import type { Compass } from '../helpers/compass';
import * as Selectors from '../helpers/selectors';
Expand Down Expand Up @@ -242,6 +243,8 @@ describe('MongoDB Assistant', function () {

describe('entry points', function () {
it('should display opt-in modal for connection error entry point', async function () {
skipForWeb(this, 'connection errors not meant to be shown in DE');

await browser.connectWithConnectionString(
'mongodb-invalid://localhost:27017',
{ connectionStatus: 'failure' }
Expand Down Expand Up @@ -509,6 +512,8 @@ describe('MongoDB Assistant', function () {
});

it('opens assistant with error message view prompt when clicking "Debug"', async function () {
skipForWeb(this, 'connection errors not meant to be shown in DE');

await browser.connectWithConnectionString(
'mongodb-invalid://localhost:27017',
{ connectionStatus: 'failure' }
Expand Down
Loading