forked from aws/agentcore-cli
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathaction.ts
More file actions
93 lines (81 loc) · 2.84 KB
/
Copy pathaction.ts
File metadata and controls
93 lines (81 loc) · 2.84 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import {
CONFIG_DIR,
ConfigIO,
packCodeZipSync,
packRuntime,
resolveCodeLocation,
validateAgentExists,
} from '../../../lib';
import type { AgentCoreProjectSpec } from '../../../schema';
import { join, resolve } from 'path';
export interface PackageOptions {
directory?: string;
runtime?: string;
}
export interface PackageContext {
project: AgentCoreProjectSpec;
configBaseDir: string;
projectRoot?: string;
targetAgent?: string;
}
export async function loadPackageConfig(options: PackageOptions): Promise<PackageContext> {
const projectRoot = options.directory ? resolve(options.directory) : undefined;
const baseDir = projectRoot ? join(projectRoot, CONFIG_DIR) : undefined;
const configIO = new ConfigIO(baseDir ? { baseDir } : undefined);
return {
project: await configIO.readProjectSpec(),
configBaseDir: configIO.getPathResolver().getBaseDir(),
projectRoot,
targetAgent: options.runtime,
};
}
export interface PackageAgentResult {
agentName: string;
artifactPath: string;
sizeMb: string;
}
export interface PackageResult {
success: boolean;
results: PackageAgentResult[];
skipped: string[];
error?: string;
}
export async function handlePackage(context: PackageContext): Promise<PackageResult> {
const { project, configBaseDir, targetAgent } = context;
const results: PackageAgentResult[] = [];
const skipped: string[] = [];
// Validate --runtime flag if specified
if (targetAgent) {
validateAgentExists(project, targetAgent);
}
// Filter agents based on --runtime flag
const agentsToPackage = targetAgent ? project.runtimes.filter(a => a.name === targetAgent) : project.runtimes;
for (const agent of agentsToPackage) {
if (agent.build === 'CodeZip') {
// Existing CodeZip packaging
const codeLocation = resolveCodeLocation(agent.codeLocation, configBaseDir);
const { artifactPath, sizeBytes } = packCodeZipSync(agent, {
projectRoot: codeLocation,
agentName: agent.name,
artifactDir: configBaseDir,
});
const sizeMb = (sizeBytes / (1024 * 1024)).toFixed(2);
results.push({ agentName: agent.name, artifactPath, sizeMb });
} else if (agent.build === 'Container') {
// Container packaging via ContainerPackager
const result = await packRuntime(agent, {
agentName: agent.name,
artifactDir: configBaseDir,
});
if (!result.artifactPath) {
// No container runtime available — skipped local build validation
console.warn('No container runtime found. Skipping local build validation. Deploy will use CodeBuild.');
skipped.push(agent.name);
} else {
const sizeMb = (result.sizeBytes / (1024 * 1024)).toFixed(2);
results.push({ agentName: agent.name, artifactPath: result.artifactPath, sizeMb });
}
}
}
return { success: true, results, skipped };
}