@adea-ai/app-framework 0.0.0-stage → 0.24.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (358) hide show
  1. package/LICENSE +201 -0
  2. package/NOTICE +30 -0
  3. package/README.md +1009 -2
  4. package/dist/app/application.d.ts +47 -0
  5. package/dist/app/application.js +115 -0
  6. package/dist/app/create-application.d.ts +13 -0
  7. package/dist/app/create-application.js +178 -0
  8. package/dist/app/service-registry.d.ts +44 -0
  9. package/dist/app/service-registry.js +116 -0
  10. package/dist/appearance/appearance-host.d.ts +62 -0
  11. package/dist/appearance/appearance-host.js +115 -0
  12. package/dist/appearance/appearance-preferences.d.ts +106 -0
  13. package/dist/appearance/appearance-preferences.js +175 -0
  14. package/dist/appearance/composition.d.ts +11 -0
  15. package/dist/appearance/composition.js +16 -0
  16. package/dist/appearance/custom-theme-import.d.ts +14 -0
  17. package/dist/appearance/custom-theme-import.js +315 -0
  18. package/dist/appearance/custom-theme-library.d.ts +146 -0
  19. package/dist/appearance/custom-theme-library.js +378 -0
  20. package/dist/appearance/editor.d.ts +20 -0
  21. package/dist/appearance/editor.js +47 -0
  22. package/dist/appearance/theme-file-importer.d.ts +23 -0
  23. package/dist/appearance/theme-file-importer.js +66 -0
  24. package/dist/appearance/theme-record-adapter.d.ts +26 -0
  25. package/dist/appearance/theme-record-adapter.js +64 -0
  26. package/dist/appearance/theme-registry.d.ts +10 -0
  27. package/dist/appearance/theme-registry.js +16 -0
  28. package/dist/appearance/window-surface.d.ts +5 -0
  29. package/dist/appearance/window-surface.js +9 -0
  30. package/dist/ci/toolchain-identity.d.ts +39 -0
  31. package/dist/ci/toolchain-identity.js +196 -0
  32. package/dist/cli/cef-helper-cli.d.ts +2 -0
  33. package/dist/cli/cef-helper-cli.js +18 -0
  34. package/dist/cli/cli-runner.d.ts +8 -0
  35. package/dist/cli/cli-runner.js +23 -0
  36. package/dist/cli/create-application-cli.d.ts +2 -0
  37. package/dist/cli/create-application-cli.js +40 -0
  38. package/dist/cli/electrobun-shortcut-patch-cli.d.ts +2 -0
  39. package/dist/cli/electrobun-shortcut-patch-cli.js +17 -0
  40. package/dist/cli/framework-update-cli.d.ts +2 -0
  41. package/dist/cli/framework-update-cli.js +40 -0
  42. package/dist/cli/release-assets-plan-cli.d.ts +2 -0
  43. package/dist/cli/release-assets-plan-cli.js +14 -0
  44. package/dist/cli/release-cut-cli.d.ts +2 -0
  45. package/dist/cli/release-cut-cli.js +27 -0
  46. package/dist/cli/release-descriptor-staging-cli.d.ts +2 -0
  47. package/dist/cli/release-descriptor-staging-cli.js +45 -0
  48. package/dist/cli/release-finalize-cli.d.ts +1 -0
  49. package/dist/cli/release-finalize-cli.js +30 -0
  50. package/dist/cli/release-promote-cli.d.ts +2 -0
  51. package/dist/cli/release-promote-cli.js +32 -0
  52. package/dist/cli/release-publish-cli.d.ts +2 -0
  53. package/dist/cli/release-publish-cli.js +48 -0
  54. package/dist/cli/release-sign-cli.d.ts +2 -0
  55. package/dist/cli/release-sign-cli.js +13 -0
  56. package/dist/cli/release-step-cli.d.ts +2 -0
  57. package/dist/cli/release-step-cli.js +44 -0
  58. package/dist/cli/toolchain-identity-cli.d.ts +2 -0
  59. package/dist/cli/toolchain-identity-cli.js +10 -0
  60. package/dist/cli/update-helper-cli.d.ts +1 -0
  61. package/dist/cli/update-helper-cli.js +10 -0
  62. package/dist/cli/windows-runtime-patch-cli.d.ts +2 -0
  63. package/dist/cli/windows-runtime-patch-cli.js +17 -0
  64. package/dist/desktop/application-command-client.d.ts +15 -0
  65. package/dist/desktop/application-command-client.js +21 -0
  66. package/dist/desktop/channel-handshake.d.ts +32 -0
  67. package/dist/desktop/channel-handshake.js +111 -0
  68. package/dist/desktop/channel-proof.d.ts +43 -0
  69. package/dist/desktop/channel-proof.js +85 -0
  70. package/dist/desktop/client-assets.d.ts +7 -0
  71. package/dist/desktop/client-assets.js +59 -0
  72. package/dist/desktop/desktop-client.d.ts +23 -0
  73. package/dist/desktop/desktop-client.js +231 -0
  74. package/dist/desktop/desktop-gateway.d.ts +18 -0
  75. package/dist/desktop/desktop-gateway.js +146 -0
  76. package/dist/desktop/desktop-host.d.ts +48 -0
  77. package/dist/desktop/desktop-host.js +208 -0
  78. package/dist/desktop/desktop-stream.d.ts +36 -0
  79. package/dist/desktop/desktop-stream.js +231 -0
  80. package/dist/desktop/loopback-policy.d.ts +19 -0
  81. package/dist/desktop/loopback-policy.js +23 -0
  82. package/dist/desktop/open-url-channel.d.ts +15 -0
  83. package/dist/desktop/open-url-channel.js +55 -0
  84. package/dist/desktop/string-policy.d.ts +2 -0
  85. package/dist/desktop/string-policy.js +11 -0
  86. package/dist/framework-source.json +1 -0
  87. package/dist/installer/archive-entry.d.ts +6 -0
  88. package/dist/installer/archive-entry.js +14 -0
  89. package/dist/installer/command-artifact.d.ts +47 -0
  90. package/dist/installer/command-artifact.js +261 -0
  91. package/dist/installer/command-qualification-command.d.ts +12 -0
  92. package/dist/installer/command-qualification-command.js +71 -0
  93. package/dist/installer/hosted-runner.d.ts +4 -0
  94. package/dist/installer/hosted-runner.js +10 -0
  95. package/dist/installer/installed-payload.d.ts +29 -0
  96. package/dist/installer/installed-payload.js +312 -0
  97. package/dist/installer/installer-ci-bootstrap.d.ts +26 -0
  98. package/dist/installer/installer-ci-bootstrap.js +160 -0
  99. package/dist/installer/installer-ci-preflight.d.ts +1 -0
  100. package/dist/installer/installer-ci-preflight.js +49 -0
  101. package/dist/installer/installer-ci-worker.d.ts +1 -0
  102. package/dist/installer/installer-ci-worker.js +105 -0
  103. package/dist/installer/installer-extraction.d.ts +14 -0
  104. package/dist/installer/installer-extraction.js +289 -0
  105. package/dist/installer/installer-fetch-guard.d.ts +15 -0
  106. package/dist/installer/installer-fetch-guard.js +50 -0
  107. package/dist/installer/installer-identity.d.ts +23 -0
  108. package/dist/installer/installer-identity.js +286 -0
  109. package/dist/installer/installer-layout.d.ts +21 -0
  110. package/dist/installer/installer-layout.js +89 -0
  111. package/dist/installer/installer-observation.d.ts +64 -0
  112. package/dist/installer/installer-observation.js +473 -0
  113. package/dist/installer/installer-process-cleanup.d.ts +18 -0
  114. package/dist/installer/installer-process-cleanup.js +158 -0
  115. package/dist/installer/installer-qualification-command.d.ts +11 -0
  116. package/dist/installer/installer-qualification-command.js +71 -0
  117. package/dist/installer/installer-renderer-evidence.d.ts +43 -0
  118. package/dist/installer/installer-renderer-evidence.js +136 -0
  119. package/dist/installer/installer-upgrade-command.d.ts +37 -0
  120. package/dist/installer/installer-upgrade-command.js +172 -0
  121. package/dist/installer/installer-worker-guard.d.ts +21 -0
  122. package/dist/installer/installer-worker-guard.js +72 -0
  123. package/dist/installer/native-executable.d.ts +5 -0
  124. package/dist/installer/native-executable.js +21 -0
  125. package/dist/installer/upgrade-asset-download.d.ts +13 -0
  126. package/dist/installer/upgrade-asset-download.js +41 -0
  127. package/dist/installer/write-all.d.ts +6 -0
  128. package/dist/installer/write-all.js +11 -0
  129. package/dist/native/app-bundle.d.ts +28 -0
  130. package/dist/native/app-bundle.js +60 -0
  131. package/dist/native/cef-helper.d.ts +28 -0
  132. package/dist/native/cef-helper.js +402 -0
  133. package/dist/native/desktop-build-hook.d.ts +7 -0
  134. package/dist/native/desktop-build-hook.js +20 -0
  135. package/dist/native/electrobun-source-patch.d.ts +25 -0
  136. package/dist/native/electrobun-source-patch.js +93 -0
  137. package/dist/native/linux-cef-links.d.ts +2 -0
  138. package/dist/native/linux-cef-links.js +15 -0
  139. package/dist/native/native-secret-store.d.ts +27 -0
  140. package/dist/native/native-secret-store.js +70 -0
  141. package/dist/native/native-utilities.d.ts +24 -0
  142. package/dist/native/native-utilities.js +85 -0
  143. package/dist/native/partitioned-window.d.ts +34 -0
  144. package/dist/native/partitioned-window.js +44 -0
  145. package/dist/native/renderer-profile.d.ts +53 -0
  146. package/dist/native/renderer-profile.js +30 -0
  147. package/dist/native/secure-window.d.ts +38 -0
  148. package/dist/native/secure-window.js +77 -0
  149. package/dist/native/sidecar-services.d.ts +23 -0
  150. package/dist/native/sidecar-services.js +46 -0
  151. package/dist/native/sidecar.d.ts +81 -0
  152. package/dist/native/sidecar.js +250 -0
  153. package/dist/native/window-bootstrap.d.ts +24 -0
  154. package/dist/native/window-bootstrap.js +63 -0
  155. package/dist/native/window-options.d.ts +32 -0
  156. package/dist/native/window-options.js +23 -0
  157. package/dist/native/windows-build-hook-internal.d.ts +2 -0
  158. package/dist/native/windows-build-hook-internal.js +32 -0
  159. package/dist/native/windows-build-hook.d.ts +2 -0
  160. package/dist/native/windows-build-hook.js +12 -0
  161. package/dist/native/windows-runtime-patch-internal.d.ts +3 -0
  162. package/dist/native/windows-runtime-patch-internal.js +20 -0
  163. package/dist/native/windows-runtime-patch.d.ts +4 -0
  164. package/dist/native/windows-runtime-patch.js +12 -0
  165. package/dist/release/feed-release-cut.d.ts +23 -0
  166. package/dist/release/feed-release-cut.js +93 -0
  167. package/dist/release/feed-state.d.ts +25 -0
  168. package/dist/release/feed-state.js +81 -0
  169. package/dist/release/framework-package-publish.d.ts +21 -0
  170. package/dist/release/framework-package-publish.js +127 -0
  171. package/dist/release/framework-update.d.ts +30 -0
  172. package/dist/release/framework-update.js +139 -0
  173. package/dist/release/github-cli.d.ts +6 -0
  174. package/dist/release/github-cli.js +16 -0
  175. package/dist/release/github-release-assets.d.ts +3 -0
  176. package/dist/release/github-release-assets.js +24 -0
  177. package/dist/release/github-release-cut.d.ts +14 -0
  178. package/dist/release/github-release-cut.js +174 -0
  179. package/dist/release/github-release-lookup.d.ts +7 -0
  180. package/dist/release/github-release-lookup.js +29 -0
  181. package/dist/release/github-release-promotion.d.ts +10 -0
  182. package/dist/release/github-release-promotion.js +78 -0
  183. package/dist/release/github-release-provenance.d.ts +9 -0
  184. package/dist/release/github-release-provenance.js +27 -0
  185. package/dist/release/github-release-publisher.d.ts +9 -0
  186. package/dist/release/github-release-publisher.js +63 -0
  187. package/dist/release/github-release-qualification.d.ts +12 -0
  188. package/dist/release/github-release-qualification.js +80 -0
  189. package/dist/release/local-provenance.d.ts +24 -0
  190. package/dist/release/local-provenance.js +72 -0
  191. package/dist/release/local-release.d.ts +133 -0
  192. package/dist/release/local-release.js +387 -0
  193. package/dist/release/macos-dmg.d.ts +22 -0
  194. package/dist/release/macos-dmg.js +91 -0
  195. package/dist/release/release-artifact.d.ts +6 -0
  196. package/dist/release/release-artifact.js +38 -0
  197. package/dist/release/release-assets-plan.d.ts +14 -0
  198. package/dist/release/release-assets-plan.js +65 -0
  199. package/dist/release/release-config.d.ts +76 -0
  200. package/dist/release/release-config.js +180 -0
  201. package/dist/release/release-cut-command.d.ts +13 -0
  202. package/dist/release/release-cut-command.js +39 -0
  203. package/dist/release/release-cut.d.ts +54 -0
  204. package/dist/release/release-cut.js +76 -0
  205. package/dist/release/release-descriptor-staging.d.ts +34 -0
  206. package/dist/release/release-descriptor-staging.js +147 -0
  207. package/dist/release/release-finalize.d.ts +16 -0
  208. package/dist/release/release-finalize.js +104 -0
  209. package/dist/release/release-promotion-command.d.ts +12 -0
  210. package/dist/release/release-promotion-command.js +28 -0
  211. package/dist/release/release-promotion.d.ts +29 -0
  212. package/dist/release/release-promotion.js +57 -0
  213. package/dist/release/release-publication.d.ts +33 -0
  214. package/dist/release/release-publication.js +138 -0
  215. package/dist/release/release-publish-command.d.ts +7 -0
  216. package/dist/release/release-publish-command.js +91 -0
  217. package/dist/release/release-qualification.d.ts +106 -0
  218. package/dist/release/release-qualification.js +135 -0
  219. package/dist/release/release-staging.d.ts +9 -0
  220. package/dist/release/release-staging.js +61 -0
  221. package/dist/release/release-steps.d.ts +38 -0
  222. package/dist/release/release-steps.js +147 -0
  223. package/dist/release/retained-release-build.d.ts +19 -0
  224. package/dist/release/retained-release-build.js +122 -0
  225. package/dist/shell/app-shell.d.ts +61 -0
  226. package/dist/shell/app-shell.js +306 -0
  227. package/dist/shell/app-utilities.d.ts +122 -0
  228. package/dist/shell/app-utilities.js +334 -0
  229. package/dist/shell/application-menu-commands.d.ts +5 -0
  230. package/dist/shell/application-menu-commands.js +11 -0
  231. package/dist/shell/application-menu.d.ts +61 -0
  232. package/dist/shell/application-menu.js +208 -0
  233. package/dist/shell/help-shortcuts.d.ts +12 -0
  234. package/dist/shell/help-shortcuts.js +22 -0
  235. package/dist/shell/navigation-drawer.d.ts +12 -0
  236. package/dist/shell/navigation-drawer.js +42 -0
  237. package/dist/shell/settings-sections.d.ts +31 -0
  238. package/dist/shell/settings-sections.js +50 -0
  239. package/dist/shell/shortcut-platform.d.ts +17 -0
  240. package/dist/shell/shortcut-platform.js +25 -0
  241. package/dist/update-helper.bundle.js +260 -0
  242. package/dist/updates/channel-update-manager.d.ts +46 -0
  243. package/dist/updates/channel-update-manager.js +114 -0
  244. package/dist/updates/desktop-updater.d.ts +104 -0
  245. package/dist/updates/desktop-updater.js +345 -0
  246. package/dist/updates/release-feed.d.ts +61 -0
  247. package/dist/updates/release-feed.js +111 -0
  248. package/dist/updates/release-location.d.ts +9 -0
  249. package/dist/updates/release-location.js +80 -0
  250. package/dist/updates/release-version.d.ts +12 -0
  251. package/dist/updates/release-version.js +43 -0
  252. package/dist/updates/signed-release.d.ts +63 -0
  253. package/dist/updates/signed-release.js +162 -0
  254. package/dist/updates/stable-file.d.ts +10 -0
  255. package/dist/updates/stable-file.js +22 -0
  256. package/dist/updates/update-adapter.d.ts +57 -0
  257. package/dist/updates/update-adapter.js +72 -0
  258. package/dist/updates/update-arm.d.ts +24 -0
  259. package/dist/updates/update-arm.js +95 -0
  260. package/dist/updates/update-channel-store.d.ts +8 -0
  261. package/dist/updates/update-channel-store.js +72 -0
  262. package/dist/updates/update-discovery.d.ts +13 -0
  263. package/dist/updates/update-discovery.js +56 -0
  264. package/dist/updates/update-download.d.ts +14 -0
  265. package/dist/updates/update-download.js +67 -0
  266. package/dist/updates/update-exclusive-rename.d.ts +2 -0
  267. package/dist/updates/update-exclusive-rename.js +52 -0
  268. package/dist/updates/update-extraction.d.ts +18 -0
  269. package/dist/updates/update-extraction.js +183 -0
  270. package/dist/updates/update-handoff-plan.d.ts +22 -0
  271. package/dist/updates/update-handoff-plan.js +28 -0
  272. package/dist/updates/update-helper.d.ts +24 -0
  273. package/dist/updates/update-helper.js +56 -0
  274. package/dist/updates/update-launch.d.ts +5 -0
  275. package/dist/updates/update-launch.js +27 -0
  276. package/dist/updates/update-manager.d.ts +40 -0
  277. package/dist/updates/update-manager.js +83 -0
  278. package/dist/updates/update-process-fence.d.ts +10 -0
  279. package/dist/updates/update-process-fence.js +114 -0
  280. package/dist/updates/update-resume.d.ts +13 -0
  281. package/dist/updates/update-resume.js +34 -0
  282. package/dist/updates/update-shutdown.d.ts +15 -0
  283. package/dist/updates/update-shutdown.js +29 -0
  284. package/dist/updates/update-state.d.ts +30 -0
  285. package/dist/updates/update-state.js +18 -0
  286. package/dist/updates/update-swap-stage.d.ts +27 -0
  287. package/dist/updates/update-swap-stage.js +58 -0
  288. package/dist/updates/update-swap.d.ts +10 -0
  289. package/dist/updates/update-swap.js +30 -0
  290. package/dist/views/app-about.d.ts +22 -0
  291. package/dist/views/app-about.js +43 -0
  292. package/dist/views/app-appearance.d.ts +11 -0
  293. package/dist/views/app-appearance.js +42 -0
  294. package/dist/views/app-help.d.ts +17 -0
  295. package/dist/views/app-help.js +42 -0
  296. package/dist/views/app-settings.d.ts +26 -0
  297. package/dist/views/app-settings.js +97 -0
  298. package/dist/views/appearance-surface.d.ts +9 -0
  299. package/dist/views/appearance-surface.js +334 -0
  300. package/dist/views/update-surface.d.ts +34 -0
  301. package/dist/views/update-surface.js +64 -0
  302. package/package.json +374 -4
  303. package/src/app/application.tsx +138 -0
  304. package/src/appearance/appearance-host.tsx +205 -0
  305. package/src/appearance/appearance-preferences.ts +287 -0
  306. package/src/appearance/composition.ts +29 -0
  307. package/src/appearance/custom-theme-import.ts +424 -0
  308. package/src/appearance/custom-theme-library.ts +600 -0
  309. package/src/appearance/editor.ts +94 -0
  310. package/src/appearance/theme-file-importer.ts +103 -0
  311. package/src/appearance/theme-record-adapter.ts +106 -0
  312. package/src/appearance/theme-registry.ts +20 -0
  313. package/src/appearance/window-surface.ts +18 -0
  314. package/src/desktop/client-assets.ts +75 -0
  315. package/src/native/electrobun-cef-main-frame-bridges.patch +63 -0
  316. package/src/native/electrobun-windows-shortcut-com.patch +923 -0
  317. package/src/native/renderer-profile.ts +27 -0
  318. package/src/native/window-options.ts +24 -0
  319. package/src/shell/app-shell.tsx +294 -0
  320. package/src/shell/app-utilities.tsx +437 -0
  321. package/src/shell/help-shortcuts.ts +24 -0
  322. package/src/shell/navigation-drawer.tsx +36 -0
  323. package/src/shell/settings-sections.ts +74 -0
  324. package/src/shell/shortcut-platform.ts +35 -0
  325. package/src/updates/release-version.ts +57 -0
  326. package/src/updates/update-adapter.ts +129 -0
  327. package/src/updates/update-state.ts +34 -0
  328. package/src/views/app-about.tsx +44 -0
  329. package/src/views/app-appearance.tsx +32 -0
  330. package/src/views/app-help.tsx +43 -0
  331. package/src/views/app-settings.tsx +88 -0
  332. package/src/views/appearance-surface.tsx +427 -0
  333. package/src/views/update-surface.tsx +85 -0
  334. package/templates/application/.gitattributes +1 -0
  335. package/templates/application/.github/workflows/release-assets.yml +29 -0
  336. package/templates/application/.github/workflows/release-finalize.yml +29 -0
  337. package/templates/application/.github/workflows/release-please.yml +19 -0
  338. package/templates/application/.github/workflows/release.yml +29 -0
  339. package/templates/application/.github/workflows/validation.yml +28 -0
  340. package/templates/application/.oxfmtrc.json +6 -0
  341. package/templates/application/.oxlintrc.json +48 -0
  342. package/templates/application/.release-please-manifest.json +3 -0
  343. package/templates/application/README.md +47 -0
  344. package/templates/application/electrobun.config.ts +22 -0
  345. package/templates/application/release-please-config.json +12 -0
  346. package/templates/application/scripts/app-version.ts +9 -0
  347. package/templates/application/scripts/build-desktop.ts +34 -0
  348. package/templates/application/scripts/secure-build.ts +1 -0
  349. package/templates/application/scripts/stage-release.ts +21 -0
  350. package/templates/application/src/bun/index.ts +80 -0
  351. package/templates/application/src/electrobun.d.ts +27 -0
  352. package/templates/application/src/web/index.html +12 -0
  353. package/templates/application/src/web/main.tsx +97 -0
  354. package/templates/application/src/web/public/icon.svg +1 -0
  355. package/templates/application/src/web/style.css +3 -0
  356. package/templates/application/tests/app-config.test.ts +9 -0
  357. package/templates/application/tsconfig.json +15 -0
  358. package/templates/application/vite.config.ts +10 -0
