Skip to content

Commit 03df319

Browse files
committed
format and lint fix
1 parent 2a74422 commit 03df319

File tree

7 files changed

+47
-78
lines changed

7 files changed

+47
-78
lines changed

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

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,33 +8,6 @@ interface MCPTool {
88
server?: string; // Add server information
99
}
1010

11-
interface MCPResponse {
12-
success: boolean;
13-
tools?: MCPTool[];
14-
result?: any;
15-
error?: string;
16-
toolCallId?: string;
17-
}
18-
19-
interface ElectronMCPApi {
20-
executeTool: (
21-
toolName: string,
22-
args: Record<string, any>,
23-
toolCallId?: string
24-
) => Promise<MCPResponse>;
25-
getStatus: () => Promise<{ isInitialized: boolean; hasClient: boolean }>;
26-
resetClient: () => Promise<MCPResponse>;
27-
getConfig: () => Promise<{ success: boolean; config?: any; error?: string }>;
28-
updateConfig: (config: any) => Promise<MCPResponse>;
29-
getToolsConfig: () => Promise<{ success: boolean; config?: any; error?: string }>;
30-
updateToolsConfig: (config: any) => Promise<MCPResponse>;
31-
setToolEnabled: (serverName: string, toolName: string, enabled: boolean) => Promise<MCPResponse>;
32-
getToolStats: (
33-
serverName: string,
34-
toolName: string
35-
) => Promise<{ success: boolean; stats?: any; error?: string }>;
36-
}
37-
3811
// Type augmentation is handled by src/types/electron.d.ts
3912

