@adea-ai/app-framework 0.28.1 → 0.28.3

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.
@@ -0,0 +1,46 @@
1
+ import { type FeedChannel } from '../updates/release-feed';
2
+ /** An inventory item from an independent, complete object listing. */
3
+ export type RetentionObject = Readonly<{
4
+ key: string;
5
+ version: string;
6
+ size: number;
7
+ sha256: string;
8
+ modifiedAt: string;
9
+ role: 'payload' | 'provenance';
10
+ }>;
11
+ /**
12
+ * Offline evidence for an advisory report. Completeness must be established by the
13
+ * caller; this module does not fetch, authenticate, lock, or delete any object.
14
+ */
15
+ export type RetentionEvidence = Readonly<{
16
+ feed: unknown;
17
+ ledger: unknown;
18
+ releases: readonly unknown[];
19
+ pointers: Readonly<Record<FeedChannel, unknown | null>>;
20
+ objects: readonly RetentionObject[];
21
+ protectedTags: Readonly<{
22
+ rollback: readonly string[];
23
+ qualification: readonly string[];
24
+ promotion: readonly string[];
25
+ inFlight: readonly string[];
26
+ }>;
27
+ /** Latest time each unprotected release could have been exposed to a reader. */
28
+ lastExposedAt: Readonly<Record<string, string>>;
29
+ /** All sources must cover the complete namespace and all reference classes. */
30
+ complete: boolean;
31
+ now: string;
32
+ discoveryGraceMs: number;
33
+ }>;
34
+ /** Advisory only: returned object identities are not a deletion authorization. */
35
+ export declare function planRetentionDryRun(input: RetentionEvidence): {
36
+ mode: 'advisory-only';
37
+ review: Readonly<{
38
+ key: string;
39
+ version: string;
40
+ size: number;
41
+ sha256: string;
42
+ modifiedAt: string;
43
+ role: 'payload' | 'provenance';
44
+ }>[];
45
+ protectedTags: string[];
46
+ };
@@ -0,0 +1,94 @@
1
+ import { feedAssetKey, parseFeedRelease, parseReleaseFeed, parseReleaseLedger } from "../updates/release-feed.js";
2
+ import { versionLessThan } from "../updates/release-version.js";
3
+ // src/release/retention-dry-run.ts
4
+ var DAY = 864e5;
5
+ var channels = [
6
+ "dev",
7
+ "daily",
8
+ "stable"
9
+ ];
10
+ function time(value) {
11
+ const parsed = Date.parse(value);
12
+ if (!Number.isFinite(parsed) || new Date(parsed).toISOString().replace(".000Z", "Z") !== value.replace(".000Z", "Z")) throw new Error("Invalid retention timestamp");
13
+ return parsed;
14
+ }
15
+ /** Advisory only: returned object identities are not a deletion authorization. */
16
+ function planRetentionDryRun(input) {
17
+ if (input.complete !== true) throw new Error("Incomplete retention evidence");
18
+ const feed = parseReleaseFeed(input.feed);
19
+ const ledger = parseReleaseLedger(input.ledger, feed.app);
20
+ const now = time(input.now);
21
+ if (!Number.isSafeInteger(input.discoveryGraceMs) || input.discoveryGraceMs < DAY || input.discoveryGraceMs > 7 * DAY) throw new Error("Invalid discovery grace");
22
+ const releases = new Map(input.releases.map((value) => {
23
+ const release = parseFeedRelease(value);
24
+ return [release.tag, release];
25
+ }));
26
+ if (releases.size !== input.releases.length || releases.size !== ledger.releases.length) throw new Error("Release inventory does not match ledger");
27
+ const protectedTags = /* @__PURE__ */ new Set();
28
+ for (const key of [
29
+ "rollback",
30
+ "qualification",
31
+ "promotion",
32
+ "inFlight"
33
+ ]) {
34
+ const list = input.protectedTags?.[key];
35
+ if (!Array.isArray(list)) throw new Error("Incomplete protection references");
36
+ for (const tag of list) protectedTags.add(tag);
37
+ }
38
+ for (const channel of channels) {
39
+ if (!Object.hasOwn(input.pointers, channel)) throw new Error("Missing channel pointer");
40
+ const value = input.pointers[channel];
41
+ const kinds = channel === "dev" ? ["dev"] : channel === "stable" ? ["stable"] : ["daily", "stable"];
42
+ if (value === null) {
43
+ if (ledger.releases.some((entry) => kinds.includes(entry.kind))) throw new Error("Missing active channel");
44
+ continue;
45
+ }
46
+ const pointer = parseFeedRelease(value);
47
+ const newest = ledger.releases.filter((item) => kinds.includes(item.kind)).reduce((best, item) => !best || versionLessThan(best.tag, item.tag) ? item : best, void 0);
48
+ const release = releases.get(pointer.tag);
49
+ const entry = ledger.releases.find((item) => item.tag === pointer.tag);
50
+ if (!release || !entry || newest?.tag !== pointer.tag || pointer.channel !== channel || !kinds.includes(entry.kind) || pointer.publishedAt !== release.publishedAt || JSON.stringify(pointer.assets) !== JSON.stringify(release.assets) || channel === "stable" && JSON.stringify(pointer.missingPlatforms) !== JSON.stringify(release.missingPlatforms)) throw new Error("Inconsistent channel pointer");
51
+ protectedTags.add(pointer.tag);
52
+ }
53
+ for (const tag of protectedTags) if (!releases.has(tag)) throw new Error("Missing protected release");
54
+ const objects = /* @__PURE__ */ new Map();
55
+ for (const item of input.objects) {
56
+ if (objects.has(item.key) || !["payload", "provenance"].includes(item.role) || typeof item.version !== "string" || !item.version || !Number.isSafeInteger(item.size) || item.size < 1 || !/^[a-f0-9]{64}$/.test(item.sha256) || time(item.modifiedAt) > now) throw new Error("Invalid object identity");
57
+ objects.set(item.key, item);
58
+ }
59
+ const review = [];
60
+ let unprotectedDailyCount = 0;
61
+ for (const entry of ledger.releases) {
62
+ const release = releases.get(entry.tag);
63
+ if (!release || release.channel !== entry.kind || release.publishedAt !== entry.publishedAt) throw new Error("Inconsistent release ledger");
64
+ if (entry.kind === "dev" || entry.kind === "stable") protectedTags.add(entry.tag);
65
+ const releaseTime = Math.max(time(entry.publishedAt), entry.promotedAt ? time(entry.promotedAt) : 0);
66
+ if (releaseTime > now) throw new Error("Future release");
67
+ const releaseObjects = [];
68
+ for (const asset of release.assets) {
69
+ const key = feedAssetKey(feed, entry.tag, asset.name);
70
+ const item = objects.get(key);
71
+ if (!item || item.size !== asset.size || item.sha256 !== asset.sha256) throw new Error("Missing or inconsistent asset identity");
72
+ objects.delete(key);
73
+ releaseObjects.push(item);
74
+ }
75
+ if (!protectedTags.has(entry.tag)) {
76
+ unprotectedDailyCount++;
77
+ const lastChange = Math.max(releaseTime, ...releaseObjects.map((item) => time(item.modifiedAt)));
78
+ if (!input.lastExposedAt || !Object.hasOwn(input.lastExposedAt, entry.tag)) throw new Error("Missing last-exposure evidence");
79
+ const exposure = input.lastExposedAt[entry.tag];
80
+ if (typeof exposure !== "string") throw new Error("Missing last-exposure evidence");
81
+ const lastExposed = time(exposure);
82
+ if (lastExposed < releaseTime || lastExposed > now) throw new Error("Invalid last-exposure evidence");
83
+ const age = now - lastChange;
84
+ if (age >= input.discoveryGraceMs && now - lastExposed >= input.discoveryGraceMs && (age >= 7 * DAY || unprotectedDailyCount > 20)) review.push(...releaseObjects.filter((item) => item.role === "payload").map((item) => ({ ...item })));
85
+ }
86
+ }
87
+ if (objects.size) throw new Error("Unaccounted release asset");
88
+ return {
89
+ mode: "advisory-only",
90
+ review,
91
+ protectedTags: [...protectedTags].toSorted()
92
+ };
93
+ }
94
+ export { planRetentionDryRun };
@@ -17,7 +17,8 @@ export type UpdateChannelSource = UpdateChannelStore | UpdateChannelService;
17
17
  export declare function updateChannelStore(source: UpdateChannelSource): UpdateChannelStore;
