-
Notifications
You must be signed in to change notification settings - Fork 116
feat(coder/modules/agentapi): enhance start script and configuration options for AgentAPI server #693
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat(coder/modules/agentapi): enhance start script and configuration options for AgentAPI server #693
Changes from all commits
6e18248
3f68310
f93b366
787ce3f
6db604b
833f0ac
b580ec2
3d4d24b
ac1fb95
63c5e2c
a332181
f52ef07
80f47d0
4459d39
d635583
15ca0aa
c630722
5edf4a9
85e7da3
03ac608
df2d72f
65c40ed
c079545
4bbc6d9
32fa6cb
253f95f
88b01db
fde6ae6
c1a3ed5
21757f3
fabb5b2
191f4ca
4732deb
5de7928
c2958d5
0f11e4a
e499d60
b14bbe4
01873e3
873c929
08fcdcc
64c6417
fc88b54
a35df64
3dddb96
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -110,6 +110,12 @@ variable "start_script" { | |
| description = "Script that starts AgentAPI." | ||
| } | ||
|
|
||
| variable "enable_agentapi" { | ||
| type = bool | ||
| description = "Whether to enable AgentAPI. If false, AgentAPI will not be installed or started, and the web app will not be created." | ||
| default = true | ||
| } | ||
|
|
||
| variable "install_agentapi" { | ||
| type = bool | ||
| description = "Whether to install AgentAPI." | ||
|
|
@@ -128,6 +134,29 @@ variable "agentapi_port" { | |
| default = 3284 | ||
| } | ||
|
|
||
| variable "agent_name" { | ||
| type = string | ||
| description = "The agent's name. This is used as server type for AgentAPI, passed using --agent flag." | ||
| } | ||
|
|
||
| variable "agentapi_term_width" { | ||
| type = number | ||
| description = "The terminal width for AgentAPI." | ||
| default = 67 | ||
| } | ||
|
|
||
| variable "agentapi_term_height" { | ||
| type = number | ||
| description = "The terminal height for AgentAPI." | ||
| default = 1190 | ||
| } | ||
|
|
||
| variable "agentapi_initial_prompt" { | ||
| type = string | ||
| description = "Initial prompt for the agent. Recommended only if the agent doesn't support initial prompt in interaction mode." | ||
| default = null | ||
| } | ||
|
|
||
| variable "task_log_snapshot" { | ||
| type = bool | ||
| description = "Capture last 10 messages when workspace stops for offline viewing while task is paused." | ||
|
|
@@ -168,10 +197,7 @@ variable "module_dir_name" { | |
| locals { | ||
| # we always trim the slash for consistency | ||
| workdir = trimsuffix(var.folder, "/") | ||
| encoded_pre_install_script = var.pre_install_script != null ? base64encode(var.pre_install_script) : "" | ||
| encoded_install_script = var.install_script != null ? base64encode(var.install_script) : "" | ||
| encoded_post_install_script = var.post_install_script != null ? base64encode(var.post_install_script) : "" | ||
| agentapi_start_script_b64 = base64encode(var.start_script) | ||
| encoded_initial_prompt = var.agentapi_initial_prompt != null ? base64encode(var.agentapi_initial_prompt) : "" | ||
| agentapi_wait_for_start_script_b64 = base64encode(file("${path.module}/scripts/agentapi-wait-for-start.sh")) | ||
| // Chat base path is only set if not using a subdomain. | ||
| // NOTE: | ||
|
|
@@ -182,39 +208,62 @@ locals { | |
| agentapi_chat_base_path = var.agentapi_subdomain ? "" : "/@${data.coder_workspace_owner.me.name}/${data.coder_workspace.me.name}.${var.agent_id}/apps/${var.web_app_slug}/chat" | ||
| main_script = file("${path.module}/scripts/main.sh") | ||
| shutdown_script = file("${path.module}/scripts/agentapi-shutdown.sh") | ||
|
|
||
| agentapi_main_script_name = "${var.agent_name}-main_script" | ||
|
|
||
| module_dir_path = "$HOME/${var.module_dir_name}" | ||
| } | ||
|
|
||
| module "agent-helper" { | ||
| source = "git::https://github.com/coder/registry.git//registry/coder/modules/agent-helper?ref=35C4n0r/feat-agent-helper-module" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This source points to a mutable feature branch ( Useful? React with 👍 / 👎. |
||
| agent_id = var.agent_id | ||
| agent_name = var.agent_name | ||
| module_dir_name = var.module_dir_name | ||
|
|
||
| pre_install_script = var.pre_install_script | ||
| install_script = var.install_script | ||
| post_install_script = var.post_install_script | ||
| start_script = var.start_script | ||
| } | ||
|
|
||
| resource "coder_script" "agentapi" { | ||
| count = var.enable_agentapi ? 1 : 0 | ||
| agent_id = var.agent_id | ||
| display_name = "Install and start AgentAPI" | ||
| display_name = "Start AgentAPI" | ||
| icon = var.web_app_icon | ||
| script = <<-EOT | ||
| #!/bin/bash | ||
| set -o errexit | ||
| set -o pipefail | ||
|
|
||
| trap 'coder exp sync complete ${local.agentapi_main_script_name}' EXIT | ||
| coder exp sync want ${local.agentapi_main_script_name} ${module.agent-helper.start_script_name} | ||
| coder exp sync start ${local.agentapi_main_script_name} | ||
|
|
||
| echo -n '${base64encode(local.main_script)}' | base64 -d > /tmp/main.sh | ||
| chmod +x /tmp/main.sh | ||
|
|
||
| ARG_MODULE_DIR_NAME='${var.module_dir_name}' \ | ||
| ARG_WORKDIR="$(echo -n '${base64encode(local.workdir)}' | base64 -d)" \ | ||
| ARG_PRE_INSTALL_SCRIPT="$(echo -n '${local.encoded_pre_install_script}' | base64 -d)" \ | ||
| ARG_INSTALL_SCRIPT="$(echo -n '${local.encoded_install_script}' | base64 -d)" \ | ||
| ARG_INSTALL_AGENTAPI='${var.install_agentapi}' \ | ||
| ARG_AGENTAPI_VERSION='${var.agentapi_version}' \ | ||
| ARG_START_SCRIPT="$(echo -n '${local.agentapi_start_script_b64}' | base64 -d)" \ | ||
| ARG_WAIT_FOR_START_SCRIPT="$(echo -n '${local.agentapi_wait_for_start_script_b64}' | base64 -d)" \ | ||
| ARG_POST_INSTALL_SCRIPT="$(echo -n '${local.encoded_post_install_script}' | base64 -d)" \ | ||
| ARG_AGENTAPI_PORT='${var.agentapi_port}' \ | ||
| ARG_AGENTAPI_SERVER_TYPE='${var.agent_name}' \ | ||
| ARG_AGENTAPI_TERM_WIDTH='${var.agentapi_term_width}' \ | ||
| ARG_AGENTAPI_TERM_HEIGHT='${var.agentapi_term_height}' \ | ||
| ARG_AGENTAPI_INITIAL_PROMPT="$(echo -n '${local.encoded_initial_prompt}' | base64 -d)" \ | ||
| ARG_AGENTAPI_CHAT_BASE_PATH='${local.agentapi_chat_base_path}' \ | ||
| ARG_TASK_ID='${try(data.coder_task.me.id, "")}' \ | ||
| ARG_TASK_LOG_SNAPSHOT='${var.task_log_snapshot}' \ | ||
| /tmp/main.sh | ||
| EOT | ||
| run_on_start = true | ||
| depends_on = [module.agent-helper] | ||
| } | ||
|
|
||
| resource "coder_script" "agentapi_shutdown" { | ||
| count = var.enable_agentapi ? 1 : 0 | ||
| agent_id = var.agent_id | ||
| display_name = "AgentAPI Shutdown" | ||
| icon = var.web_app_icon | ||
|
|
@@ -234,6 +283,7 @@ resource "coder_script" "agentapi_shutdown" { | |
| } | ||
|
|
||
| resource "coder_app" "agentapi_web" { | ||
| count = var.enable_agentapi ? 1 : 0 | ||
| slug = var.web_app_slug | ||
| display_name = var.web_app_display_name | ||
| agent_id = var.agent_id | ||
|
|
@@ -249,7 +299,7 @@ resource "coder_app" "agentapi_web" { | |
| } | ||
| } | ||
|
|
||
| resource "coder_app" "agentapi_cli" { | ||
| resource "coder_app" "agent_cli" { | ||
| count = var.cli_app ? 1 : 0 | ||
|
|
||
| slug = var.cli_app_slug | ||
|
|
@@ -262,13 +312,17 @@ resource "coder_app" "agentapi_cli" { | |
| export LANG=en_US.UTF-8 | ||
| export LC_ALL=en_US.UTF-8 | ||
|
|
||
| %{if var.enable_agentapi~} | ||
| agentapi attach | ||
| %{else} | ||
| ${local.module_dir_path}/agent-command.sh | ||
| %{endif} | ||
| EOT | ||
| icon = var.cli_app_icon | ||
| order = var.cli_app_order | ||
| group = var.cli_app_group | ||
| } | ||
|
|
||
| output "task_app_id" { | ||
| value = coder_app.agentapi_web.id | ||
| value = var.enable_agentapi ? coder_app.agentapi_web[0].id : null | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agent_namevariableThe usage example now sets
agentapi_server_type, but this module does not define that input and instead requiresagent_name; users copy-pasting this snippet will get anUnsupported argumenterror at plan/apply time and cannot configure the module successfully.Useful? React with 👍 / 👎.