moi-computer 0.12.1-next.1 → 0.12.1-next.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 (86) hide show
  1. package/client/AGENTS.md +3 -2
  2. package/client/api/app-config.ts +3 -9
  3. package/client/api/workspace-keys.ts +2 -1
  4. package/client/app/app-provider.tsx +25 -0
  5. package/client/app/routes/workspace-route.tsx +4 -0
  6. package/client/app/shell/sidebar-layout.tsx +19 -13
  7. package/client/dev/index.html +5 -5
  8. package/client/features/applets/api.ts +1 -1
  9. package/client/features/chat/connection/chat-frames.ts +2 -2
  10. package/client/features/chat/sessions/api.ts +1 -1
  11. package/client/features/chat/use-chat.ts +1 -1
  12. package/client/features/collab/host-state.ts +24 -7
  13. package/client/features/collab/local-user.ts +1 -1
  14. package/client/features/collab/proxy-user.ts +4 -9
  15. package/client/features/demo/demo-dialog.tsx +25 -79
  16. package/client/features/dev/workspace-setup-preview.tsx +43 -16
  17. package/client/features/harness/device-login-steps.tsx +2 -2
  18. package/client/features/home/api.ts +29 -9
  19. package/client/features/home/home-page.tsx +7 -4
  20. package/client/features/scratchpad/scratchpad.tsx +3 -6
  21. package/client/features/settings/api.ts +14 -8
  22. package/client/features/workspace/api.ts +12 -16
  23. package/client/features/workspace/setup/workspace-login-state.tsx +4 -4
  24. package/client/features/workspace/setup/workspace-setup.tsx +2 -1
  25. package/client/features/workspace/workspace-content.tsx +12 -52
  26. package/client/features/workspace/workspace-frame.tsx +76 -0
  27. package/client/features/workspace/workspace-layout-context.tsx +2 -0
  28. package/client/features/workspace/workspace-pending-screen.tsx +26 -0
  29. package/client/features/workspace/workspace-screen.tsx +3 -3
  30. package/client/index.html +28 -9
  31. package/client/index.tsx +7 -2
  32. package/client/lib/browser-tab-id.ts +4 -0
  33. package/client/main.tsx +9 -6
  34. package/client/runtime/app-context.ts +20 -0
  35. package/client/runtime/use-workspace-events.ts +29 -153
  36. package/client/runtime/workspace-events.ts +151 -0
  37. package/dist/chunk-00rh9df4.js +2 -0
  38. package/dist/chunk-4nh7y1hq.css +1 -0
  39. package/dist/{chunk-jvyvwwv3.js → chunk-am4agx6v.js} +1 -1
  40. package/dist/chunk-hbpdv7vd.js +1 -0
  41. package/dist/chunk-hmka9rt5.js +2 -0
  42. package/dist/chunk-mjjregkn.js +10 -0
  43. package/dist/chunk-vt6zybej.js +2 -0
  44. package/dist/chunk-wbkwf6cc.js +68 -0
  45. package/dist/chunk-xjyfyz64.js +1 -0
  46. package/dist/{chunk-q0gbdts4.js → chunk-y8nbwp21.js} +71 -71
  47. package/dist/chunk-ysfdcew7.js +1 -0
  48. package/dist/index.html +29 -10
  49. package/lib/ids.ts +2 -2
  50. package/package.json +1 -1
  51. package/server/api/index.ts +41 -22
  52. package/server/applets/thumbnails.ts +8 -5
  53. package/server/harness/codex/thread-list.ts +4 -0
  54. package/server/static.ts +4 -2
  55. package/server/vendor.ts +23 -30
  56. package/server/web.ts +3 -2
  57. package/server/workspaces/layout.ts +11 -6
  58. package/dist/chunk-08ndj2rg.js +0 -2
  59. package/dist/chunk-2x040tmg.js +0 -68
  60. package/dist/chunk-3smxq0ts.js +0 -1
  61. package/dist/chunk-68ch5hs8.js +0 -2
  62. package/dist/chunk-9vg3xa81.js +0 -2
  63. package/dist/chunk-c2p00p9j.css +0 -1
  64. package/dist/chunk-cs833y9j.js +0 -1
  65. package/dist/chunk-nwevqe86.js +0 -10
  66. package/dist/chunk-y5y3kj67.js +0 -1
  67. /package/client/vendor/react/{development → 19.2.4/development}/_impl/react-dom-client.js +0 -0
  68. /package/client/vendor/react/{development → 19.2.4/development}/_impl/react-dom.js +0 -0
  69. /package/client/vendor/react/{development → 19.2.4/development}/_impl/react-jsx-dev-runtime.js +0 -0
  70. /package/client/vendor/react/{development → 19.2.4/development}/_impl/react-jsx-runtime.js +0 -0
  71. /package/client/vendor/react/{development → 19.2.4/development}/_impl/react.js +0 -0
  72. /package/client/vendor/react/{development → 19.2.4/development}/react-dom-client.js +0 -0
  73. /package/client/vendor/react/{development → 19.2.4/development}/react-dom.js +0 -0
  74. /package/client/vendor/react/{development → 19.2.4/development}/react-jsx-dev-runtime.js +0 -0
  75. /package/client/vendor/react/{development → 19.2.4/development}/react-jsx-runtime.js +0 -0
  76. /package/client/vendor/react/{development → 19.2.4/development}/react.js +0 -0
  77. /package/client/vendor/react/{production → 19.2.4/production}/_impl/react-dom-client.js +0 -0
  78. /package/client/vendor/react/{production → 19.2.4/production}/_impl/react-dom.js +0 -0
  79. /package/client/vendor/react/{production → 19.2.4/production}/_impl/react-jsx-dev-runtime.js +0 -0
  80. /package/client/vendor/react/{production → 19.2.4/production}/_impl/react-jsx-runtime.js +0 -0
  81. /package/client/vendor/react/{production → 19.2.4/production}/_impl/react.js +0 -0
  82. /package/client/vendor/react/{production → 19.2.4/production}/react-dom-client.js +0 -0
  83. /package/client/vendor/react/{production → 19.2.4/production}/react-dom.js +0 -0
  84. /package/client/vendor/react/{production → 19.2.4/production}/react-jsx-dev-runtime.js +0 -0
  85. /package/client/vendor/react/{production → 19.2.4/production}/react-jsx-runtime.js +0 -0
  86. /package/client/vendor/react/{production → 19.2.4/production}/react.js +0 -0