4013
class ElectronMCPClient {

ai-assistant/src/components/settings/MCPServerEditor.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {
99
DialogTitle,
1010
FormControlLabel,
1111
IconButton,
12-
Paper,
1312
Switch,
1413
TextField,
1514
Typography,
@@ -244,7 +243,11 @@ export default function MCPServerEditor({
244243
sx={{ flex: 2 }}
245244
placeholder="e.g., HEADLAMP_CURRENT_CLUSTER"
246245
/>
247-
<IconButton size="small" onClick={() => handleRemoveEnvVar(index)} color="error">
246+
<IconButton
247+
size="small"
248+
onClick={() => handleRemoveEnvVar(index)}
249+
color="error"
250+
>
248251
<Icon icon="mdi:delete" />
249252
</IconButton>
250253
</Box>

ai-assistant/src/components/settings/MCPServerFormDialog.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import {
44
Alert,
55
Box,
66
Button,
7-
Chip,
87
DialogActions,
98
DialogContent,
109
DialogTitle,
@@ -76,9 +75,7 @@ export default function MCPServerFormDialog({
7675
name: server.name,
7776
command: server.command,
7877
args: server.args.join(' '),
79-
env: server.env
80-
? Object.entries(server.env).map(([key, value]) => ({ key, value }))
81-
: [],
78+
env: server.env ? Object.entries(server.env).map(([key, value]) => ({ key, value })) : [],
8279
enabled: server.enabled,
8380
}));
8481
setServers(formData);
@@ -415,7 +412,9 @@ export default function MCPServerFormDialog({
415412
control={
416413
<Switch
417414
checked={currentServer.enabled}
418-
onChange={e => setCurrentServer({ ...currentServer, enabled: e.target.checked })}
415+
onChange={e =>
416+
setCurrentServer({ ...currentServer, enabled: e.target.checked })
417+
}
419418
/>
420419
}
421420
label="Enable this server"

ai-assistant/src/components/settings/MCPSettings.tsx

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ interface MCPSettingsProps {
4141
}
4242

4343
export function MCPSettings({ config, onConfigChange }: MCPSettingsProps) {
44+
console.log('config in MCPSettings', config);
4445
const [jsonEditorOpen, setJsonEditorOpen] = useState(false);
4546
const [serverEditorOpen, setServerEditorOpen] = useState(false);
4647
const [editingServer, setEditingServer] = useState<MCPServer | undefined>(undefined);
@@ -217,19 +218,20 @@ export function MCPSettings({ config, onConfigChange }: MCPSettingsProps) {
217218

218219
const handleSaveServer = (server: MCPServer) => {
219220
if (!pendingConfig) return;
220-
221+
221222
let newServers: MCPServer[];
222223

223224
if (editingServer) {
224225
// Check if the server actually changed
225226
const originalServer = pendingConfig.servers.find(s => s.name === editingServer.name);
226-
const serverChanged = !originalServer || JSON.stringify(originalServer) !== JSON.stringify(server);
227-
227+
const serverChanged =
228+
!originalServer || JSON.stringify(originalServer) !== JSON.stringify(server);
229+
228230
if (!serverChanged) {
229231
// No changes, just close the dialog
230232
return;
231233
}
232-
234+
233235
// Update existing server
234236
newServers = pendingConfig.servers.map(s => (s.name === editingServer.name ? server : s));
235237
} else {
@@ -374,10 +376,7 @@ export function MCPSettings({ config, onConfigChange }: MCPSettingsProps) {
374376
</TableCell>
375377
<TableCell align="right">
376378
<Tooltip title="Edit">
377-
<IconButton
378-
size="small"
379-
onClick={() => handleOpenServerEditor(server)}
380-
>
379+
<IconButton size="small" onClick={() => handleOpenServerEditor(server)}>
381380
<Icon icon="mdi:pencil" />
382381
</IconButton>
383382
</Tooltip>

ai-assistant/src/langchain/LangChainManager.ts

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -169,14 +169,17 @@ export default class LangChainManager extends AIManager {
169169
const assistantPrompt: Prompt = {
170170
role: 'assistant',
171171
content: fullContent,
172-
toolCalls: toolCalls.length > 0 ? toolCalls.map(tc => ({
173-
type: 'function',
174-
id: tc.id,
175-
function: {
176-
name: tc.name,
177-
arguments: JSON.stringify(tc.args || {}),
178-
},
179-
})) : undefined,
172+
toolCalls:
173+
toolCalls.length > 0
174+
? toolCalls.map(tc => ({
175+
type: 'function',
176+
id: tc.id,
177+
function: {
178+
name: tc.name,
179+
arguments: JSON.stringify(tc.args || {}),
180+
},
181+
}))
182+
: undefined,
180183
};
181184

182185
// If there are tool calls, handle them with streaming
@@ -209,7 +212,7 @@ export default class LangChainManager extends AIManager {
209212
}
210213

211214
// Clear progress steps for non-tool responses
212-
}
215+
}
213216

214217
return assistantPrompt;
215218
} catch (error) {
@@ -864,7 +867,7 @@ The user is waiting for you to explain what the tools discovered. Provide a dire
864867
this.history.push(assistantPrompt);
865868

866869
// Clear progress steps for non-tool responses
867-
870+
868871
return assistantPrompt;
869872
}
870873
} catch (error) {
@@ -1103,12 +1106,10 @@ The user is waiting for you to explain what the tools discovered. Provide a dire
11031106
})
11041107
);
11051108

1106-
let approvedToolIds: string[] = [];
1109+
const approvedToolIds: string[] = [];
11071110

11081111
// Separate built-in tools from MCP tools (same pattern as handleToolCalls)
1109-
const builtInToolsForApproval = toolsForApproval.filter(tool =>
1110-
isBuiltInTool(tool.name)
1111-
);
1112+
const builtInToolsForApproval = toolsForApproval.filter(tool => isBuiltInTool(tool.name));
11121113
const mcpToolsForApproval = toolsForApproval.filter(tool => !isBuiltInTool(tool.name));
11131114

11141115
// Auto-approve all built-in tools (no user interaction needed)
@@ -1141,9 +1142,7 @@ The user is waiting for you to explain what the tools discovered. Provide a dire
11411142
// Match by checking if the approved ID contains the tool name as a suffix
11421143
const approvedTools = recommendedTools.filter(tool => {
11431144
const expectedIdPrefix = `orchestrated-${tool.name}-`;
1144-
return approvedToolIds.some(
1145-
id => id === tool.name || id.startsWith(expectedIdPrefix)
1146-
);
1145+
return approvedToolIds.some(id => id === tool.name || id.startsWith(expectedIdPrefix));
11471146
});
11481147

11491148
// Group tools by execution strategy (parallel vs sequential)
@@ -1411,7 +1410,7 @@ ${Object.entries(toolResults)
14111410
this.history.push(assistantPrompt);
14121411

14131412
// Clear progress steps when all tools are disabled
1414-
1413+
14151414
return assistantPrompt;
14161415
}
14171416

@@ -1464,12 +1463,12 @@ Without access to the Kubernetes API, I cannot fetch current pod, deployment, se
14641463
this.history[this.history.length - 1] = updatedPrompt;
14651464

14661465
// Clear progress steps when tools are disabled
1467-
1466+
14681467
return updatedPrompt;
14691468
}
14701469

14711470
// Clear progress steps when no tools to execute
1472-
1471+
14731472
return assistantPrompt;
14741473
}
14751474

@@ -1625,7 +1624,10 @@ Without access to the Kubernetes API, I cannot fetch current pod, deployment, se
16251624
* Handle tool calls for streaming scenario - executes tools without generating response
16261625
* (response will be streamed separately by processToolResponsesStream)
16271626
*/
1628-
private async handleToolCallsForStreaming(toolCalls: any[], assistantPrompt: Prompt): Promise<void> {
1627+
private async handleToolCallsForStreaming(
1628+
toolCalls: any[],
1629+
assistantPrompt: Prompt
1630+
): Promise<void> {
16291631
const enabledToolIds = this.toolManager.getToolNames();
16301632

16311633
// Convert tool calls to expected format
@@ -1699,10 +1701,7 @@ Without access to the Kubernetes API, I cannot fetch current pod, deployment, se
16991701

17001702
// Request approval for MCP tools
17011703
if (mcpTools.length > 0) {
1702-
const approvedMCPToolIds = await inlineToolApprovalManager.requestApproval(
1703-
mcpTools,
1704-
this
1705-
);
1704+
const approvedMCPToolIds = await inlineToolApprovalManager.requestApproval(mcpTools, this);
17061705
approvedToolIds.push(...approvedMCPToolIds);
17071706
}
17081707

@@ -2097,14 +2096,14 @@ Format your response to make the errors prominent and actionable.`,
20972096
this.history.push(assistantPrompt);
20982097

20992098
// Clear progress steps after streaming response
2100-
2099+
21012100
return assistantPrompt;
21022101
} catch (error) {
21032102
const errorPrompt = this.handleToolResponseError(error);
21042103
yield errorPrompt.content;
21052104

21062105
// Clear progress steps even on error
2107-
2106+
21082107
return errorPrompt;
21092108
}
21102109
}
@@ -2790,7 +2789,9 @@ Return the complete arguments object:`;
27902789
key.toLowerCase().includes('max'))
27912790
) {
27922791
sanitized[key] = parseFloat(value);
2793-
console.log(`[ArgSanitize] Converted ${key} from string "${value}" to number ${sanitized[key]}`);
2792+
console.log(
2793+
`[ArgSanitize] Converted ${key} from string "${value}" to number ${sanitized[key]}`
2794+
);
27942795
continue;
27952796
}
27962797
}

ai-assistant/src/langchain/tools/ToolOrchestrator.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,7 @@ const ToolRecommendationSchema = z.object({
4242
tool_name: z.string().optional().describe('Alternative field for tool name'),
4343
description: z.string().describe('What this tool will do'),
4444
arguments: z
45-
.union([
46-
z.record(z.string(), z.any()),
47-
z.string(),
48-
])
45+
.union([z.record(z.string(), z.any()), z.string()])
4946
.default({})
5047
.describe('Arguments needed for this tool'),
5148
priority: z

ai-assistant/src/utils.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@ import type {
77
import React from 'react';
88
import { useBetween } from 'use-between';
99
import { SavedConfigurations, StoredProviderConfig } from './utils/ProviderConfigManager';
10-
import {
11-
getAllAvailableToolsIncludingMCP,
12-
initializeToolsState,
13-
} from './utils/ToolConfigManager';
10+
import { getAllAvailableToolsIncludingMCP, initializeToolsState } from './utils/ToolConfigManager';
1411

1512
export const PLUGIN_NAME = '@headlamp-k8s/ai-assistant';
1613
export const getSettingsURL = () => `/settings/plugins/${encodeURIComponent(PLUGIN_NAME)}`;

0 commit comments

Comments
 (0)