Skip to content
Merged
63 changes: 56 additions & 7 deletions cli/azd/ci-build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,29 @@ param(
[string] $SourceVersion = (git rev-parse HEAD),
[switch] $CodeCoverageEnabled,
[switch] $BuildRecordMode,
[string] $MSYS2Shell # path to msys2_shell.cmd
[string] $MSYS2Shell, # path to msys2_shell.cmd
[string] $GitHubCopilotClientId,
[string] $GitHubCopilotIntegrationId
)
$PSNativeCommandArgumentPassing = 'Legacy'

# Validate GitHub Copilot parameters - both must be provided together or not at all
$GitHubCopilotEnabled = $false
if ($GitHubCopilotClientId -or $GitHubCopilotIntegrationId) {
if ([string]::IsNullOrWhiteSpace($GitHubCopilotClientId)) {
Write-Host "Error: GitHubCopilotClientId parameter is required when enabling GitHub Copilot integration" -ForegroundColor Red
Write-Host "Usage: -GitHubCopilotClientId 'your-client-id' -GitHubCopilotIntegrationId 'your-integration-id'" -ForegroundColor Yellow
exit 1
}
if ([string]::IsNullOrWhiteSpace($GitHubCopilotIntegrationId)) {
Write-Host "Error: GitHubCopilotIntegrationId parameter is required when enabling GitHub Copilot integration" -ForegroundColor Red
Write-Host "Usage: -GitHubCopilotClientId 'your-client-id' -GitHubCopilotIntegrationId 'your-integration-id'" -ForegroundColor Yellow
exit 1
}
$GitHubCopilotEnabled = $true
Write-Host "GitHub Copilot integration enabled with ClientId: $GitHubCopilotClientId and IntegrationId: $GitHubCopilotIntegrationId" -ForegroundColor Green
}

# specifying $MSYS2Shell implies building with OneAuth integration
$OneAuth = $MSYS2Shell.length -gt 0 -and $IsWindows

Expand Down Expand Up @@ -113,27 +132,56 @@ if ($CodeCoverageEnabled) {
# cfi: Enable Control Flow Integrity (CFI),
# cfg: Enable Control Flow Guard (CFG),
# osusergo: Optimize for OS user accounts
$tagsFlag = "-tags=cfi,cfg,osusergo"
# ghCopilot: Enable GitHub Copilot integration (when parameters provided)
$tags = @("cfi", "cfg", "osusergo")
if ($GitHubCopilotEnabled) {
$tags += "ghCopilot"
}
$tagsFlag = "-tags=$($tags -join ',')"

# ld linker flags
# -s: Omit symbol table and debug information
# -w: Omit DWARF symbol table
# -X: Set variable at link time. Used to set the version in source.
$ldFlag = "-ldflags=-s -w -X 'github.com/azure/azure-dev/cli/azd/internal.Version=$Version (commit $SourceVersion)' "
$ldFlags = @(
"-s",
"-w",
"-X 'github.com/azure/azure-dev/cli/azd/internal.Version=$Version (commit $SourceVersion)'"
)

# Add GitHub Copilot linker flags if enabled
if ($GitHubCopilotEnabled) {
$ldFlags += "-X 'github.com/azure/azure-dev/cli/azd/pkg/llm.clientID=$GitHubCopilotClientId'"
$ldFlags += "-X 'github.com/azure/azure-dev/cli/azd/pkg/llm.copilotIntegrationID=$GitHubCopilotIntegrationId'"
}

$ldFlag = "-ldflags=$($ldFlags -join ' ')"

if ($IsWindows) {
$msg = "Building for Windows"
if ($OneAuth) {
$msg += " with OneAuth integration"
$tagsFlag += ",oneauth"
$tags += "oneauth"
$tagsFlag = "-tags=$($tags -join ',')"
}
if ($GitHubCopilotEnabled) {
$msg += " with GitHub Copilot integration"
}
Write-Host $msg
}
elseif ($IsLinux) {
Write-Host "Building for linux"
$msg = "Building for Linux"
if ($GitHubCopilotEnabled) {
$msg += " with GitHub Copilot integration"
}
Write-Host $msg
}
elseif ($IsMacOS) {
Write-Host "Building for macOS"
$msg = "Building for macOS"
if ($GitHubCopilotEnabled) {
$msg += " with GitHub Copilot integration"
}
Write-Host $msg
}

# collect flags
Expand Down Expand Up @@ -196,7 +244,8 @@ try {
}

if (-not $recordFlagPresent) {
$buildFlags[$i] += "-tags=record"
$recordTags = $tags + @("record")
$buildFlags += "-tags=$($recordTags -join ',')"
}

$outputFlag = "-o=azd-record"
Expand Down
1 change: 1 addition & 0 deletions cli/azd/cmd/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,7 @@ func registerCommonDependencies(container *ioc.NestedContainer) {
container.MustRegisterScoped(consent.NewConsentManager)
container.MustRegisterNamedSingleton("ollama", llm.NewOllamaModelProvider)
container.MustRegisterNamedSingleton("azure", llm.NewAzureOpenAiModelProvider)
registerGitHubCopilotProvider(container)

// Agent security manager
container.MustRegisterSingleton(func() (*security.Manager, error) {
Expand Down
17 changes: 17 additions & 0 deletions cli/azd/cmd/github_copilot_registration.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

//go:build ghCopilot

package cmd

import (
"github.com/azure/azure-dev/cli/azd/pkg/ioc"
"github.com/azure/azure-dev/cli/azd/pkg/llm"
)

// registerGitHubCopilotProvider registers the GitHub Copilot LLM provider
// This function is only compiled when the 'copilot' build tag is used
func registerGitHubCopilotProvider(container *ioc.NestedContainer) {
container.MustRegisterNamedSingleton("github-copilot", llm.NewGitHubCopilotModelProvider)
}
16 changes: 16 additions & 0 deletions cli/azd/cmd/github_copilot_registration_stub.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

//go:build !ghCopilot

package cmd

import (
"github.com/azure/azure-dev/cli/azd/pkg/ioc"
)

// registerGitHubCopilotProvider is a no-op when GitHub Copilot is not enabled
// This function is only compiled when the 'with-gh-copilot' build tag is not used
func registerGitHubCopilotProvider(container *ioc.NestedContainer) {
// No-op: GitHub Copilot provider is not registered when with-gh-copilot build tag is not set
}
4 changes: 2 additions & 2 deletions cli/azd/internal/agent/agent_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,15 @@ func (f *AgentFactory) Create(ctx context.Context, opts ...AgentCreateOption) (A
}

// Default model gets the chained handler to expose the UX experience for the agent
defaultModelContainer, err := f.llmManager.GetDefaultModel(llm.WithLogger(chainedHandler))
defaultModelContainer, err := f.llmManager.GetDefaultModel(ctx, llm.WithLogger(chainedHandler))
if err != nil {
defer cleanup()
return nil, err
}

// Sampling model only gets the file logger to output sampling actions
// We don't need UX for sampling requests right now
samplingModelContainer, err := f.llmManager.GetDefaultModel(llm.WithLogger(fileLogger))
samplingModelContainer, err := f.llmManager.GetDefaultModel(ctx, llm.WithLogger(fileLogger))
if err != nil {
defer cleanup()
return nil, err
Expand Down
3 changes: 2 additions & 1 deletion cli/azd/pkg/llm/azure_openai.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package llm

import (
"context"
"fmt"

"github.com/azure/azure-dev/cli/azd/pkg/config"
Expand Down Expand Up @@ -37,7 +38,7 @@ func NewAzureOpenAiModelProvider(userConfigManager config.UserConfigManager) Mod
// CreateModelContainer creates a model container for Azure OpenAI with configuration
// loaded from user settings. It validates required fields and applies optional parameters
// like temperature and max tokens before creating the OpenAI client.
func (p *AzureOpenAiModelProvider) CreateModelContainer(opts ...ModelOption) (*ModelContainer, error) {
func (p *AzureOpenAiModelProvider) CreateModelContainer(_ context.Context, opts ...ModelOption) (*ModelContainer, error) {
userConfig, err := p.userConfigManager.Load()
if err != nil {
return nil, err
Expand Down
Loading
Loading