@@ -0,0 +1 @@
1
+ import{Tc as k}from"/chunk-hmka9rt5.js";import{Xc as m}from"/chunk-am4agx6v.js";import"/chunk-d7cbm65e.js";async function z(){try{let j=await m("/api/proxy-user");if(!j||typeof j!=="object"||Array.isArray(j)||j.provider!==void 0&&j.provider!=="cloudflare-access"||j.provider===void 0&&j.profile!==void 0)return;return k(j),j}catch{}}async function C(){return z()}export{C as loadProxyUser};
package/dist/index.html CHANGED
@@ -20,23 +20,42 @@
20
20
  }
21
21
  </style>
22
22
  <link rel="icon" type="image/png" href="/favicon-nbmyjfjh.png" />
23
- <!-- React is vendored locally (client/vendor/react, generated by
24
- scripts/build-vendor.ts) and served by the /vendor/react route, so moi
25
- runs fully offline — no CDN fetch. The server picks the development or
26
- production build per environment behind these stable URLs. -->
23
+ <!-- React is vendored locally (client/vendor/react/<version>, generated by
24
+ scripts/build-vendor.ts, which also rewrites these URLs) and served by
25
+ the /vendor/react route, so moi runs fully offline — no CDN fetch. The
26
+ version and build mode in the path let the browser cache them forever;
27
+ this source names the development build and scripts/build-client.ts
28
+ switches it to production in dist/. -->
27
29
  <script type="importmap">
