shadok-ai 0.19.72 → 0.19.73

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shadok-ai",
3
- "version": "0.19.72",
3
+ "version": "0.19.73",
4
4
  "main": "dist/session.js",
5
5
  "scripts": {
6
6
  "test": "node --import tsx --test --test-timeout=120000 test/*.ts context/*/test/*.test.mjs",
package/public/index.html CHANGED
@@ -3286,6 +3286,10 @@
3286
3286
  box-shadow: inset 0 1px 0 color-mix(in srgb, #fff 16%, transparent), 0 8px 20px -16px rgba(0, 0, 0, 0.45);
3287
3287
  }
3288
3288
  .transcript { padding-top: calc(22px + var(--chanbar-h, 0px)); scroll-padding-top: var(--chanbar-h, 0px); }
3289
+ /* The engine room is not a conversation: nothing gives the height back
3290
+ there, so the bar must not overlap it — its first rows would sit under
3291
+ the glass. */
3292
+ .chat-pane.terminal-mode #chanBar { margin-bottom: 0; }
3289
3293
  @media (max-width: 640px) { .transcript { padding-top: calc(14px + var(--chanbar-h, 0px)); } }
3290
3294
  }
3291
3295
 
@@ -5165,7 +5169,9 @@
5165
5169
  // synchronously, then `prefAppliers[key]` re-applies the server's value once
5166
5170
  // it lands. A key the server has never seen but this browser has is pushed
5167
5171
  // up once, so a person's existing choice becomes their account's instead of
