@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
55 lines (54 loc) • 1.91 kB
JavaScript
/**
* Universal Provider Options Interface (Phase 1: Factory Pattern)
* Based on TypeScript factory pattern best practices for AI provider abstraction
*/
/**
* Parameter normalization utilities
* Converts between different parameter formats for backward compatibility
*/
export class ParameterNormalizer {
/**
* Normalize legacy parameter formats to universal format
*/
static normalizeToUniversal(optionsOrPrompt) {
if (typeof optionsOrPrompt === "string") {
return { prompt: optionsOrPrompt };
}
return optionsOrPrompt;
}
/**
* Retrieve the provider type if it exists, otherwise return null
*/
static getProviderType(options) {
return "providerType" in options ? options.providerType : null;
}
/**
* Extract provider-specific parameters safely
*/
static extractProviderOptions(options, providerType) {
const currentProviderType = ParameterNormalizer.getProviderType(options);
if (currentProviderType === providerType) {
return options;
}
// Handle case where options has providerType but doesn't match
if (currentProviderType !== null) {
const { providerType: _providerType, ...genericOptions } = options;
return genericOptions;
}
// Options don't have providerType, return as generic
return options;
}
/**
* Merge default values with user-provided options
*/
static mergeWithDefaults(options, defaults) {
return {
...defaults,
...options,
// Merge nested objects (type-safe context merging)
context: { ...defaults.context, ...options.context },
contextConfig: { ...defaults.contextConfig, ...options.contextConfig },
metadata: { ...defaults.metadata, ...options.metadata },
};
}
}