Skip to content

Commit 220aea1

Browse files
committed
Added client config autogeneration.
1 parent d11d09d commit 220aea1

File tree

3 files changed

+58
-2
lines changed

3 files changed

+58
-2
lines changed

agent-server/nodejs/init-client.sh

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/bin/bash
2+
# Auto-generate client configuration for AUTOMATED_MODE
3+
# This script creates a default client YAML file if none exist (excluding example-client.yaml)
4+
5+
set -e
6+
7+
CLIENTS_DIR="${CLIENTS_DIR:-/opt/agent-server/clients}"
8+
CLIENT_NAME="${CLIENT_NAME:-DevTools Client}"
9+
10+
# Ensure clients directory exists
11+
mkdir -p "$CLIENTS_DIR"
12+
13+
# Count actual client files (excluding example-client.yaml)
14+
CLIENT_COUNT=$(find "$CLIENTS_DIR" -name "*.yaml" -o -name "*.yml" 2>/dev/null | grep -v "example-client" | wc -l)
15+
16+
if [ "$CLIENT_COUNT" -eq 0 ]; then
17+
echo "🔧 No client configurations found. Generating default client..."
18+
19+
# Generate a random UUID for the client
20+
if command -v uuidgen &> /dev/null; then
21+
CLIENT_ID=$(uuidgen | tr '[:upper:]' '[:lower:]')
22+
else
23+
# Fallback UUID generation using /proc/sys/kernel/random/uuid
24+
CLIENT_ID=$(cat /proc/sys/kernel/random/uuid 2>/dev/null || echo "$(cat /dev/urandom | tr -dc 'a-f0-9' | fold -w 32 | head -n 1 | sed 's/\(.\{8\}\)\(.\{4\}\)\(.\{4\}\)\(.\{4\}\)\(.\{12\}\)/\1-\2-\3-\4-\5/')")
25+
fi
26+
27+
# Create client YAML configuration
28+
cat > "$CLIENTS_DIR/$CLIENT_ID.yaml" <<EOF
29+
# Auto-generated client configuration
30+
# Generated at: $(date -Iseconds 2>/dev/null || date)
31+
32+
client:
33+
id: $CLIENT_ID
34+
name: $CLIENT_NAME
35+
secret_key: null
36+
description: Auto-generated client for AUTOMATED_MODE
37+
EOF
38+
39+
echo "✅ Created client configuration: $CLIENT_ID"
40+
echo " Path: $CLIENTS_DIR/$CLIENT_ID.yaml"
41+
else
42+
echo "ℹ️ Found $CLIENT_COUNT existing client configuration(s). Skipping auto-generation."
43+
fi

agent-server/nodejs/src/client-manager.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,13 @@ class ClientManager {
2929
// Only load base client YAML files, not composite ones with tab IDs
3030
const clientId = path.basename(f, path.extname(f));
3131
return !clientId.includes(':');
32+
})
33+
.filter(f => {
34+
// Skip example client template file
35+
const filename = path.basename(f, path.extname(f));
36+
return filename !== 'example-client';
3237
});
33-
38+
3439
for (const file of files) {
3540
const clientId = path.basename(file, path.extname(file));
3641
try {
@@ -39,7 +44,7 @@ class ClientManager {
3944
logger.error(`Failed to load client ${clientId}:`, error);
4045
}
4146
}
42-
47+
4348
logger.info(`Loaded ${this.clients.size} clients`);
4449
} catch (error) {
4550
logger.error('Failed to load clients:', error);

docker/Dockerfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ COPY --from=builder /workspace/devtools/devtools-frontend/out/Default/gen/front_
8383
# Copy agent-server from builder stage
8484
COPY --from=agent-server-builder /workspace/agent-server /opt/agent-server
8585

86+
# Copy client initialization script
87+
COPY agent-server/nodejs/init-client.sh /opt/agent-server/init-client.sh
88+
RUN chmod +x /opt/agent-server/init-client.sh
89+
8690
# Copy nginx config
8791
COPY docker/nginx.conf /etc/nginx/conf.d/default.conf
8892

@@ -91,6 +95,10 @@ RUN cat > /usr/local/bin/start-services.sh <<'EOFSCRIPT'
9195
#!/bin/bash
9296
set -e
9397

98+
# Initialize client configuration if needed
99+
echo "Initializing client configuration..."
100+
/opt/agent-server/init-client.sh
101+
94102
# Start nginx in background
95103
echo "Starting nginx..."
96104
nginx -g "daemon off;" &

0 commit comments

Comments
 (0)