@inkeep/agents-cli 0.62.1 → 0.63.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  //#region package.json
2
2
  var name = "@inkeep/agents-cli";
3
- var version = "0.62.1";
3
+ var version = "0.63.0";
4
4
 
5
5
  //#endregion
6
6
  export { name, version };
@@ -1 +1 @@
1
- {"version":3,"file":"component-registry.js","names":[],"sources":["../../../src/commands/pull-v4/component-registry.ts"],"sourcesContent":["/**\n * Unified Component Registry - Handles both unique variable names AND file paths\n *\n * This combines the functionality of ComponentTracker and ComponentMapper\n * into a single, clean system that handles:\n * 1. Unique variable name generation (with collision resolution)\n * 2. File path tracking for imports\n * 3. Reference resolution for code generation\n */\nimport type { FullProjectDefinition } from '@inkeep/agents-core';\n\nexport type ComponentType =\n | 'agents'\n | 'subAgents'\n | 'tools'\n | 'functionTools'\n | 'functions'\n | 'dataComponents'\n | 'artifactComponents'\n | 'statusComponents'\n | 'environments'\n | 'externalAgents'\n | 'credentials'\n | 'contextConfigs'\n | 'fetchDefinitions'\n | 'headers'\n | 'models'\n | 'skills'\n | 'triggers'\n | 'scheduledTriggers'\n | 'project';\n\nexport interface ComponentInfo {\n id: string; // Original component ID\n name: string; // Unique variable name (guaranteed unique across project)\n type: ComponentType; // Component type\n filePath: string; // Relative file path (e.g., \"agents/foo.ts\")\n exportName: string; // Export name (usually same as name)\n isInline: boolean; // Whether component was defined inline (true) or exported (false)\n}\n\nexport class ComponentRegistry {\n private components = new Map<string, ComponentInfo>();\n private componentsByTypeAndId = new Map<string, ComponentInfo>(); // Type-aware lookup\n private usedNames = new Set<string>(); // Global name registry for uniqueness\n\n /**\n * Register a component with both unique name and file path\n */\n register(\n id: string,\n type: ComponentType,\n filePath: string,\n exportName?: string,\n isInline: boolean = false\n ): ComponentInfo {\n const typeKey = `${type}:${id}`;\n\n // Check if this component already exists - if so, return the existing one\n const existing = this.componentsByTypeAndId.get(typeKey);\n if (existing) {\n return existing;\n }\n\n let name: string;\n let actualExportName: string;\n\n // If exportName is provided (real discovered name), use it directly\n // Otherwise, generate and ensure uniqueness for assumed names\n if (exportName) {\n // Real export name discovered from file - use it as-is\n name = exportName;\n actualExportName = exportName;\n } else {\n // No real export name - generate unique name with prefixes if needed\n const baseName = this.toCamelCase(id);\n const uniqueName = this.ensureUniqueName(baseName, type);\n name = uniqueName;\n actualExportName = uniqueName;\n }\n\n const info: ComponentInfo = {\n id,\n name,\n type,\n filePath,\n exportName: actualExportName,\n isInline,\n };\n\n // Store with both ID-only key (for backward compatibility) and type+ID key (for collision handling)\n this.components.set(id, info);\n this.componentsByTypeAndId.set(typeKey, info);\n\n this.usedNames.add(name);\n if (actualExportName && actualExportName !== name) {\n this.usedNames.add(actualExportName);\n }\n\n return info;\n }\n\n /**\n * Override a credential component with environment settings key\n * This allows env settings registration to take precedence over standalone credentials\n */\n overrideCredentialWithEnvKey(id: string, filePath: string, envKey: string): ComponentInfo {\n const typeKey = `credentials:${id}`;\n\n const info: ComponentInfo = {\n id,\n type: 'credentials',\n name: envKey, // Use the environment settings key\n filePath,\n exportName: envKey,\n isInline: true,\n };\n\n // Override existing registration\n this.componentsByTypeAndId.set(typeKey, info);\n this.components.set(`${filePath}:${envKey}`, info);\n\n return info;\n }\n\n /**\n * Get component info by ID and type\n */\n get(id: string, type: ComponentType): ComponentInfo | undefined {\n const typeKey = `${type}:${id}`;\n return this.componentsByTypeAndId.get(typeKey);\n }\n\n /**\n * Get component info by variable name (since variable names are globally unique)\n */\n getByVariableName(variableName: string): ComponentInfo | undefined {\n for (const component of this.componentsByTypeAndId.values()) {\n if (component.name === variableName) {\n return component;\n }\n }\n return undefined;\n }\n\n /**\n * Get unique variable name for a component by ID and type\n */\n getVariableName(id: string, type: ComponentType): string | undefined {\n const typeKey = `${type}:${id}`;\n const result = this.componentsByTypeAndId.get(typeKey)?.name;\n\n return result;\n }\n\n /**\n * Get import statement for a component\n */\n getImportStatement(\n fromFilePath: string,\n componentId: string,\n componentType: ComponentType\n ): string | undefined {\n const component = this.get(componentId, componentType);\n if (!component) return undefined;\n\n // Normalize both paths to the same format for comparison\n const normalizedFrom = this.normalizeToProjectPath(fromFilePath);\n const normalizedTo = this.normalizeToProjectPath(component.filePath);\n\n // Skip import if same file\n if (normalizedFrom === normalizedTo) {\n return undefined;\n }\n\n const relativePath = this.calculateRelativeImport(fromFilePath, component.filePath);\n const importStmt = `import { ${component.exportName} } from '${relativePath}';`;\n\n return importStmt;\n }\n\n /**\n * Format an array of references for code generation\n */\n formatReferencesForCode(\n references: any[],\n componentType: ComponentType,\n style: { quotes: 'single' | 'double'; indentation: string },\n indentLevel: number\n ): string {\n if (!Array.isArray(references) || references.length === 0) {\n return '[]';\n }\n\n const variableNames: string[] = [];\n\n for (const ref of references) {\n const id = this.extractIdFromReference(ref);\n if (id) {\n const component = this.get(id, componentType);\n if (component) {\n variableNames.push(component.name);\n } else {\n console.warn(`ComponentRegistry: Component not found: ${id} (type: ${componentType})`);\n variableNames.push(this.toCamelCase(id));\n }\n }\n }\n\n if (variableNames.length === 0) {\n return '[]';\n }\n\n if (variableNames.length === 1) {\n return `[${variableNames[0]}]`;\n }\n\n // Multi-line format\n const { indentation } = style;\n const indent = indentation.repeat(indentLevel);\n const lines = ['['];\n\n for (let i = 0; i < variableNames.length; i++) {\n const isLast = i === variableNames.length - 1;\n lines.push(`${indent}${variableNames[i]}${isLast ? '' : ','}`);\n }\n\n lines.push(`${indentation.repeat(indentLevel - 1)}]`);\n return lines.join('\\n');\n }\n\n /**\n * Get all import statements needed for a file\n */\n getImportsForFile(\n fromFilePath: string,\n referencedComponents: Array<{ id: string; type: ComponentType }>\n ): string[] {\n const imports: string[] = [];\n const seenImports = new Set<string>(); // Deduplicate imports\n\n for (const { id, type } of referencedComponents) {\n const importStatement = this.getImportStatement(fromFilePath, id, type);\n if (importStatement && !seenImports.has(importStatement)) {\n imports.push(importStatement);\n seenImports.add(importStatement);\n }\n }\n\n return imports;\n }\n\n /**\n * Get all component IDs referenced in arrays for import generation\n */\n getReferencedComponentIds(referenceArrays: any[][]): string[] {\n const componentIds: string[] = [];\n\n for (const refArray of referenceArrays) {\n if (Array.isArray(refArray)) {\n for (const ref of refArray) {\n const id = this.extractIdFromReference(ref);\n if (id) {\n componentIds.push(id);\n }\n }\n }\n }\n\n return componentIds;\n }\n\n /**\n * Extract ID from a reference (string or object) based on component type\n */\n private extractIdFromReference(ref: any): string | null {\n if (typeof ref === 'string') {\n return ref;\n }\n if (typeof ref === 'object' && ref) {\n // Handle different component types by their specific ID fields (confirmed from debug output)\n\n // Tool references (MCP tools and function tools)\n if (ref.toolId) return ref.toolId;\n\n // Agent references (main agents and sub-agents)\n if (ref.agentId) return ref.agentId;\n\n // External agent references\n if (ref.externalAgentId) return ref.externalAgentId;\n\n // Credential store references (found in generated files)\n if (ref.credentialStoreId) return ref.credentialStoreId;\n\n // Status component references using type field (confirmed from debug output)\n if (ref.type && !ref.agentId && !ref.toolId && !ref.externalAgentId) return ref.type;\n\n // Generic ID field (fallback)\n if (ref.id) return ref.id;\n\n // Name field (fallback)\n if (ref.name) return ref.name;\n\n // For objects without recognized ID fields, warn and skip\n console.warn('ComponentRegistry: Reference without recognized ID field:', ref);\n return null;\n }\n\n return null;\n }\n\n /**\n * Convert string to camelCase and ensure it's a valid JavaScript identifier\n */\n private toCamelCase(str: string): string {\n return str\n .toLowerCase()\n .replace(/[-_](.)/g, (_, char) => char.toUpperCase())\n .replace(/[^a-zA-Z0-9]/g, '')\n .replace(/^[0-9]/, '_$&');\n }\n\n /**\n * Ensure a name is unique by adding prefixes/suffixes if needed\n */\n private ensureUniqueName(baseName: string, type: ComponentType): string {\n let uniqueName = baseName;\n let counter = 1;\n\n while (this.usedNames.has(uniqueName)) {\n // Try with type prefix first\n if (counter === 1) {\n const typePrefix = this.getTypePrefix(type);\n uniqueName = `${typePrefix}${baseName.charAt(0).toUpperCase() + baseName.slice(1)}`;\n } else {\n // Then try with counter\n uniqueName = `${baseName}${counter}`;\n }\n counter++;\n\n // Safety net to prevent infinite loops\n if (counter > 100) {\n uniqueName = `${baseName}_${Date.now()}`;\n break;\n }\n }\n\n return uniqueName;\n }\n\n /**\n * Get type prefix for uniqueness resolution\n */\n private getTypePrefix(type: ComponentType): string {\n switch (type) {\n case 'agents':\n return 'agent';\n case 'subAgents':\n return 'sub';\n case 'externalAgents':\n return 'ext';\n case 'tools':\n return 'tool';\n case 'functionTools':\n return 'func';\n case 'functions':\n return 'func';\n case 'dataComponents':\n return 'data';\n case 'artifactComponents':\n return 'artifact';\n case 'statusComponents':\n return 'status';\n case 'environments':\n return 'env';\n case 'credentials':\n return 'cred';\n case 'contextConfigs':\n return 'context';\n case 'fetchDefinitions':\n return 'fetch';\n case 'headers':\n return 'header';\n case 'models':\n return 'model';\n case 'triggers':\n return 'trigger';\n case 'project':\n return 'project';\n default:\n return 'comp';\n }\n }\n\n /**\n * Normalize path to project-relative format using existing registry paths as templates\n */\n private normalizeToProjectPath(filePath: string): string {\n // If already in project format (no slashes before known directories), return as-is\n if (!filePath.includes('/') || filePath.match(/^(agents|tools|environments|data-components)/)) {\n return filePath;\n }\n\n // Find project directories by looking at existing registry paths\n const knownDirs = new Set<string>();\n for (const component of this.components.values()) {\n const firstDir = component.filePath.split('/')[0];\n if (firstDir) knownDirs.add(firstDir);\n }\n\n // Find the last occurrence of any known project directory\n const segments = filePath.split('/');\n for (let i = segments.length - 1; i >= 0; i--) {\n if (knownDirs.has(segments[i])) {\n return segments.slice(i).join('/');\n }\n }\n\n // Fallback: return the filename\n return segments[segments.length - 1] || filePath;\n }\n\n /**\n * Calculate relative import path between files\n */\n private calculateRelativeImport(fromPath: string, toPath: string): string {\n // Remove .ts extensions for calculation\n const fromParts = fromPath.replace('.ts', '').split('/');\n const toParts = toPath.replace('.ts', '').split('/');\n\n // Remove filename from fromPath (keep directory only)\n const fromDir = fromParts.slice(0, -1);\n const toFile = toParts;\n\n // Find common path prefix\n let commonLength = 0;\n while (\n commonLength < fromDir.length &&\n commonLength < toFile.length - 1 &&\n fromDir[commonLength] === toFile[commonLength]\n ) {\n commonLength++;\n }\n\n // Calculate relative path\n let relativePath = '';\n\n // Go up for remaining directories in fromDir after common path\n const upLevels = fromDir.length - commonLength;\n for (let i = 0; i < upLevels; i++) {\n relativePath += '../';\n }\n\n // Add remaining path from toFile after common path\n const remainingPath = toFile.slice(commonLength).join('/');\n relativePath += remainingPath;\n\n // Clean up path format\n if (relativePath.startsWith('../')) {\n return relativePath;\n }\n return `./${relativePath}`;\n }\n\n /**\n * Get all components for debugging\n */\n getAllComponents(): ComponentInfo[] {\n return Array.from(this.componentsByTypeAndId.values());\n }\n\n /**\n * Get all components in a specific file\n */\n getComponentsInFile(filePath: string): ComponentInfo[] {\n return Array.from(this.componentsByTypeAndId.values()).filter(\n (component) => component.filePath === filePath\n );\n }\n\n /**\n * Remove a component from the registry\n */\n removeComponent(type: string, id: string): void {\n const key = `${type}:${id}`;\n const component = this.componentsByTypeAndId.get(key);\n\n if (component) {\n // Remove from both maps\n this.componentsByTypeAndId.delete(key);\n this.components.delete(component.name);\n\n // Remove from used names if no other component uses it\n const nameStillUsed = Array.from(this.componentsByTypeAndId.values()).some(\n (comp) => comp.name === component.name\n );\n if (!nameStillUsed) {\n this.usedNames.delete(component.name);\n }\n }\n }\n\n /**\n * Clear all components (for testing)\n */\n clear(): void {\n this.components.clear();\n this.componentsByTypeAndId.clear();\n this.usedNames.clear();\n }\n}\n\n/**\n * Register all components from a project with their file paths\n */\nexport function registerAllComponents(\n project: FullProjectDefinition,\n registry: ComponentRegistry\n): void {\n // Register project\n registry.register(project.id, 'project', 'index.ts');\n\n // Register credentials\n if (project.credentialReferences) {\n for (const credId of Object.keys(project.credentialReferences)) {\n registry.register(credId, 'credentials', `credentials/${credId}.ts`);\n }\n }\n\n // Register tools\n if (project.tools) {\n for (const toolId of Object.keys(project.tools)) {\n registry.register(toolId, 'tools', `tools/${toolId}.ts`);\n }\n }\n\n // Register function tools - functionTools has the name/description, functions has the code\n // We generate files based on functionTools IDs since that's the user-facing entity\n const registeredFunctionToolIds = new Set<string>();\n\n // Register functionTools first (they have the name that identifies the tool)\n if (project.functionTools) {\n for (const funcToolId of Object.keys(project.functionTools)) {\n registry.register(funcToolId, 'functionTools', `tools/functions/${funcToolId}.ts`);\n registeredFunctionToolIds.add(funcToolId);\n }\n }\n\n // Also check agent-level functionTools\n if (project.agents) {\n for (const agentData of Object.values(project.agents)) {\n const agentFunctionTools = (agentData as any).functionTools;\n if (agentFunctionTools) {\n for (const funcToolId of Object.keys(agentFunctionTools)) {\n if (!registeredFunctionToolIds.has(funcToolId)) {\n registry.register(funcToolId, 'functionTools', `tools/functions/${funcToolId}.ts`);\n registeredFunctionToolIds.add(funcToolId);\n }\n }\n }\n }\n }\n\n // Register data components\n if (project.dataComponents) {\n for (const componentId of Object.keys(project.dataComponents)) {\n registry.register(componentId, 'dataComponents', `data-components/${componentId}.ts`);\n }\n }\n\n // Register artifact components\n if (project.artifactComponents) {\n for (const componentId of Object.keys(project.artifactComponents)) {\n registry.register(componentId, 'artifactComponents', `artifact-components/${componentId}.ts`);\n }\n }\n\n // Register external agents\n if (project.externalAgents) {\n for (const extAgentId of Object.keys(project.externalAgents)) {\n registry.register(extAgentId, 'externalAgents', `external-agents/${extAgentId}.ts`);\n }\n }\n\n // Register skills\n if (project.skills) {\n for (const skillId of Object.keys(project.skills)) {\n registry.register(skillId, 'skills', `skills/${skillId}.md`);\n }\n }\n\n // Register extracted status components\n const statusComponents = extractStatusComponents(project);\n for (const statusId of Object.keys(statusComponents)) {\n registry.register(statusId, 'statusComponents', `status-components/${statusId}.ts`);\n }\n\n // Register agents\n if (project.agents) {\n for (const agentId of Object.keys(project.agents)) {\n registry.register(agentId, 'agents', `agents/${agentId}.ts`);\n }\n }\n\n // Register triggers (agent-scoped)\n if (project.agents) {\n for (const agentData of Object.values(project.agents)) {\n const agentTriggers = (agentData as any).triggers;\n if (agentTriggers) {\n for (const triggerId of Object.keys(agentTriggers)) {\n registry.register(triggerId, 'triggers', `agents/triggers/${triggerId}.ts`);\n }\n }\n }\n }\n\n // Register extracted sub-agents\n const subAgents = extractSubAgents(project);\n for (const subAgentId of Object.keys(subAgents)) {\n registry.register(subAgentId, 'subAgents', `agents/sub-agents/${subAgentId}.ts`);\n }\n\n // Register extracted context configs\n const contextConfigs = extractContextConfigs(project);\n for (const contextId of Object.keys(contextConfigs)) {\n registry.register(contextId, 'contextConfigs', `context-configs/${contextId}.ts`);\n }\n}\n\n/**\n * Extract status components from project agents\n */\nfunction extractStatusComponents(project: FullProjectDefinition): Record<string, any> {\n const statusComponents: Record<string, any> = {};\n\n if (project.agents) {\n for (const agentData of Object.values(project.agents)) {\n if (agentData.statusUpdates?.statusComponents) {\n // statusComponents is an array that can contain strings or objects\n for (const statusComp of agentData.statusUpdates.statusComponents) {\n let statusId: string;\n\n if (typeof statusComp === 'string') {\n // Direct string reference to status component ID\n statusId = statusComp;\n } else if (typeof statusComp === 'object' && statusComp) {\n // Object with id, type, or name field\n statusId = statusComp.type;\n } else {\n continue;\n }\n\n if (statusId && !statusComponents[statusId]) {\n // Use the actual status component data instead of creating dummy data\n statusComponents[statusId] = {\n // Include any other properties from the actual data first\n ...statusComp,\n id: statusId,\n type: statusComp.type || statusId,\n description: statusComp.description || `Status component for ${statusId}`,\n detailsSchema: statusComp.detailsSchema,\n };\n }\n }\n }\n }\n }\n\n return statusComponents;\n}\n\n/**\n * Extract sub-agents from project agents\n */\nexport function extractSubAgents(project: FullProjectDefinition): Record<string, any> {\n const subAgents: Record<string, any> = {};\n\n if (project.agents) {\n for (const agentData of Object.values(project.agents)) {\n if (agentData.subAgents) {\n for (const [subAgentId, subAgentData] of Object.entries(agentData.subAgents)) {\n subAgents[subAgentId] = subAgentData;\n }\n }\n }\n }\n\n return subAgents;\n}\n\n/**\n * Extract context configs from project agents\n */\nfunction extractContextConfigs(project: FullProjectDefinition): Record<string, any> {\n const contextConfigs: Record<string, any> = {};\n\n if (project.agents) {\n for (const [agentId, agentData] of Object.entries(project.agents)) {\n if (agentData.contextConfig) {\n // Use the actual contextConfig.id (now required)\n const contextConfigId = agentData.contextConfig.id;\n if (contextConfigId) {\n contextConfigs[contextConfigId] = agentData.contextConfig;\n } else {\n console.warn(`contextConfig for agent ${agentId} is missing required 'id' field`);\n }\n }\n }\n }\n\n return contextConfigs;\n}\n\n/**\n * Find sub-agent data with parent agent info for contextConfig resolution\n */\nexport function findSubAgentWithParent(\n project: FullProjectDefinition,\n subAgentId: string\n): { subAgentData: any; parentAgentId: string; contextConfigData?: any } | undefined {\n if (project.agents) {\n for (const [agentId, agentData] of Object.entries(project.agents)) {\n if (agentData.subAgents?.[subAgentId]) {\n // Get contextConfig data if parent agent has one with an ID\n const contextConfigData = agentData.contextConfig?.id ? agentData.contextConfig : undefined;\n\n return {\n subAgentData: agentData.subAgents[subAgentId],\n parentAgentId: agentId,\n contextConfigData,\n };\n }\n }\n }\n return undefined;\n}\n"],"mappings":";AAyCA,IAAa,oBAAb,MAA+B;CAC7B,AAAQ,6BAAa,IAAI,KAA4B;CACrD,AAAQ,wCAAwB,IAAI,KAA4B;CAChE,AAAQ,4BAAY,IAAI,KAAa;;;;CAKrC,SACE,IACA,MACA,UACA,YACA,WAAoB,OACL;EACf,MAAM,UAAU,GAAG,KAAK,GAAG;EAG3B,MAAM,WAAW,KAAK,sBAAsB,IAAI,QAAQ;AACxD,MAAI,SACF,QAAO;EAGT,IAAI;EACJ,IAAI;AAIJ,MAAI,YAAY;AAEd,UAAO;AACP,sBAAmB;SACd;GAEL,MAAM,WAAW,KAAK,YAAY,GAAG;GACrC,MAAM,aAAa,KAAK,iBAAiB,UAAU,KAAK;AACxD,UAAO;AACP,sBAAmB;;EAGrB,MAAM,OAAsB;GAC1B;GACA;GACA;GACA;GACA,YAAY;GACZ;GACD;AAGD,OAAK,WAAW,IAAI,IAAI,KAAK;AAC7B,OAAK,sBAAsB,IAAI,SAAS,KAAK;AAE7C,OA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AO,CAC/D,KAAI,UAAU,YAAY,aAAa;GAErC,MAAM,oBAAoB,UAAU,eAAe,KAAK,UAAU,gBAAgB;AAElF,UAAO;IACL,cAAc,UAAU,UAAU;IAClC,eAAe;IACf;IACD"}
1
+ {"version":3,"file":"component-registry.js","names":[],"sources":["../../../src/commands/pull-v4/component-registry.ts"],"sourcesContent":["/**\n * Unified Component Registry - Handles both unique variable names AND file paths\n *\n * This combines the functionality of ComponentTracker and ComponentMapper\n * into a single, clean system that handles:\n * 1. Unique variable name generation (with collision resolution)\n * 2. File path tracking for imports\n * 3. Reference resolution for code generation\n */\nimport type { FullProjectDefinition } from '@inkeep/agents-core';\n\nexport type ComponentType =\n | 'agents'\n | 'subAgents'\n | 'tools'\n | 'functionTools'\n | 'functions'\n | 'dataComponents'\n | 'artifactComponents'\n | 'statusComponents'\n | 'environments'\n | 'externalAgents'\n | 'credentials'\n | 'contextConfigs'\n | 'fetchDefinitions'\n | 'headers'\n | 'models'\n | 'skills'\n | 'triggers'\n | 'project';\n\nexport interface ComponentInfo {\n id: string; // Original component ID\n name: string; // Unique variable name (guaranteed unique across project)\n type: ComponentType; // Component type\n filePath: string; // Relative file path (e.g., \"agents/foo.ts\")\n exportName: string; // Export name (usually same as name)\n isInline: boolean; // Whether component was defined inline (true) or exported (false)\n}\n\nexport class ComponentRegistry {\n private components = new Map<string, ComponentInfo>();\n private componentsByTypeAndId = new Map<string, ComponentInfo>(); // Type-aware lookup\n private usedNames = new Set<string>(); // Global name registry for uniqueness\n\n /**\n * Register a component with both unique name and file path\n */\n register(\n id: string,\n type: ComponentType,\n filePath: string,\n exportName?: string,\n isInline: boolean = false\n ): ComponentInfo {\n const typeKey = `${type}:${id}`;\n\n // Check if this component already exists - if so, return the existing one\n const existing = this.componentsByTypeAndId.get(typeKey);\n if (existing) {\n return existing;\n }\n\n let name: string;\n let actualExportName: string;\n\n // If exportName is provided (real discovered name), use it directly\n // Otherwise, generate and ensure uniqueness for assumed names\n if (exportName) {\n // Real export name discovered from file - use it as-is\n name = exportName;\n actualExportName = exportName;\n } else {\n // No real export name - generate unique name with prefixes if needed\n const baseName = this.toCamelCase(id);\n const uniqueName = this.ensureUniqueName(baseName, type);\n name = uniqueName;\n actualExportName = uniqueName;\n }\n\n const info: ComponentInfo = {\n id,\n name,\n type,\n filePath,\n exportName: actualExportName,\n isInline,\n };\n\n // Store with both ID-only key (for backward compatibility) and type+ID key (for collision handling)\n this.components.set(id, info);\n this.componentsByTypeAndId.set(typeKey, info);\n\n this.usedNames.add(name);\n if (actualExportName && actualExportName !== name) {\n this.usedNames.add(actualExportName);\n }\n\n return info;\n }\n\n /**\n * Override a credential component with environment settings key\n * This allows env settings registration to take precedence over standalone credentials\n */\n overrideCredentialWithEnvKey(id: string, filePath: string, envKey: string): ComponentInfo {\n const typeKey = `credentials:${id}`;\n\n const info: ComponentInfo = {\n id,\n type: 'credentials',\n name: envKey, // Use the environment settings key\n filePath,\n exportName: envKey,\n isInline: true,\n };\n\n // Override existing registration\n this.componentsByTypeAndId.set(typeKey, info);\n this.components.set(`${filePath}:${envKey}`, info);\n\n return info;\n }\n\n /**\n * Get component info by ID and type\n */\n get(id: string, type: ComponentType): ComponentInfo | undefined {\n const typeKey = `${type}:${id}`;\n return this.componentsByTypeAndId.get(typeKey);\n }\n\n /**\n * Get component info by variable name (since variable names are globally unique)\n */\n getByVariableName(variableName: string): ComponentInfo | undefined {\n for (const component of this.componentsByTypeAndId.values()) {\n if (component.name === variableName) {\n return component;\n }\n }\n return undefined;\n }\n\n /**\n * Get unique variable name for a component by ID and type\n */\n getVariableName(id: string, type: ComponentType): string | undefined {\n const typeKey = `${type}:${id}`;\n const result = this.componentsByTypeAndId.get(typeKey)?.name;\n\n return result;\n }\n\n /**\n * Get import statement for a component\n */\n getImportStatement(\n fromFilePath: string,\n componentId: string,\n componentType: ComponentType\n ): string | undefined {\n const component = this.get(componentId, componentType);\n if (!component) return undefined;\n\n // Normalize both paths to the same format for comparison\n const normalizedFrom = this.normalizeToProjectPath(fromFilePath);\n const normalizedTo = this.normalizeToProjectPath(component.filePath);\n\n // Skip import if same file\n if (normalizedFrom === normalizedTo) {\n return undefined;\n }\n\n const relativePath = this.calculateRelativeImport(fromFilePath, component.filePath);\n const importStmt = `import { ${component.exportName} } from '${relativePath}';`;\n\n return importStmt;\n }\n\n /**\n * Format an array of references for code generation\n */\n formatReferencesForCode(\n references: any[],\n componentType: ComponentType,\n style: { quotes: 'single' | 'double'; indentation: string },\n indentLevel: number\n ): string {\n if (!Array.isArray(references) || references.length === 0) {\n return '[]';\n }\n\n const variableNames: string[] = [];\n\n for (const ref of references) {\n const id = this.extractIdFromReference(ref);\n if (id) {\n const component = this.get(id, componentType);\n if (component) {\n variableNames.push(component.name);\n } else {\n console.warn(`ComponentRegistry: Component not found: ${id} (type: ${componentType})`);\n variableNames.push(this.toCamelCase(id));\n }\n }\n }\n\n if (variableNames.length === 0) {\n return '[]';\n }\n\n if (variableNames.length === 1) {\n return `[${variableNames[0]}]`;\n }\n\n // Multi-line format\n const { indentation } = style;\n const indent = indentation.repeat(indentLevel);\n const lines = ['['];\n\n for (let i = 0; i < variableNames.length; i++) {\n const isLast = i === variableNames.length - 1;\n lines.push(`${indent}${variableNames[i]}${isLast ? '' : ','}`);\n }\n\n lines.push(`${indentation.repeat(indentLevel - 1)}]`);\n return lines.join('\\n');\n }\n\n /**\n * Get all import statements needed for a file\n */\n getImportsForFile(\n fromFilePath: string,\n referencedComponents: Array<{ id: string; type: ComponentType }>\n ): string[] {\n const imports: string[] = [];\n const seenImports = new Set<string>(); // Deduplicate imports\n\n for (const { id, type } of referencedComponents) {\n const importStatement = this.getImportStatement(fromFilePath, id, type);\n if (importStatement && !seenImports.has(importStatement)) {\n imports.push(importStatement);\n seenImports.add(importStatement);\n }\n }\n\n return imports;\n }\n\n /**\n * Get all component IDs referenced in arrays for import generation\n */\n getReferencedComponentIds(referenceArrays: any[][]): string[] {\n const componentIds: string[] = [];\n\n for (const refArray of referenceArrays) {\n if (Array.isArray(refArray)) {\n for (const ref of refArray) {\n const id = this.extractIdFromReference(ref);\n if (id) {\n componentIds.push(id);\n }\n }\n }\n }\n\n return componentIds;\n }\n\n /**\n * Extract ID from a reference (string or object) based on component type\n */\n private extractIdFromReference(ref: any): string | null {\n if (typeof ref === 'string') {\n return ref;\n }\n if (typeof ref === 'object' && ref) {\n // Handle different component types by their specific ID fields (confirmed from debug output)\n\n // Tool references (MCP tools and function tools)\n if (ref.toolId) return ref.toolId;\n\n // Agent references (main agents and sub-agents)\n if (ref.agentId) return ref.agentId;\n\n // External agent references\n if (ref.externalAgentId) return ref.externalAgentId;\n\n // Credential store references (found in generated files)\n if (ref.credentialStoreId) return ref.credentialStoreId;\n\n // Status component references using type field (confirmed from debug output)\n if (ref.type && !ref.agentId && !ref.toolId && !ref.externalAgentId) return ref.type;\n\n // Generic ID field (fallback)\n if (ref.id) return ref.id;\n\n // Name field (fallback)\n if (ref.name) return ref.name;\n\n // For objects without recognized ID fields, warn and skip\n console.warn('ComponentRegistry: Reference without recognized ID field:', ref);\n return null;\n }\n\n return null;\n }\n\n /**\n * Convert string to camelCase and ensure it's a valid JavaScript identifier\n */\n private toCamelCase(str: string): string {\n return str\n .toLowerCase()\n .replace(/[-_](.)/g, (_, char) => char.toUpperCase())\n .replace(/[^a-zA-Z0-9]/g, '')\n .replace(/^[0-9]/, '_$&');\n }\n\n /**\n * Ensure a name is unique by adding prefixes/suffixes if needed\n */\n private ensureUniqueName(baseName: string, type: ComponentType): string {\n let uniqueName = baseName;\n let counter = 1;\n\n while (this.usedNames.has(uniqueName)) {\n // Try with type prefix first\n if (counter === 1) {\n const typePrefix = this.getTypePrefix(type);\n uniqueName = `${typePrefix}${baseName.charAt(0).toUpperCase() + baseName.slice(1)}`;\n } else {\n // Then try with counter\n uniqueName = `${baseName}${counter}`;\n }\n counter++;\n\n // Safety net to prevent infinite loops\n if (counter > 100) {\n uniqueName = `${baseName}_${Date.now()}`;\n break;\n }\n }\n\n return uniqueName;\n }\n\n /**\n * Get type prefix for uniqueness resolution\n */\n private getTypePrefix(type: ComponentType): string {\n switch (type) {\n case 'agents':\n return 'agent';\n case 'subAgents':\n return 'sub';\n case 'externalAgents':\n return 'ext';\n case 'tools':\n return 'tool';\n case 'functionTools':\n return 'func';\n case 'functions':\n return 'func';\n case 'dataComponents':\n return 'data';\n case 'artifactComponents':\n return 'artifact';\n case 'statusComponents':\n return 'status';\n case 'environments':\n return 'env';\n case 'credentials':\n return 'cred';\n case 'contextConfigs':\n return 'context';\n case 'fetchDefinitions':\n return 'fetch';\n case 'headers':\n return 'header';\n case 'models':\n return 'model';\n case 'triggers':\n return 'trigger';\n case 'project':\n return 'project';\n default:\n return 'comp';\n }\n }\n\n /**\n * Normalize path to project-relative format using existing registry paths as templates\n */\n private normalizeToProjectPath(filePath: string): string {\n // If already in project format (no slashes before known directories), return as-is\n if (!filePath.includes('/') || filePath.match(/^(agents|tools|environments|data-components)/)) {\n return filePath;\n }\n\n // Find project directories by looking at existing registry paths\n const knownDirs = new Set<string>();\n for (const component of this.components.values()) {\n const firstDir = component.filePath.split('/')[0];\n if (firstDir) knownDirs.add(firstDir);\n }\n\n // Find the last occurrence of any known project directory\n const segments = filePath.split('/');\n for (let i = segments.length - 1; i >= 0; i--) {\n if (knownDirs.has(segments[i])) {\n return segments.slice(i).join('/');\n }\n }\n\n // Fallback: return the filename\n return segments[segments.length - 1] || filePath;\n }\n\n /**\n * Calculate relative import path between files\n */\n private calculateRelativeImport(fromPath: string, toPath: string): string {\n // Remove .ts extensions for calculation\n const fromParts = fromPath.replace('.ts', '').split('/');\n const toParts = toPath.replace('.ts', '').split('/');\n\n // Remove filename from fromPath (keep directory only)\n const fromDir = fromParts.slice(0, -1);\n const toFile = toParts;\n\n // Find common path prefix\n let commonLength = 0;\n while (\n commonLength < fromDir.length &&\n commonLength < toFile.length - 1 &&\n fromDir[commonLength] === toFile[commonLength]\n ) {\n commonLength++;\n }\n\n // Calculate relative path\n let relativePath = '';\n\n // Go up for remaining directories in fromDir after common path\n const upLevels = fromDir.length - commonLength;\n for (let i = 0; i < upLevels; i++) {\n relativePath += '../';\n }\n\n // Add remaining path from toFile after common path\n const remainingPath = toFile.slice(commonLength).join('/');\n relativePath += remainingPath;\n\n // Clean up path format\n if (relativePath.startsWith('../')) {\n return relativePath;\n }\n return `./${relativePath}`;\n }\n\n /**\n * Get all components for debugging\n */\n getAllComponents(): ComponentInfo[] {\n return Array.from(this.componentsByTypeAndId.values());\n }\n\n /**\n * Get all components in a specific file\n */\n getComponentsInFile(filePath: string): ComponentInfo[] {\n return Array.from(this.componentsByTypeAndId.values()).filter(\n (component) => component.filePath === filePath\n );\n }\n\n /**\n * Remove a component from the registry\n */\n removeComponent(type: string, id: string): void {\n const key = `${type}:${id}`;\n const component = this.componentsByTypeAndId.get(key);\n\n if (component) {\n // Remove from both maps\n this.componentsByTypeAndId.delete(key);\n this.components.delete(component.name);\n\n // Remove from used names if no other component uses it\n const nameStillUsed = Array.from(this.componentsByTypeAndId.values()).some(\n (comp) => comp.name === component.name\n );\n if (!nameStillUsed) {\n this.usedNames.delete(component.name);\n }\n }\n }\n\n /**\n * Clear all components (for testing)\n */\n clear(): void {\n this.components.clear();\n this.componentsByTypeAndId.clear();\n this.usedNames.clear();\n }\n}\n\n/**\n * Register all components from a project with their file paths\n */\nexport function registerAllComponents(\n project: FullProjectDefinition,\n registry: ComponentRegistry\n): void {\n // Register project\n registry.register(project.id, 'project', 'index.ts');\n\n // Register credentials\n if (project.credentialReferences) {\n for (const credId of Object.keys(project.credentialReferences)) {\n registry.register(credId, 'credentials', `credentials/${credId}.ts`);\n }\n }\n\n // Register tools\n if (project.tools) {\n for (const toolId of Object.keys(project.tools)) {\n registry.register(toolId, 'tools', `tools/${toolId}.ts`);\n }\n }\n\n // Register function tools - functionTools has the name/description, functions has the code\n // We generate files based on functionTools IDs since that's the user-facing entity\n const registeredFunctionToolIds = new Set<string>();\n\n // Register functionTools first (they have the name that identifies the tool)\n if (project.functionTools) {\n for (const funcToolId of Object.keys(project.functionTools)) {\n registry.register(funcToolId, 'functionTools', `tools/functions/${funcToolId}.ts`);\n registeredFunctionToolIds.add(funcToolId);\n }\n }\n\n // Also check agent-level functionTools\n if (project.agents) {\n for (const agentData of Object.values(project.agents)) {\n const agentFunctionTools = (agentData as any).functionTools;\n if (agentFunctionTools) {\n for (const funcToolId of Object.keys(agentFunctionTools)) {\n if (!registeredFunctionToolIds.has(funcToolId)) {\n registry.register(funcToolId, 'functionTools', `tools/functions/${funcToolId}.ts`);\n registeredFunctionToolIds.add(funcToolId);\n }\n }\n }\n }\n }\n\n // Register data components\n if (project.dataComponents) {\n for (const componentId of Object.keys(project.dataComponents)) {\n registry.register(componentId, 'dataComponents', `data-components/${componentId}.ts`);\n }\n }\n\n // Register artifact components\n if (project.artifactComponents) {\n for (const componentId of Object.keys(project.artifactComponents)) {\n registry.register(componentId, 'artifactComponents', `artifact-components/${componentId}.ts`);\n }\n }\n\n // Register external agents\n if (project.externalAgents) {\n for (const extAgentId of Object.keys(project.externalAgents)) {\n registry.register(extAgentId, 'externalAgents', `external-agents/${extAgentId}.ts`);\n }\n }\n\n // Register skills\n if (project.skills) {\n for (const skillId of Object.keys(project.skills)) {\n registry.register(skillId, 'skills', `skills/${skillId}.md`);\n }\n }\n\n // Register extracted status components\n const statusComponents = extractStatusComponents(project);\n for (const statusId of Object.keys(statusComponents)) {\n registry.register(statusId, 'statusComponents', `status-components/${statusId}.ts`);\n }\n\n // Register agents\n if (project.agents) {\n for (const agentId of Object.keys(project.agents)) {\n registry.register(agentId, 'agents', `agents/${agentId}.ts`);\n }\n }\n\n // Register triggers (agent-scoped)\n if (project.agents) {\n for (const agentData of Object.values(project.agents)) {\n const agentTriggers = (agentData as any).triggers;\n if (agentTriggers) {\n for (const triggerId of Object.keys(agentTriggers)) {\n registry.register(triggerId, 'triggers', `agents/triggers/${triggerId}.ts`);\n }\n }\n }\n }\n\n // Register extracted sub-agents\n const subAgents = extractSubAgents(project);\n for (const subAgentId of Object.keys(subAgents)) {\n registry.register(subAgentId, 'subAgents', `agents/sub-agents/${subAgentId}.ts`);\n }\n\n // Register extracted context configs\n const contextConfigs = extractContextConfigs(project);\n for (const contextId of Object.keys(contextConfigs)) {\n registry.register(contextId, 'contextConfigs', `context-configs/${contextId}.ts`);\n }\n}\n\n/**\n * Extract status components from project agents\n */\nfunction extractStatusComponents(project: FullProjectDefinition): Record<string, any> {\n const statusComponents: Record<string, any> = {};\n\n if (project.agents) {\n for (const agentData of Object.values(project.agents)) {\n if (agentData.statusUpdates?.statusComponents) {\n // statusComponents is an array that can contain strings or objects\n for (const statusComp of agentData.statusUpdates.statusComponents) {\n let statusId: string;\n\n if (typeof statusComp === 'string') {\n // Direct string reference to status component ID\n statusId = statusComp;\n } else if (typeof statusComp === 'object' && statusComp) {\n // Object with id, type, or name field\n statusId = statusComp.type;\n } else {\n continue;\n }\n\n if (statusId && !statusComponents[statusId]) {\n // Use the actual status component data instead of creating dummy data\n statusComponents[statusId] = {\n // Include any other properties from the actual data first\n ...statusComp,\n id: statusId,\n type: statusComp.type || statusId,\n description: statusComp.description || `Status component for ${statusId}`,\n detailsSchema: statusComp.detailsSchema,\n };\n }\n }\n }\n }\n }\n\n return statusComponents;\n}\n\n/**\n * Extract sub-agents from project agents\n */\nexport function extractSubAgents(project: FullProjectDefinition): Record<string, any> {\n const subAgents: Record<string, any> = {};\n\n if (project.agents) {\n for (const agentData of Object.values(project.agents)) {\n if (agentData.subAgents) {\n for (const [subAgentId, subAgentData] of Object.entries(agentData.subAgents)) {\n subAgents[subAgentId] = subAgentData;\n }\n }\n }\n }\n\n return subAgents;\n}\n\n/**\n * Extract context configs from project agents\n */\nfunction extractContextConfigs(project: FullProjectDefinition): Record<string, any> {\n const contextConfigs: Record<string, any> = {};\n\n if (project.agents) {\n for (const [agentId, agentData] of Object.entries(project.agents)) {\n if (agentData.contextConfig) {\n // Use the actual contextConfig.id (now required)\n const contextConfigId = agentData.contextConfig.id;\n if (contextConfigId) {\n contextConfigs[contextConfigId] = agentData.contextConfig;\n } else {\n console.warn(`contextConfig for agent ${agentId} is missing required 'id' field`);\n }\n }\n }\n }\n\n return contextConfigs;\n}\n\n/**\n * Find sub-agent data with parent agent info for contextConfig resolution\n */\nexport function findSubAgentWithParent(\n project: FullProjectDefinition,\n subAgentId: string\n): { subAgentData: any; parentAgentId: string; contextConfigData?: any } | undefined {\n if (project.agents) {\n for (const [agentId, agentData] of Object.entries(project.agents)) {\n if (agentData.subAgents?.[subAgentId]) {\n // Get contextConfig data if parent agent has one with an ID\n const contextConfigData = agentData.contextConfig?.id ? agentData.contextConfig : undefined;\n\n return {\n subAgentData: agentData.subAgents[subAgentId],\n parentAgentId: agentId,\n contextConfigData,\n };\n }\n }\n }\n return undefined;\n}\n"],"mappings":";AAwCA,IAAa,oBAAb,MAA+B;CAC7B,AAAQ,6BAAa,IAAI,KAA4B;CACrD,AAAQ,wCAAwB,IAAI,KAA4B;CAChE,AAAQ,4BAAY,IAAI,KAAa;;;;CAKrC,SACE,IACA,MACA,UACA,YACA,WAAoB,OACL;EACf,MAAM,UAAU,GAAG,KAAK,GAAG;EAG3B,MAAM,WAAW,KAAK,sBAAsB,IAAI,QAAQ;AACxD,MAAI,SACF,QAAO;EAGT,IAAI;EACJ,IAAI;AAIJ,MAAI,YAAY;AAEd,UAAO;AACP,sBAAmB;SACd;GAEL,MAAM,WAAW,KAAK,YAAY,GAAG;GACrC,MAAM,aAAa,KAAK,iBAAiB,UAAU,KAAK;AACxD,UAAO;AACP,sBAAmB;;EAGrB,MAAM,OAAsB;GAC1B;GACA;GACA;GACA;GACA,YAAY;GACZ;GACD;AAGD,OAAK,WAAW,IAAI,IAAI,KAAK;AAC7B,OAAK,sBAAsB,IAAI,SAAS,KAAK;AAE7C,OAAK,UAAU,IAAI,KAAK;AACxB,MAAI,oBAAoB,qBAAqB,KAC3C,MAAK,UAAU,IAAI,iBAAiB;AAGtC,SAAO;;;;;;CAOT,6BAA6B,IAAY,UAA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,eAAe;IACf;IACD"}
@@ -43,20 +43,6 @@ function addTriggerImports(sourceFile, referenceNames, importRefs) {
43
43
  });
