@adea-ai/app-framework 0.39.0 → 0.39.2

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 (34) hide show
  1. package/ci/desktop-release-feed.sh +108 -0
  2. package/ci/desktop-release.sh +15 -33
  3. package/dist/cli/release-finalize-cli.d.ts +1 -0
  4. package/dist/cli/release-finalize-cli.js +17 -13
  5. package/dist/desktop/client-assets.js +52 -7
  6. package/dist/developer-app/developer-app.js +30 -12
  7. package/dist/framework-source.json +1 -1
  8. package/dist/native/sidecar.d.ts +0 -19
  9. package/dist/native/sidecar.js +35 -9
  10. package/dist/native/window-bootstrap.js +3 -1
  11. package/dist/shell/app-shell.js +49 -60
  12. package/dist/shell/app-utilities.js +17 -10
  13. package/dist/shell/media-query.d.ts +2 -1
  14. package/dist/shell/media-query.js +4 -3
  15. package/dist/update-helper.bundle.js +4 -4
  16. package/dist/updates/desktop-updater.js +2 -2
  17. package/dist/updates/helper/resume-staging.d.ts +4 -1
  18. package/dist/updates/helper/resume-staging.js +7 -9
  19. package/dist/updates/helper/update-resume.js +4 -3
  20. package/dist/updates/install/update-download.d.ts +1 -0
  21. package/dist/updates/install/update-download.js +10 -2
  22. package/dist/updates/install/update-swap.d.ts +2 -0
  23. package/dist/updates/install/update-swap.js +6 -2
  24. package/dist/updates/launch/update-launch-gate.d.ts +3 -2
  25. package/dist/updates/launch/update-launch-gate.js +3 -2
  26. package/dist/updates/locks/update-download-lock.js +2 -2
  27. package/dist/updates/retention/retirement-inventory.d.ts +4 -0
  28. package/dist/updates/retention/retirement-inventory.js +6 -4
  29. package/dist/updates/update-state-store.js +3 -3
  30. package/package.json +2 -1
  31. package/src/desktop/client-assets.ts +73 -13
  32. package/src/shell/app-shell.tsx +38 -47
  33. package/src/shell/app-utilities.tsx +22 -17
  34. package/src/shell/media-query.ts +4 -3
@@ -65,6 +65,51 @@ const unavailable = (status = 404) =>
65
65
  new Response(null, { status, headers: { 'cache-control': 'no-store' } })
66
66
 
67
67
  const IMMUTABLE_CACHE_CONTROL = 'public, max-age=31536000, immutable'
68
+ const REVALIDATE_CACHE_CONTROL = 'no-cache'
69
+
70
+ /*
71
+ * A validator for a file the manifest does not vouch for. It names the file's identity, so
72
+ * any rewrite, replacement or swapped root yields a new tag. With `no-cache` the webview keeps
73
+ * the bytes (and the compiled code it derives from them) and asks before each use; an
74
+ * unchanged file costs a 304 and no read.
75
+ */
76
+ function fileEntityTag(metadata: Stats): string {
77
+ return `W/"${[metadata.dev, metadata.ino, metadata.size, metadata.mtimeMs, metadata.ctimeMs]
78
+ .map((value) => Math.trunc(value * 1000).toString(36))
79
+ .join('-')}"`
80
+ }
81
+
82
+ function matchesEntityTag(request: Request, tag: string): boolean {
83
+ const header = request.headers.get('if-none-match')
84
+ if (!header) return false
85
+ if (header.trim() === '*') return true
86
+ return header.split(',').some((candidate) => {
87
+ const value = candidate.trim()
88
+ return value === tag || `W/${value}` === tag
89
+ })
90
+ }
91
+
92
+ const deniedPrefixCache = new Map<string, readonly string[]>()
93
+
94
+ /** Normalized, case-folded denied prefixes, computed once per distinct list. */
95
+ function deniedPrefixes(paths: readonly string[] | undefined): readonly string[] {
96
+ if (!paths?.length) return []
97
+ const key = paths.join('\0')
98
+ let prefixes = deniedPrefixCache.get(key)
99
+ if (!prefixes) {
100
+ prefixes = paths.map(
101
+ (item) =>
102
+ posix
103
+ .normalize('/' + item.replaceAll('\\', '/'))
104
+ .toLowerCase()
105
+ .replace(/\/$/, '') || '/'
106
+ )
107
+ // Lists are few and fixed per host; the bound only guards a caller that builds them per request.
108
+ if (deniedPrefixCache.size >= 32) deniedPrefixCache.clear()
109
+ deniedPrefixCache.set(key, prefixes)
110
+ }
111
+ return prefixes
112
+ }
68
113
 
69
114
  /** A caller-owned, immutable client root kept available for the resolver's lifetime. */
