1
+ <#
2
+ Run this script from the ACSAgentHub project folder (i.e., the one that has ACSAgentHub.csproj)
3
+ #>
4
+
5
+ # Requires -Version 6
6
+
7
+ Param (
8
+ [string ] $hubName ,
9
+ [string ] $resourceGroup ,
10
+ [string ] $location ,
11
+ [string ] $NuGetFullPath ,
12
+ [string ] $showCommands = " false" ,
13
+ [string ] $projDir = $ (Get-Location ),
14
+ [string ] $logFile = $ (Join-Path $PSScriptRoot .. " deploy_log.txt" )
15
+ )
16
+
17
+ # Get timestamp
18
+ $startTime = Get-Date
19
+
20
+ # Reset log file
21
+ if (Test-Path $logFile ) {
22
+ Clear-Content $logFile - Force | Out-Null
23
+ }
24
+ else {
25
+ New-Item - Path $logFile | Out-Null
26
+ }
27
+
28
+ # Get mandatory parameters
29
+ if (-not $hubName ) {
30
+ $hubName = Read-Host " ? Bot Name (used as default name for resource group and deployed resources)"
31
+ }
32
+
33
+ if (-not $resourceGroup ) {
34
+ $resourceGroup = $hubName
35
+ }
36
+
37
+ if (-not $location ) {
38
+ $location = Read-Host " ? Azure resource group region"
39
+ }
40
+
41
+ # Get timestamp
42
+ $timestamp = Get-Date - Format MMddyyyyHHmmss
43
+ $startTime = Get-Date
44
+
45
+ $solutionRoot = Get-Location
46
+ $currentDir = $solutionRoot
47
+ $agentPortalPath = " .\agent-portal"
48
+ $ACSAgentHubPath = " .\ACSAgentHub"
49
+ $errCnt = 0
50
+
51
+ # These steps follow the steps outlined in this solutions README in the "Manual Installation and Configuration" section
52
+ # Step 1 - When manually deploying the ACSAgentHub, the first step is to clone this repo so
53
+ # nothing to do in this step
54
+
55
+ # Step 2 - Deploy ACS Agent Hub
56
+ # No need for Write-Host progress update since deploy_acs_agent_hub.ps1 reports its own status
57
+ .\Deployment\Scripts\deploy_acs_agent_hub.ps1 - hubName $hubName - location $location - resourceGroup $resourceGroup - NuGetFullPAth $NuGetFullPath - showCommands $showCommands
58
+
59
+ # Step 3 - Start Agent Hub Service
60
+ Write-Host " Starting Agent Hub service" - NoNewline - ForegroundColor Green
61
+ # First, change working directory to the ACSAgentHub project folder
62
+ Set-Location $ACSAgentHubPath
63
+ start - FilePath " func" - ArgumentList " start" - WindowStyle Minimized
64
+ # Sleep before continuing to ensure Function App time is fully up and running or else Create Agent Account step will fail
65
+ Start-Sleep - s 120
66
+ if ($? ) {Write-Host " - Done." - ForegroundColor Green} else {Write-Host " - Failed" - ForegroundColor Green; $errCnt ++ }
67
+
68
+ Set-Location $solutionRoot
69
+
70
+ # Step 4 - Create Agent Accounts
71
+ Write-Host " Creating agent account for agent 1" - NoNewline - ForegroundColor Green
72
+ if ($showCommands.ToLower () -eq " true" ) { Write-Host ' ' ; Write-Host ' curl -X POST http://localhost:7071/api/agents -H \"Content-Type:application/json\" -d '' { \"id\": \"1\", \"name\": \"Agent 1\", \"status\": 1, \"skills\": [ \"skill 1\", \"skill 2\", \"skill 3\" ] }'' ' }
73
+ curl - X POST http:// localhost:7071 / api/ agents `
74
+ - H " Content-Type:application/json" `
75
+ - d ' {
76
+ \"id\": \"1\",
77
+ \"name\": \"Agent 1\",
78
+ \"status\": 1,
79
+ \"skills\": [ \"skill 1\", \"skill 2\", \"skill 3\" ]
80
+ }'
81
+
82
+ if ($? ) {Write-Host " - Done." - ForegroundColor Green} else {Write-Host " - Failed" - ForegroundColor Green; $errCnt ++ }
83
+
84
+ Write-Host " Creating agent account for agent 2" - NoNewline - ForegroundColor Green
85
+ if ($showCommands.ToLower () -eq " true" ) { Write-Host ' ' ; Write-Host ' curl -X POST http://localhost:7071/api/agents -H \"Content-Type:application/json\" -d '' { \"id\": \"2\", \"name\": \"Agent 2\", \"status\": 1, \"skills\": [ \"skill 1\", \"skill 2\", \"skill 3\" ] }'' ' }
86
+ curl - X POST http:// localhost:7071 / api/ agents `
87
+ - H " Content-Type:application/json" `
88
+ - d ' {
89
+ \"id\": \"2\",
90
+ \"name\": \"Agent 2\",
91
+ \"status\": 1,
92
+ \"skills\": [ \"skill 1\", \"skill 2\", \"skill 3\" ]
93
+ }'
94
+
95
+ if ($? ) {Write-Host " - Done." - ForegroundColor Green} else {Write-Host " - Failed" - ForegroundColor Green; $errCnt ++ }
96
+
97
+ # Step 5 - Create Tunnel to Agent Hub
98
+ Write-Host " Creating Tunnel to Agent Hub" - NoNewline - ForegroundColor Green
99
+ start - FilePath " c:\ngrok\ngrok" - ArgumentList " http 7071 -host-header=localhost:7071" - WindowStyle Minimized
100
+
101
+ if ($? ) {Write-Host " - Done." - ForegroundColor Green} else {Write-Host " - Failed" - ForegroundColor Green; $errCnt ++ }
102
+
103
+ # Sleep for a short bit while ngrok starts so we can ping it to get https endpoint
104
+ Start-Sleep - s 15 2>> " $logFile " | Out-Null
105
+
106
+ # Step 6 - Subscribe to ACS Message Event
107
+ # No need for Write-Host progress update since update_webhook.ps1 reports its own status
108
+ # Frist, query ngrok and turn JSON result into object that we can use to get https endpoint
109
+ $ngrokResult = curl http:// 127.0 .0.1 :4040 / api/ tunnels
110
+ $ngrok = ConvertFrom-Json $ngrokResult
111
+
112
+ # Next, loop through results find https endpoint (I don't want to assume it's always at the same index in results)
113
+ for ($i = 0 ; $i -lt $ngrok.tunnels.length ; $i ++ )
114
+ {
115
+ if ($ngrok.tunnels [$i ].proto -eq ' https' )
116
+ {
117
+ $httpsEndpoint = $ngrok.tunnels [$i ].proto
118
+ }
119
+ }
120
+
121
+ # Finally, if we were able to grab the https endpoint then use it to configure Event Grid to subscribe to message events
122
+ if ($httpsEndpoint )
123
+ {
124
+ .\Deployment\Scripts\update_webhook.ps1 - hubName $hubName - endpoint " $httpsEndpoint /api/agenthub/messagewebhook" - resourceGroup $resourceGroup - showCommands $showCommands
125
+ }
126
+ else
127
+ {
128
+ Write-Host " Subscribing to ACS Message Event - Failed" - ForegroundColor Green; $errCnt ++
129
+ }
130
+
131
+ # Step 7 - Install npm Packages
132
+ Write-Host " Installing npm Packages... this step takes awhile" - NoNewline - ForegroundColor Green
133
+ # First, switch to agent-portal folder
134
+ Set-Location $agentPortalPath
135
+
136
+ # Next, install npm packages
137
+ npm install 2>> " $logFile " | Out-Null
138
+
139
+ Write-Host " - Done." - ForegroundColor Green
140
+
141
+ # Step 8 - Launch Agent-Portal
142
+ # Launch agent-portal so its ready to use
143
+ Write-Host " Launching the agent portal in the browser. Note - initial app startup takes awhile" - ForegroundColor Green
144
+ Start-Sleep - s 2
145
+ start - FilePath " npm" - ArgumentList " start" - WindowStyle Minimized
146
+
147
+ # Fainally, switch to agent-hub project folder
148
+ Set-Location $solutionRoot
149
+
150
+ $endTime = Get-Date
151
+ $duration = New-TimeSpan $startTime $endTime
152
+ Write-Host " deploy_and_configure.ps1 took to $ ( $duration.minutes ) minutes finish"
153
+
154
+ Write-Host " Deployment and configuration completed with $errCnt errors"
0 commit comments