Skip to content

Commit a44c03f

Browse files
author
Yuriy Bezsonov
committed
feat(java-on-aws-aiagent): enhance clipboard copy and bedrock agent support
1 parent f9af670 commit a44c03f

4 files changed

Lines changed: 61 additions & 27 deletions

File tree

apps/aiagent/src/main/resources/static/chat.js

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -169,15 +169,36 @@ function escapeHtml(unsafe) {
169169

170170
function copyMessageContent(button) {
171171
const text = button.getAttribute('data-copy-text');
172-
navigator.clipboard.writeText(text).then(() => {
173-
const originalText = button.innerHTML;
174-
button.innerHTML = '✓ Copied';
175-
button.classList.add('copied');
176-
setTimeout(() => {
177-
button.innerHTML = originalText;
178-
button.classList.remove('copied');
179-
}, 2000);
180-
}).catch(() => {});
172+
173+
if (navigator.clipboard && window.isSecureContext) {
174+
navigator.clipboard.writeText(text).then(() => {
175+
showCopySuccess(button);
176+
}).catch(() => fallbackCopy(text, button));
177+
} else {
178+
fallbackCopy(text, button);
179+
}
180+
}
181+
182+
function fallbackCopy(text, button) {
183+
const textarea = document.createElement('textarea');
184+
textarea.value = text;
185+
textarea.style.position = 'fixed';
186+
textarea.style.opacity = '0';
187+
document.body.appendChild(textarea);
188+
textarea.select();
189+
document.execCommand('copy');
190+
document.body.removeChild(textarea);
191+
showCopySuccess(button);
192+
}
193+
194+
function showCopySuccess(button) {
195+
const originalText = button.innerHTML;
196+
button.innerHTML = '✓ Copied';
197+
button.classList.add('copied');
198+
setTimeout(() => {
199+
button.innerHTML = originalText;
200+
button.classList.remove('copied');
201+
}, 2000);
181202
}
182203

183204
async function sendMessage(message, config, auth) {
@@ -300,11 +321,11 @@ async function processStreamingResponse(response, loadingId = null) {
300321
}
301322

302323
const chunk = decoder.decode(value, { stream: true });
303-
324+
304325
if (isSSE === null) {
305326
isSSE = chunk.trimStart().startsWith('data:');
306327
}
307-
328+
308329
if (isSSE) {
309330
buffer += chunk;
310331
const lines = buffer.split('\n');

infra/cdk/src/main/java/sample/com/WorkshopStack.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ public class WorkshopStack extends Stack {
3030
# Resolution for when creating the first service in the account
3131
aws iam create-service-linked-role --aws-service-name ecs.amazonaws.com 2>/dev/null || true
3232
aws iam create-service-linked-role --aws-service-name elasticloadbalancing.amazonaws.com 2>/dev/null || true
33+
aws iam create-service-linked-role --aws-service-name network.bedrock-agentcore.amazonaws.com 2>/dev/null || true
34+
aws iam create-service-linked-role --aws-service-name runtime-identity.bedrock-agentcore.amazonaws.com 2>/dev/null || true
3335
""";
3436

3537
public WorkshopStack(final Construct scope, final String id, final StackProps props) {
@@ -257,12 +259,10 @@ public WorkshopStack(final Construct scope, final String id, final StackProps pr
257259
CMD ["nginx", "-g", "daemon off;"]
258260
EOF
259261
260-
# Build and push placeholder to both repos (create-on-push creates repos)
262+
# Build and push placeholder image (create-on-push creates repo)
261263
docker build -t placeholder /tmp
262-
for REPO in aiagent mcpserver1; do
263-
docker tag placeholder $ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/$REPO:latest
264-
docker push $ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/$REPO:latest
265-
done
264+
docker tag placeholder $ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/aiagent:latest
265+
docker push $ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/aiagent:latest
266266
""";
267267

268268
CodeBuild placeholderImageBuild = new CodeBuild(this, "PlaceholderImageBuild",

infra/cfn/java-spring-ai-agents-stack.yaml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,7 @@ Resources:
714714
Fn::GetAtt:
715715
- CodeBuildRoleE9A44575
716716
- Arn
717-
ContentHash: "1769256801727"
717+
ContentHash: "1769285698737"
718718
ProjectName:
719719
Ref: CodeBuildProjectA0FF5539
720720
ServiceToken:
@@ -801,12 +801,12 @@ Resources:
801801
Environment:
802802
ComputeType: BUILD_GENERAL1_MEDIUM
803803
EnvironmentVariables:
804-
- Name: TEMPLATE_TYPE
805-
Type: PLAINTEXT
806-
Value: java-spring-ai-agents
807804
- Name: GIT_BRANCH
808805
Type: PLAINTEXT
809806
Value: main
807+
- Name: TEMPLATE_TYPE
808+
Type: PLAINTEXT
809+
Value: java-spring-ai-agents
810810
Image: aws/codebuild/amazonlinux2-x86_64-standard:5.0
811811
ImagePullCredentialsType: CODEBUILD
812812
PrivilegedMode: false
@@ -835,6 +835,8 @@ Resources:
835835
# Resolution for when creating the first service in the account
836836
aws iam create-service-linked-role --aws-service-name ecs.amazonaws.com 2>/dev/null || true
837837
aws iam create-service-linked-role --aws-service-name elasticloadbalancing.amazonaws.com 2>/dev/null || true
838+
aws iam create-service-linked-role --aws-service-name network.bedrock-agentcore.amazonaws.com 2>/dev/null || true
839+
aws iam create-service-linked-role --aws-service-name runtime-identity.bedrock-agentcore.amazonaws.com 2>/dev/null || true
838840
Type: NO_SOURCE
839841
TimeoutInMinutes: 30
840842
VpcConfig:
@@ -2404,7 +2406,7 @@ Resources:
24042406
Fn::GetAtt:
24052407
- PlaceholderImageBuildRole66BA72FE
24062408
- Arn
2407-
ContentHash: "1769256802083"
2409+
ContentHash: "1769285699069"
24082410
ProjectName:
24092411
Ref: PlaceholderImageBuildProjectC08F4D66
24102412
ServiceToken:
@@ -2524,12 +2526,10 @@ Resources:
25242526
CMD ["nginx", "-g", "daemon off;"]
25252527
EOF
25262528
2527-
# Build and push placeholder to both repos (create-on-push creates repos)
2529+
# Build and push placeholder image (create-on-push creates repo)
25282530
docker build -t placeholder /tmp
2529-
for REPO in aiagent mcpserver1; do
2530-
docker tag placeholder $ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/$REPO:latest
2531-
docker push $ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/$REPO:latest
2532-
done
2531+
docker tag placeholder $ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/aiagent:latest
2532+
docker push $ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/aiagent:latest
25332533
Type: NO_SOURCE
25342534
TimeoutInMinutes: 30
25352535
VpcConfig:
@@ -3558,7 +3558,7 @@ Resources:
35583558
- Ref: AWS::AccountId
35593559
- "-"
35603560
- Ref: AWS::Region
3561-
- "-20260124131321"
3561+
- "-20260124211458"
35623562
PublicAccessBlockConfiguration:
35633563
BlockPublicAcls: true
35643564
BlockPublicPolicy: true

infra/scripts/templates/java-spring-ai-agents.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,19 @@ else
2020
exit 1
2121
fi
2222

23+
# Phase 2: Simplify p10k prompt (remove vcs, kubecontext, aws)
24+
log_info "Phase 2: Simplifying p10k prompt..."
25+
P10K_FILE="$HOME/.p10k.zsh"
26+
if [[ -f "$P10K_FILE" ]]; then
27+
# Remove vcs from left prompt
28+
sed -i '' "s/POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir vcs newline prompt_char)/POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir newline prompt_char)/" "$P10K_FILE"
29+
# Remove kubecontext and aws from right prompt
30+
sed -i '' "s/POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(status command_execution_time background_jobs kubecontext aws newline)/POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(status command_execution_time background_jobs newline)/" "$P10K_FILE"
31+
log_success "p10k prompt simplified"
32+
else
33+
log_warning "p10k.zsh not found, skipping prompt customization"
34+
fi
35+
2336
log_success "Java-Spring-AI-Agents workshop post-deploy setup completed successfully!"
2437

2538
# Emit for bootstrap summary

0 commit comments

Comments
 (0)