@inkeep/agents-cli 0.59.3 → 0.59.4
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.
- package/dist/agents-cli/package.js +1 -1
- package/dist/commands/pull-v4/collector-common.js +128 -0
- package/dist/commands/pull-v4/collector-common.js.map +1 -0
- package/dist/commands/pull-v4/collector-reference-helpers.js +323 -0
- package/dist/commands/pull-v4/collector-reference-helpers.js.map +1 -0
- package/dist/commands/pull-v4/component-parser.js +2 -1
- package/dist/commands/pull-v4/component-parser.js.map +1 -1
- package/dist/commands/pull-v4/file-scope.js +43 -0
- package/dist/commands/pull-v4/file-scope.js.map +1 -0
- package/dist/commands/pull-v4/generation-resolver.js +305 -0
- package/dist/commands/pull-v4/generation-resolver.js.map +1 -0
- package/dist/commands/pull-v4/generation-types.js +56 -0
- package/dist/commands/pull-v4/generation-types.js.map +1 -0
- package/dist/commands/pull-v4/generators/agent-generator.helpers.js +4 -10
- package/dist/commands/pull-v4/generators/agent-generator.helpers.js.map +1 -1
- package/dist/commands/pull-v4/generators/agent-generator.js +154 -81
- package/dist/commands/pull-v4/generators/agent-generator.js.map +1 -1
- package/dist/commands/pull-v4/generators/artifact-component-generator.js +48 -27
- package/dist/commands/pull-v4/generators/artifact-component-generator.js.map +1 -1
- package/dist/commands/pull-v4/generators/context-config-generator.js +147 -129
- package/dist/commands/pull-v4/generators/context-config-generator.js.map +1 -1
- package/dist/commands/pull-v4/generators/credential-generator.js +36 -14
- package/dist/commands/pull-v4/generators/credential-generator.js.map +1 -1
- package/dist/commands/pull-v4/generators/data-component-generator.js +55 -19
- package/dist/commands/pull-v4/generators/data-component-generator.js.map +1 -1
- package/dist/commands/pull-v4/generators/environment-generator.js +29 -33
- package/dist/commands/pull-v4/generators/environment-generator.js.map +1 -1
- package/dist/commands/pull-v4/generators/environment-settings-generator.js +57 -0
- package/dist/commands/pull-v4/generators/environment-settings-generator.js.map +1 -0
- package/dist/commands/pull-v4/generators/external-agent-generator.js +51 -23
- package/dist/commands/pull-v4/generators/external-agent-generator.js.map +1 -1
- package/dist/commands/pull-v4/generators/function-tool-generator.js +50 -14
- package/dist/commands/pull-v4/generators/function-tool-generator.js.map +1 -1
- package/dist/commands/pull-v4/generators/helpers/agent.js +129 -0
- package/dist/commands/pull-v4/generators/helpers/agent.js.map +1 -0
- package/dist/commands/pull-v4/generators/helpers/sub-agent.js +65 -0
- package/dist/commands/pull-v4/generators/helpers/sub-agent.js.map +1 -0
- package/dist/commands/pull-v4/generators/index.js +38 -0
- package/dist/commands/pull-v4/generators/index.js.map +1 -0
- package/dist/commands/pull-v4/generators/mcp-tool-generator.js +48 -27
- package/dist/commands/pull-v4/generators/mcp-tool-generator.js.map +1 -1
- package/dist/commands/pull-v4/generators/project-generator.js +144 -110
- package/dist/commands/pull-v4/generators/project-generator.js.map +1 -1
- package/dist/commands/pull-v4/generators/scheduled-trigger-generator.js +66 -0
- package/dist/commands/pull-v4/generators/scheduled-trigger-generator.js.map +1 -0
- package/dist/commands/pull-v4/generators/status-component-generator.js +55 -20
- package/dist/commands/pull-v4/generators/status-component-generator.js.map +1 -1
- package/dist/commands/pull-v4/generators/sub-agent-generator.helpers.js +4 -1
- package/dist/commands/pull-v4/generators/sub-agent-generator.helpers.js.map +1 -1
- package/dist/commands/pull-v4/generators/sub-agent-generator.js +282 -166
- package/dist/commands/pull-v4/generators/sub-agent-generator.js.map +1 -1
- package/dist/commands/pull-v4/generators/trigger-generator.js +62 -27
- package/dist/commands/pull-v4/generators/trigger-generator.js.map +1 -1
- package/dist/commands/pull-v4/import-plan.js +40 -0
- package/dist/commands/pull-v4/import-plan.js.map +1 -0
- package/dist/commands/pull-v4/introspect/index.js +11 -7
- package/dist/commands/pull-v4/introspect/index.js.map +1 -1
- package/dist/commands/pull-v4/introspect-generator.js +15 -1218
- package/dist/commands/pull-v4/introspect-generator.js.map +1 -1
- package/dist/commands/pull-v4/module-merge.js +14 -5
- package/dist/commands/pull-v4/module-merge.js.map +1 -1
- package/dist/commands/pull-v4/reference-resolution.js +111 -0
- package/dist/commands/pull-v4/reference-resolution.js.map +1 -0
- package/dist/commands/pull-v4/simple-factory-generator.js +54 -0
- package/dist/commands/pull-v4/simple-factory-generator.js.map +1 -0
- package/dist/commands/pull-v4/{generators/skill-generator.js → skill.js} +18 -6
- package/dist/commands/pull-v4/skill.js.map +1 -0
- package/dist/commands/pull-v4/typescript-file-writer.js +78 -0
- package/dist/commands/pull-v4/typescript-file-writer.js.map +1 -0
- package/dist/commands/pull-v4/utils/code-values.js +64 -0
- package/dist/commands/pull-v4/utils/code-values.js.map +1 -0
- package/dist/commands/pull-v4/utils/factory-writer.js +128 -0
- package/dist/commands/pull-v4/utils/factory-writer.js.map +1 -0
- package/dist/commands/pull-v4/utils/index.js +8 -0
- package/dist/commands/pull-v4/utils/naming.js +74 -0
- package/dist/commands/pull-v4/utils/naming.js.map +1 -0
- package/dist/commands/pull-v4/utils/schema-rendering.js +20 -0
- package/dist/commands/pull-v4/utils/schema-rendering.js.map +1 -0
- package/dist/commands/pull-v4/utils/shared.js +18 -0
- package/dist/commands/pull-v4/utils/shared.js.map +1 -0
- package/dist/commands/pull-v4/utils/templates.js +58 -0
- package/dist/commands/pull-v4/utils/templates.js.map +1 -0
- package/package.json +4 -4
- package/dist/commands/pull-v4/generators/skill-generator.js.map +0 -1
- package/dist/commands/pull-v4/scheduled-trigger-generator.js +0 -38
- package/dist/commands/pull-v4/scheduled-trigger-generator.js.map +0 -1
- package/dist/commands/pull-v4/utils.js +0 -320
- package/dist/commands/pull-v4/utils.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"component-parser.js","names":["args"],"sources":["../../../src/commands/pull-v4/component-parser.ts"],"sourcesContent":["/**\n * Component Parser - Find all component definitions (exported and inline)\n * Uses AST parsing to handle complex components including those with render attributes\n * Maps components by looking for patterns like:\n * - export const myTool = tool({id: 'tool-id', ...})\n * - dataComponent({id: 'data-id', ...}) (inline)\n */\n\nimport { existsSync, readdirSync, readFileSync, statSync } from 'node:fs';\nimport { extname, join, relative } from 'node:path';\nimport { type CallExpression, Node, type ObjectLiteralExpression } from 'ts-morph';\nimport { ComponentRegistry, type ComponentType } from './component-registry';\nimport { createInMemoryProject } from './utils';\n\ninterface ComponentMatch {\n id: string;\n type: ComponentType;\n filePath: string;\n variableName?: string; // If exported\n startLine: number;\n isInline: boolean; // true if not exported, false if exported\n overrideExisting?: boolean; // true if this should override an existing component\n}\n\n/**\n * Valid plural component types for parsing\n */\nconst VALID_COMPONENT_TYPES = new Set<ComponentType>([\n 'project',\n 'agents',\n 'subAgents',\n 'tools',\n 'functionTools',\n 'dataComponents',\n 'artifactComponents',\n 'statusComponents',\n 'externalAgents',\n 'credentials',\n 'contextConfigs',\n 'fetchDefinitions',\n 'headers',\n]);\n\n/**\n * Mapping from SDK function names to ComponentTypes\n */\nconst FUNCTION_NAME_TO_TYPE: Record<string, ComponentType> = {\n project: 'project',\n agent: 'agents',\n subAgent: 'subAgents',\n tool: 'tools',\n functionTool: 'functionTools',\n dataComponent: 'dataComponents',\n artifactComponent: 'artifactComponents',\n statusComponent: 'statusComponents',\n externalAgent: 'externalAgents',\n credential: 'credentials',\n contextConfig: 'contextConfigs',\n fetchDefinition: 'fetchDefinitions',\n header: 'headers',\n mcpTool: 'tools',\n};\n\n/**\n * Parse a single file for all component definitions using AST parsing\n * Handles all patterns: exported, declared+exported, declared-only, and inline\n */\nfunction parseFileForComponents(\n filePath: string,\n projectRoot: string,\n debug = false\n): ComponentMatch[] {\n if (!existsSync(filePath)) {\n return [];\n }\n\n const components: ComponentMatch[] = [];\n const relativePath = relative(projectRoot, filePath);\n\n try {\n const content = readFileSync(filePath, 'utf8');\n\n // Create a temporary ts-morph project for parsing\n const project = createInMemoryProject();\n\n // Add the file to the project\n const sourceFile = project.createSourceFile('temp.ts', content);\n\n // Pattern 1: Direct exports (export const name = func({...}))\n const exportedVariableDeclarations = sourceFile\n .getVariableStatements()\n .filter((statement) => statement.hasExportKeyword())\n .flatMap((statement) => statement.getDeclarationList().getDeclarations());\n\n for (const declaration of exportedVariableDeclarations) {\n const variableName = declaration.getName();\n const initializer = declaration.getInitializer();\n\n if (Node.isCallExpression(initializer)) {\n const componentMatch = parseCallExpression(initializer, variableName, false, relativePath);\n if (componentMatch) {\n components.push(componentMatch);\n }\n }\n }\n\n // Pattern 2: Separate declaration + export (const name = func({...}) + export { name })\n // First, collect all exported names from export declarations\n const exportedNames = new Set<string>();\n sourceFile.getExportDeclarations().forEach((exportDecl) => {\n const namedExports = exportDecl.getNamedExports();\n namedExports.forEach((namedExport) => {\n exportedNames.add(namedExport.getName());\n });\n });\n\n // Find variable declarations that are exported via separate export statements\n const allVariableDeclarations = sourceFile\n .getVariableStatements()\n .filter((statement) => !statement.hasExportKeyword()) // Not direct exports\n .flatMap((statement) => statement.getDeclarationList().getDeclarations());\n\n for (const declaration of allVariableDeclarations) {\n const variableName = declaration.getName();\n const initializer = declaration.getInitializer();\n\n if (Node.isCallExpression(initializer)) {\n const isExported = exportedNames.has(variableName);\n const isInline = !isExported;\n\n const componentMatch = parseCallExpression(\n initializer,\n variableName,\n isInline,\n relativePath\n );\n if (componentMatch) {\n components.push(componentMatch);\n }\n }\n }\n\n // Pattern 3: Truly inline components (function calls without variable assignment)\n // Walk the AST to find all call expressions that aren't part of variable declarations\n sourceFile.forEachDescendant((node) => {\n if (Node.isCallExpression(node)) {\n // Check if this call expression is NOT the initializer of a variable declaration\n const parent = node.getParent();\n const isVariableInitializer =\n Node.isVariableDeclaration(parent) && parent.getInitializer() === node;\n\n if (!isVariableInitializer) {\n const componentMatch = parseCallExpression(node, undefined, true, relativePath);\n if (componentMatch) {\n components.push(componentMatch);\n }\n }\n }\n });\n\n // Pattern 4: Environment-based credentials within registerEnvironmentSettings\n // export const development = registerEnvironmentSettings({\n // credentials: {\n // stripe_api_key: {\n // id: 'stripe-api-key',\n // name: 'Stripe API Key',\n // ...\n // }\n // }\n // });\n sourceFile.forEachDescendant((node) => {\n if (Node.isCallExpression(node)) {\n const expression = node.getExpression();\n\n // Check if this is a registerEnvironmentSettings call\n if (\n Node.isIdentifier(expression) &&\n expression.getText() === 'registerEnvironmentSettings'\n ) {\n const args = node.getArguments();\n if (args.length > 0 && Node.isObjectLiteralExpression(args[0])) {\n const configObject = args[0];\n\n // Look for credentials property\n const credentialsProperty = configObject.getProperty('credentials');\n if (credentialsProperty && Node.isPropertyAssignment(credentialsProperty)) {\n const credentialsValue = credentialsProperty.getInitializer();\n\n if (Node.isObjectLiteralExpression(credentialsValue)) {\n // Parse each credential in the credentials object\n credentialsValue.getProperties().forEach((property) => {\n if (Node.isPropertyAssignment(property)) {\n const credentialKey = property.getName(); // e.g., \"stripe_api_key\"\n const credentialConfig = property.getInitializer();\n\n if (Node.isObjectLiteralExpression(credentialConfig)) {\n // Inline credential definition - Look for the 'id' property in the credential config\n const idProperty = credentialConfig.getProperty('id');\n if (idProperty && Node.isPropertyAssignment(idProperty)) {\n const idValue = idProperty.getInitializer();\n if (Node.isStringLiteral(idValue)) {\n const credentialId = idValue.getLiteralValue(); // e.g., \"stripe-api-key\"\n const startLine = node.getStartLineNumber();\n\n components.push({\n id: credentialId,\n type: 'credentials',\n filePath: relativePath,\n variableName: credentialKey, // Use the key name as variable name\n startLine,\n isInline: true, // It's nested within environment settings\n });\n }\n }\n } else if (Node.isIdentifier(credentialConfig)) {\n // Variable reference - need to find the credential ID from the variable\n // This handles cases like: stripe_api_key: stripeApiKey\n const variableName = credentialConfig.getText();\n\n // Look for the credential variable definition in this file\n sourceFile.forEachDescendant((varNode) => {\n if (\n Node.isVariableDeclaration(varNode) &&\n varNode.getName() === variableName\n ) {\n const initializer = varNode.getInitializer();\n if (Node.isCallExpression(initializer)) {\n const callExpression = initializer.getExpression();\n if (\n Node.isIdentifier(callExpression) &&\n callExpression.getText() === 'credential'\n ) {\n const args = initializer.getArguments();\n if (args.length > 0 && Node.isObjectLiteralExpression(args[0])) {\n const configObject = args[0];\n const idProperty = configObject.getProperty('id');\n if (idProperty && Node.isPropertyAssignment(idProperty)) {\n const idValue = idProperty.getInitializer();\n if (Node.isStringLiteral(idValue)) {\n const credentialId = idValue.getLiteralValue();\n const startLine = node.getStartLineNumber();\n\n components.push({\n id: credentialId,\n type: 'credentials',\n filePath: relativePath,\n variableName: credentialKey, // Use the env settings key as variable name\n startLine,\n isInline: true,\n overrideExisting: true, // Mark this to override any existing registration\n });\n }\n }\n }\n }\n }\n }\n });\n }\n }\n });\n }\n }\n }\n }\n }\n });\n\n return components;\n } catch (error) {\n if (debug) {\n console.warn(`Failed to parse file ${relativePath}: ${error}`);\n }\n return [];\n }\n}\n\n/**\n * Parse a call expression to extract component information\n * Handles the same logic as the original regex patterns\n */\nfunction parseCallExpression(\n callExpression: CallExpression,\n variableName: string | undefined,\n isInline: boolean,\n relativePath: string\n): ComponentMatch | null {\n const expression = callExpression.getExpression();\n\n // Get the function name (e.g., 'dataComponent', 'tool', etc.)\n let functionName: string;\n if (Node.isIdentifier(expression)) {\n functionName = expression.getText();\n } else {\n return null;\n }\n\n // Map function name to component type\n const componentType = FUNCTION_NAME_TO_TYPE[functionName];\n if (!componentType || !VALID_COMPONENT_TYPES.has(componentType)) {\n return null;\n }\n\n // Get the first argument (should be an object literal)\n const args = callExpression.getArguments();\n if (args.length === 0 || !Node.isObjectLiteralExpression(args[0])) {\n return null;\n }\n\n const configObject = args[0] as ObjectLiteralExpression;\n\n // Extract the component ID using the same rules as regex parser\n let componentId: string | null = null;\n\n // Look for 'id' property first (most common case)\n const idProperty = configObject.getProperty('id');\n if (idProperty && Node.isPropertyAssignment(idProperty)) {\n const idValue = idProperty.getInitializer();\n if (Node.isStringLiteral(idValue)) {\n componentId = idValue.getLiteralValue();\n }\n }\n\n // For statusComponents, look for 'type' property if 'id' not found (matches regex logic)\n if (!componentId && componentType === 'statusComponents') {\n const typeProperty = configObject.getProperty('type');\n if (typeProperty && Node.isPropertyAssignment(typeProperty)) {\n const typeValue = typeProperty.getInitializer();\n if (Node.isStringLiteral(typeValue)) {\n componentId = typeValue.getLiteralValue();\n }\n }\n }\n\n // For functionTools, look for 'name' property if 'id' not found (matches regex logic)\n if (!componentId && componentType === 'functionTools') {\n const nameProperty = configObject.getProperty('name');\n if (nameProperty && Node.isPropertyAssignment(nameProperty)) {\n const nameValue = nameProperty.getInitializer();\n if (Node.isStringLiteral(nameValue)) {\n componentId = nameValue.getLiteralValue();\n }\n }\n }\n\n if (!componentId) {\n return null;\n }\n\n const startLine = callExpression.getStartLineNumber();\n\n return {\n id: componentId,\n type: componentType,\n filePath: relativePath,\n variableName: variableName,\n startLine,\n isInline,\n };\n}\n\n/**\n * Scan project directory for all components\n */\nfunction scanProjectForComponents(projectRoot: string, debug: boolean = false): ComponentMatch[] {\n const allComponents: ComponentMatch[] = [];\n\n if (!existsSync(projectRoot)) {\n return allComponents;\n }\n\n const scanDir = (dir: string) => {\n try {\n const items = readdirSync(dir);\n for (const item of items) {\n const fullPath = join(dir, item);\n const stat = statSync(fullPath);\n\n if (stat.isDirectory()) {\n // Skip node_modules, build directories, and temp validation directories\n if (\n !['node_modules', '.next', '.git', 'dist', 'build'].includes(item) &&\n !item.startsWith('.temp-validation-')\n ) {\n scanDir(fullPath);\n }\n } else if (stat.isFile() && ['.ts', '.tsx', '.js', '.jsx'].includes(extname(item))) {\n const fileComponents = parseFileForComponents(fullPath, projectRoot, debug);\n allComponents.push(...fileComponents);\n }\n }\n } catch (error) {\n if (debug) {\n console.warn(`Failed to scan directory ${dir}: ${error}`);\n }\n }\n };\n\n scanDir(projectRoot);\n\n return allComponents;\n}\n\n/**\n * Build component registry from project parsing\n */\nexport function buildComponentRegistryFromParsing(\n projectRoot: string,\n debug: boolean = false\n): ComponentRegistry {\n const registry = new ComponentRegistry();\n\n const allComponents = scanProjectForComponents(projectRoot, debug);\n\n // Sort components to prioritize exported over inline (in case of duplicates)\n allComponents.sort((a, b) => {\n if (a.id === b.id) {\n // Same ID: prioritize exported (false) over inline (true)\n return Number(a.isInline) - Number(b.isInline);\n }\n return 0; // Keep original order for different IDs\n });\n\n // Register components with registry (avoid duplicates by ID)\n const stats = {\n exported: 0,\n inline: 0,\n byType: {} as Record<string, number>,\n };\n\n const registeredTypeIds = new Set<string>(); // Use type:id instead of just id\n\n for (const component of allComponents) {\n const typeId = `${component.type}:${component.id}`;\n\n // Skip if already registered, unless this component should override existing\n if (registeredTypeIds.has(typeId) && !component.overrideExisting) {\n continue;\n }\n\n registeredTypeIds.add(typeId);\n\n if (component.variableName) {\n // Component has an actual variable name (declared with const/export const), use it\n\n if (component.overrideExisting && component.type === 'credentials') {\n // Use override method for credentials with env settings keys\n registry.overrideCredentialWithEnvKey(\n component.id,\n component.filePath,\n component.variableName\n );\n } else {\n registry.register(\n component.id,\n component.type,\n component.filePath,\n component.variableName,\n component.isInline\n );\n }\n } else {\n // Truly inline component with no variable name, let registry generate unique name\n registry.register(\n component.id,\n component.type,\n component.filePath,\n undefined, // Let registry handle naming with conflict resolution\n true // isInline = true\n );\n }\n\n // Update stats\n if (component.isInline) {\n stats.inline++;\n } else {\n stats.exported++;\n }\n stats.byType[component.type] = (stats.byType[component.type] || 0) + 1;\n }\n return registry;\n}\n\n/**\n * Get component location info for a specific component ID\n */\nexport function findComponentById(componentId: string, projectRoot: string): ComponentMatch | null {\n const allComponents = scanProjectForComponents(projectRoot, false);\n return allComponents.find((comp) => comp.id === componentId) || null;\n}\n\n/**\n * Get all local component IDs\n */\nexport function getAllLocalComponentIds(projectRoot: string): Set<string> {\n const allComponents = scanProjectForComponents(projectRoot, false);\n return new Set(allComponents.map((comp) => comp.id));\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AA2BA,MAAM,wBAAwB,IAAI,IAAmB;CACnD;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD,CAAC;;;;AAKF,MAAM,wBAAuD;CAC3D,SAAS;CACT,OAAO;CACP,UAAU;CACV,MAAM;CACN,cAAc;CACd,eAAe;CACf,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B,yBAAyB,aAAa,MAAM,CAC7C,MAAM,SAAS,KAAK,OAAO,YAAY,IAAI;;;;;AAMlE,SAAgB,wBAAwB,aAAkC;CACxE,MAAM,gBAAgB,yBAAyB,aAAa,MAAM;AAClE,QAAO,IAAI,IAAI,cAAc,KAAK,SAAS,KAAK,GAAG,CAAC"}
|
|
1
|
+
{"version":3,"file":"component-parser.js","names":["args"],"sources":["../../../src/commands/pull-v4/component-parser.ts"],"sourcesContent":["/**\n * Component Parser - Find all component definitions (exported and inline)\n * Uses AST parsing to handle complex components including those with render attributes\n * Maps components by looking for patterns like:\n * - export const myTool = tool({id: 'tool-id', ...})\n * - dataComponent({id: 'data-id', ...}) (inline)\n */\n\nimport { existsSync, readdirSync, readFileSync, statSync } from 'node:fs';\nimport { extname, join, relative } from 'node:path';\nimport { type CallExpression, Node, type ObjectLiteralExpression } from 'ts-morph';\nimport { ComponentRegistry, type ComponentType } from './component-registry';\nimport { createInMemoryProject } from './utils';\n\ninterface ComponentMatch {\n id: string;\n type: ComponentType;\n filePath: string;\n variableName?: string; // If exported\n startLine: number;\n isInline: boolean; // true if not exported, false if exported\n overrideExisting?: boolean; // true if this should override an existing component\n}\n\n/**\n * Valid plural component types for parsing\n */\nconst VALID_COMPONENT_TYPES = new Set<ComponentType>([\n 'project',\n 'agents',\n 'subAgents',\n 'tools',\n 'functionTools',\n 'dataComponents',\n 'artifactComponents',\n 'statusComponents',\n 'externalAgents',\n 'credentials',\n 'contextConfigs',\n 'fetchDefinitions',\n 'headers',\n]);\n\n/**\n * Mapping from SDK function names to ComponentTypes\n */\nconst FUNCTION_NAME_TO_TYPE: Record<string, ComponentType> = {\n project: 'project',\n agent: 'agents',\n subAgent: 'subAgents',\n tool: 'tools',\n functionTool: 'functionTools',\n dataComponent: 'dataComponents',\n artifactComponent: 'artifactComponents',\n statusComponent: 'statusComponents',\n externalAgent: 'externalAgents',\n credential: 'credentials',\n contextConfig: 'contextConfigs',\n fetchDefinition: 'fetchDefinitions',\n header: 'headers',\n mcpTool: 'tools',\n};\n\n/**\n * Parse a single file for all component definitions using AST parsing\n * Handles all patterns: exported, declared+exported, declared-only, and inline\n */\nfunction parseFileForComponents(\n filePath: string,\n projectRoot: string,\n debug = false\n): ComponentMatch[] {\n if (!existsSync(filePath)) {\n return [];\n }\n\n const components: ComponentMatch[] = [];\n const relativePath = relative(projectRoot, filePath);\n\n try {\n const content = readFileSync(filePath, 'utf8');\n\n // Create a temporary ts-morph project for parsing\n const project = createInMemoryProject();\n\n // Add the file to the project\n const sourceFile = project.createSourceFile('temp.ts', content);\n\n // Pattern 1: Direct exports (export const name = func({...}))\n const exportedVariableDeclarations = sourceFile\n .getVariableStatements()\n .filter((statement) => statement.hasExportKeyword())\n .flatMap((statement) => statement.getDeclarationList().getDeclarations());\n\n for (const declaration of exportedVariableDeclarations) {\n const variableName = declaration.getName();\n const initializer = declaration.getInitializer();\n\n if (Node.isCallExpression(initializer)) {\n const componentMatch = parseCallExpression(initializer, variableName, false, relativePath);\n if (componentMatch) {\n components.push(componentMatch);\n }\n }\n }\n\n // Pattern 2: Separate declaration + export (const name = func({...}) + export { name })\n // First, collect all exported names from export declarations\n const exportedNames = new Set<string>();\n sourceFile.getExportDeclarations().forEach((exportDecl) => {\n const namedExports = exportDecl.getNamedExports();\n namedExports.forEach((namedExport) => {\n exportedNames.add(namedExport.getName());\n });\n });\n\n // Find variable declarations that are exported via separate export statements\n const allVariableDeclarations = sourceFile\n .getVariableStatements()\n .filter((statement) => !statement.hasExportKeyword()) // Not direct exports\n .flatMap((statement) => statement.getDeclarationList().getDeclarations());\n\n for (const declaration of allVariableDeclarations) {\n const variableName = declaration.getName();\n const initializer = declaration.getInitializer();\n\n if (Node.isCallExpression(initializer)) {\n const isExported = exportedNames.has(variableName);\n const isInline = !isExported;\n\n const componentMatch = parseCallExpression(\n initializer,\n variableName,\n isInline,\n relativePath\n );\n if (componentMatch) {\n components.push(componentMatch);\n }\n }\n }\n\n // Pattern 3: Truly inline components (function calls without variable assignment)\n // Walk the AST to find all call expressions that aren't part of variable declarations\n sourceFile.forEachDescendant((node) => {\n if (Node.isCallExpression(node)) {\n // Check if this call expression is NOT the initializer of a variable declaration\n const parent = node.getParent();\n const isVariableInitializer =\n Node.isVariableDeclaration(parent) && parent.getInitializer() === node;\n\n if (!isVariableInitializer) {\n const componentMatch = parseCallExpression(node, undefined, true, relativePath);\n if (componentMatch) {\n components.push(componentMatch);\n }\n }\n }\n });\n\n // Pattern 4: Environment-based credentials within registerEnvironmentSettings\n // export const development = registerEnvironmentSettings({\n // credentials: {\n // stripe_api_key: {\n // id: 'stripe-api-key',\n // name: 'Stripe API Key',\n // ...\n // }\n // }\n // });\n sourceFile.forEachDescendant((node) => {\n if (Node.isCallExpression(node)) {\n const expression = node.getExpression();\n\n // Check if this is a registerEnvironmentSettings call\n if (\n Node.isIdentifier(expression) &&\n expression.getText() === 'registerEnvironmentSettings'\n ) {\n const args = node.getArguments();\n if (args.length > 0 && Node.isObjectLiteralExpression(args[0])) {\n const configObject = args[0];\n\n // Look for credentials property\n const credentialsProperty = configObject.getProperty('credentials');\n if (credentialsProperty && Node.isPropertyAssignment(credentialsProperty)) {\n const credentialsValue = credentialsProperty.getInitializer();\n\n if (Node.isObjectLiteralExpression(credentialsValue)) {\n // Parse each credential in the credentials object\n credentialsValue.getProperties().forEach((property) => {\n if (Node.isPropertyAssignment(property)) {\n const credentialKey = property.getName(); // e.g., \"stripe_api_key\"\n const credentialConfig = property.getInitializer();\n\n if (Node.isObjectLiteralExpression(credentialConfig)) {\n // Inline credential definition - Look for the 'id' property in the credential config\n const idProperty = credentialConfig.getProperty('id');\n if (idProperty && Node.isPropertyAssignment(idProperty)) {\n const idValue = idProperty.getInitializer();\n if (Node.isStringLiteral(idValue)) {\n const credentialId = idValue.getLiteralValue(); // e.g., \"stripe-api-key\"\n const startLine = node.getStartLineNumber();\n\n components.push({\n id: credentialId,\n type: 'credentials',\n filePath: relativePath,\n variableName: credentialKey, // Use the key name as variable name\n startLine,\n isInline: true, // It's nested within environment settings\n });\n }\n }\n } else if (Node.isIdentifier(credentialConfig)) {\n // Variable reference - need to find the credential ID from the variable\n // This handles cases like: stripe_api_key: stripeApiKey\n const variableName = credentialConfig.getText();\n\n // Look for the credential variable definition in this file\n sourceFile.forEachDescendant((varNode) => {\n if (\n Node.isVariableDeclaration(varNode) &&\n varNode.getName() === variableName\n ) {\n const initializer = varNode.getInitializer();\n if (Node.isCallExpression(initializer)) {\n const callExpression = initializer.getExpression();\n if (\n Node.isIdentifier(callExpression) &&\n callExpression.getText() === 'credential'\n ) {\n const args = initializer.getArguments();\n if (args.length > 0 && Node.isObjectLiteralExpression(args[0])) {\n const configObject = args[0];\n const idProperty = configObject.getProperty('id');\n if (idProperty && Node.isPropertyAssignment(idProperty)) {\n const idValue = idProperty.getInitializer();\n if (Node.isStringLiteral(idValue)) {\n const credentialId = idValue.getLiteralValue();\n const startLine = node.getStartLineNumber();\n\n components.push({\n id: credentialId,\n type: 'credentials',\n filePath: relativePath,\n variableName: credentialKey, // Use the env settings key as variable name\n startLine,\n isInline: true,\n overrideExisting: true, // Mark this to override any existing registration\n });\n }\n }\n }\n }\n }\n }\n });\n }\n }\n });\n }\n }\n }\n }\n }\n });\n\n return components;\n } catch (error) {\n if (debug) {\n console.warn(`Failed to parse file ${relativePath}: ${error}`);\n }\n return [];\n }\n}\n\n/**\n * Parse a call expression to extract component information\n * Handles the same logic as the original regex patterns\n */\nfunction parseCallExpression(\n callExpression: CallExpression,\n variableName: string | undefined,\n isInline: boolean,\n relativePath: string\n): ComponentMatch | null {\n const expression = callExpression.getExpression();\n\n // Get the function name (e.g., 'dataComponent', 'tool', etc.)\n let functionName: string;\n if (Node.isIdentifier(expression)) {\n functionName = expression.getText();\n } else {\n return null;\n }\n\n // Map function name to component type\n const componentType = FUNCTION_NAME_TO_TYPE[functionName];\n if (!componentType || !VALID_COMPONENT_TYPES.has(componentType)) {\n return null;\n }\n\n // Get the first argument (should be an object literal)\n const args = callExpression.getArguments();\n if (args.length === 0 || !Node.isObjectLiteralExpression(args[0])) {\n return null;\n }\n\n const configObject = args[0] as ObjectLiteralExpression;\n\n // Extract the component ID using the same rules as regex parser\n let componentId: string | null = null;\n\n // Look for 'id' property first (most common case)\n const idProperty = configObject.getProperty('id');\n if (idProperty && Node.isPropertyAssignment(idProperty)) {\n const idValue = idProperty.getInitializer();\n if (Node.isStringLiteral(idValue)) {\n componentId = idValue.getLiteralValue();\n }\n }\n\n // For statusComponents, look for 'type' property if 'id' not found (matches regex logic)\n if (!componentId && componentType === 'statusComponents') {\n const typeProperty = configObject.getProperty('type');\n if (typeProperty && Node.isPropertyAssignment(typeProperty)) {\n const typeValue = typeProperty.getInitializer();\n if (Node.isStringLiteral(typeValue)) {\n componentId = typeValue.getLiteralValue();\n }\n }\n }\n\n // For functionTools, look for 'name' property if 'id' not found (matches regex logic)\n if (!componentId && componentType === 'functionTools') {\n const nameProperty = configObject.getProperty('name');\n if (nameProperty && Node.isPropertyAssignment(nameProperty)) {\n const nameValue = nameProperty.getInitializer();\n if (Node.isStringLiteral(nameValue)) {\n componentId = nameValue.getLiteralValue();\n }\n }\n }\n\n if (!componentId) {\n return null;\n }\n\n const startLine = callExpression.getStartLineNumber();\n\n return {\n id: componentId,\n type: componentType,\n filePath: relativePath,\n variableName: variableName,\n startLine,\n isInline,\n };\n}\n\n/**\n * Scan project directory for all components\n */\nfunction scanProjectForComponents(projectRoot: string, debug: boolean = false): ComponentMatch[] {\n const allComponents: ComponentMatch[] = [];\n\n if (!existsSync(projectRoot)) {\n return allComponents;\n }\n\n const scanDir = (dir: string) => {\n try {\n const items = readdirSync(dir);\n for (const item of items) {\n const fullPath = join(dir, item);\n const stat = statSync(fullPath);\n\n if (stat.isDirectory()) {\n // Skip node_modules, build directories, and temp validation directories\n if (\n !['node_modules', '.next', '.git', 'dist', 'build'].includes(item) &&\n !item.startsWith('.temp-validation-')\n ) {\n scanDir(fullPath);\n }\n } else if (stat.isFile() && ['.ts', '.tsx', '.js', '.jsx'].includes(extname(item))) {\n const fileComponents = parseFileForComponents(fullPath, projectRoot, debug);\n allComponents.push(...fileComponents);\n }\n }\n } catch (error) {\n if (debug) {\n console.warn(`Failed to scan directory ${dir}: ${error}`);\n }\n }\n };\n\n scanDir(projectRoot);\n\n return allComponents;\n}\n\n/**\n * Build component registry from project parsing\n */\nexport function buildComponentRegistryFromParsing(\n projectRoot: string,\n debug: boolean = false\n): ComponentRegistry {\n const registry = new ComponentRegistry();\n\n const allComponents = scanProjectForComponents(projectRoot, debug);\n\n // Sort components to prioritize exported over inline (in case of duplicates)\n allComponents.sort((a, b) => {\n if (a.id === b.id) {\n // Same ID: prioritize exported (false) over inline (true)\n return Number(a.isInline) - Number(b.isInline);\n }\n return 0; // Keep original order for different IDs\n });\n\n // Register components with registry (avoid duplicates by ID)\n const stats = {\n exported: 0,\n inline: 0,\n byType: {} as Record<string, number>,\n };\n\n const registeredTypeIds = new Set<string>(); // Use type:id instead of just id\n\n for (const component of allComponents) {\n const typeId = `${component.type}:${component.id}`;\n\n // Skip if already registered, unless this component should override existing\n if (registeredTypeIds.has(typeId) && !component.overrideExisting) {\n continue;\n }\n\n registeredTypeIds.add(typeId);\n\n if (component.variableName) {\n // Component has an actual variable name (declared with const/export const), use it\n\n if (component.overrideExisting && component.type === 'credentials') {\n // Use override method for credentials with env settings keys\n registry.overrideCredentialWithEnvKey(\n component.id,\n component.filePath,\n component.variableName\n );\n } else {\n registry.register(\n component.id,\n component.type,\n component.filePath,\n component.variableName,\n component.isInline\n );\n }\n } else {\n // Truly inline component with no variable name, let registry generate unique name\n registry.register(\n component.id,\n component.type,\n component.filePath,\n undefined, // Let registry handle naming with conflict resolution\n true // isInline = true\n );\n }\n\n // Update stats\n if (component.isInline) {\n stats.inline++;\n } else {\n stats.exported++;\n }\n stats.byType[component.type] = (stats.byType[component.type] || 0) + 1;\n }\n return registry;\n}\n\n/**\n * Get component location info for a specific component ID\n */\nexport function findComponentById(componentId: string, projectRoot: string): ComponentMatch | null {\n const allComponents = scanProjectForComponents(projectRoot, false);\n return allComponents.find((comp) => comp.id === componentId) || null;\n}\n\n/**\n * Get all local component IDs\n */\nexport function getAllLocalComponentIds(projectRoot: string): Set<string> {\n const allComponents = scanProjectForComponents(projectRoot, false);\n return new Set(allComponents.map((comp) => comp.id));\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AA2BA,MAAM,wBAAwB,IAAI,IAAmB;CACnD;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD,CAAC;;;;AAKF,MAAM,wBAAuD;CAC3D,SAAS;CACT,OAAO;CACP,UAAU;CACV,MAAM;CACN,cAAc;CACd,eAAe;CACf,mBAAmB;CACnB,iBAAiB;CACjB,eAAe;CACf,YAAY;CACZ,eAAe;CACf,iBAAiB;CACjB,QAAQ;CACR,SAAS;CACV;;;;;AAMD,SAAS,uBACP,UACA,aACA,QAAQ,OACU;AAClB,KAAI,CAAC,WAAW,SAAS,CACvB,QAAO,EAAE;CAGX,MAAM,aAA+B,EAAE;CACvC,MAAM,eAAe,SAAS,aAAa,SAAS;AAEpD,KAAI;EACF,MAAM,UAAU,aAAa,UAAU,OAAO;EAM9C,MAAM,aAHU,uBAAuB,CAGZ,iBAAiB,WAAW,QAAQ;EAG/D,MAAM,+BAA+B,WAClC,uBAAuB,CACvB,QAAQ,cAAc,UAAU,kBAAkB,CAAC,CACnD,SAAS,cAAc,UAAU,oBAAoB,CAAC,iBAAiB,CAAC;AAE3E,OAAK,MAAM,eAAe,8BAA8B;GACtD,MAAM,eAAe,YAAY,SAAS;GAC1C,MAAM,cAAc,YAAY,gBAAgB;AAEhD,OAAI,KAAK,iBAAiB,YAAY,EAAE;IACtC,MAAM,iBAAiB,oBAAoB,aAAa,cAAc,OAAO,aAAa;AAC1F,QAAI,eACF,YAAW,KAAK,eAAe;;;EAOrC,MAAM,gCAAgB,IAAI,KAAa;AACvC,aAAW,uBAAuB,CAAC,SAAS,eAAe;AAEzD,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9C;AAGF,oBAAkB,IAAI,OAAO;AAE7B,MAAI,UAAU,aAGZ,KAAI,UAAU,oBAAoB,UAAU,SAAS,cAEnD,UAAS,6BACP,UAAU,IACV,UAAU,UACV,UAAU,aACX;MAED,UAAS,SACP,UAAU,IACV,UAAU,MACV,UAAU,UACV,UAAU,cACV,UAAU,SACX;MAIH,UAAS,SACP,UAAU,IACV,UAAU,MACV,UAAU,UACV,QACA,KACD;AAIH,MAAI,UAAU,SACZ,OAAM;MAEN,OAAM;AAER,QAAM,OAAO,UAAU,SAAS,MAAM,OAAO,UAAU,SAAS,KAAK;;AAEvE,QAAO;;;;;AAMT,SAAgB,kBAAkB,aAAqB,aAA4C;AAEjG,QADsB,yBAAyB,aAAa,MAAM,CAC7C,MAAM,SAAS,KAAK,OAAO,YAAY,IAAI;;;;;AAMlE,SAAgB,wBAAwB,aAAkC;CACxE,MAAM,gBAAgB,yBAAyB,aAAa,MAAM;AAClE,QAAO,IAAI,IAAI,cAAc,KAAK,SAAS,KAAK,GAAG,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { createInMemoryProject } from "./utils/factory-writer.js";
|
|
2
|
+
import "./utils/index.js";
|
|
3
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
4
|
+
|
|
5
|
+
//#region src/commands/pull-v4/file-scope.ts
|
|
6
|
+
function createFileScope(content, fileName = "scope.ts") {
|
|
7
|
+
const sourceFile = createInMemoryProject().createSourceFile(fileName, content, { overwrite: true });
|
|
8
|
+
return {
|
|
9
|
+
sourceFile,
|
|
10
|
+
reservedNames: collectReservedTopLevelNames(sourceFile)
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
function readFileScope(filePath) {
|
|
14
|
+
if (!existsSync(filePath)) return;
|
|
15
|
+
return createFileScope(readFileSync(filePath, "utf8"), filePath);
|
|
16
|
+
}
|
|
17
|
+
function collectReservedTopLevelNames(sourceFile) {
|
|
18
|
+
const reservedNames = /* @__PURE__ */ new Set();
|
|
19
|
+
for (const importDeclaration of sourceFile.getImportDeclarations()) {
|
|
20
|
+
const defaultImport = importDeclaration.getDefaultImport()?.getText();
|
|
21
|
+
if (defaultImport) reservedNames.add(defaultImport);
|
|
22
|
+
const namespaceImport = importDeclaration.getNamespaceImport()?.getText();
|
|
23
|
+
if (namespaceImport) reservedNames.add(namespaceImport);
|
|
24
|
+
for (const namedImport of importDeclaration.getNamedImports()) reservedNames.add(namedImport.getAliasNode()?.getText() ?? namedImport.getName());
|
|
25
|
+
}
|
|
26
|
+
for (const declarations of [
|
|
27
|
+
sourceFile.getVariableDeclarations(),
|
|
28
|
+
sourceFile.getFunctions(),
|
|
29
|
+
sourceFile.getClasses(),
|
|
30
|
+
sourceFile.getInterfaces(),
|
|
31
|
+
sourceFile.getTypeAliases(),
|
|
32
|
+
sourceFile.getEnums(),
|
|
33
|
+
sourceFile.getModules()
|
|
34
|
+
]) for (const declaration of declarations) {
|
|
35
|
+
const name = declaration.getName();
|
|
36
|
+
if (name) reservedNames.add(name);
|
|
37
|
+
}
|
|
38
|
+
return reservedNames;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
//#endregion
|
|
42
|
+
export { collectReservedTopLevelNames, createFileScope, readFileScope };
|
|
43
|
+
//# sourceMappingURL=file-scope.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-scope.js","names":[],"sources":["../../../src/commands/pull-v4/file-scope.ts"],"sourcesContent":["import { existsSync, readFileSync } from 'node:fs';\nimport type { SourceFile } from 'ts-morph';\nimport { createInMemoryProject } from './utils';\n\nexport interface FileScope {\n sourceFile: SourceFile;\n reservedNames: Set<string>;\n}\n\nexport function createFileScope(content: string, fileName = 'scope.ts'): FileScope {\n const sourceFile = createInMemoryProject().createSourceFile(fileName, content, {\n overwrite: true,\n });\n\n return {\n sourceFile,\n reservedNames: collectReservedTopLevelNames(sourceFile),\n };\n}\n\nexport function readFileScope(filePath: string): FileScope | undefined {\n if (!existsSync(filePath)) {\n return;\n }\n\n return createFileScope(readFileSync(filePath, 'utf8'), filePath);\n}\n\nexport function collectReservedTopLevelNames(sourceFile: SourceFile): Set<string> {\n const reservedNames = new Set<string>();\n\n for (const importDeclaration of sourceFile.getImportDeclarations()) {\n const defaultImport = importDeclaration.getDefaultImport()?.getText();\n if (defaultImport) {\n reservedNames.add(defaultImport);\n }\n\n const namespaceImport = importDeclaration.getNamespaceImport()?.getText();\n if (namespaceImport) {\n reservedNames.add(namespaceImport);\n }\n\n for (const namedImport of importDeclaration.getNamedImports()) {\n reservedNames.add(namedImport.getAliasNode()?.getText() ?? namedImport.getName());\n }\n }\n\n for (const declarations of [\n sourceFile.getVariableDeclarations(),\n sourceFile.getFunctions(),\n sourceFile.getClasses(),\n sourceFile.getInterfaces(),\n sourceFile.getTypeAliases(),\n sourceFile.getEnums(),\n sourceFile.getModules(),\n ]) {\n for (const declaration of declarations) {\n const name = declaration.getName();\n if (name) {\n reservedNames.add(name);\n }\n }\n }\n\n return reservedNames;\n}\n"],"mappings":";;;;;AASA,SAAgB,gBAAgB,SAAiB,WAAW,YAAuB;CACjF,MAAM,aAAa,uBAAuB,CAAC,iBAAiB,UAAU,SAAS,EAC7E,WAAW,MACZ,CAAC;AAEF,QAAO;EACL;EACA,eAAe,6BAA6B,WAAW;EACxD;;AAGH,SAAgB,cAAc,UAAyC;AACrE,KAAI,CAAC,WAAW,SAAS,CACvB;AAGF,QAAO,gBAAgB,aAAa,UAAU,OAAO,EAAE,SAAS;;AAGlE,SAAgB,6BAA6B,YAAqC;CAChF,MAAM,gCAAgB,IAAI,KAAa;AAEvC,MAAK,MAAM,qBAAqB,WAAW,uBAAuB,EAAE;EAClE,MAAM,gBAAgB,kBAAkB,kBAAkB,EAAE,SAAS;AACrE,MAAI,cACF,eAAc,IAAI,cAAc;EAGlC,MAAM,kBAAkB,kBAAkB,oBAAoB,EAAE,SAAS;AACzE,MAAI,gBACF,eAAc,IAAI,gBAAgB;AAGpC,OAAK,MAAM,eAAe,kBAAkB,iBAAiB,CAC3D,eAAc,IAAI,YAAY,cAAc,EAAE,SAAS,IAAI,YAAY,SAAS,CAAC;;AAIrF,MAAK,MAAM,gBAAgB;EACzB,WAAW,yBAAyB;EACpC,WAAW,cAAc;EACzB,WAAW,YAAY;EACvB,WAAW,eAAe;EAC1B,WAAW,gBAAgB;EAC3B,WAAW,UAAU;EACrB,WAAW,YAAY;EACxB,CACC,MAAK,MAAM,eAAe,cAAc;EACtC,MAAM,OAAO,YAAY,SAAS;AAClC,MAAI,KACF,eAAc,IAAI,KAAK;;AAK7B,QAAO"}
|
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
import { buildComponentFileName, isHumanReadableId, toCamelCase, toCredentialReferenceName, toKebabCase, toToolReferenceName } from "./utils/naming.js";
|
|
2
|
+
import "./utils/index.js";
|
|
3
|
+
import { asRecord, stripExtension } from "./collector-common.js";
|
|
4
|
+
import { resolveSubAgentVariableName } from "./generators/helpers/sub-agent.js";
|
|
5
|
+
import { basename, dirname, join } from "node:path";
|
|
6
|
+
|
|
7
|
+
//#region src/commands/pull-v4/generation-resolver.ts
|
|
8
|
+
var GenerationResolver = class {
|
|
9
|
+
projectRoot;
|
|
10
|
+
existingComponentRegistry;
|
|
11
|
+
toolReferenceNamesById;
|
|
12
|
+
toolReferencePathsById;
|
|
13
|
+
credentialReferenceNamesById;
|
|
14
|
+
credentialReferencePathsById;
|
|
15
|
+
externalAgentReferenceNamesById;
|
|
16
|
+
externalAgentReferencePathsById;
|
|
17
|
+
subAgentReferenceNamesById;
|
|
18
|
+
subAgentReferencePathsById;
|
|
19
|
+
agentReferenceNamesById;
|
|
20
|
+
agentReferencePathsById;
|
|
21
|
+
constructor({ project, projectRoot, completeAgentIds, existingComponentRegistry }) {
|
|
22
|
+
this.projectRoot = projectRoot;
|
|
23
|
+
this.existingComponentRegistry = existingComponentRegistry;
|
|
24
|
+
this.toolReferenceNamesById = buildToolReferenceNamesById(project);
|
|
25
|
+
this.toolReferencePathsById = buildToolReferencePathById(project);
|
|
26
|
+
this.credentialReferenceNamesById = buildCredentialReferenceNamesById(project);
|
|
27
|
+
this.credentialReferencePathsById = buildCredentialReferencePathById(project);
|
|
28
|
+
this.externalAgentReferenceNamesById = buildExternalAgentReferenceNamesById(project);
|
|
29
|
+
this.externalAgentReferencePathsById = buildExternalAgentReferencePathById(project);
|
|
30
|
+
this.subAgentReferenceNamesById = buildSubAgentReferenceNamesById(project, completeAgentIds);
|
|
31
|
+
this.subAgentReferencePathsById = buildSubAgentReferencePathById(project, completeAgentIds);
|
|
32
|
+
this.agentReferenceNamesById = buildAgentReferenceNamesById(project);
|
|
33
|
+
this.agentReferencePathsById = buildAgentReferencePathById(project);
|
|
34
|
+
}
|
|
35
|
+
getExistingComponent(id, type) {
|
|
36
|
+
return this.existingComponentRegistry?.get(id, type);
|
|
37
|
+
}
|
|
38
|
+
resolveOutputFilePath(componentType, componentId, fallbackFilePath) {
|
|
39
|
+
const existingComponent = this.getExistingComponent(componentId, componentType);
|
|
40
|
+
if (!existingComponent?.filePath) return fallbackFilePath;
|
|
41
|
+
return resolveProjectFilePath(this.projectRoot, existingComponent.filePath);
|
|
42
|
+
}
|
|
43
|
+
getToolReferenceName(toolId) {
|
|
44
|
+
return this.getPreferredReferenceName(toolId, ["functionTools", "tools"], this.toolReferenceNamesById);
|
|
45
|
+
}
|
|
46
|
+
getToolReferencePath(toolId) {
|
|
47
|
+
const existingTool = this.getExistingComponent(toolId, "functionTools") ?? this.getExistingComponent(toolId, "tools");
|
|
48
|
+
if (existingTool?.filePath) return resolveToolModulePath(existingTool.filePath);
|
|
49
|
+
return this.toolReferencePathsById[toolId];
|
|
50
|
+
}
|
|
51
|
+
getCredentialReferenceName(credentialId) {
|
|
52
|
+
return this.getPreferredReferenceName(credentialId, ["credentials"], this.credentialReferenceNamesById);
|
|
53
|
+
}
|
|
54
|
+
getCredentialReferencePath(credentialId) {
|
|
55
|
+
return this.getPreferredReferencePath(credentialId, ["credentials"], this.credentialReferencePathsById);
|
|
56
|
+
}
|
|
57
|
+
getExternalAgentReferenceName(externalAgentId) {
|
|
58
|
+
return this.getPreferredReferenceName(externalAgentId, ["externalAgents"], this.externalAgentReferenceNamesById);
|
|
59
|
+
}
|
|
60
|
+
getExternalAgentReferencePath(externalAgentId) {
|
|
61
|
+
return this.getPreferredReferencePath(externalAgentId, ["externalAgents"], this.externalAgentReferencePathsById);
|
|
62
|
+
}
|
|
63
|
+
getSubAgentReferenceName(subAgentId) {
|
|
64
|
+
return this.getPreferredReferenceName(subAgentId, ["subAgents"], this.subAgentReferenceNamesById);
|
|
65
|
+
}
|
|
66
|
+
getSubAgentReferencePath(subAgentId) {
|
|
67
|
+
return this.getPreferredReferencePath(subAgentId, ["subAgents"], this.subAgentReferencePathsById);
|
|
68
|
+
}
|
|
69
|
+
getAgentReferenceName(agentId) {
|
|
70
|
+
return this.getPreferredReferenceName(agentId, ["agents"], this.agentReferenceNamesById);
|
|
71
|
+
}
|
|
72
|
+
getAgentReferencePath(agentId) {
|
|
73
|
+
return this.getPreferredReferencePath(agentId, ["agents"], this.agentReferencePathsById);
|
|
74
|
+
}
|
|
75
|
+
getPreferredReferenceName(componentId, componentTypes, generatedNamesById) {
|
|
76
|
+
const existingComponent = this.getExistingComponentByTypes(componentId, componentTypes);
|
|
77
|
+
if (existingComponent?.name) return existingComponent.name;
|
|
78
|
+
return generatedNamesById[componentId];
|
|
79
|
+
}
|
|
80
|
+
getPreferredReferencePath(componentId, componentTypes, generatedPathsById) {
|
|
81
|
+
const existingComponent = this.getExistingComponentByTypes(componentId, componentTypes);
|
|
82
|
+
if (existingComponent?.filePath) return stripExtension(basename(existingComponent.filePath));
|
|
83
|
+
return generatedPathsById[componentId];
|
|
84
|
+
}
|
|
85
|
+
getExistingComponentByTypes(componentId, componentTypes) {
|
|
86
|
+
for (const componentType of componentTypes) {
|
|
87
|
+
const component = this.getExistingComponent(componentId, componentType);
|
|
88
|
+
if (component) return component;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
function collectFunctionToolEntries(project) {
|
|
93
|
+
const functionToolsById = collectFunctionToolsById(project);
|
|
94
|
+
const functionsById = collectFunctionsById(project);
|
|
95
|
+
const entries = [];
|
|
96
|
+
for (const [functionToolId, functionToolData] of Object.entries(functionToolsById)) {
|
|
97
|
+
const functionId = typeof functionToolData.functionId === "string" && functionToolData.functionId.length > 0 ? functionToolData.functionId : functionToolId;
|
|
98
|
+
const functionData = functionsById[functionId] ?? {};
|
|
99
|
+
const functionToolName = typeof functionToolData.name === "string" && functionToolData.name.length > 0 ? functionToolData.name : void 0;
|
|
100
|
+
const functionName = typeof functionData.name === "string" && functionData.name.length > 0 ? functionData.name : void 0;
|
|
101
|
+
const fallbackName = functionToolName ?? functionName ?? functionToolId;
|
|
102
|
+
entries.push({
|
|
103
|
+
functionToolId,
|
|
104
|
+
functionId,
|
|
105
|
+
functionToolData,
|
|
106
|
+
functionData,
|
|
107
|
+
exportName: fallbackName,
|
|
108
|
+
fileName: fallbackName
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
return entries;
|
|
112
|
+
}
|
|
113
|
+
function collectFunctionToolsById(project) {
|
|
114
|
+
const functionToolsById = {};
|
|
115
|
+
for (const [functionToolId, functionToolData] of Object.entries(project.functionTools ?? {})) {
|
|
116
|
+
const functionToolRecord = asRecord(functionToolData);
|
|
117
|
+
if (!functionToolRecord) continue;
|
|
118
|
+
functionToolsById[functionToolId] = { ...functionToolRecord };
|
|
119
|
+
}
|
|
120
|
+
for (const agentData of Object.values(project.agents ?? {})) {
|
|
121
|
+
const agentFunctionTools = asRecord(asRecord(agentData)?.functionTools);
|
|
122
|
+
if (!agentFunctionTools) continue;
|
|
123
|
+
for (const [functionToolId, functionToolData] of Object.entries(agentFunctionTools)) {
|
|
124
|
+
const functionToolRecord = asRecord(functionToolData);
|
|
125
|
+
if (!functionToolRecord) continue;
|
|
126
|
+
const existingFunctionTool = functionToolsById[functionToolId] ?? {};
|
|
127
|
+
functionToolsById[functionToolId] = {
|
|
128
|
+
...functionToolRecord,
|
|
129
|
+
...existingFunctionTool
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return functionToolsById;
|
|
134
|
+
}
|
|
135
|
+
function collectFunctionsById(project) {
|
|
136
|
+
const functionsById = {};
|
|
137
|
+
for (const [functionId, functionData] of Object.entries(project.functions ?? {})) {
|
|
138
|
+
const functionRecord = asRecord(functionData);
|
|
139
|
+
if (!functionRecord) continue;
|
|
140
|
+
functionsById[functionId] = { ...functionRecord };
|
|
141
|
+
}
|
|
142
|
+
for (const agentData of Object.values(project.agents ?? {})) {
|
|
143
|
+
const agentFunctions = asRecord(asRecord(agentData)?.functions);
|
|
144
|
+
if (!agentFunctions) continue;
|
|
145
|
+
for (const [functionId, functionData] of Object.entries(agentFunctions)) {
|
|
146
|
+
const functionRecord = asRecord(functionData);
|
|
147
|
+
if (!functionRecord) continue;
|
|
148
|
+
const existingFunction = functionsById[functionId] ?? {};
|
|
149
|
+
functionsById[functionId] = {
|
|
150
|
+
...functionRecord,
|
|
151
|
+
...existingFunction
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return functionsById;
|
|
156
|
+
}
|
|
157
|
+
function buildToolReferenceNamesById(project) {
|
|
158
|
+
const toolReferenceNamesById = {};
|
|
159
|
+
for (const [toolId, toolData] of Object.entries(project.tools ?? {})) {
|
|
160
|
+
const toolName = asRecord(toolData)?.name;
|
|
161
|
+
toolReferenceNamesById[toolId] = typeof toolName === "string" && toolName.length > 0 ? toToolReferenceName(toolName) : toToolReferenceName(toolId);
|
|
162
|
+
}
|
|
163
|
+
for (const functionToolEntry of collectFunctionToolEntries(project)) toolReferenceNamesById[functionToolEntry.functionToolId] = toToolReferenceName(functionToolEntry.exportName);
|
|
164
|
+
return toolReferenceNamesById;
|
|
165
|
+
}
|
|
166
|
+
function buildToolReferencePathById(project) {
|
|
167
|
+
const toolEntries = Object.entries(project.tools ?? {});
|
|
168
|
+
const toolFileNamesById = buildSequentialNameFileNames(toolEntries);
|
|
169
|
+
const toolReferencePathById = {};
|
|
170
|
+
for (const [toolId] of toolEntries) toolReferencePathById[toolId] = stripExtension(toolFileNamesById[toolId]);
|
|
171
|
+
const functionToolEntries = collectFunctionToolEntries(project);
|
|
172
|
+
const functionToolFileNamesById = buildSequentialNameFileNames(functionToolEntries.map(({ functionToolId, fileName }) => [functionToolId, { name: fileName }]));
|
|
173
|
+
for (const { functionToolId } of functionToolEntries) toolReferencePathById[functionToolId] = stripExtension(functionToolFileNamesById[functionToolId]);
|
|
174
|
+
return toolReferencePathById;
|
|
175
|
+
}
|
|
176
|
+
function buildCredentialReferenceNamesById(project) {
|
|
177
|
+
const credentialReferenceNamesById = {};
|
|
178
|
+
const countsByReferenceName = /* @__PURE__ */ new Map();
|
|
179
|
+
for (const [credentialId, credentialData] of Object.entries(project.credentialReferences ?? {})) {
|
|
180
|
+
const credentialName = asRecord(credentialData)?.name;
|
|
181
|
+
const baseReferenceName = typeof credentialName === "string" && credentialName.length > 0 ? toCredentialReferenceName(credentialName) : toCredentialReferenceName(credentialId);
|
|
182
|
+
const occurrence = countsByReferenceName.get(baseReferenceName) ?? 0;
|
|
183
|
+
countsByReferenceName.set(baseReferenceName, occurrence + 1);
|
|
184
|
+
credentialReferenceNamesById[credentialId] = occurrence === 0 ? baseReferenceName : `${baseReferenceName}${occurrence}`;
|
|
185
|
+
}
|
|
186
|
+
return credentialReferenceNamesById;
|
|
187
|
+
}
|
|
188
|
+
function buildCredentialReferencePathById(project) {
|
|
189
|
+
const credentialEntries = Object.entries(project.credentialReferences ?? {});
|
|
190
|
+
const credentialFileNamesById = buildSequentialNameFileNames(credentialEntries);
|
|
191
|
+
const credentialReferencePathById = {};
|
|
192
|
+
for (const [credentialId] of credentialEntries) credentialReferencePathById[credentialId] = stripExtension(credentialFileNamesById[credentialId]);
|
|
193
|
+
return credentialReferencePathById;
|
|
194
|
+
}
|
|
195
|
+
function buildExternalAgentReferenceNamesById(project) {
|
|
196
|
+
const externalAgentReferenceNamesById = {};
|
|
197
|
+
const countsByReferenceName = /* @__PURE__ */ new Map();
|
|
198
|
+
for (const [externalAgentId, externalAgentData] of Object.entries(project.externalAgents ?? {})) {
|
|
199
|
+
const baseReferenceName = toExternalAgentReferenceName(resolveExternalAgentNamingSeed(externalAgentId, externalAgentData));
|
|
200
|
+
const occurrence = countsByReferenceName.get(baseReferenceName) ?? 0;
|
|
201
|
+
countsByReferenceName.set(baseReferenceName, occurrence + 1);
|
|
202
|
+
externalAgentReferenceNamesById[externalAgentId] = occurrence === 0 ? baseReferenceName : `${baseReferenceName}${occurrence}`;
|
|
203
|
+
}
|
|
204
|
+
return externalAgentReferenceNamesById;
|
|
205
|
+
}
|
|
206
|
+
function buildExternalAgentReferencePathById(project) {
|
|
207
|
+
const externalAgentEntries = Object.entries(project.externalAgents ?? {}).map(([externalAgentId, externalAgentData]) => [externalAgentId, { name: resolveExternalAgentNamingSeed(externalAgentId, externalAgentData) }]);
|
|
208
|
+
const externalAgentFileNamesById = buildSequentialNameFileNames(externalAgentEntries);
|
|
209
|
+
const externalAgentReferencePathById = {};
|
|
210
|
+
for (const [externalAgentId] of externalAgentEntries) externalAgentReferencePathById[externalAgentId] = stripExtension(externalAgentFileNamesById[externalAgentId]);
|
|
211
|
+
return externalAgentReferencePathById;
|
|
212
|
+
}
|
|
213
|
+
function buildSubAgentReferenceNamesById(project, agentIds) {
|
|
214
|
+
const subAgentReferenceNamesById = {};
|
|
215
|
+
const candidateAgentIds = agentIds !== void 0 ? [...agentIds] : Object.keys(project.agents ?? {});
|
|
216
|
+
for (const agentId of candidateAgentIds) {
|
|
217
|
+
const agentData = project.agents?.[agentId];
|
|
218
|
+
const subAgents = asRecord(agentData?.subAgents);
|
|
219
|
+
if (!subAgents) continue;
|
|
220
|
+
for (const [subAgentId, subAgentData] of Object.entries(subAgents)) {
|
|
221
|
+
const subAgentName = asRecord(subAgentData)?.name;
|
|
222
|
+
subAgentReferenceNamesById[subAgentId] = resolveSubAgentVariableName(subAgentId, typeof subAgentName === "string" ? subAgentName : void 0);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
return subAgentReferenceNamesById;
|
|
226
|
+
}
|
|
227
|
+
function buildSubAgentReferencePathById(project, agentIds) {
|
|
228
|
+
const subAgentReferencePathById = {};
|
|
229
|
+
const candidateAgentIds = agentIds !== void 0 ? [...agentIds] : Object.keys(project.agents ?? {});
|
|
230
|
+
for (const agentId of candidateAgentIds) {
|
|
231
|
+
const agentData = project.agents?.[agentId];
|
|
232
|
+
const subAgents = asRecord(agentData?.subAgents);
|
|
233
|
+
if (!subAgents) continue;
|
|
234
|
+
for (const [subAgentId, subAgentData] of Object.entries(subAgents)) {
|
|
235
|
+
const subAgentName = asRecord(subAgentData)?.name;
|
|
236
|
+
subAgentReferencePathById[subAgentId] = stripExtension(buildComponentFileName(subAgentId, typeof subAgentName === "string" ? subAgentName : void 0));
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
return subAgentReferencePathById;
|
|
240
|
+
}
|
|
241
|
+
function buildAgentReferenceNamesById(project) {
|
|
242
|
+
const agentReferenceNamesById = {};
|
|
243
|
+
for (const agentId of Object.keys(project.agents ?? {})) agentReferenceNamesById[agentId] = toCamelCase(agentId);
|
|
244
|
+
return agentReferenceNamesById;
|
|
245
|
+
}
|
|
246
|
+
function buildAgentReferencePathById(project) {
|
|
247
|
+
const agentReferencePathById = {};
|
|
248
|
+
for (const [agentId, agentData] of Object.entries(project.agents ?? {})) {
|
|
249
|
+
const agentName = asRecord(agentData)?.name;
|
|
250
|
+
agentReferencePathById[agentId] = stripExtension(buildComponentFileName(agentId, typeof agentName === "string" ? agentName : void 0));
|
|
251
|
+
}
|
|
252
|
+
return agentReferencePathById;
|
|
253
|
+
}
|
|
254
|
+
function toExternalAgentReferenceName(input) {
|
|
255
|
+
const base = toCamelCase(input);
|
|
256
|
+
return base.endsWith("Agent") ? base : `${base}Agent`;
|
|
257
|
+
}
|
|
258
|
+
function resolveExternalAgentNamingSeed(externalAgentId, externalAgentData) {
|
|
259
|
+
if (isHumanReadableId(externalAgentId)) return externalAgentId;
|
|
260
|
+
const externalAgentName = asRecord(externalAgentData)?.name;
|
|
261
|
+
if (typeof externalAgentName === "string" && externalAgentName.length > 0) return externalAgentName;
|
|
262
|
+
return externalAgentId;
|
|
263
|
+
}
|
|
264
|
+
function resolveToolModulePath(filePath) {
|
|
265
|
+
const normalizedFilePath = normalizeFilePath(filePath);
|
|
266
|
+
const toolsIndex = normalizedFilePath.lastIndexOf("/tools/");
|
|
267
|
+
if (toolsIndex >= 0) {
|
|
268
|
+
let modulePath = stripExtension(normalizedFilePath.slice(toolsIndex + 7));
|
|
269
|
+
if (modulePath.endsWith("/index")) modulePath = modulePath.slice(0, -6);
|
|
270
|
+
if (modulePath.length > 0) return modulePath;
|
|
271
|
+
}
|
|
272
|
+
const baseModulePath = stripExtension(basename(normalizedFilePath));
|
|
273
|
+
if (baseModulePath === "index") return stripExtension(basename(dirname(normalizedFilePath)));
|
|
274
|
+
return baseModulePath;
|
|
275
|
+
}
|
|
276
|
+
function resolveProjectFilePath(projectRoot, filePath) {
|
|
277
|
+
if (filePath.startsWith("/")) return filePath;
|
|
278
|
+
return join(projectRoot, filePath);
|
|
279
|
+
}
|
|
280
|
+
function normalizeFilePath(filePath) {
|
|
281
|
+
return filePath.replaceAll("\\", "/");
|
|
282
|
+
}
|
|
283
|
+
function buildSequentialNameFileNames(entries) {
|
|
284
|
+
const countsByStem = /* @__PURE__ */ new Map();
|
|
285
|
+
const fileNamesById = {};
|
|
286
|
+
for (const [componentId, componentData] of entries) {
|
|
287
|
+
const name = asRecord(componentData)?.name;
|
|
288
|
+
const baseStem = resolveNameFileStem(componentId, typeof name === "string" ? name : void 0);
|
|
289
|
+
const occurrence = countsByStem.get(baseStem) ?? 0;
|
|
290
|
+
countsByStem.set(baseStem, occurrence + 1);
|
|
291
|
+
fileNamesById[componentId] = `${occurrence === 0 ? baseStem : `${baseStem}-${occurrence}`}.ts`;
|
|
292
|
+
}
|
|
293
|
+
return fileNamesById;
|
|
294
|
+
}
|
|
295
|
+
function resolveNameFileStem(componentId, name) {
|
|
296
|
+
const nameStem = name ? toKebabCase(name) : "";
|
|
297
|
+
if (nameStem.length > 0) return nameStem;
|
|
298
|
+
const idStem = toKebabCase(componentId);
|
|
299
|
+
if (idStem.length > 0) return idStem;
|
|
300
|
+
return componentId;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
//#endregion
|
|
304
|
+
export { GenerationResolver, buildSequentialNameFileNames, collectFunctionToolEntries, normalizeFilePath, resolveExternalAgentNamingSeed, resolveProjectFilePath, resolveToolModulePath };
|
|
305
|
+
//# sourceMappingURL=generation-resolver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generation-resolver.js","names":[],"sources":["../../../src/commands/pull-v4/generation-resolver.ts"],"sourcesContent":["import { basename, dirname, join } from 'node:path';\nimport type { FullProjectDefinition } from '@inkeep/agents-core';\nimport { asRecord, stripExtension } from './collector-common';\nimport type { ComponentInfo, ComponentRegistry, ComponentType } from './component-registry';\nimport { resolveSubAgentVariableName } from './generators/helpers/sub-agent';\nimport {\n buildComponentFileName,\n isHumanReadableId,\n toCamelCase,\n toCredentialReferenceName,\n toKebabCase,\n toToolReferenceName,\n} from './utils';\n\ninterface GenerationResolverOptions {\n project: FullProjectDefinition;\n projectRoot: string;\n completeAgentIds: Iterable<string>;\n existingComponentRegistry?: ComponentRegistry;\n}\n\nexport interface FunctionToolEntry {\n functionToolId: string;\n functionId: string;\n functionToolData: Record<string, unknown>;\n functionData: Record<string, unknown>;\n exportName: string;\n fileName: string;\n}\n\nexport class GenerationResolver {\n private readonly projectRoot: string;\n private readonly existingComponentRegistry?: ComponentRegistry;\n private readonly toolReferenceNamesById: Record<string, string>;\n private readonly toolReferencePathsById: Record<string, string>;\n private readonly credentialReferenceNamesById: Record<string, string>;\n private readonly credentialReferencePathsById: Record<string, string>;\n private readonly externalAgentReferenceNamesById: Record<string, string>;\n private readonly externalAgentReferencePathsById: Record<string, string>;\n private readonly subAgentReferenceNamesById: Record<string, string>;\n private readonly subAgentReferencePathsById: Record<string, string>;\n private readonly agentReferenceNamesById: Record<string, string>;\n private readonly agentReferencePathsById: Record<string, string>;\n\n constructor({\n project,\n projectRoot,\n completeAgentIds,\n existingComponentRegistry,\n }: GenerationResolverOptions) {\n this.projectRoot = projectRoot;\n this.existingComponentRegistry = existingComponentRegistry;\n this.toolReferenceNamesById = buildToolReferenceNamesById(project);\n this.toolReferencePathsById = buildToolReferencePathById(project);\n this.credentialReferenceNamesById = buildCredentialReferenceNamesById(project);\n this.credentialReferencePathsById = buildCredentialReferencePathById(project);\n this.externalAgentReferenceNamesById = buildExternalAgentReferenceNamesById(project);\n this.externalAgentReferencePathsById = buildExternalAgentReferencePathById(project);\n this.subAgentReferenceNamesById = buildSubAgentReferenceNamesById(project, completeAgentIds);\n this.subAgentReferencePathsById = buildSubAgentReferencePathById(project, completeAgentIds);\n this.agentReferenceNamesById = buildAgentReferenceNamesById(project);\n this.agentReferencePathsById = buildAgentReferencePathById(project);\n }\n\n getExistingComponent(id: string, type: ComponentType): ComponentInfo | undefined {\n return this.existingComponentRegistry?.get(id, type);\n }\n\n resolveOutputFilePath(\n componentType: ComponentType,\n componentId: string,\n fallbackFilePath: string\n ): string {\n const existingComponent = this.getExistingComponent(componentId, componentType);\n if (!existingComponent?.filePath) {\n return fallbackFilePath;\n }\n\n return resolveProjectFilePath(this.projectRoot, existingComponent.filePath);\n }\n\n getToolReferenceName(toolId: string): string | undefined {\n return this.getPreferredReferenceName(\n toolId,\n ['functionTools', 'tools'],\n this.toolReferenceNamesById\n );\n }\n\n getToolReferencePath(toolId: string): string | undefined {\n const existingTool =\n this.getExistingComponent(toolId, 'functionTools') ??\n this.getExistingComponent(toolId, 'tools');\n if (existingTool?.filePath) {\n return resolveToolModulePath(existingTool.filePath);\n }\n\n return this.toolReferencePathsById[toolId];\n }\n\n getCredentialReferenceName(credentialId: string): string | undefined {\n return this.getPreferredReferenceName(\n credentialId,\n ['credentials'],\n this.credentialReferenceNamesById\n );\n }\n\n getCredentialReferencePath(credentialId: string): string | undefined {\n return this.getPreferredReferencePath(\n credentialId,\n ['credentials'],\n this.credentialReferencePathsById\n );\n }\n\n getExternalAgentReferenceName(externalAgentId: string): string | undefined {\n return this.getPreferredReferenceName(\n externalAgentId,\n ['externalAgents'],\n this.externalAgentReferenceNamesById\n );\n }\n\n getExternalAgentReferencePath(externalAgentId: string): string | undefined {\n return this.getPreferredReferencePath(\n externalAgentId,\n ['externalAgents'],\n this.externalAgentReferencePathsById\n );\n }\n\n getSubAgentReferenceName(subAgentId: string): string | undefined {\n return this.getPreferredReferenceName(\n subAgentId,\n ['subAgents'],\n this.subAgentReferenceNamesById\n );\n }\n\n getSubAgentReferencePath(subAgentId: string): string | undefined {\n return this.getPreferredReferencePath(\n subAgentId,\n ['subAgents'],\n this.subAgentReferencePathsById\n );\n }\n\n getAgentReferenceName(agentId: string): string | undefined {\n return this.getPreferredReferenceName(agentId, ['agents'], this.agentReferenceNamesById);\n }\n\n getAgentReferencePath(agentId: string): string | undefined {\n return this.getPreferredReferencePath(agentId, ['agents'], this.agentReferencePathsById);\n }\n\n private getPreferredReferenceName(\n componentId: string,\n componentTypes: ComponentType[],\n generatedNamesById: Record<string, string>\n ): string | undefined {\n const existingComponent = this.getExistingComponentByTypes(componentId, componentTypes);\n if (existingComponent?.name) {\n return existingComponent.name;\n }\n\n return generatedNamesById[componentId];\n }\n\n private getPreferredReferencePath(\n componentId: string,\n componentTypes: ComponentType[],\n generatedPathsById: Record<string, string>\n ): string | undefined {\n const existingComponent = this.getExistingComponentByTypes(componentId, componentTypes);\n if (existingComponent?.filePath) {\n return stripExtension(basename(existingComponent.filePath));\n }\n\n return generatedPathsById[componentId];\n }\n\n private getExistingComponentByTypes(\n componentId: string,\n componentTypes: ComponentType[]\n ): ComponentInfo | undefined {\n for (const componentType of componentTypes) {\n const component = this.getExistingComponent(componentId, componentType);\n if (component) {\n return component;\n }\n }\n\n return;\n }\n}\n\nexport function collectFunctionToolEntries(project: FullProjectDefinition): FunctionToolEntry[] {\n const functionToolsById = collectFunctionToolsById(project);\n const functionsById = collectFunctionsById(project);\n const entries: FunctionToolEntry[] = [];\n\n for (const [functionToolId, functionToolData] of Object.entries(functionToolsById)) {\n const functionId =\n typeof functionToolData.functionId === 'string' && functionToolData.functionId.length > 0\n ? functionToolData.functionId\n : functionToolId;\n const functionData = functionsById[functionId] ?? {};\n const functionToolName =\n typeof functionToolData.name === 'string' && functionToolData.name.length > 0\n ? functionToolData.name\n : undefined;\n const functionName =\n typeof functionData.name === 'string' && functionData.name.length > 0\n ? functionData.name\n : undefined;\n const fallbackName = functionToolName ?? functionName ?? functionToolId;\n\n entries.push({\n functionToolId,\n functionId,\n functionToolData,\n functionData,\n exportName: fallbackName,\n fileName: fallbackName,\n });\n }\n\n return entries;\n}\n\nfunction collectFunctionToolsById(\n project: FullProjectDefinition\n): Record<string, Record<string, unknown>> {\n const functionToolsById: Record<string, Record<string, unknown>> = {};\n\n for (const [functionToolId, functionToolData] of Object.entries(project.functionTools ?? {})) {\n const functionToolRecord = asRecord(functionToolData);\n if (!functionToolRecord) {\n continue;\n }\n\n functionToolsById[functionToolId] = {\n ...functionToolRecord,\n };\n }\n\n for (const agentData of Object.values(project.agents ?? {})) {\n const agentRecord = asRecord(agentData);\n const agentFunctionTools = asRecord(agentRecord?.functionTools);\n if (!agentFunctionTools) {\n continue;\n }\n\n for (const [functionToolId, functionToolData] of Object.entries(agentFunctionTools)) {\n const functionToolRecord = asRecord(functionToolData);\n if (!functionToolRecord) {\n continue;\n }\n\n const existingFunctionTool = functionToolsById[functionToolId] ?? {};\n functionToolsById[functionToolId] = {\n ...functionToolRecord,\n ...existingFunctionTool,\n };\n }\n }\n\n return functionToolsById;\n}\n\nfunction collectFunctionsById(\n project: FullProjectDefinition\n): Record<string, Record<string, unknown>> {\n const functionsById: Record<string, Record<string, unknown>> = {};\n\n for (const [functionId, functionData] of Object.entries(project.functions ?? {})) {\n const functionRecord = asRecord(functionData);\n if (!functionRecord) {\n continue;\n }\n\n functionsById[functionId] = {\n ...functionRecord,\n };\n }\n\n for (const agentData of Object.values(project.agents ?? {})) {\n const agentRecord = asRecord(agentData);\n const agentFunctions = asRecord(agentRecord?.functions);\n if (!agentFunctions) {\n continue;\n }\n\n for (const [functionId, functionData] of Object.entries(agentFunctions)) {\n const functionRecord = asRecord(functionData);\n if (!functionRecord) {\n continue;\n }\n\n const existingFunction = functionsById[functionId] ?? {};\n functionsById[functionId] = {\n ...functionRecord,\n ...existingFunction,\n };\n }\n }\n\n return functionsById;\n}\n\nfunction buildToolReferenceNamesById(project: FullProjectDefinition): Record<string, string> {\n const toolReferenceNamesById: Record<string, string> = {};\n\n for (const [toolId, toolData] of Object.entries(project.tools ?? {})) {\n const toolName = asRecord(toolData)?.name;\n const referenceName =\n typeof toolName === 'string' && toolName.length > 0\n ? toToolReferenceName(toolName)\n : toToolReferenceName(toolId);\n toolReferenceNamesById[toolId] = referenceName;\n }\n\n for (const functionToolEntry of collectFunctionToolEntries(project)) {\n toolReferenceNamesById[functionToolEntry.functionToolId] = toToolReferenceName(\n functionToolEntry.exportName\n );\n }\n\n return toolReferenceNamesById;\n}\n\nfunction buildToolReferencePathById(project: FullProjectDefinition): Record<string, string> {\n const toolEntries = Object.entries(project.tools ?? {});\n const toolFileNamesById = buildSequentialNameFileNames(toolEntries);\n const toolReferencePathById: Record<string, string> = {};\n\n for (const [toolId] of toolEntries) {\n toolReferencePathById[toolId] = stripExtension(toolFileNamesById[toolId]);\n }\n\n const functionToolEntries = collectFunctionToolEntries(project);\n const functionToolFileNamesById = buildSequentialNameFileNames(\n functionToolEntries.map(({ functionToolId, fileName }) => [functionToolId, { name: fileName }])\n );\n for (const { functionToolId } of functionToolEntries) {\n toolReferencePathById[functionToolId] = stripExtension(\n functionToolFileNamesById[functionToolId]\n );\n }\n\n return toolReferencePathById;\n}\n\nfunction buildCredentialReferenceNamesById(project: FullProjectDefinition): Record<string, string> {\n const credentialReferenceNamesById: Record<string, string> = {};\n const countsByReferenceName = new Map<string, number>();\n\n for (const [credentialId, credentialData] of Object.entries(project.credentialReferences ?? {})) {\n const credentialName = asRecord(credentialData)?.name;\n const baseReferenceName =\n typeof credentialName === 'string' && credentialName.length > 0\n ? toCredentialReferenceName(credentialName)\n : toCredentialReferenceName(credentialId);\n const occurrence = countsByReferenceName.get(baseReferenceName) ?? 0;\n countsByReferenceName.set(baseReferenceName, occurrence + 1);\n credentialReferenceNamesById[credentialId] =\n occurrence === 0 ? baseReferenceName : `${baseReferenceName}${occurrence}`;\n }\n\n return credentialReferenceNamesById;\n}\n\nfunction buildCredentialReferencePathById(project: FullProjectDefinition): Record<string, string> {\n const credentialEntries = Object.entries(project.credentialReferences ?? {});\n const credentialFileNamesById = buildSequentialNameFileNames(credentialEntries);\n const credentialReferencePathById: Record<string, string> = {};\n\n for (const [credentialId] of credentialEntries) {\n credentialReferencePathById[credentialId] = stripExtension(\n credentialFileNamesById[credentialId]\n );\n }\n\n return credentialReferencePathById;\n}\n\nfunction buildExternalAgentReferenceNamesById(\n project: FullProjectDefinition\n): Record<string, string> {\n const externalAgentReferenceNamesById: Record<string, string> = {};\n const countsByReferenceName = new Map<string, number>();\n\n for (const [externalAgentId, externalAgentData] of Object.entries(project.externalAgents ?? {})) {\n const baseReferenceName = toExternalAgentReferenceName(\n resolveExternalAgentNamingSeed(externalAgentId, externalAgentData)\n );\n const occurrence = countsByReferenceName.get(baseReferenceName) ?? 0;\n countsByReferenceName.set(baseReferenceName, occurrence + 1);\n externalAgentReferenceNamesById[externalAgentId] =\n occurrence === 0 ? baseReferenceName : `${baseReferenceName}${occurrence}`;\n }\n\n return externalAgentReferenceNamesById;\n}\n\nfunction buildExternalAgentReferencePathById(\n project: FullProjectDefinition\n): Record<string, string> {\n const externalAgentEntries = Object.entries(project.externalAgents ?? {}).map(\n ([externalAgentId, externalAgentData]) =>\n [\n externalAgentId,\n { name: resolveExternalAgentNamingSeed(externalAgentId, externalAgentData) },\n ] as [string, { name: string }]\n );\n const externalAgentFileNamesById = buildSequentialNameFileNames(externalAgentEntries);\n const externalAgentReferencePathById: Record<string, string> = {};\n\n for (const [externalAgentId] of externalAgentEntries) {\n externalAgentReferencePathById[externalAgentId] = stripExtension(\n externalAgentFileNamesById[externalAgentId]\n );\n }\n\n return externalAgentReferencePathById;\n}\n\nfunction buildSubAgentReferenceNamesById(\n project: FullProjectDefinition,\n agentIds?: Iterable<string>\n): Record<string, string> {\n const subAgentReferenceNamesById: Record<string, string> = {};\n const candidateAgentIds =\n agentIds !== undefined ? [...agentIds] : Object.keys(project.agents ?? {});\n for (const agentId of candidateAgentIds) {\n const agentData = project.agents?.[agentId];\n const subAgents = asRecord(agentData?.subAgents);\n if (!subAgents) {\n continue;\n }\n\n for (const [subAgentId, subAgentData] of Object.entries(subAgents)) {\n const subAgentName = asRecord(subAgentData)?.name;\n subAgentReferenceNamesById[subAgentId] = resolveSubAgentVariableName(\n subAgentId,\n typeof subAgentName === 'string' ? subAgentName : undefined\n );\n }\n }\n\n return subAgentReferenceNamesById;\n}\n\nfunction buildSubAgentReferencePathById(\n project: FullProjectDefinition,\n agentIds?: Iterable<string>\n): Record<string, string> {\n const subAgentReferencePathById: Record<string, string> = {};\n const candidateAgentIds =\n agentIds !== undefined ? [...agentIds] : Object.keys(project.agents ?? {});\n for (const agentId of candidateAgentIds) {\n const agentData = project.agents?.[agentId];\n const subAgents = asRecord(agentData?.subAgents);\n if (!subAgents) {\n continue;\n }\n\n for (const [subAgentId, subAgentData] of Object.entries(subAgents)) {\n const subAgentName = asRecord(subAgentData)?.name;\n subAgentReferencePathById[subAgentId] = stripExtension(\n buildComponentFileName(\n subAgentId,\n typeof subAgentName === 'string' ? subAgentName : undefined\n )\n );\n }\n }\n\n return subAgentReferencePathById;\n}\n\nfunction buildAgentReferenceNamesById(project: FullProjectDefinition): Record<string, string> {\n const agentReferenceNamesById: Record<string, string> = {};\n for (const agentId of Object.keys(project.agents ?? {})) {\n agentReferenceNamesById[agentId] = toCamelCase(agentId);\n }\n return agentReferenceNamesById;\n}\n\nfunction buildAgentReferencePathById(project: FullProjectDefinition): Record<string, string> {\n const agentReferencePathById: Record<string, string> = {};\n for (const [agentId, agentData] of Object.entries(project.agents ?? {})) {\n const agentName = asRecord(agentData)?.name;\n agentReferencePathById[agentId] = stripExtension(\n buildComponentFileName(agentId, typeof agentName === 'string' ? agentName : undefined)\n );\n }\n return agentReferencePathById;\n}\n\nfunction toExternalAgentReferenceName(input: string): string {\n const base = toCamelCase(input);\n return base.endsWith('Agent') ? base : `${base}Agent`;\n}\n\nexport function resolveExternalAgentNamingSeed(\n externalAgentId: string,\n externalAgentData: unknown\n): string {\n if (isHumanReadableId(externalAgentId)) {\n return externalAgentId;\n }\n\n const externalAgentName = asRecord(externalAgentData)?.name;\n if (typeof externalAgentName === 'string' && externalAgentName.length > 0) {\n return externalAgentName;\n }\n\n return externalAgentId;\n}\n\nexport function resolveToolModulePath(filePath: string): string {\n const normalizedFilePath = normalizeFilePath(filePath);\n const toolsSegment = '/tools/';\n const toolsIndex = normalizedFilePath.lastIndexOf(toolsSegment);\n if (toolsIndex >= 0) {\n let modulePath = stripExtension(normalizedFilePath.slice(toolsIndex + toolsSegment.length));\n if (modulePath.endsWith('/index')) {\n modulePath = modulePath.slice(0, -'/index'.length);\n }\n if (modulePath.length > 0) {\n return modulePath;\n }\n }\n\n const baseModulePath = stripExtension(basename(normalizedFilePath));\n if (baseModulePath === 'index') {\n return stripExtension(basename(dirname(normalizedFilePath)));\n }\n return baseModulePath;\n}\n\nexport function resolveProjectFilePath(projectRoot: string, filePath: string): string {\n if (filePath.startsWith('/')) {\n return filePath;\n }\n return join(projectRoot, filePath);\n}\n\nexport function normalizeFilePath(filePath: string): string {\n return filePath.replaceAll('\\\\', '/');\n}\n\nexport function buildSequentialNameFileNames(\n entries: Array<[string, unknown]>\n): Record<string, string> {\n const countsByStem = new Map<string, number>();\n const fileNamesById: Record<string, string> = {};\n\n for (const [componentId, componentData] of entries) {\n const name = asRecord(componentData)?.name;\n const baseStem = resolveNameFileStem(componentId, typeof name === 'string' ? name : undefined);\n const occurrence = countsByStem.get(baseStem) ?? 0;\n countsByStem.set(baseStem, occurrence + 1);\n\n const stem = occurrence === 0 ? baseStem : `${baseStem}-${occurrence}`;\n fileNamesById[componentId] = `${stem}.ts`;\n }\n\n return fileNamesById;\n}\n\nfunction resolveNameFileStem(componentId: string, name: string | undefined): string {\n const nameStem = name ? toKebabCase(name) : '';\n if (nameStem.length > 0) {\n return nameStem;\n }\n\n const idStem = toKebabCase(componentId);\n if (idStem.length > 0) {\n return idStem;\n }\n\n return componentId;\n}\n"],"mappings":";;;;;;;AA8BA,IAAa,qBAAb,MAAgC;CAC9B,AAAiB;CACjB,AAAiB;CACjB,AAAiB;CACjB,AAAiB;CACjB,AAAiB;CACjB,AAAiB;CACjB,AAAiB;CACjB,AAAiB;CACjB,AAAiB;CACjB,AAAiB;CACjB,AAAiB;CACjB,AAAiB;CAEjB,YAAY,EACV,SACA,aACA,kBACA,6BAC4B;AAC5B,OAAK,cAAc;AACnB,OAAK,4BAA4B;AACjC,OAAK,yBAAyB,4BAA4B,QAAQ;AAClE,OAAK,yBAAyB,2BAA2B,QAAQ;AACjE,OAAK,+BAA+B,kCAAkC,QAAQ;AAC9E,OAAK,+BAA+B,iCAAiC,QAAQ;AAC7E,OAAK,kCAAkC,qCAAqC,QAAQ;AACpF,OAAK,kCAAkC,oCAAoC,QAAQ;AACnF,OAAK,6BAA6B,gCAAgC,SAAS,iBAAiB;AAC5F,OAAK,6BAA6B,+BAA+B,SAAS,iBAAiB;AAC3F,OAAK,0BAA0B,6BAA6B,QAAQ;AACpE,OAAK,0BAA0B,4BAA4B,QAAQ;;CAGrE,qBAAqB,IAAY,MAAgD;AAC/E,SAAO,KAAK,2BAA2B,IAAI,IAAI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js";
|
|
2
|
+
|
|
3
|
+
//#region src/commands/pull-v4/generation-types.ts
|
|
4
|
+
function collectCompleteAgentIds(project, skippedAgents) {
|
|
5
|
+
const completeAgentIds = /* @__PURE__ */ new Set();
|
|
6
|
+
for (const [agentId, agentData] of Object.entries(project.agents ?? {})) {
|
|
7
|
+
const completeness = isAgentComplete(agentData);
|
|
8
|
+
if (!completeness.complete) {
|
|
9
|
+
skippedAgents.push({
|
|
10
|
+
id: agentId,
|
|
11
|
+
reason: completeness.reason ?? "incomplete"
|
|
12
|
+
});
|
|
13
|
+
continue;
|
|
14
|
+
}
|
|
15
|
+
completeAgentIds.add(agentId);
|
|
16
|
+
}
|
|
17
|
+
return completeAgentIds;
|
|
18
|
+
}
|
|
19
|
+
function isAgentComplete(agentData) {
|
|
20
|
+
const data = asRecord(agentData);
|
|
21
|
+
if (!data) return {
|
|
22
|
+
complete: false,
|
|
23
|
+
reason: "invalid agent object"
|
|
24
|
+
};
|
|
25
|
+
if (!data.name || typeof data.name !== "string") return {
|
|
26
|
+
complete: false,
|
|
27
|
+
reason: "missing name"
|
|
28
|
+
};
|
|
29
|
+
if (!data.defaultSubAgentId || typeof data.defaultSubAgentId !== "string") return {
|
|
30
|
+
complete: false,
|
|
31
|
+
reason: "missing defaultSubAgentId"
|
|
32
|
+
};
|
|
33
|
+
const subAgents = asRecord(data.subAgents);
|
|
34
|
+
if (!subAgents || !Object.keys(subAgents).length) return {
|
|
35
|
+
complete: false,
|
|
36
|
+
reason: "no sub-agents defined"
|
|
37
|
+
};
|
|
38
|
+
return { complete: true };
|
|
39
|
+
}
|
|
40
|
+
function validateProject(project) {
|
|
41
|
+
if (!project || typeof project !== "object") throw new Error("Project data is required");
|
|
42
|
+
if (!project.id) throw new Error("Project id is required");
|
|
43
|
+
if (!project.name) throw new Error("Project name is required");
|
|
44
|
+
}
|
|
45
|
+
function assignComponentReferenceOverrideForProject(registry, overrides, overrideType, componentId, componentType) {
|
|
46
|
+
const component = registry.get(componentId, componentType);
|
|
47
|
+
if (!component?.name) return false;
|
|
48
|
+
const overrideMap = overrides[overrideType] ?? {};
|
|
49
|
+
overrideMap[componentId] = component.name;
|
|
50
|
+
overrides[overrideType] = overrideMap;
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
//#endregion
|
|
55
|
+
export { assignComponentReferenceOverrideForProject, collectCompleteAgentIds, validateProject };
|
|
56
|
+
//# sourceMappingURL=generation-types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generation-types.js","names":[],"sources":["../../../src/commands/pull-v4/generation-types.ts"],"sourcesContent":["import type { FullProjectDefinition } from '@inkeep/agents-core';\nimport type { SourceFile } from 'ts-morph';\nimport { asRecord } from './collector-common';\nimport type { ComponentRegistry, ComponentType } from './component-registry';\nimport type { GenerationResolver } from './generation-resolver';\n\nexport interface ProjectPaths {\n projectRoot: string;\n agentsDir: string;\n toolsDir: string;\n dataComponentsDir: string;\n artifactComponentsDir: string;\n statusComponentsDir: string;\n environmentsDir: string;\n credentialsDir: string;\n contextConfigsDir: string;\n externalAgentsDir: string;\n}\n\nexport interface GenerationContext {\n project: FullProjectDefinition;\n paths: ProjectPaths;\n completeAgentIds: Set<string>;\n existingComponentRegistry?: ComponentRegistry;\n resolver: GenerationResolver;\n}\n\nexport interface GenerationRecord<TPayload> {\n id: string;\n filePath: string;\n payload: TPayload;\n}\n\nexport interface GenerationTask<TPayload> {\n type: string;\n collect: (context: GenerationContext) => GenerationRecord<TPayload>[];\n generate: (payload: TPayload) => SourceFile;\n}\n\nexport type SubAgentReferenceOverrideType =\n | 'tools'\n | 'subAgents'\n | 'agents'\n | 'externalAgents'\n | 'dataComponents'\n | 'artifactComponents';\n\nexport type SubAgentReferenceOverrides = Partial<\n Record<SubAgentReferenceOverrideType, Record<string, string>>\n>;\n\nexport type SubAgentReferencePathOverrides = Partial<\n Record<'tools' | 'subAgents' | 'agents' | 'externalAgents', Record<string, string>>\n>;\n\nexport interface SubAgentDependencyReferences {\n referenceOverrides?: SubAgentReferenceOverrides;\n referencePathOverrides?: SubAgentReferencePathOverrides;\n}\n\nexport type ProjectReferenceOverrideType =\n | 'agents'\n | 'tools'\n | 'externalAgents'\n | 'dataComponents'\n | 'artifactComponents'\n | 'credentialReferences';\n\nexport type ProjectReferenceOverrides = Partial<\n Record<ProjectReferenceOverrideType, Record<string, string>>\n>;\n\nexport type ProjectReferencePathOverrides = Partial<\n Record<ProjectReferenceOverrideType, Record<string, string>>\n>;\n\nexport interface TemplateReferenceOverride {\n name: string;\n local?: boolean;\n}\n\nexport interface ContextTemplateReferences {\n contextConfigId: string;\n contextConfigReference: TemplateReferenceOverride;\n contextConfigHeadersReference?: TemplateReferenceOverride;\n}\n\nexport interface SkippedAgent {\n id: string;\n reason: string;\n}\n\nexport function collectCompleteAgentIds(\n project: FullProjectDefinition,\n skippedAgents: SkippedAgent[]\n): Set<string> {\n const completeAgentIds = new Set<string>();\n for (const [agentId, agentData] of Object.entries(project.agents ?? {})) {\n const completeness = isAgentComplete(agentData);\n if (!completeness.complete) {\n skippedAgents.push({ id: agentId, reason: completeness.reason ?? 'incomplete' });\n continue;\n }\n completeAgentIds.add(agentId);\n }\n return completeAgentIds;\n}\n\nfunction isAgentComplete(\n agentData: unknown\n): { complete: true } | { complete: false; reason: string } {\n const data = asRecord(agentData);\n if (!data) {\n return { complete: false, reason: 'invalid agent object' };\n }\n if (!data.name || typeof data.name !== 'string') {\n return { complete: false, reason: 'missing name' };\n }\n if (!data.defaultSubAgentId || typeof data.defaultSubAgentId !== 'string') {\n return { complete: false, reason: 'missing defaultSubAgentId' };\n }\n const subAgents = asRecord(data.subAgents);\n if (!subAgents || !Object.keys(subAgents).length) {\n return { complete: false, reason: 'no sub-agents defined' };\n }\n return { complete: true };\n}\n\nexport function validateProject(project: FullProjectDefinition): void {\n if (!project || typeof project !== 'object') {\n throw new Error('Project data is required');\n }\n if (!project.id) {\n throw new Error('Project id is required');\n }\n if (!project.name) {\n throw new Error('Project name is required');\n }\n}\n\nexport function assignComponentReferenceOverrideForProject(\n registry: ComponentRegistry,\n overrides: ProjectReferenceOverrides,\n overrideType: ProjectReferenceOverrideType,\n componentId: string,\n componentType: ComponentType\n): boolean {\n const component = registry.get(componentId, componentType);\n if (!component?.name) {\n return false;\n }\n\n const overrideMap = overrides[overrideType] ?? {};\n overrideMap[componentId] = component.name;\n overrides[overrideType] = overrideMap;\n return true;\n}\n"],"mappings":";;;AA4FA,SAAgB,wBACd,SACA,eACa;CACb,MAAM,mCAAmB,IAAI,KAAa;AAC1C,MAAK,MAAM,CAAC,SAAS,cAAc,OAAO,QAAQ,QAAQ,UAAU,EAAE,CAAC,EAAE;EACvE,MAAM,eAAe,gBAAgB,UAAU;AAC/C,MAAI,CAAC,aAAa,UAAU;AAC1B,iBAAc,KAAK;IAAE,IAAI;IAAS,QAAQ,aAAa,UAAU;IAAc,CAAC;AAChF;;AAEF,mBAAiB,IAAI,QAAQ;;AAE/B,QAAO;;AAGT,SAAS,gBACP,WAC0D;CAC1D,MAAM,OAAO,SAAS,UAAU;AAChC,KAAI,CAAC,KACH,QAAO;EAAE,UAAU;EAAO,QAAQ;EAAwB;AAE5D,KAAI,CAAC,KAAK,QAAQ,OAAO,KAAK,SAAS,SACrC,QAAO;EAAE,UAAU;EAAO,QAAQ;EAAgB;AAEpD,KAAI,CAAC,KAAK,qBAAqB,OAAO,KAAK,sBAAsB,SAC/D,QAAO;EAAE,UAAU;EAAO,QAAQ;EAA6B;CAEjE,MAAM,YAAY,SAAS,KAAK,UAAU;AAC1C,KAAI,CAAC,aAAa,CAAC,OAAO,KAAK,UAAU,CAAC,OACxC,QAAO;EAAE,UAAU;EAAO,QAAQ;EAAyB;AAE7D,QAAO,EAAE,UAAU,MAAM;;AAG3B,SAAgB,gBAAgB,SAAsC;AACpE,KAAI,CAAC,WAAW,OAAO,YAAY,SACjC,OAAM,IAAI,MAAM,2BAA2B;AAE7C,KAAI,CAAC,QAAQ,GACX,OAAM,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