From e330dc695070c3bb60c863d09afcbf364feb5dfb Mon Sep 17 00:00:00 2001 From: Drew Peifer Date: Mon, 23 Feb 2026 02:24:34 -0500 Subject: [PATCH] gave chat web search ability, made 100vh when open --- claudash/proxy-server.js | 3 ++- claudash/src/components/ChatInterface.jsx | 2 +- claudash/src/services/claudeService.js | 30 ++++++++++++++++++----- 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/claudash/proxy-server.js b/claudash/proxy-server.js index 524f34c..5d9c986 100644 --- a/claudash/proxy-server.js +++ b/claudash/proxy-server.js @@ -26,7 +26,8 @@ app.post('/api/claude', async (req, res) => { const requestBody = { model: model, max_tokens: maxTokens, - messages: messages + messages: messages, + ...(req.body.tools && { tools: req.body.tools }) }; debugLog('Request body:', JSON.stringify(requestBody, null, 2)); diff --git a/claudash/src/components/ChatInterface.jsx b/claudash/src/components/ChatInterface.jsx index e8b23f8..35c029e 100644 --- a/claudash/src/components/ChatInterface.jsx +++ b/claudash/src/components/ChatInterface.jsx @@ -47,7 +47,7 @@ function ChatInterface({ briefing, sourceData }) { bottom: 0, left: 0, right: 0, - height: isExpanded ? '40vh' : '64px', + height: isExpanded ? '100vh' : '64px', transition: 'height 0.3s ease', display: 'flex', flexDirection: 'column', diff --git a/claudash/src/services/claudeService.js b/claudash/src/services/claudeService.js index 7d0f7ca..c3232b1 100644 --- a/claudash/src/services/claudeService.js +++ b/claudash/src/services/claudeService.js @@ -13,7 +13,7 @@ import { condenseSourcesForClaude } from './sourceParser'; * @param {Array} messages - Optional message history * @returns {Promise} Claude's response */ -async function callClaude(prompt, messages = []) { +async function callClaude(prompt, messages = [], tools = null) { const apiKey = import.meta.env.REACT_APP_ANTHROPIC_API_KEY; if (!apiKey || apiKey === 'sk-ant-your-key-here') { @@ -35,7 +35,8 @@ async function callClaude(prompt, messages = []) { messages: [ ...messages, { role: 'user', content: prompt } - ] + ], + ...(tools && { tools }) }; debugLog('Sending request to proxy...'); @@ -60,11 +61,19 @@ async function callClaude(prompt, messages = []) { const data = await response.json(); debugLog('Response data structure:', Object.keys(data)); - debugLog('Response content:', data.content?.[0]?.text?.substring(0, 200) + '...'); + debugLog('Response content blocks:', data.content?.length); debugLog('Usage data:', data.usage); + // Find the text block — when web search is used there may be tool_use/tool_result + // blocks before the final text block + const textBlock = data.content?.find(block => block.type === 'text'); + if (!textBlock) { + throw new Error('No text content in Claude response'); + } + debugLog('Response text:', textBlock.text?.substring(0, 200) + '...'); + return { - text: data.content[0].text, + text: textBlock.text, usage: data.usage // { input_tokens, output_tokens } }; } catch (error) { @@ -271,9 +280,18 @@ and other information displayed in their dashboard. Be conversational and helpfu contextPrompt += `\n\nUser's message: ${message}`; + // Enable Anthropic's built-in web search tool so Claude can look things up + const chatTools = [ + { + type: 'web_search_20250305', + name: 'web_search', + max_uses: 5 + } + ]; + try { - const result = await callClaude(contextPrompt, messages); - return result.text; // For chat, just return text for now + const result = await callClaude(contextPrompt, messages, chatTools); + return result.text; } catch (error) { console.error('Error in chat:', error); return `I apologize, but I encountered an error: ${error.message}. Please try again.`;