forked from aws/agentcore-cli
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBaseRenderer.ts
More file actions
79 lines (67 loc) · 2.76 KB
/
Copy pathBaseRenderer.ts
File metadata and controls
79 lines (67 loc) · 2.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import { APP_DIR } from '../../lib';
import { copyAndRenderDir } from './render';
import type { AgentRenderConfig } from './types';
import { existsSync } from 'node:fs';
import * as path from 'node:path';
export interface RendererContext {
outputDir: string;
}
type TemplateData = AgentRenderConfig &
RendererContext & {
projectName: string;
Name: string;
hasMcp: boolean;
};
export abstract class BaseRenderer {
protected readonly config: AgentRenderConfig;
protected readonly sdkName: string;
protected readonly baseTemplateDir: string;
protected readonly protocolMode: string;
protected constructor(config: AgentRenderConfig, sdkName: string, baseTemplateDir: string, protocolMode?: string) {
this.config = config;
this.sdkName = sdkName;
this.baseTemplateDir = baseTemplateDir;
this.protocolMode = (protocolMode ?? config.protocol ?? 'HTTP').toLowerCase();
}
protected shouldRenderMemory(): boolean {
return this.config.hasMemory;
}
protected getTemplateDir(): string {
const language = this.config.targetLanguage.toLowerCase();
return path.join(this.baseTemplateDir, language, this.protocolMode, this.sdkName);
}
async render(context: RendererContext): Promise<void> {
const templateDir = this.getTemplateDir();
const projectName = this.config.name;
// Agents are placed in app/<agentName>/ directory
const projectDir = path.join(context.outputDir, APP_DIR, projectName);
const templateData: TemplateData = {
...this.config,
...context,
projectName,
Name: projectName,
hasMcp: false, // MCP is configured separately
};
// Always render base template
const baseDir = path.join(templateDir, 'base');
await copyAndRenderDir(baseDir, projectDir, templateData);
// Render capability templates based on config
// Only render if the capability directory exists (not all SDKs have all capabilities)
if (this.shouldRenderMemory()) {
const memoryCapabilityDir = path.join(templateDir, 'capabilities', 'memory');
if (existsSync(memoryCapabilityDir)) {
const memoryTargetDir = path.join(projectDir, 'memory');
await copyAndRenderDir(memoryCapabilityDir, memoryTargetDir, templateData);
}
}
// Generate Dockerfile and .dockerignore for Container builds
if (this.config.buildType === 'Container') {
const language = this.config.targetLanguage.toLowerCase();
const containerTemplateDir = path.join(this.baseTemplateDir, 'container', language);
if (existsSync(containerTemplateDir)) {
const exclude = this.config.dockerfile ? new Set(['Dockerfile']) : undefined;
await copyAndRenderDir(containerTemplateDir, projectDir, { ...templateData, entrypoint: 'main' }, { exclude });
}
}
}
}