Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
This guide shows how to call the Windows App SDK Phi Silica text summarization API directly from Electron JavaScript by using generated JS bindings.
Prerequisites
Before starting this guide, make sure you've:
- Completed the development environment setup.
- Tested on a Copilot+ PC. Phi Silica requires hardware that supports the local language model.
Step 1: Add the AI capability
Phi Silica requires the systemAIModels restricted capability. Add it to Package.appxmanifest inside <Capabilities>:
<Capabilities>
<rescap:Capability Name="runFullTrust" />
<rescap:Capability Name="systemAIModels" />
</Capabilities>
After changing the manifest, refresh debug identity:
npx winapp node add-electron-debug-identity
Step 2: Call Phi Silica from the Electron main process
Import the generated bindings through #winapp/bindings, create a TextSummarizer, and call it at the end of createWindow() to verify everything works:
Requires
@microsoft/dynwinrt-codegen≥0.1.0-preview.8— see Get started with Electron for older-project fallbacks.
// src/index.js (Electron main, CommonJS)
const {
AIFeatureReadyState,
LanguageModel,
TextSummarizer,
} = require('#winapp/bindings');
const callPhiSilica = async () => {
console.log('Summarizing with Phi Silica:');
const readyState = LanguageModel.getReadyState();
if (readyState !== AIFeatureReadyState.Ready && readyState !== AIFeatureReadyState.NotReady) {
console.log('Summary: Model is not available');
return;
}
if (readyState === AIFeatureReadyState.NotReady) {
await LanguageModel.ensureReadyAsync();
}
const languageModel = await LanguageModel.createAsync();
try {
const summarizer = TextSummarizer.createInstance(languageModel);
const result = await summarizer.summarizeParagraphAsync(
"The Windows App Development CLI lets Electron apps call Windows-native APIs from JavaScript. Package identity enables features such as notifications and background tasks."
);
console.log('Summary:', result.text);
} finally {
languageModel.close();
}
};
const createWindow = () => {
// ... existing window creation code ...
// Test the Phi Silica AI API
callPhiSilica();
};
Note
getReadyState() returns one of Ready, NotReady, DisabledByUser, or NotSupportedOnCurrentSystem. Calling ensureReadyAsync() triggers the system to download/initialize the model if it isn't ready yet.
Step 3: Run it
npm start
Check the console output — you should see the Phi Silica summary printed!
If the model is unavailable on the device, the function logs "Summary: Model is not available". Make sure you're running on supported hardware (Copilot+ PC) and that the manifest includes systemAIModels.
From here, you can integrate the summarizer into your app however you'd like — exposing it through a preload script to the renderer, wiring it to IPC handlers, or calling it directly in the main process.
Next Steps
Congratulations! You're now calling Phi Silica directly from JavaScript — no C# addon, no node-gyp build step. 🎉
Now you're ready to:
- Package Your App for Distribution — produce an MSIX you can ship (the
@microsoft/dynwinrtruntime is already in yourdependencies).
Or explore other guides:
- Show a Notification from JavaScript — show a Windows App SDK notification through JS bindings.
- Call Windows APIs from JavaScript — pick a file and read its image dimensions using JS bindings.
- Run WinML from JavaScript — use Windows App SDK ML provider discovery with
onnxruntime-node. - Creating a Phi Silica Addon — native C# addon counterpart.
- Getting Started Overview — return to the main guide.
Additional Resources
- winapp CLI Documentation — full CLI reference (
init,restore,node generate-bindings). - Sample Electron App — complete working example, including JS bindings.
- @microsoft/dynwinrt — the runtime that powers the generated bindings.
- @microsoft/dynwinrt-codegen — the code generator.
Windows developer