18
18
  /**
19
19
  * Report every snapshot the updater answers with, for a pending-update badge that
20
- * must not run a second checker. The wrapped adapter otherwise behaves identically.
20
+ * must not run a second checker. Observer failures are ignored; updater failures still propagate.
21
+ * The wrapped adapter otherwise behaves identically.
21
22
  */
22
23
  export declare function mirrorUpdateState(adapter: UpdateAdapter, onState: (state: UpdateState) => void): UpdateAdapter;
23
24
  /** A native updater snapshot in snake_case, as Rust and older desktop hosts report it. */
@@ -48,7 +49,8 @@ export declare function updateStateFromNative(update: NativeUpdateSnapshot, opti
48
49
  }): UpdateState;
49
50
  /**
50
51
  * Bridge a snake_case native updater to the shared adapter. Release notes are dropped
51
- * unless requested, which keeps the dialog's per-release notes section hidden.
52
+ * unless requested, which keeps the dialog's per-release notes section hidden. An accessor is
53
+ * read when an operation or polling interval is requested, so it can provide a replacement.
52
54
  */
53
55
  export declare function nativeUpdateAdapter(native: NativeUpdateAdapter | (() => NativeUpdateAdapter), options?: {
54
56
  releaseNotes?: boolean;
@@ -1,3 +1,4 @@
1
+ import { toUpdateState } from "./update-state.js";
1
2
  // src/updates/update-adapter.ts
2
3
  /** Normalize either channel shape to `read`/`persist`. */
3
4
  function updateChannelStore(source) {
@@ -7,19 +8,35 @@ function updateChannelStore(source) {
7
8
  persist: (channel) => source.setChannel(channel)
8
9
  };
9
10
  }
11
+ var mirroredAdapterKeys = /* @__PURE__ */ new Set([
12
+ "check",
13
+ "getStatus",
14
+ "install",
15
+ "isDesktopRuntime",
16
+ "pollIntervalMs",
17
+ "cancel",
18
+ "openExternal"
19
+ ]);
10
20
  /**
11
21
  * Report every snapshot the updater answers with, for a pending-update badge that
12
- * must not run a second checker. The wrapped adapter otherwise behaves identically.
22
+ * must not run a second checker. Observer failures are ignored; updater failures still propagate.
23
+ * The wrapped adapter otherwise behaves identically.
13
24
  */
14
25
  function mirrorUpdateState(adapter, onState) {
15
26
  const note = async (pending) => {
16
27
  const state = await pending;
17
- onState(state);
28
+ try {
29
+ Promise.resolve(onState(state)).catch(() => {});
30
+ } catch {}
18
31
  return state;
19
32
  };
20
- const cancel = adapter.cancel;
33
+ const forwarded = Object.create(null);
34
+ for (const key of Reflect.ownKeys(adapter)) {
35
+ if (mirroredAdapterKeys.has(key)) continue;
36
+ if (Object.prototype.propertyIsEnumerable.call(adapter, key)) forwarded[key] = Reflect.get(adapter, key);
37
+ }
21
38
  return {
22
- ...adapter,
39
+ ...forwarded,
23
40
  check: () => note(adapter.check()),
24
41
  getStatus: () => note(adapter.getStatus()),
25
42
  install: (expectedVersion) => note(adapter.install(expectedVersion)),
@@ -27,29 +44,24 @@ function mirrorUpdateState(adapter, onState) {
27
44
  get pollIntervalMs() {
28
45
  return adapter.pollIntervalMs;
29
46
  },
30
- ...adapter.openExternal ? { openExternal: (url) => adapter.openExternal(url) } : {},
31
- ...cancel ? { cancel: () => note(cancel.call(adapter)) } : {}
47
+ get cancel() {
48
+ const cancel = adapter.cancel;
49
+ return cancel ? () => note(cancel.call(adapter)) : void 0;
50
+ },
51
+ get openExternal() {
52
+ const openExternal = adapter.openExternal;
53
+ return openExternal ? (url) => openExternal.call(adapter, url) : void 0;
54
+ }
32
55
  };
33
56
  }
34
57
  /** Map a snake_case native snapshot to the shared update state. */
35
58
  function updateStateFromNative(update, options = {}) {
36
- return {
37
- availableVersion: update.available_version,
38
- changelog: update.changelog,
39
- currentVersion: update.current_version,
40
- downloadedBytes: update.downloaded_bytes,
41
- error: update.error,
42
- phase: update.phase,
43
- releaseDate: update.release_date,
44
- releaseNotes: options.releaseNotes ? update.release_notes ?? null : null,
45
- releaseUrl: update.github_url,
46
- restartRequired: update.restart_required,
47
- totalBytes: update.total_bytes
48
- };
59
+ return toUpdateState(update, { includeReleaseNotes: Boolean(options.releaseNotes) });
49
60
  }
50
61
  /**
51
62
  * Bridge a snake_case native updater to the shared adapter. Release notes are dropped
52
- * unless requested, which keeps the dialog's per-release notes section hidden.
63
+ * unless requested, which keeps the dialog's per-release notes section hidden. An accessor is
64
+ * read when an operation or polling interval is requested, so it can provide a replacement.
53
65
  */
54
66
  function nativeUpdateAdapter(native, options = {}) {
55
67
  const current = typeof native === "function" ? native : () => native;
@@ -58,7 +70,9 @@ function nativeUpdateAdapter(native, options = {}) {
58
70
  getStatus: async () => updateStateFromNative(await current().getStatus(), options),
59
71
  install: async (expectedVersion) => updateStateFromNative(await current().install(expectedVersion), options),
60
72
  isDesktopRuntime: () => current().isDesktopRuntime(),
61
- pollIntervalMs: current().pollIntervalMs
73
+ get pollIntervalMs() {
74
+ return current().pollIntervalMs;
75
+ }
62
76
  };
63
77
  }
64
78
  /** The adapter for a build with no installer: the dialog explains updates are desktop-only. */
@@ -13,7 +13,10 @@ export type NativeUpdateState<Phase extends string = string> = Readonly<{
13
13
  restart_required: boolean;
14
14
  }>;
15
15
  /** Project a native snapshot into the shared UI update dialog contract. */
16
- export declare function toUpdateState<Phase extends string>(update: NativeUpdateState<Phase>, options?: {
16
+ export declare function toUpdateState<Phase extends string, Url extends string | null = string>(update: Omit<NativeUpdateState<Phase>, 'github_url' | 'release_notes'> & Readonly<{
17
+ github_url: Url;
18
+ release_notes?: string | null;
19
+ }>, options?: {
17
20
  includeReleaseNotes?: boolean;
18
21
  }): {
19
22
  phase: Phase;
@@ -25,6 +28,6 @@ export declare function toUpdateState<Phase extends string>(update: NativeUpdate
25
28
  downloadedBytes: number;
26
29
  totalBytes: number | null;
27
30
  error: string | null;
28
- releaseUrl: string;
31
+ releaseUrl: Url;
29
32
  restartRequired: boolean;
30
33
  };
@@ -6,7 +6,7 @@ function toUpdateState(update, options = {}) {
6
6
  currentVersion: update.current_version,
7
7
  availableVersion: update.available_version,
8
8
  changelog: update.changelog,
9
- releaseNotes: options.includeReleaseNotes === false ? null : update.release_notes,
9
+ releaseNotes: options.includeReleaseNotes === false ? null : update.release_notes ?? null,
10
10
  releaseDate: update.release_date,
11
11
  downloadedBytes: update.downloaded_bytes,
12
12
  totalBytes: update.total_bytes,
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@adea-ai/app-framework",
3
- "version": "0.28.1",
3
+ "version": "0.28.3",
4
4
  "license": "Apache-2.0",
5
5
  "repository": {
6
6
  "type": "git",
7
- "url": "git+https://github.com/adea-ai/app-framework.git"
7
+ "url": "git+https://gitlab.com/adea-ai/ade/app-framework.git"
8
8
  },
9
9
  "bin": {
10
10
  "adea-cef-helper": "./dist/cli/cef-helper-cli.js",
@@ -127,6 +127,11 @@ export function createAppearanceContext(ui: UiThemeContextValue): AppearanceCont
127
127
 
128
128
  return {
129
129
  ...ui,
130
+ // `themes` is a live getter on the shared provider. Spreading the context
131
+ // would otherwise capture only the initial catalogue snapshot.
132
+ get themes() {
133
+ return ui.themes
134
+ },
130
135
  update: (patch) => ui.setSelection(selectionFromPreferences(patch)),
131
136
  preview,
132
137
  }
@@ -122,6 +122,83 @@ export function createClientAssetVerificationCache(maxEntries = 256): ClientAsse
122
122
  type AssetFile = Pick<FileHandle, 'close' | 'stat' | 'read'>
123
123
  type OpenAsset = (path: string, flags: 'r') => Promise<AssetFile>
124
124
 
125
+ /** One admission to hold an asset file open. */
126
+ type ClientAssetFileSlot = {
127
+ /** Resolves true once admitted, or false if withdrawn first. */
128
+ readonly ready: Promise<boolean>
129
+ /** Leave the queue if still waiting; does nothing once admitted. */
130
+ withdraw(): void
131
+ /** Free an admitted slot, or withdraw a waiting one. Idempotent. */
132
+ release(): void
133
+ }
134
+
135
+ /** Admission limit on streamed asset files a host holds open at once. */
136
+ export type ClientAssetFileLimit = {
137
+ acquire(): ClientAssetFileSlot
138
+ readonly active: number
139
+ readonly waiting: number
140
+ }
141
+
142
+ /**
143
+ * Bound open streamed asset files. Readers beyond the limit wait, first in first out,
144
+ * without holding a descriptor; a waiting reader that is cancelled leaves the queue.
145
+ */
146
+ export function createClientAssetFileLimit(maxOpenFiles = 32): ClientAssetFileLimit {
147
+ if (!Number.isInteger(maxOpenFiles) || maxOpenFiles < 1 || maxOpenFiles > 1024)
148
+ throw new Error('Invalid client asset file limit')
149
+ let active = 0
150
+ const queue: { admit(): void; withdrawn: boolean }[] = []
151
+ const next = () => {
152
+ while (active < maxOpenFiles && queue.length) {
153
+ const waiter = queue.shift()!
154
+ if (waiter.withdrawn) continue
155
+ active++
156
+ waiter.admit()
157
+ }
158
+ }
159
+ return {
160
+ get active() {
161
+ return active
162
+ },
163
+ get waiting() {
164
+ return queue.filter((waiter) => !waiter.withdrawn).length
165
+ },
166
+ acquire() {
167
+ let state: 'waiting' | 'admitted' | 'done' = 'waiting'
168
+ let settle!: (admitted: boolean) => void
169
+ const ready = new Promise<boolean>((resolve) => (settle = resolve))
170
+ const waiter = {
171
+ withdrawn: false,
172
+ admit() {
173
+ state = 'admitted'
174
+ settle(true)
175
+ },
176
+ }
177
+ const withdraw = () => {
178
+ if (state !== 'waiting') return
179
+ state = 'done'
180
+ waiter.withdrawn = true
181
+ const index = queue.indexOf(waiter)
182
+ if (index !== -1) queue.splice(index, 1)
183
+ settle(false)
184
+ }
185
+ queue.push(waiter)
186
+ next()
187
+ return {
188
+ ready,
189
+ withdraw,
190
+ release() {
191
+ if (state === 'waiting') return withdraw()
192
+ if (state !== 'admitted') return
193
+ state = 'done'
194
+ active--
195
+ next()
196
+ },
197
+ }
198
+ },
199
+ }
200
+ }
201
+
125
202
  /**
126
203
  * Stream an immutable bundled asset. This is not a snapshot: detected file changes
127
204
  * fail the stream, and a read error can surface after response headers have been sent.
@@ -129,9 +206,17 @@ type OpenAsset = (path: string, flags: 'r') => Promise<AssetFile>
129
206
  export function createClientAssetStream(
130
207
  path: string,
131
208
  expected: Stats,
132
- openAsset: OpenAsset = open
209
+ openAsset: OpenAsset = open,
210
+ limit?: ClientAssetFileLimit
133
211
  ): ReadableStream<Uint8Array> {
134
212
  let file: AssetFile | undefined
213
+ // The admission held while this stream owns an open descriptor (or waits for one).
214
+ let slot: ClientAssetFileSlot | undefined
215
+ const releaseSlot = () => {
216
+ const current = slot
217
+ slot = undefined
218
+ current?.release()
219
+ }
135
220
  let opening: Promise<void> | undefined
136
221
  let closing: Promise<void> | undefined
137
222
  let pulling: Promise<void> | undefined
@@ -143,12 +228,19 @@ export function createClientAssetStream(
143
228
  if (closing) return closing
144
229
  const current = file
145
230
  file = undefined
146
- if (!current) return Promise.resolve()
147
- const pending = current.close().catch((error: unknown) => {
148
- closeFailed = true
149
- closeFailure = error
150
- throw error
151
- })
231
+ if (!current) {
232
+ releaseSlot()
233
+ return Promise.resolve()
234
+ }
235
+ const pending = current
236
+ .close()
237
+ .catch((error: unknown) => {
238
+ closeFailed = true
239
+ closeFailure = error
240
+ throw error
241
+ })
242
+ // The descriptor is the stream's to close; once closing settles, its slot is free.
243
+ .finally(releaseSlot)
152
244
  closing = pending
153
245
  const clear = () => {
154
246
  if (closing === pending) closing = undefined
@@ -160,7 +252,21 @@ export function createClientAssetStream(
160
252
  if (cancelled || file) return Promise.resolve()
161
253
  if (opening) return opening
162
254
  const task = (async () => {
163
- const opened = await openAsset(path, 'r')
255
+ if (limit && !slot) {
256
+ const admission = limit.acquire()
257
+ slot = admission
258
+ if (!(await admission.ready) || cancelled) {
259
+ releaseSlot()
260
+ return
261
+ }
262
+ }
263
+ let opened: AssetFile
264
+ try {
265
+ opened = await openAsset(path, 'r')
266
+ } catch (error) {
267
+ releaseSlot()
268
+ throw error
269
+ }
164
270
  if (cancelled) {
165
271
  try {
166
272
  await opened.close()
@@ -168,6 +274,8 @@ export function createClientAssetStream(
168
274
  closeFailed = true
169
275
  closeFailure = error
170
276
  throw error
277
+ } finally {
278
+ releaseSlot()
171
279
  }
172
280
  return
173
281
  }
@@ -233,6 +341,8 @@ export function createClientAssetStream(
233
341
  },
234
342
  async cancel() {
235
343
  cancelled = true
344
+ // A reader still queued for admission holds no descriptor; leave the queue now.
345
+ slot?.withdraw()
236
346
  const pending = opening
237
347
  if (pending) await pending.catch(() => {})
238
348
  // A read or final stat can still be using the file after it opened.
@@ -4,13 +4,16 @@ import { open, readFile, realpath, stat } from 'node:fs/promises'
4
4
  import { extname, join, posix, relative, resolve, sep } from 'node:path'
5
5
  import {
6
6
  createClientAssetStream,
7
+ type ClientAssetFileLimit,
7
8
  type ClientAssetVerificationCache,
8
9
  verifyClientAssetCached,
9
10
  verifyClientAssetDigest,
10
11
  } from './client-asset-stream'
11
12
  import { parseClientAssetManifest, snapshotClientAssetAllowlist } from './client-asset-manifest'
12
13
  export {
14
+ createClientAssetFileLimit,
13
15
  createClientAssetVerificationCache,
16
+ type ClientAssetFileLimit,
14
17
  type ClientAssetVerificationCache,
15
18
  } from './client-asset-stream'
16
19
  export {
@@ -54,6 +57,8 @@ export type ClientOptions = {
54
57
  immutableAssets?: ReadonlyMap<string, string>
55
58
  /** Bounded, host-lifetime cache of successful checks for unchanged immutable files. */
56
59
  verificationCache?: ClientAssetVerificationCache
60
+ /** Admission limit shared by streamed GET bodies; readers past it wait without a descriptor. */
61
+ openFileLimit?: ClientAssetFileLimit
57
62
  }
58
63
 
59
64
  const unavailable = (status = 404) =>
@@ -287,13 +292,16 @@ async function serveClientInternal(
287
292
  const cacheVerified =
288
293
  immutableSha256 !== undefined &&
289
294
  (await matchesManifestDigest(physical, metadata, immutableSha256, options.verificationCache))
290
- return new Response(createClientAssetStream(physical, metadata), {
291
- headers: {
292
- 'content-type': contentType,
293
- 'cache-control': cacheVerified ? IMMUTABLE_CACHE_CONTROL : 'no-store',
294
- 'content-length': String(metadata.size),
295
- },
296
- })
295
+ return new Response(
296
+ createClientAssetStream(physical, metadata, undefined, options.openFileLimit),
297
+ {
298
+ headers: {
299
+ 'content-type': contentType,
300
+ 'cache-control': cacheVerified ? IMMUTABLE_CACHE_CONTROL : 'no-store',
301
+ 'content-length': String(metadata.size),
302
+ },
303
+ }
304
+ )
297
305
  }
298
306
 
299
307
  let body = new Uint8Array(await Bun.file(physical).arrayBuffer())
@@ -3,6 +3,7 @@ import type {
3
3
  UpdateChannel,
4
4
  UpdateState,
5
5
  } from '@adea-ai/ui/components/composites/update-dialog'
6
+ import { toUpdateState } from './update-state'
6
7
 
7
8
  export type { UpdateAdapter, UpdateChannel, UpdateState }
8
9
 
@@ -31,9 +32,20 @@ export function updateChannelStore(source: UpdateChannelSource): UpdateChannelSt
31
32
  }
32
33
  }
33
34
 
35
+ const mirroredAdapterKeys = new Set<PropertyKey>([
36
+ 'check',
37
+ 'getStatus',
38
+ 'install',
39
+ 'isDesktopRuntime',
40
+ 'pollIntervalMs',
41
+ 'cancel',
42
+ 'openExternal',
43
+ ])
44
+
34
45
  /**
35
46
  * Report every snapshot the updater answers with, for a pending-update badge that
36
- * must not run a second checker. The wrapped adapter otherwise behaves identically.
47
+ * must not run a second checker. Observer failures are ignored; updater failures still propagate.
48
+ * The wrapped adapter otherwise behaves identically.
37
49
  */
38
50
  export function mirrorUpdateState(
39
51
  adapter: UpdateAdapter,
@@ -41,12 +53,24 @@ export function mirrorUpdateState(
41
53
  ): UpdateAdapter {
42
54
  const note = async (pending: Promise<UpdateState>) => {
43
55
  const state = await pending
44
- onState(state)
56
+ try {
57
+ // An observer updates a badge; it must not change the updater's result or leave a rejected
58
+ // promise unhandled when an application supplies an async observer.
59
+ void Promise.resolve(onState(state)).catch(() => {})
60
+ } catch {
61
+ // Synchronous observer failures are isolated for the same reason.
62
+ }
45
63
  return state
46
64
  }
47
- const cancel = adapter.cancel
65
+ // Copy enumerable extension properties without evaluating overridden adapter getters early.
66
+ const forwarded: Record<PropertyKey, unknown> = Object.create(null)
67
+ for (const key of Reflect.ownKeys(adapter)) {
68
+ if (mirroredAdapterKeys.has(key)) continue
69
+ if (Object.prototype.propertyIsEnumerable.call(adapter, key))
70
+ forwarded[key] = Reflect.get(adapter, key)
71
+ }
48
72
  return {
49
- ...adapter,
73
+ ...forwarded,
50
74
  check: () => note(adapter.check()),
51
75
  getStatus: () => note(adapter.getStatus()),
52
76
  install: (expectedVersion) => note(adapter.install(expectedVersion)),
@@ -54,8 +78,14 @@ export function mirrorUpdateState(
54
78
  get pollIntervalMs() {
55
79
  return adapter.pollIntervalMs
56
80
  },
57
- ...(adapter.openExternal ? { openExternal: (url: string) => adapter.openExternal!(url) } : {}),
58
- ...(cancel ? { cancel: () => note(cancel.call(adapter)) } : {}),
81
+ get cancel() {
82
+ const cancel = adapter.cancel
83
+ return cancel ? () => note(cancel.call(adapter)) : undefined
84
+ },
85
+ get openExternal() {
86
+ const openExternal = adapter.openExternal
87
+ return openExternal ? (url: string) => openExternal.call(adapter, url) : undefined
88
+ },
59
89
  }
60
90
  }
61
91
 
@@ -88,24 +118,13 @@ export function updateStateFromNative(
88
118
  update: NativeUpdateSnapshot,
89
119
  options: { releaseNotes?: boolean } = {}
90
120
  ): UpdateState {
91
- return {
92
- availableVersion: update.available_version,
93
- changelog: update.changelog,
94
- currentVersion: update.current_version,
95
- downloadedBytes: update.downloaded_bytes,
96
- error: update.error,
97
- phase: update.phase,
98
- releaseDate: update.release_date,
99
- releaseNotes: options.releaseNotes ? (update.release_notes ?? null) : null,
100
- releaseUrl: update.github_url,
101
- restartRequired: update.restart_required,
102
- totalBytes: update.total_bytes,
103
- }
121
+ return toUpdateState(update, { includeReleaseNotes: Boolean(options.releaseNotes) })
104
122
  }
105
123
 
106
124
  /**
107
125
  * Bridge a snake_case native updater to the shared adapter. Release notes are dropped
108
- * unless requested, which keeps the dialog's per-release notes section hidden.
126
+ * unless requested, which keeps the dialog's per-release notes section hidden. An accessor is
127
+ * read when an operation or polling interval is requested, so it can provide a replacement.
109
128
  */
110
129
  export function nativeUpdateAdapter(
111
130
  native: NativeUpdateAdapter | (() => NativeUpdateAdapter),
@@ -118,7 +137,9 @@ export function nativeUpdateAdapter(
118
137
  install: async (expectedVersion) =>
119
138
  updateStateFromNative(await current().install(expectedVersion), options),
120
139
  isDesktopRuntime: () => current().isDesktopRuntime(),
121
- pollIntervalMs: current().pollIntervalMs,
140
+ get pollIntervalMs() {
141
+ return current().pollIntervalMs
142
+ },
122
143
  }
123
144
  }
124
145
 
@@ -14,8 +14,9 @@ export type NativeUpdateState<Phase extends string = string> = Readonly<{
14
14
  }>
15
15
 
16
16
  /** Project a native snapshot into the shared UI update dialog contract. */
17
- export function toUpdateState<Phase extends string>(
18
- update: NativeUpdateState<Phase>,
17
+ export function toUpdateState<Phase extends string, Url extends string | null = string>(
18
+ update: Omit<NativeUpdateState<Phase>, 'github_url' | 'release_notes'> &
19
+ Readonly<{ github_url: Url; release_notes?: string | null }>,
19
20
  options: { includeReleaseNotes?: boolean } = {}
20
21
  ) {
21
22
  return {
@@ -23,7 +24,7 @@ export function toUpdateState<Phase extends string>(
23
24
  currentVersion: update.current_version,
24
25
  availableVersion: update.available_version,
25
26
  changelog: update.changelog,
26
- releaseNotes: options.includeReleaseNotes === false ? null : update.release_notes,
27
+ releaseNotes: options.includeReleaseNotes === false ? null : (update.release_notes ?? null),
27
28
  releaseDate: update.release_date,
28
29
  downloadedBytes: update.downloaded_bytes,
29
30
  totalBytes: update.total_bytes,