moi-computer 0.5.1 → 0.5.2-next.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.
package/dist/index.html CHANGED
@@ -21,7 +21,7 @@
21
21
  }
22
22
  </script>
23
23
 
24
- <link rel="stylesheet" crossorigin href="/chunk-s7za1qsv.css"><script type="module" crossorigin src="/chunk-4tcmvefj.js"></script></head>
24
+ <link rel="stylesheet" crossorigin href="/chunk-s7za1qsv.css"><script type="module" crossorigin src="/chunk-fhhv99bd.js"></script></head>
25
25
  <body>
26
26
  <div id="root"></div>
27
27
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "moi-computer",
3
- "version": "0.5.1",
3
+ "version": "0.5.2-next.0",
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",
package/server/applets.ts CHANGED
@@ -7,8 +7,9 @@
7
7
  //
8
8
  // Each applet builds into its OWN directory `.build/<kind>/<name>/`, holding a
9
9
  // fixed `index.js` entry plus any code chunks and bundled assets (hashed
10
- // images/fonts). The client dynamic-imports `<name>/index.js`; assets and
11
- // chunks resolve module-relative from there. `.js` files carry the
10
+ // images/fonts). The client dynamic-imports that entry at `<name>/module` — an
11
+ // extensionless alias, see `ENTRY_ROUTE_FILE` — and assets and chunks resolve
12
+ // module-relative from there. `.js` files carry the
12
13
  // `%%MOI_APPLET_API_BASE%%` sentinel (for RPC + `fileUrl`), swapped to the real
13
14
  // `/api/workspaces/<id>` base when served — so the on-disk bundle is
14
15
  // workspace-agnostic.
@@ -271,12 +272,21 @@ const HASHED_FILE_RE = /^chunk-[0-9a-z]+\.\w+$|-[0-9a-f]{6,}\.\w+$/i
271
272
  // prefix — substituted for the build-time sentinel in every `.js` so RPC and
272
273
  // `fileUrl` calls hit the right workspace. Assets stream untouched.
273
274
  //
275
+ // `file` is the ON-DISK name (the route's extensionless entry alias is already
276
+ // mapped back to `index.js` by `parseAppletTail`), so the content-type and
277
+ // sentinel-swap decisions below key off the real `.js` — do not switch them to
278
+ // the requested url, or the entry would ship as `application/octet-stream` and
279
+ // fail the browser's module MIME check.
280
+ //
274
281
  // Caching turns on the hashed-vs-stable split. A content-hashed chunk/asset gets
275
282
  // a new url whenever its bytes change, so it's cached forever. The `index.js`
276
283
  // entry (and anything not recognizably hashed) lives at ONE url across rebuilds,
277
284
  // so a shared cache (e.g. Cloudflare) that stored it once would hand back a
278
285
  // STALE copy after the next `moi bundle` — it gets an ETag (size+mtime) +
279
- // `no-cache` instead, so an unchanged file costs a 304 and a rebuilt one busts.
286
+ // `private, no-cache` instead, so an unchanged file costs a 304 and a rebuilt
287
+ // one busts. `private` keeps it out of any shared cache that would store it
288
+ // anyway, and is the one directive Cloudflare preserves when its Browser Cache
289
+ // TTL rewrites the header (see `ENTRY_ROUTE_FILE` for the rest of that story).
280
290
  export async function serveApplet(
281
291
  kind: AppletKind,
282
292
  name: string,
@@ -306,7 +316,7 @@ export async function serveApplet(
306
316
  cache = { 'Cache-Control': IMMUTABLE_CACHE }
307
317
  } else {
308
318
  const etag = `"${bunFile.size}-${Math.trunc(bunFile.lastModified)}"`
309
- cache = { ETag: etag, 'Cache-Control': 'no-cache' }
319
+ cache = { ETag: etag, 'Cache-Control': 'private, no-cache' }
310
320
  if (ifNoneMatch === etag) return new Response(null, { status: 304, headers: cache })
311
321
  }
312
322
 
@@ -329,8 +339,36 @@ export function apiBaseFor(id: string): string {
329
339
  return `/api/workspaces/${id}`
330
340
  }
331
341
 
342
+ // The entry's real name in the bundle dir (`.build/<kind>/<name>/index.js`).
343
+ const ENTRY_DISK_FILE = 'index.js'
344
+
345
+ // …and the url the client asks for it at: `…/<segment>/<name>/module`. The route
346
+ // name and the disk name differ ON PURPOSE, and the reason is proxies.
347
+ //
348
+ // Cloudflare — which sits between many users and their moi, usually as a tunnel
349
+ // — decides whether a response is cache-eligible from the url's FILE EXTENSION,
350
+ // not from its content type, and `JS` is on its default cached-extension list.
351
+ // Once a response is cache-eligible, the zone's Browser Cache TTL applies, and
352
+ // that setting overrides the origin's `Cache-Control` on the way to the browser
353
+ // whenever the origin's freshness is lower than the TTL. Its default is 4 hours
354
+ // on every plan, so our `no-cache` came back to the browser as `max-age=14400`.
355
+ // The entry lives at ONE url across rebuilds, so that rewrite pinned a stale
356
+ // bundle in the user's browser for hours: no revalidation, so the ETag never got
357
+ // a chance to bust it, and `?v` couldn't either (it's an in-memory counter that
358
+ // resets to 0 on reload, landing right back on the poisoned url).
359
+ //
360
+ // An extensionless path isn't cache-eligible by default, so it reaches the
361
+ // browser with the headers we actually sent. Chunks and assets keep their
362
+ // extensions deliberately — they're content-hashed and WANT the edge cache.
363
+ // The build only ever emits `index.js`, `chunk-<hash>.js` and hashed assets, so
364
+ // this name can never collide with a real bundle file. Mirrors `appletUrl` in
365
+ // `client/features/applets/applet-cache.ts`.
366
+ const ENTRY_ROUTE_FILE = 'module'
367
+
332
368
  // Split an applet file request `…/<segment>/<name>/<file>` into name + file. A
333
- // bare `…/<segment>/<name>` (or legacy `…/<name>.js`) targets the entry.
369
+ // bare `…/<segment>/<name>` (or legacy `…/<name>.js`) targets the entry, as does
370
+ // the extensionless `…/<name>/module` alias. `file` is always the on-disk name,
371
+ // so `serveApplet` never has to know the route spelling.
334
372
  export function parseAppletTail(
335
373
  url: string,
336
374
  id: string,
@@ -338,8 +376,12 @@ export function parseAppletTail(
338
376
  ): { name: string; file: string } {
339
377
  const tail = new URL(url).pathname.split(`/api/workspaces/${id}/${segment}/`)[1] ?? ''
340
378
  const slash = tail.indexOf('/')
341
- if (slash === -1) return { name: tail.replace(/\.js$/, ''), file: 'index.js' }
342
- return { name: tail.slice(0, slash), file: tail.slice(slash + 1) }
379
+ if (slash === -1) return { name: tail.replace(/\.js$/, ''), file: ENTRY_DISK_FILE }
380
+ const file = tail.slice(slash + 1)
381
+ return {
382
+ name: tail.slice(0, slash),
383
+ file: file === ENTRY_ROUTE_FILE ? ENTRY_DISK_FILE : file
384
+ }
343
385
  }
344
386
 
345
387
  // Extensions `fileUrl()` may stream from the workspace. Media + image/doc