refactor(config): Standardize env var access and config getters
This commit focuses on standardizing configuration and API key access patterns across key modules as part of subtask 61.34. Key changes include: - Refactored `ai-services.js` to remove global AI clients and use `resolveEnvVariable` for API key checks. Client instantiation now relies on `getAnthropicClient`/`getPerplexityClient` accepting a session object. - Refactored `task-manager.js` (`analyzeTaskComplexity` function) to use the unified `generateTextService` from `ai-services-unified.js`, removing direct AI client calls. - Replaced direct `process.env` access for model parameters and other configurations (`PERPLEXITY_MODEL`, `CONFIG.*`) in `task-manager.js` with calls to the appropriate getters from `config-manager.js` (e.g., `getResearchModelId(session)`, `getMainMaxTokens(session)`). - Ensured `utils.js` (`resolveEnvVariable`) correctly handles potentially undefined session objects. - Updated function signatures where necessary to propagate the `session` object for correct context-aware configuration/key retrieval. This moves towards the goal of using `ai-client-factory.js` and `ai-services-unified.js` as the standard pattern for AI interactions and centralizing configuration management through `config-manager.js`.
This commit is contained in:
30
scripts/modules/task-manager/task-exists.js
Normal file
30
scripts/modules/task-manager/task-exists.js
Normal file
@@ -0,0 +1,30 @@
|
||||
/**
|
||||
* Checks if a task with the given ID exists
|
||||
* @param {Array} tasks - Array of tasks to search
|
||||
* @param {string|number} taskId - ID of task or subtask to check
|
||||
* @returns {boolean} Whether the task exists
|
||||
*/
|
||||
function taskExists(tasks, taskId) {
|
||||
// Handle subtask IDs (e.g., "1.2")
|
||||
if (typeof taskId === 'string' && taskId.includes('.')) {
|
||||
const [parentIdStr, subtaskIdStr] = taskId.split('.');
|
||||
const parentId = parseInt(parentIdStr, 10);
|
||||
const subtaskId = parseInt(subtaskIdStr, 10);
|
||||
|
||||
// Find the parent task
|
||||
const parentTask = tasks.find((t) => t.id === parentId);
|
||||
|
||||
// If parent exists, check if subtask exists
|
||||
return (
|
||||
parentTask &&
|
||||
parentTask.subtasks &&
|
||||
parentTask.subtasks.some((st) => st.id === subtaskId)
|
||||
);
|
||||
}
|
||||
|
||||
// Handle regular task IDs
|
||||
const id = parseInt(taskId, 10);
|
||||
return tasks.some((t) => t.id === id);
|
||||
}
|
||||
|
||||
export default taskExists;
|
||||
Reference in New Issue
Block a user