UNPKG

@juspay/neurolink

Version:

Universal AI Development Platform with working MCP integration, multi-provider support, voice (TTS/STT/realtime), and professional CLI. 58+ external MCP servers discoverable, multimodal file processing, RAG pipelines. Build, test, and deploy AI applicatio

239 lines (238 loc) 6.63 kB
/** * React Hooks for NeuroLink Client SDK * * Provides React hooks for interacting with NeuroLink agents, chat, workflows, * and voice features. Compatible with React 18+ and follows React hooks best practices. * * @remarks * This module requires React 18+ as a peer dependency. Install it with: * ```bash * npm install react react-dom * # or * pnpm add react react-dom * ``` * * @module @neurolink/react */ import type { ReactNode } from "react"; import type { NeuroLinkProviderProps, UseChatOptions, UseChatReturn, UseAgentOptions, UseAgentReturn, UseWorkflowOptions, UseWorkflowReturn, UseVoiceOptions, UseVoiceReturn, UseStreamOptions, UseStreamReturn, UseToolsOptions, UseToolsReturn, SpeechRecognitionInternal } from "../types/index.js"; import { NeuroLinkClient } from "./httpClient.js"; /** * Provider component for NeuroLink client * * Wraps your application to provide the NeuroLink client to all hooks. * * @example * ```tsx * import { NeuroLinkProvider } from '@neurolink/react'; * * function App() { * return ( * <NeuroLinkProvider * config={{ * baseUrl: 'https://api.neurolink.example.com', * apiKey: process.env.NEUROLINK_API_KEY, * }} * > * <YourApp /> * </NeuroLinkProvider> * ); * } * ``` */ export declare function NeuroLinkProvider({ config, children, }: NeuroLinkProviderProps & { children: ReactNode; }): ReactNode; /** * Hook to access the NeuroLink client * * Must be used within a NeuroLinkProvider. * * @throws Error if used outside of NeuroLinkProvider */ export declare function useNeuroLinkClient(): NeuroLinkClient; /** * React hook for chat interactions with NeuroLink agents * * Provides a chat interface with support for streaming responses, * tool calls, and conversation history management. * * @example Basic usage * ```tsx * function ChatComponent() { * const { messages, input, handleInputChange, handleSubmit, isLoading } = useChat({ * api: '/api/chat', * agentId: 'my-agent', * }); * * return ( * <div> * {messages.map(m => ( * <div key={m.id} className={m.role}> * {m.content} * </div> * ))} * <form onSubmit={handleSubmit}> * <input value={input} onChange={handleInputChange} /> * <button type="submit" disabled={isLoading}>Send</button> * </form> * </div> * ); * } * ``` */ export declare function useChat(options?: UseChatOptions): UseChatReturn; /** * React hook for interacting with NeuroLink agents * * Provides methods for executing agents with both streaming * and non-streaming responses, with session management. * * @example Basic usage * ```tsx * function AgentComponent() { * const { execute, isLoading, result, error } = useAgent({ * agentId: 'my-agent', * onResponse: (result) => console.log('Agent responded:', result), * }); * * return ( * <div> * <button onClick={() => execute('Hello!')}> * {isLoading ? 'Thinking...' : 'Ask Agent'} * </button> * {result && <p>{result.content}</p>} * {error && <p className="error">{error.message}</p>} * </div> * ); * } * ``` */ export declare function useAgent(options: UseAgentOptions): UseAgentReturn; /** * React hook for executing NeuroLink workflows * * Provides methods for executing, resuming, and monitoring workflows * with automatic status polling and suspension handling. * * @example Basic usage * ```tsx * function WorkflowComponent() { * const { execute, status, result, isLoading, error } = useWorkflow({ * workflowId: 'data-processing-workflow', * onComplete: (result) => console.log('Workflow completed:', result), * onStepComplete: (step) => console.log('Step completed:', step.stepId), * }); * * return ( * <div> * <button onClick={() => execute({ data: inputData })}> * Run Workflow * </button> * {status && <p>Status: {status}</p>} * {result?.output && <pre>{JSON.stringify(result.output, null, 2)}</pre>} * </div> * ); * } * ``` */ export declare function useWorkflow(options: UseWorkflowOptions): UseWorkflowReturn; /** * React hook for voice interactions with NeuroLink * * Provides voice input (speech recognition) and output (text-to-speech) * capabilities with support for real-time conversation. * * @example Basic usage * ```tsx * function VoiceComponent() { * const { * startListening, * stopListening, * speak, * isListening, * isSpeaking, * transcript, * isSupported, * } = useVoice({ * voice: 'en-US-Neural2-C', * autoPlay: true, * }); * * if (!isSupported) { * return <p>Voice not supported in this browser</p>; * } * * return ( * <div> * <button onClick={isListening ? stopListening : startListening}> * {isListening ? 'Stop' : 'Start'} Listening * </button> * <p>Transcript: {transcript}</p> * <button onClick={() => speak('Hello!')}>Speak</button> * </div> * ); * } * ``` */ export declare function useVoice(options?: UseVoiceOptions): UseVoiceReturn; /** * React hook for streaming responses from NeuroLink * * @example * ```tsx * function StreamComponent() { * const { start, stop, text, isStreaming } = useStream({ * api: '/api/stream', * }); * * return ( * <div> * <button onClick={() => start({ prompt: 'Tell me a story' })}> * Start * </button> * <button onClick={stop} disabled={!isStreaming}>Stop</button> * <p>{text}</p> * </div> * ); * } * ``` */ export declare function useStream(options?: UseStreamOptions): UseStreamReturn; /** * React hook for accessing and executing NeuroLink tools * * @example * ```tsx * function ToolsComponent() { * const { tools, execute, isLoading, error } = useTools({ * category: 'data', * }); * * return ( * <div> * {tools.map(tool => ( * <div key={tool.name}> * <h3>{tool.name}</h3> * <p>{tool.description}</p> * <button onClick={() => execute(tool.name, { input: 'test' })}> * Execute * </button> * </div> * ))} * </div> * ); * } * ``` */ export declare function useTools(options?: UseToolsOptions): UseToolsReturn; declare global { interface Window { SpeechRecognition: { new (): SpeechRecognitionInternal; }; webkitSpeechRecognition: { new (): SpeechRecognitionInternal; }; } }