@adea-ai/app-framework 0.25.0 → 0.26.0

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 (138) hide show
  1. package/README.md +157 -19
  2. package/dist/app/application.d.ts +11 -4
  3. package/dist/app/application.js +24 -4
  4. package/dist/app/create-application.d.ts +9 -0
  5. package/dist/app/create-application.js +214 -143
  6. package/dist/app/private-group.d.ts +14 -0
  7. package/dist/app/private-group.js +39 -0
  8. package/dist/app/service-registry.d.ts +8 -4
  9. package/dist/app/service-registry.js +43 -6
  10. package/dist/appearance/custom-theme-import.d.ts +5 -7
  11. package/dist/appearance/custom-theme-import.js +66 -18
  12. package/dist/appearance/custom-theme-library.d.ts +51 -3
  13. package/dist/appearance/custom-theme-library.js +262 -33
  14. package/dist/appearance/editor.d.ts +3 -1
  15. package/dist/appearance/editor.js +37 -2
  16. package/dist/appearance/theme-file-importer.d.ts +7 -3
  17. package/dist/appearance/theme-file-importer.js +27 -7
  18. package/dist/appearance/theme-library-action-fence.d.ts +11 -0
  19. package/dist/appearance/theme-library-action-fence.js +29 -0
  20. package/dist/cli/cef-helper-cli.js +0 -0
  21. package/dist/cli/create-application-cli.js +0 -0
  22. package/dist/cli/electrobun-shortcut-patch-cli.js +0 -0
  23. package/dist/cli/framework-update-cli.js +16 -3
  24. package/dist/cli/macos-signing-cli.js +0 -0
  25. package/dist/cli/release-assets-plan-cli.js +0 -0
  26. package/dist/cli/release-cut-cli.js +0 -0
  27. package/dist/cli/release-descriptor-staging-cli.js +0 -0
  28. package/dist/cli/release-finalize-cli.js +0 -0
  29. package/dist/cli/release-promote-cli.js +0 -0
  30. package/dist/cli/release-publish-cli.js +0 -0
  31. package/dist/cli/release-sign-cli.js +0 -0
  32. package/dist/cli/release-step-cli.js +0 -0
  33. package/dist/cli/toolchain-identity-cli.js +0 -0
  34. package/dist/cli/windows-runtime-patch-cli.js +0 -0
  35. package/dist/desktop/application-command-client.d.ts +11 -1
  36. package/dist/desktop/application-command-client.js +66 -3
  37. package/dist/desktop/channel-handshake.d.ts +2 -1
  38. package/dist/desktop/channel-handshake.js +21 -5
  39. package/dist/desktop/client-asset-stream.d.ts +10 -0
  40. package/dist/desktop/client-asset-stream.js +97 -0
  41. package/dist/desktop/client-assets.d.ts +3 -1
  42. package/dist/desktop/client-assets.js +41 -6
  43. package/dist/desktop/desktop-client.d.ts +15 -1
  44. package/dist/desktop/desktop-client.js +235 -109
  45. package/dist/desktop/desktop-gateway.d.ts +2 -0
  46. package/dist/desktop/desktop-gateway.js +134 -22
  47. package/dist/desktop/desktop-host-websocket.d.ts +10 -0
  48. package/dist/desktop/desktop-host-websocket.js +28 -0
  49. package/dist/desktop/desktop-host.d.ts +9 -0
  50. package/dist/desktop/desktop-host.js +70 -61
  51. package/dist/desktop/desktop-port-file.d.ts +2 -0
  52. package/dist/desktop/desktop-port-file.js +23 -0
  53. package/dist/desktop/desktop-stream.d.ts +5 -0
  54. package/dist/desktop/desktop-stream.js +83 -15
  55. package/dist/desktop/gateway-limits.d.ts +2 -0
  56. package/dist/desktop/gateway-limits.js +6 -0
  57. package/dist/desktop/open-url-channel.d.ts +5 -3
  58. package/dist/desktop/open-url-channel.js +18 -5
  59. package/dist/desktop/typed-array-intrinsics.d.ts +6 -0
  60. package/dist/desktop/typed-array-intrinsics.js +19 -0
  61. package/dist/framework-source.json +1 -1
  62. package/dist/installer/installed-payload.js +1 -1
  63. package/dist/installer/installer-ci-bootstrap.js +2 -1
  64. package/dist/installer/installer-command.d.ts +13 -0
  65. package/dist/installer/installer-command.js +47 -0
  66. package/dist/installer/installer-extraction.js +27 -61
  67. package/dist/installer/installer-identity.d.ts +19 -3
  68. package/dist/installer/installer-identity.js +58 -70
  69. package/dist/installer/installer-image-mount.d.ts +48 -0
  70. package/dist/installer/installer-image-mount.js +347 -0
  71. package/dist/installer/installer-layout.js +1 -1
  72. package/dist/installer/installer-process-cleanup.js +1 -1
  73. package/dist/installer/installer-renderer-evidence.js +6 -2
  74. package/dist/installer/upgrade-asset-download.js +30 -8
  75. package/dist/native/app-bundle.d.ts +2 -2
  76. package/dist/native/app-bundle.js +5 -4
  77. package/dist/native/cef-helper-download.d.ts +1 -0
  78. package/dist/native/cef-helper-download.js +35 -0
  79. package/dist/native/cef-helper.js +146 -61
  80. package/dist/native/exclusive-rename.d.ts +2 -0
  81. package/dist/native/exclusive-rename.js +52 -0
  82. package/dist/native/native-secret-store.js +5 -4
  83. package/dist/native/partitioned-window.d.ts +5 -2
  84. package/dist/native/partitioned-window.js +69 -9
  85. package/dist/native/sidecar-services.js +2 -2
  86. package/dist/native/sidecar.js +68 -25
  87. package/dist/native/window-bootstrap.js +2 -2
  88. package/dist/release/feed-state.js +2 -1
  89. package/dist/release/framework-update-lock.d.ts +2 -0
  90. package/dist/release/framework-update-lock.js +42 -0
  91. package/dist/release/framework-update.d.ts +6 -2
  92. package/dist/release/framework-update.js +165 -40
  93. package/dist/release/local-release.js +68 -39
  94. package/dist/release/release-config.js +1 -1
  95. package/dist/shared/discard-stream.d.ts +4 -0
  96. package/dist/shared/discard-stream.js +9 -0
  97. package/dist/shell/app-shell.js +59 -7
  98. package/dist/shell/app-utilities.js +2 -2
  99. package/dist/shell/application-menu.d.ts +13 -0
  100. package/dist/shell/application-menu.js +21 -8
  101. package/dist/update-helper.bundle.js +40 -4
  102. package/dist/updates/channel-update-manager.d.ts +2 -0
  103. package/dist/updates/channel-update-manager.js +15 -3
  104. package/dist/updates/desktop-updater.d.ts +2 -0
  105. package/dist/updates/desktop-updater.js +36 -7
  106. package/dist/updates/linux-process-state.d.ts +2 -0
  107. package/dist/updates/linux-process-state.js +13 -0
  108. package/dist/updates/release-location.js +5 -4
  109. package/dist/updates/update-adapter.js +5 -0
  110. package/dist/updates/update-arm.d.ts +2 -0
  111. package/dist/updates/update-arm.js +58 -7
  112. package/dist/updates/update-discovery.js +2 -1
  113. package/dist/updates/update-download-cleanup.d.ts +7 -0
  114. package/dist/updates/update-download-cleanup.js +21 -0
  115. package/dist/updates/update-download.js +41 -20
  116. package/dist/updates/update-exclusive-rename.d.ts +3 -2
  117. package/dist/updates/update-exclusive-rename.js +3 -50
  118. package/dist/updates/update-extraction.js +1 -1
  119. package/dist/updates/update-manager.d.ts +17 -1
  120. package/dist/updates/update-manager.js +27 -8
  121. package/dist/updates/update-process-fence.js +18 -3
  122. package/dist/views/appearance-surface.js +51 -15
  123. package/package.json +11 -6
  124. package/src/app/application.tsx +49 -7
  125. package/src/appearance/custom-theme-import.ts +67 -7
  126. package/src/appearance/custom-theme-library.ts +391 -33
  127. package/src/appearance/editor.ts +49 -10
  128. package/src/appearance/theme-file-importer.ts +43 -12
  129. package/src/appearance/theme-library-action-fence.ts +28 -0
  130. package/src/desktop/client-asset-stream.ts +118 -0
  131. package/src/desktop/client-assets.ts +55 -5
  132. package/src/shell/app-shell.tsx +71 -8
  133. package/src/shell/app-utilities.tsx +2 -2
  134. package/src/updates/update-adapter.ts +5 -0
  135. package/src/views/appearance-surface.tsx +61 -29
  136. package/templates/application/README.md +5 -1
  137. package/templates/application/scripts/app-version.ts +7 -3
  138. package/templates/application/src/bun/index.ts +2 -0
