private/FoundationaLLM-Plugin.ps1
|
function Get-PackageRuntimeName { param ( [string]$Platform ) switch -Regex ($Platform) { '^(?i)dotnet$' { return 'Dotnet' } '^(?i)python$' { return 'Python' } '^(?i)foundationallm$' { return 'FoundationaLLM' } default { throw "Unsupported package runtime: $Platform" } } } function Merge-StorePackage { param ( [string]$ResourceType, [string]$PackageName, [string]$PackageRuntime, [string]$PackageVersion, [string]$PackageStoreType = 'Public' ) if ([string]::IsNullOrWhiteSpace($PackageStoreType)) { $PackageStoreType = 'Public' } $body = [ordered]@{ type = $ResourceType name = $PackageName package_runtime = (Get-PackageRuntimeName -Platform $PackageRuntime) package_version = $PackageVersion package_store_type = $PackageStoreType } $resourceTypeName = if ($ResourceType -eq 'artifact-package') { 'artifactPackages' } else { 'pluginPackages' } Invoke-ManagementAPI ` -Method POST ` -RelativeUri "providers/FoundationaLLM.Platform/$resourceTypeName/$PackageName" ` -Body $body } function Merge-PluginPackage { param ( [string]$Platform, [string]$PackageName, [string]$PublishedPackageName, [string]$PublishedPackageVersion, [string]$PackagePath, [string]$PackageStoreType ) if ($PackageStoreType -or (-not $PackagePath -and -not $PublishedPackageName)) { return Merge-StorePackage ` -ResourceType 'plugin-package' ` -PackageName $PackageName ` -PackageRuntime $Platform ` -PackageVersion $PublishedPackageVersion ` -PackageStoreType $PackageStoreType } if (-not $PackagePath) { if ($Platform -eq "python") { $packageMetadata = Invoke-RestMethod -Uri "https://pypi.org/pypi/$PublishedPackageName/$PublishedPackageVersion/json" $wheelEntry = $packageMetadata.urls | Where-Object { $_.packagetype -eq 'bdist_wheel' } | Select-Object -First 1 $PackagePath = Join-Path ([System.IO.Path]::GetTempPath()) (Split-Path $wheelEntry.url -Leaf) Invoke-RestMethod -Uri $wheelEntry.url -OutFile $PackagePath } elseif ($Platform -eq "dotnet") { $nugetUrl = "https://api.nuget.org/v3-flatcontainer/$PublishedPackageName/$PublishedPackageVersion/$PublishedPackageName.$PublishedPackageVersion.nupkg" $PackagePath = Join-Path "$([System.IO.Path]::GetTempPath())" "$PublishedPackageName.$PublishedPackageVersion.nupkg" Invoke-RestMethod -Uri $nugetUrl -OutFile $PackagePath } else { throw "Unsupported platform: $Platform" } } $form = @{ file = Get-Item -Path $PackagePath resource = "{`"type`": `"plugin-package`",`"name`": `"$PackageName`"}" } Invoke-ManagementAPI ` -Method POST ` -RelativeUri "providers/FoundationaLLM.Platform/pluginPackages/$($PackageName)" ` -Form $form } function Merge-ArtifactPackage { param ( [string]$PackageName, [string]$PackageVersion, [string]$PackageStoreType = 'Public', [string]$PackageRuntime = 'FoundationaLLM' ) Merge-StorePackage ` -ResourceType 'artifact-package' ` -PackageName $PackageName ` -PackageRuntime $PackageRuntime ` -PackageVersion $PackageVersion ` -PackageStoreType $PackageStoreType } |