@@ -592,6 +592,8 @@ function Ensure-AgentApi {
592592 Write-Host " [preview] + operation: $ ( $op.method ) $ ( $op.template ) ($ ( $op.name ) )"
593593 }
594594 }
595+ Write-Host " [preview] + API-level policy (CORS, timeout=120s, on-error)"
596+ Write-Host " [preview] + Operation-level streaming policy (invoke-stream, timeout=180s, buffer-response=false)"
595597 return
596598 }
597599
@@ -692,6 +694,36 @@ function Ensure-AgentApi {
692694 }
693695 Write-Host " Registered $ ( $serviceSpecificOperations [$Service ].Count) extra operations for $Service "
694696 }
697+
698+ # --- Apply API-level policy ---
699+ $subscriptionId = az account show -- query id - o tsv 2> $null
700+ if (-not $subscriptionId ) {
701+ throw " Failed to resolve Azure subscription id for agent API policy update ($Service )."
702+ }
703+
704+ $agentPolicyPath = Join-Path $PSScriptRoot ' ..\..\apim-policies\agent-api-policy.xml'
705+ if (Test-Path $agentPolicyPath ) {
706+ $corsOriginXml = Get-CorsOriginXml - OriginsCsv $ApimCorsAllowedOrigins
707+ $agentPolicyXml = (Get-Content - Path $agentPolicyPath - Raw) -replace ' \{\{cors-origins\}\}' , $corsOriginXml
708+ $policyPayload = @ { properties = @ { format = ' rawxml' ; value = $agentPolicyXml } } | ConvertTo-Json - Depth 8
709+ $policyTempFile = Join-Path ([System.IO.Path ]::GetTempPath()) " apim-agent-policy-$Service .json"
710+ Set-Content - Path $policyTempFile - Value $policyPayload - Encoding UTF8
711+ $policyUrl = " https://management.azure.com/subscriptions/$subscriptionId /resourceGroups/$Rg /providers/Microsoft.ApiManagement/service/$Apim /apis/$apiId /policies/policy?api-version=2022-08-01"
712+ az rest -- method put -- url $policyUrl -- headers ' Content-Type=application/json' -- body " @$policyTempFile " -- only- show-errors * > $null
713+ Write-Host " Applied API-level policy for $Service "
714+ }
715+
716+ # --- Apply operation-level streaming policy for /invoke/stream ---
717+ $streamPolicyPath = Join-Path $PSScriptRoot ' ..\..\apim-policies\agent-stream-operation-policy.xml'
718+ if (Test-Path $streamPolicyPath ) {
719+ $streamPolicyXml = Get-Content - Path $streamPolicyPath - Raw
720+ $streamPayload = @ { properties = @ { format = ' rawxml' ; value = $streamPolicyXml } } | ConvertTo-Json - Depth 8
721+ $streamTempFile = Join-Path ([System.IO.Path ]::GetTempPath()) " apim-agent-stream-policy-$Service .json"
722+ Set-Content - Path $streamTempFile - Value $streamPayload - Encoding UTF8
723+ $streamOpUrl = " https://management.azure.com/subscriptions/$subscriptionId /resourceGroups/$Rg /providers/Microsoft.ApiManagement/service/$Apim /apis/$apiId /operations/invoke-stream/policies/policy?api-version=2022-08-01"
724+ az rest -- method put -- url $streamOpUrl -- headers ' Content-Type=application/json' -- body " @$streamTempFile " -- only- show-errors * > $null
725+ Write-Host " Applied streaming operation policy for $Service "
726+ }
695727}
696728
697729function Update-CrudApi {
0 commit comments