@juspay/neurolink
Version:
Universal AI Development Platform with working MCP integration, multi-provider support, and professional CLI. Built-in tools operational, 58+ external MCP servers discoverable. Connect to filesystem, GitHub, database operations, and more. Build, test, and
202 lines (201 loc) • 7.48 kB
TypeScript
/**
* NeuroLink - Unified AI Interface with Real MCP Tool Integration
*
* REDESIGNED FALLBACK CHAIN - NO CIRCULAR DEPENDENCIES
* Enhanced AI provider system with natural MCP tool access.
* Uses real MCP infrastructure for tool discovery and execution.
*/
import type { TextGenerationOptions, TextGenerationResult } from "./core/types.js";
import type { GenerateOptions, GenerateResult } from "./types/generateTypes.js";
import type { StreamOptions, StreamResult } from "./types/streamTypes.js";
import type { SimpleTool } from "./sdk/toolRegistration.js";
import type { InMemoryMCPServerConfig } from "./types/mcpTypes.js";
export interface ProviderStatus {
provider: string;
status: "working" | "failed" | "not-configured";
configured: boolean;
authenticated: boolean;
error?: string;
responseTime?: number;
model?: string;
}
export interface MCPStatus {
mcpInitialized: boolean;
totalServers: number;
availableServers: number;
autoDiscoveredCount: number;
totalTools: number;
autoDiscoveredServers: MCPServerInfo[];
customToolsCount: number;
inMemoryServersCount: number;
error?: string;
[key: string]: unknown;
}
export interface MCPServerInfo {
id: string;
name: string;
source: string;
status: "connected" | "discovered" | "failed";
hasServer: boolean;
metadata?: unknown;
}
export declare class NeuroLink {
private mcpInitialized;
private customTools;
private inMemoryServers;
constructor();
/**
* Initialize MCP registry with enhanced error handling and resource cleanup
* Uses isolated async context to prevent hanging
*/
private initializeMCP;
/**
* MAIN ENTRY POINT: Enhanced generate method with new function signature
* Replaces both generateText and legacy methods
*/
generate(optionsOrPrompt: GenerateOptions | string): Promise<GenerateResult>;
/**
* BACKWARD COMPATIBILITY: Legacy generateText method
* Internally calls generate() and converts result format
*/
generateText(options: TextGenerationOptions): Promise<TextGenerationResult>;
/**
* REDESIGNED INTERNAL GENERATION - NO CIRCULAR DEPENDENCIES
*
* This method implements a clean fallback chain:
* 1. Try MCP-enhanced generation if available
* 2. Fall back to direct provider generation
* 3. No recursive calls - each method has a specific purpose
*/
private generateTextInternal;
/**
* Try MCP-enhanced generation (no fallback recursion)
*/
private tryMCPGeneration;
/**
* Direct provider generation (no MCP, no recursion)
*/
private directProviderGeneration;
/**
* Create tool-aware system prompt that informs AI about available tools
*/
private createToolAwareSystemPrompt;
/**
* BACKWARD COMPATIBILITY: Legacy streamText method
* Internally calls stream() and converts result format
*/
streamText(prompt: string, options?: Partial<StreamOptions>): Promise<AsyncIterable<string>>;
/**
* PRIMARY METHOD: Stream content using AI (recommended for new code)
* Future-ready for multi-modal capabilities with current text focus
*/
stream(options: StreamOptions): Promise<StreamResult>;
/**
* Register a custom tool that will be available to all AI providers
* @param name - Unique name for the tool
* @param tool - Tool configuration
*/
registerTool(name: string, tool: SimpleTool): void;
/**
* Register multiple tools at once
* @param tools - Object mapping tool names to configurations
*/
registerTools(tools: Record<string, SimpleTool>): void;
/**
* Unregister a custom tool
* @param name - Name of the tool to remove
* @returns true if the tool was removed, false if it didn't exist
*/
unregisterTool(name: string): boolean;
/**
* Get all registered custom tools
* @returns Map of tool names to configurations
*/
getCustomTools(): Map<string, SimpleTool>;
/**
* Add an in-memory MCP server (from git diff)
* Allows registration of pre-instantiated server objects
* @param serverId - Unique identifier for the server
* @param config - Server configuration
*/
addInMemoryMCPServer(serverId: string, config: InMemoryMCPServerConfig): Promise<void>;
/**
* Get all registered in-memory servers
* @returns Map of server IDs to configurations
*/
getInMemoryServers(): Map<string, InMemoryMCPServerConfig>;
/**
* Execute a specific tool by name (from git diff)
* Supports both custom tools and MCP server tools
* @param toolName - Name of the tool to execute
* @param params - Parameters to pass to the tool
* @param options - Execution options
* @returns Tool execution result
*/
executeTool<T = unknown>(toolName: string, params?: unknown, options?: {
timeout?: number;
}): Promise<T>;
/**
* Get all available tools including custom and in-memory ones
* @returns Array of available tools with metadata
*/
getAllAvailableTools(): Promise<import("./index.js").ToolInfo[]>;
/**
* Get comprehensive status of all AI providers
* Primary method for provider health checking and diagnostics
*/
getProviderStatus(options?: {
quiet?: boolean;
}): Promise<ProviderStatus[]>;
/**
* Test a specific AI provider's connectivity and authentication
* @param providerName - Name of the provider to test
* @returns Promise resolving to true if provider is working
*/
testProvider(providerName: string): Promise<boolean>;
/**
* Internal method to test provider connection with minimal generation call
*/
private testProviderConnection;
/**
* Check if a provider has required environment variables configured
* @param providerName - Name of the provider to check
* @returns True if provider has required environment variables
*/
hasProviderEnvVars(providerName: string): Promise<boolean>;
/**
* Get the best available AI provider based on configuration and availability
* @param requestedProvider - Optional preferred provider name
* @returns Promise resolving to the best provider name
*/
getBestProvider(requestedProvider?: string): Promise<string>;
/**
* Get list of all available AI provider names
* @returns Array of supported provider names
*/
getAvailableProviders(): Promise<string[]>;
/**
* Validate if a provider name is supported
* @param providerName - Provider name to validate
* @returns True if provider name is valid
*/
isValidProvider(providerName: string): Promise<boolean>;
/**
* Get comprehensive MCP (Model Context Protocol) status information
* @returns Promise resolving to MCP status details
*/
getMCPStatus(): Promise<MCPStatus>;
/**
* List all configured MCP servers with their status
* @returns Promise resolving to array of MCP server information
*/
listMCPServers(): Promise<MCPServerInfo[]>;
/**
* Test connectivity to a specific MCP server
* @param serverId - ID of the MCP server to test
* @returns Promise resolving to true if server is reachable
*/
testMCPServer(serverId: string): Promise<boolean>;
}
export declare const neurolink: NeuroLink;
export default neurolink;