@kritchoff/agent-browser 0.9.52 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/sdk.sh DELETED
@@ -1,176 +0,0 @@
1
- #!/bin/bash
2
- # Agent Browser SDK Wrapper
3
- #
4
- # A user-friendly entry point for AI Agents to interact with the Android Browser Environment.
5
- # Handles "Hyper-Speed Snapshot" logic for instant startups.
6
- #
7
- # Usage:
8
- # ./sdk.sh start - Start the environment (Cold boot 1st time, Warm boot after)
9
- # ./sdk.sh stop - Stop the environment
10
- # ./sdk.sh reset - Fast Reset the browser (15s)
11
- # ./sdk.sh agent ... - Run agent commands (e.g. ./sdk.sh agent open google.com)
12
- #
13
-
14
- set -e
15
-
16
- # Set high timeouts for large image downloads
17
- export COMPOSE_HTTP_TIMEOUT=900
18
- export DOCKER_CLIENT_TIMEOUT=900
19
-
20
- SDK_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
21
- CACHE_DIR="$SDK_ROOT/cache"
22
- SNAPSHOT_DIR="$CACHE_DIR/snapshots/quickboot"
23
-
24
- # Default to production/local build unless --dist is used
25
- COMPOSE_FILE="$SDK_ROOT/docker-compose.prod.yml"
26
-
27
- # Colors
28
- GREEN='\033[0;32m'
29
- BLUE='\033[0;34m'
30
- YELLOW='\033[1;33m'
31
- RED='\033[0;31m'
32
- NC='\033[0m' # No Color
33
-
34
- # Parse global options
35
- while [[ $# -gt 0 ]]; do
36
- case $1 in
37
- --dist)
38
- COMPOSE_FILE="$SDK_ROOT/docker-compose.sdk.yml"
39
- shift
40
- ;;
41
- *)
42
- break
43
- ;;
44
- esac
45
- done
46
-
47
- # Ensure cache dir exists
48
- mkdir -p "$CACHE_DIR/snapshots"
49
-
50
- log_info() { echo -e "${BLUE}[SDK]${NC} $1"; }
51
- log_success() { echo -e "${GREEN}[SDK]${NC} $1"; }
52
- log_warn() { echo -e "${YELLOW}[SDK]${NC} $1"; }
53
- log_error() { echo -e "${RED}[SDK]${NC} $1"; }
54
-
55
- pull_images_with_retry() {
56
- if [[ "$COMPOSE_FILE" != *"docker-compose.sdk.yml" ]]; then
57
- return 0
58
- fi
59
-
60
- local max_retries=10
61
- local count=0
62
-
63
- log_info "Please wait while we get things ready..."
64
-
65
- while [ $count -lt $max_retries ]; do
66
- if docker compose -f "$COMPOSE_FILE" pull; then
67
- return 0
68
- fi
69
-
70
- count=$((count + 1))
71
- log_warn "Download failed/interrupted. Retrying ($count/$max_retries) in 10s..."
72
- sleep 10
73
- done
74
-
75
- log_error "Failed to download images after $max_retries attempts. Please check your internet connection."
76
- exit 1
77
- }
78
-
79
- cmd_start() {
80
- log_info "Initializing Agent Environment (using $COMPOSE_FILE)..."
81
- export COMPOSE_FILE="$COMPOSE_FILE"
82
- pull_images_with_retry
83
-
84
- log_info "Cleaning up previous container state..."
85
- docker compose -f "$COMPOSE_FILE" down -v --remove-orphans >/dev/null 2>&1 || true
86
-
87
- if [ -d "$SNAPSHOT_DIR" ]; then
88
- # === WARM START ===
89
- log_success "Found cached baseline snapshot. Performing HYPER-SPEED WARM BOOT..."
90
- export EMULATOR_SNAPSHOT_NAME="quickboot"
91
- "$SDK_ROOT/start.sh"
92
- else
93
- # === COLD START & FREEZE ===
94
- log_warn "No baseline found. Performing FIRST RUN SETUP (Cold Boot)..."
95
- log_warn "This will take ~60-90 seconds, but only once."
96
-
97
- export EMULATOR_SNAPSHOT_NAME=""
98
-
99
- "$SDK_ROOT/start.sh" &
100
- START_PID=$!
101
- wait $START_PID
102
-
103
- if [ $? -ne 0 ]; then
104
- log_error "Startup failed."
105
- exit 1
106
- fi
107
-
108
- cd "$SDK_ROOT"
109
- CONTAINER=$(docker compose ps -q android-service)
110
-
111
- if [ -z "$CONTAINER" ]; then
112
- log_error "Error: Android container not found."
113
- exit 1
114
- fi
115
-
116
- log_info "Saving emulator state (quickboot)..."
117
- if docker exec "$CONTAINER" adb emu avd snapshot save quickboot; then
118
- log_success "Snapshot saved to host volume."
119
- log_success "Setup Complete! Future runs will launch instantly."
120
- else
121
- log_error "Failed to save snapshot inside emulator."
122
- exit 1
123
- fi
124
- fi
125
- }
126
-
127
- cmd_stop() {
128
- log_info "Stopping environment (using $COMPOSE_FILE)..."
129
- cd "$SDK_ROOT"
130
- docker compose -f "$COMPOSE_FILE" stop
131
- log_success "Stopped."
132
- }
133
-
134
- cmd_clean() {
135
- log_info "Tearing down environment and releasing ports (using $COMPOSE_FILE)..."
136
- cd "$SDK_ROOT"
137
- docker compose -f "$COMPOSE_FILE" down -v --remove-orphans
138
- log_success "Environment cleaned."
139
- }
140
-
141
- cmd_reset() {
142
- log_info "Performing Fast Browser Reset..."
143
- export COMPOSE_FILE="$COMPOSE_FILE"
144
- "$SDK_ROOT/scripts/fast_reset.sh"
145
- }
146
-
147
- cmd_agent() {
148
- if [ -f "$SDK_ROOT/agent" ]; then
149
- "$SDK_ROOT/agent" "$@"
150
- else
151
- node "$SDK_ROOT/bin/agent-browser.js" "$@"
152
- fi
153
- }
154
-
155
- case "$1" in
156
- start)
157
- cmd_start
158
- ;;
159
- stop)
160
- cmd_stop
161
- ;;
162
- clean)
163
- cmd_clean
164
- ;;
165
- reset)
166
- cmd_reset
167
- ;;
168
- agent)
169
- shift
170
- cmd_agent "$@"
171
- ;;
172
- *)
173
- echo "Usage: $0 {start|stop|clean|reset|agent}"
174
- exit 1
175
- ;;
176
- esac
package/start.sh DELETED
@@ -1,109 +0,0 @@
1
- #!/bin/bash
2
- set -e
3
-
4
- SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
5
-
6
- # Colors
7
- GREEN='\033[0;32m'
8
- BLUE='\033[0;34m'
9
- YELLOW='\033[1;33m'
10
- RED='\033[0;31m'
11
- NC='\033[0m' # No Color
12
-
13
- echo -e "${BLUE}=================================================${NC}"
14
- echo -e "${BLUE} Agent Browser - Android Environment Setup ${NC}"
15
- echo -e "${BLUE}=================================================${NC}"
16
-
17
- SNAPSHOT_PATH=""
18
- while [[ $# -gt 0 ]]; do
19
- case $1 in
20
- --snapshot)
21
- SNAPSHOT_PATH="$2"
22
- shift 2
23
- ;;
24
- *)
25
- echo "Unknown option: $1"
26
- exit 1
27
- ;;
28
- esac
29
- done
30
-
31
- # 1. Pre-flight Checks
32
- echo -e "\n${YELLOW}[1/4] Checking System Requirements...${NC}"
33
-
34
- if ! command -v docker &> /dev/null; then
35
- echo -e "${RED}Error: Docker is not installed.${NC}"
36
- exit 1
37
- fi
38
-
39
- if [[ "$OSTYPE" == "linux-gnu"* ]]; then
40
- if [ -e /dev/kvm ]; then
41
- echo -e "${GREEN}✓ KVM Acceleration detected (/dev/kvm)${NC}"
42
- else
43
- echo -e "${YELLOW}⚠ Warning: No KVM detected. Emulator will be slow.${NC}"
44
- fi
45
- fi
46
-
47
- # 2. Start Services
48
- echo -e "\n${YELLOW}[2/4] Starting Docker Stack...${NC}"
49
- echo " (First run may take a few minutes to download images)"
50
-
51
- docker compose -f "${COMPOSE_FILE:-docker-compose.prod.yml}" up -d --build --remove-orphans
52
-
53
- # Find actual container names
54
- ANDROID_CONTAINER=$(docker compose -f "${COMPOSE_FILE:-docker-compose.prod.yml}" ps -q android-service)
55
- AGENT_CONTAINER=$(docker compose -f "${COMPOSE_FILE:-docker-compose.prod.yml}" ps -q agent-service)
56
-
57
- # 3. Wait for Readiness
58
- echo -e "\n${YELLOW}[3/4] Waiting for Initialization...${NC}"
59
-
60
- wait_for_log() {
61
- local container=$1
62
- local pattern=$2
63
- local label=$3
64
-
65
- echo -n " Waiting for $label... "
66
- until docker logs "$container" 2>&1 | grep -q "$pattern"; do
67
- sleep 1 # Faster polling
68
- done
69
- echo -e "${GREEN}Done!${NC}"
70
- }
71
-
72
- if [ -z "$SNAPSHOT_PATH" ] && [ -z "$EMULATOR_SNAPSHOT_NAME" ]; then
73
- # --- COLD BOOT PATH (Wait for everything) ---
74
- wait_for_log "$ANDROID_CONTAINER" "Emulator boot complete" "Android Emulator Boot"
75
- wait_for_log "$ANDROID_CONTAINER" "APK installation complete" "WootzApp Installation"
76
- wait_for_log "$ANDROID_CONTAINER" "CDP Bridge ready" "CDP Bridge"
77
- else
78
- # --- WARM BOOT PATH (Hyper-Speed) ---
79
- # We skip Boot and APK installation because they are inside the snapshot.
80
- # We only wait for the Daemon to reconnect to the resumed emulator.
81
- echo -e "${GREEN} Snapshot detected. Skipping OS boot and APK install waits.${NC}"
82
- fi
83
-
84
- # We always wait for the Daemon because it's the final bridge to the SDK
85
- wait_for_log "$AGENT_CONTAINER" "Daemon listening on TCP" "Agent Daemon Connection"
86
-
87
- # 3.5 Network Rehydration (Warm Boot Only)
88
- if [ -n "$SNAPSHOT_PATH" ] || [ -n "$EMULATOR_SNAPSHOT_NAME" ]; then
89
- echo " Rehydrating Android network connection..."
90
- # Toggle airplane mode to force DHCP lease renewal
91
- docker exec "$ANDROID_CONTAINER" adb shell cmd connectivity airplane-mode enable
92
- sleep 2
93
- docker exec "$ANDROID_CONTAINER" adb shell cmd connectivity airplane-mode disable
94
- # Wait for internet to come back
95
- sleep 3
96
- fi
97
-
98
- # 4. Success
99
- echo -e "\n${GREEN}[4/4] Environment Ready!${NC}"
100
- echo -e "${BLUE}=================================================${NC}"
101
- echo -e "You can now control the Android browser."
102
- echo -e ""
103
- echo -e "Try these commands:"
104
- echo -e " ${GREEN}./agent open https://google.com${NC}"
105
- echo -e " ${GREEN}./agent snapshot${NC}"
106
- echo -e " ${GREEN}./agent click @e1${NC}"
107
- echo -e ""
108
- echo -e "See COMMANDS.md for full reference."
109
- echo -e "${BLUE}=================================================${NC}"