Skip to content

Commit 9b44262

Browse files
refactor(gemini): reorganize agentapi module configuration and enhance start script
1 parent 370e73d commit 9b44262

File tree

2 files changed

+32
-19
lines changed

2 files changed

+32
-19
lines changed

registry/coder-labs/modules/gemini/main.tf

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -179,18 +179,39 @@ module "agentapi" {
179179
version = "1.0.0"
180180

181181
agent_id = var.agent_id
182+
folder = var.folder
182183
web_app_slug = local.app_slug
183184
web_app_order = var.order
184185
web_app_group = var.group
185186
web_app_icon = var.icon
186187
web_app_display_name = "Gemini"
188+
cli_app = true
187189
cli_app_slug = "${local.app_slug}-cli"
188190
cli_app_display_name = "Gemini CLI"
191+
cli_app_icon = var.icon
192+
cli_app_order = var.order
193+
cli_app_group = var.group
189194
module_dir_name = local.module_dir_name
190195
install_agentapi = var.install_agentapi
191196
agentapi_version = var.agentapi_version
192197
pre_install_script = var.pre_install_script
193198
post_install_script = var.post_install_script
199+
install_script = <<-EOT
200+
#!/bin/bash
201+
set -o errexit
202+
set -o pipefail
203+
204+
echo -n '${base64encode(local.install_script)}' | base64 -d > /tmp/install.sh
205+
chmod +x /tmp/install.sh
206+
ARG_INSTALL='${var.install_gemini}' \
207+
ARG_GEMINI_VERSION='${var.gemini_version}' \
208+
ARG_GEMINI_CONFIG='${base64encode(var.gemini_settings_json)}' \
209+
BASE_EXTENSIONS='${base64encode(replace(local.base_extensions, "'", "'\\''"))}' \
210+
ADDITIONAL_EXTENSIONS='${base64encode(replace(var.additional_extensions != null ? var.additional_extensions : "", "'", "'\\''"))}' \
211+
GEMINI_START_DIRECTORY='${var.folder}' \
212+
GEMINI_SYSTEM_PROMPT='${base64encode(var.gemini_system_prompt)}' \
213+
/tmp/install.sh
214+
EOT
194215
start_script = <<-EOT
195216
#!/bin/bash
196217
set -o errexit
@@ -207,21 +228,4 @@ module "agentapi" {
207228
GEMINI_TASK_PROMPT='${base64encode(var.task_prompt)}' \
208229
/tmp/start.sh
209230
EOT
210-
211-
install_script = <<-EOT
212-
#!/bin/bash
213-
set -o errexit
214-
set -o pipefail
215-
216-
echo -n '${base64encode(local.install_script)}' | base64 -d > /tmp/install.sh
217-
chmod +x /tmp/install.sh
218-
ARG_INSTALL='${var.install_gemini}' \
219-
ARG_GEMINI_VERSION='${var.gemini_version}' \
220-
ARG_GEMINI_CONFIG='${base64encode(var.gemini_settings_json)}' \
221-
BASE_EXTENSIONS='${base64encode(replace(local.base_extensions, "'", "'\\''"))}' \
222-
ADDITIONAL_EXTENSIONS='${base64encode(replace(var.additional_extensions != null ? var.additional_extensions : "", "'", "'\\''"))}' \
223-
GEMINI_START_DIRECTORY='${var.folder}' \
224-
GEMINI_SYSTEM_PROMPT='${base64encode(var.gemini_system_prompt)}' \
225-
/tmp/install.sh
226-
EOT
227231
}

registry/coder-labs/modules/gemini/scripts/start.sh

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
#!/bin/bash
2+
set -o errexit
3+
set -o pipefail
4+
5+
# Handle parameters from agentapi module
6+
USE_PROMPT="$1"
7+
AGENTAPI_PORT="$2"
28

39
source "$HOME"/.bashrc
410

@@ -41,7 +47,8 @@ else
4147
}
4248
fi
4349

44-
if [ -n "$GEMINI_TASK_PROMPT" ]; then
50+
# Handle prompt logic based on parameters
51+
if [ -n "$USE_PROMPT" ] && [ "$USE_PROMPT" = "true" ] && [ -n "$GEMINI_TASK_PROMPT" ]; then
4552
printf "Running automated task: %s\n" "$GEMINI_TASK_PROMPT"
4653
PROMPT="Every step of the way, report tasks to Coder with proper descriptions and statuses. Your task at hand: $GEMINI_TASK_PROMPT"
4754
GEMINI_ARGS=(--prompt)
@@ -66,4 +73,6 @@ else
6673
printf "No API key provided (neither GEMINI_API_KEY nor GOOGLE_API_KEY)\n"
6774
fi
6875

69-
agentapi server --term-width 67 --term-height 1190 -- gemini "${GEMINI_ARGS[@]}"
76+
# Use the port parameter if provided, otherwise default to 3284
77+
PORT=${AGENTAPI_PORT:-3284}
78+
agentapi server --port "$PORT" --term-width 67 --term-height 1190 -- gemini "${GEMINI_ARGS[@]}"

0 commit comments

Comments
 (0)