UNPKG

@hivetechs/hive-ai

Version:

Real-time streaming AI consensus platform with HTTP+SSE MCP integration for Claude Code, VS Code, Cursor, and Windsurf - powered by OpenRouter's unified API

113 lines 5.9 kB
/** * hive-tools Capture Tool * * This tool captures content generated by an AI assistant and saves it to the knowledge base. * It's particularly useful for storing code analyses and other insights that should be preserved * for future reference. */ import { z } from "zod"; import { v4 as uuidv4 } from 'uuid'; import * as contextManager from '../../storage/contextManager.js'; import * as topicTagging from '../../storage/topicTagging.js'; // knowledgeRetrieval removed - contained direct OpenAI calls // Old consensus import removed - using new SOURCE_OF_TRUTH system // import { runHiveConsensusTool } from './consensus.js'; // Tool name and description export const hiveCaptureToolName = "capture"; export const hiveCaptureToolDescription = "Capture insights, code analyses, and other valuable content into the hive-tools knowledge base for future reference."; // Schema for the capture tool export const HiveCaptureToolSchema = z.object({ content: z.string().min(1, "Content to capture is required."), title: z.string().min(1, "Title is required for properly categorizing the captured content."), content_type: z.enum(["code_analysis", "architecture_insight", "design_pattern", "best_practice", "general"]), tags: z.array(z.string()).optional(), source_path: z.string().optional(), // Optional path to the source code being analyzed conversation_id: z.string().optional(), }); /** * Main function to run the capture tool */ export async function runHiveCaptureTool(args) { const startTime = Date.now(); try { const { content, title, content_type, tags = [], source_path, conversation_id: explicitConversationId } = args; console.log('[CAPTURE] Starting content capture process'); console.log(`[CAPTURE] Content type: ${content_type}`); console.log(`[CAPTURE] Title: ${title}`); // Generate a new conversation ID if one wasn't provided const conversationId = explicitConversationId || uuidv4(); console.log(`[CAPTURE] Using conversation ID: ${conversationId}`); // Create the conversation if it doesn't exist await contextManager.getOrCreateConversation(conversationId); // Format the content for storage const formattedContent = `# ${title}\n\n${content_type === 'code_analysis' ? '## Code Analysis' : ''}\n\n${content}`; // Add metadata const metadata = { capture_type: content_type, source_path: source_path || 'Not specified', tags: tags.join(', '), capture_time: new Date().toISOString(), }; // Store as a user message (the input/question) const capturePrompt = `Please capture the following ${content_type} with title "${title}" into the knowledge base:\n\n${content.substring(0, 100)}...`; await contextManager.addUserMessage(conversationId, capturePrompt); // TODO: Re-enable consensus integration with new SOURCE_OF_TRUTH system // Process through the consensus pipeline for additional insights and structured storage // console.log('[CAPTURE] Processing through consensus pipeline...'); // Store the content as-is for now let enhancedContent = formattedContent; console.log('[CAPTURE] Storing enhanced content in the knowledge base...'); // Add the assistant message (the stored content/answer) await contextManager.addAssistantMessage(conversationId, enhancedContent); // Tag with topics for future retrieval console.log('[CAPTURE] Tagging with topics for thematic retrieval...'); try { // Extract and tag topics const extractedTopics = await topicTagging.tagConversation(conversationId); console.log(`[CAPTURE] Tagged with topics: ${extractedTopics.join(', ')}`); // Also index for vector search as a backup approach // Knowledge indexing removed - contained direct OpenAI calls console.log('[CAPTURE] Indexed for vector-based retrieval'); // Add user-specified tags as additional topics if they aren't already present if (tags.length > 0) { console.log(`[CAPTURE] Adding user-specified tags: ${tags.join(', ')}`); // Note: In a production system, you would want to add these tags to your topic system } } catch (error) { console.error('[CAPTURE] Error during tagging and indexing:', error); } // Calculate processing time const processingTime = Date.now() - startTime; console.log(`[CAPTURE] Completed in ${processingTime}ms`); // Return success response with conversation ID for reference return { content: [ { type: "text", text: `✅ Successfully captured ${content_type}: "${title}"\n\nThis content has been processed, enhanced, and stored in the knowledge base with conversation ID: ${conversationId}\n\nThe content can be retrieved in future sessions using thematic relationship detection.`, }, ], metadata: { conversation_id: conversationId, processing_time_ms: processingTime, content_type, title, tags: tags.join(', '), source_path: source_path || 'Not specified', } }; } catch (error) { console.error(`[CAPTURE] Error:`, error); return { content: [ { type: "text", text: `Error capturing content: ${error.message || error}\n\nThis could be due to database connectivity issues or invalid input. Please check your inputs and try again.`, }, ], }; } } //# sourceMappingURL=capture.js.map