@@ -0,0 +1,24 @@
1
+ import type { createServiceRegistry } from '../app/service-registry';
2
+ type Utility = 'info' | 'open-external' | 'pick-folder' | 'pick-files';
3
+ /** What the web side may ask an open-file dialog for. Electrobun 2.0.5 has no save dialog. */
4
+ export type PickFilesRequest = Readonly<{
5
+ startingFolder?: string;
6
+ /** File extensions without the dot, e.g. `['png', 'jpg']`; omitted allows any file. */
7
+ extensions?: readonly string[];
8
+ multiple: boolean;
9
+ }>;
10
+ /** Register shared native utilities behind the host's authenticated principal and policy. */
11
+ export declare function registerNativeUtilities<Principal>(options: {
12
+ services: ReturnType<typeof createServiceRegistry<Principal>>;
13
+ info: Readonly<{
14
+ name: string;
15
+ version: string;
16
+ platform: string;
17
+ }>;
18
+ authorize(principal: Principal, utility: Utility): boolean | Promise<boolean>;
19
+ openExternal(url: string): boolean | Promise<boolean>;
20
+ pickFolder(startingFolder?: string): Promise<readonly string[]>;
21
+ /** Optional open-file dialog, registered as `shell.pick-files` when supplied. */
22
+ pickFiles?(request: PickFilesRequest): Promise<readonly string[]>;
23
+ }): () => void;
24
+ export {};
@@ -0,0 +1,85 @@
1
+ import { containsAsciiControl } from "../desktop/string-policy.js";
2
+ import { isAbsolute } from "node:path";
3
+ // src/native/native-utilities.ts
4
+ var MAX_PICKED_FILES = 1e3;
5
+ var object = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
6
+ var path = (value) => typeof value === "string" && value.length > 0 && value.length <= 4096 && !containsAsciiControl(value) && isAbsolute(value) && (process.platform !== "win32" || /^[A-Za-z]:[\\/]/.test(value) || /^\\\\[A-Za-z0-9][A-Za-z0-9._-]*\\[^\\/?]+(?:\\|$)/.test(value));
7
+ /** Register shared native utilities behind the host's authenticated principal and policy. */
8
+ function registerNativeUtilities(options) {
9
+ const { services, authorize, openExternal, pickFolder, pickFiles } = options;
10
+ const info = {
11
+ name: options.info?.name,
12
+ version: options.info?.version,
13
+ platform: options.info?.platform
14
+ };
15
+ if (!services || typeof authorize !== "function" || typeof openExternal !== "function" || typeof pickFolder !== "function" || pickFiles !== void 0 && typeof pickFiles !== "function" || typeof info.name !== "string" || !info.name.trim() || info.name.length > 100 || containsAsciiControl(info.name) || typeof info.version !== "string" || info.version.length > 64 || !/^\d+\.\d+\.\d+(?:-dev\.\d+)?$/.test(info.version) || ![
16
+ "darwin",
17
+ "win32",
18
+ "linux"
19
+ ].includes(info.platform)) throw new Error("Invalid native utility configuration");
20
+ const unregister = [];
21
+ const remove = () => {
22
+ for (const fn of unregister.splice(0).reverse()) fn();
23
+ };
24
+ try {
25
+ unregister.push(services.register("shell.info", {
26
+ parse(value) {
27
+ if (value !== null) throw new Error("Invalid input");
28
+ return null;
29
+ },
30
+ authorize: (principal) => authorize(principal, "info"),
31
+ run: () => ({ ...info })
32
+ }));
33
+ unregister.push(services.register("shell.open-external", {
34
+ parse(value) {
35
+ if (!object(value) || Object.keys(value).length !== 1 || typeof value.url !== "string" || value.url.length > 2048 || containsAsciiControl(value.url, true)) throw new Error("Invalid URL");
36
+ const url = new URL(value.url);
37
+ if (!["http:", "https:"].includes(url.protocol) || url.username || url.password) throw new Error("Invalid URL");
38
+ return url.href;
39
+ },
40
+ authorize: (principal) => authorize(principal, "open-external"),
41
+ async run(_principal, url) {
42
+ const opened = await openExternal(url);
43
+ if (typeof opened !== "boolean") throw new Error("Invalid native result");
44
+ return { opened };
45
+ }
46
+ }));
47
+ unregister.push(services.register("shell.pick-folder", {
48
+ parse(value) {
49
+ if (!object(value) || Object.keys(value).some((key) => key !== "startingFolder") || value.startingFolder !== void 0 && !path(value.startingFolder)) throw new Error("Invalid folder request");
50
+ return value.startingFolder;
51
+ },
52
+ authorize: (principal) => authorize(principal, "pick-folder"),
53
+ async run(_principal, startingFolder) {
54
+ const paths = await pickFolder(startingFolder);
55
+ if (!Array.isArray(paths) || paths.length > 1 || paths.some((value) => !path(value))) throw new Error("Invalid native result");
56
+ return { paths: [...paths] };
57
+ }
58
+ }));
59
+ if (pickFiles) unregister.push(services.register("shell.pick-files", {
60
+ parse(value) {
61
+ if (!object(value) || Object.keys(value).some((key) => ![
62
+ "startingFolder",
63
+ "extensions",
64
+ "multiple"
65
+ ].includes(key)) || value.startingFolder !== void 0 && !path(value.startingFolder) || value.multiple !== void 0 && typeof value.multiple !== "boolean" || value.extensions !== void 0 && (!Array.isArray(value.extensions) || value.extensions.length === 0 || value.extensions.length > 32 || value.extensions.some((item) => typeof item !== "string" || !/^[A-Za-z0-9]{1,16}$/.test(item)))) throw new Error("Invalid file request");
66
+ return {
67
+ ...value.startingFolder === void 0 ? {} : { startingFolder: value.startingFolder },
68
+ ...value.extensions === void 0 ? {} : { extensions: [...value.extensions] },
69
+ multiple: value.multiple === true
70
+ };
71
+ },
72
+ authorize: (principal) => authorize(principal, "pick-files"),
73
+ async run(_principal, request) {
74
+ const paths = await pickFiles(request);
75
+ if (!Array.isArray(paths) || paths.length > (request.multiple ? MAX_PICKED_FILES : 1) || paths.some((value) => !path(value))) throw new Error("Invalid native result");
76
+ return { paths: [...paths] };
77
+ }
78
+ }));
79
+ } catch (error) {
80
+ remove();
81
+ throw error;
82
+ }
83
+ return remove;
84
+ }
85
+ export { registerNativeUtilities };
@@ -0,0 +1,34 @@
1
+ /**
2
+ * The part of Electrobun's `BrowserView` class this helper relies on: the
3
+ * constructor stores `options.partition` and then calls `init()`, which passes
4
+ * `this.partition` to the native `createWebview` request (2.0.1 and 2.0.5).
5
+ */
6
+ export type PartitionableViewClass = {
7
+ prototype: {
8
+ init(this: {
9
+ partition: string | null;
10
+ }): unknown;
11
+ };
12
+ };
13
+ export type PartitionedWindow = {
14
+ webview?: {
15
+ partition?: string | null;
16
+ } | null;
17
+ close(): unknown;
18
+ };
19
+ /**
20
+ * Construct a `BrowserWindow` whose own webview uses `partition`.
21
+ *
22
+ * Electrobun accepts `partition` on `BrowserView` but its `BrowserWindow`
23
+ * constructor does not forward it to the view it creates. While `construct`
24
+ * runs synchronously, this assigns the partition to the first view initialized
25
+ * and restores `BrowserView.prototype.init` afterwards. It fails closed (and
26
+ * closes the window) unless exactly one view was created and the window's view
27
+ * reports the requested partition. Without a partition it only calls
28
+ * `construct`, so ordinary windows keep Electrobun's default profile.
29
+ */
30
+ export declare function constructPartitionedWindow<Window extends PartitionedWindow>(options: {
31
+ BrowserView: PartitionableViewClass;
32
+ partition: string | null | undefined;
33
+ construct(): Window;
34
+ }): Window;
@@ -0,0 +1,44 @@
1
+ // src/native/partitioned-window.ts
2
+ var PARTITION = /^(?:persist:)?[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/;
3
+ var constructing = false;
4
+ /**
5
+ * Construct a `BrowserWindow` whose own webview uses `partition`.
6
+ *
7
+ * Electrobun accepts `partition` on `BrowserView` but its `BrowserWindow`
8
+ * constructor does not forward it to the view it creates. While `construct`
9
+ * runs synchronously, this assigns the partition to the first view initialized
10
+ * and restores `BrowserView.prototype.init` afterwards. It fails closed (and
11
+ * closes the window) unless exactly one view was created and the window's view
12
+ * reports the requested partition. Without a partition it only calls
13
+ * `construct`, so ordinary windows keep Electrobun's default profile.
14
+ */
15
+ function constructPartitionedWindow(options) {
16
+ const { partition } = options;
17
+ if (partition === void 0 || partition === null) return options.construct();
18
+ if (!PARTITION.test(partition)) throw new Error("Invalid browser partition");
19
+ const prototype = options.BrowserView.prototype;
20
+ const init = prototype.init;
21
+ if (typeof init !== "function") throw new Error("Unsupported Electrobun BrowserView");
22
+ if (constructing) throw new Error("Partitioned windows must be constructed one at a time");
23
+ let views = 0;
24
+ let window;
25
+ constructing = true;
26
+ prototype.init = function() {
27
+ if (++views === 1) this.partition = partition;
28
+ return init.call(this);
29
+ };
30
+ try {
31
+ window = options.construct();
32
+ } finally {
33
+ prototype.init = init;
34
+ constructing = false;
35
+ }
36
+ if (views !== 1 || window.webview?.partition !== partition) {
37
+ try {
38
+ window.close();
39
+ } catch {}
40
+ throw new Error("Electrobun did not create the window view in the requested partition");
41
+ }
42
+ return window;
43
+ }
44
+ export { constructPartitionedWindow };
@@ -0,0 +1,53 @@
1
+ /** Electrobun's system webview or an explicitly bundled Chromium runtime. */
2
+ export type DesktopRenderer = 'native' | 'cef';
3
+ /**
4
+ * Use the same renderer for build and window creation. Merge each build fragment
5
+ * with the app's existing per-platform signing and packaging configuration.
6
+ */
7
+ export declare function createRendererProfile(renderer?: DesktopRenderer): {
8
+ readonly renderer: DesktopRenderer;
9
+ readonly build: {
10
+ readonly mac: {
11
+ bundleCEF: boolean;
12
+ defaultRenderer: "cef";
13
+ chromiumFlags: {
14
+ 'disable-web-security': boolean;
15
+ 'remote-allow-origins': boolean;
16
+ 'allow-insecure-localhost': boolean;
17
+ 'remote-debugging-port': boolean;
18
+ };
19
+ } | {
20
+ chromiumFlags?: undefined;
21
+ bundleCEF: boolean;
22
+ defaultRenderer: "native";
23
+ };
24
+ readonly win: {
25
+ bundleCEF: boolean;
26
+ defaultRenderer: "cef";
27
+ chromiumFlags: {
28
+ 'disable-web-security': boolean;
29
+ 'remote-allow-origins': boolean;
30
+ 'allow-insecure-localhost': boolean;
31
+ 'remote-debugging-port': boolean;
32
+ };
33
+ } | {
34
+ chromiumFlags?: undefined;
35
+ bundleCEF: boolean;
36
+ defaultRenderer: "native";
37
+ };
38
+ readonly linux: {
39
+ bundleCEF: boolean;
40
+ defaultRenderer: "cef";
41
+ chromiumFlags: {
42
+ 'disable-web-security': boolean;
43
+ 'remote-allow-origins': boolean;
44
+ 'allow-insecure-localhost': boolean;
45
+ 'remote-debugging-port': boolean;
46
+ };
47
+ } | {
48
+ chromiumFlags?: undefined;
49
+ bundleCEF: boolean;
50
+ defaultRenderer: "native";
51
+ };
52
+ };
53
+ };
@@ -0,0 +1,30 @@
1
+ // src/native/renderer-profile.ts
2
+ /**
3
+ * Use the same renderer for build and window creation. Merge each build fragment
4
+ * with the app's existing per-platform signing and packaging configuration.
5
+ */
6
+ function createRendererProfile(renderer = "native") {
7
+ if (renderer !== "native" && renderer !== "cef") throw new Error("Unsupported desktop renderer");
8
+ const platform = () => renderer === "cef" ? {
9
+ bundleCEF: true,
10
+ defaultRenderer: renderer,
11
+ chromiumFlags: {
12
+ "disable-web-security": false,
13
+ "remote-allow-origins": false,
14
+ "allow-insecure-localhost": false,
15
+ "remote-debugging-port": false
16
+ }
17
+ } : {
18
+ bundleCEF: false,
19
+ defaultRenderer: renderer
20
+ };
21
+ return {
22
+ renderer,
23
+ build: {
24
+ mac: platform(),
25
+ win: platform(),
26
+ linux: platform()
27
+ }
28
+ };
29
+ }
30
+ export { createRendererProfile };
@@ -0,0 +1,38 @@
1
+ import { type DesktopRenderer } from './renderer-profile';
2
+ import { createWindowOptions, type WindowFrame } from './window-options';
3
+ export type SecureWindowOptions = Omit<ReturnType<typeof createWindowOptions>, 'url'> & {
4
+ url: null | 'about:blank';
5
+ renderer: DesktopRenderer;
6
+ preload: string;
7
+ sandbox: true;
8
+ hidden?: boolean;
9
+ };
10
+ export type NativeWindow = {
11
+ webview: {
12
+ setNavigationRules(rules: string[]): unknown;
13
+ loadURL(url: string): unknown;
14
+ on?(event: 'did-commit-navigation' | 'will-navigate', handler: (event: unknown) => void): unknown;
15
+ };
16
+ on(event: 'close', handler: () => void): unknown;
17
+ close(): unknown;
18
+ };
19
+ /**
20
+ * Create a blank window, install navigation rules, then load its trusted origin.
21
+ * Electrobun 2.0.1 does not reliably apply the constructor's navigationRules;
22
+ * setting them after a URL starts loading is too late to protect the preload.
23
+ */
24
+ export declare function createSecureWindow<Window extends NativeWindow>(options: {
25
+ origin: string;
26
+ grant: {
27
+ origin: string;
28
+ preload: string;
29
+ revoke(): void;
30
+ };
31
+ renderer: DesktopRenderer;
32
+ platform: string;
33
+ title: string;
34
+ frame?: WindowFrame;
35
+ transparent?: boolean;
36
+ hidden?: boolean;
37
+ construct(options: SecureWindowOptions): Window;
38
+ }): Window;
@@ -0,0 +1,77 @@
1
+ import { createRendererProfile } from "./renderer-profile.js";
2
+ import { createLoopbackPolicy } from "../desktop/loopback-policy.js";
3
+ import { createWindowOptions } from "./window-options.js";
4
+ // src/native/secure-window.ts
5
+ /**
6
+ * Create a blank window, install navigation rules, then load its trusted origin.
7
+ * Electrobun 2.0.1 does not reliably apply the constructor's navigationRules;
8
+ * setting them after a URL starts loading is too late to protect the preload.
9
+ */
10
+ function createSecureWindow(options) {
11
+ const origin = createLoopbackPolicy(options.origin).origin;
12
+ if (origin !== options.grant.origin) throw new Error("Window grant origin mismatch");
13
+ const renderer = createRendererProfile(options.renderer).renderer;
14
+ let window;
15
+ let deadline;
16
+ const clearDeadline = () => {
17
+ if (deadline) clearTimeout(deadline);
18
+ deadline = void 0;
19
+ };
20
+ try {
21
+ window = options.construct({
22
+ ...createWindowOptions({
23
+ title: options.title,
24
+ url: origin + "/",
25
+ platform: options.platform,
26
+ renderer,
27
+ frame: options.frame,
28
+ transparent: options.transparent
29
+ }),
30
+ url: options.platform === "linux" && renderer === "cef" ? "about:blank" : null,
31
+ renderer,
32
+ preload: options.grant.preload,
33
+ sandbox: true,
34
+ hidden: options.hidden
35
+ });
36
+ window.on("close", () => {
37
+ clearDeadline();
38
+ options.grant.revoke();
39
+ });
40
+ window.webview.setNavigationRules(["^*", origin + "/*"]);
41
+ if (options.platform === "linux" && renderer === "cef") {
42
+ const view = window.webview;
43
+ const on = view.on;
44
+ if (!on) throw new Error("Window navigation events are unavailable");
45
+ let blankCommitted = false;
46
+ on.call(view, "did-commit-navigation", (event) => {
47
+ const detail = event?.data?.detail;
48
+ if (detail === "about:blank" && !blankCommitted) {
49
+ blankCommitted = true;
50
+ try {
51
+ view.loadURL(origin + "/");
52
+ } catch {
53
+ clearDeadline();
54
+ options.grant.revoke();
55
+ window?.close();
56
+ }
57
+ } else if (typeof detail === "string") try {
58
+ if (new URL(detail).origin === origin) clearDeadline();
59
+ } catch {}
60
+ });
61
+ deadline = setTimeout(() => {
62
+ clearDeadline();
63
+ options.grant.revoke();
64
+ window?.close();
65
+ }, 1e4);
66
+ } else window.webview.loadURL(origin + "/");
67
+ return window;
68
+ } catch (error) {
69
+ clearDeadline();
70
+ options.grant.revoke();
71
+ try {
72
+ window?.close();
73
+ } catch {}
74
+ throw error;
75
+ }
76
+ }
77
+ export { createSecureWindow };
@@ -0,0 +1,23 @@
1
+ import { type createServiceRegistry } from '../app/service-registry';
2
+ import type { Sidecar } from './sidecar';
3
+ /** Accept a web caller's arguments: absent, null, or a plain object. */
4
+ export declare function parseSidecarArgs(value: unknown): Record<string, unknown>;
5
+ /**
6
+ * Register sidecar commands as framework services so the web side calls them
7
+ * through the desktop client. A service named `${prefix}${command}` forwards its
8
+ * arguments to the sidecar command and returns the reply value. A sidecar
9
+ * failure becomes a `ServiceError` whose code is the failure reason
10
+ * (`command_failed`, `timeout`, `exited`, ...) and whose message is readable.
11
+ */
12
+ export declare function registerSidecarServices<Principal>(options: {
13
+ services: ReturnType<typeof createServiceRegistry<Principal>>;
14
+ sidecar: Pick<Sidecar, 'call'>;
15
+ commands: readonly string[];
16
+ authorize(principal: Principal, command: string): boolean | Promise<boolean>;
17
+ /** Prepended to each command to form its service name. Default none. */
18
+ prefix?: string;
19
+ /** Replaces the default plain-object argument check. */
20
+ parse?(command: string, value: unknown): Record<string, unknown>;
21
+ /** Invoke body limit for each service; see `ServiceDefinition.maxBodyBytes`. */
22
+ maxBodyBytes?: number;
23
+ }): () => void;
@@ -0,0 +1,46 @@
1
+ import { ServiceError } from "../app/service-registry.js";
2
+ // src/native/sidecar-services.ts
3
+ var MAX_ARGUMENT_KEYS = 64;
4
+ /** Accept a web caller's arguments: absent, null, or a plain object. */
5
+ function parseSidecarArgs(value) {
6
+ if (value === void 0 || value === null) return {};
7
+ if (typeof value !== "object" || Array.isArray(value)) throw new Error("Invalid input");
8
+ const prototype = Object.getPrototypeOf(value);
9
+ if (prototype !== Object.prototype && prototype !== null) throw new Error("Invalid input");
10
+ if (Object.keys(value).length > MAX_ARGUMENT_KEYS) throw new Error("Invalid input");
11
+ return value;
12
+ }
13
+ /**
14
+ * Register sidecar commands as framework services so the web side calls them
15
+ * through the desktop client. A service named `${prefix}${command}` forwards its
16
+ * arguments to the sidecar command and returns the reply value. A sidecar
17
+ * failure becomes a `ServiceError` whose code is the failure reason
18
+ * (`command_failed`, `timeout`, `exited`, ...) and whose message is readable.
19
+ */
20
+ function registerSidecarServices(options) {
21
+ const { services, sidecar, commands, authorize } = options;
22
+ const prefix = options.prefix ?? "";
23
+ const parse = options.parse ?? ((_command, value) => parseSidecarArgs(value));
24
+ if (!services || typeof sidecar?.call !== "function" || typeof authorize !== "function" || typeof parse !== "function" || typeof prefix !== "string" || !Array.isArray(commands) || new Set(commands).size !== commands.length) throw new Error("Invalid sidecar service configuration");
25
+ const unregister = [];
26
+ const remove = () => {
27
+ for (const fn of unregister.splice(0)) fn();
28
+ };
29
+ try {
30
+ for (const command of commands) unregister.push(services.register(prefix + command, {
31
+ parse: (value) => parse(command, value),
32
+ authorize: (principal) => authorize(principal, command),
33
+ async run(_principal, args) {
34
+ const reply = await sidecar.call(command, args);
35
+ if (reply.ok) return reply.value;
36
+ throw new ServiceError(reply.reason, reply.error);
37
+ },
38
+ ...options.maxBodyBytes === void 0 ? {} : { maxBodyBytes: options.maxBodyBytes }
39
+ }));
40
+ } catch (error) {
41
+ remove();
42
+ throw error;
43
+ }
44
+ return remove;
45
+ }
46
+ export { parseSidecarArgs, registerSidecarServices };
@@ -0,0 +1,81 @@
1
+ /**
2
+ * Language-agnostic sidecar host: runs a bundled executable, written in any
3
+ * language, and calls it over stdio with line-delimited JSON.
4
+ *
5
+ * Wire protocol, one JSON object per line in each direction:
6
+ *
7
+ * host → sidecar {"id": 1, "command": "name", "args": {...}}
8
+ * sidecar → host {"id": 1, "ok": true, "value": ...}
9
+ * {"id": 1, "ok": false, "error": "readable message"}
10
+ *
11
+ * Ids are positive JavaScript-safe integers; replies may arrive in any order.
12
+ * A sidecar must exit when its stdin closes so it never outlives the host, and
13
+ * should answer a request it cannot parse with `"id": null` (logged here).
14
+ *
15
+ * The host starts the process on the first call, respawns it on the next call
16
+ * after it exits (within the restart budget), and kills it on `stop()` or when
17
+ * the host process exits. `call()` never throws: every failure resolves as
18
+ * `{ok: false, reason, error}` with a readable message.
19
+ */
20
+ export type SidecarFailure =
21
+ /** The sidecar answered with `ok: false`. */
22
+ 'command_failed' | 'timeout' | 'aborted' | 'request_too_large' | 'reply_too_large'
23
+ /** The executable could not be started (missing, not executable, ...). */
24
+ | 'unavailable'
25
+ /** The process exited before replying. */
26
+ | 'exited'
27
+ /** The process exited too often within the restart window. */
28
+ | 'restart_limit' | 'stopped' | 'invalid_request';
29
+ export type SidecarReply<Value = unknown> = {
30
+ ok: true;
31
+ value: Value;
32
+ } | {
33
+ ok: false;
34
+ reason: SidecarFailure;
35
+ error: string;
36
+ };
37
+ /** Describe a sidecar's commands to type `call`: `{ command: { args; value } }`. */
38
+ export type SidecarCommands = Record<string, {
39
+ args: Record<string, unknown>;
40
+ value: unknown;
41
+ }>;
42
+ export type SidecarState = 'idle' | 'running' | 'stopped';
43
+ export type SidecarOptions = {
44
+ /** Absolute path of the executable; see `packagedSidecarPath` in `app-bundle`. */
45
+ executable: string;
46
+ args?: readonly string[];
47
+ /** Replaces the inherited environment when given. */
48
+ env?: Record<string, string | undefined>;
49
+ /** Shown in error messages and logs. Default `sidecar`. */
50
+ name?: string;
51
+ /** Default 30 s. */
52
+ requestTimeoutMs?: number;
53
+ /** Default 1 MiB per request line. */
54
+ maxRequestBytes?: number;
55
+ /** Default 8 MiB per reply line, plus 1 KiB of framing. */
56
+ maxReplyBytes?: number;
57
+ /** Respawns allowed after an exit within `windowMs`; the first start is not a restart. */
58
+ restart: {
59
+ maxRestarts: number;
60
+ windowMs: number;
61
+ };
62
+ /** Bytes of recent stderr kept for `stderr()`. Default 64 KiB. */
63
+ maxStderrBytes?: number;
64
+ /** Receives stderr lines and lifecycle notes. */
65
+ log?: (line: string) => void;
66
+ };
67
+ export type Sidecar<Commands extends SidecarCommands = SidecarCommands> = {
68
+ call<Command extends keyof Commands & string>(command: Command, args?: Commands[Command]['args'], options?: {
69
+ signal?: AbortSignal;
70
+ timeoutMs?: number;
71
+ }): Promise<SidecarReply<Commands[Command]['value']>>;
72
+ /** Start now instead of on the first call. Returns false when it could not start. */
73
+ start(): boolean;
74
+ /** Kill the process and fail pending calls. Later calls resolve as `stopped`. */
75
+ stop(): void;
76
+ readonly state: SidecarState;
77
+ readonly pid: number | undefined;
78
+ /** Recent stderr, bounded, for diagnostics. Never send it to the web side. */
79
+ stderr(): string;
80
+ };
81
+ export declare function createSidecar<Commands extends SidecarCommands = SidecarCommands>(options: SidecarOptions): Sidecar<Commands>;