UNPKG

@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

205 lines (204 loc) 6.95 kB
/** * Object Transformation Utilities * Centralizes repeated object transformation patterns to improve code reuse and maintainability */ import type { StandardRecord, StringArray } from "../types/typeAliases.js"; /** * Transform tool execution results from AI SDK format to NeuroLink GenerateResult format * Handles both single execution and array formats with robust type checking * * @param toolExecutions - Array of tool execution results from AI SDK (optional) * @returns Array of standardized tool execution objects with name, input, output, and duration * * @example * ```typescript * const executions = transformToolExecutions([ * { name: "calculator", input: { a: 5, b: 3 }, output: 8, duration: 150 } * ]); * // Returns: [{ name: "calculator", input: { a: 5, b: 3 }, output: 8, duration: 150 }] * ``` */ export declare function transformToolExecutions(toolExecutions?: unknown[]): Array<{ name: string; input: StandardRecord; output: unknown; duration: number; }>; /** * Transform tool execution results from AI SDK format to internal format (for MCP generation) * Used in tryMCPGeneration method */ export declare function transformToolExecutionsForMCP(toolExecutions?: unknown[]): Array<{ toolName: string; executionTime: number; success: boolean; serverId?: string; }>; /** * Transform available tools from internal format to GenerateResult format * Ensures consistent tool information structure across the API with schema normalization * * @param availableTools - Array of tool definitions from various sources (MCP servers, builtin tools, etc.) * @returns Array of normalized tool descriptions with consistent schema format * * @example * ```typescript * const tools = transformAvailableTools([ * { name: "calculator", description: "Math tool", server: "builtin", inputSchema: {...} } * ]); * // Returns: [{ name: "calculator", description: "Math tool", serverId: "builtin", schema: {...} }] * ``` */ export declare function transformAvailableTools(availableTools?: Array<{ name: string; description: string; server: string; category?: string; inputSchema?: StandardRecord; parameters?: StandardRecord; schema?: StandardRecord; }>): Array<{ name: string; description: string; server: string; parameters: StandardRecord; }>; /** * Transform tools for MCP generation format * Simple transformation for internal MCP tool lists */ export declare function transformToolsForMCP(availableTools: Array<{ name: string; description: string; server: string; category?: string; }>): Array<{ name: string; description: string; server: string; category?: string; }>; /** * Transform tools to expected format with required properties * Used in getAllAvailableTools method for final output */ export declare function transformToolsToExpectedFormat(tools: Array<{ name: string; description?: string; serverId?: string; category?: string; inputSchema?: StandardRecord; }>): Array<{ name: string; description: string; server: string; category?: string; inputSchema?: StandardRecord; }>; /** * Extract tool names from tool objects * Common pattern for creating arrays of tool names */ export declare function extractToolNames<T extends { name: string; }>(tools: T[]): StringArray; /** * Extract object keys as a comma-separated string * Common pattern for logging and debugging */ export declare function getKeysAsString(obj: StandardRecord, fallback?: string): string; /** * Count object properties * Common pattern for metrics and logging */ export declare function getKeyCount(obj: StandardRecord): number; /** * Transform schema properties to parameter descriptions * Used in tool-aware system prompt generation */ export declare function transformSchemaToParameterDescription(schema: { properties?: StandardRecord; required?: string[]; }): string; /** * Transform tools to tool descriptions for system prompts * Consolidated pattern for creating tool-aware prompts */ export declare function transformToolsToDescriptions(availableTools: Array<{ name: string; description: string; server: string; inputSchema?: StandardRecord; }>): string; /** * Transform parameters for validation * Common pattern when logging or checking parameter structures */ export declare function transformParamsForLogging(params: unknown): string; /** * Safe property extraction from unknown objects * Common pattern for safely accessing properties from unknown structures */ export declare function safeExtractProperty<T = unknown>(obj: unknown, key: string, fallback: T): T; /** * Safe extraction of string properties * Specialized version for string properties with fallback */ export declare function safeExtractString(obj: unknown, key: string, fallback?: string): string; /** * Safe extraction of number properties * Specialized version for number properties with fallback */ export declare function safeExtractNumber(obj: unknown, key: string, fallback?: number): number; /** * Safe extraction of boolean properties * Specialized version for boolean properties with fallback */ export declare function safeExtractBoolean(obj: unknown, key: string, fallback?: boolean): boolean; /** * Transform Map to array of values * Common pattern for converting tool maps to arrays */ export declare function mapToArray<T>(map: Map<string, T>): T[]; /** * Transform Map to array of key-value pairs * Common pattern for processing map entries */ export declare function mapToEntries<T>(map: Map<string, T>): Array<[string, T]>; /** * Group array items by a key * Common pattern for organizing tools or other objects by category */ export declare function groupBy<T>(items: T[], keyFn: (item: T) => string): Map<string, T[]>; /** * Remove undefined properties from objects * Common pattern for cleaning up object structures */ export declare function removeUndefinedProperties<T extends StandardRecord>(obj: T): T; /** * Merge objects with undefined handling * Common pattern for combining configuration objects */ export declare function mergeWithUndefinedHandling<T extends StandardRecord>(target: T, ...sources: Partial<T>[]): T; /** * Optimize tool information for collection with minimal object creation * Consolidates repeated optimization patterns across different tool sources * * @param tool - Tool information to optimize * @param defaults - Default values to apply if missing * @returns Optimized tool with minimal object creation * * @example * ```typescript * const optimized = optimizeToolForCollection(tool, { * serverId: "builtin", * category: "math" * }); * ``` */ export declare function optimizeToolForCollection<T extends Record<string, unknown>>(tool: T, defaults: { description?: string; serverId?: string; category?: string; inputSchema?: StandardRecord; }): T;