fixing prettier
This commit is contained in:
parent
51fafb485c
commit
5e69116f47
52 changed files with 7830 additions and 7525 deletions
|
|
@ -1,2 +1,5 @@
|
||||||
pnpm-lock.yaml
|
pnpm-lock.yaml
|
||||||
*.md
|
*.md
|
||||||
|
.wrangler
|
||||||
|
.vscode
|
||||||
|
test-results
|
||||||
|
|
|
||||||
|
|
@ -14,13 +14,12 @@ test.describe('Build Tests', () => {
|
||||||
try {
|
try {
|
||||||
const { stderr } = await execAsync('pnpm build', {
|
const { stderr } = await execAsync('pnpm build', {
|
||||||
cwd: process.cwd(),
|
cwd: process.cwd(),
|
||||||
timeout: 60000
|
timeout: 60000,
|
||||||
})
|
})
|
||||||
|
|
||||||
// Check for TypeScript compilation errors
|
// Check for TypeScript compilation errors
|
||||||
expect(stderr).not.toContain('error TS')
|
expect(stderr).not.toContain('error TS')
|
||||||
expect(stderr).not.toContain('Type error')
|
expect(stderr).not.toContain('Type error')
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const execError = error as ExecError
|
const execError = error as ExecError
|
||||||
console.error('Build failed:', execError.stdout, execError.stderr)
|
console.error('Build failed:', execError.stdout, execError.stderr)
|
||||||
|
|
@ -32,12 +31,11 @@ test.describe('Build Tests', () => {
|
||||||
try {
|
try {
|
||||||
const { stderr } = await execAsync('pnpm lint', {
|
const { stderr } = await execAsync('pnpm lint', {
|
||||||
cwd: process.cwd(),
|
cwd: process.cwd(),
|
||||||
timeout: 30000
|
timeout: 30000,
|
||||||
})
|
})
|
||||||
|
|
||||||
// ESLint should pass without errors
|
// ESLint should pass without errors
|
||||||
expect(stderr).not.toContain('error')
|
expect(stderr).not.toContain('error')
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const execError = error as ExecError
|
const execError = error as ExecError
|
||||||
console.error('Lint failed:', execError.stdout, execError.stderr)
|
console.error('Lint failed:', execError.stdout, execError.stderr)
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ import { test, expect } from '@playwright/test'
|
||||||
test.describe('Chat Functionality', () => {
|
test.describe('Chat Functionality', () => {
|
||||||
test.beforeEach(async ({ page }) => {
|
test.beforeEach(async ({ page }) => {
|
||||||
// Mock the external AI API calls
|
// Mock the external AI API calls
|
||||||
await page.route('https://api.groq.com/**', async route => {
|
await page.route('https://api.groq.com/**', async (route) => {
|
||||||
// Mock streaming response for Groq
|
// Mock streaming response for Groq
|
||||||
const mockResponse = 'Hello! This is a mocked response from the AI assistant.'
|
const mockResponse = 'Hello! This is a mocked response from the AI assistant.'
|
||||||
|
|
||||||
|
|
@ -16,7 +16,7 @@ test.describe('Chat Functionality', () => {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
await page.route('https://api.anthropic.com/**', async route => {
|
await page.route('https://api.anthropic.com/**', async (route) => {
|
||||||
// Mock streaming response for Anthropic
|
// Mock streaming response for Anthropic
|
||||||
const mockResponse = 'Hello! This is a mocked response from Claude.'
|
const mockResponse = 'Hello! This is a mocked response from Claude.'
|
||||||
|
|
||||||
|
|
@ -30,13 +30,15 @@ test.describe('Chat Functionality', () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
// Mock the local API endpoint
|
// Mock the local API endpoint
|
||||||
await page.route('/api/chat', async route => {
|
await page.route('/api/chat', async (route) => {
|
||||||
const mockResponse = {
|
const mockResponse = {
|
||||||
choices: [{
|
choices: [
|
||||||
delta: {
|
{
|
||||||
content: 'Hello! This is a mocked response from the local API.'
|
delta: {
|
||||||
}
|
content: 'Hello! This is a mocked response from the local API.',
|
||||||
}]
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
}
|
}
|
||||||
|
|
||||||
route.fulfill({
|
route.fulfill({
|
||||||
|
|
@ -60,7 +62,10 @@ test.describe('Chat Functionality', () => {
|
||||||
await expect(messageInput).toBeVisible()
|
await expect(messageInput).toBeVisible()
|
||||||
|
|
||||||
// Check for a send button or similar
|
// Check for a send button or similar
|
||||||
const sendButton = page.locator('button').filter({ hasText: /send|submit/i }).first()
|
const sendButton = page
|
||||||
|
.locator('button')
|
||||||
|
.filter({ hasText: /send|submit/i })
|
||||||
|
.first()
|
||||||
if (await sendButton.isVisible()) {
|
if (await sendButton.isVisible()) {
|
||||||
await expect(sendButton).toBeVisible()
|
await expect(sendButton).toBeVisible()
|
||||||
}
|
}
|
||||||
|
|
@ -97,7 +102,7 @@ test.describe('Chat Functionality', () => {
|
||||||
|
|
||||||
test('should handle API errors gracefully', async ({ page }) => {
|
test('should handle API errors gracefully', async ({ page }) => {
|
||||||
// Override mocks to simulate API errors
|
// Override mocks to simulate API errors
|
||||||
await page.route('https://api.groq.com/**', async route => {
|
await page.route('https://api.groq.com/**', async (route) => {
|
||||||
route.fulfill({
|
route.fulfill({
|
||||||
status: 500,
|
status: 500,
|
||||||
headers: {
|
headers: {
|
||||||
|
|
@ -107,7 +112,7 @@ test.describe('Chat Functionality', () => {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
await page.route('https://api.anthropic.com/**', async route => {
|
await page.route('https://api.anthropic.com/**', async (route) => {
|
||||||
route.fulfill({
|
route.fulfill({
|
||||||
status: 401,
|
status: 401,
|
||||||
headers: {
|
headers: {
|
||||||
|
|
@ -123,7 +128,10 @@ test.describe('Chat Functionality', () => {
|
||||||
const messageInput = page.locator('textarea, input[type="text"]').first()
|
const messageInput = page.locator('textarea, input[type="text"]').first()
|
||||||
await messageInput.fill('Test message')
|
await messageInput.fill('Test message')
|
||||||
|
|
||||||
const sendButton = page.locator('button').filter({ hasText: /send|submit/i }).first()
|
const sendButton = page
|
||||||
|
.locator('button')
|
||||||
|
.filter({ hasText: /send|submit/i })
|
||||||
|
.first()
|
||||||
if (await sendButton.isVisible()) {
|
if (await sendButton.isVisible()) {
|
||||||
await sendButton.click()
|
await sendButton.click()
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -144,7 +152,10 @@ test.describe('Chat Functionality', () => {
|
||||||
const messageInput = page.locator('textarea, input[type="text"]').first()
|
const messageInput = page.locator('textarea, input[type="text"]').first()
|
||||||
await messageInput.fill('Test message for persistence')
|
await messageInput.fill('Test message for persistence')
|
||||||
|
|
||||||
const sendButton = page.locator('button').filter({ hasText: /send|submit/i }).first()
|
const sendButton = page
|
||||||
|
.locator('button')
|
||||||
|
.filter({ hasText: /send|submit/i })
|
||||||
|
.first()
|
||||||
if (await sendButton.isVisible()) {
|
if (await sendButton.isVisible()) {
|
||||||
await sendButton.click()
|
await sendButton.click()
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -19,10 +19,7 @@ export default tseslint.config(
|
||||||
},
|
},
|
||||||
rules: {
|
rules: {
|
||||||
...reactHooks.configs.recommended.rules,
|
...reactHooks.configs.recommended.rules,
|
||||||
'react-refresh/only-export-components': [
|
'react-refresh/only-export-components': ['warn', { allowConstantExport: true }],
|
||||||
'warn',
|
|
||||||
{ allowConstantExport: true },
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
},
|
}
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import { BrowserRouter as Router, Routes, Route } from 'react-router-dom'
|
import { BrowserRouter as Router, Routes, Route } from 'react-router-dom'
|
||||||
import ChatApp from "./components/ChatApp";
|
import ChatApp from './components/ChatApp'
|
||||||
import { OAuthCallback } from "./components/OAuthCallback";
|
import { OAuthCallback } from './components/OAuthCallback'
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
return (
|
return (
|
||||||
|
|
@ -10,7 +10,7 @@ function App() {
|
||||||
<Route path="/" element={<ChatApp />} />
|
<Route path="/" element={<ChatApp />} />
|
||||||
</Routes>
|
</Routes>
|
||||||
</Router>
|
</Router>
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export default App;
|
export default App
|
||||||
|
|
|
||||||
|
|
@ -10,12 +10,7 @@ interface ApiKeyModalProps {
|
||||||
onSave: (apiKey: string) => void
|
onSave: (apiKey: string) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
const ApiKeyModal: React.FC<ApiKeyModalProps> = ({
|
const ApiKeyModal: React.FC<ApiKeyModalProps> = ({ isOpen, onClose, provider, onSave }) => {
|
||||||
isOpen,
|
|
||||||
onClose,
|
|
||||||
provider,
|
|
||||||
onSave,
|
|
||||||
}) => {
|
|
||||||
const [apiKey, setApiKey] = useState('')
|
const [apiKey, setApiKey] = useState('')
|
||||||
const [showApiKey, setShowApiKey] = useState(false)
|
const [showApiKey, setShowApiKey] = useState(false)
|
||||||
|
|
||||||
|
|
@ -36,22 +31,13 @@ const ApiKeyModal: React.FC<ApiKeyModalProps> = ({
|
||||||
}
|
}
|
||||||
|
|
||||||
const modalContent = (
|
const modalContent = (
|
||||||
<div
|
<div className="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50" onClick={handleClose}>
|
||||||
className="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50"
|
<div className="bg-white rounded-lg p-6 w-full max-w-md mx-4" onClick={(e) => e.stopPropagation()}>
|
||||||
onClick={handleClose}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
className="bg-white rounded-lg p-6 w-full max-w-md mx-4"
|
|
||||||
onClick={(e) => e.stopPropagation()}
|
|
||||||
>
|
|
||||||
<div className="flex items-center justify-between mb-4">
|
<div className="flex items-center justify-between mb-4">
|
||||||
<h2 className="text-lg font-semibold text-zinc-900">
|
<h2 className="text-lg font-semibold text-zinc-900">
|
||||||
{provider.logo} {provider.name} API Key
|
{provider.logo} {provider.name} API Key
|
||||||
</h2>
|
</h2>
|
||||||
<button
|
<button onClick={handleClose} className="text-zinc-400 hover:text-zinc-600 p-1">
|
||||||
onClick={handleClose}
|
|
||||||
className="text-zinc-400 hover:text-zinc-600 p-1"
|
|
||||||
>
|
|
||||||
<X size={20} />
|
<X size={20} />
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -95,11 +81,7 @@ const ApiKeyModal: React.FC<ApiKeyModalProps> = ({
|
||||||
Get API key →
|
Get API key →
|
||||||
</a>
|
</a>
|
||||||
<div className="flex gap-2">
|
<div className="flex gap-2">
|
||||||
<button
|
<button type="button" onClick={handleClose} className="px-4 py-2 text-sm text-zinc-600 hover:text-zinc-800">
|
||||||
type="button"
|
|
||||||
onClick={handleClose}
|
|
||||||
className="px-4 py-2 text-sm text-zinc-600 hover:text-zinc-800"
|
|
||||||
>
|
|
||||||
Cancel
|
Cancel
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
|
|
|
||||||
|
|
@ -1,74 +1,69 @@
|
||||||
import React, { useState, useEffect } from "react";
|
import React, { useState, useEffect } from 'react'
|
||||||
import ConversationThread from "./ConversationThread.tsx";
|
import ConversationThread from './ConversationThread.tsx'
|
||||||
import { storeName } from "../consts.ts";
|
import { storeName } from '../consts.ts'
|
||||||
import { type Conversation } from "../types";
|
import { type Conversation } from '../types'
|
||||||
import { useIndexedDB } from "../hooks/useIndexedDB";
|
import { useIndexedDB } from '../hooks/useIndexedDB'
|
||||||
import { type Model } from "../types/models";
|
import { type Model } from '../types/models'
|
||||||
import { getSelectedModel, setSelectedModel as saveSelectedModel } from "../utils/modelPreferences";
|
import { getSelectedModel, setSelectedModel as saveSelectedModel } from '../utils/modelPreferences'
|
||||||
import { type IDBPDatabase } from "idb";
|
import { type IDBPDatabase } from 'idb'
|
||||||
import { type Tool } from "use-mcp/react";
|
import { type Tool } from 'use-mcp/react'
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
|
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
|
||||||
interface ChatAppProps {}
|
interface ChatAppProps {}
|
||||||
|
|
||||||
const ChatApp: React.FC<ChatAppProps> = () => {
|
const ChatApp: React.FC<ChatAppProps> = () => {
|
||||||
const [conversations, setConversations] = useState<Conversation[]>([]);
|
const [conversations, setConversations] = useState<Conversation[]>([])
|
||||||
const [conversationId, setConversationId] = useState<number | undefined>(
|
const [conversationId, setConversationId] = useState<number | undefined>(undefined)
|
||||||
undefined
|
|
||||||
);
|
|
||||||
|
|
||||||
const [selectedModel, setSelectedModel] = useState<Model>(getSelectedModel());
|
const [selectedModel, setSelectedModel] = useState<Model>(getSelectedModel())
|
||||||
const [apiKeyUpdateTrigger, setApiKeyUpdateTrigger] = useState<number>(0);
|
const [apiKeyUpdateTrigger, setApiKeyUpdateTrigger] = useState<number>(0)
|
||||||
const [mcpTools, setMcpTools] = useState<Tool[]>([]);
|
const [mcpTools, setMcpTools] = useState<Tool[]>([])
|
||||||
const [animationDelay] = useState<number>(() => -Math.random() * 60);
|
const [animationDelay] = useState<number>(() => -Math.random() * 60)
|
||||||
const db = useIndexedDB();
|
const db = useIndexedDB()
|
||||||
|
|
||||||
const handleApiKeyUpdate = () => {
|
const handleApiKeyUpdate = () => {
|
||||||
setApiKeyUpdateTrigger(prev => prev + 1);
|
setApiKeyUpdateTrigger((prev) => prev + 1)
|
||||||
};
|
}
|
||||||
|
|
||||||
const handleModelChange = (model: Model) => {
|
const handleModelChange = (model: Model) => {
|
||||||
setSelectedModel(model);
|
setSelectedModel(model)
|
||||||
saveSelectedModel(model);
|
saveSelectedModel(model)
|
||||||
};
|
}
|
||||||
|
|
||||||
// set up conversations on app load
|
// set up conversations on app load
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
getConversations();
|
getConversations()
|
||||||
deleteUnusedConversations();
|
deleteUnusedConversations()
|
||||||
startNewConversation();
|
startNewConversation()
|
||||||
}, [db]);
|
}, [db])
|
||||||
|
|
||||||
// Initialize sidebar visibility based on screen size
|
// Initialize sidebar visibility based on screen size
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// const isMobile = window.matchMedia("(max-width: 768px)").matches;
|
// const isMobile = window.matchMedia("(max-width: 768px)").matches;
|
||||||
// setSidebarVisible(!isMobile);
|
// setSidebarVisible(!isMobile);
|
||||||
}, []);
|
}, [])
|
||||||
|
|
||||||
const getConversations = async () => {
|
const getConversations = async () => {
|
||||||
if (!db) return;
|
if (!db) return
|
||||||
|
|
||||||
const conversations = (await db.getAll(storeName)) as Conversation[];
|
const conversations = (await db.getAll(storeName)) as Conversation[]
|
||||||
const inverseConversations = conversations.reverse();
|
const inverseConversations = conversations.reverse()
|
||||||
setConversations(inverseConversations);
|
setConversations(inverseConversations)
|
||||||
};
|
}
|
||||||
|
|
||||||
const deleteConversation = async (id: number, showPromptToUser = true) => {
|
const deleteConversation = async (id: number, showPromptToUser = true) => {
|
||||||
try {
|
try {
|
||||||
if (
|
if (showPromptToUser && !window.confirm('Are you sure you want to delete this conversation?')) {
|
||||||
showPromptToUser &&
|
return
|
||||||
!window.confirm("Are you sure you want to delete this conversation?")
|
|
||||||
) {
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
await db?.delete(storeName, id);
|
await db?.delete(storeName, id)
|
||||||
setConversations((prev) => prev.filter((conv) => conv.id !== id));
|
setConversations((prev) => prev.filter((conv) => conv.id !== id))
|
||||||
setConversationId(conversations[0]?.id);
|
setConversationId(conversations[0]?.id)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Failed to delete conversation:", error);
|
console.error('Failed to delete conversation:', error)
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
// const editConversationTitle = async (id: number, newTitle: string) => {
|
// const editConversationTitle = async (id: number, newTitle: string) => {
|
||||||
// const conversation = (await db!.get(storeName, id)) as Conversation;
|
// const conversation = (await db!.get(storeName, id)) as Conversation;
|
||||||
|
|
@ -81,24 +76,22 @@ const ChatApp: React.FC<ChatAppProps> = () => {
|
||||||
|
|
||||||
const startNewConversation = async () => {
|
const startNewConversation = async () => {
|
||||||
//create unique id for new conversation
|
//create unique id for new conversation
|
||||||
setConversationId(Date.now() + Math.floor(Math.random() * 1000));
|
setConversationId(Date.now() + Math.floor(Math.random() * 1000))
|
||||||
// if (window.matchMedia("(max-width: 768px)").matches) {
|
// if (window.matchMedia("(max-width: 768px)").matches) {
|
||||||
// setSidebarVisible(false);
|
// setSidebarVisible(false);
|
||||||
// }
|
// }
|
||||||
};
|
}
|
||||||
|
|
||||||
// delete conversations with no messages
|
// delete conversations with no messages
|
||||||
const deleteUnusedConversations = async () => {
|
const deleteUnusedConversations = async () => {
|
||||||
if (!db) return;
|
if (!db) return
|
||||||
const conversations = (await db.getAll(storeName)) as Conversation[];
|
const conversations = (await db.getAll(storeName)) as Conversation[]
|
||||||
const unusedConversations = conversations.filter(
|
const unusedConversations = conversations.filter((conversation) => conversation.messages.length === 0)
|
||||||
(conversation) => conversation.messages.length === 0
|
|
||||||
);
|
|
||||||
|
|
||||||
for (const conversation of unusedConversations) {
|
for (const conversation of unusedConversations) {
|
||||||
deleteConversation(conversation.id as number, false);
|
deleteConversation(conversation.id as number, false)
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
|
|
@ -146,7 +139,7 @@ const ChatApp: React.FC<ChatAppProps> = () => {
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
)
|
||||||
};
|
}
|
||||||
|
|
||||||
export default ChatApp;
|
export default ChatApp
|
||||||
|
|
|
||||||
|
|
@ -1,47 +1,41 @@
|
||||||
import React from "react";
|
import React from 'react'
|
||||||
import ReactMarkdown from "react-markdown";
|
import ReactMarkdown from 'react-markdown'
|
||||||
import remarkGfm from "remark-gfm";
|
import remarkGfm from 'remark-gfm'
|
||||||
import rehypeHighlight from "rehype-highlight";
|
import rehypeHighlight from 'rehype-highlight'
|
||||||
import { type Message } from "../types";
|
import { type Message } from '../types'
|
||||||
import ToolCallMessage from "./ToolCallMessage";
|
import ToolCallMessage from './ToolCallMessage'
|
||||||
import ToolResultMessage from "./ToolResultMessage";
|
import ToolResultMessage from './ToolResultMessage'
|
||||||
import ReasoningBlock from "./ReasoningBlock";
|
import ReasoningBlock from './ReasoningBlock'
|
||||||
|
|
||||||
interface ChatMessageProps {
|
interface ChatMessageProps {
|
||||||
message: Message;
|
message: Message
|
||||||
}
|
}
|
||||||
|
|
||||||
const ChatMessage: React.FC<ChatMessageProps> = ({
|
const ChatMessage: React.FC<ChatMessageProps> = ({ message }) => {
|
||||||
message,
|
|
||||||
}) => {
|
|
||||||
// Handle tool calls and results differently
|
// Handle tool calls and results differently
|
||||||
if (message.role === "tool-call") {
|
if (message.role === 'tool-call') {
|
||||||
return <ToolCallMessage message={message} />
|
return <ToolCallMessage message={message} />
|
||||||
}
|
}
|
||||||
|
|
||||||
if (message.role === "tool-result") {
|
if (message.role === 'tool-result') {
|
||||||
return <ToolResultMessage message={message} />
|
return <ToolResultMessage message={message} />
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle regular messages (user, assistant, system)
|
// Handle regular messages (user, assistant, system)
|
||||||
return (
|
return (
|
||||||
<div
|
<div className={`flex ${message.role === 'user' ? 'justify-end' : 'justify-start'}`}>
|
||||||
className={`flex ${
|
|
||||||
message.role === "user" ? "justify-end" : "justify-start"
|
|
||||||
}`}
|
|
||||||
>
|
|
||||||
<div
|
<div
|
||||||
className={`
|
className={`
|
||||||
${
|
${
|
||||||
message.role === "user"
|
message.role === 'user'
|
||||||
? "max-w-[80%] rounded-2xl px-3 py-2 border border-zinc-200/10 bg-white text-black"
|
? 'max-w-[80%] rounded-2xl px-3 py-2 border border-zinc-200/10 bg-white text-black'
|
||||||
: " text-zinc-900 w-full"
|
: ' text-zinc-900 w-full'
|
||||||
}`}
|
}`}
|
||||||
>
|
>
|
||||||
{/* Show reasoning block for assistant messages with reasoning */}
|
{/* Show reasoning block for assistant messages with reasoning */}
|
||||||
{message.role === "assistant" && "reasoning" in message && (message.reasoning || message.isReasoningStreaming) && (
|
{message.role === 'assistant' && 'reasoning' in message && (message.reasoning || message.isReasoningStreaming) && (
|
||||||
<ReasoningBlock
|
<ReasoningBlock
|
||||||
reasoning={message.reasoning || ""}
|
reasoning={message.reasoning || ''}
|
||||||
isStreaming={message.isReasoningStreaming}
|
isStreaming={message.isReasoningStreaming}
|
||||||
startTime={message.reasoningStartTime}
|
startTime={message.reasoningStartTime}
|
||||||
endTime={message.reasoningEndTime}
|
endTime={message.reasoningEndTime}
|
||||||
|
|
@ -55,9 +49,7 @@ const ChatMessage: React.FC<ChatMessageProps> = ({
|
||||||
remarkPlugins={[remarkGfm]}
|
remarkPlugins={[remarkGfm]}
|
||||||
rehypePlugins={[rehypeHighlight]}
|
rehypePlugins={[rehypeHighlight]}
|
||||||
components={{
|
components={{
|
||||||
table: ({ children }) => (
|
table: ({ children }) => <div className="overflow-x-scroll text-sm">{children}</div>,
|
||||||
<div className="overflow-x-scroll text-sm">{children}</div>
|
|
||||||
),
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{message.content}
|
{message.content}
|
||||||
|
|
@ -66,7 +58,7 @@ const ChatMessage: React.FC<ChatMessageProps> = ({
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
)
|
||||||
};
|
}
|
||||||
|
|
||||||
export default ChatMessage;
|
export default ChatMessage
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,12 @@
|
||||||
import React from "react";
|
import React from 'react'
|
||||||
import { PanelLeftOpen } from "lucide-react";
|
import { PanelLeftOpen } from 'lucide-react'
|
||||||
|
|
||||||
interface ChatNavbarProps {
|
interface ChatNavbarProps {
|
||||||
sidebarVisible: boolean;
|
sidebarVisible: boolean
|
||||||
setSidebarVisible: React.Dispatch<React.SetStateAction<boolean>>;
|
setSidebarVisible: React.Dispatch<React.SetStateAction<boolean>>
|
||||||
}
|
}
|
||||||
|
|
||||||
const ChatNavbar: React.FC<ChatNavbarProps> = ({
|
const ChatNavbar: React.FC<ChatNavbarProps> = ({ sidebarVisible, setSidebarVisible }) => {
|
||||||
sidebarVisible,
|
|
||||||
setSidebarVisible,
|
|
||||||
}) => {
|
|
||||||
return (
|
return (
|
||||||
<div className="sticky top-0 bg-white border-b border-zinc-200 z-10">
|
<div className="sticky top-0 bg-white border-b border-zinc-200 z-10">
|
||||||
<div className="my-3 mx-2 flex items-center justify-between">
|
<div className="my-3 mx-2 flex items-center justify-between">
|
||||||
|
|
@ -27,13 +24,11 @@ const ChatNavbar: React.FC<ChatNavbarProps> = ({
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
<h1 className="text-base font-semibold text-zinc-600 ml-2">
|
<h1 className="text-base font-semibold text-zinc-600 ml-2">AI Chat Template</h1>
|
||||||
AI Chat Template
|
|
||||||
</h1>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
)
|
||||||
};
|
}
|
||||||
|
|
||||||
export default ChatNavbar;
|
export default ChatNavbar
|
||||||
|
|
|
||||||
|
|
@ -1,36 +1,30 @@
|
||||||
import React from "react";
|
import React from 'react'
|
||||||
import {
|
import { Edit, Trash2, PanelLeftClose, PanelLeftOpen, SquarePen } from 'lucide-react'
|
||||||
Edit,
|
import ModelSelector from './ModelSelector'
|
||||||
Trash2,
|
import { McpServers } from './McpServers'
|
||||||
PanelLeftClose,
|
import { type Model } from '../types/models'
|
||||||
PanelLeftOpen,
|
import { type Message } from '../types'
|
||||||
SquarePen,
|
import { type Tool } from 'use-mcp/react'
|
||||||
} from "lucide-react";
|
|
||||||
import ModelSelector from "./ModelSelector";
|
|
||||||
import { McpServers } from "./McpServers";
|
|
||||||
import { type Model } from "../types/models";
|
|
||||||
import { type Message } from "../types";
|
|
||||||
import { type Tool } from "use-mcp/react";
|
|
||||||
|
|
||||||
interface Conversation {
|
interface Conversation {
|
||||||
id?: number;
|
id?: number
|
||||||
title: string;
|
title: string
|
||||||
messages: Message[];
|
messages: Message[]
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ChatSidebarProps {
|
interface ChatSidebarProps {
|
||||||
sidebarVisible: boolean;
|
sidebarVisible: boolean
|
||||||
setSidebarVisible: React.Dispatch<React.SetStateAction<boolean>>;
|
setSidebarVisible: React.Dispatch<React.SetStateAction<boolean>>
|
||||||
conversations: Conversation[];
|
conversations: Conversation[]
|
||||||
conversationId: number | undefined;
|
conversationId: number | undefined
|
||||||
setConversationId: React.Dispatch<React.SetStateAction<number | undefined>>;
|
setConversationId: React.Dispatch<React.SetStateAction<number | undefined>>
|
||||||
deleteConversation: (id: number) => void;
|
deleteConversation: (id: number) => void
|
||||||
editConversationTitle: (id: number, newTitle: string) => void;
|
editConversationTitle: (id: number, newTitle: string) => void
|
||||||
startNewConversation: () => void;
|
startNewConversation: () => void
|
||||||
selectedModel: Model;
|
selectedModel: Model
|
||||||
onModelChange: (model: Model) => void;
|
onModelChange: (model: Model) => void
|
||||||
apiKeyUpdateTrigger: number;
|
apiKeyUpdateTrigger: number
|
||||||
onMcpToolsUpdate: (tools: Tool[]) => void;
|
onMcpToolsUpdate: (tools: Tool[]) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
const ChatSidebar: React.FC<ChatSidebarProps> = ({
|
const ChatSidebar: React.FC<ChatSidebarProps> = ({
|
||||||
|
|
@ -48,21 +42,16 @@ const ChatSidebar: React.FC<ChatSidebarProps> = ({
|
||||||
onMcpToolsUpdate,
|
onMcpToolsUpdate,
|
||||||
}) => {
|
}) => {
|
||||||
const handleConversationClick = (id: number | undefined) => {
|
const handleConversationClick = (id: number | undefined) => {
|
||||||
setConversationId(id);
|
setConversationId(id)
|
||||||
if (window.matchMedia("(max-width: 768px)").matches) {
|
if (window.matchMedia('(max-width: 768px)').matches) {
|
||||||
setSidebarVisible(false);
|
setSidebarVisible(false)
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{/* Mobile overlay */}
|
{/* Mobile overlay */}
|
||||||
{sidebarVisible && (
|
{sidebarVisible && <div className="md:hidden fixed inset-0 bg-black/30 z-20" onClick={() => setSidebarVisible(false)} />}
|
||||||
<div
|
|
||||||
className="md:hidden fixed inset-0 bg-black/30 z-20"
|
|
||||||
onClick={() => setSidebarVisible(false)}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
<div
|
<div
|
||||||
className={`
|
className={`
|
||||||
fixed md:relative
|
fixed md:relative
|
||||||
|
|
@ -71,16 +60,12 @@ const ChatSidebar: React.FC<ChatSidebarProps> = ({
|
||||||
bg-zinc-50
|
bg-zinc-50
|
||||||
transition-all duration-300
|
transition-all duration-300
|
||||||
|
|
||||||
${
|
${sidebarVisible ? 'w-64 lg:w-[32rem] translate-x-0' : 'w-0 -translate-x-full md:translate-x-0'}
|
||||||
sidebarVisible
|
|
||||||
? "w-64 lg:w-[32rem] translate-x-0"
|
|
||||||
: "w-0 -translate-x-full md:translate-x-0"
|
|
||||||
}
|
|
||||||
`}
|
`}
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
className={`m-2 flex items-center justify-between
|
className={`m-2 flex items-center justify-between
|
||||||
${sidebarVisible ? "sticky" : "hidden"}
|
${sidebarVisible ? 'sticky' : 'hidden'}
|
||||||
`}
|
`}
|
||||||
>
|
>
|
||||||
<button
|
<button
|
||||||
|
|
@ -90,11 +75,7 @@ const ChatSidebar: React.FC<ChatSidebarProps> = ({
|
||||||
hover:bg-zinc-100 hover:cursor-pointer
|
hover:bg-zinc-100 hover:cursor-pointer
|
||||||
transition-colors text-zinc-600 hover:text-zinc-800"
|
transition-colors text-zinc-600 hover:text-zinc-800"
|
||||||
>
|
>
|
||||||
{sidebarVisible ? (
|
{sidebarVisible ? <PanelLeftClose size={20} /> : <PanelLeftOpen size={20} />}
|
||||||
<PanelLeftClose size={20} />
|
|
||||||
) : (
|
|
||||||
<PanelLeftOpen size={20} />
|
|
||||||
)}
|
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
className="rounded-lg p-[0.4em]
|
className="rounded-lg p-[0.4em]
|
||||||
|
|
@ -116,28 +97,21 @@ const ChatSidebar: React.FC<ChatSidebarProps> = ({
|
||||||
<li
|
<li
|
||||||
key={conversation.id}
|
key={conversation.id}
|
||||||
className={`cursor-pointer p-2 transition-colors rounded-lg ${
|
className={`cursor-pointer p-2 transition-colors rounded-lg ${
|
||||||
conversation.id === conversationId ||
|
conversation.id === conversationId || (!conversationId && !conversation.id)
|
||||||
(!conversationId && !conversation.id)
|
? 'bg-zinc-200 text-zinc-900'
|
||||||
? "bg-zinc-200 text-zinc-900"
|
: 'hover:bg-zinc-200 text-zinc-600'
|
||||||
: "hover:bg-zinc-200 text-zinc-600"
|
|
||||||
}`}
|
}`}
|
||||||
onClick={() => handleConversationClick(conversation.id)}
|
onClick={() => handleConversationClick(conversation.id)}
|
||||||
>
|
>
|
||||||
<div className="flex items-center justify-between">
|
<div className="flex items-center justify-between">
|
||||||
<span className="truncate flex-grow text-sm">
|
<span className="truncate flex-grow text-sm">{conversation.title}</span>
|
||||||
{conversation.title}
|
|
||||||
</span>
|
|
||||||
<div className="flex space-x-2 ml-2">
|
<div className="flex space-x-2 ml-2">
|
||||||
<button
|
<button
|
||||||
className="opacity-60 hover:opacity-100 transition-opacity"
|
className="opacity-60 hover:opacity-100 transition-opacity"
|
||||||
onClick={(e) => {
|
onClick={(e) => {
|
||||||
e.stopPropagation();
|
e.stopPropagation()
|
||||||
const newTitle = prompt(
|
const newTitle = prompt('Enter new title:', conversation.title)
|
||||||
"Enter new title:",
|
if (newTitle) editConversationTitle(conversation.id!, newTitle)
|
||||||
conversation.title
|
|
||||||
);
|
|
||||||
if (newTitle)
|
|
||||||
editConversationTitle(conversation.id!, newTitle);
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Edit size={14} />
|
<Edit size={14} />
|
||||||
|
|
@ -145,9 +119,9 @@ const ChatSidebar: React.FC<ChatSidebarProps> = ({
|
||||||
<button
|
<button
|
||||||
className="opacity-60 hover:opacity-100 transition-opacity"
|
className="opacity-60 hover:opacity-100 transition-opacity"
|
||||||
onClick={(e) => {
|
onClick={(e) => {
|
||||||
e.stopPropagation();
|
e.stopPropagation()
|
||||||
deleteConversation(conversation.id!);
|
deleteConversation(conversation.id!)
|
||||||
setConversationId(undefined);
|
setConversationId(undefined)
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Trash2 size={14} />
|
<Trash2 size={14} />
|
||||||
|
|
@ -161,17 +135,13 @@ const ChatSidebar: React.FC<ChatSidebarProps> = ({
|
||||||
|
|
||||||
{/* Model Selector and MCP Servers at bottom */}
|
{/* Model Selector and MCP Servers at bottom */}
|
||||||
<div className="p-2 border-t border-zinc-200 space-y-3">
|
<div className="p-2 border-t border-zinc-200 space-y-3">
|
||||||
<ModelSelector
|
<ModelSelector selectedModel={selectedModel} onModelChange={onModelChange} apiKeyUpdateTrigger={apiKeyUpdateTrigger} />
|
||||||
selectedModel={selectedModel}
|
|
||||||
onModelChange={onModelChange}
|
|
||||||
apiKeyUpdateTrigger={apiKeyUpdateTrigger}
|
|
||||||
/>
|
|
||||||
<McpServers onToolsUpdate={onMcpToolsUpdate} />
|
<McpServers onToolsUpdate={onMcpToolsUpdate} />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
);
|
)
|
||||||
};
|
}
|
||||||
|
|
||||||
export default ChatSidebar;
|
export default ChatSidebar
|
||||||
|
|
|
||||||
|
|
@ -205,12 +205,14 @@ const ConversationThread: React.FC<ConversationThreadProps> = ({
|
||||||
{currentConversation.messages
|
{currentConversation.messages
|
||||||
.filter((message) => {
|
.filter((message) => {
|
||||||
// Filter out empty assistant messages (no content and no reasoning)
|
// Filter out empty assistant messages (no content and no reasoning)
|
||||||
if (message.role === "assistant" &&
|
if (
|
||||||
(!message.content || !message.content.trim()) &&
|
message.role === 'assistant' &&
|
||||||
!("reasoning" in message && (message.reasoning || message.isReasoningStreaming))) {
|
(!message.content || !message.content.trim()) &&
|
||||||
return false;
|
!('reasoning' in message && (message.reasoning || message.isReasoningStreaming))
|
||||||
|
) {
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
return true;
|
return true
|
||||||
})
|
})
|
||||||
.map((message, index) => (
|
.map((message, index) => (
|
||||||
<ChatMessage key={index} message={message} />
|
<ChatMessage key={index} message={message} />
|
||||||
|
|
@ -242,11 +244,9 @@ const ConversationThread: React.FC<ConversationThreadProps> = ({
|
||||||
>
|
>
|
||||||
<span className="text-lg">🧠</span>
|
<span className="text-lg">🧠</span>
|
||||||
<span className="text-sm text-zinc-500">
|
<span className="text-sm text-zinc-500">
|
||||||
{hasApiKey(selectedModel.provider.id) ? (
|
{hasApiKey(selectedModel.provider.id)
|
||||||
selectedModel.name.toLowerCase() + ' (' + selectedModel.provider.name.toLowerCase() + ')'
|
? selectedModel.name.toLowerCase() + ' (' + selectedModel.provider.name.toLowerCase() + ')'
|
||||||
) : (
|
: 'none'}
|
||||||
"none"
|
|
||||||
)}
|
|
||||||
</span>
|
</span>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
|
|
@ -270,12 +270,12 @@ const ConversationThread: React.FC<ConversationThreadProps> = ({
|
||||||
}, 0)
|
}, 0)
|
||||||
|
|
||||||
if (totalServers === 0) {
|
if (totalServers === 0) {
|
||||||
return "0/0 servers, 0/0 tools"
|
return '0/0 servers, 0/0 tools'
|
||||||
}
|
}
|
||||||
|
|
||||||
return `${enabledServers}/${totalServers} servers, ${enabledTools}/${totalTools} tools`
|
return `${enabledServers}/${totalServers} servers, ${enabledTools}/${totalTools} tools`
|
||||||
} catch {
|
} catch {
|
||||||
return mcpTools.length > 0 ? `1/1 servers, ${mcpTools.length}/${mcpTools.length} tools` : "0/0 servers, 0/0 tools"
|
return mcpTools.length > 0 ? `1/1 servers, ${mcpTools.length}/${mcpTools.length} tools` : '0/0 servers, 0/0 tools'
|
||||||
}
|
}
|
||||||
})()}
|
})()}
|
||||||
</span>
|
</span>
|
||||||
|
|
@ -300,11 +300,7 @@ const ConversationThread: React.FC<ConversationThreadProps> = ({
|
||||||
apiKeyUpdateTrigger={apiKeyUpdateTrigger}
|
apiKeyUpdateTrigger={apiKeyUpdateTrigger}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<McpServerModal
|
<McpServerModal isOpen={mcpServerModal} onClose={() => setMcpServerModal(false)} onToolsUpdate={onMcpToolsUpdate} />
|
||||||
isOpen={mcpServerModal}
|
|
||||||
onClose={() => setMcpServerModal(false)}
|
|
||||||
onToolsUpdate={onMcpToolsUpdate}
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,14 +31,7 @@ function McpConnection({
|
||||||
// Update parent component with connection data
|
// Update parent component with connection data
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
onConnectionUpdate(server.id, connection)
|
onConnectionUpdate(server.id, connection)
|
||||||
}, [
|
}, [server.id, connection.state, connection.tools, connection.error, connection.log.length, connection.authUrl])
|
||||||
server.id,
|
|
||||||
connection.state,
|
|
||||||
connection.tools,
|
|
||||||
connection.error,
|
|
||||||
connection.log.length,
|
|
||||||
connection.authUrl,
|
|
||||||
])
|
|
||||||
|
|
||||||
// Return null as this is just a hook wrapper
|
// Return null as this is just a hook wrapper
|
||||||
return null
|
return null
|
||||||
|
|
@ -50,11 +43,7 @@ interface McpServerModalProps {
|
||||||
onToolsUpdate?: (tools: Tool[]) => void
|
onToolsUpdate?: (tools: Tool[]) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
const McpServerModal: React.FC<McpServerModalProps> = ({
|
const McpServerModal: React.FC<McpServerModalProps> = ({ isOpen, onClose, onToolsUpdate }) => {
|
||||||
isOpen,
|
|
||||||
onClose,
|
|
||||||
onToolsUpdate,
|
|
||||||
}) => {
|
|
||||||
const [servers, setServers] = useState<McpServer[]>(() => {
|
const [servers, setServers] = useState<McpServer[]>(() => {
|
||||||
const stored = localStorage.getItem('mcpServers')
|
const stored = localStorage.getItem('mcpServers')
|
||||||
return stored ? JSON.parse(stored) : []
|
return stored ? JSON.parse(stored) : []
|
||||||
|
|
@ -73,12 +62,16 @@ const McpServerModal: React.FC<McpServerModalProps> = ({
|
||||||
|
|
||||||
// Helper to cycle through transport types
|
// Helper to cycle through transport types
|
||||||
const cycleTransportType = () => {
|
const cycleTransportType = () => {
|
||||||
setTransportType(current => {
|
setTransportType((current) => {
|
||||||
switch (current) {
|
switch (current) {
|
||||||
case 'auto': return 'http'
|
case 'auto':
|
||||||
case 'http': return 'sse'
|
return 'http'
|
||||||
case 'sse': return 'auto'
|
case 'http':
|
||||||
default: return 'auto'
|
return 'sse'
|
||||||
|
case 'sse':
|
||||||
|
return 'auto'
|
||||||
|
default:
|
||||||
|
return 'auto'
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
@ -115,12 +108,11 @@ const McpServerModal: React.FC<McpServerModalProps> = ({
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const allTools: Tool[] = []
|
const allTools: Tool[] = []
|
||||||
|
|
||||||
servers.forEach(server => {
|
servers.forEach((server) => {
|
||||||
if (server.enabled && connectionData[server.id]?.tools) {
|
if (server.enabled && connectionData[server.id]?.tools) {
|
||||||
const serverTools = connectionData[server.id].tools.map((t: Tool) => ({
|
const serverTools = connectionData[server.id].tools.map((t: Tool) => ({
|
||||||
...t,
|
...t,
|
||||||
callTool: (args: Record<string, unknown>) =>
|
callTool: (args: Record<string, unknown>) => connectionData[server.id].callTool(t.name, args),
|
||||||
connectionData[server.id].callTool(t.name, args),
|
|
||||||
}))
|
}))
|
||||||
allTools.push(...serverTools)
|
allTools.push(...serverTools)
|
||||||
}
|
}
|
||||||
|
|
@ -139,10 +131,10 @@ const McpServerModal: React.FC<McpServerModalProps> = ({
|
||||||
id: Date.now().toString(),
|
id: Date.now().toString(),
|
||||||
url: newServerUrl.trim(),
|
url: newServerUrl.trim(),
|
||||||
enabled: true,
|
enabled: true,
|
||||||
name: new URL(newServerUrl.trim()).hostname
|
name: new URL(newServerUrl.trim()).hostname,
|
||||||
}
|
}
|
||||||
|
|
||||||
setServers(prev => [...prev, newServer])
|
setServers((prev) => [...prev, newServer])
|
||||||
setNewServerUrl('')
|
setNewServerUrl('')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -154,13 +146,13 @@ const McpServerModal: React.FC<McpServerModalProps> = ({
|
||||||
connection.disconnect()
|
connection.disconnect()
|
||||||
}
|
}
|
||||||
|
|
||||||
setServers(prev => prev.filter(s => s.id !== serverId))
|
setServers((prev) => prev.filter((s) => s.id !== serverId))
|
||||||
setConnectionData(prev => {
|
setConnectionData((prev) => {
|
||||||
const newData = { ...prev }
|
const newData = { ...prev }
|
||||||
delete newData[serverId]
|
delete newData[serverId]
|
||||||
return newData
|
return newData
|
||||||
})
|
})
|
||||||
setServerToolCounts(prev => {
|
setServerToolCounts((prev) => {
|
||||||
const newCounts = { ...prev }
|
const newCounts = { ...prev }
|
||||||
delete newCounts[serverId]
|
delete newCounts[serverId]
|
||||||
return newCounts
|
return newCounts
|
||||||
|
|
@ -169,14 +161,10 @@ const McpServerModal: React.FC<McpServerModalProps> = ({
|
||||||
|
|
||||||
// Handle toggling server enabled state
|
// Handle toggling server enabled state
|
||||||
const handleToggleServer = (serverId: string) => {
|
const handleToggleServer = (serverId: string) => {
|
||||||
setServers(prev => prev.map(server =>
|
setServers((prev) => prev.map((server) => (server.id === serverId ? { ...server, enabled: !server.enabled } : server)))
|
||||||
server.id === serverId
|
|
||||||
? { ...server, enabled: !server.enabled }
|
|
||||||
: server
|
|
||||||
))
|
|
||||||
|
|
||||||
// If disabling, disconnect
|
// If disabling, disconnect
|
||||||
const server = servers.find(s => s.id === serverId)
|
const server = servers.find((s) => s.id === serverId)
|
||||||
if (server?.enabled && connectionData[serverId]?.disconnect) {
|
if (server?.enabled && connectionData[serverId]?.disconnect) {
|
||||||
connectionData[serverId].disconnect()
|
connectionData[serverId].disconnect()
|
||||||
}
|
}
|
||||||
|
|
@ -184,16 +172,16 @@ const McpServerModal: React.FC<McpServerModalProps> = ({
|
||||||
|
|
||||||
// Handle connection update for a specific server
|
// Handle connection update for a specific server
|
||||||
const handleConnectionUpdate = (serverId: string, data: any) => {
|
const handleConnectionUpdate = (serverId: string, data: any) => {
|
||||||
setConnectionData(prev => ({
|
setConnectionData((prev) => ({
|
||||||
...prev,
|
...prev,
|
||||||
[serverId]: data
|
[serverId]: data,
|
||||||
}))
|
}))
|
||||||
|
|
||||||
// Store tool count for this server (even if it gets disabled later)
|
// Store tool count for this server (even if it gets disabled later)
|
||||||
if (data.tools && Array.isArray(data.tools)) {
|
if (data.tools && Array.isArray(data.tools)) {
|
||||||
setServerToolCounts(prev => ({
|
setServerToolCounts((prev) => ({
|
||||||
...prev,
|
...prev,
|
||||||
[serverId]: data.tools.length
|
[serverId]: data.tools.length,
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -216,48 +204,20 @@ const McpServerModal: React.FC<McpServerModalProps> = ({
|
||||||
|
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case 'discovering':
|
case 'discovering':
|
||||||
return (
|
return <span className={`${baseClasses} bg-blue-100 text-blue-800`}>Discovering</span>
|
||||||
<span className={`${baseClasses} bg-blue-100 text-blue-800`}>
|
|
||||||
Discovering
|
|
||||||
</span>
|
|
||||||
)
|
|
||||||
case 'authenticating':
|
case 'authenticating':
|
||||||
return (
|
return <span className={`${baseClasses} bg-purple-100 text-purple-800`}>Authenticating</span>
|
||||||
<span className={`${baseClasses} bg-purple-100 text-purple-800`}>
|
|
||||||
Authenticating
|
|
||||||
</span>
|
|
||||||
)
|
|
||||||
case 'connecting':
|
case 'connecting':
|
||||||
return (
|
return <span className={`${baseClasses} bg-yellow-100 text-yellow-800`}>Connecting</span>
|
||||||
<span className={`${baseClasses} bg-yellow-100 text-yellow-800`}>
|
|
||||||
Connecting
|
|
||||||
</span>
|
|
||||||
)
|
|
||||||
case 'loading':
|
case 'loading':
|
||||||
return (
|
return <span className={`${baseClasses} bg-orange-100 text-orange-800`}>Loading</span>
|
||||||
<span className={`${baseClasses} bg-orange-100 text-orange-800`}>
|
|
||||||
Loading
|
|
||||||
</span>
|
|
||||||
)
|
|
||||||
case 'ready':
|
case 'ready':
|
||||||
return (
|
return <span className={`${baseClasses} bg-green-100 text-green-800`}>Connected</span>
|
||||||
<span className={`${baseClasses} bg-green-100 text-green-800`}>
|
|
||||||
Connected
|
|
||||||
</span>
|
|
||||||
)
|
|
||||||
case 'failed':
|
case 'failed':
|
||||||
return (
|
return <span className={`${baseClasses} bg-red-100 text-red-800`}>Failed</span>
|
||||||
<span className={`${baseClasses} bg-red-100 text-red-800`}>
|
|
||||||
Failed
|
|
||||||
</span>
|
|
||||||
)
|
|
||||||
case 'not-connected':
|
case 'not-connected':
|
||||||
default:
|
default:
|
||||||
return (
|
return <span className={`${baseClasses} bg-gray-100 text-gray-800`}>Not Connected</span>
|
||||||
<span className={`${baseClasses} bg-gray-100 text-gray-800`}>
|
|
||||||
Not Connected
|
|
||||||
</span>
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -268,23 +228,14 @@ const McpServerModal: React.FC<McpServerModalProps> = ({
|
||||||
style={{ backgroundColor: 'rgba(0,0,0,0.8)' }}
|
style={{ backgroundColor: 'rgba(0,0,0,0.8)' }}
|
||||||
onClick={onClose}
|
onClick={onClose}
|
||||||
>
|
>
|
||||||
<div
|
<div className="bg-white rounded-lg shadow-xl w-full max-w-3xl max-h-[80vh] overflow-hidden" onClick={(e) => e.stopPropagation()}>
|
||||||
className="bg-white rounded-lg shadow-xl w-full max-w-3xl max-h-[80vh] overflow-hidden"
|
|
||||||
onClick={(e) => e.stopPropagation()}
|
|
||||||
>
|
|
||||||
<div className="flex items-center justify-between p-6 border-b border-zinc-200">
|
<div className="flex items-center justify-between p-6 border-b border-zinc-200">
|
||||||
<h2 className="text-xl font-semibold text-zinc-900">MCP Servers</h2>
|
<h2 className="text-xl font-semibold text-zinc-900">MCP Servers</h2>
|
||||||
<div className="flex items-center gap-2">
|
<div className="flex items-center gap-2">
|
||||||
<button
|
<button className="rounded-md border border-gray-200 p-1 hover:bg-gray-50" onClick={() => setShowSettings(!showSettings)}>
|
||||||
className="rounded-md border border-gray-200 p-1 hover:bg-gray-50"
|
|
||||||
onClick={() => setShowSettings(!showSettings)}
|
|
||||||
>
|
|
||||||
<Settings size={16} className="text-gray-500" />
|
<Settings size={16} className="text-gray-500" />
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button onClick={onClose} className="text-zinc-400 hover:text-zinc-600 p-1 cursor-pointer">
|
||||||
onClick={onClose}
|
|
||||||
className="text-zinc-400 hover:text-zinc-600 p-1 cursor-pointer"
|
|
||||||
>
|
|
||||||
<X size={24} />
|
<X size={24} />
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -344,16 +295,12 @@ const McpServerModal: React.FC<McpServerModalProps> = ({
|
||||||
{server.enabled && (
|
{server.enabled && (
|
||||||
<>
|
<>
|
||||||
{error && state === 'failed' && (
|
{error && state === 'failed' && (
|
||||||
<div className="text-sm text-red-600 p-3 bg-red-50 rounded border mb-3">
|
<div className="text-sm text-red-600 p-3 bg-red-50 rounded border mb-3">{error}</div>
|
||||||
{error}
|
|
||||||
</div>
|
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{authUrl && (
|
{authUrl && (
|
||||||
<div className="p-3 bg-orange-50 border border-orange-200 rounded mb-3">
|
<div className="p-3 bg-orange-50 border border-orange-200 rounded mb-3">
|
||||||
<p className="text-sm mb-2">
|
<p className="text-sm mb-2">Authentication required. Please click the link below:</p>
|
||||||
Authentication required. Please click the link below:
|
|
||||||
</p>
|
|
||||||
<a
|
<a
|
||||||
href={authUrl}
|
href={authUrl}
|
||||||
target="_blank"
|
target="_blank"
|
||||||
|
|
@ -368,16 +315,12 @@ const McpServerModal: React.FC<McpServerModalProps> = ({
|
||||||
|
|
||||||
{state === 'ready' && tools.length > 0 && (
|
{state === 'ready' && tools.length > 0 && (
|
||||||
<div>
|
<div>
|
||||||
<h4 className="font-medium text-sm mb-2">
|
<h4 className="font-medium text-sm mb-2">Available Tools ({tools.length})</h4>
|
||||||
Available Tools ({tools.length})
|
|
||||||
</h4>
|
|
||||||
<div className="border border-gray-200 rounded p-2 bg-gray-50 max-h-24 overflow-y-auto space-y-1">
|
<div className="border border-gray-200 rounded p-2 bg-gray-50 max-h-24 overflow-y-auto space-y-1">
|
||||||
{tools.map((tool: Tool, index: number) => (
|
{tools.map((tool: Tool, index: number) => (
|
||||||
<div key={index} className="text-xs">
|
<div key={index} className="text-xs">
|
||||||
<span className="font-medium">{tool.name}</span>
|
<span className="font-medium">{tool.name}</span>
|
||||||
{tool.description && (
|
{tool.description && <span className="text-gray-600 ml-2">- {tool.description}</span>}
|
||||||
<span className="text-gray-600 ml-2">- {tool.description}</span>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -441,7 +384,7 @@ const McpServerModal: React.FC<McpServerModalProps> = ({
|
||||||
<h3 className="font-medium text-sm mb-3">Debug Information</h3>
|
<h3 className="font-medium text-sm mb-3">Debug Information</h3>
|
||||||
<div className="text-xs space-y-2">
|
<div className="text-xs space-y-2">
|
||||||
<div>Total Servers: {servers.length}</div>
|
<div>Total Servers: {servers.length}</div>
|
||||||
<div>Enabled Servers: {servers.filter(s => s.enabled).length}</div>
|
<div>Enabled Servers: {servers.filter((s) => s.enabled).length}</div>
|
||||||
<div>Connected Servers: {Object.values(connectionData).filter((c: any) => c.state === 'ready').length}</div>
|
<div>Connected Servers: {Object.values(connectionData).filter((c: any) => c.state === 'ready').length}</div>
|
||||||
<div>Total Tools: {Object.values(connectionData).reduce((sum: number, c: any) => sum + (c.tools?.length || 0), 0)}</div>
|
<div>Total Tools: {Object.values(connectionData).reduce((sum: number, c: any) => sum + (c.tools?.length || 0), 0)}</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -452,14 +395,11 @@ const McpServerModal: React.FC<McpServerModalProps> = ({
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Render MCP connections for all enabled servers */}
|
{/* Render MCP connections for all enabled servers */}
|
||||||
{servers.filter(s => s.enabled).map(server => (
|
{servers
|
||||||
<McpConnection
|
.filter((s) => s.enabled)
|
||||||
key={server.id}
|
.map((server) => (
|
||||||
server={server}
|
<McpConnection key={server.id} server={server} onConnectionUpdate={handleConnectionUpdate} transportType={transportType} />
|
||||||
onConnectionUpdate={handleConnectionUpdate}
|
))}
|
||||||
transportType={transportType}
|
|
||||||
/>
|
|
||||||
))}
|
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,13 +3,7 @@ import { useMcp, type Tool } from 'use-mcp/react'
|
||||||
import { Settings, Info } from 'lucide-react'
|
import { Settings, Info } from 'lucide-react'
|
||||||
|
|
||||||
// MCP Connection wrapper that only renders when active
|
// MCP Connection wrapper that only renders when active
|
||||||
function McpConnection({
|
function McpConnection({ serverUrl, onConnectionUpdate }: { serverUrl: string; onConnectionUpdate: (data: any) => void }) {
|
||||||
serverUrl,
|
|
||||||
onConnectionUpdate,
|
|
||||||
}: {
|
|
||||||
serverUrl: string
|
|
||||||
onConnectionUpdate: (data: any) => void
|
|
||||||
}) {
|
|
||||||
// Use the MCP hook with the server URL
|
// Use the MCP hook with the server URL
|
||||||
const connection = useMcp({
|
const connection = useMcp({
|
||||||
url: serverUrl,
|
url: serverUrl,
|
||||||
|
|
@ -21,23 +15,13 @@ function McpConnection({
|
||||||
// Update parent component with connection data
|
// Update parent component with connection data
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
onConnectionUpdate(connection)
|
onConnectionUpdate(connection)
|
||||||
}, [
|
}, [connection.state, connection.tools, connection.error, connection.log.length, connection.authUrl])
|
||||||
connection.state,
|
|
||||||
connection.tools,
|
|
||||||
connection.error,
|
|
||||||
connection.log.length,
|
|
||||||
connection.authUrl,
|
|
||||||
])
|
|
||||||
|
|
||||||
// Return null as this is just a hook wrapper
|
// Return null as this is just a hook wrapper
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
export function McpServers({
|
export function McpServers({ onToolsUpdate }: { onToolsUpdate?: (tools: Tool[]) => void }) {
|
||||||
onToolsUpdate,
|
|
||||||
}: {
|
|
||||||
onToolsUpdate?: (tools: Tool[]) => void
|
|
||||||
}) {
|
|
||||||
const [serverUrl, setServerUrl] = useState(() => {
|
const [serverUrl, setServerUrl] = useState(() => {
|
||||||
return sessionStorage.getItem('mcpServerUrl') || ''
|
return sessionStorage.getItem('mcpServerUrl') || ''
|
||||||
})
|
})
|
||||||
|
|
@ -52,15 +36,13 @@ export function McpServers({
|
||||||
retry: () => {},
|
retry: () => {},
|
||||||
disconnect: () => {},
|
disconnect: () => {},
|
||||||
authenticate: () => Promise.resolve(undefined),
|
authenticate: () => Promise.resolve(undefined),
|
||||||
callTool: (_name: string, _args?: Record<string, unknown>) =>
|
callTool: (_name: string, _args?: Record<string, unknown>) => Promise.resolve(undefined),
|
||||||
Promise.resolve(undefined),
|
|
||||||
clearStorage: () => {},
|
clearStorage: () => {},
|
||||||
})
|
})
|
||||||
const logRef = useRef<HTMLDivElement>(null)
|
const logRef = useRef<HTMLDivElement>(null)
|
||||||
|
|
||||||
// Extract connection properties
|
// Extract connection properties
|
||||||
const { state, tools, error, log, authUrl, disconnect, authenticate } =
|
const { state, tools, error, log, authUrl, disconnect, authenticate } = connectionData
|
||||||
connectionData
|
|
||||||
|
|
||||||
// Notify parent component when tools change
|
// Notify parent component when tools change
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
@ -68,9 +50,8 @@ export function McpServers({
|
||||||
onToolsUpdate(
|
onToolsUpdate(
|
||||||
tools.map((t: Tool) => ({
|
tools.map((t: Tool) => ({
|
||||||
...t,
|
...t,
|
||||||
callTool: (args: Record<string, unknown>) =>
|
callTool: (args: Record<string, unknown>) => connectionData.callTool(t.name, args),
|
||||||
connectionData.callTool(t.name, args),
|
}))
|
||||||
})),
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}, [tools, onToolsUpdate])
|
}, [tools, onToolsUpdate])
|
||||||
|
|
@ -94,8 +75,7 @@ export function McpServers({
|
||||||
retry: () => {},
|
retry: () => {},
|
||||||
disconnect: () => {},
|
disconnect: () => {},
|
||||||
authenticate: () => Promise.resolve(undefined),
|
authenticate: () => Promise.resolve(undefined),
|
||||||
callTool: (_name: string, _args?: Record<string, unknown>) =>
|
callTool: (_name: string, _args?: Record<string, unknown>) => Promise.resolve(undefined),
|
||||||
Promise.resolve(undefined),
|
|
||||||
clearStorage: () => {},
|
clearStorage: () => {},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
@ -122,48 +102,20 @@ export function McpServers({
|
||||||
|
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case 'discovering':
|
case 'discovering':
|
||||||
return (
|
return <span className={`${baseClasses} bg-blue-100 text-blue-800`}>Discovering</span>
|
||||||
<span className={`${baseClasses} bg-blue-100 text-blue-800`}>
|
|
||||||
Discovering
|
|
||||||
</span>
|
|
||||||
)
|
|
||||||
case 'authenticating':
|
case 'authenticating':
|
||||||
return (
|
return <span className={`${baseClasses} bg-purple-100 text-purple-800`}>Authenticating</span>
|
||||||
<span className={`${baseClasses} bg-purple-100 text-purple-800`}>
|
|
||||||
Authenticating
|
|
||||||
</span>
|
|
||||||
)
|
|
||||||
case 'connecting':
|
case 'connecting':
|
||||||
return (
|
return <span className={`${baseClasses} bg-yellow-100 text-yellow-800`}>Connecting</span>
|
||||||
<span className={`${baseClasses} bg-yellow-100 text-yellow-800`}>
|
|
||||||
Connecting
|
|
||||||
</span>
|
|
||||||
)
|
|
||||||
case 'loading':
|
case 'loading':
|
||||||
return (
|
return <span className={`${baseClasses} bg-orange-100 text-orange-800`}>Loading</span>
|
||||||
<span className={`${baseClasses} bg-orange-100 text-orange-800`}>
|
|
||||||
Loading
|
|
||||||
</span>
|
|
||||||
)
|
|
||||||
case 'ready':
|
case 'ready':
|
||||||
return (
|
return <span className={`${baseClasses} bg-green-100 text-green-800`}>Connected</span>
|
||||||
<span className={`${baseClasses} bg-green-100 text-green-800`}>
|
|
||||||
Connected
|
|
||||||
</span>
|
|
||||||
)
|
|
||||||
case 'failed':
|
case 'failed':
|
||||||
return (
|
return <span className={`${baseClasses} bg-red-100 text-red-800`}>Failed</span>
|
||||||
<span className={`${baseClasses} bg-red-100 text-red-800`}>
|
|
||||||
Failed
|
|
||||||
</span>
|
|
||||||
)
|
|
||||||
case 'not-connected':
|
case 'not-connected':
|
||||||
default:
|
default:
|
||||||
return (
|
return <span className={`${baseClasses} bg-gray-100 text-gray-800`}>Not Connected</span>
|
||||||
<span className={`${baseClasses} bg-gray-100 text-gray-800`}>
|
|
||||||
Not Connected
|
|
||||||
</span>
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -183,17 +135,13 @@ export function McpServers({
|
||||||
<Info size={14} className="text-gray-400" />
|
<Info size={14} className="text-gray-400" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<button
|
<button className="rounded-md border border-gray-200 p-1 hover:bg-gray-50" onClick={() => setShowSettings(!showSettings)}>
|
||||||
className="rounded-md border border-gray-200 p-1 hover:bg-gray-50"
|
|
||||||
onClick={() => setShowSettings(!showSettings)}
|
|
||||||
>
|
|
||||||
<Settings size={16} className="text-gray-500" />
|
<Settings size={16} className="text-gray-500" />
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<p className="text-gray-500 text-xs mt-1 mb-3">
|
<p className="text-gray-500 text-xs mt-1 mb-3">
|
||||||
Connect to Model Context Protocol (MCP) servers to access additional AI
|
Connect to Model Context Protocol (MCP) servers to access additional AI capabilities.
|
||||||
capabilities.
|
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<div className="space-y-3">
|
<div className="space-y-3">
|
||||||
|
|
@ -202,11 +150,7 @@ export function McpServers({
|
||||||
{getStatusBadge()}
|
{getStatusBadge()}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{error && state === 'failed' && (
|
{error && state === 'failed' && <div className="text-xs text-red-600 p-2 bg-red-50 rounded border">{error}</div>}
|
||||||
<div className="text-xs text-red-600 p-2 bg-red-50 rounded border">
|
|
||||||
{error}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<input
|
<input
|
||||||
|
|
@ -222,8 +166,7 @@ export function McpServers({
|
||||||
disabled={isActive && state !== 'failed'}
|
disabled={isActive && state !== 'failed'}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{state === 'ready' ||
|
{state === 'ready' || (isActive && state !== 'not-connected' && state !== 'failed') ? (
|
||||||
(isActive && state !== 'not-connected' && state !== 'failed') ? (
|
|
||||||
<button
|
<button
|
||||||
className="w-full px-3 py-2 bg-orange-100 hover:bg-orange-200 text-orange-900 rounded text-sm font-medium"
|
className="w-full px-3 py-2 bg-orange-100 hover:bg-orange-200 text-orange-900 rounded text-sm font-medium"
|
||||||
onClick={handleDisconnect}
|
onClick={handleDisconnect}
|
||||||
|
|
@ -244,9 +187,7 @@ export function McpServers({
|
||||||
{/* Authentication Link if needed */}
|
{/* Authentication Link if needed */}
|
||||||
{authUrl && (
|
{authUrl && (
|
||||||
<div className="p-3 bg-orange-50 border border-orange-200 rounded">
|
<div className="p-3 bg-orange-50 border border-orange-200 rounded">
|
||||||
<p className="text-xs mb-2">
|
<p className="text-xs mb-2">Authentication required. Please click the link below:</p>
|
||||||
Authentication required. Please click the link below:
|
|
||||||
</p>
|
|
||||||
<a
|
<a
|
||||||
href={authUrl}
|
href={authUrl}
|
||||||
target="_blank"
|
target="_blank"
|
||||||
|
|
@ -262,21 +203,12 @@ export function McpServers({
|
||||||
{/* Tools display when connected */}
|
{/* Tools display when connected */}
|
||||||
{state === 'ready' && tools.length > 0 && (
|
{state === 'ready' && tools.length > 0 && (
|
||||||
<div>
|
<div>
|
||||||
<h3 className="font-medium text-xs mb-2">
|
<h3 className="font-medium text-xs mb-2">Available Tools ({tools.length})</h3>
|
||||||
Available Tools ({tools.length})
|
|
||||||
</h3>
|
|
||||||
<div className="border border-gray-200 rounded p-2 bg-gray-50 max-h-32 overflow-y-auto space-y-2">
|
<div className="border border-gray-200 rounded p-2 bg-gray-50 max-h-32 overflow-y-auto space-y-2">
|
||||||
{tools.map((tool: Tool, index: number) => (
|
{tools.map((tool: Tool, index: number) => (
|
||||||
<div
|
<div key={index} className="text-xs pb-2 border-b border-gray-100 last:border-b-0">
|
||||||
key={index}
|
|
||||||
className="text-xs pb-2 border-b border-gray-100 last:border-b-0"
|
|
||||||
>
|
|
||||||
<span className="font-medium">{tool.name}</span>
|
<span className="font-medium">{tool.name}</span>
|
||||||
{tool.description && (
|
{tool.description && <p className="text-gray-500 mt-1 text-xs">{tool.description}</p>}
|
||||||
<p className="text-gray-500 mt-1 text-xs">
|
|
||||||
{tool.description}
|
|
||||||
</p>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -287,10 +219,7 @@ export function McpServers({
|
||||||
{showSettings && (
|
{showSettings && (
|
||||||
<div>
|
<div>
|
||||||
<label className="font-medium text-xs block mb-2">Debug Log</label>
|
<label className="font-medium text-xs block mb-2">Debug Log</label>
|
||||||
<div
|
<div ref={logRef} className="border border-gray-200 rounded p-2 bg-gray-50 h-32 overflow-y-auto font-mono text-xs">
|
||||||
ref={logRef}
|
|
||||||
className="border border-gray-200 rounded p-2 bg-gray-50 h-32 overflow-y-auto font-mono text-xs"
|
|
||||||
>
|
|
||||||
{log.length > 0 ? (
|
{log.length > 0 ? (
|
||||||
log.map((entry: any, index: number) => (
|
log.map((entry: any, index: number) => (
|
||||||
<div
|
<div
|
||||||
|
|
@ -330,12 +259,7 @@ export function McpServers({
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Only render the actual MCP connection when active */}
|
{/* Only render the actual MCP connection when active */}
|
||||||
{isActive && (
|
{isActive && <McpConnection serverUrl={serverUrl} onConnectionUpdate={setConnectionData} />}
|
||||||
<McpConnection
|
|
||||||
serverUrl={serverUrl}
|
|
||||||
onConnectionUpdate={setConnectionData}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</section>
|
</section>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ const ModelSelectionModal: React.FC<ModelSelectionModalProps> = ({
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const statuses: Record<string, boolean> = {}
|
const statuses: Record<string, boolean> = {}
|
||||||
availableModels.forEach(model => {
|
availableModels.forEach((model) => {
|
||||||
statuses[model.provider.id] = hasApiKey(model.provider.id)
|
statuses[model.provider.id] = hasApiKey(model.provider.id)
|
||||||
})
|
})
|
||||||
setApiKeyStatuses(statuses)
|
setApiKeyStatuses(statuses)
|
||||||
|
|
@ -59,7 +59,7 @@ const ModelSelectionModal: React.FC<ModelSelectionModalProps> = ({
|
||||||
const handleApiKeySave = (apiKey: string) => {
|
const handleApiKeySave = (apiKey: string) => {
|
||||||
if (apiKeyModal.model) {
|
if (apiKeyModal.model) {
|
||||||
setApiKey(apiKeyModal.model.provider.id, apiKey)
|
setApiKey(apiKeyModal.model.provider.id, apiKey)
|
||||||
setApiKeyStatuses(prev => ({ ...prev, [apiKeyModal.model!.provider.id]: true }))
|
setApiKeyStatuses((prev) => ({ ...prev, [apiKeyModal.model!.provider.id]: true }))
|
||||||
onModelChange(apiKeyModal.model)
|
onModelChange(apiKeyModal.model)
|
||||||
setApiKeyModal({ isOpen: false, model: null })
|
setApiKeyModal({ isOpen: false, model: null })
|
||||||
onClose()
|
onClose()
|
||||||
|
|
@ -69,7 +69,7 @@ const ModelSelectionModal: React.FC<ModelSelectionModalProps> = ({
|
||||||
const handleClearApiKey = (providerId: string, e: React.MouseEvent) => {
|
const handleClearApiKey = (providerId: string, e: React.MouseEvent) => {
|
||||||
e.stopPropagation()
|
e.stopPropagation()
|
||||||
clearApiKey(providerId)
|
clearApiKey(providerId)
|
||||||
setApiKeyStatuses(prev => ({ ...prev, [providerId]: false }))
|
setApiKeyStatuses((prev) => ({ ...prev, [providerId]: false }))
|
||||||
}
|
}
|
||||||
|
|
||||||
const getStatusIcon = (providerId: string) => {
|
const getStatusIcon = (providerId: string) => {
|
||||||
|
|
@ -91,16 +91,10 @@ const ModelSelectionModal: React.FC<ModelSelectionModalProps> = ({
|
||||||
style={{ backgroundColor: 'rgba(0,0,0,0.8)' }}
|
style={{ backgroundColor: 'rgba(0,0,0,0.8)' }}
|
||||||
onClick={onClose}
|
onClick={onClose}
|
||||||
>
|
>
|
||||||
<div
|
<div className="bg-white rounded-lg shadow-xl w-full max-w-2xl max-h-[80vh] overflow-hidden" onClick={(e) => e.stopPropagation()}>
|
||||||
className="bg-white rounded-lg shadow-xl w-full max-w-2xl max-h-[80vh] overflow-hidden"
|
|
||||||
onClick={(e) => e.stopPropagation()}
|
|
||||||
>
|
|
||||||
<div className="flex items-center justify-between p-6 border-b border-zinc-200">
|
<div className="flex items-center justify-between p-6 border-b border-zinc-200">
|
||||||
<h2 className="text-xl font-semibold text-zinc-900">Select Model</h2>
|
<h2 className="text-xl font-semibold text-zinc-900">Select Model</h2>
|
||||||
<button
|
<button onClick={onClose} className="text-zinc-400 hover:text-zinc-600 p-1 cursor-pointer">
|
||||||
onClick={onClose}
|
|
||||||
className="text-zinc-400 hover:text-zinc-600 p-1 cursor-pointer"
|
|
||||||
>
|
|
||||||
<X size={24} />
|
<X size={24} />
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -115,9 +109,7 @@ const ModelSelectionModal: React.FC<ModelSelectionModalProps> = ({
|
||||||
<div
|
<div
|
||||||
key={model.id}
|
key={model.id}
|
||||||
className={`border rounded-lg p-4 cursor-pointer transition-colors ${
|
className={`border rounded-lg p-4 cursor-pointer transition-colors ${
|
||||||
isSelected
|
isSelected ? 'border-blue-500 bg-blue-50' : 'border-zinc-200 hover:border-zinc-300 hover:bg-zinc-50'
|
||||||
? 'border-blue-500 bg-blue-50'
|
|
||||||
: 'border-zinc-200 hover:border-zinc-300 hover:bg-zinc-50'
|
|
||||||
}`}
|
}`}
|
||||||
onClick={() => handleModelSelect(model)}
|
onClick={() => handleModelSelect(model)}
|
||||||
>
|
>
|
||||||
|
|
|
||||||
|
|
@ -10,11 +10,7 @@ interface ModelSelectorProps {
|
||||||
apiKeyUpdateTrigger: number
|
apiKeyUpdateTrigger: number
|
||||||
}
|
}
|
||||||
|
|
||||||
const ModelSelector: React.FC<ModelSelectorProps> = ({
|
const ModelSelector: React.FC<ModelSelectorProps> = ({ selectedModel, onModelChange, apiKeyUpdateTrigger }) => {
|
||||||
selectedModel,
|
|
||||||
onModelChange,
|
|
||||||
apiKeyUpdateTrigger,
|
|
||||||
}) => {
|
|
||||||
const [isOpen, setIsOpen] = useState(false)
|
const [isOpen, setIsOpen] = useState(false)
|
||||||
const [apiKeyModal, setApiKeyModal] = useState<{ isOpen: boolean; model: Model | null }>({
|
const [apiKeyModal, setApiKeyModal] = useState<{ isOpen: boolean; model: Model | null }>({
|
||||||
isOpen: false,
|
isOpen: false,
|
||||||
|
|
@ -25,7 +21,7 @@ const ModelSelector: React.FC<ModelSelectorProps> = ({
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const statuses: Record<string, boolean> = {}
|
const statuses: Record<string, boolean> = {}
|
||||||
availableModels.forEach(model => {
|
availableModels.forEach((model) => {
|
||||||
statuses[model.provider.id] = hasApiKey(model.provider.id)
|
statuses[model.provider.id] = hasApiKey(model.provider.id)
|
||||||
})
|
})
|
||||||
setApiKeyStatuses(statuses)
|
setApiKeyStatuses(statuses)
|
||||||
|
|
@ -58,7 +54,7 @@ const ModelSelector: React.FC<ModelSelectorProps> = ({
|
||||||
const handleApiKeySave = (apiKey: string) => {
|
const handleApiKeySave = (apiKey: string) => {
|
||||||
if (apiKeyModal.model) {
|
if (apiKeyModal.model) {
|
||||||
setApiKey(apiKeyModal.model.provider.id, apiKey)
|
setApiKey(apiKeyModal.model.provider.id, apiKey)
|
||||||
setApiKeyStatuses(prev => ({ ...prev, [apiKeyModal.model!.provider.id]: true }))
|
setApiKeyStatuses((prev) => ({ ...prev, [apiKeyModal.model!.provider.id]: true }))
|
||||||
onModelChange(apiKeyModal.model)
|
onModelChange(apiKeyModal.model)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -66,7 +62,7 @@ const ModelSelector: React.FC<ModelSelectorProps> = ({
|
||||||
const handleClearApiKey = (providerId: string, e: React.MouseEvent) => {
|
const handleClearApiKey = (providerId: string, e: React.MouseEvent) => {
|
||||||
e.stopPropagation()
|
e.stopPropagation()
|
||||||
clearApiKey(providerId)
|
clearApiKey(providerId)
|
||||||
setApiKeyStatuses(prev => ({ ...prev, [providerId]: false }))
|
setApiKeyStatuses((prev) => ({ ...prev, [providerId]: false }))
|
||||||
}
|
}
|
||||||
|
|
||||||
const getApiKeyIcon = (providerId: string) => {
|
const getApiKeyIcon = (providerId: string) => {
|
||||||
|
|
@ -74,11 +70,7 @@ const ModelSelector: React.FC<ModelSelectorProps> = ({
|
||||||
|
|
||||||
if (hasKey) {
|
if (hasKey) {
|
||||||
return (
|
return (
|
||||||
<button
|
<button onClick={(e) => handleClearApiKey(providerId, e)} className="text-zinc-400 hover:text-red-500 p-1" title="Clear token">
|
||||||
onClick={(e) => handleClearApiKey(providerId, e)}
|
|
||||||
className="text-zinc-400 hover:text-red-500 p-1"
|
|
||||||
title="Clear token"
|
|
||||||
>
|
|
||||||
<X size={14} />
|
<X size={14} />
|
||||||
</button>
|
</button>
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -1,91 +1,82 @@
|
||||||
import React, { useState, useEffect } from "react";
|
import React, { useState, useEffect } from 'react'
|
||||||
|
|
||||||
interface ReasoningBlockProps {
|
interface ReasoningBlockProps {
|
||||||
reasoning: string;
|
reasoning: string
|
||||||
isStreaming?: boolean;
|
isStreaming?: boolean
|
||||||
startTime?: number;
|
startTime?: number
|
||||||
endTime?: number;
|
endTime?: number
|
||||||
}
|
}
|
||||||
|
|
||||||
const ReasoningBlock: React.FC<ReasoningBlockProps> = ({
|
const ReasoningBlock: React.FC<ReasoningBlockProps> = ({ reasoning, isStreaming = false, startTime, endTime }) => {
|
||||||
reasoning,
|
const [isExpanded, setIsExpanded] = useState(isStreaming) // Start expanded when streaming
|
||||||
isStreaming = false,
|
|
||||||
startTime,
|
|
||||||
endTime
|
|
||||||
}) => {
|
|
||||||
const [isExpanded, setIsExpanded] = useState(isStreaming); // Start expanded when streaming
|
|
||||||
|
|
||||||
// Auto-collapse instantly when streaming finishes
|
// Auto-collapse instantly when streaming finishes
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!isStreaming && startTime && endTime) {
|
if (!isStreaming && startTime && endTime) {
|
||||||
setIsExpanded(false);
|
setIsExpanded(false)
|
||||||
}
|
|
||||||
}, [isStreaming, startTime, endTime]);
|
|
||||||
|
|
||||||
if (!reasoning || reasoning.trim().length === 0) {
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
}, [isStreaming, startTime, endTime])
|
||||||
|
|
||||||
const toggleExpanded = () => {
|
if (!reasoning || reasoning.trim().length === 0) {
|
||||||
setIsExpanded(!isExpanded);
|
return null
|
||||||
};
|
}
|
||||||
|
|
||||||
// Calculate thinking duration
|
const toggleExpanded = () => {
|
||||||
const duration = startTime && endTime ? (endTime - startTime) / 1000 : null;
|
setIsExpanded(!isExpanded)
|
||||||
|
}
|
||||||
|
|
||||||
// Format duration nicely
|
// Calculate thinking duration
|
||||||
const formatDuration = (seconds: number) => {
|
const duration = startTime && endTime ? (endTime - startTime) / 1000 : null
|
||||||
if (seconds < 1) {
|
|
||||||
return `${Math.round(seconds * 1000)}ms`;
|
|
||||||
}
|
|
||||||
return `${seconds.toFixed(1)}s`;
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
// Format duration nicely
|
||||||
<div className="mb-3">
|
const formatDuration = (seconds: number) => {
|
||||||
<div
|
if (seconds < 1) {
|
||||||
className={`text-sm text-zinc-600 border border-zinc-200 rounded-lg p-3 bg-zinc-50 cursor-pointer hover:bg-zinc-100 transition-all duration-300 ${
|
return `${Math.round(seconds * 1000)}ms`
|
||||||
isExpanded ? "border-zinc-300" : ""
|
}
|
||||||
}`}
|
return `${seconds.toFixed(1)}s`
|
||||||
onClick={toggleExpanded}
|
}
|
||||||
>
|
|
||||||
<div className="flex items-start gap-2">
|
|
||||||
<span className="text-zinc-400 text-xs mt-0.5 flex-shrink-0">💭</span>
|
|
||||||
|
|
||||||
{isExpanded ? (
|
return (
|
||||||
// Expanded view: show reasoning content
|
<div className="mb-3">
|
||||||
<div className={`flex-1 ${isStreaming ? "overflow-hidden whitespace-nowrap flex justify-end" : "whitespace-pre-wrap"}`}>
|
<div
|
||||||
<span className={isStreaming ? "inline-block" : ""}>
|
className={`text-sm text-zinc-600 border border-zinc-200 rounded-lg p-3 bg-zinc-50 cursor-pointer hover:bg-zinc-100 transition-all duration-300 ${
|
||||||
{reasoning}
|
isExpanded ? 'border-zinc-300' : ''
|
||||||
{isStreaming && (
|
}`}
|
||||||
<span className="inline-block w-2 h-4 bg-zinc-400 ml-1 animate-pulse"></span>
|
onClick={toggleExpanded}
|
||||||
)}
|
>
|
||||||
</span>
|
<div className="flex items-start gap-2">
|
||||||
</div>
|
<span className="text-zinc-400 text-xs mt-0.5 flex-shrink-0">💭</span>
|
||||||
) : (
|
|
||||||
// Collapsed view: show timing summary
|
|
||||||
<div className="flex-1">
|
|
||||||
<span className="text-zinc-500">
|
|
||||||
{isStreaming ? "Thinking..." :
|
|
||||||
duration ? `Thought for ${formatDuration(duration)}` :
|
|
||||||
"Thought process"}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<button
|
{isExpanded ? (
|
||||||
className="text-zinc-400 hover:text-zinc-600 text-xs ml-auto flex-shrink-0"
|
// Expanded view: show reasoning content
|
||||||
onClick={(e) => {
|
<div className={`flex-1 ${isStreaming ? 'overflow-hidden whitespace-nowrap flex justify-end' : 'whitespace-pre-wrap'}`}>
|
||||||
e.stopPropagation();
|
<span className={isStreaming ? 'inline-block' : ''}>
|
||||||
toggleExpanded();
|
{reasoning}
|
||||||
}}
|
{isStreaming && <span className="inline-block w-2 h-4 bg-zinc-400 ml-1 animate-pulse"></span>}
|
||||||
>
|
</span>
|
||||||
{isExpanded ? "↑" : "↓"}
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
) : (
|
||||||
);
|
// Collapsed view: show timing summary
|
||||||
};
|
<div className="flex-1">
|
||||||
|
<span className="text-zinc-500">
|
||||||
|
{isStreaming ? 'Thinking...' : duration ? `Thought for ${formatDuration(duration)}` : 'Thought process'}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
export default ReasoningBlock;
|
<button
|
||||||
|
className="text-zinc-400 hover:text-zinc-600 text-xs ml-auto flex-shrink-0"
|
||||||
|
onClick={(e) => {
|
||||||
|
e.stopPropagation()
|
||||||
|
toggleExpanded()
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{isExpanded ? '↑' : '↓'}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default ReasoningBlock
|
||||||
|
|
|
||||||
|
|
@ -20,9 +20,7 @@ const ToolCallMessage: React.FC<ToolCallMessageProps> = ({ message }) => {
|
||||||
<div className="flex-grow min-w-0">
|
<div className="flex-grow min-w-0">
|
||||||
<div className="flex items-center gap-2 mb-1">
|
<div className="flex items-center gap-2 mb-1">
|
||||||
<span className="font-medium text-blue-800 text-sm">Tool Call</span>
|
<span className="font-medium text-blue-800 text-sm">Tool Call</span>
|
||||||
<span className="text-blue-600 text-sm font-mono bg-blue-100 px-2 py-0.5 rounded">
|
<span className="text-blue-600 text-sm font-mono bg-blue-100 px-2 py-0.5 rounded">{message.toolName}</span>
|
||||||
{message.toolName}
|
|
||||||
</span>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
|
|
@ -34,15 +32,11 @@ const ToolCallMessage: React.FC<ToolCallMessageProps> = ({ message }) => {
|
||||||
{expanded ? JSON.stringify(message.toolArgs, null, 2) : `${argsPreview}${shouldTruncate ? '...' : ''}`}
|
{expanded ? JSON.stringify(message.toolArgs, null, 2) : `${argsPreview}${shouldTruncate ? '...' : ''}`}
|
||||||
</span>
|
</span>
|
||||||
{shouldTruncate && (
|
{shouldTruncate && (
|
||||||
<button className="ml-2 flex-shrink-0">
|
<button className="ml-2 flex-shrink-0">{expanded ? <ChevronDown size={14} /> : <ChevronRight size={14} />}</button>
|
||||||
{expanded ? <ChevronDown size={14} /> : <ChevronRight size={14} />}
|
|
||||||
</button>
|
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
{expanded && shouldTruncate && (
|
{expanded && shouldTruncate && (
|
||||||
<pre className="mt-2 whitespace-pre-wrap break-words max-h-64 overflow-y-auto">
|
<pre className="mt-2 whitespace-pre-wrap break-words max-h-64 overflow-y-auto">{JSON.stringify(message.toolArgs, null, 2)}</pre>
|
||||||
{JSON.stringify(message.toolArgs, null, 2)}
|
|
||||||
</pre>
|
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -20,9 +20,7 @@ const ToolResultMessage: React.FC<ToolResultMessageProps> = ({ message }) => {
|
||||||
<div className="flex-grow min-w-0">
|
<div className="flex-grow min-w-0">
|
||||||
<div className="flex items-center gap-2 mb-1">
|
<div className="flex items-center gap-2 mb-1">
|
||||||
<span className="font-medium text-green-800 text-sm">Tool Result</span>
|
<span className="font-medium text-green-800 text-sm">Tool Result</span>
|
||||||
<span className="text-green-600 text-sm font-mono bg-green-100 px-2 py-0.5 rounded">
|
<span className="text-green-600 text-sm font-mono bg-green-100 px-2 py-0.5 rounded">{message.toolName}</span>
|
||||||
{message.toolName}
|
|
||||||
</span>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
|
|
@ -34,9 +32,7 @@ const ToolResultMessage: React.FC<ToolResultMessageProps> = ({ message }) => {
|
||||||
{expanded ? JSON.stringify(message.toolResult, null, 2) : `${resultPreview}${shouldTruncate ? '...' : ''}`}
|
{expanded ? JSON.stringify(message.toolResult, null, 2) : `${resultPreview}${shouldTruncate ? '...' : ''}`}
|
||||||
</span>
|
</span>
|
||||||
{shouldTruncate && (
|
{shouldTruncate && (
|
||||||
<button className="ml-2 flex-shrink-0">
|
<button className="ml-2 flex-shrink-0">{expanded ? <ChevronDown size={14} /> : <ChevronRight size={14} />}</button>
|
||||||
{expanded ? <ChevronDown size={14} /> : <ChevronRight size={14} />}
|
|
||||||
</button>
|
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
{expanded && shouldTruncate && (
|
{expanded && shouldTruncate && (
|
||||||
|
|
|
||||||
|
|
@ -1,2 +1,2 @@
|
||||||
export const storeName = "conversations";
|
export const storeName = 'conversations'
|
||||||
export const dbName = "localgpt";
|
export const dbName = 'localgpt'
|
||||||
|
|
|
||||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue