Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion cli/azd/extensions/azure.ai.agents/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ require (
github.com/google/uuid v1.6.0
github.com/mark3labs/mcp-go v0.41.1
github.com/spf13/cobra v1.10.1
github.com/spf13/pflag v1.0.10
go.yaml.in/yaml/v3 v3.0.4
google.golang.org/protobuf v1.36.10
gopkg.in/yaml.v3 v3.0.1
Expand Down Expand Up @@ -75,7 +76,6 @@ require (
github.com/rivo/uniseg v0.4.7 // indirect
github.com/sethvargo/go-retry v0.3.0 // indirect
github.com/spf13/cast v1.10.0 // indirect
github.com/spf13/pflag v1.0.10 // indirect
github.com/stretchr/testify v1.11.1 // indirect
github.com/theckman/yacspin v0.13.12 // indirect
github.com/wk8/go-ordered-map/v2 v2.1.8 // indirect
Expand All @@ -97,3 +97,5 @@ require (
google.golang.org/genproto/googleapis/rpc v0.0.0-20251007200510-49b9836ed3ff // indirect
google.golang.org/grpc v1.76.0 // indirect
)

replace github.com/azure/azure-dev/cli/azd => ../..
2 changes: 0 additions & 2 deletions cli/azd/extensions/azure.ai.agents/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ github.com/aymanbagabas/go-udiff v0.2.0 h1:TK0fH4MteXUDspT88n8CKzvK0X9O2xu9yQjWp
github.com/aymanbagabas/go-udiff v0.2.0/go.mod h1:RE4Ex0qsGkTAJoQdQQCA0uG+nAzJO/pI/QwceO5fgrA=
github.com/aymerick/douceur v0.2.0 h1:Mv+mAeH1Q+n9Fr+oyamOlAkUNPWPlA8PPGR0QAaYuPk=
github.com/aymerick/douceur v0.2.0/go.mod h1:wlT5vV2O3h55X9m7iVYN0TBM0NH/MmbLnd30/FjWUq4=
github.com/azure/azure-dev/cli/azd v0.0.0-20251121010829-d5e0a142e813 h1:6RgPxlo9PsEc4q/IDkompYhL7U0+XdW0V4iP+1tpoKc=
github.com/azure/azure-dev/cli/azd v0.0.0-20251121010829-d5e0a142e813/go.mod h1:k86H7K6vCw8UmimYs0/gDTilxQwXUZDaikRYfDweB/U=
github.com/bahlo/generic-list-go v0.2.0 h1:5sz/EEAK+ls5wF+NeqDpk5+iNdMDXrh3z3nPnH1Wvgk=
github.com/bahlo/generic-list-go v0.2.0/go.mod h1:2KvAjgMlE5NNynlg/5iLrrCCZ2+5xWbdbCW3pNTGyYg=
github.com/benbjohnson/clock v1.3.5 h1:VvXlSJBzZpA/zum6Sj74hxwYI2DIxRWuNIoXAzHZz5o=
Expand Down
44 changes: 44 additions & 0 deletions cli/azd/extensions/azure.ai.agents/internal/cmd/debug.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package cmd

import (
"fmt"
"os"
"regexp"
"strconv"
"time"

azcorelog "github.com/Azure/azure-sdk-for-go/sdk/azcore/log"
"github.com/spf13/pflag"
)

var connectionStringJSONRegex = regexp.MustCompile(`("[\w]*(?:CONNECTION_STRING|ConnectionString)":\s*)"[^"]*"`)

// setupDebugLogging configures the Azure SDK logger if debug mode is enabled.
func setupDebugLogging(flags *pflag.FlagSet) {
if isDebug(flags) {
currentDate := time.Now().Format("2006-01-02")
logFileName := fmt.Sprintf("azd-ai-agents-%s.log", currentDate)

logFile, err := os.OpenFile(logFileName, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0644)
if err != nil {
logFile = os.Stderr
}
azcorelog.SetListener(func(event azcorelog.Event, msg string) {
msg = connectionStringJSONRegex.ReplaceAllString(msg, `${1}"REDACTED"`)
fmt.Fprintf(logFile, "[%s] %s: %s\n", time.Now().Format(time.RFC3339), event, msg)
})
}
}

// isDebug checks if debug mode is enabled via --debug flag or AZD_EXT_DEBUG environment variable
func isDebug(flags *pflag.FlagSet) bool {
if debugFlag, err := flags.GetBool("debug"); err == nil && debugFlag {
return true
}

debug, _ := strconv.ParseBool(os.Getenv("AZD_EXT_DEBUG"))
return debug
}
6 changes: 4 additions & 2 deletions cli/azd/extensions/azure.ai.agents/internal/cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ func newInitCommand(rootFlags rootFlagsDefinition) *cobra.Command {
RunE: func(cmd *cobra.Command, args []string) error {
ctx := azdext.WithAccessToken(cmd.Context())

setupDebugLogging(cmd.Flags())

azdClient, err := azdext.NewAzdClient()
if err != nil {
return fmt.Errorf("failed to create azd client: %w", err)
Expand Down Expand Up @@ -317,7 +319,7 @@ func ensureEnvironment(ctx context.Context, flags *initFlags, azdClient *azdext.
}

// Create Cognitive Services Projects client
projectsClient, err := armcognitiveservices.NewProjectsClient(foundryProject.SubscriptionId, credential, nil)
projectsClient, err := armcognitiveservices.NewProjectsClient(foundryProject.SubscriptionId, credential, azure.NewArmClientOptions())
if err != nil {
return nil, fmt.Errorf("failed to create Cognitive Services Projects client: %w", err)
}
Expand Down Expand Up @@ -1736,7 +1738,7 @@ func (a *InitAction) getModelDeploymentDetails(ctx context.Context, model agent_
accountName = parts[8] // accounts/{account}
}

deploymentsClient, err := armcognitiveservices.NewDeploymentsClient(subscription, a.credential, nil)
deploymentsClient, err := armcognitiveservices.NewDeploymentsClient(subscription, a.credential, azure.NewArmClientOptions())
if err != nil {
return nil, fmt.Errorf("failed to create deployments client: %w", err)
}
Expand Down
29 changes: 1 addition & 28 deletions cli/azd/extensions/azure.ai.agents/internal/cmd/listen.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,14 @@ import (
"fmt"
"os"
"path/filepath"
"strconv"
"strings"
"time"

"azureaiagent/internal/pkg/agents/agent_yaml"
"azureaiagent/internal/pkg/azure"
"azureaiagent/internal/project"

azcorelog "github.com/Azure/azure-sdk-for-go/sdk/azcore/log"
"github.com/azure/azure-dev/cli/azd/pkg/azdext"
"github.com/braydonk/yaml"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"google.golang.org/protobuf/types/known/structpb"
)

Expand All @@ -34,19 +29,7 @@ func newListenCommand() *cobra.Command {
// Create a new context that includes the AZD access token.
ctx := azdext.WithAccessToken(cmd.Context())

if isDebug(cmd.Flags()) {
currentDate := time.Now().Format("2006-01-02")
logFileName := fmt.Sprintf("azd-ai-agents-%s.log", currentDate)

logFile, err := os.OpenFile(logFileName, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0644)
if err != nil {
logFile = os.Stderr
}
azcorelog.SetListener(func(event azcorelog.Event, msg string) {
msg = azure.ConnectionStringJSONRegex.ReplaceAllString(msg, `${1}"REDACTED"`)
fmt.Fprintf(logFile, "[%s] %s: %s\n", time.Now().Format(time.RFC3339), event, msg)
})
}
setupDebugLogging(cmd.Flags())

// Create a new AZD client.
azdClient, err := azdext.NewAzdClient()
Expand Down Expand Up @@ -334,13 +317,3 @@ func populateContainerSettings(ctx context.Context, azdClient *azdext.AzdClient,

return nil
}

// isDebug checks if debug mode is enabled via --debug flag or AZD_EXT_DEBUG environment variable
func isDebug(flags *pflag.FlagSet) bool {
if debugFlag, err := flags.GetBool("debug"); err == nil && debugFlag {
return true
}

debug, _ := strconv.ParseBool(os.Getenv("AZD_EXT_DEBUG"))
return debug
}
Loading
Loading