|
4 | 4 | package cmd |
5 | 5 |
|
6 | 6 | import ( |
| 7 | + "context" |
7 | 8 | "fmt" |
8 | 9 |
|
9 | 10 | "azureaiagent/internal/project" |
@@ -33,7 +34,37 @@ func newListenCommand() *cobra.Command { |
33 | 34 | WithServiceTarget(AiAgentHost, func() azdext.ServiceTargetProvider { |
34 | 35 | return project.NewAgentServiceTargetProvider(azdClient) |
35 | 36 | }). |
36 | | - WithProjectEventHandler("preprovision", projectParser.SetIdentity). |
| 37 | + WithProjectEventHandler("preprovision", func(ctx context.Context, args *azdext.ProjectEventArgs) error { |
| 38 | + if err := projectParser.SetIdentity(ctx, args); err != nil { |
| 39 | + return fmt.Errorf("failed to set identity: %w", err) |
| 40 | + } |
| 41 | + |
| 42 | + // TODO: Move this function into its own file |
| 43 | + for _, svc := range args.Project.Services { |
| 44 | + if svc.Host != "foundry.containeragent" { |
| 45 | + continue |
| 46 | + } |
| 47 | + |
| 48 | + var foundryAgentConfig *project.ServiceTargetAgentConfig |
| 49 | + if err := project.UnmarshalStruct(svc.Config, &foundryAgentConfig); err != nil { |
| 50 | + return fmt.Errorf("failed to parse foundry agent config: %w", err) |
| 51 | + } |
| 52 | + |
| 53 | + currentEnvResponse, err := azdClient.Environment().GetCurrent(ctx, &azdext.EmptyRequest{}) |
| 54 | + if err != nil { |
| 55 | + return err |
| 56 | + } |
| 57 | + |
| 58 | + // TODO: Generate and update any missing environment variables needed by the agent |
| 59 | + azdClient.Environment().SetValue(ctx, &azdext.SetEnvRequest{ |
| 60 | + EnvName: currentEnvResponse.Environment.Name, |
| 61 | + Key: "MISSING_KEY", |
| 62 | + Value: "MISSING_VALUE", |
| 63 | + }) |
| 64 | + } |
| 65 | + |
| 66 | + return nil |
| 67 | + }). |
37 | 68 | WithProjectEventHandler("postdeploy", projectParser.CoboPostDeploy) |
38 | 69 |
|
39 | 70 | // Start listening for events |
|
0 commit comments