cmte
Version:
Design by Committee™ except it's just you and LLMs
55 lines (50 loc) • 1.89 kB
JavaScript
/**
* Simplified context management for the Committee framework.
* Handles basic context creation and enhancement without complex validation.
*/
/**
* Creates a new context with optional initial values
* @param {Object} initialValues - Initial values to populate the context with
* @returns {Object} The created context object
*/
export function createContext(initialValues = {}) {
return { ...initialValues };
}
/**
* Enhances an existing context with new values
* @param {Object} baseContext - The base context to enhance
* @param {Object} newValues - New values to add to the context
* @returns {Object} The enhanced context object
*/
export function enhanceContext(baseContext, newValues) {
return { ...baseContext, ...newValues };
}
/**
* Merges multiple contexts together
* @param {...Object} contexts - Contexts to merge
* @returns {Object} The merged context object
*/
export function mergeContexts(...contexts) {
return contexts.reduce((acc, context) => ({ ...acc, ...context }), {});
}
/**
* Creates a context for a specific task with task-specific variables
* @param {Object} baseContext - The base workflow context
* @param {Object} taskVariables - Task-specific variables
* @returns {Object} The task-specific context
*/
export function createTaskContext(baseContext, taskVariables = {}) {
return enhanceContext(baseContext, taskVariables);
}
/**
* Validates that required context variables are present
* @param {Object} context - The context to validate
* @param {string[]} requiredVars - Array of required variable names
* @throws {Error} If any required variables are missing
*/
export function validateRequiredVariables(context, requiredVars) {
const missing = requiredVars.filter(varName => !(varName in context));
if (missing.length > 0) {
throw new Error(`Missing required context variables: ${missing.join(', ')}`);
}
}