Skip to content

Commit 5bda725

Browse files
committed
ai-plugin: Add utility enhancements and helper functions
- Add isElectron utility function for environment detection - Enhance ToolConfigManager with configuration validation - Update AIInputSection with improved tool integration - Add electron client improvements for MCP communication - Include helper functions for better component integration Signed-off-by: ashu8912 <aghildiyal@microsoft.com>
1 parent 9adc527 commit 5bda725

File tree

4 files changed

+61
-0
lines changed

4 files changed

+61
-0
lines changed

ai-assistant/src/ai/mcp/electron-client.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ class ElectronMCPClient {
9090
}
9191

9292
try {
93+
console.log("args for tool executed is ", args)
9394
const response = await window.desktopApi!.mcp.executeTool(toolName, args, toolCallId);
9495

9596
if (response.success) {

ai-assistant/src/components/assistant/AIInputSection.tsx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { getProviderById } from '../../config/modelConfig';
1515
import { getModelDisplayName, getProviderModelsForChat } from '../../utils/modalUtils';
1616
import { StoredProviderConfig } from '../../utils/ProviderConfigManager';
1717
import TestModeInput from './TestModeInput';
18+
import { ToolsDialog } from './ToolsDialog';
1819

1920
interface AIInputSectionProps {
2021
promptVal: string;
@@ -24,11 +25,13 @@ interface AIInputSectionProps {
2425
activeConfig: StoredProviderConfig | null;
2526
availableConfigs: StoredProviderConfig[];
2627
selectedModel: string;
28+
enabledTools: string[];
2729
onSend: (prompt: string) => void;
2830
onStop: () => void;
2931
onClearHistory: () => void;
3032
onConfigChange: (config: StoredProviderConfig, model: string) => void;
3133
onTestModeResponse: (content: string, type: 'assistant' | 'user', hasError?: boolean) => void;
34+
onToolsChange: (enabledTools: string[]) => void;
3235
}
3336

3437
export const AIInputSection: React.FC<AIInputSectionProps> = ({
@@ -39,12 +42,15 @@ export const AIInputSection: React.FC<AIInputSectionProps> = ({
3942
activeConfig,
4043
availableConfigs,
4144
selectedModel,
45+
enabledTools,
4246
onSend,
4347
onStop,
4448
onClearHistory,
4549
onConfigChange,
4650
onTestModeResponse,
51+
onToolsChange,
4752
}) => {
53+
const [showToolsDialog, setShowToolsDialog] = React.useState(false);
4854
const handleKeyDown = (e: React.KeyboardEvent) => {
4955
if (e.key === 'Enter' && !e.shiftKey) {
5056
e.preventDefault();
@@ -188,6 +194,20 @@ export const AIInputSection: React.FC<AIInputSectionProps> = ({
188194
</Select>
189195
</Box>
190196
)}
197+
198+
{/* Tools Button */}
199+
{!isTestMode && (
200+
<Box ml={1}>
201+
<ActionButton
202+
description="Manage Tools"
203+
onClick={() => setShowToolsDialog(true)}
204+
icon="mdi:tools"
205+
iconButtonProps={{
206+
size: 'small',
207+
}}
208+
/>
209+
</Box>
210+
)}
191211
</Grid>
192212

193213
<Grid item>
@@ -214,6 +234,14 @@ export const AIInputSection: React.FC<AIInputSectionProps> = ({
214234
)}
215235
</Grid>
216236
</Grid>
237+
238+
{/* Tools Dialog */}
239+
<ToolsDialog
240+
open={showToolsDialog}
241+
onClose={() => setShowToolsDialog(false)}
242+
enabledTools={enabledTools}
243+
onToolsChange={onToolsChange}
244+
/>
217245
</Box>
218246
);
219247
};

ai-assistant/src/utils.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ function usePluginSettings() {
2121
// Add state to control UI panel visibility - initialize from stored settings
2222
const [isUIPanelOpen, setIsUIPanelOpenState] = React.useState(conf?.isUIPanelOpen ?? false);
2323

24+
// Add state for enabled tools - initialize from stored settings
25+
const [enabledTools, setEnabledToolsState] = React.useState<string[]>(conf?.enabledTools ?? []);
26+
2427
// Wrap setIsUIPanelOpen to also update the stored configuration
2528
const setIsUIPanelOpen = (isOpen: boolean) => {
2629
setIsUIPanelOpenState(isOpen);
@@ -32,6 +35,17 @@ function usePluginSettings() {
3235
});
3336
};
3437

38+
// Wrap setEnabledTools to also update the stored configuration
39+
const setEnabledTools = (tools: string[]) => {
40+
setEnabledToolsState(tools);
41+
// Save the tools configuration
42+
const currentConf = pluginStore.get() || {};
43+
pluginStore.update({
44+
...currentConf,
45+
enabledTools: tools,
46+
});
47+
};
48+
3549
return {
3650
event,
3751
setEvent,
@@ -41,6 +55,8 @@ function usePluginSettings() {
4155
setActiveProvider,
4256
isUIPanelOpen,
4357
setIsUIPanelOpen,
58+
enabledTools,
59+
setEnabledTools,
4460
};
4561
}
4662

ai-assistant/src/utils/ToolConfigManager.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,19 @@ export function getEnabledToolIds(pluginSettings: any): string[] {
5252
const allTools = getAllAvailableTools();
5353
return allTools.map(tool => tool.id).filter(toolId => isToolEnabled(pluginSettings, toolId));
5454
}
55+
56+
// Sets the enabled tools list in plugin settings
57+
export function setEnabledTools(pluginSettings: any, enabledToolIds: string[]): any {
58+
const enabledTools: Record<string, boolean> = {};
59+
60+
// Get all available tools and set their enabled state
61+
const allTools = getAllAvailableTools();
62+
allTools.forEach(tool => {
63+
enabledTools[tool.id] = enabledToolIds.includes(tool.id);
64+
});
65+
66+
return {
67+
...pluginSettings,
68+
enabledTools,
69+
};
70+
}

0 commit comments

Comments
 (0)