You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Compass Assistant package provides a modular architecture for integrating AI-powered assistance into MongoDB Compass. The components are designed to be flexible and composable, allowing the assistant functionality to be placed at different levels in the component tree.
6
+
7
+
## Architecture
8
+
9
+
### Components
10
+
11
+
1.**AssistantProvider** - Context provider that manages chat state and provides assistant functionality
12
+
2.**AssistantChat** - Chat interface component that consumes the assistant context
13
+
3.**AssistantDrawer** - Pre-configured drawer section that wraps AssistantChat
14
+
4.**useAssistant** - Hook for consuming assistant context in components
15
+
16
+
### Usage Patterns
17
+
18
+
#### Basic Setup
19
+
20
+
```tsx
21
+
import {
22
+
AssistantProvider,
23
+
AssistantDrawer,
24
+
} from'@mongodb-js/compass-assistant';
25
+
26
+
// At the top level, wrap your app with the provider
27
+
<AssistantProviderchat={chatInstance}>
28
+
<YourApp />
29
+
30
+
{/* Place the drawer anywhere in your component tree */}
31
+
<AssistantDrawer />
32
+
</AssistantProvider>;
33
+
```
34
+
35
+
#### Custom Implementation
36
+
37
+
```tsx
38
+
import {
39
+
AssistantProvider,
40
+
AssistantChat,
41
+
useAssistant,
42
+
} from'@mongodb-js/compass-assistant';
43
+
44
+
// Custom component that uses the assistant context
45
+
function CustomAssistantUI() {
46
+
const { messages, sendMessage } =useAssistant();
47
+
48
+
return (
49
+
<div>
50
+
<h2>Custom Assistant UI</h2>
51
+
<AssistantChat />
52
+
<div>Message count: {messages.length}</div>
53
+
</div>
54
+
);
55
+
}
56
+
57
+
// Usage
58
+
<AssistantProviderchat={chatInstance}>
59
+
<YourApp />
60
+
<CustomAssistantUI />
61
+
</AssistantProvider>;
62
+
```
63
+
64
+
## Benefits
65
+
66
+
-**Separation of Concerns**: Chat UI is separate from state management
67
+
-**Flexibility**: Components can be placed at any level in the tree
68
+
-**Reusability**: Multiple components can consume the same assistant context
69
+
-**Testability**: Easy to mock context for testing individual components
0 commit comments