5168
- // being reset by the first device that asks.
5172
+ // being reset by the first device that asks — EXCEPT "tour seen", which is
5173
+ // only pushed from a copy known to be this account's (public/pref-sync.js):
5174
+ // inherited from the browser, it hid the tour from every later account.
5169
5175
  const PREF_CACHE = {
5170
5176
  mode: { key: "cp.mode", enc: (v) => v, dec: (s) => (s === "light" || s === "dark" ? s : undefined) },
5171
5177
  soundMuted: { key: "cp.muteNotif", enc: (v) => (v ? "1" : "0"), dec: (s) => (s === "1" ? true : s === "0" ? false : undefined) },
@@ -5191,26 +5197,39 @@
5191
5197
  // Started at once and awaited only by what must not act on a stale cache (the
5192
5198
  // tour). Bounded: a server that does not answer must not hold the page — the
5193
5199
  // cache is then what we go by, exactly as before this existed.
5200
+ // Whose preferences the localStorage copy holds. localStorage is the
5201
+ // BROWSER's; the preferences are an ACCOUNT's — and several accounts pass
5202
+ // through one browser (public/pref-sync.js).
5203
+ const PREFS_OWNER_KEY = "cp.prefsOwner";
5194
5204
  const prefsReady = (async () => {
5195
5205
  const ctl = new AbortController();
5196
5206
  const timer = setTimeout(() => ctl.abort(), 3000);
5197
5207
  try {
5198
- const r = await fetch("/prefs", { signal: ctl.signal });
5208
+ const [r, who, mod] = await Promise.all([
5209
+ fetch("/prefs", { signal: ctl.signal }),
5210
+ fetch("/me", { signal: ctl.signal }).then((x) => (x.ok ? x.json() : null)).catch(() => null),
5211
+ import("/pref-sync.js?v=__ASSET_V__"),
5212
+ ]);
5199
5213
  if (!r.ok) return; // an agent/peer view or logged out: keep the cache
5200
5214
  const server = await r.json();
5201
- const push = {};
5202
- for (const name of Object.keys(PREF_CACHE)) {
5203
- const local = cachedPref(name);
5204
- if (server[name] !== undefined) {
5205
- if (server[name] !== local) {
5206
- cachePref(name, server[name]);
5207
- try { prefAppliers[name]?.(server[name]); } catch { /* one bad applier must not stop the rest */ }
5208
- }
5209
- } else if (local !== undefined) {
5210
- push[name] = local;
5215
+ const owner = who && typeof who.name === "string" ? who.name : null;
5216
+ let cacheOwner = null;
5217
+ try { cacheOwner = localStorage.getItem(PREFS_OWNER_KEY); } catch { /* private mode */ }
5218
+ const names = Object.keys(PREF_CACHE);
5219
+ const local = {};
5220
+ for (const name of names) { const v = cachedPref(name); if (v !== undefined) local[name] = v; }
5221
+ const plan = mod.prefSyncPlan({ names, owner, cacheOwner, server, local });
5222
+ for (const [name, value] of Object.entries(plan.cache)) {
5223
+ if (value === null) {
5224
+ // Someone else's "I did this" (the tour): not this account's to keep.
5225
+ try { localStorage.removeItem(PREF_CACHE[name].key); } catch { /* private mode */ }
5226
+ continue;
5211
5227
  }
5228
+ cachePref(name, value);
5229
+ try { prefAppliers[name]?.(value); } catch { /* one bad applier must not stop the rest */ }
5212
5230
  }
5213
- if (Object.keys(push).length) putPrefs(push);
5231
+ if (owner != null) { try { localStorage.setItem(PREFS_OWNER_KEY, owner); } catch { /* private mode */ } }
5232
+ if (Object.keys(plan.push).length) putPrefs(plan.push);
5214
5233
  } catch { /* timeout or offline: the cache stands */ }
5215
5234
  finally { clearTimeout(timer); }
5216
5235
  })();
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Reconciling the browser's copy of the personal preferences with the
3
+ * account's (GET /prefs, src/user-prefs.ts). Pure. ESM, browser + tests.
4
+ *
5
+ * The copy lives in localStorage, which belongs to the BROWSER; the
6
+ * preferences belong to an ACCOUNT. Several accounts pass through one browser
7
+ * (an admin who signs out and redeems the invitation they just made, a shared
8
+ * machine), so the copy is not always the caller's own.
9
+ */
10
+
11
+ /**
12
+ * Preferences that state something the PERSON did, and so must never be taken
13
+ * from a copy that may be someone else's. "The tour was seen" is true of one
14
+ * person; inherited from the browser, it hid the guided tour from every
15
+ * account after the first one to use that browser. The others (light/dark,
16
+ * the chime, the folded rail) are tastes of whoever sits at this screen, and
17
+ * inheriting them is a fair starting point.
18
+ */
19
+ export const NEVER_INHERITED = ["tourSeen"];
20
+
21
+ /**
22
+ * What to do with each preference once the server has answered.
23
+ *
24
+ * - `owner`: the signed-in account, or null when it could not be read.
25
+ * - `cacheOwner`: the account this browser's copy was last reconciled for, or
26
+ * null when it was never recorded (a copy older than this rule).
27
+ * - `server` / `local`: the two sides, a key absent when that side has no value.
28
+ *
29
+ * Returns `cache` (values to write into the copy; null = remove the key) and
30
+ * `push` (local values the account never had, to send up once).
31
+ */
32
+ export function prefSyncPlan({ names, owner, cacheOwner, server, local }) {
33
+ const mine = owner != null && cacheOwner != null && cacheOwner === owner;
34
+ const cache = {};
35
+ const push = {};
36
+ for (const name of names || []) {
37
+ const s = server?.[name];
38
+ const l = local?.[name];
39
+ if (s !== undefined) {
40
+ if (s !== l) cache[name] = s;
41
+ } else if (l !== undefined) {
42
+ // The account has no value and the browser does. Unless the copy is
43
+ // KNOWN to be this account's, a never-inherited preference is dropped
44
+ // rather than pushed: unknown is not "mine".
45
+ if (NEVER_INHERITED.includes(name) && !mine) cache[name] = null;
46
+ else push[name] = l;
47
+ }
48
+ }
49
+ return { cache, push };
50
+ }