diff --git a/sdk_v2/js/script/install.cjs b/sdk_v2/js/script/install.cjs index f43f4f09..94d27a6b 100644 --- a/sdk_v2/js/script/install.cjs +++ b/sdk_v2/js/script/install.cjs @@ -55,7 +55,7 @@ const CORE_FEED = useNightly ? ORT_NIGHTLY_FEED : NUGET_FEED; const ARTIFACTS = [ { name: useWinML ? 'Microsoft.AI.Foundry.Local.Core.WinML' : 'Microsoft.AI.Foundry.Local.Core', - version: useNightly ? undefined : useWinML ? '0.9.0.7-dev.20260209T090407.b5352143' : '0.9.0.8-dev.20260209T090216.b5352143', // Set later using resolveLatestVersion if undefined + version: useNightly ? undefined : useWinML ? '0.9.0.170-dev-20260219T211559-2c971802' : '0.9.0.8-dev.20260209T090216.b5352143', // Set later using resolveLatestVersion if undefined feed: ORT_NIGHTLY_FEED }, { diff --git a/sdk_v2/js/src/detail/coreInterop.ts b/sdk_v2/js/src/detail/coreInterop.ts index d74c1c1a..a0040168 100644 --- a/sdk_v2/js/src/detail/coreInterop.ts +++ b/sdk_v2/js/src/detail/coreInterop.ts @@ -72,6 +72,44 @@ export class CoreInterop { if (process.platform === 'win32') { koffi.load(path.join(coreDir, `onnxruntime${ext}`)); koffi.load(path.join(coreDir, `onnxruntime-genai${ext}`)); + + // Load WinML libraries only if they exist (needed for NPU execution providers) + const winAppRuntimePath = path.join(coreDir, `Microsoft.WindowsAppRuntime${ext}`); + if (fs.existsSync(winAppRuntimePath)) { + koffi.load(winAppRuntimePath); + } else { + console.warn(`Microsoft.WindowsAppRuntime${ext} not found at ${winAppRuntimePath}, NPU execution providers may not be available`); + } + + const winAIMachineLearningPath = path.join(coreDir, `Microsoft.Windows.AI.MachineLearning${ext}`); + if (fs.existsSync(winAIMachineLearningPath)) { + koffi.load(winAIMachineLearningPath); + } else { + console.warn(`Microsoft.Windows.AI.MachineLearning${ext} not found at ${winAIMachineLearningPath}, NPU execution providers may not be available`); + } + + // Initialize the Windows App SDK bootstrapper so WinRT APIs (e.g. ExecutionProviderCatalog) + // can discover and download NPU execution providers. + const bootstrapPath = path.join(coreDir, 'Microsoft.WindowsAppRuntime.Bootstrap.dll'); + if (fs.existsSync(bootstrapPath)) { + const bootstrapLib = koffi.load(bootstrapPath); + const MddBootstrapInitialize2 = bootstrapLib.func( + 'int32_t MddBootstrapInitialize2(uint32_t majorMinorVersion, str16 versionTag, uint64_t minVersion, uint32_t options)' + ); + + // Windows App SDK 1.8 → major=1, minor=8 → 0x00010008 + const majorMinorVersion = 0x00010008; + const versionTag = null; // no tag + const minVersion = 0n; // accept any minimum version (BigInt for uint64) + const options = 0; // MddBootstrapInitializeOptions::None + + const hr = MddBootstrapInitialize2(majorMinorVersion, versionTag, minVersion, options); + if (hr !== 0) { + console.warn(`MddBootstrapInitialize2 failed with HRESULT: 0x${(hr >>> 0).toString(16)}`); + } + } else { + console.warn(`Microsoft.WindowsAppRuntime.Bootstrap.dll not found at ${bootstrapPath}, NPU execution providers may not be available`); + } } this.lib = koffi.load(corePath);