-
Notifications
You must be signed in to change notification settings - Fork 121
feat: add AI Bridge Proxy support to copilot module #725
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: ssncf/feat-aibridge-proxy-module
Are you sure you want to change the base?
Changes from all commits
86e5d47
8afeedd
a9e60bd
84b32ac
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 | ||||
|---|---|---|---|---|---|---|
| @@ -1,5 +1,5 @@ | ||||||
| terraform { | ||||||
| required_version = ">= 1.0" | ||||||
| required_version = ">= 1.9" | ||||||
| required_providers { | ||||||
| coder = { | ||||||
| source = "coder/coder" | ||||||
|
|
@@ -173,6 +173,35 @@ variable "post_install_script" { | |||||
| default = null | ||||||
| } | ||||||
|
|
||||||
| variable "enable_aibridge_proxy" { | ||||||
| type = bool | ||||||
| description = "Route Copilot traffic through AI Bridge Proxy. See https://coder.com/docs/ai-coder/ai-bridge/ai-bridge-proxy" | ||||||
| default = false | ||||||
|
|
||||||
| validation { | ||||||
ssncferreira marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| condition = !var.enable_aibridge_proxy || length(var.aibridge_proxy_auth_url) > 0 | ||||||
|
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 validation references another input ( Useful? React with 👍 / 👎. |
||||||
| error_message = "aibridge_proxy_auth_url is required when enable_aibridge_proxy is true." | ||||||
| } | ||||||
|
|
||||||
| validation { | ||||||
| condition = !var.enable_aibridge_proxy || length(var.aibridge_proxy_cert_path) > 0 | ||||||
| error_message = "aibridge_proxy_cert_path is required when enable_aibridge_proxy is true." | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| variable "aibridge_proxy_auth_url" { | ||||||
| type = string | ||||||
| description = "AI Bridge Proxy URL with authentication. Use the proxy_auth_url output from the aibridge-proxy module." | ||||||
| default = "" | ||||||
|
Member
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.
Suggested change
|
||||||
| sensitive = true | ||||||
| } | ||||||
|
|
||||||
| variable "aibridge_proxy_cert_path" { | ||||||
| type = string | ||||||
| description = "Path to the AI Bridge Proxy CA certificate. Use the cert_path output from the aibridge-proxy module." | ||||||
| default = "" | ||||||
|
Member
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.
Suggested change
|
||||||
| } | ||||||
|
|
||||||
| data "coder_workspace" "me" {} | ||||||
| data "coder_workspace_owner" "me" {} | ||||||
|
|
||||||
|
|
@@ -279,6 +308,9 @@ module "agentapi" { | |||||
| ARG_TRUSTED_DIRECTORIES='${join(",", var.trusted_directories)}' \ | ||||||
| ARG_EXTERNAL_AUTH_ID='${var.external_auth_id}' \ | ||||||
| ARG_RESUME_SESSION='${var.resume_session}' \ | ||||||
| ARG_ENABLE_AIBRIDGE_PROXY='${var.enable_aibridge_proxy}' \ | ||||||
| ARG_AIBRIDGE_PROXY_AUTH_URL='${var.aibridge_proxy_auth_url}' \ | ||||||
| ARG_AIBRIDGE_PROXY_CERT_PATH='${var.aibridge_proxy_cert_path}' \ | ||||||
| /tmp/start.sh | ||||||
| EOT | ||||||
|
|
||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,9 @@ ARG_DENY_TOOLS=${ARG_DENY_TOOLS:-} | |
| ARG_TRUSTED_DIRECTORIES=${ARG_TRUSTED_DIRECTORIES:-} | ||
| ARG_EXTERNAL_AUTH_ID=${ARG_EXTERNAL_AUTH_ID:-github} | ||
| ARG_RESUME_SESSION=${ARG_RESUME_SESSION:-true} | ||
| ARG_ENABLE_AIBRIDGE_PROXY=${ARG_ENABLE_AIBRIDGE_PROXY:-false} | ||
| ARG_AIBRIDGE_PROXY_AUTH_URL=${ARG_AIBRIDGE_PROXY_AUTH_URL:-} | ||
| ARG_AIBRIDGE_PROXY_CERT_PATH=${ARG_AIBRIDGE_PROXY_CERT_PATH:-} | ||
|
|
||
| validate_copilot_installation() { | ||
| if ! command_exists copilot; then | ||
|
|
@@ -118,6 +121,48 @@ setup_github_authentication() { | |
| return 0 | ||
| } | ||
|
|
||
| setup_aibridge_proxy() { | ||
| if [ "$ARG_ENABLE_AIBRIDGE_PROXY" != "true" ]; then | ||
| return 0 | ||
| fi | ||
|
|
||
| echo "Setting up AI Bridge Proxy..." | ||
|
|
||
| # Wait for the aibridge-proxy module to finish. | ||
| # Uses startup coordination to block until aibridge-proxy-setup signals completion. | ||
| if command -v coder > /dev/null 2>&1; then | ||
| coder exp sync want "copilot-aibridge" "aibridge-proxy-setup" || true | ||
| coder exp sync start "copilot-aibridge" || true | ||
| trap 'coder exp sync complete "copilot-aibridge" > /dev/null 2>&1 || true' EXIT | ||
| fi | ||
|
|
||
| if [ -z "$ARG_AIBRIDGE_PROXY_AUTH_URL" ]; then | ||
| echo "ERROR: AI Bridge Proxy is enabled but no proxy auth URL provided." | ||
| exit 1 | ||
| fi | ||
|
|
||
| if [ -z "$ARG_AIBRIDGE_PROXY_CERT_PATH" ]; then | ||
| echo "ERROR: AI Bridge Proxy is enabled but no certificate path provided." | ||
| exit 1 | ||
| fi | ||
|
|
||
| if [ ! -f "$ARG_AIBRIDGE_PROXY_CERT_PATH" ]; then | ||
| echo "ERROR: AI Bridge Proxy certificate not found at $ARG_AIBRIDGE_PROXY_CERT_PATH." | ||
| echo " Ensure the aibridge-proxy module has completed setup." | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Set proxy environment variables scoped to this process tree only. | ||
| # These are inherited by the agentapi/copilot process below, | ||
| # but do not affect other workspace processes, avoiding routing | ||
| # unnecessary traffic through the proxy. | ||
| export HTTPS_PROXY="$ARG_AIBRIDGE_PROXY_AUTH_URL" | ||
|
Contributor
Author
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. Testing with |
||
| export NODE_EXTRA_CA_CERTS="$ARG_AIBRIDGE_PROXY_CERT_PATH" | ||
|
|
||
| echo "✓ AI Bridge Proxy configured" | ||
| echo " CA certificate: $ARG_AIBRIDGE_PROXY_CERT_PATH" | ||
| } | ||
|
|
||
| start_agentapi() { | ||
| echo "Starting in directory: $ARG_WORKDIR" | ||
| cd "$ARG_WORKDIR" | ||
|
|
@@ -157,5 +202,6 @@ start_agentapi() { | |
| } | ||
|
|
||
| setup_github_authentication | ||
| setup_aibridge_proxy | ||
| validate_copilot_installation | ||
| start_agentapi | ||
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.
How do we ensure that prxy is ready configured before the Copilot module starts up the Copilot CLI?
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.
consider using https://coder.com/docs/admin/templates/startup-coordination
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.
That is a good point. I tried setting this up with commits:
And seems to be working. But probably still needs more testing.