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

153 lines • 7.41 kB
import { z } from "zod"; // Removed openRouterSyncManager - now using bulletproof database import { securePipelineConfig } from '../../security/secure-pipeline-config.js'; // Tool schemas export const ListPipelineProfilesToolSchema = z.object({}); export const SetDefaultProfileToolSchema = z.object({ profile_name: z.string().describe('Name of the profile to set as default') }); export const ConfigurePipelineToolSchema = z.object({ command: z.string().describe('Configuration command: "NAME GENERATOR:MODEL REFINER:MODEL VALIDATOR:MODEL [CURATOR:MODEL]"') }); // Tool exports export const listPipelineProfilesToolName = 'list_pipeline_profiles'; export const listPipelineProfilesToolDescription = 'List all configured pipeline profiles'; export const setDefaultProfileToolName = 'set_default_profile'; export const setDefaultProfileToolDescription = 'Set a pipeline profile as the default'; export const configurePipelineToolName = 'configure_pipeline'; export const configurePipelineToolDescription = 'Configure a new pipeline profile with custom models'; // Helper function to get provider models async function getProviderModels(providerName) { try { const { getDatabase } = await import('../../storage/unified-database.js'); const database = await getDatabase(); const models = await database.all(` SELECT * FROM openrouter_models WHERE provider_name = ? AND is_active = 1 ORDER BY name `, [providerName]); return models.map((model) => ({ id: model.openrouter_id, description: model.description || `${model.name} - Context: ${model.context_window} tokens` })); } catch (error) { console.warn(`Failed to get models for ${providerName}:`, error); return []; } } // Parse a stage command in format "PROVIDER_NAME:MODEL_NAME[:TEMPERATURE]" function parseStageCommand(stageCommand) { // Support both | and : separators for backward compatibility const separator = stageCommand.includes('|') ? '|' : ':'; const parts = stageCommand.trim().split(separator); if (parts.length < 2) { throw new Error(`Invalid stage format: ${stageCommand}. Expected "PROVIDER_NAME${separator}MODEL_NAME[${separator}TEMPERATURE]"`); } const provider_name = parts[0]; const model = parts[1]; let temperature = 0.7; // default if (parts.length > 2) { temperature = parseFloat(parts[2]); if (isNaN(temperature) || temperature < 0 || temperature > 2) { throw new Error(`Invalid temperature: ${parts[2]}. Must be between 0 and 2.`); } } // Return in the format expected by secure-pipeline-config return `${provider_name}:${model}:${temperature}`; } // Tool implementations export async function runListPipelineProfilesTool() { try { // Use the secure pipeline config that the wizard uses const profiles = await securePipelineConfig.getProfiles(); if (profiles.length === 0) { return { result: "No pipeline profiles configured yet. Use the setup wizard to create profiles.\n\nRun: `hive setup`" }; } const profileList = profiles.map((profile) => { const defaultMarker = profile.is_default ? ' (default)' : ''; return `šŸ“ **${profile.name}**${defaultMarker}\n` + ` 🧠 Generator: ${profile.generator.model}\n` + ` ⚔ Refiner: ${profile.refiner.model}\n` + ` šŸ” Validator: ${profile.validator.model}\n` + ` ✨ Curator: ${profile.curator?.model || 'Same as validator'}\n` + ` šŸ“… Created: ${new Date(profile.created_at).toLocaleDateString()}`; }).join('\n\n'); return { result: `# šŸ¤– Configured Pipeline Profiles\n\n${profileList}\n\n**Commands:**\n• Set default: \`hive pipeline default <profile-name>\`\n• Create new: \`hive setup\`` }; } catch (error) { return { result: `āŒ Error listing profiles: ${error.message || 'Unknown error'}` }; } } export async function runSetDefaultProfileTool(args) { try { const { profile_name } = args; const profile = await securePipelineConfig.setDefaultProfile(profile_name); if (!profile) { return { result: `āŒ Profile "${profile_name}" not found.\n\nUse \`hive-ai pipeline list\` to see available profiles.` }; } return { result: `āœ… Set "${profile.name}" as the default pipeline profile.\n\nšŸ¤– **Active Pipeline:**\n` + `🧠 Generator: ${profile.generator.model}\n` + `⚔ Refiner: ${profile.refiner.model}\n` + `šŸ” Validator: ${profile.validator.model}\n` + `✨ Curator: ${profile.curator?.model || 'Same as validator'}` }; } catch (error) { return { result: `āŒ Error setting default profile: ${error.message || 'Unknown error'}` }; } } export async function runConfigurePipelineTool(args) { try { const { command } = args; // Parse command: "ProfileName Generator:Model Refiner:Model Validator:Model [Curator:Model]" const parts = command.trim().split(/\s+/); if (parts.length < 4) { return { result: `āŒ Invalid command format.\n\n**Usage:** \`ProfileName Generator:Model Refiner:Model Validator:Model [Curator:Model]\`\n\n**Example:** \`MyProfile openai:gpt-4o anthropic:claude-3-5-sonnet openai:gpt-4o-mini anthropic:claude-3-haiku\`\n\n**Tip:** Use \`hive setup\` for guided configuration.` }; } const [profileName, generatorCmd, refinerCmd, validatorCmd, curatorCmd] = parts; try { // Parse stage commands const generator = parseStageCommand(generatorCmd); const refiner = parseStageCommand(refinerCmd); const validator = parseStageCommand(validatorCmd); const curator = curatorCmd ? parseStageCommand(curatorCmd) : undefined; // Create the profile using secure-pipeline-config const profile = await securePipelineConfig.configurePipeline(profileName, generator, refiner, validator, curator); return { result: `āœ… Pipeline profile "${profile.name}" configured successfully!\n\n` + `šŸ¤– **Configuration:**\n` + `🧠 Generator: ${profile.generator.model}\n` + `⚔ Refiner: ${profile.refiner.model}\n` + `šŸ” Validator: ${profile.validator.model}\n` + `✨ Curator: ${profile.curator?.model || 'Same as validator'}\n\n` + `**Set as default:** \`hive pipeline default ${profile.name}\`\n` + `**Test consensus:** \`hive consensus "test question"\`` }; } catch (parseError) { return { result: `āŒ ${parseError.message}\n\n**Tip:** Use \`hive setup\` for guided model selection.` }; } } catch (error) { return { result: `āŒ Error configuring pipeline: ${error.message || 'Unknown error'}\n\n**Tip:** Use \`hive setup\` for guided configuration.` }; } } //# sourceMappingURL=pipeline-config.js.map