@sethdouglasford/claude-flow
Version:
Claude Code Flow - Advanced AI-powered development workflows with SPARC methodology
220 lines • 10.6 kB
JavaScript
/**
* Comprehensive types and interfaces for the swarm system
*/
// ===== TYPE GUARDS =====
export function isAgentId(obj) {
const agentObj = obj;
return Boolean(obj && typeof agentObj.id === "string" && typeof agentObj.swarmId === "string");
}
export function isTaskId(obj) {
const taskObj = obj;
return Boolean(obj && typeof taskObj.id === "string" && typeof taskObj.swarmId === "string");
}
export function isSwarmEvent(obj) {
const eventObj = obj;
return Boolean(obj && typeof eventObj.id === "string" && typeof eventObj.type === "string");
}
export function isTaskDefinition(obj) {
const taskObj = obj;
return Boolean(obj && isTaskId(taskObj.id) && typeof taskObj.type === "string");
}
export function isAgentState(obj) {
const agentObj = obj;
return Boolean(obj && isAgentId(agentObj.id) && typeof agentObj.status === "string");
}
// Enhanced type guards for new interfaces
export function isTaskMetadata(obj) {
return Boolean(obj && typeof obj === "object" && !Array.isArray(obj));
}
export function isQualityRequirements(obj) {
if (!obj || typeof obj !== "object")
return false;
const qualityObj = obj;
return ((qualityObj.minQualityScore === undefined || typeof qualityObj.minQualityScore === "number") &&
(qualityObj.codeQualityRules === undefined || Array.isArray(qualityObj.codeQualityRules)) &&
(qualityObj.documentationRequired === undefined || typeof qualityObj.documentationRequired === "boolean") &&
(qualityObj.peerReviewRequired === undefined || typeof qualityObj.peerReviewRequired === "boolean"));
}
export function isTestingRequirements(obj) {
if (!obj || typeof obj !== "object")
return false;
const testingObj = obj;
return ((testingObj.unitTestsRequired === undefined || typeof testingObj.unitTestsRequired === "boolean") &&
(testingObj.integrationTestsRequired === undefined || typeof testingObj.integrationTestsRequired === "boolean") &&
(testingObj.performanceTestsRequired === undefined || typeof testingObj.performanceTestsRequired === "boolean") &&
(testingObj.securityTestsRequired === undefined || typeof testingObj.securityTestsRequired === "boolean") &&
(testingObj.coverageThreshold === undefined || typeof testingObj.coverageThreshold === "number"));
}
export function isResourceHints(obj) {
if (!obj || typeof obj !== "object")
return false;
const resourceObj = obj;
return Boolean((resourceObj.preferredAgentTypes === undefined || Array.isArray(resourceObj.preferredAgentTypes)) &&
(resourceObj.memoryIntensive === undefined || typeof resourceObj.memoryIntensive === "boolean") &&
(resourceObj.computeIntensive === undefined || typeof resourceObj.computeIntensive === "boolean") &&
(resourceObj.networkIntensive === undefined || typeof resourceObj.networkIntensive === "boolean") &&
(resourceObj.storageIntensive === undefined || typeof resourceObj.storageIntensive === "boolean"));
}
export function isPerformanceTargets(obj) {
const perfObj = obj;
return Boolean(obj && typeof obj === "object" &&
(perfObj.maxExecutionTime === undefined || typeof perfObj.maxExecutionTime === "number") &&
(perfObj.maxMemoryUsage === undefined || typeof perfObj.maxMemoryUsage === "number") &&
(perfObj.maxCpuUsage === undefined || typeof perfObj.maxCpuUsage === "number") &&
(perfObj.throughputTarget === undefined || typeof perfObj.throughputTarget === "number"));
}
export function isAgentEnvironment(obj) {
const envObj = obj;
return Boolean(obj && typeof obj === "object" &&
typeof envObj.runtime === "string" &&
typeof envObj.version === "string" &&
typeof envObj.workingDirectory === "string" &&
typeof envObj.tempDirectory === "string" &&
typeof envObj.logDirectory === "string" &&
typeof envObj.apiEndpoints === "object" &&
typeof envObj.credentials === "object" &&
Array.isArray(envObj.availableTools) &&
typeof envObj.toolConfigs === "object");
}
export function isNetworkConfig(obj) {
const netObj = obj;
return Boolean(obj && typeof obj === "object" &&
(netObj.maxConnections === undefined || typeof netObj.maxConnections === "number") &&
(netObj.timeout === undefined || typeof netObj.timeout === "number") &&
(netObj.rateLimits === undefined || typeof netObj.rateLimits === "object"));
}
export function isSystemInfo(obj) {
const sysObj = obj;
return Boolean(obj && typeof obj === "object" &&
typeof sysObj.platform === "string" &&
typeof sysObj.architecture === "string" &&
typeof sysObj.cpuCores === "number" &&
typeof sysObj.totalMemory === "number" &&
typeof sysObj.availableMemory === "number" &&
typeof sysObj.diskSpace === "number");
}
export function isResourceLimits(obj) {
const resObj = obj;
return Boolean(obj && typeof obj === "object" &&
(resObj.maxMemoryUsage === undefined || typeof resObj.maxMemoryUsage === "number") &&
(resObj.maxCpuUsage === undefined || typeof resObj.maxCpuUsage === "number") &&
(resObj.maxDiskUsage === undefined || typeof resObj.maxDiskUsage === "number") &&
(resObj.maxNetworkBandwidth === undefined || typeof resObj.maxNetworkBandwidth === "number") &&
(resObj.maxFileDescriptors === undefined || typeof resObj.maxFileDescriptors === "number") &&
(resObj.maxProcesses === undefined || typeof resObj.maxProcesses === "number"));
}
export function isSecurityConfig(obj) {
const secObj = obj;
return Boolean(obj && typeof obj === "object" &&
(secObj.allowedDomains === undefined || Array.isArray(secObj.allowedDomains)) &&
(secObj.blockedDomains === undefined || Array.isArray(secObj.blockedDomains)) &&
(secObj.allowFileSystem === undefined || typeof secObj.allowFileSystem === "boolean") &&
(secObj.allowNetworkAccess === undefined || typeof secObj.allowNetworkAccess === "boolean") &&
(secObj.allowProcessExecution === undefined || typeof secObj.allowProcessExecution === "boolean") &&
(secObj.sandboxed === undefined || typeof secObj.sandboxed === "boolean") &&
(secObj.permissions === undefined || Array.isArray(secObj.permissions)));
}
export function isContainerConfig(obj) {
const contObj = obj;
return Boolean(obj && typeof obj === "object" &&
typeof contObj.isContainerized === "boolean" &&
(contObj.containerRuntime === undefined || typeof contObj.containerRuntime === "string") &&
(contObj.imageName === undefined || typeof contObj.imageName === "string") &&
(contObj.volumes === undefined || Array.isArray(contObj.volumes)) &&
(contObj.networkMode === undefined || typeof contObj.networkMode === "string"));
}
export function isMonitoringConfig(obj) {
const monObj = obj;
return Boolean(obj && typeof obj === "object" &&
typeof monObj.metricsEnabled === "boolean" &&
typeof monObj.loggingEnabled === "boolean" &&
typeof monObj.tracingEnabled === "boolean" &&
(monObj.healthCheckInterval === undefined || typeof monObj.healthCheckInterval === "number") &&
(monObj.alertingEnabled === undefined || typeof monObj.alertingEnabled === "boolean") &&
(monObj.alertThresholds === undefined || typeof monObj.alertThresholds === "object"));
}
// Validation helpers for enhanced interfaces
export function validateTaskDefinitionWithMetadata(obj) {
const errors = [];
if (!isTaskDefinition(obj)) {
errors.push("Invalid TaskDefinition structure");
return errors;
}
if (obj.metadata && !isTaskMetadata(obj.metadata)) {
errors.push("Invalid TaskMetadata structure");
}
if (obj.metadata?.qualityRequirements && !isQualityRequirements(obj.metadata.qualityRequirements)) {
errors.push("Invalid QualityRequirements in metadata");
}
if (obj.metadata?.testingRequirements && !isTestingRequirements(obj.metadata.testingRequirements)) {
errors.push("Invalid TestingRequirements in metadata");
}
if (obj.metadata?.resourceHints && !isResourceHints(obj.metadata.resourceHints)) {
errors.push("Invalid ResourceHints in metadata");
}
if (obj.metadata?.performanceTargets && !isPerformanceTargets(obj.metadata.performanceTargets)) {
errors.push("Invalid PerformanceTargets in metadata");
}
return errors;
}
export function validateAgentEnvironment(obj) {
const errors = [];
if (!isAgentEnvironment(obj)) {
errors.push("Invalid AgentEnvironment structure");
return errors;
}
if (obj.networkConfig && !isNetworkConfig(obj.networkConfig)) {
errors.push("Invalid NetworkConfig in environment");
}
if (obj.systemInfo && !isSystemInfo(obj.systemInfo)) {
errors.push("Invalid SystemInfo in environment");
}
if (obj.resourceLimits && !isResourceLimits(obj.resourceLimits)) {
errors.push("Invalid ResourceLimits in environment");
}
if (obj.securityConfig && !isSecurityConfig(obj.securityConfig)) {
errors.push("Invalid SecurityConfig in environment");
}
if (obj.containerConfig && !isContainerConfig(obj.containerConfig)) {
errors.push("Invalid ContainerConfig in environment");
}
if (obj.monitoringConfig && !isMonitoringConfig(obj.monitoringConfig)) {
errors.push("Invalid MonitoringConfig in environment");
}
return errors;
}
// ===== CONSTANTS =====
export const SWARM_CONSTANTS = {
// Timeouts
DEFAULT_TASK_TIMEOUT: 5 * 60 * 1000, // 5 minutes
DEFAULT_AGENT_TIMEOUT: 30 * 1000, // 30 seconds
DEFAULT_HEARTBEAT_INTERVAL: 10 * 1000, // 10 seconds
// Limits
MAX_AGENTS_PER_SWARM: 100,
MAX_TASKS_PER_AGENT: 10,
MAX_RETRIES: 3,
// Quality thresholds
MIN_QUALITY_THRESHOLD: 0.7,
DEFAULT_QUALITY_THRESHOLD: 0.8,
HIGH_QUALITY_THRESHOLD: 0.9,
// Performance targets
DEFAULT_THROUGHPUT_TARGET: 10, // tasks per minute
DEFAULT_LATENCY_TARGET: 1000, // milliseconds
DEFAULT_RELIABILITY_TARGET: 0.95, // 95%
// Resource limits
DEFAULT_MEMORY_LIMIT: 512 * 1024 * 1024, // 512MB
DEFAULT_CPU_LIMIT: 1.0, // 1 CPU core
DEFAULT_DISK_LIMIT: 1024 * 1024 * 1024, // 1GB
};
// ===== EXPORTS =====
export default {
// Type exports are handled by TypeScript
SWARM_CONSTANTS,
// Utility functions
isAgentId,
isTaskId,
isSwarmEvent,
isTaskDefinition,
isAgentState,
};
//# sourceMappingURL=types.js.map