@@ -0,0 +1,28 @@
1
+ import { typedArrayBuffer, typedArrayByteLength, typedArrayByteOffset } from "./typed-array-intrinsics.js";
2
+ // src/desktop/desktop-host-websocket.ts
3
+ function getTypedArrayByteLength(payload) {
4
+ try {
5
+ const byteLength = typedArrayByteLength(payload);
6
+ if (byteLength > 0) return byteLength;
7
+ const buffer = typedArrayBuffer(payload);
8
+ const byteOffset = typedArrayByteOffset(payload);
9
+ return new Uint8Array(buffer, byteOffset, 0).byteLength;
10
+ } catch {
11
+ return;
12
+ }
13
+ }
14
+ var DESKTOP_STREAM_BACKPRESSURE_LIMIT = 1048576;
15
+ /** Adapt Bun's byte-count send result to the boolean contract used by streams. */
16
+ function sendDesktopStreamPayload(socket, payload) {
17
+ const byteLength = typeof payload === "string" ? payload.length : getTypedArrayByteLength(payload);
18
+ if (byteLength === void 0) return false;
19
+ if (!(byteLength === 0)) return socket.send(payload) > 0;
20
+ const readyState = socket.readyState;
21
+ if (readyState !== 1) return false;
22
+ const bufferedAmount = socket.getBufferedAmount();
23
+ if (!Number.isFinite(bufferedAmount) || bufferedAmount < 0 || bufferedAmount > 1048576) return false;
24
+ const sent = socket.send(payload);
25
+ if (sent > 0) return true;
26
+ return sent === 0 && readyState === 1 && bufferedAmount <= 1048576;
27
+ }
28
+ export { DESKTOP_STREAM_BACKPRESSURE_LIMIT, sendDesktopStreamPayload };
@@ -6,6 +6,8 @@ import { createDesktopStreams } from './desktop-stream';
6
6
  /** Bind an isolated client server and open a window with a per-window channel. */
