Kun Extension Examples

July 16, 2026 ยท View on GitHub

These examples exercise the stable @kun/extension-api surface without importing Kun runtime, renderer, Electron, or private HTTP/IPC modules.

ExampleWhat it demonstratesEntry shape
hello-sidebarSandboxed right-sidebar View, theme, locale, and persisted View stateBrowser/Webview
workspace-dashboardEditor dashboard, namespaced command, workspace reads, storage, and Host messagesNode + Webview
agent-assistantExtension-owned Agent run, replayable events, cancellation, and owned thread historyNode + Webview
presentation-studioRevisioned standalone HTML slides, visual editing, typed Agent operations, and safe projectionNode + Webview
social-media-sidebarStateful desktop/mobile browser pages for Douyin, Bilibili, and XiaohongshuBrowser/WebContentsView
tool-providerNamespaced typed tool, progress, cancellation, and workspace accessNode/headless
streaming-model-providerAPI-key and OAuth account bindings, normalized model streaming, usage, cancellation, and no-fallback errorsNode/headless
direct-domHigh-risk isolated-world content script with bounded, failure-tolerant DOM changesNode + content script
kun-video-editorReference v1.1 right-sidebar View, protected media, Agent tools, jobs, and generated artifactsNode + Webview

Repository checkout

Install and build from the repository root, then build and validate an example:

npm ci
npm run build --workspace @kun/extension-api
npm run build:kun
npm --prefix examples/extensions/hello-sidebar run typecheck
npm --prefix examples/extensions/hello-sidebar run build
node examples/extensions/validate-manifest.mjs \
  examples/extensions/hello-sidebar/kun-extension.json

Once the Kun extension CLI is available, every package also follows the normal scaffolder workflow:

npm --prefix examples/extensions/hello-sidebar run validate
npm --prefix examples/extensions/hello-sidebar run pack

The validate and pack scripts deliberately use run-repository-kun-cli.mjs. It resolves kun/dist/cli/serve-entry.js from the helper's own location, so repository validation never depends on the caller's working directory or an unrelated executable on PATH. Build Kun first; these repository scripts are not the standalone distribution path.

The Webview examples use Vite to bundle the public API client into confined relative assets. check:extension-examples inspects the generated HTML and JavaScript so a bare npm import cannot accidentally ship to Chromium.

Standalone and public-registry setup

A standalone extension uses the Kun CLI shipped with a Kun installation and published SDK packages by their package names. Before running a scaffolder or npm install, verify that the packages required by the chosen template exist in the configured registry:

kun extension --help
npm view create-kun-extension version
npm view @kun/extension-api version
npm view @kun/extension-react version
npm view @kun/extension-test version

Continue only when the required commands return versions. E404 means that registry cannot currently provide the standalone artifacts; use the repository workflow above instead. Do not replace public dependencies with repository file: paths in a project meant to be portable. The unscoped npm package named kun is unrelated to the Kun Agent CLI and must not be used as a substitute.

Security notes

  • Webviews receive only window.kunExtension; they do not use window.kunGui.
  • The Tool and Provider examples also run under kun serve or supported CLI flows without Electron.
  • The Provider example never receives a credential value. It checks an account reference and leaves credential collection to Kun-owned protected UI.
  • direct-dom is intentionally high risk and unsupported by Extension API SemVer. Prefer a stable View contribution whenever possible.