44
44
  }
45
45
  }
46
- function addScheduledTriggerImports(sourceFile, referenceNames, importRefs) {
47
- for (const [scheduledTriggerId, referenceName] of referenceNames) {
48
- const importRef = importRefs.get(scheduledTriggerId);
49
- if (!importRef) continue;
50
- const { importName, modulePath } = importRef;
51
- sourceFile.addImportDeclaration({
52
- namedImports: [importName === referenceName ? importName : {
53
- name: importName,
54
- alias: referenceName
55
- }],
56
- moduleSpecifier: `./scheduled-triggers/${modulePath}`
57
- });
58
- }
59
- }
60
46
  function extractStatusComponentIds(statusUpdates) {
61
47
  if (!statusUpdates?.statusComponents?.length) return [];
62
48
  const statusComponentIds = statusUpdates.statusComponents.map(resolveStatusComponentId);
@@ -105,35 +91,6 @@ function createReferenceNameMap(ids, reservedNames, conflictSuffix) {
105
91
  }
106
92
  return map;
107
93
  }
108
- function createScheduledTriggerReferenceMaps(scheduledTriggers, reservedNames) {
109
- const referenceNames = /* @__PURE__ */ new Map();
110
- const importRefs = /* @__PURE__ */ new Map();
111
- if (!scheduledTriggers || !isPlainObject(scheduledTriggers)) return {
112
- referenceNames,
113
- importRefs
114
- };
115
- const moduleNameCounts = /* @__PURE__ */ new Map();
116
- for (const [scheduledTriggerId, scheduledTriggerData] of Object.entries(scheduledTriggers)) {
117
- if (referenceNames.has(scheduledTriggerId)) continue;
118
- const scheduledTriggerRecord = isPlainObject(scheduledTriggerData) ? scheduledTriggerData : void 0;
119
- const scheduledTriggerName = typeof scheduledTriggerRecord?.name === "string" && scheduledTriggerRecord.name.length > 0 ? scheduledTriggerRecord.name : scheduledTriggerId;
120
- const importName = toTriggerReferenceName(scheduledTriggerName);
121
- const referenceName = createNumericReferenceName(importName, reservedNames);
122
- const baseModuleName = toKebabCase(scheduledTriggerName) || toKebabCase(scheduledTriggerId) || scheduledTriggerId;
123
- const moduleCount = moduleNameCounts.get(baseModuleName) ?? 0;
124
- moduleNameCounts.set(baseModuleName, moduleCount + 1);
125
- const modulePath = moduleCount === 0 ? baseModuleName : `${baseModuleName}-${moduleCount}`;
126
- referenceNames.set(scheduledTriggerId, referenceName);
127
- importRefs.set(scheduledTriggerId, {
128
- importName,
129
- modulePath
130
- });
131
- }
132
- return {
133
- referenceNames,
134
- importRefs
135
- };
136
- }
137
94
  function createTriggerReferenceMaps(triggers, reservedNames) {
138
95
  const referenceNames = /* @__PURE__ */ new Map();
139
96
  const importRefs = /* @__PURE__ */ new Map();
@@ -176,5 +133,5 @@ function createNumericReferenceName(baseName, reservedNames) {
176
133
  }
177
134
 
178
135
  //#endregion
179
- export { addScheduledTriggerImports, addStatusComponentImports, addSubAgentImports, addTriggerImports, createReferenceNameMap, createScheduledTriggerReferenceMaps, createSubAgentReferenceMaps, createTriggerReferenceMaps, extractContextConfigId, extractIds, extractStatusComponentIds, resolveStatusComponentId };
136
+ export { addStatusComponentImports, addSubAgentImports, addTriggerImports, createReferenceNameMap, createSubAgentReferenceMaps, createTriggerReferenceMaps, extractContextConfigId, extractIds, extractStatusComponentIds, resolveStatusComponentId };
180
137
  //# sourceMappingURL=agent-generator.helpers.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"agent-generator.helpers.js","names":[],"sources":["../../../../src/commands/pull-v4/generators/agent-generator.helpers.ts"],"sourcesContent":["import type { SourceFile } from 'ts-morph';\nimport {\n createUniqueReferenceName,\n isPlainObject,\n toCamelCase,\n toKebabCase,\n toTriggerReferenceName,\n} from '../utils';\n\nexport type ReferenceNameMap = Map<string, string>;\nexport type TriggerImportMap = Map<string, { importName: string; modulePath: string }>;\n\ninterface SubAgentReferenceOverride {\n name: string;\n local?: boolean;\n}\n\ntype StatusComponentLike = string | { id?: string; type?: string; name?: string };\ntype StatusUpdatesLike = { statusComponents?: StatusComponentLike[] } | undefined;\n\nexport function extractIds(value: unknown[] | Record<string, unknown>): string[] {\n if (Array.isArray(value)) {\n return value\n .map((item) => {\n if (typeof item === 'string') {\n return item;\n }\n if (isPlainObject(item) && typeof item.id === 'string') {\n return item.id;\n }\n return null;\n })\n .filter((id): id is string => Boolean(id));\n }\n return Object.keys(value);\n}\n\nexport function extractContextConfigId(\n contextConfig?: string | { id?: string }\n): string | undefined {\n if (!contextConfig) {\n return;\n }\n if (typeof contextConfig === 'string') {\n return contextConfig;\n }\n return contextConfig.id;\n}\n\nexport function addSubAgentImports(\n sourceFile: SourceFile,\n referenceNames: ReferenceNameMap,\n importNames: ReferenceNameMap,\n modulePathOverrides?: Record<string, string>\n): void {\n for (const [subAgentId, referenceName] of referenceNames) {\n const importName = importNames.get(subAgentId);\n if (!importName) {\n continue;\n }\n\n sourceFile.addImportDeclaration({\n namedImports: [\n importName === referenceName ? importName : { name: importName, alias: referenceName },\n ],\n moduleSpecifier: `./sub-agents/${modulePathOverrides?.[subAgentId] ?? subAgentId}`,\n });\n }\n}\n\nexport function addTriggerImports(\n sourceFile: SourceFile,\n referenceNames: ReferenceNameMap,\n importRefs: TriggerImportMap\n): void {\n for (const [triggerId, referenceName] of referenceNames) {\n const importRef = importRefs.get(triggerId);\n if (!importRef) {\n continue;\n }\n\n const { importName, modulePath } = importRef;\n sourceFile.addImportDeclaration({\n namedImports: [\n importName === referenceName ? importName : { name: importName, alias: referenceName },\n ],\n moduleSpecifier: `./triggers/${modulePath}`,\n });\n }\n}\n\nexport function addScheduledTriggerImports(\n sourceFile: SourceFile,\n referenceNames: ReferenceNameMap,\n importRefs: TriggerImportMap\n): void {\n for (const [scheduledTriggerId, referenceName] of referenceNames) {\n const importRef = importRefs.get(scheduledTriggerId);\n if (!importRef) {\n continue;\n }\n\n const { importName, modulePath } = importRef;\n sourceFile.addImportDeclaration({\n namedImports: [\n importName === referenceName ? importName : { name: importName, alias: referenceName },\n ],\n moduleSpecifier: `./scheduled-triggers/${modulePath}`,\n });\n }\n}\n\nexport function extractStatusComponentIds(statusUpdates: StatusUpdatesLike): string[] {\n if (!statusUpdates?.statusComponents?.length) {\n return [];\n }\n\n const statusComponentIds = statusUpdates.statusComponents.map(resolveStatusComponentId);\n return [...new Set(statusComponentIds)];\n}\n\nexport function resolveStatusComponentId(statusComponent: StatusComponentLike): string {\n const id =\n typeof statusComponent === 'string'\n ? statusComponent\n : statusComponent.id || statusComponent.type;\n if (!id) {\n throw new Error(\n `Unable to resolve status component with id ${JSON.stringify(statusComponent)}`\n );\n }\n return id;\n}\n\nexport function addStatusComponentImports(\n sourceFile: SourceFile,\n referenceNames: ReferenceNameMap\n): void {\n for (const [statusComponentId, referenceName] of referenceNames) {\n const importName = toCamelCase(statusComponentId);\n sourceFile.addImportDeclaration({\n namedImports: [\n importName === referenceName ? importName : { name: importName, alias: referenceName },\n ],\n moduleSpecifier: `../status-components/${statusComponentId}`,\n });\n }\n}\n\nexport function createSubAgentReferenceMaps(\n ids: Iterable<string>,\n reservedNames: Set<string>,\n conflictSuffix: string,\n overrides?: Record<string, SubAgentReferenceOverride>\n): {\n referenceNames: ReferenceNameMap;\n importNames: ReferenceNameMap;\n} {\n const referenceNames: ReferenceNameMap = new Map();\n const importNames: ReferenceNameMap = new Map();\n\n for (const id of ids) {\n if (referenceNames.has(id)) {\n continue;\n }\n\n const override = overrides?.[id];\n const importName = override?.name ?? toCamelCase(id);\n const isLocal = override?.local === true;\n const referenceName = isLocal\n ? importName\n : createUniqueReferenceName(importName, reservedNames, conflictSuffix);\n\n if (isLocal) {\n reservedNames.add(referenceName);\n } else {\n importNames.set(id, importName);\n }\n\n referenceNames.set(id, referenceName);\n }\n\n return { referenceNames, importNames };\n}\n\nexport function createReferenceNameMap(\n ids: Iterable<string>,\n reservedNames: Set<string>,\n conflictSuffix: string\n): ReferenceNameMap {\n const map: ReferenceNameMap = new Map();\n for (const id of ids) {\n if (map.has(id)) {\n continue;\n }\n map.set(id, createUniqueReferenceName(toCamelCase(id), reservedNames, conflictSuffix));\n }\n return map;\n}\n\nexport function createScheduledTriggerReferenceMaps(\n scheduledTriggers: unknown,\n reservedNames: Set<string>\n): {\n referenceNames: ReferenceNameMap;\n importRefs: TriggerImportMap;\n} {\n const referenceNames: ReferenceNameMap = new Map();\n const importRefs: TriggerImportMap = new Map();\n\n if (!scheduledTriggers || !isPlainObject(scheduledTriggers)) {\n return { referenceNames, importRefs };\n }\n\n const moduleNameCounts = new Map<string, number>();\n\n for (const [scheduledTriggerId, scheduledTriggerData] of Object.entries(scheduledTriggers)) {\n if (referenceNames.has(scheduledTriggerId)) {\n continue;\n }\n\n const scheduledTriggerRecord = isPlainObject(scheduledTriggerData)\n ? scheduledTriggerData\n : undefined;\n const scheduledTriggerName =\n typeof scheduledTriggerRecord?.name === 'string' && scheduledTriggerRecord.name.length > 0\n ? scheduledTriggerRecord.name\n : scheduledTriggerId;\n\n const importName = toTriggerReferenceName(scheduledTriggerName);\n const referenceName = createNumericReferenceName(importName, reservedNames);\n\n const baseModuleName =\n toKebabCase(scheduledTriggerName) || toKebabCase(scheduledTriggerId) || scheduledTriggerId;\n const moduleCount = moduleNameCounts.get(baseModuleName) ?? 0;\n moduleNameCounts.set(baseModuleName, moduleCount + 1);\n const modulePath = moduleCount === 0 ? baseModuleName : `${baseModuleName}-${moduleCount}`;\n\n referenceNames.set(scheduledTriggerId, referenceName);\n importRefs.set(scheduledTriggerId, { importName, modulePath });\n }\n\n return { referenceNames, importRefs };\n}\n\nexport function createTriggerReferenceMaps(\n triggers: unknown,\n reservedNames: Set<string>\n): {\n referenceNames: ReferenceNameMap;\n importRefs: TriggerImportMap;\n} {\n const referenceNames: ReferenceNameMap = new Map();\n const importRefs: TriggerImportMap = new Map();\n\n if (!triggers || !isPlainObject(triggers)) {\n return { referenceNames, importRefs };\n }\n\n const moduleNameCounts = new Map<string, number>();\n\n for (const [triggerId, triggerData] of Object.entries(triggers)) {\n if (referenceNames.has(triggerId)) {\n continue;\n }\n\n const triggerRecord = isPlainObject(triggerData) ? triggerData : undefined;\n const triggerName =\n typeof triggerRecord?.name === 'string' && triggerRecord.name.length > 0\n ? triggerRecord.name\n : triggerId;\n\n const importName = toTriggerReferenceName(triggerName);\n const referenceName = createNumericReferenceName(importName, reservedNames);\n\n const baseModuleName = toKebabCase(triggerName) || toKebabCase(triggerId) || triggerId;\n const moduleCount = moduleNameCounts.get(baseModuleName) ?? 0;\n moduleNameCounts.set(baseModuleName, moduleCount + 1);\n const modulePath = moduleCount === 0 ? baseModuleName : `${baseModuleName}-${moduleCount}`;\n\n referenceNames.set(triggerId, referenceName);\n importRefs.set(triggerId, { importName, modulePath });\n }\n\n return { referenceNames, importRefs };\n}\n\nfunction createNumericReferenceName(baseName: string, reservedNames: Set<string>): string {\n if (!reservedNames.has(baseName)) {\n reservedNames.add(baseName);\n return baseName;\n }\n\n let index = 1;\n while (reservedNames.has(`${baseName}${index}`)) {\n index += 1;\n }\n\n const uniqueName = `${baseName}${index}`;\n reservedNames.add(uniqueName);\n return uniqueName;\n}\n"],"mappings":";;;;;AAoBA,SAAgB,WAAW,OAAsD;AAC/E,KAAI,MAAM,QAAQ,MAAM,CACtB,QAAO,MACJ,KAAK,SAAS;AACb,MAAI,OAAO,SAAS,SAClB,QAAO;AAET,MAAI,cAAc,KAAK,IAAI,OAAO,KAAK,OAAO,SAC5C,QAAO,KAAK;AAEd,SAAO;GACP,CACD,QAAQ,OAAqB,QAAQ,GAAG,CAAC;AAE9C,QAAO,OAAO,KAAK,MAAM;;AAG3B,SAAgB,uBACd,eACoB;AACpB,KAAI,CAAC,cACH;AAEF,KAAI,OAAO,kBAAkB,SAC3B,QAAO;AAET,QAAO,cAAc;;AAGvB,SAAgB,mBACd,YACA,gBACA,aACA,qBACM;AACN,MAAK,MAAM,CAAC,YAAY,kBAAkB,gBAAgB;EACxD,MAAM,aAAa,YAAY,IAAI,WAAW;AAC9C,MAAI,CAAC,WACH;AAGF,aAAW,qBAAqB;GAC9B,cAAc,CACZ,eAAe,gBAAgB,aAAa;IAAE,MAAM;IAAY,OAAO;IAAe,CACvF;GACD,iBAAiB,gBAAgB,sBAAsB,eAAe;GACvE,CAAC;;;AAIN,S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AGT,IAAI,QAAQ;AACZ,QAAO,cAAc,IAAI,GAAG,WAAW,QAAQ,CAC7C,UAAS;CAGX,MAAM,aAAa,GAAG,WAAW;AACjC,eAAc,IAAI,WAAW;AAC7B,QAAO"}
1
+ {"version":3,"file":"agent-generator.helpers.js","names":[],"sources":["../../../../src/commands/pull-v4/generators/agent-generator.helpers.ts"],"sourcesContent":["import type { SourceFile } from 'ts-morph';\nimport {\n createUniqueReferenceName,\n isPlainObject,\n toCamelCase,\n toKebabCase,\n toTriggerReferenceName,\n} from '../utils';\n\nexport type ReferenceNameMap = Map<string, string>;\nexport type TriggerImportMap = Map<string, { importName: string; modulePath: string }>;\n\ninterface SubAgentReferenceOverride {\n name: string;\n local?: boolean;\n}\n\ntype StatusComponentLike = string | { id?: string; type?: string; name?: string };\ntype StatusUpdatesLike = { statusComponents?: StatusComponentLike[] } | undefined;\n\nexport function extractIds(value: unknown[] | Record<string, unknown>): string[] {\n if (Array.isArray(value)) {\n return value\n .map((item) => {\n if (typeof item === 'string') {\n return item;\n }\n if (isPlainObject(item) && typeof item.id === 'string') {\n return item.id;\n }\n return null;\n })\n .filter((id): id is string => Boolean(id));\n }\n return Object.keys(value);\n}\n\nexport function extractContextConfigId(\n contextConfig?: string | { id?: string }\n): string | undefined {\n if (!contextConfig) {\n return;\n }\n if (typeof contextConfig === 'string') {\n return contextConfig;\n }\n return contextConfig.id;\n}\n\nexport function addSubAgentImports(\n sourceFile: SourceFile,\n referenceNames: ReferenceNameMap,\n importNames: ReferenceNameMap,\n modulePathOverrides?: Record<string, string>\n): void {\n for (const [subAgentId, referenceName] of referenceNames) {\n const importName = importNames.get(subAgentId);\n if (!importName) {\n continue;\n }\n\n sourceFile.addImportDeclaration({\n namedImports: [\n importName === referenceName ? importName : { name: importName, alias: referenceName },\n ],\n moduleSpecifier: `./sub-agents/${modulePathOverrides?.[subAgentId] ?? subAgentId}`,\n });\n }\n}\n\nexport function addTriggerImports(\n sourceFile: SourceFile,\n referenceNames: ReferenceNameMap,\n importRefs: TriggerImportMap\n): void {\n for (const [triggerId, referenceName] of referenceNames) {\n const importRef = importRefs.get(triggerId);\n if (!importRef) {\n continue;\n }\n\n const { importName, modulePath } = importRef;\n sourceFile.addImportDeclaration({\n namedImports: [\n importName === referenceName ? importName : { name: importName, alias: referenceName },\n ],\n moduleSpecifier: `./triggers/${modulePath}`,\n });\n }\n}\n\nexport function extractStatusComponentIds(statusUpdates: StatusUpdatesLike): string[] {\n if (!statusUpdates?.statusComponents?.length) {\n return [];\n }\n\n const statusComponentIds = statusUpdates.statusComponents.map(resolveStatusComponentId);\n return [...new Set(statusComponentIds)];\n}\n\nexport function resolveStatusComponentId(statusComponent: StatusComponentLike): string {\n const id =\n typeof statusComponent === 'string'\n ? statusComponent\n : statusComponent.id || statusComponent.type;\n if (!id) {\n throw new Error(\n `Unable to resolve status component with id ${JSON.stringify(statusComponent)}`\n );\n }\n return id;\n}\n\nexport function addStatusComponentImports(\n sourceFile: SourceFile,\n referenceNames: ReferenceNameMap\n): void {\n for (const [statusComponentId, referenceName] of referenceNames) {\n const importName = toCamelCase(statusComponentId);\n sourceFile.addImportDeclaration({\n namedImports: [\n importName === referenceName ? importName : { name: importName, alias: referenceName },\n ],\n moduleSpecifier: `../status-components/${statusComponentId}`,\n });\n }\n}\n\nexport function createSubAgentReferenceMaps(\n ids: Iterable<string>,\n reservedNames: Set<string>,\n conflictSuffix: string,\n overrides?: Record<string, SubAgentReferenceOverride>\n): {\n referenceNames: ReferenceNameMap;\n importNames: ReferenceNameMap;\n} {\n const referenceNames: ReferenceNameMap = new Map();\n const importNames: ReferenceNameMap = new Map();\n\n for (const id of ids) {\n if (referenceNames.has(id)) {\n continue;\n }\n\n const override = overrides?.[id];\n const importName = override?.name ?? toCamelCase(id);\n const isLocal = override?.local === true;\n const referenceName = isLocal\n ? importName\n : createUniqueReferenceName(importName, reservedNames, conflictSuffix);\n\n if (isLocal) {\n reservedNames.add(referenceName);\n } else {\n importNames.set(id, importName);\n }\n\n referenceNames.set(id, referenceName);\n }\n\n return { referenceNames, importNames };\n}\n\nexport function createReferenceNameMap(\n ids: Iterable<string>,\n reservedNames: Set<string>,\n conflictSuffix: string\n): ReferenceNameMap {\n const map: ReferenceNameMap = new Map();\n for (const id of ids) {\n if (map.has(id)) {\n continue;\n }\n map.set(id, createUniqueReferenceName(toCamelCase(id), reservedNames, conflictSuffix));\n }\n return map;\n}\n\nexport function createTriggerReferenceMaps(\n triggers: unknown,\n reservedNames: Set<string>\n): {\n referenceNames: ReferenceNameMap;\n importRefs: TriggerImportMap;\n} {\n const referenceNames: ReferenceNameMap = new Map();\n const importRefs: TriggerImportMap = new Map();\n\n if (!triggers || !isPlainObject(triggers)) {\n return { referenceNames, importRefs };\n }\n\n const moduleNameCounts = new Map<string, number>();\n\n for (const [triggerId, triggerData] of Object.entries(triggers)) {\n if (referenceNames.has(triggerId)) {\n continue;\n }\n\n const triggerRecord = isPlainObject(triggerData) ? triggerData : undefined;\n const triggerName =\n typeof triggerRecord?.name === 'string' && triggerRecord.name.length > 0\n ? triggerRecord.name\n : triggerId;\n\n const importName = toTriggerReferenceName(triggerName);\n const referenceName = createNumericReferenceName(importName, reservedNames);\n\n const baseModuleName = toKebabCase(triggerName) || toKebabCase(triggerId) || triggerId;\n const moduleCount = moduleNameCounts.get(baseModuleName) ?? 0;\n moduleNameCounts.set(baseModuleName, moduleCount + 1);\n const modulePath = moduleCount === 0 ? baseModuleName : `${baseModuleName}-${moduleCount}`;\n\n referenceNames.set(triggerId, referenceName);\n importRefs.set(triggerId, { importName, modulePath });\n }\n\n return { referenceNames, importRefs };\n}\n\nfunction createNumericReferenceName(baseName: string, reservedNames: Set<string>): string {\n if (!reservedNames.has(baseName)) {\n reservedNames.add(baseName);\n return baseName;\n }\n\n let index = 1;\n while (reservedNames.has(`${baseName}${index}`)) {\n index += 1;\n }\n\n const uniqueName = `${baseName}${index}`;\n reservedNames.add(uniqueName);\n return uniqueName;\n}\n"],"mappings":";;;;;AAoBA,S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KAAqB;AAElD,MAAK,MAAM,CAAC,WAAW,gBAAgB,OAAO,QAAQ,SAAS,EAAE;AAC/D,MAAI,eAAe,IAAI,UAAU,CAC/B;EAGF,MAAM,gBAAgB,cAAc,YAAY,GAAG,cAAc;EACjE,MAAM,cACJ,OAAO,eAAe,SAAS,YAAY,cAAc,KAAK,SAAS,IACnE,cAAc,OACd;EAEN,MAAM,aAAa,uBAAuB,YAAY;EACtD,MAAM,gBAAgB,2BAA2B,YAAY,cAAc;EAE3E,MAAM,iBAAiB,YAAY,YAAY,IAAI,YAAY,UAAU,IAAI;EAC7E,MAAM,cAAc,iBAAiB,IAAI,eAAe,IAAI;AAC5D,mBAAiB,IAAI,gBAAgB,cAAc,EAAE;EACrD,MAAM,aAAa,gBAAgB,IAAI,iBAAiB,GAAG,eAAe,GAAG;AAE7E,iBAAe,IAAI,WAAW,cAAc;AAC5C,aAAW,IAAI,WAAW;GAAE;GAAY;GAAY,CAAC;;AAGvD,QAAO;EAAE;EAAgB;EAAY;;AAGvC,SAAS,2BAA2B,UAAkB,eAAoC;AACxF,KAAI,CAAC,cAAc,IAAI,SAAS,EAAE;AAChC,gBAAc,IAAI,SAAS;AAC3B,SAAO;;CAGT,IAAI,QAAQ;AACZ,QAAO,cAAc,IAAI,GAAG,WAAW,QAAQ,CAC7C,UAAS;CAGX,MAAM,aAAa,GAAG,WAAW;AACjC,eAAc,IAAI,WAAW;AAC7B,QAAO"}
@@ -8,7 +8,7 @@ import { asRecord, collectTemplateVariablesFromValues } from "../collector-commo
8
8
  import { collectContextTemplateReferences, collectSubAgentReferenceOverrides, collectSubAgentReferencePathOverrides } from "../collector-reference-helpers.js";
9
9
  import { addResolvedReferenceImports, resolveReferenceBinding, resolveReferenceBindingsFromIds, toReferenceNameMap } from "../reference-resolution.js";
10
10
  import { generateFactorySourceFile } from "../simple-factory-generator.js";
11
- import { addScheduledTriggerImports, addStatusComponentImports, addTriggerImports, createReferenceNameMap, createScheduledTriggerReferenceMaps, createTriggerReferenceMaps, extractIds } from "./helpers/agent.js";
11
+ import { addStatusComponentImports, addTriggerImports, createReferenceNameMap, createTriggerReferenceMaps, extractIds } from "./helpers/agent.js";
12
12
  import { AgentWithinContextOfProjectSchemaBase } from "@inkeep/agents-core";
13
13
  import { z } from "zod";
14
14
  import { join } from "node:path";
@@ -122,8 +122,6 @@ function generateAgentDefinition({ id, createdAt, updatedAt, ...data }) {
122
122
  }
123
123
  const { referenceNames: triggerReferenceNames, importRefs: triggerImportRefs } = createTriggerReferenceMaps(parsed.triggers, reservedReferenceNames);
124
124
  addTriggerImports(sourceFile, triggerReferenceNames, triggerImportRefs);
125
- const { referenceNames: scheduledTriggerReferenceNames, importRefs: scheduledTriggerImportRefs } = createScheduledTriggerReferenceMaps(parsed.scheduledTriggers, reservedReferenceNames);
126
- addScheduledTriggerImports(sourceFile, scheduledTriggerReferenceNames, scheduledTriggerImportRefs);
127
125
  const statusComponentReferenceNames = createReferenceNameMap(parsed.normalizedStatusComponentIds, reservedReferenceNames, "StatusComponent");
128
126
  addStatusComponentImports(sourceFile, statusComponentReferenceNames);
129
127
  writeAgentConfig(configObject, parsed, {
@@ -131,7 +129,6 @@ function generateAgentDefinition({ id, createdAt, updatedAt, ...data }) {
131
129
  contextConfig: contextConfigReferenceName,
132
130
  contextHeaders: contextHeadersReferenceName,
133
131
  triggers: triggerReferenceNames,
134
- scheduledTriggers: scheduledTriggerReferenceNames,
135
132
  statusComponents: statusComponentReferenceNames
136
133
  });
137
134
  }
@@ -155,8 +152,6 @@ function writeAgentConfig(configObject, data, referenceNames) {
155
152
  if (data.normalizedContextConfigId && referenceNames.contextConfig) agentConfig.contextConfig = codeReference(referenceNames.contextConfig);
156
153
  const triggerIds = data.triggers ? extractIds(data.triggers) : [];
157
154
  if (triggerIds.length) agentConfig.triggers = createReferenceGetterValue(triggerIds.map((id) => referenceNames.triggers.get(id) ?? toTriggerReferenceName(id)));
158
- const scheduledTriggerIds = data.scheduledTriggers ? extractIds(data.scheduledTriggers) : [];
159
- if (scheduledTriggerIds.length) agentConfig.scheduledTriggers = createReferenceGetterValue(scheduledTriggerIds.map((id) => referenceNames.scheduledTriggers.get(id) ?? toTriggerReferenceName(id)));
160
155
  if (data.statusUpdates) {
161
156
  const statusComponentRefs = data.normalizedStatusComponentSequence.map((statusComponentId) => codePropertyAccess(referenceNames.statusComponents.get(statusComponentId) ?? toCamelCase(statusComponentId), "config"));
162
157
  agentConfig.statusUpdates = {
@@ -1 +1 @@
1
- {"version":3,"file":"agent-generator.js","names":["id"],"sources":["../../../../src/commands/pull-v4/generators/agent-generator.ts"],"sourcesContent":["import { join } from 'node:path';\nimport { AgentWithinContextOfProjectSchemaBase } from '@inkeep/agents-core';\nimport type { ObjectLiteralExpression, SourceFile } from 'ts-morph';\nimport { z } from 'zod';\nimport { asRecord, collectTemplateVariablesFromValues } from '../collector-common';\nimport {\n collectContextTemplateReferences,\n collectSubAgentReferenceOverrides,\n collectSubAgentReferencePathOverrides,\n} from '../collector-reference-helpers';\nimport type { GenerationTask } from '../generation-types';\nimport {\n addResolvedReferenceImports,\n resolveReferenceBinding,\n resolveReferenceBindingsFromIds,\n toReferenceNameMap,\n} from '../reference-resolution';\nimport { generateFactorySourceFile } from '../simple-factory-generator';\nimport {\n addValueToObject,\n buildComponentFileName,\n codePropertyAccess,\n codeReference,\n createReferenceGetterValue,\n formatTemplate,\n isPlainObject,\n toCamelCase,\n toTriggerReferenceName,\n} from '../utils';\nimport {\n addScheduledTriggerImports,\n addStatusComponentImports,\n addTriggerImports,\n createReferenceNameMap,\n createScheduledTriggerReferenceMaps,\n createTriggerReferenceMaps,\n extractIds,\n type ReferenceNameMap,\n} from './helpers/agent';\n\nconst SubAgentReferenceSchema = z.object({\n name: z.string().nonempty(),\n local: z.boolean().optional(),\n});\n\nconst MySchema = AgentWithinContextOfProjectSchemaBase.omit({\n id: true,\n});\n\nconst SubAgentSchema = MySchema.shape.subAgents.valueType.omit({\n // Invalid input: expected \"internal\"\n type: true,\n});\n\nconst ToolSchema = MySchema.shape.tools.unwrap().valueType;\n\nconst BaseAgentSchema = z.strictObject({\n agentId: z.string().nonempty(),\n ...MySchema.shape,\n description: z.preprocess((v) => v || undefined, MySchema.shape.description),\n models: z.preprocess((v) => v ?? undefined, MySchema.shape.models),\n stopWhen: z.preprocess(\n (v) => (v && Object.keys(v).length && v) || undefined,\n MySchema.shape.stopWhen\n ),\n subAgents: z.record(\n z.string(),\n z.strictObject({\n ...SubAgentSchema.shape,\n models: z.preprocess((v) => v ?? undefined, SubAgentSchema.shape.models),\n stopWhen: z.preprocess((v) => v ?? undefined, SubAgentSchema.shape.stopWhen),\n // Unrecognized keys: \"name\", \"description\", \"content\", \"metadata\", \"subAgentSkillId\", \"subAgentId\", \"createdAt\", \"updatedAt\"\n skills: z.unknown(),\n // Invalid input\n canDelegateTo: z.unknown(),\n })\n ),\n tools: z\n .record(\n z.string(),\n z.strictObject({\n ...ToolSchema.shape,\n // Invalid input: expected string, received null\n imageUrl: z.preprocess((v) => v ?? undefined, ToolSchema.shape.imageUrl),\n })\n )\n .optional(),\n // ✖ Invalid input: expected string, received undefined\n // → at triggers.t546ck7yueh52jils88rm.authentication.headers[0].value\n triggers: z.record(z.string(), z.unknown()).optional(),\n agentVariableName: z.string().nonempty().optional(),\n subAgentReferences: z.record(z.string(), SubAgentReferenceSchema).optional(),\n subAgentReferencePathOverrides: z.record(z.string(), z.string().nonempty()).optional(),\n contextConfigReference: SubAgentReferenceSchema.optional(),\n contextConfigHeadersReference: SubAgentReferenceSchema.optional(),\n});\n\nconst AgentSchema = BaseAgentSchema.transform((data) => ({\n ...data,\n normalizedContextConfigId: normalizeContextConfigId(data.contextConfig),\n normalizedStatusComponentIds: normalizeStatusComponentIds(data.statusUpdates?.statusComponents),\n normalizedStatusComponentSequence: normalizeStatusComponentSequence(\n data.statusUpdates?.statusComponents\n ),\n}));\n\ntype AgentInput = z.input<typeof AgentSchema>;\ntype AgentOutput = z.output<typeof AgentSchema>;\n\nfunction normalizeContextConfigId(contextConfig: unknown): string | undefined {\n if (typeof contextConfig === 'string') {\n return contextConfig;\n }\n\n if (isPlainObject(contextConfig) && typeof contextConfig.id === 'string') {\n return contextConfig.id;\n }\n\n return undefined;\n}\n\nfunction normalizeStatusComponentId(statusComponent: unknown): string | undefined {\n if (typeof statusComponent === 'string') {\n return statusComponent;\n }\n\n if (!isPlainObject(statusComponent)) {\n return undefined;\n }\n\n if (typeof statusComponent.id === 'string') {\n return statusComponent.id;\n }\n\n if (typeof statusComponent.type === 'string') {\n return statusComponent.type;\n }\n\n return undefined;\n}\n\nfunction normalizeStatusComponentSequence(statusComponents: unknown[] | undefined): string[] {\n if (!Array.isArray(statusComponents)) {\n return [];\n }\n\n return statusComponents\n .map((statusComponent) => normalizeStatusComponentId(statusComponent))\n .filter((statusComponentId): statusComponentId is string => Boolean(statusComponentId));\n}\n\nfunction normalizeStatusComponentIds(statusComponents: unknown[] | undefined): string[] {\n return [...new Set(normalizeStatusComponentSequence(statusComponents))];\n}\n\ninterface AgentReferenceNames {\n subAgents: ReferenceNameMap;\n contextConfig?: string;\n contextHeaders?: string;\n triggers: ReferenceNameMap;\n scheduledTriggers: ReferenceNameMap;\n statusComponents: ReferenceNameMap;\n}\n\nexport function generateAgentDefinition({\n id,\n createdAt,\n updatedAt,\n ...data\n}: AgentInput & Record<string, unknown>): SourceFile {\n return generateFactorySourceFile(data, {\n schema: AgentSchema,\n factory: {\n importName: 'agent',\n variableName: (parsed) => parsed.agentVariableName || toCamelCase(parsed.agentId),\n },\n render({ parsed, sourceFile, configObject }) {\n const subAgentIds = new Set(extractIds(parsed.subAgents));\n if (parsed.defaultSubAgentId) {\n subAgentIds.add(parsed.defaultSubAgentId);\n }\n const agentVarName = parsed.agentVariableName || toCamelCase(parsed.agentId);\n const reservedReferenceNames = new Set([agentVarName]);\n const subAgentReferences = resolveReferenceBindingsFromIds({\n ids: subAgentIds,\n reservedNames: reservedReferenceNames,\n conflictSuffix: 'SubAgent',\n referenceOverrides: parsed.subAgentReferences,\n referencePathOverrides: parsed.subAgentReferencePathOverrides,\n defaultModulePath: (id) => id,\n });\n const subAgentReferenceNames = toReferenceNameMap(subAgentReferences);\n addResolvedReferenceImports(sourceFile, subAgentReferences, (reference) => {\n return `./sub-agents/${reference.modulePath}`;\n });\n\n const contextConfigId = parsed.normalizedContextConfigId;\n let contextConfigReferenceName: string | undefined;\n let contextHeadersReferenceName: string | undefined;\n const promptTemplateVariables = collectTemplateVariablesFromValues([\n parsed.prompt,\n parsed.statusUpdates?.prompt,\n ]);\n const hasHeadersTemplateVariables = promptTemplateVariables.some((variableName) =>\n variableName.startsWith('headers.')\n );\n if (contextConfigId) {\n const contextConfigReference = resolveReferenceBinding(\n {\n id: `${contextConfigId}:context`,\n importName: parsed.contextConfigReference?.name ?? toCamelCase(contextConfigId),\n modulePath: contextConfigId,\n local: parsed.contextConfigReference?.local === true,\n conflictSuffix: 'ContextConfig',\n },\n {\n reservedNames: reservedReferenceNames,\n }\n );\n contextConfigReferenceName = contextConfigReference.localName;\n\n const contextReferences = [contextConfigReference];\n if (hasHeadersTemplateVariables) {\n const headersReference = resolveReferenceBinding(\n {\n id: `${contextConfigId}:headers`,\n importName:\n parsed.contextConfigHeadersReference?.name ??\n `${toCamelCase(contextConfigId)}Headers`,\n modulePath: contextConfigId,\n local: parsed.contextConfigHeadersReference?.local === true,\n conflictSuffix: 'Headers',\n },\n {\n reservedNames: reservedReferenceNames,\n }\n );\n contextHeadersReferenceName = headersReference.localName;\n contextReferences.push(headersReference);\n }\n\n addResolvedReferenceImports(sourceFile, contextReferences, () => {\n return `../context-configs/${contextConfigId}`;\n });\n }\n\n const { referenceNames: triggerReferenceNames, importRefs: triggerImportRefs } =\n createTriggerReferenceMaps(parsed.triggers, reservedReferenceNames);\n addTriggerImports(sourceFile, triggerReferenceNames, triggerImportRefs);\n\n const {\n referenceNames: scheduledTriggerReferenceNames,\n importRefs: scheduledTriggerImportRefs,\n } = createScheduledTriggerReferenceMaps(parsed.scheduledTriggers, reservedReferenceNames);\n addScheduledTriggerImports(\n sourceFile,\n scheduledTriggerReferenceNames,\n scheduledTriggerImportRefs\n );\n\n const statusComponentReferenceNames = createReferenceNameMap(\n parsed.normalizedStatusComponentIds,\n reservedReferenceNames,\n 'StatusComponent'\n );\n addStatusComponentImports(sourceFile, statusComponentReferenceNames);\n\n writeAgentConfig(configObject, parsed, {\n subAgents: subAgentReferenceNames,\n contextConfig: contextConfigReferenceName,\n contextHeaders: contextHeadersReferenceName,\n triggers: triggerReferenceNames,\n scheduledTriggers: scheduledTriggerReferenceNames,\n statusComponents: statusComponentReferenceNames,\n });\n },\n });\n}\n\nfunction writeAgentConfig(\n configObject: ObjectLiteralExpression,\n data: AgentOutput,\n referenceNames: AgentReferenceNames\n) {\n const agentConfig: Record<string, unknown> = {\n id: data.agentId,\n name: data.name,\n description: data.description,\n prompt:\n data.prompt &&\n formatTemplate(data.prompt, {\n contextReference: referenceNames.contextConfig,\n headersReference: referenceNames.contextHeaders,\n }),\n models: data.models,\n stopWhen: data.stopWhen,\n };\n\n const { defaultSubAgentId } = data;\n if (defaultSubAgentId) {\n agentConfig.defaultSubAgent = codeReference(\n referenceNames.subAgents.get(defaultSubAgentId) ?? toCamelCase(defaultSubAgentId)\n );\n }\n\n const subAgentIds = extractIds(data.subAgents);\n agentConfig.subAgents = createReferenceGetterValue(\n subAgentIds.map((id) => referenceNames.subAgents.get(id) ?? toCamelCase(id))\n );\n\n const contextConfigId = data.normalizedContextConfigId;\n if (contextConfigId && referenceNames.contextConfig) {\n agentConfig.contextConfig = codeReference(referenceNames.contextConfig);\n }\n\n const triggerIds = data.triggers ? extractIds(data.triggers) : [];\n if (triggerIds.length) {\n agentConfig.triggers = createReferenceGetterValue(\n triggerIds.map((id) => referenceNames.triggers.get(id) ?? toTriggerReferenceName(id))\n );\n }\n\n const scheduledTriggerIds = data.scheduledTriggers ? extractIds(data.scheduledTriggers) : [];\n if (scheduledTriggerIds.length) {\n agentConfig.scheduledTriggers = createReferenceGetterValue(\n scheduledTriggerIds.map(\n (id) => referenceNames.scheduledTriggers.get(id) ?? toTriggerReferenceName(id)\n )\n );\n }\n\n if (data.statusUpdates) {\n const statusComponentRefs = data.normalizedStatusComponentSequence.map((statusComponentId) =>\n codePropertyAccess(\n referenceNames.statusComponents.get(statusComponentId) ?? toCamelCase(statusComponentId),\n 'config'\n )\n );\n agentConfig.statusUpdates = {\n numEvents: data.statusUpdates.numEvents,\n timeInSeconds: data.statusUpdates.timeInSeconds,\n prompt:\n data.statusUpdates.prompt &&\n formatTemplate(data.statusUpdates.prompt, {\n contextReference: referenceNames.contextConfig,\n headersReference: referenceNames.contextHeaders,\n }),\n ...(statusComponentRefs?.length && { statusComponents: statusComponentRefs }),\n };\n }\n\n for (const [key, value] of Object.entries(agentConfig)) {\n addValueToObject(configObject, key, value);\n }\n}\n\nexport const task = {\n type: 'agent',\n collect(context) {\n if (!context.project.agents) {\n return [];\n }\n\n const records = [];\n for (const agentId of context.completeAgentIds) {\n const agentData = context.project.agents[agentId];\n if (!agentData) {\n continue;\n }\n\n const agentName = typeof agentData.name === 'string' ? agentData.name : undefined;\n const agentFilePath = context.resolver.resolveOutputFilePath(\n 'agents',\n agentId,\n join(context.paths.agentsDir, buildComponentFileName(agentId, agentName))\n );\n const existingAgent = context.resolver.getExistingComponent(agentId, 'agents');\n const subAgentReferences = collectSubAgentReferenceOverrides(\n context,\n agentData,\n agentFilePath\n );\n const subAgentReferencePathOverrides = collectSubAgentReferencePathOverrides(\n context,\n agentData\n );\n const statusUpdates = asRecord(agentData.statusUpdates);\n const contextTemplateReferences = collectContextTemplateReferences(\n context,\n agentData,\n agentFilePath,\n [\n typeof agentData.prompt === 'string' ? agentData.prompt : undefined,\n typeof statusUpdates?.prompt === 'string' ? statusUpdates.prompt : undefined,\n ]\n );\n\n records.push({\n id: agentId,\n filePath: agentFilePath,\n payload: {\n agentId,\n ...agentData,\n ...(existingAgent?.name?.length && { agentVariableName: existingAgent.name }),\n ...(Object.keys(subAgentReferences).length && { subAgentReferences }),\n ...(Object.keys(subAgentReferencePathOverrides).length && {\n subAgentReferencePathOverrides,\n }),\n ...(contextTemplateReferences && {\n contextConfigReference: contextTemplateReferences.contextConfigReference,\n }),\n ...(contextTemplateReferences?.contextConfigHeadersReference && {\n contextConfigHeadersReference: contextTemplateReferences.contextConfigHeadersReference,\n }),\n } as Parameters<typeof generateAgentDefinition>[0],\n });\n }\n\n return records;\n },\n generate: generateAgentDefinition,\n} satisfies GenerationTask<Parameters<typeof generateAgentDefinition>[0]>;\n"],"mappings":";;;;;;;;;;;;;;;;AAwCA,MAAM,0BAA0B,EAAE,OAAO;CACvC,MAAM,EAAE,QAAQ,CAAC,UAAU;CAC3B,OAAO,EAAE,SAAS,CAAC,UAAU;CAC9B,CAAC;AAEF,MAAM,WAAW,sCAAsC,KAAK,EAC1D,IAAI,MACL,CAAC;AAEF,MAAM,iBAAiB,SAAS,MAAM,UAAU,UAAU,KAAK,EAE7D,MAAM,MACP,CAAC;AAEF,MAAM,aAAa,SAAS,MAAM,MAAM,QAAQ,CAAC;AA2CjD,MAAM,cAzCkB,EAAE,aAAa;CACrC,SAAS,EAAE,QAAQ,CAAC,UAAU;CAC9B,GAAG,SAAS;CACZ,aAAa,EAAE,YAAY,MAAM,KAAK,QAAW,SAAS,MAAM,YAAY;CAC5E,QAAQ,EAAE,YAAY,MAAM,KAAK,QAAW,SAAS,MAAM,OAAO;CAClE,UAAU,EAAE,YACT,MAAO,KAAK,OAAO,KAAK,EAAE,CAAC,UAAU,KAAM,QAC5C,SAAS,MAAM,SAChB;CACD,WAAW,EAAE,OACX,EAAE,QAAQ,EACV,EAAE,aAAa;EACb,GAAG,eAAe;EAClB,QAAQ,EAAE,YAAY,MAAM,KAAK,QAAW,eAAe,MAAM,OAAO;EACxE,UAAU,EAAE,YAAY,MAAM,KAAK,QAAW,eAAe,MAAM,SAAS;EAE5E,QAAQ,EAAE,SAAS;EAEnB,eAAe,EAAE,SAAS;EAC3B,CAA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AQ,MAAM,WAAW,uBAAuB,SAAS,UAAU,CAAC,CAC1E;GACD,MAAM,gBAAgB,QAAQ,SAAS,qBAAqB,SAAS,SAAS;GAC9E,MAAM,qBAAqB,kCACzB,SACA,WACA,cACD;GACD,MAAM,iCAAiC,sCACrC,SACA,UACD;GACD,MAAM,gBAAgB,SAAS,UAAU,cAAc;GACvD,MAAM,4BAA4B,iCAChC,SACA,WACA,eACA,CACE,OAAO,UAAU,WAAW,WAAW,UAAU,SAAS,QAC1D,OAAO,eAAe,WAAW,WAAW,cAAc,SAAS,OACpE,CACF;AAED,WAAQ,KAAK;IACX,IAAI;IACJ,UAAU;IACV,SAAS;KACP;KACA,GAAG;KACH,GAAI,eAAe,MAAM,UAAU,EAAE,mBAAmB,cAAc,MAAM;KAC5E,GAAI,OAAO,KAAK,mBAAmB,CAAC,UAAU,EAAE,oBAAoB;KACpE,GAAI,OAAO,KAAK,+BAA+B,CAAC,UAAU,EACxD,gCACD;KACD,GAAI,6BAA6B,EAC/B,wBAAwB,0BAA0B,wBACnD;KACD,GAAI,2BAA2B,iCAAiC,EAC9D,+BAA+B,0BAA0B,+BAC1D;KACF;IACF,CAAC;;AAGJ,SAAO;;CAET,UAAU;CACX"}
1
+ {"version":3,"file":"agent-generator.js","names":["id"],"sources":["../../../../src/commands/pull-v4/generators/agent-generator.ts"],"sourcesContent":["import { join } from 'node:path';\nimport { AgentWithinContextOfProjectSchemaBase } from '@inkeep/agents-core';\nimport type { ObjectLiteralExpression, SourceFile } from 'ts-morph';\nimport { z } from 'zod';\nimport { asRecord, collectTemplateVariablesFromValues } from '../collector-common';\nimport {\n collectContextTemplateReferences,\n collectSubAgentReferenceOverrides,\n collectSubAgentReferencePathOverrides,\n} from '../collector-reference-helpers';\nimport type { GenerationTask } from '../generation-types';\nimport {\n addResolvedReferenceImports,\n resolveReferenceBinding,\n resolveReferenceBindingsFromIds,\n toReferenceNameMap,\n} from '../reference-resolution';\nimport { generateFactorySourceFile } from '../simple-factory-generator';\nimport {\n addValueToObject,\n buildComponentFileName,\n codePropertyAccess,\n codeReference,\n createReferenceGetterValue,\n formatTemplate,\n isPlainObject,\n toCamelCase,\n toTriggerReferenceName,\n} from '../utils';\nimport {\n addStatusComponentImports,\n addTriggerImports,\n createReferenceNameMap,\n createTriggerReferenceMaps,\n extractIds,\n type ReferenceNameMap,\n} from './helpers/agent';\n\nconst SubAgentReferenceSchema = z.object({\n name: z.string().nonempty(),\n local: z.boolean().optional(),\n});\n\nconst MySchema = AgentWithinContextOfProjectSchemaBase.omit({\n id: true,\n});\n\nconst SubAgentSchema = MySchema.shape.subAgents.valueType.omit({\n // Invalid input: expected \"internal\"\n type: true,\n});\n\nconst ToolSchema = MySchema.shape.tools.unwrap().valueType;\n\nconst BaseAgentSchema = z.strictObject({\n agentId: z.string().nonempty(),\n ...MySchema.shape,\n description: z.preprocess((v) => v || undefined, MySchema.shape.description),\n models: z.preprocess((v) => v ?? undefined, MySchema.shape.models),\n stopWhen: z.preprocess(\n (v) => (v && Object.keys(v).length && v) || undefined,\n MySchema.shape.stopWhen\n ),\n subAgents: z.record(\n z.string(),\n z.strictObject({\n ...SubAgentSchema.shape,\n models: z.preprocess((v) => v ?? undefined, SubAgentSchema.shape.models),\n stopWhen: z.preprocess((v) => v ?? undefined, SubAgentSchema.shape.stopWhen),\n // Unrecognized keys: \"name\", \"description\", \"content\", \"metadata\", \"subAgentSkillId\", \"subAgentId\", \"createdAt\", \"updatedAt\"\n skills: z.unknown(),\n // Invalid input\n canDelegateTo: z.unknown(),\n })\n ),\n tools: z\n .record(\n z.string(),\n z.strictObject({\n ...ToolSchema.shape,\n // Invalid input: expected string, received null\n imageUrl: z.preprocess((v) => v ?? undefined, ToolSchema.shape.imageUrl),\n })\n )\n .optional(),\n // ✖ Invalid input: expected string, received undefined\n // → at triggers.t546ck7yueh52jils88rm.authentication.headers[0].value\n triggers: z.record(z.string(), z.unknown()).optional(),\n agentVariableName: z.string().nonempty().optional(),\n subAgentReferences: z.record(z.string(), SubAgentReferenceSchema).optional(),\n subAgentReferencePathOverrides: z.record(z.string(), z.string().nonempty()).optional(),\n contextConfigReference: SubAgentReferenceSchema.optional(),\n contextConfigHeadersReference: SubAgentReferenceSchema.optional(),\n});\n\nconst AgentSchema = BaseAgentSchema.transform((data) => ({\n ...data,\n normalizedContextConfigId: normalizeContextConfigId(data.contextConfig),\n normalizedStatusComponentIds: normalizeStatusComponentIds(data.statusUpdates?.statusComponents),\n normalizedStatusComponentSequence: normalizeStatusComponentSequence(\n data.statusUpdates?.statusComponents\n ),\n}));\n\ntype AgentInput = z.input<typeof AgentSchema>;\ntype AgentOutput = z.output<typeof AgentSchema>;\n\nfunction normalizeContextConfigId(contextConfig: unknown): string | undefined {\n if (typeof contextConfig === 'string') {\n return contextConfig;\n }\n\n if (isPlainObject(contextConfig) && typeof contextConfig.id === 'string') {\n return contextConfig.id;\n }\n\n return undefined;\n}\n\nfunction normalizeStatusComponentId(statusComponent: unknown): string | undefined {\n if (typeof statusComponent === 'string') {\n return statusComponent;\n }\n\n if (!isPlainObject(statusComponent)) {\n return undefined;\n }\n\n if (typeof statusComponent.id === 'string') {\n return statusComponent.id;\n }\n\n if (typeof statusComponent.type === 'string') {\n return statusComponent.type;\n }\n\n return undefined;\n}\n\nfunction normalizeStatusComponentSequence(statusComponents: unknown[] | undefined): string[] {\n if (!Array.isArray(statusComponents)) {\n return [];\n }\n\n return statusComponents\n .map((statusComponent) => normalizeStatusComponentId(statusComponent))\n .filter((statusComponentId): statusComponentId is string => Boolean(statusComponentId));\n}\n\nfunction normalizeStatusComponentIds(statusComponents: unknown[] | undefined): string[] {\n return [...new Set(normalizeStatusComponentSequence(statusComponents))];\n}\n\ninterface AgentReferenceNames {\n subAgents: ReferenceNameMap;\n contextConfig?: string;\n contextHeaders?: string;\n triggers: ReferenceNameMap;\n statusComponents: ReferenceNameMap;\n}\n\nexport function generateAgentDefinition({\n id,\n createdAt,\n updatedAt,\n ...data\n}: AgentInput & Record<string, unknown>): SourceFile {\n return generateFactorySourceFile(data, {\n schema: AgentSchema,\n factory: {\n importName: 'agent',\n variableName: (parsed) => parsed.agentVariableName || toCamelCase(parsed.agentId),\n },\n render({ parsed, sourceFile, configObject }) {\n const subAgentIds = new Set(extractIds(parsed.subAgents));\n if (parsed.defaultSubAgentId) {\n subAgentIds.add(parsed.defaultSubAgentId);\n }\n const agentVarName = parsed.agentVariableName || toCamelCase(parsed.agentId);\n const reservedReferenceNames = new Set([agentVarName]);\n const subAgentReferences = resolveReferenceBindingsFromIds({\n ids: subAgentIds,\n reservedNames: reservedReferenceNames,\n conflictSuffix: 'SubAgent',\n referenceOverrides: parsed.subAgentReferences,\n referencePathOverrides: parsed.subAgentReferencePathOverrides,\n defaultModulePath: (id) => id,\n });\n const subAgentReferenceNames = toReferenceNameMap(subAgentReferences);\n addResolvedReferenceImports(sourceFile, subAgentReferences, (reference) => {\n return `./sub-agents/${reference.modulePath}`;\n });\n\n const contextConfigId = parsed.normalizedContextConfigId;\n let contextConfigReferenceName: string | undefined;\n let contextHeadersReferenceName: string | undefined;\n const promptTemplateVariables = collectTemplateVariablesFromValues([\n parsed.prompt,\n parsed.statusUpdates?.prompt,\n ]);\n const hasHeadersTemplateVariables = promptTemplateVariables.some((variableName) =>\n variableName.startsWith('headers.')\n );\n if (contextConfigId) {\n const contextConfigReference = resolveReferenceBinding(\n {\n id: `${contextConfigId}:context`,\n importName: parsed.contextConfigReference?.name ?? toCamelCase(contextConfigId),\n modulePath: contextConfigId,\n local: parsed.contextConfigReference?.local === true,\n conflictSuffix: 'ContextConfig',\n },\n {\n reservedNames: reservedReferenceNames,\n }\n );\n contextConfigReferenceName = contextConfigReference.localName;\n\n const contextReferences = [contextConfigReference];\n if (hasHeadersTemplateVariables) {\n const headersReference = resolveReferenceBinding(\n {\n id: `${contextConfigId}:headers`,\n importName:\n parsed.contextConfigHeadersReference?.name ??\n `${toCamelCase(contextConfigId)}Headers`,\n modulePath: contextConfigId,\n local: parsed.contextConfigHeadersReference?.local === true,\n conflictSuffix: 'Headers',\n },\n {\n reservedNames: reservedReferenceNames,\n }\n );\n contextHeadersReferenceName = headersReference.localName;\n contextReferences.push(headersReference);\n }\n\n addResolvedReferenceImports(sourceFile, contextReferences, () => {\n return `../context-configs/${contextConfigId}`;\n });\n }\n\n const { referenceNames: triggerReferenceNames, importRefs: triggerImportRefs } =\n createTriggerReferenceMaps(parsed.triggers, reservedReferenceNames);\n addTriggerImports(sourceFile, triggerReferenceNames, triggerImportRefs);\n\n const statusComponentReferenceNames = createReferenceNameMap(\n parsed.normalizedStatusComponentIds,\n reservedReferenceNames,\n 'StatusComponent'\n );\n addStatusComponentImports(sourceFile, statusComponentReferenceNames);\n\n writeAgentConfig(configObject, parsed, {\n subAgents: subAgentReferenceNames,\n contextConfig: contextConfigReferenceName,\n contextHeaders: contextHeadersReferenceName,\n triggers: triggerReferenceNames,\n statusComponents: statusComponentReferenceNames,\n });\n },\n });\n}\n\nfunction writeAgentConfig(\n configObject: ObjectLiteralExpression,\n data: AgentOutput,\n referenceNames: AgentReferenceNames\n) {\n const agentConfig: Record<string, unknown> = {\n id: data.agentId,\n name: data.name,\n description: data.description,\n prompt:\n data.prompt &&\n formatTemplate(data.prompt, {\n contextReference: referenceNames.contextConfig,\n headersReference: referenceNames.contextHeaders,\n }),\n models: data.models,\n stopWhen: data.stopWhen,\n };\n\n const { defaultSubAgentId } = data;\n if (defaultSubAgentId) {\n agentConfig.defaultSubAgent = codeReference(\n referenceNames.subAgents.get(defaultSubAgentId) ?? toCamelCase(defaultSubAgentId)\n );\n }\n\n const subAgentIds = extractIds(data.subAgents);\n agentConfig.subAgents = createReferenceGetterValue(\n subAgentIds.map((id) => referenceNames.subAgents.get(id) ?? toCamelCase(id))\n );\n\n const contextConfigId = data.normalizedContextConfigId;\n if (contextConfigId && referenceNames.contextConfig) {\n agentConfig.contextConfig = codeReference(referenceNames.contextConfig);\n }\n\n const triggerIds = data.triggers ? extractIds(data.triggers) : [];\n if (triggerIds.length) {\n agentConfig.triggers = createReferenceGetterValue(\n triggerIds.map((id) => referenceNames.triggers.get(id) ?? toTriggerReferenceName(id))\n );\n }\n\n if (data.statusUpdates) {\n const statusComponentRefs = data.normalizedStatusComponentSequence.map((statusComponentId) =>\n codePropertyAccess(\n referenceNames.statusComponents.get(statusComponentId) ?? toCamelCase(statusComponentId),\n 'config'\n )\n );\n agentConfig.statusUpdates = {\n numEvents: data.statusUpdates.numEvents,\n timeInSeconds: data.statusUpdates.timeInSeconds,\n prompt:\n data.statusUpdates.prompt &&\n formatTemplate(data.statusUpdates.prompt, {\n contextReference: referenceNames.contextConfig,\n headersReference: referenceNames.contextHeaders,\n }),\n ...(statusComponentRefs?.length && { statusComponents: statusComponentRefs }),\n };\n }\n\n for (const [key, value] of Object.entries(agentConfig)) {\n addValueToObject(configObject, key, value);\n }\n}\n\nexport const task = {\n type: 'agent',\n collect(context) {\n if (!context.project.agents) {\n return [];\n }\n\n const records = [];\n for (const agentId of context.completeAgentIds) {\n const agentData = context.project.agents[agentId];\n if (!agentData) {\n continue;\n }\n\n const agentName = typeof agentData.name === 'string' ? agentData.name : undefined;\n const agentFilePath = context.resolver.resolveOutputFilePath(\n 'agents',\n agentId,\n join(context.paths.agentsDir, buildComponentFileName(agentId, agentName))\n );\n const existingAgent = context.resolver.getExistingComponent(agentId, 'agents');\n const subAgentReferences = collectSubAgentReferenceOverrides(\n context,\n agentData,\n agentFilePath\n );\n const subAgentReferencePathOverrides = collectSubAgentReferencePathOverrides(\n context,\n agentData\n );\n const statusUpdates = asRecord(agentData.statusUpdates);\n const contextTemplateReferences = collectContextTemplateReferences(\n context,\n agentData,\n agentFilePath,\n [\n typeof agentData.prompt === 'string' ? agentData.prompt : undefined,\n typeof statusUpdates?.prompt === 'string' ? statusUpdates.prompt : undefined,\n ]\n );\n\n records.push({\n id: agentId,\n filePath: agentFilePath,\n payload: {\n agentId,\n ...agentData,\n ...(existingAgent?.name?.length && { agentVariableName: existingAgent.name }),\n ...(Object.keys(subAgentReferences).length && { subAgentReferences }),\n ...(Object.keys(subAgentReferencePathOverrides).length && {\n subAgentReferencePathOverrides,\n }),\n ...(contextTemplateReferences && {\n contextConfigReference: contextTemplateReferences.contextConfigReference,\n }),\n ...(contextTemplateReferences?.contextConfigHeadersReference && {\n contextConfigHeadersReference: contextTemplateReferences.contextConfigHeadersReference,\n }),\n } as Parameters<typeof generateAgentDefinition>[0],\n });\n }\n\n return records;\n },\n generate: generateAgentDefinition,\n} satisfies GenerationTask<Parameters<typeof generateAgentDefinition>[0]>;\n"],"mappings":";;;;;;;;;;;;;;;;AAsCA,MAAM,0BAA0B,EAAE,OAAO;CACvC,MAAM,EAAE,QAAQ,CAAC,UAAU;CAC3B,OAAO,EAAE,SAAS,CAAC,UAAU;CAC9B,CAAC;AAEF,MAAM,WAAW,sCAAsC,KAAK,EAC1D,IAAI,MACL,CAAC;AAEF,MAAM,iBAAiB,SAAS,MAAM,UAAU,UAAU,KAAK,EAE7D,MAAM,MACP,CAAC;AAEF,MAAM,aAAa,SAAS,MAAM,MAAM,QAAQ,CAAC;AA2CjD,MAAM,cAzCkB,EAAE,aAAa;CACrC,SAAS,EAAE,QAAQ,CAAC,UAAU;CAC9B,GAAG,SAAS;CACZ,aAAa,EAAE,YAAY,MAAM,KAAK,QAAW,SAAS,MAAM,YAAY;CAC5E,QAAQ,EAAE,YAAY,MAAM,KAAK,QAAW,SAAS,MAAM,OAAO;CAClE,UAAU,EAAE,YACT,MAAO,KAAK,OAAO,KAAK,EAAE,CAAC,UAAU,KAAM,QAC5C,SAAS,MAAM,SAChB;CACD,WAAW,EAAE,OACX,EAAE,QAAQ,EACV,EAAE,aAAa;EACb,GAAG,eAAe;EAClB,QAAQ,EAAE,YAAY,MAAM,KAAK,QAAW,eAAe,MAAM,OAAO;EACxE,UAAU,EAAE,YAAY,MAAM,KAAK,QAAW,eAAe,MAAM,SAAS;EAE5E,QAAQ,EAAE,SAAS;EAEnB,eAAe,EAAE,SAAS;EAC3B,CAAC,CAC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,WAAW,WAAW,cAAc,SAAS,OACpE,CACF;AAED,WAAQ,KAAK;IACX,IAAI;IACJ,UAAU;IACV,SAAS;KACP;KACA,GAAG;KACH,GAAI,eAAe,MAAM,UAAU,EAAE,mBAAmB,cAAc,MAAM;KAC5E,GAAI,OAAO,KAAK,mBAAmB,CAAC,UAAU,EAAE,oBAAoB;KACpE,GAAI,OAAO,KAAK,+BAA+B,CAAC,UAAU,EACxD,gCACD;KACD,GAAI,6BAA6B,EAC/B,wBAAwB,0BAA0B,wBACnD;KACD,GAAI,2BAA2B,iCAAiC,EAC9D,+BAA+B,0BAA0B,+BAC1D;KACF;IACF,CAAC;;AAGJ,SAAO;;CAET,UAAU;CACX"}
@@ -22,16 +22,6 @@ function addTriggerImports(sourceFile, referenceNames, importRefs) {
22
22
  }
23
23
  applyImportPlan(sourceFile, importPlan);
24
24
  }
25
- function addScheduledTriggerImports(sourceFile, referenceNames, importRefs) {
26
- const importPlan = createImportPlan();
27
- for (const [scheduledTriggerId, referenceName] of referenceNames) {
28
- const importRef = importRefs.get(scheduledTriggerId);
29
- if (!importRef) continue;
30
- const { importName, modulePath } = importRef;
31
- addNamedImports(importPlan, `./scheduled-triggers/${modulePath}`, toNamedImport(importName, referenceName));
32
- }
33
- applyImportPlan(sourceFile, importPlan);
34
- }
35
25
  function addStatusComponentImports(sourceFile, referenceNames) {
36
26
  const importPlan = createImportPlan();
37
27
  for (const [statusComponentId, referenceName] of referenceNames) {
@@ -48,35 +38,6 @@ function createReferenceNameMap(ids, reservedNames, conflictSuffix) {
48
38
  }
49
39
  return map;
50
40
  }
51
- function createScheduledTriggerReferenceMaps(scheduledTriggers, reservedNames) {
52
- const referenceNames = /* @__PURE__ */ new Map();
53
- const importRefs = /* @__PURE__ */ new Map();
54
- if (!scheduledTriggers || !isPlainObject(scheduledTriggers)) return {
55
- referenceNames,
56
- importRefs
57
- };
58
- const moduleNameCounts = /* @__PURE__ */ new Map();
59
- for (const [scheduledTriggerId, scheduledTriggerData] of Object.entries(scheduledTriggers)) {
60
- if (referenceNames.has(scheduledTriggerId)) continue;
61
- const scheduledTriggerRecord = isPlainObject(scheduledTriggerData) ? scheduledTriggerData : void 0;
62
- const scheduledTriggerName = typeof scheduledTriggerRecord?.name === "string" && scheduledTriggerRecord.name.length > 0 ? scheduledTriggerRecord.name : scheduledTriggerId;
63
- const importName = toTriggerReferenceName(scheduledTriggerName);
64
- const referenceName = createNumericReferenceName(importName, reservedNames);
65
- const baseModuleName = toKebabCase(scheduledTriggerName) || toKebabCase(scheduledTriggerId) || scheduledTriggerId;
66
- const moduleCount = moduleNameCounts.get(baseModuleName) ?? 0;
67
- moduleNameCounts.set(baseModuleName, moduleCount + 1);
68
- const modulePath = moduleCount === 0 ? baseModuleName : `${baseModuleName}-${moduleCount}`;
69
- referenceNames.set(scheduledTriggerId, referenceName);
70
- importRefs.set(scheduledTriggerId, {
71
- importName,
72
- modulePath
73
- });
74
- }
75
- return {
76
- referenceNames,
77
- importRefs
78
- };
79
- }
80
41
  function createTriggerReferenceMaps(triggers, reservedNames) {
81
42
  const referenceNames = /* @__PURE__ */ new Map();
82
43
  const importRefs = /* @__PURE__ */ new Map();
@@ -125,5 +86,5 @@ function toNamedImport(importName, referenceName) {
125
86
  }
126
87
 
127
88
  //#endregion
128
- export { addScheduledTriggerImports, addStatusComponentImports, addTriggerImports, createReferenceNameMap, createScheduledTriggerReferenceMaps, createTriggerReferenceMaps, extractIds };
89
+ export { addStatusComponentImports, addTriggerImports, createReferenceNameMap, createTriggerReferenceMaps, extractIds };
129
90
  //# sourceMappingURL=agent.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"agent.js","names":[],"sources":["../../../../../src/commands/pull-v4/generators/helpers/agent.ts"],"sourcesContent":["import type { SourceFile } from 'ts-morph';\nimport {\n addNamedImports,\n applyImportPlan,\n createImportPlan,\n type NamedImportSpec,\n} from '../../import-plan';\nimport {\n createUniqueReferenceName,\n isPlainObject,\n toCamelCase,\n toKebabCase,\n toTriggerReferenceName,\n} from '../../utils';\n\nexport type ReferenceNameMap = Map<string, string>;\nexport type TriggerImportMap = Map<string, { importName: string; modulePath: string }>;\n\nexport function extractIds(value: unknown[] | Record<string, unknown>): string[] {\n if (Array.isArray(value)) {\n return value\n .map((item) => {\n if (typeof item === 'string') {\n return item;\n }\n if (isPlainObject(item) && typeof item.id === 'string') {\n return item.id;\n }\n return null;\n })\n .filter((id): id is string => Boolean(id));\n }\n return Object.keys(value);\n}\n\nexport function addTriggerImports(\n sourceFile: SourceFile,\n referenceNames: ReferenceNameMap,\n importRefs: TriggerImportMap\n): void {\n const importPlan = createImportPlan();\n for (const [triggerId, referenceName] of referenceNames) {\n const importRef = importRefs.get(triggerId);\n if (!importRef) {\n continue;\n }\n\n const { importName, modulePath } = importRef;\n addNamedImports(\n importPlan,\n `./triggers/${modulePath}`,\n toNamedImport(importName, referenceName)\n );\n }\n applyImportPlan(sourceFile, importPlan);\n}\n\nexport function addScheduledTriggerImports(\n sourceFile: SourceFile,\n referenceNames: ReferenceNameMap,\n importRefs: TriggerImportMap\n): void {\n const importPlan = createImportPlan();\n for (const [scheduledTriggerId, referenceName] of referenceNames) {\n const importRef = importRefs.get(scheduledTriggerId);\n if (!importRef) {\n continue;\n }\n\n const { importName, modulePath } = importRef;\n addNamedImports(\n importPlan,\n `./scheduled-triggers/${modulePath}`,\n toNamedImport(importName, referenceName)\n );\n }\n applyImportPlan(sourceFile, importPlan);\n}\n\nexport function addStatusComponentImports(\n sourceFile: SourceFile,\n referenceNames: ReferenceNameMap\n): void {\n const importPlan = createImportPlan();\n for (const [statusComponentId, referenceName] of referenceNames) {\n const importName = toCamelCase(statusComponentId);\n addNamedImports(\n importPlan,\n `../status-components/${statusComponentId}`,\n toNamedImport(importName, referenceName)\n );\n }\n applyImportPlan(sourceFile, importPlan);\n}\n\nexport function createReferenceNameMap(\n ids: Iterable<string>,\n reservedNames: Set<string>,\n conflictSuffix: string\n): ReferenceNameMap {\n const map: ReferenceNameMap = new Map();\n for (const id of ids) {\n if (map.has(id)) {\n continue;\n }\n map.set(id, createUniqueReferenceName(toCamelCase(id), reservedNames, conflictSuffix));\n }\n return map;\n}\n\nexport function createScheduledTriggerReferenceMaps(\n scheduledTriggers: unknown,\n reservedNames: Set<string>\n): {\n referenceNames: ReferenceNameMap;\n importRefs: TriggerImportMap;\n} {\n const referenceNames: ReferenceNameMap = new Map();\n const importRefs: TriggerImportMap = new Map();\n\n if (!scheduledTriggers || !isPlainObject(scheduledTriggers)) {\n return { referenceNames, importRefs };\n }\n\n const moduleNameCounts = new Map<string, number>();\n\n for (const [scheduledTriggerId, scheduledTriggerData] of Object.entries(scheduledTriggers)) {\n if (referenceNames.has(scheduledTriggerId)) {\n continue;\n }\n\n const scheduledTriggerRecord = isPlainObject(scheduledTriggerData)\n ? scheduledTriggerData\n : undefined;\n const scheduledTriggerName =\n typeof scheduledTriggerRecord?.name === 'string' && scheduledTriggerRecord.name.length > 0\n ? scheduledTriggerRecord.name\n : scheduledTriggerId;\n\n const importName = toTriggerReferenceName(scheduledTriggerName);\n const referenceName = createNumericReferenceName(importName, reservedNames);\n\n const baseModuleName =\n toKebabCase(scheduledTriggerName) || toKebabCase(scheduledTriggerId) || scheduledTriggerId;\n const moduleCount = moduleNameCounts.get(baseModuleName) ?? 0;\n moduleNameCounts.set(baseModuleName, moduleCount + 1);\n const modulePath = moduleCount === 0 ? baseModuleName : `${baseModuleName}-${moduleCount}`;\n\n referenceNames.set(scheduledTriggerId, referenceName);\n importRefs.set(scheduledTriggerId, { importName, modulePath });\n }\n\n return { referenceNames, importRefs };\n}\n\nexport function createTriggerReferenceMaps(\n triggers: unknown,\n reservedNames: Set<string>\n): {\n referenceNames: ReferenceNameMap;\n importRefs: TriggerImportMap;\n} {\n const referenceNames: ReferenceNameMap = new Map();\n const importRefs: TriggerImportMap = new Map();\n\n if (!triggers || !isPlainObject(triggers)) {\n return { referenceNames, importRefs };\n }\n\n const moduleNameCounts = new Map<string, number>();\n\n for (const [triggerId, triggerData] of Object.entries(triggers)) {\n if (referenceNames.has(triggerId)) {\n continue;\n }\n\n const triggerRecord = isPlainObject(triggerData) ? triggerData : undefined;\n const triggerName =\n typeof triggerRecord?.name === 'string' && triggerRecord.name.length > 0\n ? triggerRecord.name\n : triggerId;\n\n const importName = toTriggerReferenceName(triggerName);\n const referenceName = createNumericReferenceName(importName, reservedNames);\n\n const baseModuleName = toKebabCase(triggerName) || toKebabCase(triggerId) || triggerId;\n const moduleCount = moduleNameCounts.get(baseModuleName) ?? 0;\n moduleNameCounts.set(baseModuleName, moduleCount + 1);\n const modulePath = moduleCount === 0 ? baseModuleName : `${baseModuleName}-${moduleCount}`;\n\n referenceNames.set(triggerId, referenceName);\n importRefs.set(triggerId, { importName, modulePath });\n }\n\n return { referenceNames, importRefs };\n}\n\nfunction createNumericReferenceName(baseName: string, reservedNames: Set<string>): string {\n if (!reservedNames.has(baseName)) {\n reservedNames.add(baseName);\n return baseName;\n }\n\n let index = 1;\n while (reservedNames.has(`${baseName}${index}`)) {\n index += 1;\n }\n\n const uniqueName = `${baseName}${index}`;\n reservedNames.add(uniqueName);\n return uniqueName;\n}\n\nfunction toNamedImport(importName: string, referenceName: string): NamedImportSpec {\n return importName === referenceName ? importName : { name: importName, alias: referenceName };\n}\n"],"mappings":";;;;;;AAkBA,SAAgB,WAAW,OAAsD;AAC/E,KAAI,MAAM,QAAQ,MAAM,CACtB,QAAO,MACJ,KAAK,SAAS;AACb,MAAI,OAAO,SAAS,SAClB,QAAO;AAET,MAAI,cAAc,KAAK,IAAI,OAAO,KAAK,OAAO,SAC5C,QAAO,KAAK;AAEd,SAAO;GACP,CACD,QAAQ,OAAqB,QAAQ,GAAG,CAAC;AAE9C,QAAO,OAAO,KAAK,MAAM;;AAG3B,SAAgB,kBACd,YACA,gBACA,YACM;CACN,MAAM,aAAa,kBAAkB;AACrC,MAAK,MAAM,CAAC,WAAW,kBAAkB,gBAAgB;EACvD,MAAM,YAAY,WAAW,IAAI,UAAU;AAC3C,MAAI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AI,WAAW;GAAE;GAAY;GAAY,CAAC;;AAGvD,QAAO;EAAE;EAAgB;EAAY;;AAGvC,SAAS,2BAA2B,UAAkB,eAAoC;AACxF,KAAI,CAAC,cAAc,IAAI,SAAS,EAAE;AAChC,gBAAc,IAAI,SAAS;AAC3B,SAAO;;CAGT,IAAI,QAAQ;AACZ,QAAO,cAAc,IAAI,GAAG,WAAW,QAAQ,CAC7C,UAAS;CAGX,MAAM,aAAa,GAAG,WAAW;AACjC,eAAc,IAAI,WAAW;AAC7B,QAAO;;AAGT,SAAS,cAAc,YAAoB,eAAwC;AACjF,QAAO,eAAe,gBAAgB,aAAa;EAAE,MAAM;EAAY,OAAO;EAAe"}
1
+ {"version":3,"file":"agent.js","names":[],"sources":["../../../../../src/commands/pull-v4/generators/helpers/agent.ts"],"sourcesContent":["import type { SourceFile } from 'ts-morph';\nimport {\n addNamedImports,\n applyImportPlan,\n createImportPlan,\n type NamedImportSpec,\n} from '../../import-plan';\nimport {\n createUniqueReferenceName,\n isPlainObject,\n toCamelCase,\n toKebabCase,\n toTriggerReferenceName,\n} from '../../utils';\n\nexport type ReferenceNameMap = Map<string, string>;\nexport type TriggerImportMap = Map<string, { importName: string; modulePath: string }>;\n\nexport function extractIds(value: unknown[] | Record<string, unknown>): string[] {\n if (Array.isArray(value)) {\n return value\n .map((item) => {\n if (typeof item === 'string') {\n return item;\n }\n if (isPlainObject(item) && typeof item.id === 'string') {\n return item.id;\n }\n return null;\n })\n .filter((id): id is string => Boolean(id));\n }\n return Object.keys(value);\n}\n\nexport function addTriggerImports(\n sourceFile: SourceFile,\n referenceNames: ReferenceNameMap,\n importRefs: TriggerImportMap\n): void {\n const importPlan = createImportPlan();\n for (const [triggerId, referenceName] of referenceNames) {\n const importRef = importRefs.get(triggerId);\n if (!importRef) {\n continue;\n }\n\n const { importName, modulePath } = importRef;\n addNamedImports(\n importPlan,\n `./triggers/${modulePath}`,\n toNamedImport(importName, referenceName)\n );\n }\n applyImportPlan(sourceFile, importPlan);\n}\n\nexport function addStatusComponentImports(\n sourceFile: SourceFile,\n referenceNames: ReferenceNameMap\n): void {\n const importPlan = createImportPlan();\n for (const [statusComponentId, referenceName] of referenceNames) {\n const importName = toCamelCase(statusComponentId);\n addNamedImports(\n importPlan,\n `../status-components/${statusComponentId}`,\n toNamedImport(importName, referenceName)\n );\n }\n applyImportPlan(sourceFile, importPlan);\n}\n\nexport function createReferenceNameMap(\n ids: Iterable<string>,\n reservedNames: Set<string>,\n conflictSuffix: string\n): ReferenceNameMap {\n const map: ReferenceNameMap = new Map();\n for (const id of ids) {\n if (map.has(id)) {\n continue;\n }\n map.set(id, createUniqueReferenceName(toCamelCase(id), reservedNames, conflictSuffix));\n }\n return map;\n}\n\nexport function createTriggerReferenceMaps(\n triggers: unknown,\n reservedNames: Set<string>\n): {\n referenceNames: ReferenceNameMap;\n importRefs: TriggerImportMap;\n} {\n const referenceNames: ReferenceNameMap = new Map();\n const importRefs: TriggerImportMap = new Map();\n\n if (!triggers || !isPlainObject(triggers)) {\n return { referenceNames, importRefs };\n }\n\n const moduleNameCounts = new Map<string, number>();\n\n for (const [triggerId, triggerData] of Object.entries(triggers)) {\n if (referenceNames.has(triggerId)) {\n continue;\n }\n\n const triggerRecord = isPlainObject(triggerData) ? triggerData : undefined;\n const triggerName =\n typeof triggerRecord?.name === 'string' && triggerRecord.name.length > 0\n ? triggerRecord.name\n : triggerId;\n\n const importName = toTriggerReferenceName(triggerName);\n const referenceName = createNumericReferenceName(importName, reservedNames);\n\n const baseModuleName = toKebabCase(triggerName) || toKebabCase(triggerId) || triggerId;\n const moduleCount = moduleNameCounts.get(baseModuleName) ?? 0;\n moduleNameCounts.set(baseModuleName, moduleCount + 1);\n const modulePath = moduleCount === 0 ? baseModuleName : `${baseModuleName}-${moduleCount}`;\n\n referenceNames.set(triggerId, referenceName);\n importRefs.set(triggerId, { importName, modulePath });\n }\n\n return { referenceNames, importRefs };\n}\n\nfunction createNumericReferenceName(baseName: string, reservedNames: Set<string>): string {\n if (!reservedNames.has(baseName)) {\n reservedNames.add(baseName);\n return baseName;\n }\n\n let index = 1;\n while (reservedNames.has(`${baseName}${index}`)) {\n index += 1;\n }\n\n const uniqueName = `${baseName}${index}`;\n reservedNames.add(uniqueName);\n return uniqueName;\n}\n\nfunction toNamedImport(importName: string, referenceName: string): NamedImportSpec {\n return importName === referenceName ? importName : { name: importName, alias: referenceName };\n}\n"],"mappings":";;;;;;AAkBA,SAAgB,WAAW,OAAsD;AAC/E,KAAI,MAAM,QAAQ,MAAM,CACtB,QAAO,MACJ,KAAK,SAAS;AACb,MAAI,OAAO,SAAS,SAClB,QAAO;AAET,MAAI,cAAc,KAAK,IAAI,OAAO,KAAK,OAAO,SAC5C,QAAO,KAAK;AAEd,SAAO;GACP,CACD,QAAQ,OAAqB,QAAQ,GAAG,CAAC;AAE9C,QAAO,OAAO,KAAK,MAAM;;AAG3B,SAAgB,kBACd,YACA,gBACA,YACM;CACN,MAAM,aAAa,kBAAkB;AACrC,MAAK,MAAM,CAAC,WAAW,kBAAkB,gBAAgB;EACvD,MAAM,YAAY,WAAW,IAAI,UAAU;AAC3C,MAAI,CAAC,UACH;EAGF,MAAM,EAAE,YAAY,eAAe;AACnC,kBACE,YACA,cAAc,cACd,cAAc,YAAY,cAAc,CACzC;;AAEH,iBAAgB,YAAY,WAAW;;AAGzC,SAAgB,0BACd,YACA,gBACM;CACN,MAAM,aAAa,kBAAkB;AACrC,MAAK,MAAM,CAAC,mBAAmB,kBAAkB,gBAAgB;EAC/D,MAAM,aAAa,YAAY,kBAAkB;AACjD,kBACE,YACA,wBAAwB,qBACxB,cAAc,YAAY,cAAc,CACzC;;AAEH,iBAAgB,YAAY,WAAW;;AAGzC,SAAgB,uBACd,KACA,eACA,gBACkB;CAClB,MAAM,sBAAwB,IAAI,KAAK;AACvC,MAAK,MAAM,MAAM,KAAK;AACpB,MAAI,IAAI,IAAI,GAAG,CACb;AAEF,MAAI,IAAI,IAAI,0BAA0B,YAAY,GAAG,E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9 @@ import { task as task$8 } from "./external-agent-generator.js";
9
9
  import { task as task$9 } from "./function-tool-generator.js";
10
10
  import { task as task$10 } from "./mcp-tool-generator.js";
11
11
  import { task as task$11 } from "./project-generator.js";
12
- import { task as task$12 } from "./scheduled-trigger-generator.js";
13
- import { task as task$13 } from "./status-component-generator.js";
14
- import { task as task$14 } from "./sub-agent-generator.js";
15
- import { task as task$15 } from "./trigger-generator.js";
12
+ import { task as task$12 } from "./status-component-generator.js";
13
+ import { task as task$13 } from "./sub-agent-generator.js";
14
+ import { task as task$14 } from "./trigger-generator.js";
16
15
 
17
16
  //#region src/commands/pull-v4/generators/index.ts
18
17
  const generationTasks = {
@@ -27,10 +26,9 @@ const generationTasks = {
27
26
  "./function-tool-generator.ts": task$9,
28
27
  "./mcp-tool-generator.ts": task$10,
29
28
  "./project-generator.ts": task$11,
30
- "./scheduled-trigger-generator.ts": task$12,
31
- "./status-component-generator.ts": task$13,
32
- "./sub-agent-generator.ts": task$14,
33
- "./trigger-generator.ts": task$15
29
+ "./status-component-generator.ts": task$12,
30
+ "./sub-agent-generator.ts": task$13,
31
+ "./trigger-generator.ts": task$14
34
32
  };
35
33
 
36
34
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../../../src/commands/pull-v4/generators/index.ts"],"sourcesContent":["import type { GenerationTask } from '../generation-types';\n\nexport const generationTasks: Record<\n `./${string}-generator.ts`,\n GenerationTask<unknown>\n> = import.meta\n // @ts-expect-error -- https://vite.dev/guide/features#named-imports\n .glob('./*-generator.ts', {\n import: 'task',\n eager: true,\n });\n"],"mappings":";;;;;;;;;;;;;;;;;AAEA,MAAa,kBAGT;;;;;;;;;;;;;;;;CAKA"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../../src/commands/pull-v4/generators/index.ts"],"sourcesContent":["import type { GenerationTask } from '../generation-types';\n\nexport const generationTasks: Record<\n `./${string}-generator.ts`,\n GenerationTask<unknown>\n> = import.meta\n // @ts-expect-error -- https://vite.dev/guide/features#named-imports\n .glob('./*-generator.ts', {\n import: 'task',\n eager: true,\n });\n"],"mappings":";;;;;;;;;;;;;;;;AAEA,MAAa,kBAGT;;;;;;;;;;;;;;;CAKA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inkeep/agents-cli",
3
- "version": "0.62.1",
3
+ "version": "0.63.0",
4
4
  "description": "Inkeep CLI tool",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -39,8 +39,8 @@
39
39
  "tsx": "^4.20.5",
40
40
  "yaml": "^2.7.0",
41
41
  "zod": "^4.3.6",
42
- "@inkeep/agents-core": "^0.62.1",
43
- "@inkeep/agents-sdk": "^0.62.1"
42
+ "@inkeep/agents-core": "^0.63.0",
43
+ "@inkeep/agents-sdk": "^0.63.0"
44
44
  },
45
45
  "devDependencies": {
46
46
  "@types/degit": "^2.8.6",
@@ -1,66 +0,0 @@
1
- import { toTriggerReferenceName } from "../utils/naming.js";
2
- import "../utils/index.js";
3
- import { buildSequentialNameFileNames } from "../generation-resolver.js";
4
- import { generateSimpleFactoryDefinition } from "../simple-factory-generator.js";
5
- import { FullProjectDefinitionSchema } from "@inkeep/agents-core";
6
- import { z } from "zod";
7
- import { join } from "node:path";
8
- import { SyntaxKind } from "ts-morph";
9
-
10
- //#region src/commands/pull-v4/generators/scheduled-trigger-generator.ts
11
- const MySchema = FullProjectDefinitionSchema.shape.agents.valueType.shape.scheduledTriggers.unwrap().valueType.omit({
12
- id: true,
13
- runAsUserId: true,
14
- createdBy: true
15
- });
16
- const ScheduledTriggerSchema = z.strictObject({
17
- scheduledTriggerId: z.string().nonempty(),
18
- ...MySchema.shape,
19
- description: z.preprocess((v) => v ?? void 0, MySchema.shape.description),
20
- runAt: z.preprocess((v) => v ?? void 0, MySchema.shape.runAt),
21
- payload: z.preprocess((v) => v ?? void 0, MySchema.shape.payload)
22
- });
23
- function generateScheduledTriggerDefinition({ id, runAsUserId, createdBy, ...data }) {
24
- return generateSimpleFactoryDefinition(data, {
25
- schema: ScheduledTriggerSchema,
26
- factory: {
27
- importName: "ScheduledTrigger",
28
- variableName: (parsed) => toTriggerReferenceName(parsed.name),
29
- syntaxKind: SyntaxKind.NewExpression
30
- },
31
- buildConfig(parsed) {
32
- const { scheduledTriggerId, ...rest } = parsed;
33
- return {
34
- id: scheduledTriggerId,
35
- ...rest
36
- };
37
- }
38
- });
39
- }
40
- const task = {
41
- type: "scheduled-trigger",
42
- collect(context) {
43
- if (!context.project.agents) return [];
44
- const records = [];
45
- for (const agentId of context.completeAgentIds) {
46
- const agentData = context.project.agents[agentId];
47
- if (!agentData?.scheduledTriggers) continue;
48
- const scheduledTriggerEntries = Object.entries(agentData.scheduledTriggers);
49
- const fileNamesByScheduledTriggerId = buildSequentialNameFileNames(scheduledTriggerEntries);
50
- for (const [scheduledTriggerId, scheduledTriggerData] of scheduledTriggerEntries) records.push({
51
- id: scheduledTriggerId,
52
- filePath: context.resolver.resolveOutputFilePath("scheduledTriggers", scheduledTriggerId, join(context.paths.agentsDir, "scheduled-triggers", fileNamesByScheduledTriggerId[scheduledTriggerId])),
53
- payload: {
54
- scheduledTriggerId,
55
- ...scheduledTriggerData
56
- }
57
- });
58
- }
59
- return records;
60
- },
61
- generate: generateScheduledTriggerDefinition
62
- };
63
-
64
- //#endregion
65
- export { generateScheduledTriggerDefinition, task };
66
- //# sourceMappingURL=scheduled-trigger-generator.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"scheduled-trigger-generator.js","names":[],"sources":["../../../../src/commands/pull-v4/generators/scheduled-trigger-generator.ts"],"sourcesContent":["import { join } from 'node:path';\nimport { FullProjectDefinitionSchema } from '@inkeep/agents-core';\nimport { type SourceFile, SyntaxKind } from 'ts-morph';\nimport { z } from 'zod';\nimport { buildSequentialNameFileNames } from '../generation-resolver';\nimport type { GenerationTask } from '../generation-types';\nimport { generateSimpleFactoryDefinition } from '../simple-factory-generator';\nimport { toTriggerReferenceName } from '../utils';\n\nconst MySchema = FullProjectDefinitionSchema.shape.agents.valueType.shape.scheduledTriggers\n .unwrap()\n .valueType.omit({\n id: true,\n runAsUserId: true,\n createdBy: true,\n });\n\nconst ScheduledTriggerSchema = z.strictObject({\n scheduledTriggerId: z.string().nonempty(),\n ...MySchema.shape,\n description: z.preprocess((v) => v ?? undefined, MySchema.shape.description),\n runAt: z.preprocess((v) => v ?? undefined, MySchema.shape.runAt),\n payload: z.preprocess((v) => v ?? undefined, MySchema.shape.payload),\n});\n\ntype ScheduledTriggerInput = z.input<typeof ScheduledTriggerSchema>;\n\nexport function generateScheduledTriggerDefinition({\n id,\n runAsUserId,\n createdBy,\n ...data\n}: ScheduledTriggerInput & Record<string, unknown>): SourceFile {\n return generateSimpleFactoryDefinition(data, {\n schema: ScheduledTriggerSchema,\n factory: {\n importName: 'ScheduledTrigger',\n variableName: (parsed) => toTriggerReferenceName(parsed.name),\n syntaxKind: SyntaxKind.NewExpression,\n },\n buildConfig(parsed) {\n const { scheduledTriggerId, ...rest } = parsed;\n return {\n id: scheduledTriggerId,\n ...rest,\n };\n },\n });\n}\n\nexport const task = {\n type: 'scheduled-trigger',\n collect(context) {\n if (!context.project.agents) {\n return [];\n }\n\n const records = [];\n for (const agentId of context.completeAgentIds) {\n const agentData = context.project.agents[agentId];\n if (!agentData?.scheduledTriggers) {\n continue;\n }\n\n const scheduledTriggerEntries = Object.entries(agentData.scheduledTriggers);\n const fileNamesByScheduledTriggerId = buildSequentialNameFileNames(scheduledTriggerEntries);\n\n for (const [scheduledTriggerId, scheduledTriggerData] of scheduledTriggerEntries) {\n records.push({\n id: scheduledTriggerId,\n filePath: context.resolver.resolveOutputFilePath(\n 'scheduledTriggers',\n scheduledTriggerId,\n join(\n context.paths.agentsDir,\n 'scheduled-triggers',\n fileNamesByScheduledTriggerId[scheduledTriggerId]\n )\n ),\n payload: {\n scheduledTriggerId,\n ...scheduledTriggerData,\n } as Parameters<typeof generateScheduledTriggerDefinition>[0],\n });\n }\n }\n\n return records;\n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