7
7
  export declare function startDesktopHost<Principal, Window extends NativeWindow>(options: {
8
8
  clientRoot: string;
9
+ /** Stream only when the client root is immutable; defaults to buffered snapshots. */
10
+ streamClientAssets?: boolean;
9
11
  /** Existing app-owned file or new path for a stable loopback origin. */
10
12
  portFile?: string;
11
13
  /** Preserve an existing loopback origin when creating the port file. */
@@ -15,6 +17,13 @@ export declare function startDesktopHost<Principal, Window extends NativeWindow>
15
17
  platform: string;
16
18
  principal: Principal;
17
19
  services: ReturnType<typeof createServiceRegistry<Principal>>;
20
+ /** Opt-in deadline for service dispatch; no framework deadline is applied when omitted. */
21
+ dispatchTimeoutMs?: number;
22
+ /**
23
+ * Register stream providers synchronously before the window starts. The host
24
+ * stops its streams and server on failure; app-owned side effects are the
25
+ * callback's responsibility.
26
+ */
18
27
  configureStreams?: (streams: ReturnType<typeof createDesktopStreams<Principal>>) => void;
19
28
  /** App-owned same-origin HTTP routes. Handlers must apply their own authorization. */
20
29
  routes?: readonly {
@@ -1,11 +1,14 @@
1
1
  import { createChannelAuthority } from "./channel-handshake.js";
2
2
  import { serveClient } from "./client-assets.js";
3
3
  import { createLoopbackPolicy, matchesLoopbackOrigin } from "./loopback-policy.js";
4
+ import { isValidGatewayTimeoutMs } from "./gateway-limits.js";
4
5
  import { createDesktopGateway } from "./desktop-gateway.js";
6
+ import { DESKTOP_STREAM_BACKPRESSURE_LIMIT, sendDesktopStreamPayload } from "./desktop-host-websocket.js";
7
+ import { publishDesktopPort } from "./desktop-port-file.js";
5
8
  import { createNativeWindowGrant } from "../native/window-bootstrap.js";
6
9
  import { createSecureWindow } from "../native/secure-window.js";
7
10
  import { createDesktopStreams } from "./desktop-stream.js";
8
- import { lstatSync, readFileSync, writeFileSync } from "node:fs";
11
+ import { lstatSync, readFileSync } from "node:fs";
9
12
  // src/desktop/desktop-host.ts
10
13
  var DesktopPortInUseError = class extends Error {
11
14
  code = "EADDRINUSE";
@@ -15,6 +18,15 @@ var DesktopPortInUseError = class extends Error {
15
18
  };
16
19
  /** Bind an isolated client server and open a window with a per-window channel. */
17
20
  function startDesktopHost(options) {
21
+ const reportRequest = (...args) => {
22
+ try {
23
+ const result = options.onRequest?.(...args);
24
+ if (result !== void 0) Promise.resolve(result).catch(() => {});
25
+ } catch {}
26
+ };
27
+ const dispatchTimeoutMs = options.dispatchTimeoutMs;
28
+ if (!isValidGatewayTimeoutMs(dispatchTimeoutMs)) throw new Error("Invalid gateway limits");
29
+ if (options.streamClientAssets !== void 0 && typeof options.streamClientAssets !== "boolean") throw new Error("Invalid desktop client asset policy");
18
30
  const configuredRoutes = options.routes ?? [];
19
31
  if (!Array.isArray(configuredRoutes) || configuredRoutes.length > 32 || configuredRoutes.some((route) => !route || typeof route.prefix !== "string" || !/^\/[a-zA-Z0-9][a-zA-Z0-9._-]*(?:\/[a-zA-Z0-9][a-zA-Z0-9._-]*)*$/.test(route.prefix) || route.prefix.length > 200 || route.prefix === "/__framework" || route.prefix.startsWith("/__framework/") || typeof route.handle !== "function") || configuredRoutes.some((route, index) => configuredRoutes.slice(index + 1).some((other) => route.prefix === other.prefix || route.prefix.startsWith(other.prefix + "/") || other.prefix.startsWith(route.prefix + "/")))) throw new Error("Invalid desktop route policy");
20
32
  const routes = configuredRoutes.map(({ prefix, handle }) => ({
@@ -40,6 +52,9 @@ function startDesktopHost(options) {
40
52
  let origin = "";
41
53
  let gateway;
42
54
  let streams;
55
+ let grant;
56
+ let window;
57
+ let stopped = false;
43
58
  let server;
44
59
  try {
45
60
  server = Bun.serve({
@@ -49,9 +64,7 @@ function startDesktopHost(options) {
49
64
  if (!origin || !gateway) return new Response(null, { status: 503 });
50
65
  const url = new URL(request.url);
51
66
  if (url.origin !== origin || request.headers.get("host") !== new URL(origin).host) {
52
- try {
53
- options.onRequest?.("rejected");
54
- } catch {}
67
+ reportRequest("rejected");
55
68
  return new Response(null, { status: 403 });
56
69
  }
57
70
  if (url.pathname === "/__framework/stream") {
@@ -68,13 +81,11 @@ function startDesktopHost(options) {
68
81
  if (kind === "invoke") connection.timeout(request, 0);
69
82
  const result = await gateway.handle(request);
70
83
  const header = request.headers.get("origin");
71
- try {
72
- options.onRequest?.(kind, {
73
- status: result.status,
74
- origin: header === origin ? "matching" : header === null ? "missing" : header === "null" ? "opaque" : /^http:\/\/127\.0\.0\.1(?::[0-9]{1,5})?$/.test(header) ? "same-host" : "other",
75
- fetchSite: request.headers.get("sec-fetch-site")
76
- });
77
- } catch {}
84
+ reportRequest(kind, {
85
+ status: result.status,
86
+ origin: header === origin ? "matching" : header === null ? "missing" : header === "null" ? "opaque" : /^http:\/\/127\.0\.0\.1(?::[0-9]{1,5})?$/.test(header) ? "same-host" : "other",
87
+ fetchSite: request.headers.get("sec-fetch-site")
88
+ });
78
89
  return result;
79
90
  }
80
91
  const route = routes.find((value) => url.pathname === value.prefix || url.pathname.startsWith(value.prefix + "/"));
@@ -84,9 +95,7 @@ function startDesktopHost(options) {
84
95
  origin: request.headers.get("origin"),
85
96
  secFetchSite: request.headers.get("sec-fetch-site")
86
97
  }, createLoopbackPolicy(origin))) return new Response(null, { status: 403 });
87
- try {
88
- options.onRequest?.("route");
89
- } catch {}
98
+ reportRequest("route");
90
99
  try {
91
100
  const result = await route.handle(request);
92
101
  return result instanceof Response ? result : new Response(null, { status: 500 });
@@ -94,11 +103,11 @@ function startDesktopHost(options) {
94
103
  return new Response(null, { status: 500 });
95
104
  }
96
105
  }
97
- try {
98
- options.onRequest?.(kind);
99
- } catch {}
100
- if (request.method !== "GET" && request.method !== "HEAD") return new Response(null, { status: 405 });
101
- const result = await serveClient(request, { root: options.clientRoot });
106
+ reportRequest(kind);
107
+ const result = await serveClient(request, {
108
+ root: options.clientRoot,
109
+ streamAssets: options.streamClientAssets
110
+ });
102
111
  result.headers.set("content-security-policy", "frame-src 'none'; frame-ancestors 'none'; object-src 'none'; base-uri 'none'");
103
112
  result.headers.set("x-content-type-options", "nosniff");
104
113
  result.headers.set("referrer-policy", "no-referrer");
@@ -106,11 +115,11 @@ function startDesktopHost(options) {
106
115
  },
107
116
  websocket: {
108
117
  maxPayloadLength: 262144,
109
- backpressureLimit: 1048576,
118
+ backpressureLimit: DESKTOP_STREAM_BACKPRESSURE_LIMIT,
110
119
  closeOnBackpressureLimit: true,
111
120
  open(socket) {
112
121
  socket.data.connection = streams?.accept({
113
- send: (payload) => socket.send(payload) > 0,
122
+ send: (payload) => sendDesktopStreamPayload(socket, payload),
114
123
  close: () => socket.close()
115
124
  });
116
125
  if (!socket.data.connection) socket.close();
@@ -127,49 +136,49 @@ function startDesktopHost(options) {
127
136
  if (error?.code === "EADDRINUSE") throw new DesktopPortInUseError(error);
128
137
  throw error;
129
138
  }
130
- if (options.portFile !== void 0 && savePort) try {
131
- writeFileSync(options.portFile, `${server.port}\n`, {
132
- flag: "wx",
133
- mode: 384
134
- });
135
- } catch (error) {
136
- server.stop(true);
137
- throw error;
138
- }
139
- origin = `http://127.0.0.1:${server.port}`;
140
- const authority = createChannelAuthority();
141
- if (options.configureStreams) {
142
- streams = createDesktopStreams({ authority });
143
- try {
144
- options.configureStreams(streams);
145
- } catch (error) {
146
- streams.stop();
147
- server.stop(true);
148
- throw error;
149
- }
150
- }
151
- const grant = createNativeWindowGrant({
152
- origin,
153
- authority,
154
- principal: options.principal
155
- });
156
- gateway = createDesktopGateway({
157
- origin,
158
- authority,
159
- services: options.services,
160
- windowGrant: grant
161
- });
162
- let window;
163
- let stopped = false;
164
- const stop = () => {
139
+ const cleanupResources = (throwCleanupError) => {
165
140
  if (stopped) return;
166
141
  stopped = true;
167
- streams?.stop();
168
- grant.revoke();
169
- server.stop(true);
170
- window?.close();
142
+ let cleanupFailed = false;
143
+ let cleanupError;
144
+ for (const cleanup of [
145
+ () => streams?.stop(),
146
+ () => grant?.revoke(),
147
+ () => server.stop(true),
148
+ () => window?.close()
149
+ ]) try {
150
+ cleanup();
151
+ } catch (error) {
152
+ if (!cleanupFailed) cleanupError = error;
153
+ cleanupFailed = true;
154
+ }
155
+ if (throwCleanupError && cleanupFailed) throw cleanupError;
171
156
  };
157
+ const stop = () => cleanupResources(true);
172
158
  try {
159
+ if (options.portFile !== void 0 && savePort) publishDesktopPort(options.portFile, server.port);
160
+ origin = `http://127.0.0.1:${server.port}`;
161
+ const authority = createChannelAuthority();
162
+ if (options.configureStreams) {
163
+ streams = createDesktopStreams({ authority });
164
+ const configured = options.configureStreams(streams);
165
+ if (configured !== null && (typeof configured === "object" || typeof configured === "function") && typeof configured.then === "function") {
166
+ Promise.resolve(configured).catch(() => {});
167
+ throw new Error("Desktop stream configuration must be synchronous");
168
+ }
169
+ }
170
+ grant = createNativeWindowGrant({
171
+ origin,
172
+ authority,
173
+ principal: options.principal
174
+ });
175
+ gateway = createDesktopGateway({
176
+ origin,
177
+ authority,
178
+ services: options.services,
179
+ dispatchTimeoutMs,
180
+ windowGrant: grant
181
+ });
173
182
  window = createSecureWindow({
174
183
  origin,
175
184
  grant,
@@ -189,7 +198,7 @@ function startDesktopHost(options) {
189
198
  revokeChannels: () => authority.revokeAll()
190
199
  };
191
200
  } catch (error) {
192
- stop();
201
+ cleanupResources(false);
193
202
  throw error;
194
203
  }
195
204
  }
@@ -0,0 +1,2 @@
1
+ /** Publish a complete port record without replacing any existing entry. */
2
+ export declare function publishDesktopPort(path: string, port: number): void;
@@ -0,0 +1,23 @@
1
+ import { dirname, join } from "node:path";
2
+ import { linkSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
3
+ // src/desktop/desktop-port-file.ts
4
+ /** Publish a complete port record without replacing any existing entry. */
5
+ function publishDesktopPort(path, port) {
6
+ const work = mkdtempSync(join(dirname(path), ".framework-port-"));
7
+ try {
8
+ const staged = join(work, "port");
9
+ writeFileSync(staged, `${port}\n`, {
10
+ flag: "wx",
11
+ mode: 384
12
+ });
13
+ linkSync(staged, path);
14
+ } finally {
15
+ try {
16
+ rmSync(work, {
17
+ recursive: true,
18
+ force: true
19
+ });
20
+ } catch {}
21
+ }
22
+ }
23
+ export { publishDesktopPort };
@@ -26,6 +26,11 @@ export declare function createDesktopStreams<Principal>(options: {
26
26
  maxConnections?: number;
27
27
  maxFrameBytes?: number;
28
28
  }): {
29
+ /**
30
+ * Capture callable identities for this registration; receiver state remains
31
+ * app-owned. A stale disposer cannot remove a later registration. Removing a
32
+ * registration closes connections using the same provider object under any name.
33
+ */
29
34
  register(name: string, provider: StreamProvider<Principal>): () => void;
30
35
  accept(socket: Socket): {
31
36
  close: () => void;
@@ -1,7 +1,19 @@
1
1
  import { createChannelProofVerifier } from "./channel-proof.js";
2
+ import { typedArrayBuffer, typedArrayByteLength, typedArrayByteOffset } from "./typed-array-intrinsics.js";
3
+ import { types } from "node:util";
4
+ import { Buffer } from "node:buffer";
2
5
  // src/desktop/desktop-stream.ts
3
6
  function payloadSize(payload) {
4
- return typeof payload === "string" ? new TextEncoder().encode(payload).byteLength : payload.byteLength;
7
+ try {
8
+ return typeof payload === "string" ? Buffer.byteLength(payload, "utf8") : typedArrayByteLength(payload);
9
+ } catch {
10
+ return Infinity;
11
+ }
12
+ }
13
+ function copyBinary(payload, bytes) {
14
+ const buffer = typedArrayBuffer(payload);
15
+ const offset = typedArrayByteOffset(payload);
16
+ return Uint8Array.from(new Uint8Array(buffer, offset, bytes));
5
17
  }
6
18
  /** Application-owned stream authorization and lifecycle, independent of the socket implementation. */
7
19
  function createDesktopStreams(options) {
@@ -13,7 +25,7 @@ function createDesktopStreams(options) {
13
25
  timeout,
14
26
  limit,
15
27
  maxFrameBytes
16
- ].every((value) => Number.isSafeInteger(value) && value > 0)) throw new Error("Invalid stream limits");
28
+ ].every((value) => Number.isSafeInteger(value) && value > 0) || timeout > 2147483647) throw new Error("Invalid stream limits");
17
29
  const verifier = createChannelProofVerifier({
18
30
  resolve: options.authority.resolve,
19
31
  now,
@@ -27,13 +39,30 @@ function createDesktopStreams(options) {
27
39
  });
28
40
  let stopped = false;
29
41
  return {
42
+ /**
43
+ * Capture callable identities for this registration; receiver state remains
44
+ * app-owned. A stale disposer cannot remove a later registration. Removing a
45
+ * registration closes connections using the same provider object under any name.
46
+ */
30
47
  register(name, provider) {
31
- if (stopped || !/^[a-z][a-z0-9]*(?:[._-][a-z0-9]+)*$/.test(name) || name.length > 128 || providers.has(name) || typeof provider.parse !== "function" || typeof provider.authorize !== "function" || typeof provider.open !== "function") throw new Error("Invalid stream provider");
32
- providers.set(name, provider);
48
+ if (stopped || !/^[a-z][a-z0-9]*(?:[._-][a-z0-9]+)*$/.test(name) || name.length > 128 || providers.has(name)) throw new Error("Invalid stream provider");
49
+ const { parse, authorize, open } = provider;
50
+ if (stopped || providers.has(name) || typeof parse !== "function" || typeof authorize !== "function" || typeof open !== "function") throw new Error("Invalid stream provider");
51
+ const registration = {
52
+ source: provider,
53
+ parse: (value) => Reflect.apply(parse, provider, [value]),
54
+ authorize: (principal, input) => Reflect.apply(authorize, provider, [principal, input]),
55
+ open: (principal, input, context) => Reflect.apply(open, provider, [
56
+ principal,
57
+ input,
58
+ context
59
+ ])
60
+ };
61
+ providers.set(name, registration);
33
62
  return () => {
34
- if (providers.get(name) !== provider) return;
63
+ if (providers.get(name) !== registration) return;
35
64
  providers.delete(name);
36
- for (const connection of connections) if (connection.provider === provider) connection.close();
65
+ for (const connection of connections) if (connection.provider?.source === provider) connection.close();
37
66
  };
38
67
  },
39
68
  accept(socket) {
@@ -70,18 +99,29 @@ function createDesktopStreams(options) {
70
99
  const timer = setTimeout(close, timeout);
71
100
  connections.add(connection);
72
101
  const send = (payload) => {
73
- if (!current() || typeof payload !== "string" && !(payload instanceof Uint8Array) || payloadSize(payload) > maxFrameBytes) {
102
+ if (!current() || typeof payload !== "string" && !(payload instanceof Uint8Array)) {
103
+ close();
104
+ return false;
105
+ }
106
+ const bytes = payloadSize(payload);
107
+ if (bytes > maxFrameBytes) {
74
108
  close();
75
109
  return false;
76
110
  }
77
111
  if (phase === "opening") {
78
- if (outbound.length >= 64 || outboundBytes + payloadSize(payload) > 1048576) {
112
+ if (outbound.length >= 64 || outboundBytes + bytes > 1048576) {
113
+ close();
114
+ return false;
115
+ }
116
+ let copy;
117
+ try {
118
+ copy = typeof payload === "string" ? payload : copyBinary(payload, bytes);
119
+ } catch {
79
120
  close();
80
121
  return false;
81
122
  }
82
- const copy = typeof payload === "string" ? payload : Uint8Array.from(payload);
83
123
  outbound.push(copy);
84
- outboundBytes += payloadSize(copy);
124
+ outboundBytes += bytes;
85
125
  return true;
86
126
  }
87
127
  if (phase !== "open") {
@@ -89,7 +129,12 @@ function createDesktopStreams(options) {
89
129
  return false;
90
130
  }
91
131
  try {
92
- if (socket.send(payload) === true) return true;
132
+ let output = payload;
133
+ if (typeof payload !== "string") {
134
+ const buffer = typedArrayBuffer(payload);
135
+ if (types.isSharedArrayBuffer(buffer)) output = copyBinary(payload, bytes);
136
+ }
137
+ if (socket.send(output) === true) return true;
93
138
  } catch {}
94
139
  close();
95
140
  return false;
@@ -99,12 +144,22 @@ function createDesktopStreams(options) {
99
144
  async receive(payload) {
100
145
  if (closed) return;
101
146
  if (phase === "open") {
102
- if (typeof payload !== "string" && !(payload instanceof Uint8Array) || payloadSize(payload) > maxFrameBytes || queuedCount >= 64 || queuedBytes + payloadSize(payload) > 1048576) {
147
+ if (typeof payload !== "string" && !(payload instanceof Uint8Array)) {
148
+ close();
149
+ return;
150
+ }
151
+ const bytes = payloadSize(payload);
152
+ if (bytes > maxFrameBytes || queuedCount >= 64 || queuedBytes + bytes > 1048576) {
153
+ close();
154
+ return;
155
+ }
156
+ let copy;
157
+ try {
158
+ copy = typeof payload === "string" ? payload : copyBinary(payload, bytes);
159
+ } catch {
103
160
  close();
104
161
  return;
105
162
  }
106
- const copy = typeof payload === "string" ? payload : Uint8Array.from(payload);
107
- const bytes = payloadSize(copy);
108
163
  queuedCount++;
109
164
  queuedBytes += bytes;
110
165
  const task = queue.then(async () => {
@@ -186,7 +241,20 @@ function createDesktopStreams(options) {
186
241
  close();
187
242
  return;
188
243
  }
189
- expiry = setTimeout(close, Math.min(channel.expiresAt - now(), 2147483647));
244
+ const scheduleExpiry = () => {
245
+ try {
246
+ if (current()) {
247
+ const remaining = channel.expiresAt - now();
248
+ if (remaining > 0) {
249
+ expiry = setTimeout(scheduleExpiry, Math.min(remaining, 2147483647));
250
+ return true;
251
+ }
252
+ }
253
+ } catch {}
254
+ close();
255
+ return false;
256
+ };
257
+ if (!scheduleExpiry()) return;
190
258
  const opened = await provider.open(result.principal, parsed, {
191
259
  signal: abort.signal,
192
260
  send,
@@ -0,0 +1,2 @@
1
+ export declare const MAX_GATEWAY_TIMER_DELAY_MS = 2147483647;
2
+ export declare function isValidGatewayTimeoutMs(timeoutMs: number | undefined): boolean;
@@ -0,0 +1,6 @@
1
+ // src/desktop/gateway-limits.ts
2
+ var MAX_GATEWAY_TIMER_DELAY_MS = 2147483647;
3
+ function isValidGatewayTimeoutMs(timeoutMs) {
4
+ return timeoutMs === void 0 || Number.isSafeInteger(timeoutMs) && timeoutMs >= 1 && timeoutMs <= 2147483647;
5
+ }
6
+ export { MAX_GATEWAY_TIMER_DELAY_MS, isValidGatewayTimeoutMs };
@@ -1,10 +1,11 @@
1
+ type OpenUrlListener = (payload: unknown) => void;
1
2
  /** A bounded queue for native open-url events received before app initialization.
2
3
  * URL contents are untrusted; the receiver must validate targets and payloads.
3
4
  * Async receivers start in event order but their completion is not serialized. */
4
5
  export declare function createOpenUrlChannel(app: {
5
- on(name: 'open-url', handler: (payload: {
6
- url?: unknown;
7
- }) => void): unknown;
6
+ on(name: 'open-url', handler: OpenUrlListener): unknown;
7
+ off?(name: 'open-url', handler: OpenUrlListener): unknown;
8
+ removeListener?(name: 'open-url', handler: OpenUrlListener): unknown;
8
9
  }, options?: {
9
10
  maxBuffered?: number;
10
11
  maxLength?: number;
@@ -13,3 +14,4 @@ export declare function createOpenUrlChannel(app: {
13
14
  attach(next: (url: string) => void | Promise<void>): void;
14
15
  dispose(): void;
15
16
  };
17
+ export {};
@@ -21,14 +21,25 @@ function createOpenUrlChannel(app, options = {}) {
21
21
  reportError();
22
22
  }
23
23
  };
24
- const unsubscribe = app.on("open-url", (payload) => {
25
- if (disposed || typeof payload?.url !== "string" || !payload.url || payload.url.length > maxLength) return;
24
+ const listener = (payload) => {
25
+ if (disposed) return;
26
+ let url;
27
+ try {
28
+ if (typeof payload !== "object" || payload === null) return;
29
+ const event = payload;
30
+ const nested = event.data?.url;
31
+ url = typeof nested === "string" ? nested : event.url;
32
+ } catch {
33
+ return;
34
+ }
35
+ if (typeof url !== "string" || !url || url.length > maxLength) return;
26
36
  if (receive && !draining) {
27
- deliver(payload.url);
37
+ deliver(url);
28
38
  return;
29
39
  }
30
- if (pending.length < maxBuffered) pending.push(payload.url);
31
- });
40
+ if (pending.length < maxBuffered) pending.push(url);
41
+ };
42
+ const unsubscribe = app.on("open-url", listener);
32
43
  return {
33
44
  attach(next) {
34
45
  if (disposed || receive || typeof next !== "function") throw new Error("Open-url receiver is unavailable");
@@ -49,6 +60,8 @@ function createOpenUrlChannel(app, options = {}) {
49
60
  receive = void 0;
50
61
  pending.length = 0;
51
62
  if (typeof unsubscribe === "function") unsubscribe();
63
+ else if (typeof app.off === "function") app.off("open-url", listener);
64
+ else app.removeListener?.("open-url", listener);
52
65
  }
53
66
  };
54
67
  }
@@ -0,0 +1,6 @@
1
+ /** Read the internal buffer slot; invalid receivers (including proxies) throw. */
2
+ export declare function typedArrayBuffer(view: Uint8Array): ArrayBufferLike;
3
+ /** Read the internal byte-length slot; invalid receivers (including proxies) throw. */
4
+ export declare function typedArrayByteLength(view: Uint8Array): number;
5
+ /** Read the internal byte-offset slot; invalid receivers (including proxies) throw. */
6
+ export declare function typedArrayByteOffset(view: Uint8Array): number;
@@ -0,0 +1,19 @@
1
+ // src/desktop/typed-array-intrinsics.ts
2
+ /** Captured Uint8Array base getters, independent of user-overridden view properties. */
3
+ var typedArrayPrototype = Object.getPrototypeOf(Uint8Array.prototype);
4
+ var typedArrayBufferGetter = Object.getOwnPropertyDescriptor(typedArrayPrototype, "buffer").get;
5
+ var typedArrayByteLengthGetter = Object.getOwnPropertyDescriptor(typedArrayPrototype, "byteLength").get;
6
+ var typedArrayByteOffsetGetter = Object.getOwnPropertyDescriptor(typedArrayPrototype, "byteOffset").get;
7
+ /** Read the internal buffer slot; invalid receivers (including proxies) throw. */
8
+ function typedArrayBuffer(view) {
9
+ return typedArrayBufferGetter.call(view);
10
+ }
11
+ /** Read the internal byte-length slot; invalid receivers (including proxies) throw. */
12
+ function typedArrayByteLength(view) {
13
+ return typedArrayByteLengthGetter.call(view);
14
+ }
15
+ /** Read the internal byte-offset slot; invalid receivers (including proxies) throw. */
16
+ function typedArrayByteOffset(view) {
17
+ return typedArrayByteOffsetGetter.call(view);
18
+ }
19
+ export { typedArrayBuffer, typedArrayByteLength, typedArrayByteOffset };
@@ -1 +1 @@
1
- {"version":"0.25.0","commit":"cdd27e85b7321e4fe3418bb7960bde6321b06462"}
1
+ {"version":"0.26.0","commit":"0619c543d21813fb8ce967fc6e9d11233c986f3f"}
@@ -170,7 +170,7 @@ async function verifyInstalledPayload(options) {
170
170
  const env = options.env ?? process.env;
171
171
  assertInstallerContext(env, options.platform, process.platform, process.arch);
172
172
  assertPortableAppName(options.appName);
173
- const sidecars = assertSidecarNames(options.sidecars ?? []).map((name) => sidecarBundlePath(name, options.platform));
173
+ const sidecars = assertSidecarNames(options.sidecars ?? [], options.platform).map((name) => sidecarBundlePath(name, options.platform));
174
174
  if (!/^\d+\.\d+\.\d+(?:-dev\.\d+)?$/.test(options.version) || options.version.length > 64) throw new Error("Invalid installed version");
175
175
  const profile = await realpath(options.profile), root = await realpath(options.installedRoot), archive = resolve(options.archive);
176
176
  if (!(await lstat(profile)).isDirectory() || !(await lstat(root)).isDirectory() || !within(profile, root)) throw new Error("Installed root escapes isolated profile");
@@ -13,7 +13,8 @@ var bootstrapModules = [
13
13
  "installer/installer-renderer-evidence.js",
14
14
  "installer/hosted-runner.js",
15
15
  "release/release-qualification.js",
16
- "desktop/string-policy.js"
16
+ "desktop/string-policy.js",
17
+ "shared/discard-stream.js"
17
18
  ];
18
19
  /** Copy a bounded external preload into the current disposable runner's temp directory. */
19
20
  async function prepareInstallerCiBootstrap(env = process.env) {
@@ -0,0 +1,13 @@
1
+ export type InstallerCommandChild = {
2
+ stdout: AsyncIterable<Uint8Array>;
3
+ stderr: AsyncIterable<Uint8Array>;
4
+ exited: Promise<number>;
5
+ kill(): unknown;
6
+ };
7
+ export type InstallerCommandSpawn = (args: string[], env: Record<string, string>) => InstallerCommandChild;
8
+ export declare function runInstallerCommand(args: string[], env: Record<string, string>, options: {
9
+ outputLimit: number;
10
+ overflowMessage: string;
11
+ failureMessage: string;
12
+ spawn?: InstallerCommandSpawn;
13
+ }): Promise<string>;
@@ -0,0 +1,47 @@
1
+ // src/installer/installer-command.ts
2
+ async function runInstallerCommand(args, env, options) {
3
+ const child = (options.spawn ?? ((command, commandEnv) => Bun.spawn({
4
+ cmd: command,
5
+ env: commandEnv,
6
+ stdout: "pipe",
7
+ stderr: "pipe",
8
+ signal: AbortSignal.timeout(12e4)
9
+ })))(args, env);
10
+ const stop = () => {
11
+ try {
12
+ child.kill();
13
+ } catch {}
14
+ };
15
+ const output = (async () => {
16
+ try {
17
+ const chunks = [];
18
+ let size = 0;
19
+ for await (const chunk of child.stdout) {
20
+ size += chunk.length;
21
+ if (size > options.outputLimit) {
22
+ stop();
23
+ throw new Error(options.overflowMessage);
24
+ }
25
+ chunks.push(chunk);
26
+ }
27
+ return Buffer.concat(chunks).toString("utf8");
28
+ } catch (error) {
29
+ stop();
30
+ throw error;
31
+ }
32
+ })();
33
+ const errors = (async () => {
34
+ for await (const _chunk of child.stderr);
35
+ })();
36
+ const [text, stderr, status] = await Promise.allSettled([
37
+ output,
38
+ errors,
39
+ child.exited
40
+ ]);
41
+ if (text.status === "rejected") throw text.reason;
42
+ if (stderr.status === "rejected") throw stderr.reason;
43
+ if (status.status === "rejected") throw status.reason;
44
+ if (status.value !== 0) throw new Error(options.failureMessage);
45
+ return text.value;
46
+ }
47
+ export { runInstallerCommand };