-
Notifications
You must be signed in to change notification settings - Fork 244
feat(compass-assistant): connection error entrypoint COMPASS-9605 #7224
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
Changes from 9 commits
5a9083a
c41f147
0e9cf5c
d49a82a
7cb3315
527077d
9c698ac
c5288cf
3b36765
2398388
0f144ee
3f34053
8575109
a0bb1e1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,12 +2,17 @@ import React, { type PropsWithChildren, useRef } from 'react'; | |
| import { type UIMessage } from './@ai-sdk/react/use-chat'; | ||
| import { Chat } from './@ai-sdk/react/chat-react'; | ||
| import { createContext, useContext } from 'react'; | ||
| import { registerCompassPlugin } from '@mongodb-js/compass-app-registry'; | ||
| import { | ||
| createServiceLocator, | ||
| registerCompassPlugin, | ||
| } from '@mongodb-js/compass-app-registry'; | ||
| import { atlasServiceLocator } from '@mongodb-js/atlas-service/provider'; | ||
| import { DocsProviderTransport } from './docs-provider-transport'; | ||
| import { useDrawerActions } from '@mongodb-js/compass-components'; | ||
| import { buildExplainPlanPrompt } from './prompts'; | ||
| import { buildConnectionErrorPrompt, buildExplainPlanPrompt } from './prompts'; | ||
| import { usePreference } from 'compass-preferences-model/provider'; | ||
| import type { ConnectionInfo } from '@mongodb-js/connection-info'; | ||
| import { redactConnectionString } from 'mongodb-connection-string-url'; | ||
|
|
||
| export const ASSISTANT_DRAWER_ID = 'compass-assistant-drawer'; | ||
|
|
||
|
|
@@ -32,11 +37,19 @@ type AssistantActionsContextType = { | |
| namespace: string; | ||
| explainPlan: string; | ||
| }) => void; | ||
| interpretConnectionError: ({ | ||
| connectionInfo, | ||
| error, | ||
| }: { | ||
| connectionInfo: ConnectionInfo; | ||
| error: Error; | ||
| }) => void; | ||
| clearChat: () => void; | ||
| }; | ||
| export const AssistantActionsContext = | ||
| createContext<AssistantActionsContextType>({ | ||
| interpretExplainPlan: () => {}, | ||
| interpretConnectionError: () => {}, | ||
| clearChat: () => {}, | ||
| }); | ||
|
|
||
|
|
@@ -51,6 +64,24 @@ export function useAssistantActions(): AssistantActionsContextType & { | |
| }; | ||
| } | ||
|
|
||
| export const compassAssistantServiceLocator = createServiceLocator(function () { | ||
| const { isAssistantEnabled, ...actions } = useAssistantActions(); | ||
|
|
||
| const assistantEnabledRef = useRef(isAssistantEnabled); | ||
| assistantEnabledRef.current = isAssistantEnabled; | ||
|
|
||
| return { | ||
| ...actions, | ||
| getIsAssistantEnabled() { | ||
| return assistantEnabledRef.current; | ||
| }, | ||
| }; | ||
| }, 'compassAssistantLocator'); | ||
|
|
||
| export type CompassAssistantService = ReturnType< | ||
| typeof compassAssistantServiceLocator | ||
| >; | ||
|
|
||
| export const AssistantProvider: React.FunctionComponent< | ||
| PropsWithChildren<{ | ||
| chat: Chat<AssistantMessage>; | ||
|
|
@@ -72,6 +103,25 @@ export const AssistantProvider: React.FunctionComponent< | |
| {} | ||
| ); | ||
| }, | ||
| interpretConnectionError: ({ connectionInfo, error }) => { | ||
| openDrawer(ASSISTANT_DRAWER_ID); | ||
|
|
||
| const connectionString = redactConnectionString( | ||
| connectionInfo.connectionOptions.connectionString | ||
| ); | ||
| const connectionError = error.toString(); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we want more than just the error as a string?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems fine to me |
||
|
|
||
| const { prompt } = buildConnectionErrorPrompt({ | ||
| connectionString, | ||
| connectionError, | ||
| }); | ||
| void chat.sendMessage( | ||
| { | ||
| text: prompt, | ||
| }, | ||
| {} | ||
| ); | ||
| }, | ||
| clearChat: () => { | ||
| chat.messages = []; | ||
| }, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,7 @@ | ||
| export { CompassAssistantProvider } from './compass-assistant-provider'; | ||
| export { CompassAssistantDrawer } from './compass-assistant-drawer'; | ||
| export { useAssistantActions } from './compass-assistant-provider'; | ||
| export { | ||
| useAssistantActions, | ||
| compassAssistantServiceLocator, | ||
| } from './compass-assistant-provider'; | ||
| export type { CompassAssistantService } from './compass-assistant-provider'; |
Uh oh!
There was an error while loading. Please reload this page.