shadok-ai 0.17.46 → 0.17.48

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.17.46",
3
+ "version": "0.17.48",
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",
@@ -83,3 +83,18 @@ export function reconcileTabGroup(local, synced, server) {
83
83
  export function groupIsDirty(local, synced) {
84
84
  return synced === undefined || (local ?? null) !== synced;
85
85
  }
86
+
87
+ /**
88
+ * Which agent to focus when a group view becomes current. Switching groups used
89
+ * to snap to the TOP agent every time; instead we return to the one you last had
90
+ * focused in that group (`rememberedId`), so flipping between groups no longer
91
+ * loses your place. Falls back to the first agent when nothing is remembered yet
92
+ * or the remembered one has since gone (closed, or moved to another group), and
93
+ * to `null` for an empty group. `idsInView` is the group's agent session ids, in
94
+ * display order.
95
+ */
96
+ export function focusTarget(idsInView, rememberedId) {
97
+ const ids = idsInView || [];
98
+ if (rememberedId != null && ids.includes(rememberedId)) return rememberedId;
99
+ return ids.length ? ids[0] : null;
100
+ }
package/public/index.html CHANGED
@@ -3898,7 +3898,7 @@
3898
3898
  window.buildMessageLink = buildMessageLink;
3899
3899
  window.parseMessageLink = parseMessageLink;
3900
3900
  window.samePrompt = samePrompt;
3901
- import { GROUP_ICONS, UNGROUPED, randomGroupIcon, resolveGroupView, groupMood, cleanGroupIcon, reconcileTabGroup, groupIsDirty } from "/group-nav.js?v=__ASSET_V__";
3901
+ import { GROUP_ICONS, UNGROUPED, randomGroupIcon, resolveGroupView, groupMood, cleanGroupIcon, reconcileTabGroup, groupIsDirty, focusTarget } from "/group-nav.js?v=__ASSET_V__";
3902
3902
  window.GROUP_ICONS = GROUP_ICONS;
3903
3903
  window.UNGROUPED = UNGROUPED;
3904
3904
  window.randomGroupIcon = randomGroupIcon;
@@ -3907,6 +3907,7 @@
3907
3907
  window.cleanGroupIcon = cleanGroupIcon;
3908
3908
  window.reconcileTabGroup = reconcileTabGroup;
3909
3909
  window.groupIsDirty = groupIsDirty;
3910
+ window.focusTarget = focusTarget;
3910
3911
  import { searchEmoji, looksLikeEmoji } from "/emoji-search.js?v=__ASSET_V__";
3911
3912
  window.searchEmoji = searchEmoji;
3912
3913
  window.looksLikeEmoji = looksLikeEmoji;
@@ -4087,6 +4088,11 @@
4087
4088
  return { move: true, synced: srv };
4088
4089
  },
4089
4090
  groupIsDirty: (local, synced) => synced === undefined || (local ?? null) !== synced,
4091
+ // A group switch is a user click, long after the module lands; the stub
4092
+ // mirrors the real "remembered-or-first" so even a race keeps today's
4093
+ // top-agent fallback.
4094
+ focusTarget: (ids, remembered) =>
4095
+ (remembered != null && (ids || []).includes(remembered)) ? remembered : ((ids || []).length ? ids[0] : null),
4090
4096
  // The emoji keyword search feeds the icon picker, which opens well after
4091
4097
  // load; before the module lands, no suggestions (and typed text is treated
4092
4098
  // as a word, not an emoji) — both harmless, repainted on bridge-ready.
@@ -5329,6 +5335,16 @@
5329
5335
  // real group, because Main HAS its own vault).
5330
5336
  const COMMONS_GROUP_ID = "main";
5331
5337
  const foldCommons = (id) => (id != null && String(id) === COMMONS_GROUP_ID ? null : id);
5338
+ // Does the server carry that commons row (multi-tenant)? Then the "Main" view is
5339
+ // a REAL group a new agent must be filed into by name: a start with no `group`
5340
+ // is read by the server as "no choice made" and lands in the caller's own single
5341
+ // private group — the admin's Personal — so an agent created on the Main view
5342
+ // jumped to Personal on the next sync. Mono-tenant has no such row and keeps
5343
+ // omitting the key (its start message stays byte-for-byte what it was).
5344
+ let commonsOnServer = false;
5345
+ const noteCommons = (list) => {
5346
+ if (Array.isArray(list)) commonsOnServer = list.some((g) => g && String(g.id) === COMMONS_GROUP_ID);
5347
+ };
5332
5348
 
