@takboo/dsh-coopanion 0.4.13 → 0.4.15

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 (44) hide show
  1. package/README.md +4 -4
  2. package/desktop/display-controller.cjs +8 -4
  3. package/desktop/main.cjs +8 -2
  4. package/desktop/preload.cjs +2 -0
  5. package/dist/bridge.js +90 -8
  6. package/dist/bridge.js.map +4 -4
  7. package/dist/build-info.json +2 -2
  8. package/dist/client.js +1 -1
  9. package/dist/figure-server.cjs +1 -1
  10. package/dist/index.js +91 -9
  11. package/dist/index.js.map +4 -4
  12. package/docs/desktop-recovery-contract.md +4 -0
  13. package/docs/development.md +20 -0
  14. package/docs/multi-display-contract.md +6 -0
  15. package/docs/release-notes.md +25 -0
  16. package/docs/releasing.md +2 -2
  17. package/docs/session-chat-contract.md +1 -1
  18. package/docs/usage.md +22 -7
  19. package/npm-shrinkwrap.json +21 -21
  20. package/package.json +20 -20
  21. package/scripts/observe-companion.mjs +1 -1
  22. package/src/bridge.ts +19 -4
  23. package/src/client/index.ts +1 -1
  24. package/src/controls.ts +1 -1
  25. package/src/electron-runtime.ts +50 -0
  26. package/src/figure-server.ts +3 -1
  27. package/tests/companionship-ui.mjs +38 -4
  28. package/tests/display-geometry.test.js +37 -1
  29. package/tests/electron-startup.test.ts +93 -0
  30. package/tests/figures.test.ts +45 -2
  31. package/tests/fixtures/late-display-quit.cjs +8 -0
  32. package/tests/fixtures/lifecycle-shutdown-trace.cjs +37 -0
  33. package/tests/helpers/native-pointer.mjs +33 -7
  34. package/tests/helpers/windows-taskbar.ps1 +22 -0
  35. package/tests/inbox-ui.mjs +1 -0
  36. package/tests/install.mjs +15 -5
  37. package/tests/lifecycle-startup-native.mjs +44 -9
  38. package/tests/locale-client.mjs +23 -0
  39. package/tests/multi-display-ui.mjs +42 -0
  40. package/tests/preload-geometry.test.js +23 -0
  41. package/tests/session-replies-ui.mjs +22 -0
  42. package/tests/windows-geometry-native.mjs +78 -0
  43. package/tests/windows-pointer-native.mjs +43 -0
  44. package/web/pet.js +23 -5
@@ -7,6 +7,7 @@ import { join } from 'node:path';
7
7
  import { after, before, test } from 'node:test';
8
8
  import { chromium } from 'playwright-core';
9
9
  import { previewServer } from '../scripts/preview.mjs';
10
+ import { controlNpc, npcUntil } from './helpers/npc-life.mjs';
10
11
  let directory, server, browser;
