feat(config): Implement new config system and resolve refactoring errors Introduced config-manager.js and new utilities (resolveEnvVariable, findProjectRoot). Removed old global CONFIG object from utils.js. Updated .taskmasterconfig, mcp.json, and .env.example. Added generateComplexityAnalysisPrompt to ui.js. Removed unused updateSubtaskById from task-manager.js. Resolved SyntaxError and ReferenceError issues across commands.js, ui.js, task-manager.js, and ai-services.js by replacing CONFIG references with config-manager getters (getDebugFlag, getProjectName, getDefaultSubtasks, isApiKeySet). Refactored 'models' command to use getConfig/writeConfig. Simplified version checking. This stabilizes the codebase after initial Task 61 refactoring, fixing CLI errors and enabling subsequent work on Subtasks 61.34 and 61.35.
2025-04-20 01:09:30 -04:00
/ * *
* ai - services - unified . js
2025-04-22 02:42:04 -04:00
* Centralized AI service layer using provider modules and config - manager .
feat(config): Implement new config system and resolve refactoring errors Introduced config-manager.js and new utilities (resolveEnvVariable, findProjectRoot). Removed old global CONFIG object from utils.js. Updated .taskmasterconfig, mcp.json, and .env.example. Added generateComplexityAnalysisPrompt to ui.js. Removed unused updateSubtaskById from task-manager.js. Resolved SyntaxError and ReferenceError issues across commands.js, ui.js, task-manager.js, and ai-services.js by replacing CONFIG references with config-manager getters (getDebugFlag, getProjectName, getDefaultSubtasks, isApiKeySet). Refactored 'models' command to use getConfig/writeConfig. Simplified version checking. This stabilizes the codebase after initial Task 61 refactoring, fixing CLI errors and enabling subsequent work on Subtasks 61.34 and 61.35.
2025-04-20 01:09:30 -04:00
* /
2025-04-22 02:42:04 -04:00
// Vercel AI SDK functions are NOT called directly anymore.
// import { generateText, streamText, generateObject } from 'ai';
// --- Core Dependencies ---
import {
2025-04-28 14:38:01 -04:00
getMainProvider ,
2025-04-22 02:42:04 -04:00
getMainModelId ,
getResearchProvider ,
getResearchModelId ,
getFallbackProvider ,
getFallbackModelId ,
getParametersForRole
2025-04-28 14:38:01 -04:00
} from './config-manager.js' ;
2025-05-01 13:45:11 -04:00
import { log , resolveEnvVariable , findProjectRoot } from './utils.js' ;
2025-04-22 02:42:04 -04:00
import * as anthropic from '../../src/ai-providers/anthropic.js' ;
import * as perplexity from '../../src/ai-providers/perplexity.js' ;
2025-04-28 14:38:01 -04:00
import * as google from '../../src/ai-providers/google.js' ;
import * as openai from '../../src/ai-providers/openai.js' ;
import * as xai from '../../src/ai-providers/xai.js' ;
import * as openrouter from '../../src/ai-providers/openrouter.js' ;
2025-04-27 03:56:23 -04:00
// TODO: Import other provider modules when implemented (ollama, etc.)
2025-04-22 02:42:04 -04:00
// --- Provider Function Map ---
// Maps provider names (lowercase) to their respective service functions
const PROVIDER _FUNCTIONS = {
anthropic : {
generateText : anthropic . generateAnthropicText ,
streamText : anthropic . streamAnthropicText ,
generateObject : anthropic . generateAnthropicObject
} ,
perplexity : {
generateText : perplexity . generatePerplexityText ,
streamText : perplexity . streamPerplexityText ,
generateObject : perplexity . generatePerplexityObject
2025-04-27 01:23:18 -04:00
} ,
google : {
// Add Google entry
generateText : google . generateGoogleText ,
streamText : google . streamGoogleText ,
generateObject : google . generateGoogleObject
2025-04-27 03:56:23 -04:00
} ,
openai : {
// ADD: OpenAI entry
generateText : openai . generateOpenAIText ,
streamText : openai . streamOpenAIText ,
generateObject : openai . generateOpenAIObject
2025-04-27 14:47:50 -04:00
} ,
xai : {
// ADD: xAI entry
generateText : xai . generateXaiText ,
streamText : xai . streamXaiText ,
generateObject : xai . generateXaiObject // Note: Object generation might be unsupported
2025-04-27 18:23:56 -04:00
} ,
openrouter : {
// ADD: OpenRouter entry
generateText : openrouter . generateOpenRouterText ,
streamText : openrouter . streamOpenRouterText ,
generateObject : openrouter . generateOpenRouterObject
2025-04-22 02:42:04 -04:00
}
2025-04-27 03:56:23 -04:00
// TODO: Add entries for ollama, etc. when implemented
2025-04-22 02:42:04 -04:00
} ;
feat(config): Implement new config system and resolve refactoring errors Introduced config-manager.js and new utilities (resolveEnvVariable, findProjectRoot). Removed old global CONFIG object from utils.js. Updated .taskmasterconfig, mcp.json, and .env.example. Added generateComplexityAnalysisPrompt to ui.js. Removed unused updateSubtaskById from task-manager.js. Resolved SyntaxError and ReferenceError issues across commands.js, ui.js, task-manager.js, and ai-services.js by replacing CONFIG references with config-manager getters (getDebugFlag, getProjectName, getDefaultSubtasks, isApiKeySet). Refactored 'models' command to use getConfig/writeConfig. Simplified version checking. This stabilizes the codebase after initial Task 61 refactoring, fixing CLI errors and enabling subsequent work on Subtasks 61.34 and 61.35.
2025-04-20 01:09:30 -04:00
// --- Configuration for Retries ---
2025-04-28 14:38:01 -04:00
const MAX _RETRIES = 2 ;
const INITIAL _RETRY _DELAY _MS = 1000 ;
feat(config): Implement new config system and resolve refactoring errors Introduced config-manager.js and new utilities (resolveEnvVariable, findProjectRoot). Removed old global CONFIG object from utils.js. Updated .taskmasterconfig, mcp.json, and .env.example. Added generateComplexityAnalysisPrompt to ui.js. Removed unused updateSubtaskById from task-manager.js. Resolved SyntaxError and ReferenceError issues across commands.js, ui.js, task-manager.js, and ai-services.js by replacing CONFIG references with config-manager getters (getDebugFlag, getProjectName, getDefaultSubtasks, isApiKeySet). Refactored 'models' command to use getConfig/writeConfig. Simplified version checking. This stabilizes the codebase after initial Task 61 refactoring, fixing CLI errors and enabling subsequent work on Subtasks 61.34 and 61.35.
2025-04-20 01:09:30 -04:00
// Helper function to check if an error is retryable
function isRetryableError ( error ) {
const errorMessage = error . message ? . toLowerCase ( ) || '' ;
return (
errorMessage . includes ( 'rate limit' ) ||
errorMessage . includes ( 'overloaded' ) ||
errorMessage . includes ( 'service temporarily unavailable' ) ||
errorMessage . includes ( 'timeout' ) ||
errorMessage . includes ( 'network error' ) ||
2025-04-28 14:38:01 -04:00
error . status === 429 ||
error . status >= 500
feat(config): Implement new config system and resolve refactoring errors Introduced config-manager.js and new utilities (resolveEnvVariable, findProjectRoot). Removed old global CONFIG object from utils.js. Updated .taskmasterconfig, mcp.json, and .env.example. Added generateComplexityAnalysisPrompt to ui.js. Removed unused updateSubtaskById from task-manager.js. Resolved SyntaxError and ReferenceError issues across commands.js, ui.js, task-manager.js, and ai-services.js by replacing CONFIG references with config-manager getters (getDebugFlag, getProjectName, getDefaultSubtasks, isApiKeySet). Refactored 'models' command to use getConfig/writeConfig. Simplified version checking. This stabilizes the codebase after initial Task 61 refactoring, fixing CLI errors and enabling subsequent work on Subtasks 61.34 and 61.35.
2025-04-20 01:09:30 -04:00
) ;
}
2025-04-27 03:56:23 -04:00
/ * *
* Extracts a user - friendly error message from a potentially complex AI error object .
* Prioritizes nested messages and falls back to the top - level message .
* @ param { Error | object | any } error - The error object .
* @ returns { string } A concise error message .
* /
function _extractErrorMessage ( error ) {
try {
// Attempt 1: Look for Vercel SDK specific nested structure (common)
if ( error ? . data ? . error ? . message ) {
return error . data . error . message ;
}
// Attempt 2: Look for nested error message directly in the error object
if ( error ? . error ? . message ) {
return error . error . message ;
}
// Attempt 3: Look for nested error message in response body if it's JSON string
if ( typeof error ? . responseBody === 'string' ) {
try {
const body = JSON . parse ( error . responseBody ) ;
if ( body ? . error ? . message ) {
return body . error . message ;
}
} catch ( parseError ) {
// Ignore if responseBody is not valid JSON
}
}
// Attempt 4: Use the top-level message if it exists
if ( typeof error ? . message === 'string' && error . message ) {
return error . message ;
}
// Attempt 5: Handle simple string errors
if ( typeof error === 'string' ) {
return error ;
}
// Fallback
return 'An unknown AI service error occurred.' ;
} catch ( e ) {
// Safety net
return 'Failed to extract error message.' ;
}
}
feat(config): Implement new config system and resolve refactoring errors Introduced config-manager.js and new utilities (resolveEnvVariable, findProjectRoot). Removed old global CONFIG object from utils.js. Updated .taskmasterconfig, mcp.json, and .env.example. Added generateComplexityAnalysisPrompt to ui.js. Removed unused updateSubtaskById from task-manager.js. Resolved SyntaxError and ReferenceError issues across commands.js, ui.js, task-manager.js, and ai-services.js by replacing CONFIG references with config-manager getters (getDebugFlag, getProjectName, getDefaultSubtasks, isApiKeySet). Refactored 'models' command to use getConfig/writeConfig. Simplified version checking. This stabilizes the codebase after initial Task 61 refactoring, fixing CLI errors and enabling subsequent work on Subtasks 61.34 and 61.35.
2025-04-20 01:09:30 -04:00
/ * *
2025-04-22 02:42:04 -04:00
* Internal helper to resolve the API key for a given provider .
* @ param { string } providerName - The name of the provider ( lowercase ) .
* @ param { object | null } session - Optional MCP session object .
2025-05-01 13:45:11 -04:00
* @ param { string | null } projectRoot - Optional project root path for . env fallback .
2025-04-22 02:42:04 -04:00
* @ returns { string | null } The API key or null if not found / needed .
* @ throws { Error } If a required API key is missing .
* /
2025-05-01 13:45:11 -04:00
function _resolveApiKey ( providerName , session , projectRoot = null ) {
2025-04-22 02:42:04 -04:00
const keyMap = {
openai : 'OPENAI_API_KEY' ,
anthropic : 'ANTHROPIC_API_KEY' ,
2025-04-28 14:38:01 -04:00
google : 'GOOGLE_API_KEY' ,
2025-04-22 02:42:04 -04:00
perplexity : 'PERPLEXITY_API_KEY' ,
mistral : 'MISTRAL_API_KEY' ,
azure : 'AZURE_OPENAI_API_KEY' ,
2025-04-28 14:38:01 -04:00
openrouter : 'OPENROUTER_API_KEY' ,
2025-04-27 03:56:23 -04:00
xai : 'XAI_API_KEY'
2025-04-22 02:42:04 -04:00
} ;
docs: Update documentation for new AI/config architecture and finalize cleanup
This commit updates all relevant documentation (READMEs, docs/*, .cursor/rules) to accurately reflect the finalized unified AI service architecture and the new configuration system (.taskmasterconfig + .env/mcp.json). It also includes the final code cleanup steps related to the refactoring.
Key Changes:
1. **Documentation Updates:**
* Revised `README.md`, `README-task-master.md`, `assets/scripts_README.md`, `docs/configuration.md`, and `docs/tutorial.md` to explain the new configuration split (.taskmasterconfig vs .env/mcp.json).
* Updated MCP configuration examples in READMEs and tutorials to only include API keys in the `env` block.
* Added/updated examples for using the `--research` flag in `docs/command-reference.md`, `docs/examples.md`, and `docs/tutorial.md`.
* Updated `.cursor/rules/ai_services.mdc`, `.cursor/rules/architecture.mdc`, `.cursor/rules/dev_workflow.mdc`, `.cursor/rules/mcp.mdc`, `.cursor/rules/taskmaster.mdc`, `.cursor/rules/utilities.mdc`, and `.cursor/rules/new_features.mdc` to align with the new architecture, removing references to old patterns/files.
* Removed internal rule links from user-facing rules (`taskmaster.mdc`, `dev_workflow.mdc`, `self_improve.mdc`).
* Deleted outdated example file `docs/ai-client-utils-example.md`.
2. **Final Code Refactor & Cleanup:**
* Corrected `update-task-by-id.js` by removing the last import from the old `ai-services.js`.
* Refactored `update-subtask-by-id.js` to correctly use the unified service and logger patterns.
* Removed the obsolete export block from `mcp-server/src/core/task-master-core.js`.
* Corrected logger implementation in `update-tasks.js` for CLI context.
* Updated API key mapping in `config-manager.js` and `ai-services-unified.js`.
3. **Configuration Files:**
* Updated API keys in `.cursor/mcp.json`, replacing `GROK_API_KEY` with `XAI_API_KEY`.
* Updated `.env.example` with current API key names.
* Added `azureOpenaiBaseUrl` to `.taskmasterconfig` example.
4. **Task Management:**
* Marked documentation subtask 61.10 as 'done'.
* Includes various other task content/status updates from the diff summary.
5. **Changeset:**
* Added `.changeset/cuddly-zebras-matter.md` for user-facing `expand`/`expand-all` improvements.
This commit concludes the major architectural refactoring (Task 61) and ensures the documentation accurately reflects the current system.
2025-04-25 14:43:12 -04:00
// Double check this -- I have had to use an api key for ollama in the past
// if (providerName === 'ollama') {
// return null; // Ollama typically doesn't require an API key for basic setup
// }
2025-04-22 02:42:04 -04:00
const envVarName = keyMap [ providerName ] ;
if ( ! envVarName ) {
throw new Error (
` Unknown provider ' ${ providerName } ' for API key resolution. `
) ;
}
2025-05-01 13:45:11 -04:00
const apiKey = resolveEnvVariable ( envVarName , session , projectRoot ) ;
2025-04-22 02:42:04 -04:00
if ( ! apiKey ) {
throw new Error (
2025-05-01 13:45:11 -04:00
` Required API key ${ envVarName } for provider ' ${ providerName } ' is not set in environment, session, or .env file. `
2025-04-22 02:42:04 -04:00
) ;
}
return apiKey ;
}
/ * *
* Internal helper to attempt a provider - specific AI API call with retries .
feat(config): Implement new config system and resolve refactoring errors Introduced config-manager.js and new utilities (resolveEnvVariable, findProjectRoot). Removed old global CONFIG object from utils.js. Updated .taskmasterconfig, mcp.json, and .env.example. Added generateComplexityAnalysisPrompt to ui.js. Removed unused updateSubtaskById from task-manager.js. Resolved SyntaxError and ReferenceError issues across commands.js, ui.js, task-manager.js, and ai-services.js by replacing CONFIG references with config-manager getters (getDebugFlag, getProjectName, getDefaultSubtasks, isApiKeySet). Refactored 'models' command to use getConfig/writeConfig. Simplified version checking. This stabilizes the codebase after initial Task 61 refactoring, fixing CLI errors and enabling subsequent work on Subtasks 61.34 and 61.35.
2025-04-20 01:09:30 -04:00
*
2025-04-22 02:42:04 -04:00
* @ param { function } providerApiFn - The specific provider function to call ( e . g . , generateAnthropicText ) .
* @ param { object } callParams - Parameters object for the provider function .
* @ param { string } providerName - Name of the provider ( for logging ) .
* @ param { string } modelId - Specific model ID ( for logging ) .
feat(config): Implement new config system and resolve refactoring errors Introduced config-manager.js and new utilities (resolveEnvVariable, findProjectRoot). Removed old global CONFIG object from utils.js. Updated .taskmasterconfig, mcp.json, and .env.example. Added generateComplexityAnalysisPrompt to ui.js. Removed unused updateSubtaskById from task-manager.js. Resolved SyntaxError and ReferenceError issues across commands.js, ui.js, task-manager.js, and ai-services.js by replacing CONFIG references with config-manager getters (getDebugFlag, getProjectName, getDefaultSubtasks, isApiKeySet). Refactored 'models' command to use getConfig/writeConfig. Simplified version checking. This stabilizes the codebase after initial Task 61 refactoring, fixing CLI errors and enabling subsequent work on Subtasks 61.34 and 61.35.
2025-04-20 01:09:30 -04:00
* @ param { string } attemptRole - The role being attempted ( for logging ) .
* @ returns { Promise < object > } The result from the successful API call .
* @ throws { Error } If the call fails after all retries .
* /
2025-04-22 02:42:04 -04:00
async function _attemptProviderCallWithRetries (
providerApiFn ,
callParams ,
providerName ,
modelId ,
feat(config): Implement new config system and resolve refactoring errors Introduced config-manager.js and new utilities (resolveEnvVariable, findProjectRoot). Removed old global CONFIG object from utils.js. Updated .taskmasterconfig, mcp.json, and .env.example. Added generateComplexityAnalysisPrompt to ui.js. Removed unused updateSubtaskById from task-manager.js. Resolved SyntaxError and ReferenceError issues across commands.js, ui.js, task-manager.js, and ai-services.js by replacing CONFIG references with config-manager getters (getDebugFlag, getProjectName, getDefaultSubtasks, isApiKeySet). Refactored 'models' command to use getConfig/writeConfig. Simplified version checking. This stabilizes the codebase after initial Task 61 refactoring, fixing CLI errors and enabling subsequent work on Subtasks 61.34 and 61.35.
2025-04-20 01:09:30 -04:00
attemptRole
) {
let retries = 0 ;
2025-04-28 14:38:01 -04:00
const fnName = providerApiFn . name ;
2025-04-22 02:42:04 -04:00
feat(config): Implement new config system and resolve refactoring errors Introduced config-manager.js and new utilities (resolveEnvVariable, findProjectRoot). Removed old global CONFIG object from utils.js. Updated .taskmasterconfig, mcp.json, and .env.example. Added generateComplexityAnalysisPrompt to ui.js. Removed unused updateSubtaskById from task-manager.js. Resolved SyntaxError and ReferenceError issues across commands.js, ui.js, task-manager.js, and ai-services.js by replacing CONFIG references with config-manager getters (getDebugFlag, getProjectName, getDefaultSubtasks, isApiKeySet). Refactored 'models' command to use getConfig/writeConfig. Simplified version checking. This stabilizes the codebase after initial Task 61 refactoring, fixing CLI errors and enabling subsequent work on Subtasks 61.34 and 61.35.
2025-04-20 01:09:30 -04:00
while ( retries <= MAX _RETRIES ) {
try {
log (
'info' ,
2025-04-22 02:42:04 -04:00
` Attempt ${ retries + 1 } / ${ MAX _RETRIES + 1 } calling ${ fnName } (Provider: ${ providerName } , Model: ${ modelId } , Role: ${ attemptRole } ) `
feat(config): Implement new config system and resolve refactoring errors Introduced config-manager.js and new utilities (resolveEnvVariable, findProjectRoot). Removed old global CONFIG object from utils.js. Updated .taskmasterconfig, mcp.json, and .env.example. Added generateComplexityAnalysisPrompt to ui.js. Removed unused updateSubtaskById from task-manager.js. Resolved SyntaxError and ReferenceError issues across commands.js, ui.js, task-manager.js, and ai-services.js by replacing CONFIG references with config-manager getters (getDebugFlag, getProjectName, getDefaultSubtasks, isApiKeySet). Refactored 'models' command to use getConfig/writeConfig. Simplified version checking. This stabilizes the codebase after initial Task 61 refactoring, fixing CLI errors and enabling subsequent work on Subtasks 61.34 and 61.35.
2025-04-20 01:09:30 -04:00
) ;
2025-04-22 02:42:04 -04:00
// Call the specific provider function directly
const result = await providerApiFn ( callParams ) ;
feat(config): Implement new config system and resolve refactoring errors Introduced config-manager.js and new utilities (resolveEnvVariable, findProjectRoot). Removed old global CONFIG object from utils.js. Updated .taskmasterconfig, mcp.json, and .env.example. Added generateComplexityAnalysisPrompt to ui.js. Removed unused updateSubtaskById from task-manager.js. Resolved SyntaxError and ReferenceError issues across commands.js, ui.js, task-manager.js, and ai-services.js by replacing CONFIG references with config-manager getters (getDebugFlag, getProjectName, getDefaultSubtasks, isApiKeySet). Refactored 'models' command to use getConfig/writeConfig. Simplified version checking. This stabilizes the codebase after initial Task 61 refactoring, fixing CLI errors and enabling subsequent work on Subtasks 61.34 and 61.35.
2025-04-20 01:09:30 -04:00
log (
'info' ,
2025-04-22 02:42:04 -04:00
` ${ fnName } succeeded for role ${ attemptRole } (Provider: ${ providerName } ) on attempt ${ retries + 1 } `
feat(config): Implement new config system and resolve refactoring errors Introduced config-manager.js and new utilities (resolveEnvVariable, findProjectRoot). Removed old global CONFIG object from utils.js. Updated .taskmasterconfig, mcp.json, and .env.example. Added generateComplexityAnalysisPrompt to ui.js. Removed unused updateSubtaskById from task-manager.js. Resolved SyntaxError and ReferenceError issues across commands.js, ui.js, task-manager.js, and ai-services.js by replacing CONFIG references with config-manager getters (getDebugFlag, getProjectName, getDefaultSubtasks, isApiKeySet). Refactored 'models' command to use getConfig/writeConfig. Simplified version checking. This stabilizes the codebase after initial Task 61 refactoring, fixing CLI errors and enabling subsequent work on Subtasks 61.34 and 61.35.
2025-04-20 01:09:30 -04:00
) ;
2025-04-28 14:38:01 -04:00
return result ;
feat(config): Implement new config system and resolve refactoring errors Introduced config-manager.js and new utilities (resolveEnvVariable, findProjectRoot). Removed old global CONFIG object from utils.js. Updated .taskmasterconfig, mcp.json, and .env.example. Added generateComplexityAnalysisPrompt to ui.js. Removed unused updateSubtaskById from task-manager.js. Resolved SyntaxError and ReferenceError issues across commands.js, ui.js, task-manager.js, and ai-services.js by replacing CONFIG references with config-manager getters (getDebugFlag, getProjectName, getDefaultSubtasks, isApiKeySet). Refactored 'models' command to use getConfig/writeConfig. Simplified version checking. This stabilizes the codebase after initial Task 61 refactoring, fixing CLI errors and enabling subsequent work on Subtasks 61.34 and 61.35.
2025-04-20 01:09:30 -04:00
} catch ( error ) {
log (
'warn' ,
2025-04-22 02:42:04 -04:00
` Attempt ${ retries + 1 } failed for role ${ attemptRole } ( ${ fnName } / ${ providerName } ): ${ error . message } `
feat(config): Implement new config system and resolve refactoring errors Introduced config-manager.js and new utilities (resolveEnvVariable, findProjectRoot). Removed old global CONFIG object from utils.js. Updated .taskmasterconfig, mcp.json, and .env.example. Added generateComplexityAnalysisPrompt to ui.js. Removed unused updateSubtaskById from task-manager.js. Resolved SyntaxError and ReferenceError issues across commands.js, ui.js, task-manager.js, and ai-services.js by replacing CONFIG references with config-manager getters (getDebugFlag, getProjectName, getDefaultSubtasks, isApiKeySet). Refactored 'models' command to use getConfig/writeConfig. Simplified version checking. This stabilizes the codebase after initial Task 61 refactoring, fixing CLI errors and enabling subsequent work on Subtasks 61.34 and 61.35.
2025-04-20 01:09:30 -04:00
) ;
if ( isRetryableError ( error ) && retries < MAX _RETRIES ) {
retries ++ ;
const delay = INITIAL _RETRY _DELAY _MS * Math . pow ( 2 , retries - 1 ) ;
log (
'info' ,
` Retryable error detected. Retrying in ${ delay / 1000 } s... `
) ;
await new Promise ( ( resolve ) => setTimeout ( resolve , delay ) ) ;
} else {
log (
'error' ,
2025-04-22 02:42:04 -04:00
` Non-retryable error or max retries reached for role ${ attemptRole } ( ${ fnName } / ${ providerName } ). `
feat(config): Implement new config system and resolve refactoring errors Introduced config-manager.js and new utilities (resolveEnvVariable, findProjectRoot). Removed old global CONFIG object from utils.js. Updated .taskmasterconfig, mcp.json, and .env.example. Added generateComplexityAnalysisPrompt to ui.js. Removed unused updateSubtaskById from task-manager.js. Resolved SyntaxError and ReferenceError issues across commands.js, ui.js, task-manager.js, and ai-services.js by replacing CONFIG references with config-manager getters (getDebugFlag, getProjectName, getDefaultSubtasks, isApiKeySet). Refactored 'models' command to use getConfig/writeConfig. Simplified version checking. This stabilizes the codebase after initial Task 61 refactoring, fixing CLI errors and enabling subsequent work on Subtasks 61.34 and 61.35.
2025-04-20 01:09:30 -04:00
) ;
2025-04-28 14:38:01 -04:00
throw error ;
feat(config): Implement new config system and resolve refactoring errors Introduced config-manager.js and new utilities (resolveEnvVariable, findProjectRoot). Removed old global CONFIG object from utils.js. Updated .taskmasterconfig, mcp.json, and .env.example. Added generateComplexityAnalysisPrompt to ui.js. Removed unused updateSubtaskById from task-manager.js. Resolved SyntaxError and ReferenceError issues across commands.js, ui.js, task-manager.js, and ai-services.js by replacing CONFIG references with config-manager getters (getDebugFlag, getProjectName, getDefaultSubtasks, isApiKeySet). Refactored 'models' command to use getConfig/writeConfig. Simplified version checking. This stabilizes the codebase after initial Task 61 refactoring, fixing CLI errors and enabling subsequent work on Subtasks 61.34 and 61.35.
2025-04-20 01:09:30 -04:00
}
}
}
2025-04-22 02:42:04 -04:00
// Should not be reached due to throw in the else block
feat(config): Implement new config system and resolve refactoring errors Introduced config-manager.js and new utilities (resolveEnvVariable, findProjectRoot). Removed old global CONFIG object from utils.js. Updated .taskmasterconfig, mcp.json, and .env.example. Added generateComplexityAnalysisPrompt to ui.js. Removed unused updateSubtaskById from task-manager.js. Resolved SyntaxError and ReferenceError issues across commands.js, ui.js, task-manager.js, and ai-services.js by replacing CONFIG references with config-manager getters (getDebugFlag, getProjectName, getDefaultSubtasks, isApiKeySet). Refactored 'models' command to use getConfig/writeConfig. Simplified version checking. This stabilizes the codebase after initial Task 61 refactoring, fixing CLI errors and enabling subsequent work on Subtasks 61.34 and 61.35.
2025-04-20 01:09:30 -04:00
throw new Error (
2025-04-22 02:42:04 -04:00
` Exhausted all retries for role ${ attemptRole } ( ${ fnName } / ${ providerName } ) `
feat(config): Implement new config system and resolve refactoring errors Introduced config-manager.js and new utilities (resolveEnvVariable, findProjectRoot). Removed old global CONFIG object from utils.js. Updated .taskmasterconfig, mcp.json, and .env.example. Added generateComplexityAnalysisPrompt to ui.js. Removed unused updateSubtaskById from task-manager.js. Resolved SyntaxError and ReferenceError issues across commands.js, ui.js, task-manager.js, and ai-services.js by replacing CONFIG references with config-manager getters (getDebugFlag, getProjectName, getDefaultSubtasks, isApiKeySet). Refactored 'models' command to use getConfig/writeConfig. Simplified version checking. This stabilizes the codebase after initial Task 61 refactoring, fixing CLI errors and enabling subsequent work on Subtasks 61.34 and 61.35.
2025-04-20 01:09:30 -04:00
) ;
}
/ * *
2025-04-22 02:42:04 -04:00
* Base logic for unified service functions .
* @ param { string } serviceType - Type of service ( 'generateText' , 'streamText' , 'generateObject' ) .
* @ param { object } params - Original parameters passed to the service function .
2025-05-01 13:45:11 -04:00
* @ param { string } [ params . projectRoot ] - Optional project root path .
2025-04-22 02:42:04 -04:00
* @ returns { Promise < any > } Result from the underlying provider call .
feat(config): Implement new config system and resolve refactoring errors Introduced config-manager.js and new utilities (resolveEnvVariable, findProjectRoot). Removed old global CONFIG object from utils.js. Updated .taskmasterconfig, mcp.json, and .env.example. Added generateComplexityAnalysisPrompt to ui.js. Removed unused updateSubtaskById from task-manager.js. Resolved SyntaxError and ReferenceError issues across commands.js, ui.js, task-manager.js, and ai-services.js by replacing CONFIG references with config-manager getters (getDebugFlag, getProjectName, getDefaultSubtasks, isApiKeySet). Refactored 'models' command to use getConfig/writeConfig. Simplified version checking. This stabilizes the codebase after initial Task 61 refactoring, fixing CLI errors and enabling subsequent work on Subtasks 61.34 and 61.35.
2025-04-20 01:09:30 -04:00
* /
2025-04-22 02:42:04 -04:00
async function _unifiedServiceRunner ( serviceType , params ) {
feat(config): Implement new config system and resolve refactoring errors Introduced config-manager.js and new utilities (resolveEnvVariable, findProjectRoot). Removed old global CONFIG object from utils.js. Updated .taskmasterconfig, mcp.json, and .env.example. Added generateComplexityAnalysisPrompt to ui.js. Removed unused updateSubtaskById from task-manager.js. Resolved SyntaxError and ReferenceError issues across commands.js, ui.js, task-manager.js, and ai-services.js by replacing CONFIG references with config-manager getters (getDebugFlag, getProjectName, getDefaultSubtasks, isApiKeySet). Refactored 'models' command to use getConfig/writeConfig. Simplified version checking. This stabilizes the codebase after initial Task 61 refactoring, fixing CLI errors and enabling subsequent work on Subtasks 61.34 and 61.35.
2025-04-20 01:09:30 -04:00
const {
role : initialRole ,
session ,
2025-05-01 13:45:11 -04:00
projectRoot ,
2025-04-22 02:42:04 -04:00
systemPrompt ,
prompt ,
schema ,
objectName ,
... restApiParams
feat(config): Implement new config system and resolve refactoring errors Introduced config-manager.js and new utilities (resolveEnvVariable, findProjectRoot). Removed old global CONFIG object from utils.js. Updated .taskmasterconfig, mcp.json, and .env.example. Added generateComplexityAnalysisPrompt to ui.js. Removed unused updateSubtaskById from task-manager.js. Resolved SyntaxError and ReferenceError issues across commands.js, ui.js, task-manager.js, and ai-services.js by replacing CONFIG references with config-manager getters (getDebugFlag, getProjectName, getDefaultSubtasks, isApiKeySet). Refactored 'models' command to use getConfig/writeConfig. Simplified version checking. This stabilizes the codebase after initial Task 61 refactoring, fixing CLI errors and enabling subsequent work on Subtasks 61.34 and 61.35.
2025-04-20 01:09:30 -04:00
} = params ;
2025-05-01 13:45:11 -04:00
log ( 'info' , ` ${ serviceType } Service called ` , {
role : initialRole ,
projectRoot
} ) ;
// Determine the effective project root (passed in or detected)
const effectiveProjectRoot = projectRoot || findProjectRoot ( ) ;
feat(config): Implement new config system and resolve refactoring errors Introduced config-manager.js and new utilities (resolveEnvVariable, findProjectRoot). Removed old global CONFIG object from utils.js. Updated .taskmasterconfig, mcp.json, and .env.example. Added generateComplexityAnalysisPrompt to ui.js. Removed unused updateSubtaskById from task-manager.js. Resolved SyntaxError and ReferenceError issues across commands.js, ui.js, task-manager.js, and ai-services.js by replacing CONFIG references with config-manager getters (getDebugFlag, getProjectName, getDefaultSubtasks, isApiKeySet). Refactored 'models' command to use getConfig/writeConfig. Simplified version checking. This stabilizes the codebase after initial Task 61 refactoring, fixing CLI errors and enabling subsequent work on Subtasks 61.34 and 61.35.
2025-04-20 01:09:30 -04:00
let sequence ;
if ( initialRole === 'main' ) {
sequence = [ 'main' , 'fallback' , 'research' ] ;
} else if ( initialRole === 'research' ) {
2025-05-01 13:45:11 -04:00
sequence = [ 'research' , 'fallback' , 'main' ] ;
} else if ( initialRole === 'fallback' ) {
sequence = [ 'fallback' , 'main' , 'research' ] ;
feat(config): Implement new config system and resolve refactoring errors Introduced config-manager.js and new utilities (resolveEnvVariable, findProjectRoot). Removed old global CONFIG object from utils.js. Updated .taskmasterconfig, mcp.json, and .env.example. Added generateComplexityAnalysisPrompt to ui.js. Removed unused updateSubtaskById from task-manager.js. Resolved SyntaxError and ReferenceError issues across commands.js, ui.js, task-manager.js, and ai-services.js by replacing CONFIG references with config-manager getters (getDebugFlag, getProjectName, getDefaultSubtasks, isApiKeySet). Refactored 'models' command to use getConfig/writeConfig. Simplified version checking. This stabilizes the codebase after initial Task 61 refactoring, fixing CLI errors and enabling subsequent work on Subtasks 61.34 and 61.35.
2025-04-20 01:09:30 -04:00
} else {
log (
'warn' ,
` Unknown initial role: ${ initialRole } . Defaulting to main -> fallback -> research sequence. `
) ;
sequence = [ 'main' , 'fallback' , 'research' ] ;
}
let lastError = null ;
2025-04-27 03:56:23 -04:00
let lastCleanErrorMessage =
'AI service call failed for all configured roles.' ;
feat(config): Implement new config system and resolve refactoring errors Introduced config-manager.js and new utilities (resolveEnvVariable, findProjectRoot). Removed old global CONFIG object from utils.js. Updated .taskmasterconfig, mcp.json, and .env.example. Added generateComplexityAnalysisPrompt to ui.js. Removed unused updateSubtaskById from task-manager.js. Resolved SyntaxError and ReferenceError issues across commands.js, ui.js, task-manager.js, and ai-services.js by replacing CONFIG references with config-manager getters (getDebugFlag, getProjectName, getDefaultSubtasks, isApiKeySet). Refactored 'models' command to use getConfig/writeConfig. Simplified version checking. This stabilizes the codebase after initial Task 61 refactoring, fixing CLI errors and enabling subsequent work on Subtasks 61.34 and 61.35.
2025-04-20 01:09:30 -04:00
for ( const currentRole of sequence ) {
2025-04-22 02:42:04 -04:00
let providerName , modelId , apiKey , roleParams , providerFnSet , providerApiFn ;
feat(config): Implement new config system and resolve refactoring errors Introduced config-manager.js and new utilities (resolveEnvVariable, findProjectRoot). Removed old global CONFIG object from utils.js. Updated .taskmasterconfig, mcp.json, and .env.example. Added generateComplexityAnalysisPrompt to ui.js. Removed unused updateSubtaskById from task-manager.js. Resolved SyntaxError and ReferenceError issues across commands.js, ui.js, task-manager.js, and ai-services.js by replacing CONFIG references with config-manager getters (getDebugFlag, getProjectName, getDefaultSubtasks, isApiKeySet). Refactored 'models' command to use getConfig/writeConfig. Simplified version checking. This stabilizes the codebase after initial Task 61 refactoring, fixing CLI errors and enabling subsequent work on Subtasks 61.34 and 61.35.
2025-04-20 01:09:30 -04:00
try {
2025-04-24 13:34:51 -04:00
log ( 'info' , ` New AI service call with role: ${ currentRole } ` ) ;
feat(config): Implement new config system and resolve refactoring errors Introduced config-manager.js and new utilities (resolveEnvVariable, findProjectRoot). Removed old global CONFIG object from utils.js. Updated .taskmasterconfig, mcp.json, and .env.example. Added generateComplexityAnalysisPrompt to ui.js. Removed unused updateSubtaskById from task-manager.js. Resolved SyntaxError and ReferenceError issues across commands.js, ui.js, task-manager.js, and ai-services.js by replacing CONFIG references with config-manager getters (getDebugFlag, getProjectName, getDefaultSubtasks, isApiKeySet). Refactored 'models' command to use getConfig/writeConfig. Simplified version checking. This stabilizes the codebase after initial Task 61 refactoring, fixing CLI errors and enabling subsequent work on Subtasks 61.34 and 61.35.
2025-04-20 01:09:30 -04:00
2025-04-22 02:42:04 -04:00
// 1. Get Config: Provider, Model, Parameters for the current role
2025-05-01 13:45:11 -04:00
// Pass effectiveProjectRoot to config getters
2025-04-22 02:42:04 -04:00
if ( currentRole === 'main' ) {
2025-05-01 13:45:11 -04:00
providerName = getMainProvider ( effectiveProjectRoot ) ;
modelId = getMainModelId ( effectiveProjectRoot ) ;
2025-04-22 02:42:04 -04:00
} else if ( currentRole === 'research' ) {
2025-05-01 13:45:11 -04:00
providerName = getResearchProvider ( effectiveProjectRoot ) ;
modelId = getResearchModelId ( effectiveProjectRoot ) ;
2025-04-22 02:42:04 -04:00
} else if ( currentRole === 'fallback' ) {
2025-05-01 13:45:11 -04:00
providerName = getFallbackProvider ( effectiveProjectRoot ) ;
modelId = getFallbackModelId ( effectiveProjectRoot ) ;
2025-04-22 02:42:04 -04:00
} else {
log (
'error' ,
` Unknown role encountered in _unifiedServiceRunner: ${ currentRole } `
) ;
lastError =
lastError || new Error ( ` Unknown AI role specified: ${ currentRole } ` ) ;
2025-04-28 14:38:01 -04:00
continue ;
2025-04-22 02:42:04 -04:00
}
feat(config): Implement new config system and resolve refactoring errors Introduced config-manager.js and new utilities (resolveEnvVariable, findProjectRoot). Removed old global CONFIG object from utils.js. Updated .taskmasterconfig, mcp.json, and .env.example. Added generateComplexityAnalysisPrompt to ui.js. Removed unused updateSubtaskById from task-manager.js. Resolved SyntaxError and ReferenceError issues across commands.js, ui.js, task-manager.js, and ai-services.js by replacing CONFIG references with config-manager getters (getDebugFlag, getProjectName, getDefaultSubtasks, isApiKeySet). Refactored 'models' command to use getConfig/writeConfig. Simplified version checking. This stabilizes the codebase after initial Task 61 refactoring, fixing CLI errors and enabling subsequent work on Subtasks 61.34 and 61.35.
2025-04-20 01:09:30 -04:00
2025-04-22 02:42:04 -04:00
if ( ! providerName || ! modelId ) {
feat(config): Implement new config system and resolve refactoring errors Introduced config-manager.js and new utilities (resolveEnvVariable, findProjectRoot). Removed old global CONFIG object from utils.js. Updated .taskmasterconfig, mcp.json, and .env.example. Added generateComplexityAnalysisPrompt to ui.js. Removed unused updateSubtaskById from task-manager.js. Resolved SyntaxError and ReferenceError issues across commands.js, ui.js, task-manager.js, and ai-services.js by replacing CONFIG references with config-manager getters (getDebugFlag, getProjectName, getDefaultSubtasks, isApiKeySet). Refactored 'models' command to use getConfig/writeConfig. Simplified version checking. This stabilizes the codebase after initial Task 61 refactoring, fixing CLI errors and enabling subsequent work on Subtasks 61.34 and 61.35.
2025-04-20 01:09:30 -04:00
log (
'warn' ,
2025-04-22 02:42:04 -04:00
` Skipping role ' ${ currentRole } ': Provider or Model ID not configured. `
feat(config): Implement new config system and resolve refactoring errors Introduced config-manager.js and new utilities (resolveEnvVariable, findProjectRoot). Removed old global CONFIG object from utils.js. Updated .taskmasterconfig, mcp.json, and .env.example. Added generateComplexityAnalysisPrompt to ui.js. Removed unused updateSubtaskById from task-manager.js. Resolved SyntaxError and ReferenceError issues across commands.js, ui.js, task-manager.js, and ai-services.js by replacing CONFIG references with config-manager getters (getDebugFlag, getProjectName, getDefaultSubtasks, isApiKeySet). Refactored 'models' command to use getConfig/writeConfig. Simplified version checking. This stabilizes the codebase after initial Task 61 refactoring, fixing CLI errors and enabling subsequent work on Subtasks 61.34 and 61.35.
2025-04-20 01:09:30 -04:00
) ;
2025-04-22 02:42:04 -04:00
lastError =
lastError ||
new Error (
` Configuration missing for role ' ${ currentRole } '. Provider: ${ providerName } , Model: ${ modelId } `
) ;
2025-04-28 14:38:01 -04:00
continue ;
2025-04-22 02:42:04 -04:00
}
2025-05-01 13:45:11 -04:00
// Pass effectiveProjectRoot to getParametersForRole
roleParams = getParametersForRole ( currentRole , effectiveProjectRoot ) ;
2025-04-22 02:42:04 -04:00
// 2. Get Provider Function Set
providerFnSet = PROVIDER _FUNCTIONS [ providerName ? . toLowerCase ( ) ] ;
if ( ! providerFnSet ) {
feat(config): Implement new config system and resolve refactoring errors Introduced config-manager.js and new utilities (resolveEnvVariable, findProjectRoot). Removed old global CONFIG object from utils.js. Updated .taskmasterconfig, mcp.json, and .env.example. Added generateComplexityAnalysisPrompt to ui.js. Removed unused updateSubtaskById from task-manager.js. Resolved SyntaxError and ReferenceError issues across commands.js, ui.js, task-manager.js, and ai-services.js by replacing CONFIG references with config-manager getters (getDebugFlag, getProjectName, getDefaultSubtasks, isApiKeySet). Refactored 'models' command to use getConfig/writeConfig. Simplified version checking. This stabilizes the codebase after initial Task 61 refactoring, fixing CLI errors and enabling subsequent work on Subtasks 61.34 and 61.35.
2025-04-20 01:09:30 -04:00
log (
'warn' ,
2025-04-22 02:42:04 -04:00
` Skipping role ' ${ currentRole } ': Provider ' ${ providerName } ' not supported or map entry missing. `
feat(config): Implement new config system and resolve refactoring errors Introduced config-manager.js and new utilities (resolveEnvVariable, findProjectRoot). Removed old global CONFIG object from utils.js. Updated .taskmasterconfig, mcp.json, and .env.example. Added generateComplexityAnalysisPrompt to ui.js. Removed unused updateSubtaskById from task-manager.js. Resolved SyntaxError and ReferenceError issues across commands.js, ui.js, task-manager.js, and ai-services.js by replacing CONFIG references with config-manager getters (getDebugFlag, getProjectName, getDefaultSubtasks, isApiKeySet). Refactored 'models' command to use getConfig/writeConfig. Simplified version checking. This stabilizes the codebase after initial Task 61 refactoring, fixing CLI errors and enabling subsequent work on Subtasks 61.34 and 61.35.
2025-04-20 01:09:30 -04:00
) ;
2025-04-22 02:42:04 -04:00
lastError =
lastError ||
new Error ( ` Unsupported provider configured: ${ providerName } ` ) ;
continue ;
feat(config): Implement new config system and resolve refactoring errors Introduced config-manager.js and new utilities (resolveEnvVariable, findProjectRoot). Removed old global CONFIG object from utils.js. Updated .taskmasterconfig, mcp.json, and .env.example. Added generateComplexityAnalysisPrompt to ui.js. Removed unused updateSubtaskById from task-manager.js. Resolved SyntaxError and ReferenceError issues across commands.js, ui.js, task-manager.js, and ai-services.js by replacing CONFIG references with config-manager getters (getDebugFlag, getProjectName, getDefaultSubtasks, isApiKeySet). Refactored 'models' command to use getConfig/writeConfig. Simplified version checking. This stabilizes the codebase after initial Task 61 refactoring, fixing CLI errors and enabling subsequent work on Subtasks 61.34 and 61.35.
2025-04-20 01:09:30 -04:00
}
2025-04-22 02:42:04 -04:00
// Use the original service type to get the function
providerApiFn = providerFnSet [ serviceType ] ;
if ( typeof providerApiFn !== 'function' ) {
log (
'warn' ,
` Skipping role ' ${ currentRole } ': Service type ' ${ serviceType } ' not implemented for provider ' ${ providerName } '. `
) ;
lastError =
lastError ||
new Error (
` Service ' ${ serviceType } ' not implemented for provider ${ providerName } `
) ;
continue ;
}
feat(config): Implement new config system and resolve refactoring errors Introduced config-manager.js and new utilities (resolveEnvVariable, findProjectRoot). Removed old global CONFIG object from utils.js. Updated .taskmasterconfig, mcp.json, and .env.example. Added generateComplexityAnalysisPrompt to ui.js. Removed unused updateSubtaskById from task-manager.js. Resolved SyntaxError and ReferenceError issues across commands.js, ui.js, task-manager.js, and ai-services.js by replacing CONFIG references with config-manager getters (getDebugFlag, getProjectName, getDefaultSubtasks, isApiKeySet). Refactored 'models' command to use getConfig/writeConfig. Simplified version checking. This stabilizes the codebase after initial Task 61 refactoring, fixing CLI errors and enabling subsequent work on Subtasks 61.34 and 61.35.
2025-04-20 01:09:30 -04:00
2025-04-22 02:42:04 -04:00
// 3. Resolve API Key (will throw if required and missing)
2025-05-01 13:45:11 -04:00
// Pass effectiveProjectRoot to _resolveApiKey
apiKey = _resolveApiKey (
providerName ? . toLowerCase ( ) ,
session ,
effectiveProjectRoot
) ;
feat(config): Implement new config system and resolve refactoring errors Introduced config-manager.js and new utilities (resolveEnvVariable, findProjectRoot). Removed old global CONFIG object from utils.js. Updated .taskmasterconfig, mcp.json, and .env.example. Added generateComplexityAnalysisPrompt to ui.js. Removed unused updateSubtaskById from task-manager.js. Resolved SyntaxError and ReferenceError issues across commands.js, ui.js, task-manager.js, and ai-services.js by replacing CONFIG references with config-manager getters (getDebugFlag, getProjectName, getDefaultSubtasks, isApiKeySet). Refactored 'models' command to use getConfig/writeConfig. Simplified version checking. This stabilizes the codebase after initial Task 61 refactoring, fixing CLI errors and enabling subsequent work on Subtasks 61.34 and 61.35.
2025-04-20 01:09:30 -04:00
2025-04-22 02:42:04 -04:00
// 4. Construct Messages Array
const messages = [ ] ;
if ( systemPrompt ) {
messages . push ( { role : 'system' , content : systemPrompt } ) ;
}
feat(config): Implement new config system and resolve refactoring errors Introduced config-manager.js and new utilities (resolveEnvVariable, findProjectRoot). Removed old global CONFIG object from utils.js. Updated .taskmasterconfig, mcp.json, and .env.example. Added generateComplexityAnalysisPrompt to ui.js. Removed unused updateSubtaskById from task-manager.js. Resolved SyntaxError and ReferenceError issues across commands.js, ui.js, task-manager.js, and ai-services.js by replacing CONFIG references with config-manager getters (getDebugFlag, getProjectName, getDefaultSubtasks, isApiKeySet). Refactored 'models' command to use getConfig/writeConfig. Simplified version checking. This stabilizes the codebase after initial Task 61 refactoring, fixing CLI errors and enabling subsequent work on Subtasks 61.34 and 61.35.
2025-04-20 01:09:30 -04:00
2025-04-22 02:42:04 -04:00
// IN THE FUTURE WHEN DOING CONTEXT IMPROVEMENTS
// {
// type: 'text',
// text: 'Large cached context here like a tasks json',
// providerOptions: {
// anthropic: { cacheControl: { type: 'ephemeral' } }
// }
// }
feat(config): Implement new config system and resolve refactoring errors Introduced config-manager.js and new utilities (resolveEnvVariable, findProjectRoot). Removed old global CONFIG object from utils.js. Updated .taskmasterconfig, mcp.json, and .env.example. Added generateComplexityAnalysisPrompt to ui.js. Removed unused updateSubtaskById from task-manager.js. Resolved SyntaxError and ReferenceError issues across commands.js, ui.js, task-manager.js, and ai-services.js by replacing CONFIG references with config-manager getters (getDebugFlag, getProjectName, getDefaultSubtasks, isApiKeySet). Refactored 'models' command to use getConfig/writeConfig. Simplified version checking. This stabilizes the codebase after initial Task 61 refactoring, fixing CLI errors and enabling subsequent work on Subtasks 61.34 and 61.35.
2025-04-20 01:09:30 -04:00
2025-04-22 02:42:04 -04:00
// Example
// if (params.context) { // context is a json string of a tasks object or some other stu
// messages.push({
// type: 'text',
// text: params.context,
// providerOptions: { anthropic: { cacheControl: { type: 'ephemeral' } } }
// });
// }
feat(config): Implement new config system and resolve refactoring errors Introduced config-manager.js and new utilities (resolveEnvVariable, findProjectRoot). Removed old global CONFIG object from utils.js. Updated .taskmasterconfig, mcp.json, and .env.example. Added generateComplexityAnalysisPrompt to ui.js. Removed unused updateSubtaskById from task-manager.js. Resolved SyntaxError and ReferenceError issues across commands.js, ui.js, task-manager.js, and ai-services.js by replacing CONFIG references with config-manager getters (getDebugFlag, getProjectName, getDefaultSubtasks, isApiKeySet). Refactored 'models' command to use getConfig/writeConfig. Simplified version checking. This stabilizes the codebase after initial Task 61 refactoring, fixing CLI errors and enabling subsequent work on Subtasks 61.34 and 61.35.
2025-04-20 01:09:30 -04:00
2025-04-22 02:42:04 -04:00
if ( prompt ) {
// Ensure prompt exists before adding
messages . push ( { role : 'user' , content : prompt } ) ;
} else {
// Throw an error if the prompt is missing, as it's essential
throw new Error ( 'User prompt content is missing.' ) ;
}
// 5. Prepare call parameters (using messages array)
const callParams = {
apiKey ,
modelId ,
maxTokens : roleParams . maxTokens ,
temperature : roleParams . temperature ,
2025-04-28 14:38:01 -04:00
messages ,
2025-04-22 02:42:04 -04:00
... ( serviceType === 'generateObject' && { schema , objectName } ) ,
2025-04-28 14:38:01 -04:00
... restApiParams
feat(config): Implement new config system and resolve refactoring errors Introduced config-manager.js and new utilities (resolveEnvVariable, findProjectRoot). Removed old global CONFIG object from utils.js. Updated .taskmasterconfig, mcp.json, and .env.example. Added generateComplexityAnalysisPrompt to ui.js. Removed unused updateSubtaskById from task-manager.js. Resolved SyntaxError and ReferenceError issues across commands.js, ui.js, task-manager.js, and ai-services.js by replacing CONFIG references with config-manager getters (getDebugFlag, getProjectName, getDefaultSubtasks, isApiKeySet). Refactored 'models' command to use getConfig/writeConfig. Simplified version checking. This stabilizes the codebase after initial Task 61 refactoring, fixing CLI errors and enabling subsequent work on Subtasks 61.34 and 61.35.
2025-04-20 01:09:30 -04:00
} ;
2025-04-22 02:42:04 -04:00
// 6. Attempt the call with retries
const result = await _attemptProviderCallWithRetries (
providerApiFn ,
callParams ,
providerName ,
modelId ,
feat(config): Implement new config system and resolve refactoring errors Introduced config-manager.js and new utilities (resolveEnvVariable, findProjectRoot). Removed old global CONFIG object from utils.js. Updated .taskmasterconfig, mcp.json, and .env.example. Added generateComplexityAnalysisPrompt to ui.js. Removed unused updateSubtaskById from task-manager.js. Resolved SyntaxError and ReferenceError issues across commands.js, ui.js, task-manager.js, and ai-services.js by replacing CONFIG references with config-manager getters (getDebugFlag, getProjectName, getDefaultSubtasks, isApiKeySet). Refactored 'models' command to use getConfig/writeConfig. Simplified version checking. This stabilizes the codebase after initial Task 61 refactoring, fixing CLI errors and enabling subsequent work on Subtasks 61.34 and 61.35.
2025-04-20 01:09:30 -04:00
currentRole
) ;
2025-04-22 02:42:04 -04:00
log ( 'info' , ` ${ serviceType } Service succeeded using role: ${ currentRole } ` ) ;
2025-04-28 14:38:01 -04:00
return result ;
feat(config): Implement new config system and resolve refactoring errors Introduced config-manager.js and new utilities (resolveEnvVariable, findProjectRoot). Removed old global CONFIG object from utils.js. Updated .taskmasterconfig, mcp.json, and .env.example. Added generateComplexityAnalysisPrompt to ui.js. Removed unused updateSubtaskById from task-manager.js. Resolved SyntaxError and ReferenceError issues across commands.js, ui.js, task-manager.js, and ai-services.js by replacing CONFIG references with config-manager getters (getDebugFlag, getProjectName, getDefaultSubtasks, isApiKeySet). Refactored 'models' command to use getConfig/writeConfig. Simplified version checking. This stabilizes the codebase after initial Task 61 refactoring, fixing CLI errors and enabling subsequent work on Subtasks 61.34 and 61.35.
2025-04-20 01:09:30 -04:00
} catch ( error ) {
2025-04-28 14:38:01 -04:00
const cleanMessage = _extractErrorMessage ( error ) ;
feat(config): Implement new config system and resolve refactoring errors Introduced config-manager.js and new utilities (resolveEnvVariable, findProjectRoot). Removed old global CONFIG object from utils.js. Updated .taskmasterconfig, mcp.json, and .env.example. Added generateComplexityAnalysisPrompt to ui.js. Removed unused updateSubtaskById from task-manager.js. Resolved SyntaxError and ReferenceError issues across commands.js, ui.js, task-manager.js, and ai-services.js by replacing CONFIG references with config-manager getters (getDebugFlag, getProjectName, getDefaultSubtasks, isApiKeySet). Refactored 'models' command to use getConfig/writeConfig. Simplified version checking. This stabilizes the codebase after initial Task 61 refactoring, fixing CLI errors and enabling subsequent work on Subtasks 61.34 and 61.35.
2025-04-20 01:09:30 -04:00
log (
2025-04-28 14:38:01 -04:00
'error' ,
` Service call failed for role ${ currentRole } (Provider: ${ providerName || 'unknown' } , Model: ${ modelId || 'unknown' } ): ${ cleanMessage } `
feat(config): Implement new config system and resolve refactoring errors Introduced config-manager.js and new utilities (resolveEnvVariable, findProjectRoot). Removed old global CONFIG object from utils.js. Updated .taskmasterconfig, mcp.json, and .env.example. Added generateComplexityAnalysisPrompt to ui.js. Removed unused updateSubtaskById from task-manager.js. Resolved SyntaxError and ReferenceError issues across commands.js, ui.js, task-manager.js, and ai-services.js by replacing CONFIG references with config-manager getters (getDebugFlag, getProjectName, getDefaultSubtasks, isApiKeySet). Refactored 'models' command to use getConfig/writeConfig. Simplified version checking. This stabilizes the codebase after initial Task 61 refactoring, fixing CLI errors and enabling subsequent work on Subtasks 61.34 and 61.35.
2025-04-20 01:09:30 -04:00
) ;
2025-04-28 14:38:01 -04:00
lastError = error ;
lastCleanErrorMessage = cleanMessage ;
2025-04-27 18:23:56 -04:00
if ( serviceType === 'generateObject' ) {
const lowerCaseMessage = cleanMessage . toLowerCase ( ) ;
if (
lowerCaseMessage . includes (
'no endpoints found that support tool use'
) ||
lowerCaseMessage . includes ( 'does not support tool_use' ) ||
lowerCaseMessage . includes ( 'tool use is not supported' ) ||
lowerCaseMessage . includes ( 'tools are not supported' ) ||
lowerCaseMessage . includes ( 'function calling is not supported' )
) {
const specificErrorMsg = ` Model ' ${ modelId || 'unknown' } ' via provider ' ${ providerName || 'unknown' } ' does not support the 'tool use' required by generateObjectService. Please configure a model that supports tool/function calling for the ' ${ currentRole } ' role, or use generateTextService if structured output is not strictly required. ` ;
log ( 'error' , ` [Tool Support Error] ${ specificErrorMsg } ` ) ;
throw new Error ( specificErrorMsg ) ;
}
}
feat(config): Implement new config system and resolve refactoring errors Introduced config-manager.js and new utilities (resolveEnvVariable, findProjectRoot). Removed old global CONFIG object from utils.js. Updated .taskmasterconfig, mcp.json, and .env.example. Added generateComplexityAnalysisPrompt to ui.js. Removed unused updateSubtaskById from task-manager.js. Resolved SyntaxError and ReferenceError issues across commands.js, ui.js, task-manager.js, and ai-services.js by replacing CONFIG references with config-manager getters (getDebugFlag, getProjectName, getDefaultSubtasks, isApiKeySet). Refactored 'models' command to use getConfig/writeConfig. Simplified version checking. This stabilizes the codebase after initial Task 61 refactoring, fixing CLI errors and enabling subsequent work on Subtasks 61.34 and 61.35.
2025-04-20 01:09:30 -04:00
}
}
2025-04-22 02:42:04 -04:00
// If loop completes, all roles failed
feat(config): Implement new config system and resolve refactoring errors Introduced config-manager.js and new utilities (resolveEnvVariable, findProjectRoot). Removed old global CONFIG object from utils.js. Updated .taskmasterconfig, mcp.json, and .env.example. Added generateComplexityAnalysisPrompt to ui.js. Removed unused updateSubtaskById from task-manager.js. Resolved SyntaxError and ReferenceError issues across commands.js, ui.js, task-manager.js, and ai-services.js by replacing CONFIG references with config-manager getters (getDebugFlag, getProjectName, getDefaultSubtasks, isApiKeySet). Refactored 'models' command to use getConfig/writeConfig. Simplified version checking. This stabilizes the codebase after initial Task 61 refactoring, fixing CLI errors and enabling subsequent work on Subtasks 61.34 and 61.35.
2025-04-20 01:09:30 -04:00
log ( 'error' , ` All roles in the sequence [ ${ sequence . join ( ', ' ) } ] failed. ` ) ;
2025-04-27 03:56:23 -04:00
// Throw a new error with the cleaner message from the last failure
throw new Error ( lastCleanErrorMessage ) ;
feat(config): Implement new config system and resolve refactoring errors Introduced config-manager.js and new utilities (resolveEnvVariable, findProjectRoot). Removed old global CONFIG object from utils.js. Updated .taskmasterconfig, mcp.json, and .env.example. Added generateComplexityAnalysisPrompt to ui.js. Removed unused updateSubtaskById from task-manager.js. Resolved SyntaxError and ReferenceError issues across commands.js, ui.js, task-manager.js, and ai-services.js by replacing CONFIG references with config-manager getters (getDebugFlag, getProjectName, getDefaultSubtasks, isApiKeySet). Refactored 'models' command to use getConfig/writeConfig. Simplified version checking. This stabilizes the codebase after initial Task 61 refactoring, fixing CLI errors and enabling subsequent work on Subtasks 61.34 and 61.35.
2025-04-20 01:09:30 -04:00
}
/ * *
2025-04-22 02:42:04 -04:00
* Unified service function for generating text .
feat(config): Implement new config system and resolve refactoring errors Introduced config-manager.js and new utilities (resolveEnvVariable, findProjectRoot). Removed old global CONFIG object from utils.js. Updated .taskmasterconfig, mcp.json, and .env.example. Added generateComplexityAnalysisPrompt to ui.js. Removed unused updateSubtaskById from task-manager.js. Resolved SyntaxError and ReferenceError issues across commands.js, ui.js, task-manager.js, and ai-services.js by replacing CONFIG references with config-manager getters (getDebugFlag, getProjectName, getDefaultSubtasks, isApiKeySet). Refactored 'models' command to use getConfig/writeConfig. Simplified version checking. This stabilizes the codebase after initial Task 61 refactoring, fixing CLI errors and enabling subsequent work on Subtasks 61.34 and 61.35.
2025-04-20 01:09:30 -04:00
* Handles client retrieval , retries , and fallback sequence .
*
* @ param { object } params - Parameters for the service call .
* @ param { string } params . role - The initial client role ( 'main' , 'research' , 'fallback' ) .
* @ param { object } [ params . session = null ] - Optional MCP session object .
2025-05-01 13:45:11 -04:00
* @ param { string } [ params . projectRoot = null ] - Optional project root path for . env fallback .
feat(config): Implement new config system and resolve refactoring errors Introduced config-manager.js and new utilities (resolveEnvVariable, findProjectRoot). Removed old global CONFIG object from utils.js. Updated .taskmasterconfig, mcp.json, and .env.example. Added generateComplexityAnalysisPrompt to ui.js. Removed unused updateSubtaskById from task-manager.js. Resolved SyntaxError and ReferenceError issues across commands.js, ui.js, task-manager.js, and ai-services.js by replacing CONFIG references with config-manager getters (getDebugFlag, getProjectName, getDefaultSubtasks, isApiKeySet). Refactored 'models' command to use getConfig/writeConfig. Simplified version checking. This stabilizes the codebase after initial Task 61 refactoring, fixing CLI errors and enabling subsequent work on Subtasks 61.34 and 61.35.
2025-04-20 01:09:30 -04:00
* @ param { string } params . prompt - The prompt for the AI .
2025-04-22 02:42:04 -04:00
* @ param { string } [ params . systemPrompt ] - Optional system prompt .
* // Other specific generateText params can be included here.
* @ returns { Promise < string > } The generated text content .
feat(config): Implement new config system and resolve refactoring errors Introduced config-manager.js and new utilities (resolveEnvVariable, findProjectRoot). Removed old global CONFIG object from utils.js. Updated .taskmasterconfig, mcp.json, and .env.example. Added generateComplexityAnalysisPrompt to ui.js. Removed unused updateSubtaskById from task-manager.js. Resolved SyntaxError and ReferenceError issues across commands.js, ui.js, task-manager.js, and ai-services.js by replacing CONFIG references with config-manager getters (getDebugFlag, getProjectName, getDefaultSubtasks, isApiKeySet). Refactored 'models' command to use getConfig/writeConfig. Simplified version checking. This stabilizes the codebase after initial Task 61 refactoring, fixing CLI errors and enabling subsequent work on Subtasks 61.34 and 61.35.
2025-04-20 01:09:30 -04:00
* /
2025-04-22 02:42:04 -04:00
async function generateTextService ( params ) {
return _unifiedServiceRunner ( 'generateText' , params ) ;
}
feat(config): Implement new config system and resolve refactoring errors Introduced config-manager.js and new utilities (resolveEnvVariable, findProjectRoot). Removed old global CONFIG object from utils.js. Updated .taskmasterconfig, mcp.json, and .env.example. Added generateComplexityAnalysisPrompt to ui.js. Removed unused updateSubtaskById from task-manager.js. Resolved SyntaxError and ReferenceError issues across commands.js, ui.js, task-manager.js, and ai-services.js by replacing CONFIG references with config-manager getters (getDebugFlag, getProjectName, getDefaultSubtasks, isApiKeySet). Refactored 'models' command to use getConfig/writeConfig. Simplified version checking. This stabilizes the codebase after initial Task 61 refactoring, fixing CLI errors and enabling subsequent work on Subtasks 61.34 and 61.35.
2025-04-20 01:09:30 -04:00
2025-04-22 02:42:04 -04:00
/ * *
* Unified service function for streaming text .
* Handles client retrieval , retries , and fallback sequence .
*
* @ param { object } params - Parameters for the service call .
* @ param { string } params . role - The initial client role ( 'main' , 'research' , 'fallback' ) .
* @ param { object } [ params . session = null ] - Optional MCP session object .
2025-05-01 13:45:11 -04:00
* @ param { string } [ params . projectRoot = null ] - Optional project root path for . env fallback .
2025-04-22 02:42:04 -04:00
* @ param { string } params . prompt - The prompt for the AI .
* @ param { string } [ params . systemPrompt ] - Optional system prompt .
* // Other specific streamText params can be included here.
* @ returns { Promise < ReadableStream < string >> } A readable stream of text deltas .
* /
async function streamTextService ( params ) {
return _unifiedServiceRunner ( 'streamText' , params ) ;
}
feat(config): Implement new config system and resolve refactoring errors Introduced config-manager.js and new utilities (resolveEnvVariable, findProjectRoot). Removed old global CONFIG object from utils.js. Updated .taskmasterconfig, mcp.json, and .env.example. Added generateComplexityAnalysisPrompt to ui.js. Removed unused updateSubtaskById from task-manager.js. Resolved SyntaxError and ReferenceError issues across commands.js, ui.js, task-manager.js, and ai-services.js by replacing CONFIG references with config-manager getters (getDebugFlag, getProjectName, getDefaultSubtasks, isApiKeySet). Refactored 'models' command to use getConfig/writeConfig. Simplified version checking. This stabilizes the codebase after initial Task 61 refactoring, fixing CLI errors and enabling subsequent work on Subtasks 61.34 and 61.35.
2025-04-20 01:09:30 -04:00
2025-04-22 02:42:04 -04:00
/ * *
* Unified service function for generating structured objects .
* Handles client retrieval , retries , and fallback sequence .
*
* @ param { object } params - Parameters for the service call .
* @ param { string } params . role - The initial client role ( 'main' , 'research' , 'fallback' ) .
* @ param { object } [ params . session = null ] - Optional MCP session object .
2025-05-01 13:45:11 -04:00
* @ param { string } [ params . projectRoot = null ] - Optional project root path for . env fallback .
2025-04-22 02:42:04 -04:00
* @ param { import ( 'zod' ) . ZodSchema } params . schema - The Zod schema for the expected object .
* @ param { string } params . prompt - The prompt for the AI .
* @ param { string } [ params . systemPrompt ] - Optional system prompt .
* @ param { string } [ params . objectName = 'generated_object' ] - Name for object / tool .
* @ param { number } [ params . maxRetries = 3 ] - Max retries for object generation .
* @ returns { Promise < object > } The generated object matching the schema .
* /
async function generateObjectService ( params ) {
const defaults = {
objectName : 'generated_object' ,
maxRetries : 3
} ;
const combinedParams = { ... defaults , ... params } ;
return _unifiedServiceRunner ( 'generateObject' , combinedParams ) ;
feat(config): Implement new config system and resolve refactoring errors Introduced config-manager.js and new utilities (resolveEnvVariable, findProjectRoot). Removed old global CONFIG object from utils.js. Updated .taskmasterconfig, mcp.json, and .env.example. Added generateComplexityAnalysisPrompt to ui.js. Removed unused updateSubtaskById from task-manager.js. Resolved SyntaxError and ReferenceError issues across commands.js, ui.js, task-manager.js, and ai-services.js by replacing CONFIG references with config-manager getters (getDebugFlag, getProjectName, getDefaultSubtasks, isApiKeySet). Refactored 'models' command to use getConfig/writeConfig. Simplified version checking. This stabilizes the codebase after initial Task 61 refactoring, fixing CLI errors and enabling subsequent work on Subtasks 61.34 and 61.35.
2025-04-20 01:09:30 -04:00
}
export { generateTextService , streamTextService , generateObjectService } ;