28
30
  {
29
31
  "imports": {
30
- "react": "/vendor/react/react.js",
31
- "react/jsx-runtime": "/vendor/react/react-jsx-runtime.js",
32
- "react/jsx-dev-runtime": "/vendor/react/react-jsx-dev-runtime.js",
33
- "react-dom": "/vendor/react/react-dom.js",
34
- "react-dom/client": "/vendor/react/react-dom-client.js"
32
+ "react": "/vendor/react/19.2.4/production/react.js",
33
+ "react/jsx-runtime": "/vendor/react/19.2.4/production/react-jsx-runtime.js",
34
+ "react/jsx-dev-runtime": "/vendor/react/19.2.4/production/react-jsx-dev-runtime.js",
35
+ "react-dom": "/vendor/react/19.2.4/production/react-dom.js",
36
+ "react-dom/client": "/vendor/react/19.2.4/production/react-dom-client.js"
35
37
  }
36
38
  }
37
39
  </script>
40
+ <!-- Fetch React (the wrappers and the _impl files they import) as soon as
41
+ the HTML is parsed, instead of two round trips later when the preload
42
+ script below gets to run. Must stay after the importmap: a module
43
+ fetch that starts before the map is parsed disables the map. -->
44
+ <link rel="modulepreload" href="/vendor/react/19.2.4/production/react.js" />
45
+ <link rel="modulepreload" href="/vendor/react/19.2.4/production/_impl/react.js" />
46
+ <link rel="modulepreload" href="/vendor/react/19.2.4/production/react-jsx-runtime.js" />
47
+ <link rel="modulepreload" href="/vendor/react/19.2.4/production/_impl/react-jsx-runtime.js" />
48
+ <link rel="modulepreload" href="/vendor/react/19.2.4/production/react-jsx-dev-runtime.js" />
49
+ <link
50
+ rel="modulepreload"
51
+ href="/vendor/react/19.2.4/production/_impl/react-jsx-dev-runtime.js"
52
+ />
53
+ <link rel="modulepreload" href="/vendor/react/19.2.4/production/react-dom.js" />
54
+ <link rel="modulepreload" href="/vendor/react/19.2.4/production/_impl/react-dom.js" />
55
+ <link rel="modulepreload" href="/vendor/react/19.2.4/production/react-dom-client.js" />
56
+ <link rel="modulepreload" href="/vendor/react/19.2.4/production/_impl/react-dom-client.js" />
38
57
 
39
- <link rel="stylesheet" crossorigin href="/chunk-c2p00p9j.css"><script type="module" crossorigin src="/chunk-y5y3kj67.js"></script></head>
58
+ <link rel="stylesheet" crossorigin href="/chunk-4nh7y1hq.css"><script type="module" crossorigin src="/chunk-hbpdv7vd.js"></script></head>
40
59
  <body>
41
60
  <div id="root"></div>
42
61
 
package/lib/ids.ts CHANGED
@@ -10,12 +10,12 @@ export const newWorkspaceId = customAlphabet(ALPHABET, 10)
10
10
 
11
11
  // Ids no workspace can hold, because a URL carrying one never reaches it:
12
12
  // `/api/workspaces/:id` is registered after the literal collection routes, so
13
- // `create`, `discover` and `order` match those instead, and `ws` is claimed by
13
+ // `create`, `discover`, `order` and `previews` match those instead, and `ws` is claimed by
14
14
  // the live-event WebSocket upgrade in `server/web.ts` before Hono sees the
15
15
  // request. A workspace registered under one of these would persist fine and
16
16
  // then be unreachable in the app. `server/api/reserved-ids.test.ts` re-derives
17
17
  // this list from the router so a new collection route cannot outgrow it.
18
- export const RESERVED_WORKSPACE_IDS = ['create', 'discover', 'order', 'ws']
18
+ export const RESERVED_WORKSPACE_IDS = ['create', 'discover', 'order', 'previews', 'ws']
19
19
 
20
20
  // Ids may also be chosen by hand (`moi init --id <id>`), so they are validated