5333
5349
  // Group nature (server-owned): public / restricted / private. A walled group
5334
5350
  // (restricted or private) carries a padlock. The operator never sees the
@@ -5589,6 +5605,10 @@
5589
5605
  const railEl = $("groupRail"), railList = $("railList");
5590
5606
  const VIEW_KEY = () => dirKey("cp.groupView", instanceKey);
5591
5607
  let groupView = localStorage.getItem(VIEW_KEY()) || "ungrouped";
5608
+ // The agent last focused in each group view (view id → sessionId), so
5609
+ // switching groups returns to where you were instead of the top agent.
5610
+ // In-memory: a reload restores one active agent via `cp.activeSession`.
5611
+ const lastAgentByView = {};
5592
5612
 
5593
5613
  /** Is the two-column layout on screen? (Hidden on a phone.) */
5594
5614
  const railShown = () => getComputedStyle(railEl).display !== "none";
@@ -5637,10 +5657,14 @@
5637
5657
  applyView();
5638
5658
  animateViewSwitch(from, currentView());
5639
5659
  // Picking a group shows one of ITS agents: staying on an agent that is no
5640
- // longer in the list would leave the chat and the list disagreeing.
5660
+ // longer in the list would leave the chat and the list disagreeing. Return
5661
+ // to the agent you last had focused in this group rather than snapping to
5662
+ // the top one every time (focusTarget falls back to the first).
5641
5663
  if (follow && active && !active.btnEl.closest("#tweakSlot") && viewOfTab(active) !== currentView()) {
5642
- const first = tabsInView(currentView())[0];
5643
- if (first) activate(first);
5664
+ const inView = tabsInView(currentView());
5665
+ const wantId = window.focusTarget(inView.map((t) => t.sessionId), lastAgentByView[currentView()]);
5666
+ const pick = inView.find((t) => t.sessionId === wantId) || inView[0];
5667
+ if (pick) activate(pick);
5644
5668
  }
5645
5669
  }
5646
5670
  /** Whatever opens an agent (a click, a link, a notification) brings its group. */
@@ -6151,6 +6175,7 @@
6151
6175
  // A group created on another device must exist here before an agent can be
6152
6176
  // filed into it. Additive only: a group missing from the server may be one
6153
6177
  // this tab just made and has not pushed yet.
6178
+ noteCommons(srvGroups);
6154
6179
  if (Array.isArray(srvGroups)) {
6155
6180
  for (const sg of srvGroups) {
6156
6181
  if (sg == null || sg.id == null) continue;
@@ -6320,6 +6345,9 @@
6320
6345
  persistDraft(active);
6321
6346
  }
6322
6347
  active = tab;
6348
+ // Remember this as the group's last-focused agent, so returning to the
6349
+ // group comes back to it rather than the top one (consumed by setView).
6350
+ if (tab.sessionId) lastAgentByView[viewOfTab(tab)] = tab.sessionId;
6323
6351
  showTabGroup(tab);
6324
6352
  // A reload must come back to the channel you were watching: remember its
6325
6353
  // sessionId (outside the initial restore, which replays the activates itself).
@@ -8473,6 +8501,9 @@
8473
8501
  if (mode === "new") {
8474
8502
  const tg = viewGroupId();
8475
8503
  if (tg) msg.group = tg;
8504
+ // The Main view on screen is a choice too (see `commonsOnServer`). Only when
8505
+ // the rail shows it: a phone has no view, and keeps the server's default.
8506
+ else if (commonsOnServer && setupGroup == null && railShown()) msg.group = COMMONS_GROUP_ID;
8476
8507
  }
8477
8508
  $("startBtn").disabled = true;
8478
8509
  closeSetup();
@@ -14221,6 +14252,7 @@
14221
14252
  // empty. Only a failed fetch falls back to the (now dir-scoped) cache.
14222
14253
  let savedGroups = pickChannelSource(groupsR, JSON.parse(localStorage.getItem(dirKey("cp.groups", instanceKey)) || "[]"));
14223
14254
  // The commons group ("main") is the "Main" view, never a rail group (see foldCommons).
14255
+ if (groupsR.status === "fulfilled") noteCommons(groupsR.value);
14224
14256
  for (const g of savedGroups) if (String(g.id) !== COMMONS_GROUP_ID) createGroup(g);
14225
14257
 
14226
14258
  let saved = pickChannelSource(channelsR, JSON.parse(localStorage.getItem(dirKey("cp.channels", instanceKey)) || "[]"));