dsh-talk-map 0.1.94 → 0.1.95

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/client/client.js CHANGED
@@ -276,8 +276,8 @@ var talkMapApi = {
276
276
  * The last message the USER sent, per session — what the card body shows now
277
277
  * that the LLM summary is gone. Read straight off the Host's session surface.
278
278
  */
279
- lastUserMessages(sessionIds) {
280
- return postJson("/talk-map/last-user", { sessionIds });
279
+ lastUserMessages(ids) {
280
+ return postJson("/talk-map/last-user", { sessionIds: ids });
281
281
  },
282
282
  /**
283
283
  * The live window: what the model is given right now, minus everything compaction
@@ -498,7 +498,7 @@ var zh = {
498
498
  "digest.empty": "这条对话还没有摘要,先刷新摘要再来看。",
499
499
  "digest.copy": "复制",
500
500
  "digest.close": "关闭",
501
- "global.searchPlaceholder": "b94 · 搜地图上的卡片(标题/正文)",
501
+ "global.searchPlaceholder": "b95 · 搜地图上的卡片(标题/正文)",
502
502
  "global.searchRun": "搜索",
503
503
  "global.searchTitle": "搜索地图",
504
504
  "font.group": "文字大小",
@@ -691,7 +691,7 @@ var en = {
691
691
  "menu.noGroup": "Remove from group (free card)",
692
692
  "menu.open": "Open conversation",
693
693
  "menu.markUnread": "Mark as unread",
694
- "global.searchPlaceholder": "b94 · Search cards on the map",
694
+ "global.searchPlaceholder": "b95 · Search cards on the map",
695
695
  "global.searchRun": "Search",
696
696
  "global.searchTitle": "Search the map",
697
697
  "font.group": "Text size",
@@ -11552,6 +11552,9 @@ var sessionActivity = {
11552
11552
 
11553
11553
  // src/client/draft-watch.ts
11554
11554
  var STORE_PREFIX = "dsh.conversation.";
11555
+ function draftMayBeEmpty(raw) {
11556
+ return raw.includes('"draft":""') || raw.includes('"draft":{}') || !raw.includes('"draft"');
11557
+ }
11555
11558
  function draftTextOf(value) {
11556
11559
  if (typeof value === "string") return value;
11557
11560
  if (value !== null && typeof value === "object") {
@@ -11591,6 +11594,8 @@ function readDraftTexts() {
11591
11594
  if (key === null || !key.startsWith(STORE_PREFIX)) continue;
11592
11595
  const sessionId = key.slice(STORE_PREFIX.length);
11593
11596
  if (sessionId === "") continue;
11597
+ const raw = localStorage.getItem(key);
11598
+ if (raw === null || draftMayBeEmpty(raw)) continue;
11594
11599
  const text = readDraftText(sessionId);
11595
11600
  if (text.trim() !== "") out[sessionId] = text;
11596
11601
  }
@@ -11606,7 +11611,7 @@ function readDraftSessions() {
11606
11611
  if (sessionId === "") continue;
11607
11612
  try {
11608
11613
  const raw = localStorage.getItem(key);
11609
- if (raw === null) continue;
11614
+ if (raw === null || draftMayBeEmpty(raw)) continue;
11610
11615
  const stored = JSON.parse(raw);
11611
11616
  const draft = stored !== null && typeof stored === "object" ? stored.draft : void 0;
11612
11617
  if (draftTextOf(draft).trim() !== "") out.add(sessionId);
@@ -14279,7 +14284,7 @@ function snap(value) {
14279
14284
  return Math.round(value / GRID) * GRID;
14280
14285
  }
14281
14286
  var IMPORT_CAP = 120;
14282
- var PREVIEW_BATCH = 40;
14287
+ var PREVIEW_BATCH = 8;
14283
14288
  function placeableSessionIds(sessions, archived) {
14284
14289
  return sessions.ids.filter((id2) => {
14285
14290
  const summary = sessions.byId[id2];
@@ -14490,6 +14495,7 @@ function CanvasInner(props) {
14490
14495
  });
14491
14496
  (0, import_react13.useEffect)(() => {
14492
14497
  const tick = () => {
14498
+ if (typeof document !== "undefined" && document.hidden) return;
14493
14499
  const { cards, sessions: latest } = previewInputs.current;
14494
14500
  const pending = [];
14495
14501
  const stamps = [];
@@ -14500,10 +14506,11 @@ function CanvasInner(props) {
14500
14506
  stamps.push([card.sessionId, stamp]);
14501
14507
  }
14502
14508
  if (pending.length === 0) return;
14503
- const batch = pending.slice(0, PREVIEW_BATCH);
14509
+ stamps.sort((a, b) => b[1] - a[1]);
14504
14510
  const batchStamps = stamps.slice(0, PREVIEW_BATCH);
14511
+ const batch = batchStamps.map(([id2]) => id2);
14505
14512
  for (const [sessionId, stamp] of batchStamps) previewStamp.current.set(sessionId, stamp);
14506
- void talkMapApi.lastUserMessages(batch).then(({ texts }) => {
14513
+ void talkMapApi.lastUserMessages(batchStamps.map(([id2, stamp]) => ({ id: id2, stamp }))).then(({ texts }) => {
14507
14514
  const cleaned = {};
14508
14515
  for (const [sessionId, text] of Object.entries(texts)) {
14509
14516
  const value = cleanPreviewText(text).slice(0, 240);
@@ -16557,6 +16564,7 @@ function SidebarQueue() {
16557
16564
  const askedRef = (0, import_react18.useRef)(/* @__PURE__ */ new Set());
16558
16565
  (0, import_react18.useEffect)(() => {
16559
16566
  const timer4 = setInterval(() => {
16567
+ if (typeof document !== "undefined" && document.hidden) return;
16560
16568
  setDrafts(readDraftTexts());
16561
16569
  }, 1500);
16562
16570
  return () => {
@@ -16636,9 +16644,9 @@ function SidebarQueue() {
16636
16644
  return sortQueueRows(out);
16637
16645
  }, [canvasState.cards, sessions, statusById, alerts2, finished2, drafts, opened, archivedSessionIds]);
16638
16646
  (0, import_react18.useEffect)(() => {
16639
- const wanted = rows.slice(0, PREVIEW_LIMIT).map((row) => row.sessionId).filter((id2) => !askedRef.current.has(id2));
16647
+ const wanted = rows.slice(0, PREVIEW_LIMIT).filter((row) => !askedRef.current.has(row.sessionId)).map((row) => ({ id: row.sessionId, stamp: row.updatedAt ?? 0 }));
16640
16648
  if (wanted.length === 0) return;
16641
- for (const id2 of wanted) askedRef.current.add(id2);
16649
+ for (const item of wanted) askedRef.current.add(item.id);
16642
16650
  void talkMapApi.lastUserMessages(wanted).then((page) => {
16643
16651
  setPreviews((current) => {
16644
16652
  const next = { ...current };
package/lib/index.js CHANGED
@@ -252,6 +252,49 @@ var DigestPipeline = class {
252
252
  return text;
253
253
  }
254
254
  };
255
+ // src/host/preview.ts
256
+ /**
257
+ * Run `task` over `items` with at most `limit` in flight. Awaiting is sequential per worker,
258
+ * so peak memory stays around `limit` surfaces instead of `items.length`.
259
+ */
260
+ async function runLimited(items, limit, task) {
261
+ const width = Math.max(1, Math.min(limit, items.length));
262
+ let cursor = 0;
263
+ const worker = async () => {
264
+ for (;;) {
265
+ const index = cursor;
266
+ cursor += 1;
267
+ if (index >= items.length) return;
268
+ await task(items[index]);
269
+ }
270
+ };
271
+ await Promise.all(Array.from({ length: width }, worker));
272
+ }
273
+ /** Insertion-ordered map used as an LRU: re-setting a key moves it to the end. */
274
+ function createPreviewCache(max) {
275
+ const store = /* @__PURE__ */ new Map();
276
+ return {
277
+ get(id) {
278
+ const hit = store.get(id);
279
+ if (hit === void 0) return void 0;
280
+ store.delete(id);
281
+ store.set(id, hit);
282
+ return hit;
283
+ },
284
+ set(id, entry) {
285
+ store.delete(id);
286
+ store.set(id, entry);
287
+ while (store.size > max) {
288
+ const oldest = store.keys().next();
289
+ if (oldest.done === true) break;
290
+ store.delete(oldest.value);
291
+ }
292
+ },
293
+ get size() {
294
+ return store.size;
295
+ }
296
+ };
297
+ }
255
298
  // src/host/spawn.ts
256
299
  /** Typed so the HTTP layer can answer with a structured code instead of
257
300
  * clients substring-matching a stringified error. */
@@ -840,14 +883,36 @@ function mountTalkMapRoutes(services, storeReady, runtime) {
840
883
  }
841
884
  return;
842
885
  }
886
+ const previewCache = createPreviewCache(400);
843
887
  if (route === "POST /talk-map/last-user") {
844
888
  const body = await readJsonBody(request);
845
- const ids = Array.isArray(body.sessionIds) ? body.sessionIds.filter((id) => typeof id === "string").slice(0, 200) : [];
889
+ const listed = Array.isArray(body.sessionIds) ? body.sessionIds : [];
890
+ const wanted = [];
891
+ for (const entry of listed) {
892
+ if (typeof entry === "string") {
893
+ wanted.push({ id: entry });
894
+ continue;
895
+ }
896
+ if (entry === null || typeof entry !== "object") continue;
897
+ const id = entry.id;
898
+ if (typeof id !== "string") continue;
899
+ const stamp = entry.stamp;
900
+ wanted.push(typeof stamp === "number" ? {
901
+ id,
902
+ stamp
903
+ } : { id });
904
+ }
846
905
  const texts = {};
847
906
  const query = runtime.sessionQuery;
848
- if (query !== void 0) await Promise.all(ids.map(async (sessionId) => {
907
+ if (query !== void 0) await runLimited(wanted.filter((item) => {
908
+ if (item.stamp === void 0) return true;
909
+ const cached = previewCache.get(item.id);
910
+ if (cached === void 0 || cached.stamp !== item.stamp) return true;
911
+ texts[item.id] = cached.text;
912
+ return false;
913
+ }), 3, async (item) => {
849
914
  try {
850
- const surface = await query.readSurface(sessionId);
915
+ const surface = await query.readSurface(item.id);
851
916
  let text = "";
852
917
  for (const raw of surface.events) {
853
918
  const event = raw;
@@ -856,9 +921,14 @@ function mountTalkMapRoutes(services, storeReady, runtime) {
856
921
  const body = textOfBlocks(event.data?.content);
857
922
  if (body !== "") text = body;
858
923
  }
859
- if (text !== "") texts[sessionId] = text.length > 240 ? text.slice(0, 240) : text;
924
+ const trimmed = text.length > 240 ? text.slice(0, 240) : text;
925
+ if (item.stamp !== void 0) previewCache.set(item.id, {
926
+ stamp: item.stamp,
927
+ text: trimmed
928
+ });
929
+ if (trimmed !== "") texts[item.id] = trimmed;
860
930
  } catch {}
861
- }));
931
+ });
862
932
  sendJson(response, 200, { texts });
863
933
  return;
864
934
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-talk-map",
3
- "version": "0.1.94",
3
+ "version": "0.1.95",
4
4
  "description": "Visual conversation map for DeepSeek Harness: an infinite whiteboard where every session is a card — drag to arrange, double-click to start a chat in place, draw an edge to fork a new session with injected context. Built for ADHD-friendly spatial memory. · DSH 可视化对话地图:会话即卡片,双击即聊,连线分叉带上下文的新对话。",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",