70
115
  export type RetainedClientAssetRoot = Readonly<{
@@ -210,16 +255,14 @@ async function serveClientInternal(
210
255
 
211
256
  const logical = clientPath(request)
212
257
  if (logical === undefined) return unavailable()
213
- const denied = (path: string) =>
214
- (options.deniedPaths ?? []).some((item) => {
215
- const prefix =
216
- posix
217
- .normalize('/' + item.replaceAll('\\', '/'))
218
- .toLowerCase()
219
- .replace(/\/$/, '') || '/'
220
- const folded = path.toLowerCase()
221
- return prefix === '/' || folded === prefix || folded.startsWith(prefix + '/')
222
- })
258
+ const prefixes = deniedPrefixes(options.deniedPaths)
259
+ const denied = (path: string) => {
260
+ if (!prefixes.length) return false
261
+ const folded = path.toLowerCase()
262
+ return prefixes.some(
263
+ (prefix) => prefix === '/' || folded === prefix || folded.startsWith(prefix + '/')
264
+ )
265
+ }
223
266
  if (denied(logical)) return unavailable()
224
267
  let root: string
225
268
  try {
@@ -257,6 +300,23 @@ async function serveClientInternal(
257
300
  /^[a-f0-9]{64}$/.test(configuredSha256)
258
301
  ? configuredSha256
259
302
  : undefined
303
+ // A file the manifest does not name revalidates instead of being refetched, so the webview
304
+ // keeps its bytes and compiled code across reloads and launches. HTML stays uncached because
305
+ // the host may inject per-launch values into it, and so does a file the manifest names whose
306
+ // bytes disagree with it.
307
+ const entityTag =
308
+ extension !== '.html' && extension !== '.map' && configuredSha256 === undefined
309
+ ? fileEntityTag(metadata)
310
+ : undefined
311
+ if (entityTag !== undefined && matchesEntityTag(request, entityTag))
312
+ return new Response(null, {
313
+ status: 304,
314
+ headers: { etag: entityTag, 'cache-control': REVALIDATE_CACHE_CONTROL },
315
+ })
316
+ const uncachedHeaders: Record<string, string> =
317
+ entityTag === undefined
318
+ ? { 'cache-control': 'no-store' }
319
+ : { 'cache-control': REVALIDATE_CACHE_CONTROL, etag: entityTag }
260
320
  if (request.method === 'HEAD' && !(extension === '.html' && options.transformHtml)) {
261
321
  // Open the file to check readability and derive the representation length.
262
322
  const file = await open(physical, 'r')
@@ -279,7 +339,7 @@ async function serveClientInternal(
279
339
  headers: {
280
340
  'content-type': contentType,
281
341
  'content-length': String(fileMetadata.size),
282
- 'cache-control': cacheVerified ? IMMUTABLE_CACHE_CONTROL : 'no-store',
342
+ ...(cacheVerified ? { 'cache-control': IMMUTABLE_CACHE_CONTROL } : uncachedHeaders),
283
343
  },
284
344
  })
285
345
  }
@@ -297,7 +357,7 @@ async function serveClientInternal(
297
357
  {
298
358
  headers: {
299
359
  'content-type': contentType,
300
- 'cache-control': cacheVerified ? IMMUTABLE_CACHE_CONTROL : 'no-store',
360
+ ...(cacheVerified ? { 'cache-control': IMMUTABLE_CACHE_CONTROL } : uncachedHeaders),
301
361
  'content-length': String(metadata.size),
302
362
  },
303
363
  }
@@ -314,7 +374,7 @@ async function serveClientInternal(
314
374
  return new Response(request.method === 'HEAD' ? null : body, {
315
375
  headers: {
316
376
  'content-type': contentType,
317
- 'cache-control': cacheVerified ? IMMUTABLE_CACHE_CONTROL : 'no-store',
377
+ ...(cacheVerified ? { 'cache-control': IMMUTABLE_CACHE_CONTROL } : uncachedHeaders),
318
378
  ...(cacheVerified && request.method === 'GET'
319
379
  ? { 'content-length': String(body.byteLength) }
320
380
  : {}),
@@ -17,10 +17,12 @@ import { ActionButton } from '@adea-ai/ui/components/composites/action-button'
17
17
  import { TooltipProvider } from '@adea-ai/ui/components/ui/tooltip'
18
18
  import { PanelLeftClose, PanelLeftIcon, PanelLeftOpen } from 'lucide-solid'
19
19
  import { hasEditableKeyboardTarget } from './keyboard-target'
20
+ import { createMediaQuery, DEFAULT_NARROW_QUERY } from './media-query'
20
21
  import {
21
22
  For,
22
23
  Show,
23
24
  Suspense,
25
+ children,
24
26
  createComputed,
25
27
  createEffect,
26
28
  createSignal,
@@ -89,36 +91,17 @@ export type ApplicationShellProps = {
89
91
  class?: string
90
92
  }
91
93
 
92
- function createNarrow(query: () => string | undefined) {
93
- const [narrow, setNarrow] = createSignal(false)
94
- createEffect(() => {
95
- const value = query()
96
- if (!value || typeof window === 'undefined' || !window.matchMedia) return setNarrow(false)
97
- const media = window.matchMedia(value)
98
- const update = () => setNarrow(media.matches)
99
- update()
100
- media.addEventListener('change', update)
101
- onCleanup(() => media.removeEventListener('change', update))
102
- })
103
- return narrow
104
- }
105
-
106
94
  function getSidebarResponsiveMode(sidebar: ContextualSidebarProps | undefined) {
107
- // `responsiveMode` was added after the oldest UI versions supported by Framework.
108
- if (sidebar && 'responsiveMode' in sidebar) {
109
- const mode = sidebar.responsiveMode
110
- if (mode === 'auto' || mode === 'desktop' || mode === 'mobile') return mode
111
- }
112
- return undefined
95
+ return sidebar?.responsiveMode
113
96
  }
114
97
 
115
98
  /** Shared chrome and navigation composition; applications own routes and services. */
116
99
  export function ApplicationShell(props: ApplicationShellProps) {
117
100
  let sidebarToggle: HTMLButtonElement | undefined
118
- const narrow = createNarrow(() =>
119
- props.drawer ? (props.narrowQuery ?? '(max-width: 799px)') : undefined
101
+ const narrow = createMediaQuery(() =>
102
+ props.drawer ? (props.narrowQuery ?? DEFAULT_NARROW_QUERY) : undefined
120
103
  )
121
- const sidebarMobile = createNarrow(() =>
104
+ const sidebarMobile = createMediaQuery(() =>
122
105
  !props.drawer && props.sidebar ? '(max-width: 48rem)' : undefined
123
106
  )
124
107
  const [sidebarElementMobile, setSidebarElementMobile] = createSignal<boolean>()
@@ -248,6 +231,37 @@ export function ApplicationShell(props: ApplicationShellProps) {
248
231
  window.removeEventListener('keydown', handleToggle)
249
232
  })
250
233
  })
234
+ // The rail slot resolves once, and only while the rail shows: reading a JSX prop in both a
235
+ // `when` and the body would build the app's rail twice.
236
+ const RailContent = () => {
237
+ const rail = children(() => props.rail)
238
+ return (
239
+ <Show
240
+ when={rail()}
241
+ fallback={
242
+ <SideRailSection label="Views">
243
+ <For each={props.destinations}>
244
+ {(item) => (
245
+ <SideRailItem
246
+ as="button"
247
+ type="button"
248
+ label={item.label}
249
+ aria-label={item.label}
250
+ active={props.activeDestination === item.id}
251
+ aria-pressed={props.activeDestination === item.id}
252
+ onClick={() => props.onNavigate(item.id)}
253
+ >
254
+ {item.icon}
255
+ </SideRailItem>
256
+ )}
257
+ </For>
258
+ </SideRailSection>
259
+ }
260
+ >
261
+ {rail()}
262
+ </Show>
263
+ )
264
+ }
251
265
  return (
252
266
  <TooltipProvider openDelay={150}>
253
267
  <div class={`flex h-screen w-screen flex-col overflow-hidden ${props.class ?? ''}`}>
@@ -302,30 +316,7 @@ export function ApplicationShell(props: ApplicationShellProps) {
302
316
  searchKeys={props.searchKeys}
303
317
  footer={props.footer}
304
318
  >
305
- <Show
306
- when={props.rail}
307
- fallback={
308
- <SideRailSection label="Views">
309
- <For each={props.destinations}>
310
- {(item) => (
311
- <SideRailItem
312
- as="button"
313
- type="button"
314
- label={item.label}
315
- aria-label={item.label}
316
- active={props.activeDestination === item.id}
317
- aria-pressed={props.activeDestination === item.id}
318
- onClick={() => props.onNavigate(item.id)}
319
- >
320
- {item.icon}
321
- </SideRailItem>
322
- )}
323
- </For>
324
- </SideRailSection>
325
- }
326
- >
327
- {props.rail}
328
- </Show>
319
+ <RailContent />
329
320
  </ShellRail>
330
321
  </Show>
331
322
  <AppShellBody>
@@ -234,7 +234,7 @@ export function ApplicationUtilities(props: ApplicationUtilitiesProps) {
234
234
  }
235
235
  const settingsOpen = () =>
236
236
  props.settings?.open !== undefined ? props.settings.open : dialog() === 'settings'
237
- const updatesAlways = () => props.accountMenu?.updates === 'always'
237
+ const updatesAlways = createMemo(() => props.accountMenu?.updates === 'always')
238
238
  const updateAdapter = createMemo(
239
239
  () => props.updater ?? browserUpdateAdapter(props.identity.version)
240
240
  )
@@ -327,31 +327,36 @@ export function ApplicationUtilities(props: ApplicationUtilitiesProps) {
327
327
  })
328
328
  })
329
329
  const close = () => show(undefined)
330
- const items = (): AccountMenuItem[] => {
331
- const menu = props.accountMenu
330
+ // Menu inputs as separate memos: an app that passes `accountMenu` as an inline object (say,
331
+ // with a reactive `busy`) rebuilds that object on every change, and the items must not be
332
+ // rebuilt, nor the open menu re-rendered, for a field they never read.
333
+ const menuSettingsShortcut = createMemo(() => props.accountMenu?.settingsShortcut)
334
+ const menuSettingsKeyshortcuts = createMemo(
335
+ () => props.accountMenu?.settingsKeyshortcuts ?? DEFAULT_SETTINGS_KEYSHORTCUTS
336
+ )
337
+ const menuAppearance = createMemo(() => props.accountMenu?.appearance !== false)
338
+ const hasSettings = createMemo(() => Boolean(props.settings))
339
+ const hasHelp = createMemo(() => Boolean(props.help))
340
+ const hasUpdates = createMemo(() => Boolean(props.updater || props.onUpdates || updatesAlways()))
341
+ const items = createMemo((): AccountMenuItem[] => {
342
+ const onSettings = props.onSettings
343
+ const onHelp = props.onHelp
332
344
  const shared = createAppMenuItems({
333
345
  primaryItem: props.primaryItem,
334
- settingsShortcut: menu?.settingsShortcut,
346
+ settingsShortcut: menuSettingsShortcut(),
335
347
  onAbout: (target) => open('about', target),
336
- onUpdates:
337
- props.updater || props.onUpdates || updatesAlways()
338
- ? (target) => openUpdates(target)
339
- : undefined,
348
+ onUpdates: hasUpdates() ? (target) => openUpdates(target) : undefined,
340
349
  onSettings:
341
- props.onSettings ??
342
- (props.settings ? (target) => openSettings(undefined, target) : undefined),
343
- onHelp: props.onHelp ?? (props.help ? (target) => open('help', target) : undefined),
350
+ onSettings ?? (hasSettings() ? (target) => openSettings(undefined, target) : undefined),
351
+ onHelp: onHelp ?? (hasHelp() ? (target) => open('help', target) : undefined),
344
352
  onFeedback: props.onFeedback,
345
353
  }).map((item) => {
346
354
  if (item.id === 'settings' && item.shortcut)
347
- return {
348
- ...item,
349
- keyshortcuts: menu?.settingsKeyshortcuts ?? DEFAULT_SETTINGS_KEYSHORTCUTS,
350
- }
355
+ return { ...item, keyshortcuts: menuSettingsKeyshortcuts() }
351
356
  if (item.id === 'updates' && updatesAlways()) return { ...item, platform: undefined }
352
357
  return item
353
358
  })
354
- if (menu?.appearance === false) return shared
359
+ if (!menuAppearance()) return shared
355
360
  return [
356
361
  {
357
362
  id: 'appearance',
@@ -361,7 +366,7 @@ export function ApplicationUtilities(props: ApplicationUtilitiesProps) {
361
366
  },
362
367
  ...shared,
363
368
  ]
364
- }
369
+ })
365
370
  return (
366
371
  <>
367
372
  <AccountMenu
@@ -1,4 +1,4 @@
1
- import { createEffect, createSignal, onCleanup } from 'solid-js'
1
+ import { createComputed, createSignal, onCleanup } from 'solid-js'
2
2
 
3
3
  /** When the application shell counts a window as narrow. */
4
4
  export const DEFAULT_NARROW_QUERY = '(max-width: 799px)'
@@ -42,12 +42,13 @@ function subscribe(query: string, subscriber: (matches: boolean) => void): () =>
42
42
  /**
43
43
  * Reactive `matchMedia`. Components watching the same query share one listener. The query
44
44
  * may be reactive and the subscription follows it; an empty or absent query, or a runtime
45
- * without `matchMedia`, reads as not matching.
45
+ * without `matchMedia`, reads as not matching. The first read already reflects the window, so
46
+ * a narrow window never renders its wide layout for a frame and then swaps it out.
46
47
  */
47
48
  export function createMediaQuery(query: string | (() => string | undefined)): () => boolean {
48
49
  const text = typeof query === 'function' ? query : () => query
49
50
  const [matches, setMatches] = createSignal(false)
50
- createEffect(() => {
51
+ createComputed(() => {
51
52
  const value = text()
52
53
  if (!value || !supported()) {
53
54
  setMatches(false)