agent-claw: automated task changes
This commit is contained in:
91
agentclaw/agentcore/cdk/bin/cdk.ts
Normal file
91
agentclaw/agentcore/cdk/bin/cdk.ts
Normal file
@@ -0,0 +1,91 @@
|
||||
#!/usr/bin/env node
|
||||
import { AgentCoreStack } from '../lib/cdk-stack';
|
||||
import { ConfigIO, type AwsDeploymentTarget } from '@aws/agentcore-cdk';
|
||||
import { App, type Environment } from 'aws-cdk-lib';
|
||||
import * as path from 'path';
|
||||
import * as fs from 'fs';
|
||||
|
||||
function toEnvironment(target: AwsDeploymentTarget): Environment {
|
||||
return {
|
||||
account: target.account,
|
||||
region: target.region,
|
||||
};
|
||||
}
|
||||
|
||||
function sanitize(name: string): string {
|
||||
return name.replace(/_/g, '-');
|
||||
}
|
||||
|
||||
function toStackName(projectName: string, targetName: string): string {
|
||||
return `AgentCore-${sanitize(projectName)}-${sanitize(targetName)}`;
|
||||
}
|
||||
|
||||
async function main() {
|
||||
// Config root is parent of cdk/ directory. The CLI sets process.cwd() to agentcore/cdk/.
|
||||
const configRoot = path.resolve(process.cwd(), '..');
|
||||
const configIO = new ConfigIO({ baseDir: configRoot });
|
||||
|
||||
const spec = await configIO.readProjectSpec();
|
||||
const targets = await configIO.readAWSDeploymentTargets();
|
||||
|
||||
// Extract MCP configuration from project spec.
|
||||
// Gateway fields are stored in agentcore.json but may not yet be on the
|
||||
// AgentCoreProjectSpec type from @aws/agentcore-cdk, so we read them
|
||||
// dynamically and cast the resulting object.
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const specAny = spec as any;
|
||||
const mcpSpec = specAny.agentCoreGateways?.length
|
||||
? {
|
||||
agentCoreGateways: specAny.agentCoreGateways,
|
||||
mcpRuntimeTools: specAny.mcpRuntimeTools,
|
||||
unassignedTargets: specAny.unassignedTargets,
|
||||
}
|
||||
: undefined;
|
||||
|
||||
// Read deployed state for credential ARNs (populated by pre-deploy identity setup)
|
||||
let deployedState: Record<string, unknown> | undefined;
|
||||
try {
|
||||
deployedState = JSON.parse(fs.readFileSync(path.join(configRoot, '.cli', 'deployed-state.json'), 'utf8'));
|
||||
} catch {
|
||||
// Deployed state may not exist on first deploy
|
||||
}
|
||||
|
||||
if (targets.length === 0) {
|
||||
throw new Error('No deployment targets configured. Please define targets in agentcore/aws-targets.json');
|
||||
}
|
||||
|
||||
const app = new App();
|
||||
|
||||
for (const target of targets) {
|
||||
const env = toEnvironment(target);
|
||||
const stackName = toStackName(spec.name, target.name);
|
||||
|
||||
// Extract credentials from deployed state for this target
|
||||
const targetState = (deployedState as Record<string, unknown>)?.targets as
|
||||
| Record<string, Record<string, unknown>>
|
||||
| undefined;
|
||||
const targetResources = targetState?.[target.name]?.resources as Record<string, unknown> | undefined;
|
||||
const credentials = targetResources?.credentials as
|
||||
| Record<string, { credentialProviderArn: string; clientSecretArn?: string }>
|
||||
| undefined;
|
||||
|
||||
new AgentCoreStack(app, stackName, {
|
||||
spec,
|
||||
mcpSpec,
|
||||
credentials,
|
||||
env,
|
||||
description: `AgentCore stack for ${spec.name} deployed to ${target.name} (${target.region})`,
|
||||
tags: {
|
||||
'agentcore:project-name': spec.name,
|
||||
'agentcore:target-name': target.name,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
app.synth();
|
||||
}
|
||||
|
||||
main().catch((error: unknown) => {
|
||||
console.error('AgentCore CDK synthesis failed:', error instanceof Error ? error.message : error);
|
||||
process.exitCode = 1;
|
||||
});
|
||||
Reference in New Issue
Block a user