Files
claude-task-master/src/provider-registry/index.js
Oren Me b53065713c feat: add support for MCP Sampling as AI provider (#863)
* feat: support MCP sampling

* support provider registry

* use standard config options for MCP provider

* update fastmcp to support passing params to requestSampling

* move key name definition to base provider

* moved check for required api key to provider class

* remove unused code

* more cleanup

* more cleanup

* refactor provider

* remove not needed files

* more cleanup

* more cleanup

* more cleanup

* update docs

* fix tests

* add tests

* format fix

* clean files

* merge fixes

* format fix

* feat: add support for MCP Sampling as AI provider

* initial mcp ai sdk

* fix references to old provider

* update models

* lint

* fix gemini-cli conflicts

* ran format

* Update src/provider-registry/index.js

Co-authored-by: Ralph Khreish <35776126+Crunchyman-ralph@users.noreply.github.com>

* fix circular dependency

Circular Dependency Issue  FIXED
Root Cause: BaseAIProvider was importing from index.js, which includes commands.js and other modules that eventually import back to AI providers
Solution: Changed imports to use direct paths to avoid circular dependencies:
Updated base-provider.js to import log directly from utils.js
Updated gemini-cli.js to import log directly from utils.js
Result: Fixed 11 failing tests in mcp-provider.test.js

* fix gemini test

* fix(claude-code): recover from CLI JSON truncation bug (#913) (#920)

Gracefully handle SyntaxError thrown by @anthropic-ai/claude-code when the CLI truncates large JSON outputs (4–16 kB cut-offs).\n\nKey points:\n• Detect JSON parse error + existing buffered text in both doGenerate() and doStream() code paths.\n• Convert the failure into a recoverable 'truncated' finish state and push a provider-warning.\n• Allows Task Master to continue parsing long PRDs / expand-task operations instead of crashing.\n\nA patch changeset (.changeset/claude-code-json-truncation.md) is included for the next release.\n\nRef: eyaltoledano/claude-task-master#913

* docs: fix gemini-cli authentication documentation (#923)

Remove erroneous 'gemini auth login' command references and replace with correct 'gemini' command authentication flow. Update documentation to reflect proper OAuth setup process via the gemini CLI interactive interface.

* fix tests

* fix: update ai-sdk-provider-gemini-cli to 0.0.4 for improved authentication (#932)

- Fixed authentication compatibility issues with Google auth
- Added support for 'api-key' auth type alongside 'gemini-api-key'
- Resolved "Unsupported authType: undefined" runtime errors
- Updated @google/gemini-cli-core dependency to 0.1.9
- Improved documentation and removed invalid auth references
- Maintained backward compatibility while enhancing type validation

* call logging directly

Need to patch upstream fastmcp to allow easier access and bootstrap the TM mcp logger to use the fastmcp logger which today is only exposed in the tools handler

* fix tests

* removing logs until we figure out how to pass mcp logger

* format

* fix tests

* format

* clean up

* cleanup

* readme fix

---------

Co-authored-by: Oren Melamed <oren.m@gloat.com>
Co-authored-by: Ralph Khreish <35776126+Crunchyman-ralph@users.noreply.github.com>
Co-authored-by: Ben Vargas <ben@vargas.com>
2025-07-09 10:54:38 +02:00

135 lines
3.3 KiB
JavaScript

/**
* Provider Registry - Singleton for managing AI providers
*
* This module implements a singleton registry that allows dynamic registration
* of AI providers at runtime, while maintaining compatibility with the existing
* static PROVIDERS object in ai-services-unified.js.
*/
// Singleton instance
let instance = null;
/**
* Provider Registry class - Manages dynamic provider registration
*/
class ProviderRegistry {
constructor() {
// Private provider map
this._providers = new Map();
// Flag to track initialization
this._initialized = false;
}
/**
* Get the singleton instance
* @returns {ProviderRegistry} The singleton instance
*/
static getInstance() {
if (!instance) {
instance = new ProviderRegistry();
}
return instance;
}
/**
* Initialize the registry
* @returns {ProviderRegistry} The singleton instance
*/
initialize() {
if (this._initialized) {
return this;
}
this._initialized = true;
return this;
}
/**
* Register a provider with the registry
* @param {string} providerName - The name of the provider
* @param {object} provider - The provider instance
* @param {object} options - Additional options for registration
* @returns {ProviderRegistry} The singleton instance for chaining
*/
registerProvider(providerName, provider, options = {}) {
if (!providerName || typeof providerName !== 'string') {
throw new Error('Provider name must be a non-empty string');
}
if (!provider) {
throw new Error('Provider instance is required');
}
// Validate that provider implements the required interface
if (
typeof provider.generateText !== 'function' ||
typeof provider.streamText !== 'function' ||
typeof provider.generateObject !== 'function'
) {
throw new Error('Provider must implement BaseAIProvider interface');
}
// Add provider to the registry
this._providers.set(providerName, {
instance: provider,
options,
registeredAt: new Date()
});
return this;
}
/**
* Check if a provider exists in the registry
* @param {string} providerName - The name of the provider
* @returns {boolean} True if the provider exists
*/
hasProvider(providerName) {
return this._providers.has(providerName);
}
/**
* Get a provider from the registry
* @param {string} providerName - The name of the provider
* @returns {object|null} The provider instance or null if not found
*/
getProvider(providerName) {
const providerEntry = this._providers.get(providerName);
return providerEntry ? providerEntry.instance : null;
}
/**
* Get all registered providers
* @returns {Map} Map of all registered providers
*/
getAllProviders() {
return new Map(this._providers);
}
/**
* Remove a provider from the registry
* @param {string} providerName - The name of the provider
* @returns {boolean} True if the provider was removed
*/
unregisterProvider(providerName) {
if (this._providers.has(providerName)) {
this._providers.delete(providerName);
return true;
}
return false;
}
/**
* Reset the registry (primarily for testing)
*/
reset() {
this._providers.clear();
this._initialized = false;
}
}
ProviderRegistry.getInstance().initialize(); // Ensure singleton is initialized on import
// Export singleton getter
export default ProviderRegistry;