11
12
  before(async () => {
12
13
  directory = await mkdtemp(join(tmpdir(),'dsh-display-ui-'));
@@ -22,6 +23,47 @@ const cases = [
22
23
  {displayId:3,contentBounds:{x:160,y:-640,width:520,height:720},scaleFactor:2},
23
24
  {displayId:1,contentBounds:{x:0,y:25,width:980,height:680},scaleFactor:2},
24
25
  ];
26
+ test('native NPC requests missing and stale geometry and resumes without restarting its character', async t => {
27
+ const page = await browser.newPage({ viewport: { width: 980, height: 720 } }); t.after(() => page.close());
28
+ await controlNpc(page);
29
+ await page.addInitScript(() => {
30
+ window.geometryRequests = 0;
31
+ window.dshPetBridge = {
32
+ nativeGeometry: true,
33
+ subscribe(fn) { window.displayReceive = fn; }, action() {}, hit() {},
34
+ requestGeometry() {
35
+ window.geometryRequests++;
36
+ if (!window.geometryAvailable) return;
37
+ const bounds = { x: -420, y: 25, width: innerWidth, height: innerHeight };
38
+ window.displayReceive({ type: 'display-changed', displayId: 2, revision: ++window.geometryRevision, contentBounds: bounds, workArea: bounds, scaleFactor: 1.25 });
39
+ },
40
+ };
41
+ window.geometryRevision = 0;
42
+ });
43
+ await page.goto(`http://127.0.0.1:${server.address().port}`);
44
+ await page.waitForSelector('#pet[data-mode]');
45
+ await page.evaluate(() => {
46
+ window.originalBody = document.querySelector('#body-layer iframe');
47
+ window.displayReceive({ type: 'init', options: { companionship: 'quiet', roam: true }, snapshot: { mood: 'idle', active: false, sessions: [], results: [] } });
48
+ });
49
+ await page.waitForSelector('#pet[data-npc-reason=geometry]');
50
+ await page.evaluate(() => { window.geometryAvailable = true; });
51
+ await page.waitForFunction(() => window.geometryRequests > 0, null, { timeout: 5000 });
52
+ await page.waitForFunction(() => document.querySelector('#pet').dataset.npcReason !== 'geometry', null, { timeout: 5000 });
53
+ await npcUntil(page, 'outbound');
54
+ await page.evaluate(() => {
55
+ // Hold the reply until the paused state is observed. A correct, fast heal
56
+ // must not make an external poll miss the transient geometry state.
57
+ window.geometryAvailable = false;
58
+ window.displayReceive({ type: 'display-changed', displayId: 2, revision: ++window.geometryRevision, contentBounds: { x: -420, y: 25, width: 980, height: 768 }, workArea: { x: -420, y: 25, width: 980, height: 720 }, scaleFactor: 1.25 });
59
+ });
60
+ await page.waitForSelector('#pet[data-npc-reason=geometry]');
61
+ const requests = await page.evaluate(() => window.geometryRequests);
62
+ await page.evaluate(() => { window.geometryAvailable = true; });
63
+ await page.waitForFunction(n => window.geometryRequests > n && document.querySelector('#pet').dataset.npcReason !== 'geometry', requests, { timeout: 5000 });
64
+ await npcUntil(page, 'outbound');
65
+ assert.equal(await page.evaluate(() => document.querySelector('#body-layer iframe') === window.originalBody), true);
66
+ });
25
67
  test('controlled irregular layout and mixed DPR preserve reading, draft, in-flight identity and hit areas', async t => {
26
68
  const page = await browser.newPage({viewport:{width:980,height:720},reducedMotion:'reduce'}); t.after(()=>page.close());
27
69
  const errors=[]; page.on('pageerror',e=>errors.push(e.message)); t.after(()=>assert.deepEqual(errors,[]));
@@ -0,0 +1,23 @@
1
+ import { it, expect } from 'vitest';
2
+ import { readFileSync } from 'node:fs';
3
+ import { runInNewContext } from 'node:vm';
4
+
5
+ it('requests current native geometry after the renderer listener is attached', () => {
6
+ let api, listener;
7
+ const sent = [];
8
+ const ipcRenderer = {
9
+ on(channel, fn) { expect(channel).toBe('pet:update'); listener = fn; },
10
+ send(channel) { sent.push(channel); listener(null, { type: 'display-changed', revision: sent.length }); },
11
+ removeListener(channel, fn) { expect(channel).toBe('pet:update'); expect(fn).toBe(listener); listener = undefined; },
12
+ };
13
+ runInNewContext(readFileSync(new URL('../desktop/preload.cjs', import.meta.url), 'utf8'), {
14
+ process: { argv: [] },
15
+ require: () => ({ ipcRenderer, contextBridge: { exposeInMainWorld(name, value) { expect(name).toBe('dshPetBridge'); api = value; } } }),
16
+ });
17
+ const received = [];
18
+ const unsubscribe = api.subscribe(value => received.push(value));
19
+ expect(received).toEqual([{ type: 'display-changed', revision: 1 }]);
20
+ api.requestGeometry(); expect(received.at(-1).revision).toBe(2);
21
+ expect(sent).toEqual(['pet:geometry-request', 'pet:geometry-request']);
22
+ unsubscribe(); expect(listener).toBeUndefined();
23
+ });
@@ -164,10 +164,32 @@ test('full-result continue opens the exact source composer without replacing the
164
164
  await page.locator('#reader-session').click();
165
165
  assert.equal(await page.locator('#chat').isVisible(), true);
166
166
  assert.equal(await page.locator('#chat-session-name').innerText(), source.label);
167
+ // The preceding read action can publish its old selection before the Host
168
+ // acknowledges the select action sent by Continue.
169
+ await receive(frame([{ ...old, read: true }, newer]));
170
+ assert.equal(await page.locator('#chat-session-name').innerText(), source.label, 'an earlier read snapshot cannot undo the requested source');
167
171
  await page.locator('#message').fill('继续来源会话'); await page.locator('#send').click();
168
172
  const actions = await page.evaluate(() => window.replyActions);
169
173
  assert.equal(actions.filter(a => a.type === 'chat').at(-1).sessionId, source.id);
170
174
  assert.equal(actions.some(a => a.type === 'read' && a.resultId === newer.id), false);
175
+ await page.locator('#chat-session').click();
176
+ assert.equal(await page.evaluate(() => window.replyActions.filter(a => a.type === 'open-session').at(-1).sessionId), source.id);
177
+ await receive({ ...frame([{ ...old, read: true }, newer]), sessionId: source.id });
178
+ await receive(frame([{ ...old, read: true }, newer]));
179
+ assert.equal(await page.locator('#chat-session-name').innerText(), focus.label, 'after Host confirms the choice, later Host selection changes apply');
180
+ });
181
+
182
+ test('the latest explicit selection survives an earlier selection receipt and releases a removed target', async t => {
183
+ const old = reply('source:1:3', source.id, 1, '完整旧正文');
184
+ const { page, receive } = await fixture(t, [old]);
185
+ await page.locator('#attention').click();
186
+ await page.locator('#reader-session').click();
187
+ await page.locator('#chat-current').click();
188
+ await page.locator(`#conversation-list [data-session-id="${other.id}"]`).click();
189
+ await receive({ ...frame([old]), sessionId: source.id });
190
+ assert.equal(await page.locator('#chat-session-name').innerText(), other.label);
191
+ await receive({ ...frame([old]), sessions: [focus, source] });
192
+ assert.equal(await page.locator('#chat-session-name').innerText(), focus.label, 'a missing requested target is not kept alive locally');
171
193
  });
172
194
 
173
195
  test('composer timeout preserves identity and acceptance remains monotonic', async () => {
@@ -0,0 +1,78 @@
1
+ import assert from 'node:assert/strict';
2
+ import { createRequire } from 'node:module';
3
+ import { execFile, execFileSync } from 'node:child_process';
4
+ import { promisify } from 'node:util';
5
+ import { mkdtemp, readFile, mkdir, rm, writeFile } from 'node:fs/promises';
6
+ import { tmpdir } from 'node:os';
7
+ import { join, resolve } from 'node:path';
8
+ import { _electron } from 'playwright-core';
9
+ import { controlNpc, npcUntil } from './helpers/npc-life.mjs';
10
+ import { parkNativePointer } from './helpers/native-pointer.mjs';
11
+
12
+ assert.equal(process.platform, 'win32', 'Run this test on an isolated Windows interactive desktop');
13
+ const require = createRequire(import.meta.url), run = promisify(execFile);
14
+ const root = await mkdtemp(join(tmpdir(), 'dsh-windows-geometry-'));
15
+ const taskbarSource = await readFile(new URL('./helpers/windows-taskbar.ps1', import.meta.url), 'utf8');
16
+ const taskbar = async state => {
17
+ const script = `$requestedState=${state === undefined ? '$null' : Number(state)};\n` + taskbarSource;
18
+ const { stdout } = await run('powershell.exe', ['-NoProfile', '-NonInteractive', '-EncodedCommand', Buffer.from(script, 'utf16le').toString('base64')], { windowsHide: true });
19
+ return JSON.parse(stdout.replace(/^\uFEFF/, ''));
20
+ };
21
+ const originalTaskbar = (await taskbar()).before;
22
+ let app, page;
23
+ const samples = [], errors = [];
24
+ try {
25
+ app = await _electron.launch({ executablePath: require('electron'), args: ['--no-sandbox', resolve('desktop/main.cjs')], env: { ...process.env, DSH_PET_TEST_DATA_DIR: root, DSH_PET_TEST_NO_SANDBOX: '1', DSH_PET_TEST_DEBUG_PORT: '0' } });
26
+ page = await app.firstWindow(); page.setDefaultTimeout(15000);
27
+ page.on('pageerror', error => errors.push(error.message));
28
+ // firstWindow observes window creation, before main's loadURL can finish.
29
+ // Reloading that initial navigation makes native startup abort instead.
30
+ await page.waitForURL(/^http:\/\/127\.0\.0\.1:/, { waitUntil: 'load' });
31
+ await controlNpc(page);
32
+ await page.addInitScript(() => { window.npcPointer = null; });
33
+ const options = { size: 180, roam: true, companionship: 'quiet', notifications: false, bubbleDurationMs: 12000 };
34
+ await app.evaluate((_, options) => process.emit('message', { type: 'init', baseline: true, options, snapshot: { mood: 'idle', active: false, sessions: [], results: [] } }), options);
35
+ await page.reload(); await page.waitForSelector('#pet[data-mode][data-display-revision]');
36
+ await parkNativePointer(page);
37
+ const sample = () => page.evaluate(async () => ({ viewport: { width: innerWidth, height: innerHeight }, dpr: devicePixelRatio, reason: document.querySelector('#pet').dataset.npcReason,
38
+ native: await window.dshPetBridge.testScreenPoint({ x: 0, y: 0, width: innerWidth, height: innerHeight }) }));
39
+ const settled = async () => {
40
+ let value;
41
+ for (let i = 0; i < 60; i++) {
42
+ value = await sample();
43
+ const bounds = value.native.contentBounds, geometry = value.native.geometry;
44
+ if (bounds.width === value.viewport.width && bounds.height === value.viewport.height && geometry.contentBounds.width === bounds.width && geometry.contentBounds.height === bounds.height && value.reason !== 'geometry') return value;
45
+ await page.waitForTimeout(100);
46
+ }
47
+ assert.fail('Native geometry failed to settle: ' + JSON.stringify(value));
48
+ };
49
+ const initial = await settled();
50
+ assert.equal(initial.native.geometry.scaleFactor, Number(process.env.DSH_WINDOWS_EXPECT_SCALE ?? 1.25), 'DPI must come from Windows, without a forced Chromium scale');
51
+ await npcUntil(page, 'outbound');
52
+ await page.evaluate(() => { window.originalGeometryBody = document.querySelector('#body-layer iframe'); });
53
+ for (const state of [originalTaskbar | 1, originalTaskbar & ~1, originalTaskbar | 1]) {
54
+ const changed = await taskbar(state); assert.equal(changed.after & 1, state & 1);
55
+ await page.waitForTimeout(300);
56
+ samples.push({ taskbar: changed.after, ...await settled() });
57
+ await npcUntil(page, 'outbound');
58
+ }
59
+ assert.ok(new Set(samples.map(s => s.native.geometry.workArea.height)).size > 1, 'Real taskbar changes must exercise different workArea heights');
60
+ // Keep native bounds stale until the renderer has observed the pause. The
61
+ // window, actual viewport, revision protocol and resync IPC remain real.
62
+ await app.evaluate(({ BrowserWindow, screen }) => {
63
+ const win = BrowserWindow.getAllWindows()[0], original = win.getContentBounds.bind(win), bounds = original();
64
+ globalThis.dshGeometryRestore = () => { win.getContentBounds = original; };
65
+ win.getContentBounds = () => ({ ...bounds, height: bounds.height + 48 });
66
+ screen.emit('display-metrics-changed', {}, screen.getPrimaryDisplay(), ['workArea']);
67
+ });
68
+ await page.waitForSelector('#pet[data-npc-reason=geometry]');
69
+ await app.evaluate(() => globalThis.dshGeometryRestore());
70
+ const recovered = await settled(); await npcUntil(page, 'outbound');
71
+ assert.equal(await page.evaluate(() => document.querySelector('#body-layer iframe') === window.originalGeometryBody), true);
72
+ assert.deepEqual(errors, []);
73
+ await mkdir('artifacts', { recursive: true });
74
+ await page.screenshot({ path: 'artifacts/windows-geometry-native.png' });
75
+ await writeFile('artifacts/windows-geometry-native.json', JSON.stringify({ commit: execFileSync('git', ['rev-parse', 'HEAD'], { encoding: 'utf8' }).trim(), build: JSON.parse(await readFile('dist/build-info.json', 'utf8')), initial, samples, recovered,
76
+ windowsDpiFromSystem: true, realTaskbarChanges: true, controlledStaleBounds: true, controlledNpcClockAndPerception: true, sameCharacterFrame: true, physicalMultiDisplay: false }, null, 2) + '\n');
77
+ console.log('Windows native geometry passed: system DPI, actual taskbar workAreas, stale-bound resync and retained character.');
78
+ } finally { await app?.close(); await taskbar(originalTaskbar); await rm(root, { recursive: true, force: true }); }
@@ -0,0 +1,43 @@
1
+ import assert from 'node:assert/strict';
2
+ import { createRequire } from 'node:module';
3
+ import { mkdtemp, rm, mkdir, readFile, writeFile } from 'node:fs/promises';
4
+ import { tmpdir } from 'node:os';
5
+ import { join, resolve } from 'node:path';
6
+ import { execFileSync } from 'node:child_process';
7
+ import { _electron } from 'playwright-core';
8
+ import { petClick, nativeClick } from './helpers/native-pointer.mjs';
9
+
10
+ assert.equal(process.platform, 'win32', 'Use an isolated Windows interactive desktop');
11
+ const require = createRequire(import.meta.url);
12
+ const root = await mkdtemp(join(tmpdir(), 'dsh-windows-pointer-'));
13
+ let app;
14
+ try {
15
+ app = await _electron.launch({
16
+ executablePath: require('electron'), args: ['--no-sandbox', resolve('desktop/main.cjs')],
17
+ env: { ...process.env, DSH_PET_TEST_DATA_DIR: root, DSH_PET_TEST_NO_SANDBOX: '1', DSH_PET_TEST_DEBUG_PORT: '0' },
18
+ });
19
+ const page = await app.firstWindow();
20
+ page.setDefaultTimeout(10000);
21
+ await page.waitForURL(/^http:\/\/127\.0\.0\.1:/, { waitUntil: 'load' });
22
+ await app.evaluate((_, options) => process.emit('message', {
23
+ type: 'init', baseline: true, options,
24
+ snapshot: { mood: 'idle', active: false, sessions: [], results: [] },
25
+ }), { size: 150, roam: false, companionship: 'off', notifications: false, bubbleDurationMs: 12000 });
26
+ await page.waitForSelector('#pet[data-display-revision]');
27
+ const scale = await app.evaluate(({ screen }) => screen.getPrimaryDisplay().scaleFactor);
28
+ assert.equal(scale, Number(process.env.DSH_WINDOWS_EXPECT_SCALE ?? 1.25), 'Use real system scaling without a Chromium override');
29
+ await petClick(page, { button: 'right' });
30
+ assert.equal(await page.locator('#menu').isVisible(), true, 'Native hit testing must allow the context menu');
31
+ const measurement = await nativeClick(page, '#open-characters');
32
+ await page.locator('#characters:not([hidden])').waitFor();
33
+ await mkdir('artifacts', { recursive: true });
34
+ await writeFile('artifacts/windows-pointer-native.json', JSON.stringify({
35
+ sourceCommit: execFileSync('git', ['rev-parse', 'HEAD'], { encoding: 'utf8' }).trim(),
36
+ build: JSON.parse(await readFile('dist/build-info.json', 'utf8')),
37
+ scale, measurement, nativeContextMenu: true, nativePanelClick: true, physicalMultiDisplay: false,
38
+ }, null, 2) + '\n');
39
+ console.log('Windows native pointer passed at actual scale ' + scale);
40
+ } finally {
41
+ await app?.close();
42
+ await rm(root, { recursive: true, force: true });
43
+ }
package/web/pet.js CHANGED
@@ -48,12 +48,14 @@ let renderedSessionId = null, reactionUntil = 0, reactionMood, bubbleSession, tr
48
48
  let bubbleResult, readerResult, pendingOnly = false, talkAt = 0;
49
49
  let readerQueue, inboxState = { requests: [], issues: [], replies: [], total: 0 };
50
50
  let resizeLayout, displayGeometry, pendingDisplayPlacement, resizeOrigin;
51
+ let geometryRequestedAt = -Infinity;
51
52
  let stageWidth = innerWidth, pressedPointerId;
52
53
  const composer = new ChatComposer();
53
54
  const sessionAttention = new SessionAttention();
54
55
  let attentionSnapshot = snapshot;
55
56
  const chatTimers = new Map();
56
57
  let draftSessionId;
58
+ let pendingSessionId;
57
59
  let activityWords = [], actionRestorePending = false, localHour, hourCheckedAt = -Infinity;
58
60
  let companion = initialCompanionship(), companionAction, companionManualId, companionFeedbackUntil = 0, companionReadAt = 0;
59
61
  const companionStroke = createCompanionStroke();
@@ -289,6 +291,9 @@ function updateNpc(now, active, readingAttention) {
289
291
  !layout || layout.busy || ['air', 'drag', 'crouch', 'sleep'].includes(layout.mode);
290
292
  const keyboard = performance.now() - keyboardAt <= 2500 ? keyboardActivity : 'unknown';
291
293
  const geometryReady = !native?.nativeGeometry || displayGeometry && innerWidth === displayGeometry.contentBounds.width && innerHeight === displayGeometry.contentBounds.height;
294
+ if (!geometryReady && performance.now() - geometryRequestedAt >= 1000) {
295
+ geometryRequestedAt = performance.now(); native?.requestGeometry?.();
296
+ }
292
297
  // A held body's x stays at its old foot anchor while box follows the pointer.
293
298
  // Only grounded frames describe a footprint relative to the same anchor.
294
299
  if (layout && !layout.busy && !['air', 'drag', 'crouch'].includes(layout.mode)) npcGroundLayout = layout;
@@ -551,6 +556,7 @@ function receive(message) {
551
556
  switch (message.type) {
552
557
  case 'init':
553
558
  applyOptions(message.options);
559
+ pendingSessionId = undefined;
554
560
  if (message.snapshot) snapshot = message.snapshot;
555
561
  // Recovery restores unread results as an inbox baseline, without speaking them again.
556
562
  if (message.baseline) for (const result of snapshot.results ?? []) shownResults.add(result.id);
@@ -589,9 +595,16 @@ function receive(message) {
589
595
  else if (message.command === 'sound') $('toggle-sound').click();
590
596
  break;
591
597
  case 'characters': $('open-characters').click(); break;
592
- case 'snapshot':
598
+ case 'snapshot': {
593
599
  if (JSON.stringify((message.snapshot.sessions ?? []).map(s => [s.id, s.revision, s.mood])) !== JSON.stringify((snapshot.sessions ?? []).map(s => [s.id, s.revision, s.mood]))) attentionToWork();
594
- snapshot = { ...message.snapshot, results: message.snapshot.results ?? snapshot.results ?? [] }; render(); break;
600
+ const next = { ...message.snapshot, results: message.snapshot.results ?? snapshot.results ?? [] };
601
+ // Read/status responses queued before a local selection still carry the
602
+ // previous target. Hold the user's choice until Host confirms it or the
603
+ // target is no longer available.
604
+ if (pendingSessionId && next.sessionId !== pendingSessionId && next.sessions.some(session => session.id === pendingSessionId)) next.sessionId = pendingSessionId;
605
+ else pendingSessionId = undefined;
606
+ snapshot = next; render(); break;
607
+ }
595
608
  case 'chat-result':
596
609
  if (composer.receive(message)) {
597
610
  clearTimeout(chatTimers.get(message.requestId)); chatTimers.delete(message.requestId); render();
@@ -752,13 +765,18 @@ $('conversation-list').onclick = event => {
752
765
  const session = card && snapshot.sessions.find(item => item.id === card.dataset.sessionId);
753
766
  if (!session) return;
754
767
  conversations.hidden = true;
755
- if (session.id !== snapshot.sessionId) send({ type: 'select', sessionId: session.id });
768
+ if (session.id !== snapshot.sessionId) selectSession(session.id);
756
769
  const result = unreadReplies(snapshot, acknowledgedResults).find(r => r.sessionId === session.id);
757
770
  if (result) openReader(result); else render();
758
771
  };
772
+ function selectSession(id) {
773
+ if (!id || !snapshot.sessions.some(session => session.id === id)) return false;
774
+ pendingSessionId = id; snapshot = { ...snapshot, sessionId: id };
775
+ send({ type: 'select', sessionId: id }); render();
776
+ return true;
777
+ }
759
778
  function continueSession(id) {
760
- if (!id || !snapshot.sessions.some(session => session.id === id)) return;
761
- send({ type: 'select', sessionId: id }); snapshot = { ...snapshot, sessionId: id }; render(); openChat();
779
+ if (selectSession(id)) openChat();
762
780
  }
763
781
  function openSession(id) {
764
782
  if (!id) return;