21
21
  // rather than assumed. Slightly wider than the generated alphabet — dashes and
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "moi-computer",
3
- "version": "0.12.1-next.1",
3
+ "version": "0.12.1-next.2",
4
4
  "description": "Local AI workspace powered by the Claude Agent SDK, Bun, React, and Tailwind. Requires Bun.",
5
5
  "license": "Elastic-2.0",
6
6
  "type": "module",
@@ -115,6 +115,12 @@ import {
115
115
  // `/api/workspaces/:id/*` handler can read it without re-querying the registry.
116
116
  type ApiEnv = { Variables: { ws: WorkspaceEntry } }
117
117
 
118
+ // The writing browser tab's id from a request body, echoed on the resulting
119
+ // event so that tab can skip it. See client/lib/browser-tab-id.ts.
120
+ function eventOrigin(value: unknown): string | undefined {
121
+ return typeof value === 'string' ? value : undefined
122
+ }
123
+
118
124
  function publishSelectedSession(workspaceId: string, update: SelectedSessionUpdate): void {
119
125
  if (!update.changed) return
120
126
  publishEvent({
@@ -178,20 +184,6 @@ const withWorkspace = createMiddleware<ApiEnv>(async (c, next) => {
178
184
  const one = new Hono<ApiEnv>()
179
185
  one.use('*', withWorkspace)
180
186
 
181
- one.get('/preview', async c => {
182
- const ws = c.get('ws')
183
- const views = await listCompiledViews(ws.path)
184
- return c.json(
185
- await getWorkspacePreview(ws.path, {
186
- getProviderPreview: includeFirstUserMessage =>
187
- harnessFor(ws).workspacePreview(ws, includeFirstUserMessage),
188
- viewIds: views.map(view => view.id),
189
- thumbnailUrl: (kind, id) =>
190
- `/api/workspaces/${ws.id}/applet-thumbnails/${kind}/${encodeURIComponent(id)}`
191
- })
192
- )
193
- })
194
-
195
187
  one.get('/widgets', c => listWidgets(c.get('ws').path))
196
188
 
197
189
  // Widget bundle: the compiled ESM for one widget, dynamically imported by the
@@ -734,7 +726,7 @@ one.put('/config', async c => {
734
726
  return c.text('Expected a workspace config field', 400)
735
727
  }
736
728
  await setWorkspaceConfig(ws.path, { name, icon })
737
- publishEvent({ type: 'workspace:updated' })
729
+ publishEvent({ type: 'workspace:updated', origin: eventOrigin(body.origin) })
738
730
  return c.json(await getWorkspaceConfig(ws.path))
739
731
  })
740
732
 
@@ -758,7 +750,7 @@ one.put('/scratchpad', async c => {
758
750
  publishEvent({
759
751
  type: 'scratchpad:updated',
760
752
  workspaceId: ws.id,
761
- origin: typeof body.origin === 'string' ? body.origin : undefined
753
+ origin: eventOrigin(body.origin)
762
754
  })
763
755
  return c.body(null, 204)
764
756
  })
@@ -850,11 +842,15 @@ one.get('/applet-thumbnails', async c =>
850
842
  one.get('/applet-thumbnails/:kind/:name', c => {
851
843
  const kind = c.req.param('kind')
852
844
  if (kind !== 'widget' && kind !== 'view') return c.text('Not found', 404)
845
+ // `<id>` or `<id>:<version>`. Applet ids never contain `:`, and the version
846
+ // lives in the path rather than a query string so every CDN keys on it.
847
+ const [id, version] = c.req.param('name').split(':')
853
848
  return serveAppletThumbnail(
854
849
  c.get('ws').path,
855
850
  kind,
856
- c.req.param('name'),
857
- c.req.header('if-none-match')
851
+ id!,
852
+ c.req.header('if-none-match'),
853
+ version !== undefined
858
854
  )
859
855
  })
860
856
 
@@ -888,16 +884,18 @@ one.put('/', async c => {
888
884
  const ws = c.get('ws')
889
885
  const body = await c.req.json()
890
886
  if (!body || body.version !== 1) return c.text('Bad request', 400)
887
+ // `origin` is the writing tab's id, echoed so that tab skips its own event.
888
+ const { origin, ...layout } = body
891
889
  // Preserve server-owned identity (name/icon) across a grid/theme save so the
892
890
  // client's PUT can't erase a `moi config`-set name. See mergeLayoutForSave.
893
891
  const existing = await loadLayout(ws.path)
894
- const next = mergeLayoutForSave(existing, body)
892
+ const next = mergeLayoutForSave(existing, layout)
895
893
  await saveLayout(next, ws.path)
896
894
  if (
897
895
  JSON.stringify(resolveWorkspaceTheme(existing.theme)) !==
898
896
  JSON.stringify(resolveWorkspaceTheme(next.theme))
899
897
  ) {
900
- publishEvent({ type: 'theme:updated' })
898
+ publishEvent({ type: 'theme:updated', origin: eventOrigin(origin) })
901
899
  }
902
900
  return c.body(null, 204)
903
901
  })
@@ -945,7 +943,7 @@ workspaces.put('/order', async c => {
945
943
  // List-only change: a narrow event so clients refetch just the sidebar
946
944
  // list, not every per-workspace query (`workspace:updated` also triggers
947
945
  // layout refetches in open workspaces).
948
- publishEvent({ type: 'workspaces-list:updated' })
946
+ publishEvent({ type: 'workspaces-list:updated', origin: eventOrigin(body.origin) })
949
947
  return c.json(await mergeWorkspaceList(entries))
950
948
  } catch (err) {
951
949
  const message = err instanceof Error ? err.message : String(err)
@@ -994,6 +992,27 @@ workspaces.post('/', async c => {
994
992
 
995
993
  workspaces.get('/discover', async c => c.json(await discoverWorkspaces()))
996
994
 
995
+ // Home-card previews for every workspace in one request, keyed by id, so the
996
+ // home page fetches them beside the list instead of one per card after it.
997
+ workspaces.get('/previews', async c => {
998
+ const entries = await listWorkspaces()
999
+ const previews = await Promise.all(
1000
+ entries.map(async ws => {
1001
+ const views = await listCompiledViews(ws.path).catch(() => [])
1002
+ const preview = await getWorkspacePreview(ws.path, {
1003
+ getProviderPreview: includeFirstUserMessage =>
1004
+ harnessFor(ws).workspacePreview(ws, includeFirstUserMessage),
1005
+ viewIds: views.map(view => view.id),
1006
+ // Capture time in base36 keeps the versioned segment short and URL-safe.
1007
+ thumbnailUrl: (kind, id, capturedAt) =>
1008
+ `/api/workspaces/${ws.id}/applet-thumbnails/${kind}/${id}:${Date.parse(capturedAt).toString(36)}`
1009
+ })
1010
+ return [ws.id, preview] as const
1011
+ })
1012
+ )
1013
+ return c.json(Object.fromEntries(previews))
1014
+ })
1015
+
997
1016
  // Backends the create dialog can provision from scratch. OpenClaw workspaces
998
1017
  // belong to their agents and arrive via discovery.
999
1018
  const CREATABLE_TYPES = new Set<WorkspaceType>(['claude-code', 'codex'])
@@ -1090,7 +1109,7 @@ api.post('/api/update', async c => {
1090
1109
 
1091
1110
  try {
1092
1111
  const result = await installUpdate()
1093
- if (!result) return c.text('This Moi install cannot be updated from the app.', 409)
1112
+ if (!result) return c.text('This Moi cannot be updated from the app', 409)
1094
1113
  const response = c.json(result)
1095
1114
  scheduleRestartForUpdate()
1096
1115
  return response
@@ -162,21 +162,24 @@ export function pruneAppletThumbnails(
162
162
  // Records that actually have an image on disk, for the home-card preview.
163
163
  export async function getCapturedThumbnails(
164
164
  workspacePath: string
165
- ): Promise<{ kind: AppletKind; id: string; viewedAt: string }[]> {
165
+ ): Promise<{ kind: AppletKind; id: string; capturedAt: string; viewedAt: string }[]> {
166
166
  const records = await loadIndex(getThumbnailsDir(workspacePath))
167
167
  return records
168
168
  .filter(record => record.file !== undefined)
169
- .map(({ kind, id, viewedAt }) => ({ kind, id, viewedAt }))
169
+ .map(({ kind, id, capturedAt, viewedAt }) => ({ kind, id, capturedAt, viewedAt }))
170
170
  }
171
171
 
172
172
  // One thumbnail image. Same caching story as applet bundles: strong ETag from
173
173
  // size+mtime with `private, no-cache`, so an unchanged file costs a bodyless
174
- // 304 and a re-capture busts every consumer on the next revalidation.
174
+ // 304 and a re-capture busts every consumer on the next revalidation. A
175
+ // `versioned` URL (the home preview's `<id>:<version>`) changes with every
176
+ // capture instead, so the browser keeps it without revalidating.
175
177
  export async function serveAppletThumbnail(
176
178
  workspacePath: string,
177
179
  kind: AppletKind,
178
180
  id: string,
179
- ifNoneMatch?: string | null
181
+ ifNoneMatch?: string | null,
182
+ versioned = false
180
183
  ): Promise<Response> {
181
184
  if (!isValidAppletId(id)) return new Response('Invalid id', { status: 400 })
182
185
  const dir = getThumbnailsDir(workspacePath)
@@ -189,7 +192,7 @@ export async function serveAppletThumbnail(
189
192
  const etag = `"${file.size}-${Math.trunc(file.lastModified)}"`
190
193
  const headers = {
191
194
  ETag: etag,
192
- 'Cache-Control': 'private, no-cache',
195
+ 'Cache-Control': versioned ? 'private, max-age=604800, immutable' : 'private, no-cache',
193
196
  'Content-Type': MIME_BY_EXT[record.file.split('.').pop() ?? ''] ?? 'application/octet-stream'
194
197
  }
195
198
  if (ifNoneMatch === etag) return new Response(null, { status: 304, headers })
@@ -26,6 +26,10 @@ export async function listCodexThreads(
26
26
  cwd: workspacePath,
27
27
  limit: 100,
28
28
  sortKey: 'updated_at',
29
+ // Codex lists only the current provider's chats unless asked for all.
30
+ // Switching between a ChatGPT sign-in and a provider in config.toml (the
31
+ // cloud demo's AI Gateway, an API key) must not hide earlier chats.
32
+ modelProviders: [],
29
33
  useStateDbOnly
30
34
  })
31
35
  let threads: CodexThread[]
package/server/static.ts CHANGED
@@ -17,7 +17,9 @@ const DIST_INDEX = join(DIST_DIR, 'index.html')
17
17
  export const prebuilt = !process.env.MOI_DEV && existsSync(DIST_INDEX)
18
18
 
19
19
  // The prebuilt SPA shell, served for client-side routes in production. In dev,
20
- // web.ts uses the live-bundled HTML import instead (for HMR).
20
+ // web.ts uses the live-bundled HTML import instead (for HMR). `no-cache`: the
21
+ // shell is the one unhashed document — it names the hashed chunks and the
22
+ // versioned React, which are cached for good, so it must be revalidated itself.
21
23
  export function distShell(): Response {
22
- return new Response(Bun.file(DIST_INDEX))
24
+ return new Response(Bun.file(DIST_INDEX), { headers: { 'Cache-Control': 'no-cache' } })
23
25
  }
package/server/vendor.ts CHANGED
@@ -1,48 +1,41 @@
1
- // Serves the locally-vendored React ESM (client/vendor/react, generated by
2
- // scripts/build-vendor.ts) behind the stable `/vendor/react/*` URLs the
3
- // importmap in client/index.html points at. This is what makes moi run offline
4
- // — no esm.sh fetch.
1
+ // Serves the locally-vendored React ESM (client/vendor/react/<version>,
2
+ // generated by scripts/build-vendor.ts) behind the
3
+ // `/vendor/react/<version>/<mode>/*` URLs the importmap in client/index.html
4
+ // points at. This is what makes moi run offline — no esm.sh fetch.
5
5
  //
6
- // The importmap URLs carry no dev/prod distinction; we pick the build here so
7
- // developers get React's warnings (invalid hook calls, key warnings) while
8
- // production gets the smaller build. `client/` ships in the published package
9
- // (see package.json `files`), so this resolves in a global install too.
6
+ // Both the version and the build mode are in the URL, which is what makes the
7
+ // files safe to cache forever: a React bump moves the URL, and the development
8
+ // and production builds (different bytes — prod's jsx-dev-runtime has no
9
+ // `jsxDEV`) never share one, so a prebuilt `moi` and `bun run dev` on the same
10
+ // port cannot poison each other's cache. The source HTML names the development
11
+ // build; scripts/build-client.ts switches it to production in `dist/`.
12
+ // `client/` ships in the published package (see package.json `files`), so this
13
+ // resolves in a global install too.
10
14
  import { join } from 'node:path'
11
15
 
12
- import { prebuilt } from './static'
13
-
14
16
  const VENDOR_DIR = join(import.meta.dir, '..', 'client', 'vendor', 'react')
15
17
  const EMOJIBASE_DIR = join(import.meta.dir, '..', 'client', 'vendor', 'emojibase')
16
- const MODE = prebuilt ? 'production' : 'development'
17
18
 
18
- // A single flat file (`react.js`) or one nested under `_impl/` — both `.js`,
19
- // no traversal. Matches exactly the layout build-vendor.ts emits.
20
- const ALLOWED = /^(_impl\/)?[a-zA-Z0-9_-]+\.js$/
19
+ // `<version>/<mode>/<file>`: a version folder, the build mode, then a single
20
+ // flat file (`react.js`) or one nested under `_impl/` — all `.js`, no
21
+ // traversal. Matches exactly the layout build-vendor.ts emits.
22
+ const ALLOWED = /^\d[\w.-]*\/(development|production)\/(_impl\/)?[a-zA-Z0-9_-]+\.js$/
21
23
 
22
24
  export async function serveVendorReact(req: Request): Promise<Response> {
23
25
  const rel = new URL(req.url).pathname.replace(/^\/vendor\/react\//, '')
24
26
  if (!ALLOWED.test(rel) || rel.includes('..')) {
25
27
  return new Response('Not found', { status: 404 })
26
28
  }
27
- const file = Bun.file(join(VENDOR_DIR, MODE, rel))
29
+ const file = Bun.file(join(VENDOR_DIR, rel))
28
30
  if (!(await file.exists())) {
29
31
  return new Response('Not found', { status: 404 })
30
32
  }
31
- // Revalidate on every load (no max-age): the same URLs serve different bytes
32
- // when the mode flips (prebuilt `moi` vs `bun run dev` on one port) or after
33
- // a `vendor:react` regen. The ETag encodes both, so browsers keep the bytes
34
- // (304) but never reuse a stale mode — prod jsx-dev-runtime has no `jsxDEV`
35
- // and would crash dev.
36
- const etag = `"${MODE}-${file.lastModified}-${file.size}"`
37
- const headers = {
38
- 'Content-Type': 'text/javascript; charset=utf-8',
39
- 'Cache-Control': 'no-cache',
40
- ETag: etag
41
- }
42
- if (req.headers.get('if-none-match') === etag) {
43
- return new Response(null, { status: 304, headers })
44
- }
45
- return new Response(file, { headers })
33
+ return new Response(file, {
34
+ headers: {
35
+ 'Content-Type': 'text/javascript; charset=utf-8',
36
+ 'Cache-Control': 'public, max-age=31536000, immutable'
37
+ }
38
+ })
46
39
  }
47
40
 
48
41
  // `<locale>/<file>.json` only — mirrors the emojibase-data package layout the
package/server/web.ts CHANGED
@@ -140,8 +140,9 @@ export const app = Bun.serve<WsData>({
140
140
  headers: { 'Content-Type': 'text/plain; charset=utf-8', 'Cache-Control': 'no-store' }
141
141
  }),
142
142
 
143
- // Locally-vendored React ESM (offline; no CDN). The importmap in
144
- // client/index.html points here; the handler picks dev/prod per env.
143
+ // Locally-vendored React ESM (offline; no CDN), under a versioned path so
144
+ // production can cache it for good. The importmap in client/index.html
145
+ // points here; the handler picks dev/prod per env.
145
146
  '/vendor/react/*': (req: Request) => serveVendorReact(req),
146
147
 
147
148
  // Vendored emojibase-data for the settings emoji picker (offline; no CDN).
@@ -100,7 +100,8 @@ export type WorkspacePreviewOptions = {
100
100
  viewIds?: readonly string[]
101
101
  // Maps a captured applet to the image URL the home card should render —
102
102
  // the API layer owns the route shape (GET .../applet-thumbnails/:kind/:id).
103
- thumbnailUrl: (kind: AppletKind, id: string) => string
103
+ // `version` changes with every capture, so the URL can be cached forever.
104
+ thumbnailUrl: (kind: AppletKind, id: string, version: string) => string
104
105
  }
105
106
 
106
107
  export async function getWorkspacePreview(
@@ -111,17 +112,21 @@ export async function getWorkspacePreview(
111
112
  const layout = await loadLayout(workspacePath)
112
113
  const captured = await getCapturedThumbnails(workspacePath)
113
114
  const validViewIds = new Set(viewIds)
114
- const capturedWidgets = new Set(
115
- captured.filter(record => record.kind === 'widget').map(record => record.id)
115
+ const capturedWidgets = new Map(
116
+ captured
117
+ .filter(record => record.kind === 'widget')
118
+ .map(record => [record.id, record.capturedAt])
116
119
  )
117
120
  const widgetImages = [...layout.widgetGrid]
118
121
  .sort((a, b) => a.y - b.y || a.x - b.x)
119
- .filter(item => capturedWidgets.has(item.i))
120
- .map(item => thumbnailUrl('widget', item.i))
122
+ .flatMap(item => {
123
+ const version = capturedWidgets.get(item.i)
124
+ return version === undefined ? [] : [thumbnailUrl('widget', item.i, version)]
125
+ })
121
126
  const viewImages = captured
122
127
  .filter(record => record.kind === 'view' && validViewIds.has(record.id))
123
128
  .sort((a, b) => Date.parse(b.viewedAt) - Date.parse(a.viewedAt))
124
- .map(record => thumbnailUrl('view', record.id))
129
+ .map(record => thumbnailUrl('view', record.id, record.capturedAt))
125
130
  const thumbnails = [...widgetImages, ...viewImages].slice(0, PREVIEW_LIMIT)
126
131
  // The message bubble is the card's fallback for "nothing to show": gate on
127
132
  // captured thumbnails, not grid emptiness — a workspace with widgets that
@@ -1,2 +0,0 @@
1
- import{Rc as p}from"/chunk-jvyvwwv3.js";import{Uc as y,Xc as r}from"/chunk-9vg3xa81.js";import{_c as m}from"/chunk-d7cbm65e.js";var E=m(y(),1);var a={collab:!1},f=Object.keys(a);var F={environment:"local",demo:!1,experimental:{...a},demoInstallUrl:"https://moi.computer"},t=F,o=new Set;function d(e){return o.add(e),()=>{o.delete(e)}}async function x(){try{t=await p("/api/config");for(let e of o)e();return t}catch{}}async function b(){let e=await x();return r(()=>{x()}),e}function A(){return E.useSyncExternalStore(d,()=>t)}
2
- export{b as Hc,A as Ic};