Edit

Call Phi Silica from JavaScript (JS bindings)

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:

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-codegen0.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:

Or explore other guides:

Additional Resources