create-pmos 0.375.0 → 0.377.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/package.json +30 -30
- package/payload/KIT-VERSION +1 -1
- package/payload/planning/evals/eval-calibration.md +1 -1
- package/payload/planning/okrs/health-budgets.md +1 -1
- package/payload/state/discoveries.md +1 -1
- package/workspace/briefing-premium-calendar-3-test.js +28 -0
- package/workspace/briefing-premium-test.js +7 -9
- package/workspace/changelog.json +29 -0
- package/workspace/guide/briefing-premium.md +17 -4
- package/workspace/lib/chat-files.js +99 -0
- package/workspace/lib/routes-briefing-premium.js +52 -2
- package/workspace/package-lock.json +2 -2
- package/workspace/package.json +1 -1
- package/workspace/premium-chat-attach-test.js +147 -0
- package/workspace/premium-chat-viewer-test.js +125 -0
- package/workspace/premium-phone-room-test.js +6 -5
- package/workspace/premium-viewer-test.js +1 -1
- package/workspace/public/pm/premium-attach.js +141 -0
- package/workspace/public/pm/premium-meeting.js +2 -2
- package/workspace/public/pm/premium-shell.js +89 -17
- package/workspace/public/pm/premium-viewer.js +57 -6
- package/workspace/public/pm/premium.css +83 -5
- package/workspace/server.js +2 -0
- package/workspace/test-lists/premium-chat-attach.json +13 -0
- package/workspace/test-lists/premium-chat-viewer.json +9 -0
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
/* premium-chat-attach-test.js — files and photos on a premium chat message (initiative premium-chat-attach).
|
|
4
|
+
* Serves the real My work page from the real server with a fixture model; files save through the real /api/chat-file in a scratch state folder.
|
|
5
|
+
* B1 the + and its menu · B2 Slash commands · B3 pick two files, chips, saved · B4 remove one · B5 paste and drop · B6 send names the files
|
|
6
|
+
* B7 the PM's bubble shows the files and a chip opens the photo in the viewer · B8 no key, no + · B9 phone */
|
|
7
|
+
const fs = require('fs');
|
|
8
|
+
const path = require('path');
|
|
9
|
+
const { spawn } = require('child_process');
|
|
10
|
+
const { findBrowser } = require('./lib/find-browser');
|
|
11
|
+
const T = require('./test-run').configure({ name: 'premium-chat-attach' });
|
|
12
|
+
const WP = require('./lib/my-work-premium.js');
|
|
13
|
+
const F = require('./fixtures/my-work-premium-facts.js');
|
|
14
|
+
|
|
15
|
+
const BASE = T.BASE;
|
|
16
|
+
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
17
|
+
const until = async (fn, ms = 6000, step = 100) => { const t0 = Date.now(); for (;;) { const v = await fn(); if (v) return v; if (Date.now() - t0 > ms) return v; await sleep(step); } };
|
|
18
|
+
const results = [];
|
|
19
|
+
const ok = (name, cond, extra = '') => { results.push({ name, cond: !!cond }); console.log(`${cond ? '✓' : '✗'} ${name}${!cond && extra !== '' ? ' — ' + extra : ''}`); };
|
|
20
|
+
let srv = null; let browser = null;
|
|
21
|
+
const finish = async (code) => {
|
|
22
|
+
if (browser) await browser.close().catch(() => {});
|
|
23
|
+
if (srv) { try { srv.kill('SIGKILL'); } catch { /* gone */ } }
|
|
24
|
+
T.killTmux();
|
|
25
|
+
const bad = results.filter((x) => !x.cond).length;
|
|
26
|
+
console.log(`\n${results.length - bad}/${results.length} premium-chat-attach assertions passed`);
|
|
27
|
+
process.exit(code !== undefined ? code : (bad ? 1 : 0));
|
|
28
|
+
};
|
|
29
|
+
process.on('unhandledRejection', (e) => { console.error(e); finish(1); });
|
|
30
|
+
const SHOTS = process.env.ATTACH_SHOTS || ''; // a folder: the suite also saves screenshots there for review
|
|
31
|
+
const shot = async (page, n) => { if (SHOTS) await page.screenshot({ path: path.join(SHOTS, n + '.png') }); };
|
|
32
|
+
const KEY = 'work:attach-1';
|
|
33
|
+
// a 2x2 PNG, so the chip and the viewer have a real picture to draw
|
|
34
|
+
const PNG = Buffer.from('iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAIAAAD91JpzAAAAFklEQVR4nGP4z8DwnwEIGP4zMDAwAAA+xAP9TfeQ1AAAAABJRU5ErkJggg==', 'base64');
|
|
35
|
+
const filesIn = () => { const d = path.join(T.STATE_DIR, 'chat-files'); const out = []; try { for (const s of fs.readdirSync(d)) for (const f of fs.readdirSync(path.join(d, s))) out.push(f); } catch { /* none yet */ } return out; };
|
|
36
|
+
|
|
37
|
+
(async () => {
|
|
38
|
+
const exe = findBrowser();
|
|
39
|
+
if (!exe) { console.log('✗ no Chrome/Chromium on this machine — the suite cannot run'); return finish(1); }
|
|
40
|
+
let chromium;
|
|
41
|
+
try { ({ chromium } = require('playwright-core')); } catch { console.log('✗ playwright-core is not installed'); return finish(1); }
|
|
42
|
+
srv = spawn(process.execPath, [path.join(__dirname, 'server.js')], { cwd: __dirname, stdio: 'ignore', env: T.env({ PMOS_WS_PORT: String(T.PORT) }) });
|
|
43
|
+
await T.waitForServer(BASE);
|
|
44
|
+
browser = await chromium.launch({ executablePath: exe });
|
|
45
|
+
const model = WP.build({ v: F.view(), now: F.NOW });
|
|
46
|
+
|
|
47
|
+
const open = async ({ w = 1280, h = 900, scheme = 'light' } = {}) => {
|
|
48
|
+
const ctx = await browser.newContext({ viewport: { width: w, height: h }, colorScheme: scheme });
|
|
49
|
+
const page = await ctx.newPage();
|
|
50
|
+
const errors = [], asks = [];
|
|
51
|
+
page.on('pageerror', (e) => errors.push(String((e && e.message) || e)));
|
|
52
|
+
await page.route('**/api/my-work-premium', (r) => r.fulfill({ contentType: 'application/json', body: JSON.stringify({ ok: true, state: 'ready', model, as_of: Date.now() }) }));
|
|
53
|
+
await page.route('**/api/briefing-premium/**', (r) => { const rq = r.request(); if (rq.method() !== 'GET') asks.push({ path: new URL(rq.url()).pathname, body: JSON.parse(rq.postData() || '{}') }); r.fulfill({ contentType: 'application/json', body: JSON.stringify({ ok: true, turns: [], working: false }) }); });
|
|
54
|
+
await page.goto(BASE + '/premium-work.html', { waitUntil: 'domcontentloaded' });
|
|
55
|
+
await page.waitForFunction(() => document.querySelector('#dBody') !== null);
|
|
56
|
+
return { page, ctx, errors, asks };
|
|
57
|
+
};
|
|
58
|
+
const dlg = (page, key) => page.evaluate(async (key) => { const m = await import('/pm/premium-shell.js'); m.openDlg({ eye: 'Test', title: 'Attach test', say: 'Hello.', noteKey: key, html: '<p>detail</p>' }); m.setTab('chat'); }, key);
|
|
59
|
+
const close = (page) => page.evaluate(async () => { const m = await import('/pm/premium-shell.js'); m.closeDlg(); });
|
|
60
|
+
const chips = (page) => page.$$eval('#attRow .atc', (xs) => xs.map((x) => ({ name: x.querySelector('b').textContent, meta: (x.querySelector('em') || {}).textContent || '' })));
|
|
61
|
+
|
|
62
|
+
let { page, ctx, errors, asks } = await open();
|
|
63
|
+
await dlg(page, KEY);
|
|
64
|
+
/* B1 */
|
|
65
|
+
ok('B1 the + is at the left inside the message box', await page.isVisible('#askPlus') && await page.evaluate(() => { const p = document.querySelector('#askPlus').getBoundingClientRect(), t = document.querySelector('#askIn').getBoundingClientRect(); return p.left >= t.left && p.right < t.left + 60 && p.bottom <= t.bottom + 1 && p.top >= t.top - 1; }));
|
|
66
|
+
ok('B1 the menu starts closed and no chip row shows', await page.isHidden('#plusM') && await page.isHidden('#attRow'));
|
|
67
|
+
await page.click('#askPlus');
|
|
68
|
+
ok('B1 the + opens a menu of three above the box', await page.isVisible('#plusM') && (await page.$$('#plusM [data-plus]')).length === 3 && await page.evaluate(() => document.querySelector('#plusM').getBoundingClientRect().bottom <= document.querySelector('#askIn').getBoundingClientRect().top + 8));
|
|
69
|
+
ok('B1 the menu names Add files or photos, Slash commands and Scratchpad', /Add files or photos[\s\S]*Slash commands[\s\S]*Scratchpad/.test(await page.textContent('#plusM')));
|
|
70
|
+
await shot(page, 'menu-1280-light');
|
|
71
|
+
await page.keyboard.press('Escape');
|
|
72
|
+
ok('B1 Escape closes the menu and leaves the dialog open', await page.isHidden('#plusM') && await page.evaluate(() => document.querySelector('#dlg').classList.contains('on')));
|
|
73
|
+
/* B2 */
|
|
74
|
+
await page.click('#askPlus'); await page.click('[data-plus="slash"]');
|
|
75
|
+
ok('B2 Slash commands puts / in the box and shows the commands', (await page.inputValue('#askIn')) === '/' && await page.isVisible('#slashM'));
|
|
76
|
+
await page.fill('#askIn', ''); await page.evaluate(() => document.querySelector('#askIn').dispatchEvent(new Event('input', { bubbles: true })));
|
|
77
|
+
await page.click('#askPlus'); await page.click('[data-plus="pad"]');
|
|
78
|
+
ok('B2 Scratchpad opens the pad', await page.isVisible('#sPad'));
|
|
79
|
+
await page.click('#sPadT');
|
|
80
|
+
/* B3 */
|
|
81
|
+
await page.setInputFiles('#askFile', [{ name: 'Screenshot 1.41.39 PM.png', mimeType: 'image/png', buffer: PNG }, { name: 'Q4 roadmap.pdf', mimeType: 'application/pdf', buffer: Buffer.from('%PDF-1.4 test') }]);
|
|
82
|
+
ok('B3 two picked files show as two chips with their sizes once saved', !!(await until(async () => { const c = await chips(page); return c.length === 2 && c.every((x) => /KB/.test(x.meta)); })), JSON.stringify(await chips(page)));
|
|
83
|
+
ok('B3 a photo chip shows the picture', await page.evaluate(() => { const i = document.querySelector('#attRow img.ath'); return !!i && i.complete && i.naturalWidth === 2; }));
|
|
84
|
+
ok('B3 both files are saved in the state folder, never under the key', filesIn().length === 2 && filesIn().some((f) => /-Screenshot-1.41.39-PM\.png$/.test(f)));
|
|
85
|
+
await shot(page, 'chips-1280-light');
|
|
86
|
+
/* B4 */
|
|
87
|
+
await page.click('#attRow .atc:nth-child(2) [data-att-rm]');
|
|
88
|
+
ok('B4 × removes the chip and deletes the file not sent', (await chips(page)).length === 1 && !!(await until(async () => filesIn().length === 1)));
|
|
89
|
+
/* B5 */
|
|
90
|
+
await page.evaluate(() => { const dt = new DataTransfer(); dt.items.add(new File(['note text'], 'notes.txt', { type: 'text/plain' })); const e = new ClipboardEvent('paste', { clipboardData: dt, bubbles: true, cancelable: true }); document.querySelector('#askIn').dispatchEvent(e); });
|
|
91
|
+
ok('B5 a pasted file is attached', !!(await until(async () => { const c = await chips(page); return c.length === 2 && c[1].name === 'notes.txt' && /KB/.test(c[1].meta); })));
|
|
92
|
+
ok('B5 the paste put no text in the box', (await page.inputValue('#askIn')) === '');
|
|
93
|
+
await page.evaluate(() => { const dt = new DataTransfer(); dt.items.add(new File(['x'], 'dropped.csv', { type: 'text/csv' })); const b = document.querySelector('#dBody'); b.dispatchEvent(new DragEvent('dragover', { dataTransfer: dt, bubbles: true, cancelable: true })); b.dispatchEvent(new DragEvent('drop', { dataTransfer: dt, bubbles: true, cancelable: true })); });
|
|
94
|
+
ok('B5 a file dropped on the conversation is attached', !!(await until(async () => (await chips(page)).length === 3)));
|
|
95
|
+
ok('B5 the drop outline goes away after the drop', !(await page.evaluate(() => document.querySelector('#dBody').classList.contains('atdrop'))));
|
|
96
|
+
/* B6 */
|
|
97
|
+
await page.fill('#askIn', 'Where is this on PMOS?');
|
|
98
|
+
await page.click('#askGo');
|
|
99
|
+
const ask = await until(async () => asks.find((a) => a.path.endsWith('/ask')));
|
|
100
|
+
ok('B6 send passes the words and the three saved names', !!ask && ask.body.text === 'Where is this on PMOS?' && Array.isArray(ask.body.files) && ask.body.files.length === 3 && ask.body.files.every((n) => filesIn().includes(n)), JSON.stringify(ask && ask.body));
|
|
101
|
+
ok('B6 after the send the chips go', !!(await until(async () => await page.isHidden('#attRow'))));
|
|
102
|
+
// the real ask route turns the names into the closing line (no session here: the route answers, the line is checked through the store)
|
|
103
|
+
const lib = require('./lib/chat-files.js');
|
|
104
|
+
const paths = lib.pathsOf({ runtimeDir: T.STATE_DIR, key: KEY, names: ask.body.files });
|
|
105
|
+
ok('B6 the names resolve to the files of this conversation', paths.ok && paths.paths.length === 3);
|
|
106
|
+
/* B7 */
|
|
107
|
+
const line = lib.withFiles('Where is this on PMOS?', paths.paths).replace(/\n/g, ' ');
|
|
108
|
+
await page.evaluate(async (text) => { const m = await import('/pm/premium-shell.js'); document.querySelector('#dBody .stream').innerHTML = m.sessionHtml({ state: 'conv', messages: [{ role: 'user', text }] }); }, line);
|
|
109
|
+
ok('B7 the PM\'s bubble shows the files as chips and the words, not the line', await page.evaluate(() => { const u = document.querySelector('#dBody .turn.u .ub'); return !!u && u.querySelectorAll('.atc[data-att]').length === 3 && /Where is this on PMOS\?/.test(u.textContent) && !/Attached files/.test(u.textContent); }));
|
|
110
|
+
await shot(page, 'bubble-1280-light');
|
|
111
|
+
await page.click('#dBody .turn.u .atc[data-att$=".png"]');
|
|
112
|
+
ok('B7 a photo chip opens the picture in the viewer', !!(await until(async () => page.evaluate(() => { const i = document.querySelector('#dOut .obody.vw:not([hidden]) img.atview'); return !!i && i.complete && i.naturalWidth === 2; }))));
|
|
113
|
+
await shot(page, 'viewer-1280-light');
|
|
114
|
+
const png = paths.paths.find((p) => p.endsWith('.png')), txt = paths.paths.find((p) => p.endsWith('.txt'));
|
|
115
|
+
const r1 = await fetch(BASE + '/api/chat-file?path=' + encodeURIComponent(png));
|
|
116
|
+
ok('B7 a photo is served inline as an image', r1.status === 200 && r1.headers.get('content-type') === 'image/png' && /^inline/.test(r1.headers.get('content-disposition')));
|
|
117
|
+
const r2 = await fetch(BASE + '/api/chat-file?path=' + encodeURIComponent(txt));
|
|
118
|
+
ok('B7 any other file is a sandboxed download', r2.status === 200 && /^attachment/.test(r2.headers.get('content-disposition')) && r2.headers.get('content-security-policy') === 'sandbox');
|
|
119
|
+
const r3 = await fetch(BASE + '/api/chat-file?path=' + encodeURIComponent(path.join(T.STATE_DIR, 'settings.json')));
|
|
120
|
+
ok('B7 a path outside the attachments is refused', r3.status === 404);
|
|
121
|
+
const r4 = await fetch(BASE + '/api/chat-file?key=' + encodeURIComponent(KEY) + '&name=x.png', { method: 'POST', body: PNG });
|
|
122
|
+
ok('B7 a save that does not come from the page is refused', r4.status === 403);
|
|
123
|
+
await close(page);
|
|
124
|
+
/* B8 */
|
|
125
|
+
await dlg(page, null);
|
|
126
|
+
ok('B8 a dialog with no conversation has no +', await page.isHidden('#askPlus'));
|
|
127
|
+
await close(page);
|
|
128
|
+
ok('B1-B8 no page errors', errors.length === 0, errors.join(' | '));
|
|
129
|
+
await ctx.close();
|
|
130
|
+
|
|
131
|
+
/* B9 phone, both themes */
|
|
132
|
+
for (const scheme of ['light', 'dark']) {
|
|
133
|
+
({ page, ctx, errors } = await open({ w: 390, h: 844, scheme }));
|
|
134
|
+
await dlg(page, KEY);
|
|
135
|
+
const h0 = await page.evaluate(() => document.querySelector('#askF').getBoundingClientRect().height);
|
|
136
|
+
await page.setInputFiles('#askFile', [{ name: 'IMG_2041.png', mimeType: 'image/png', buffer: PNG }, { name: 'a-rather-long-file-name-for-a-phone.pdf', mimeType: 'application/pdf', buffer: Buffer.from('%PDF') }, { name: 'third.png', mimeType: 'image/png', buffer: PNG }]);
|
|
137
|
+
await until(async () => (await chips(page)).length === 3 && (await chips(page)).every((x) => /KB/.test(x.meta)));
|
|
138
|
+
await shot(page, 'chips-390-' + scheme);
|
|
139
|
+
ok(`B9 ${scheme}: on a phone the +, the box and the chips stay inside the width`, await page.evaluate(() => { const w = innerWidth; return ['#askPlus', '#askIn', '#attRow'].every((s) => { const r = document.querySelector(s).getBoundingClientRect(); return r.width > 0 && r.left >= 0 && r.right <= w + 1; }) && document.documentElement.scrollWidth <= w; }));
|
|
140
|
+
ok(`B9 ${scheme}: the chips sit in one row, so the box grows by one row only`, await page.evaluate((h0) => { const r = [...document.querySelectorAll('#attRow .atc')].map((x) => Math.round(x.getBoundingClientRect().top)); return new Set(r).size === 1 && document.querySelector('#askF').getBoundingClientRect().height < h0 + 70; }, h0));
|
|
141
|
+
ok(`B9 ${scheme}: the + and × are 44px targets`, await page.evaluate(() => document.querySelector('#askPlus').getBoundingClientRect().height >= 44 && document.querySelector('[data-att-rm]').getBoundingClientRect().height >= 44));
|
|
142
|
+
await page.click('#askPlus'); await shot(page, 'menu-390-' + scheme);
|
|
143
|
+
ok(`B9 ${scheme}: no page errors`, errors.length === 0, errors.join(' | '));
|
|
144
|
+
await ctx.close();
|
|
145
|
+
}
|
|
146
|
+
finish();
|
|
147
|
+
})();
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
/* premium-chat-viewer-test.js — the Chat page's viewer opens when something opens in it (initiative premium-chat-viewer, slice 1).
|
|
4
|
+
* A real server on a scratch repository (c3-scan-fixture.js); the file reads are routed and the conversation is filled in the page.
|
|
5
|
+
* V1 at 1280 the page opens with no viewer column; a file press opens it and folds the session list; closing its last tab closes it again
|
|
6
|
+
* V3 a closed viewer with tabs shows the head's Viewer pill with the count, and the pill opens it
|
|
7
|
+
* V4 in a full-screen dialog on another page, a folded viewer unfolds when something opens in it
|
|
8
|
+
* V5 at 390 there is no Detail / Conversation switch; a file press covers the page with the file and Back; Back and Escape return
|
|
9
|
+
* V6 tabs that do not fit fold into "+N", whose menu opens each
|
|
10
|
+
* Set CHAT_VIEWER_SHOTS=<dir> to save the page at 1280 and 390, light and dark. */
|
|
11
|
+
const { findBrowser } = require('./lib/find-browser');
|
|
12
|
+
require('./test-run').configure({ name: 'premium-chat-viewer' });
|
|
13
|
+
const Fx = require('./c3-scan-fixture.js');
|
|
14
|
+
|
|
15
|
+
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
16
|
+
const until = async (fn, ms = 8000, step = 100) => { const t0 = Date.now(); for (;;) { let v; try { v = await fn(); } catch { v = null; } if (v) return v; if (Date.now() - t0 > ms) return v; await sleep(step); } };
|
|
17
|
+
const results = [];
|
|
18
|
+
const ok = (name, cond, extra = '') => { results.push({ name, cond: !!cond }); console.log(`${cond ? '✓' : '✗'} ${name}${!cond && extra !== '' ? ' — ' + String(extra).slice(0, 600) : ''}`); };
|
|
19
|
+
let F = null, browser = null;
|
|
20
|
+
const finish = async (code) => {
|
|
21
|
+
if (browser) await browser.close().catch(() => {});
|
|
22
|
+
if (F) F.stop();
|
|
23
|
+
const bad = results.filter((x) => !x.cond).length;
|
|
24
|
+
console.log(`\n${results.length - bad}/${results.length} premium-chat-viewer assertions passed`);
|
|
25
|
+
process.exit(code !== undefined ? code : (bad ? 1 : 0));
|
|
26
|
+
};
|
|
27
|
+
process.on('unhandledRejection', (e) => { console.error(e); finish(1); });
|
|
28
|
+
|
|
29
|
+
const MD = '# Sign-up drop\n\nThe **sign-up** rate fell from 41% to 38%.\n';
|
|
30
|
+
const fill = () => {
|
|
31
|
+
const s = document.querySelector('#dBody .stream');
|
|
32
|
+
s.insertAdjacentHTML('beforeend', '<div class="turn a"><div class="tc"><div class="md"><p>I wrote it up in <button type="button" class="fpath" data-file="planning/research/signup-drop.md">planning/research/signup-drop.md</button> and read <button type="button" class="fpath" data-file="planning/prd/signup-fix.md">planning/prd/signup-fix.md</button>.</p></div></div></div>');
|
|
33
|
+
};
|
|
34
|
+
/* the page's own state */
|
|
35
|
+
const look = () => {
|
|
36
|
+
const g = document.querySelector('#dlg'), w = (s) => { const e = document.querySelector(s); return e ? Math.round(e.getBoundingClientRect().width) : 0; }, pill = document.querySelector('#vwPill');
|
|
37
|
+
const out = document.querySelector('#dOut').getBoundingClientRect();
|
|
38
|
+
return { shut: g.classList.contains('vw-shut'), layer: g.classList.contains('vw-layer'), srlMin: g.classList.contains('srl-min'), conv: w('#dBody'), out: Math.round(out.width), outH: Math.round(out.height), vh: innerHeight,
|
|
39
|
+
sw: getComputedStyle(document.querySelector('#dTabs')).display, pill: pill && !pill.hidden ? pill.textContent.trim() : null, back: !!document.querySelector('#vBack') && getComputedStyle(document.querySelector('#vBack')).display !== 'none',
|
|
40
|
+
tabs: [...document.querySelectorAll('#vTabs .vtab')].map((t) => (t.hidden ? '~' : '') + t.textContent.trim()), more: (document.querySelector('#vTabs .vmore') || {}).textContent || null,
|
|
41
|
+
railOff: getComputedStyle(document.querySelector('.rail')).opacity === '0', wide: document.documentElement.scrollWidth > innerWidth + 1 };
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
(async () => {
|
|
45
|
+
const exe = findBrowser();
|
|
46
|
+
if (!exe) { console.log('✗ no Chrome/Chromium on this machine — the suite cannot run'); return finish(1); }
|
|
47
|
+
let chromium;
|
|
48
|
+
try { ({ chromium } = require('playwright-core')); } catch { console.log('✗ playwright-core is not installed'); return finish(1); }
|
|
49
|
+
F = await Fx.start({ name: 'premium-chat-viewer' });
|
|
50
|
+
browser = await chromium.launch({ executablePath: exe, headless: true, args: ['--no-sandbox'] });
|
|
51
|
+
const shots = process.env.CHAT_VIEWER_SHOTS;
|
|
52
|
+
const chat = `${F.BASE}/premium-chat.html?ws=${encodeURIComponent(F.ws)}`;
|
|
53
|
+
const open = async (width, scheme = 'light') => {
|
|
54
|
+
const ctx = await browser.newContext({ viewport: { width, height: width < 1000 ? 844 : 800 }, colorScheme: scheme, hasTouch: width < 1000 });
|
|
55
|
+
const p = await ctx.newPage(); const errs = []; p.on('pageerror', (e) => errs.push(String(e)));
|
|
56
|
+
await p.route('**/api/doc/locate**', (r) => { const rel = r.request().url().includes('prd') ? 'planning/prd/signup-fix.md' : 'planning/research/signup-drop.md'; r.fulfill({ json: { ok: true, ws: F.ws, rel, name: rel.split('/').pop(), abs: '/x/' + rel, mtime: 1, size: MD.length } }); });
|
|
57
|
+
await p.route('**/api/doc?**', (r) => r.fulfill({ contentType: 'text/plain', headers: { 'X-Doc-Kind': 'markdown' }, body: MD }));
|
|
58
|
+
await p.goto(chat); await until(() => p.evaluate(() => document.querySelector('#dlg').classList.contains('on') && !!document.querySelector('#dBody .stream')));
|
|
59
|
+
await p.evaluate(fill); await sleep(300);
|
|
60
|
+
return { p, ctx, errs };
|
|
61
|
+
};
|
|
62
|
+
const many = (p) => p.evaluate(async () => { const v = await import('/pm/premium-viewer.js'); for (const n of ['funnel-export.csv', 'support-tickets.md', 'pricing-notes.md', 'a-longer-quarterly-plan.md']) v.vwOpen({ id: 'x:' + n, title: n, html: '<article class="paper doc"><p>' + n + '</p></article>' }); });
|
|
63
|
+
|
|
64
|
+
{ const { p, ctx, errs } = await open(1280);
|
|
65
|
+
const s0 = await p.evaluate(look);
|
|
66
|
+
ok('V1 at 1280 the Chat page opens with no viewer column and the conversation wide', s0.shut && s0.out === 0 && s0.conv > 700 && !s0.pill && s0.tabs.length === 0, JSON.stringify(s0));
|
|
67
|
+
await p.click('.fpath >> nth=0');
|
|
68
|
+
const s1 = await until(async () => { const v = await p.evaluate(look); return !v.shut && v.out > 400 ? v : null; }) || await p.evaluate(look);
|
|
69
|
+
ok('V1 a file press opens the viewer beside a conversation of at least 380 px and folds the session list', !s1.shut && s1.out > 400 && s1.conv >= 380 && s1.srlMin, JSON.stringify(s1));
|
|
70
|
+
ok('V2 the placeholder is not a tab: the strip shows only the file', s1.tabs.length === 1 && /signup-drop\.md/.test(s1.tabs[0]), JSON.stringify(s1.tabs));
|
|
71
|
+
await p.click('#vTabs [data-vx]');
|
|
72
|
+
const s2 = await until(async () => { const v = await p.evaluate(look); return v.shut ? v : null; }) || await p.evaluate(look);
|
|
73
|
+
ok('V1 closing the last tab closes the viewer and unfolds the list', s2.shut && s2.out === 0 && !s2.srlMin, JSON.stringify(s2));
|
|
74
|
+
await p.click('.fpath >> nth=0'); await p.click('.fpath >> nth=1'); await sleep(300);
|
|
75
|
+
await p.click('#vFold');
|
|
76
|
+
const s3 = await until(async () => { const v = await p.evaluate(look); return v.shut && v.pill ? v : null; }) || await p.evaluate(look);
|
|
77
|
+
ok('V3 the close button closes the viewer and the head shows "Viewer 2"', s3.shut && /Viewer\s*2/.test(s3.pill || ''), JSON.stringify(s3));
|
|
78
|
+
await p.click('#vwPill');
|
|
79
|
+
const s4 = await until(async () => { const v = await p.evaluate(look); return !v.shut ? v : null; }) || await p.evaluate(look);
|
|
80
|
+
ok('V3 the pill opens it again on the last tab', !s4.shut && !s4.pill && /signup-fix\.md/.test(s4.tabs.find((t) => !t.startsWith('~')) && s4.tabs[s4.tabs.length - 1]), JSON.stringify(s4));
|
|
81
|
+
if (shots) await p.screenshot({ path: `${shots}/chat-viewer-1280-light.png` });
|
|
82
|
+
await many(p); await sleep(400);
|
|
83
|
+
const s5 = await p.evaluate(look);
|
|
84
|
+
ok('V6 tabs that do not fit fold into +N and the current tab shows', /^\+\d$/.test(s5.more || '') && s5.tabs.some((t) => t.startsWith('~')) && !s5.tabs[s5.tabs.length - 1].startsWith('~'), JSON.stringify(s5));
|
|
85
|
+
await p.click('#vTabs .vmore'); await sleep(200);
|
|
86
|
+
const items = await p.evaluate(() => [...document.querySelectorAll('#vMore [data-vw]')].map((b) => b.dataset.vw));
|
|
87
|
+
await p.click('#vMore [data-vw] >> nth=0'); await sleep(200);
|
|
88
|
+
const on = await p.evaluate(() => (document.querySelector('#vTabs .vtab[aria-selected="true"]') || {}).dataset.vw);
|
|
89
|
+
ok('V6 the +N menu lists the hidden tabs and opens one', items.length >= 1 && on === items[0], JSON.stringify({ items, on }));
|
|
90
|
+
ok('F1 no page error and no sideways scroll', !errs.length && !s5.wide, errs.join(' | '));
|
|
91
|
+
await ctx.close(); }
|
|
92
|
+
|
|
93
|
+
for (const scheme of ['light', 'dark']) {
|
|
94
|
+
const { p, ctx, errs } = await open(390, scheme);
|
|
95
|
+
const s0 = await p.evaluate(look);
|
|
96
|
+
ok(`V5 (${scheme}) at 390 there is no Detail / Conversation switch and no viewer`, s0.sw === 'none' && !s0.layer && s0.conv > 300, JSON.stringify(s0));
|
|
97
|
+
await p.click('.fpath >> nth=0');
|
|
98
|
+
const s1 = await until(async () => { const v = await p.evaluate(look); return v.layer && v.outH >= v.vh - 2 && v.railOff ? v : null; }) || await p.evaluate(look);
|
|
99
|
+
ok(`V5 (${scheme}) a file press covers the page with the file, Back shows and the rail steps aside`, s1.layer && s1.outH >= s1.vh - 2 && s1.back && s1.railOff, JSON.stringify(s1));
|
|
100
|
+
if (shots) await p.screenshot({ path: `${shots}/chat-viewer-390-${scheme}.png` });
|
|
101
|
+
await p.click('#vBack');
|
|
102
|
+
const s2 = await until(async () => { const v = await p.evaluate(look); return !v.layer && !v.railOff ? v : null; }) || await p.evaluate(look);
|
|
103
|
+
ok(`V5 (${scheme}) Back returns to the conversation, the pill shows the count`, !s2.layer && /1/.test(s2.pill || '') && !s2.railOff, JSON.stringify(s2));
|
|
104
|
+
await p.click('#vwPill'); await until(() => p.evaluate(() => document.querySelector('#dlg').classList.contains('vw-layer')));
|
|
105
|
+
await p.keyboard.press('Escape');
|
|
106
|
+
const s3 = await until(async () => { const v = await p.evaluate(look); return !v.layer ? v : null; }) || await p.evaluate(look);
|
|
107
|
+
ok(`V5 (${scheme}) Escape returns to the conversation`, !s3.layer, JSON.stringify(s3));
|
|
108
|
+
ok(`F1 (${scheme}) no page error and no sideways scroll at 390`, !errs.length && !s3.wide, errs.join(' | '));
|
|
109
|
+
await ctx.close();
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
{ const ctx = await browser.newContext({ viewport: { width: 1280, height: 800 } }); const p = await ctx.newPage();
|
|
113
|
+
await p.addInitScript(() => { try { localStorage.setItem('pmos.srl.view', 'min'); } catch { /* none */ } });
|
|
114
|
+
await p.goto(`${F.BASE}/premium.html?ws=${encodeURIComponent(F.ws)}`); await until(() => p.evaluate(() => !!document.querySelector('.rail')));
|
|
115
|
+
await p.evaluate(async () => { const m = await import('/pm/premium-shell.js'); m.openDlg({ eye: 'Goal', title: 'Check the funnel', html: '<p>detail</p>', say: 'Hello', noteKey: 'work:x' }); m.setFull(true); });
|
|
116
|
+
await sleep(300);
|
|
117
|
+
const before = await p.evaluate(() => document.querySelector('#dlg').classList.contains('vw-min'));
|
|
118
|
+
await p.evaluate(async () => { const v = await import('/pm/premium-viewer.js'); v.vwOpen({ id: 'x:a', title: 'a.md', html: '<p>a</p>' }); });
|
|
119
|
+
await sleep(200);
|
|
120
|
+
const after = await p.evaluate(() => document.querySelector('#dlg').classList.contains('vw-min'));
|
|
121
|
+
ok('V4 a folded viewer in a full-screen dialog unfolds when something opens in it', before && !after, JSON.stringify({ before, after }));
|
|
122
|
+
await ctx.close(); }
|
|
123
|
+
|
|
124
|
+
return finish();
|
|
125
|
+
})();
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
/* premium-phone-room-test.js — Focus on a phone (Wawan, 2026-10-21: the scroll area is too small; then "UI broken. Better to have manual CTA to
|
|
4
4
|
* Focus" after the automatic hiding misdrew the page with the keyboard up). A real server on a scratch repository (c3-scan-fixture.js); the
|
|
5
5
|
* conversation is filled in the page.
|
|
6
|
-
* P1 the Chat page at rest · P2 scrolling and typing hide nothing · P3 Focus gives the dialog the screen and moves the rail away · P4 a second
|
|
6
|
+
* P1 the Chat page at rest (no Detail switch since premium-chat-viewer) · P2 scrolling and typing hide nothing · P3 Focus gives the dialog the screen and moves the rail away · P4 a second
|
|
7
7
|
* press brings it all back · P5 a chat dialog on another page takes the screen, the rail class stays off · P6 a desktop has no Focus button
|
|
8
8
|
* Set PHONE_ROOM_SHOTS=<dir> to save the Chat page at 390 wide, light and dark, at rest and in focus. */
|
|
9
9
|
const { findBrowser } = require('./lib/find-browser');
|
|
@@ -50,11 +50,12 @@ const hand = (dy) => { const b = document.querySelector('#dBody'); b.dispatchEve
|
|
|
50
50
|
};
|
|
51
51
|
|
|
52
52
|
{ const { p, ctx, errs } = await open(390);
|
|
53
|
+
await until(() => p.evaluate(() => document.querySelector('#dlg').getBoundingClientRect().top === 0)); // the dialog's entrance has finished
|
|
53
54
|
const s0 = await p.evaluate(look);
|
|
54
|
-
ok('P1 the Chat page at rest shows the
|
|
55
|
+
ok('P1 the Chat page at rest shows the rail and a Focus button, and no Detail switch (premium-chat-viewer V5: the viewer is a layer)', !s0.tabs && !s0.focus && s0.btn && s0.pressed === 'false' && s0.railTop < s0.vh, JSON.stringify(s0));
|
|
55
56
|
await p.evaluate(hand, 300); await sleep(400); await p.evaluate(hand, -100); await p.focus('#askIn'); await sleep(500);
|
|
56
57
|
const s1 = await p.evaluate(look);
|
|
57
|
-
ok('P2 scrolling and typing hide nothing by themselves',
|
|
58
|
+
ok('P2 scrolling and typing hide nothing by themselves', !s1.focus && s1.railTop < s1.vh && s1.dlgH === s0.dlgH, JSON.stringify(s1));
|
|
58
59
|
await p.evaluate(() => document.querySelector('#askIn').blur());
|
|
59
60
|
if (shots) await p.screenshot({ path: `${shots}/chat-rest-390-light.png` });
|
|
60
61
|
await p.click('#dFocus');
|
|
@@ -63,8 +64,8 @@ const hand = (dy) => { const b = document.querySelector('#dBody'); b.dispatchEve
|
|
|
63
64
|
ok('P3b in focus the conversation gets at least 680 px of the 844 px screen (516 px before)', s2.room >= 680, JSON.stringify(s2));
|
|
64
65
|
if (shots) await p.screenshot({ path: `${shots}/chat-focus-390-light.png` });
|
|
65
66
|
await p.click('#dFocus');
|
|
66
|
-
const s3 = await until(async () => { const v = await p.evaluate(look); return !v.focus && !v.dfocus && v.
|
|
67
|
-
ok('P4 a second press brings the
|
|
67
|
+
const s3 = await until(async () => { const v = await p.evaluate(look); return !v.focus && !v.dfocus && v.railTop < v.vh ? v : null; }) || await p.evaluate(look);
|
|
68
|
+
ok('P4 a second press brings the rail back', !s3.focus && !s3.dfocus && s3.railTop < s3.vh && s3.pressed === 'false', JSON.stringify(s3));
|
|
68
69
|
ok('P4b no page error', errs.length === 0, errs.join(' | '));
|
|
69
70
|
await ctx.close(); }
|
|
70
71
|
|
|
@@ -121,7 +121,7 @@ process.on('unhandledRejection', (e) => { console.error(e); finish(1); });
|
|
|
121
121
|
for (const id of ['a', 'b']) await page.evaluate((x) => window.__premiumViewer.vwOpen({ id: x, title: 'A long item title ' + x, html: `<p>${x}</p>` }), id);
|
|
122
122
|
const m = await page.evaluate(() => {
|
|
123
123
|
const r = (e) => e.getBoundingClientRect();
|
|
124
|
-
const tabs = [...document.querySelectorAll('#vTabs .vtab')], xs = [...document.querySelectorAll('#vTabs .vx')];
|
|
124
|
+
const tabs = [...document.querySelectorAll('#vTabs .vtab:not([hidden])')], xs = [...document.querySelectorAll('#vTabs .vtab:not([hidden]) .vx')]; // tabs past the strip's width sit in the +N menu (premium-chat-viewer V6)
|
|
125
125
|
return { tabH: Math.min(...tabs.map((t) => r(t).height)), xH: Math.min(...xs.map((t) => r(t).height)), xW: Math.min(...xs.map((t) => r(t).width)),
|
|
126
126
|
over: document.documentElement.scrollWidth > window.innerWidth, stripW: r(document.querySelector('#vTabs')).right <= window.innerWidth + 1,
|
|
127
127
|
bg: getComputedStyle(document.querySelector('#vTabs .vtab[aria-selected="true"]')).backgroundColor };
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/* pm/premium-attach.js — files and photos on a premium chat message (initiative premium-chat-attach; PM, 2026-10-21: "Where is Add photos or file on PMOS?").
|
|
2
|
+
* A + at the left of the message box opens a small menu: Add files or photos, Slash commands, Scratchpad. A file can also be dropped on the chat or pasted
|
|
3
|
+
* into the box. Each file is saved at once through POST /api/chat-file (in the workspace state folder, never a repository) and shows as a chip above
|
|
4
|
+
* the text with ×. On send the ask route names each file's path for Claude in one closing line; the PM's bubble shows that line as chips, and a chip
|
|
5
|
+
* opens the file in the viewer: a photo as the picture, a PDF as the document, anything else as a download.
|
|
6
|
+
* attachMarkup() · attachRowMarkup() · mountAttach({ getKey, input, note, onSlash, onPad }) · attachNames() · clearAttach()
|
|
7
|
+
* splitFiles(text) · filesHtml(paths) · openAttachment(path) */
|
|
8
|
+
import { pressFetch, pmPost } from './http.js';
|
|
9
|
+
import { vwOpen, vwStyle } from './premium-viewer.js';
|
|
10
|
+
|
|
11
|
+
export const MAX_BYTES = 20 * 1024 * 1024, MAX_FILES = 10;
|
|
12
|
+
const LEAD = '[Attached files, read each one: ';
|
|
13
|
+
const IMG = /\.(png|jpe?g|gif|webp)$/i, PDF = /\.pdf$/i;
|
|
14
|
+
const esc = (s) => String(s == null ? '' : s).replace(/[&<>"']/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c]));
|
|
15
|
+
const CLIP = '<svg class="i" viewBox="0 0 24 24"><path d="M20 11.5l-8 8a5 5 0 01-7-7l8.5-8.5a3.3 3.3 0 014.7 4.7L9.7 17.2a1.7 1.7 0 01-2.4-2.4L15 7"/></svg>';
|
|
16
|
+
const SLASH = '<svg class="i" viewBox="0 0 24 24"><path d="M15 4L9 20"/></svg>';
|
|
17
|
+
const PEN = '<svg class="i" viewBox="0 0 24 24"><path d="M4 20h4L19 9l-4-4L4 16v4z"/><path d="M14 6l4 4"/></svg>';
|
|
18
|
+
const PLUS = '<svg class="i" viewBox="0 0 24 24"><path d="M12 5v14M5 12h14"/></svg>';
|
|
19
|
+
|
|
20
|
+
/** The PM's words and the files the closing line names (the server's lib/chat-files.js splitFiles). Pure. */
|
|
21
|
+
export function splitFiles(text) {
|
|
22
|
+
const t = String(text == null ? '' : text);
|
|
23
|
+
const i = t.lastIndexOf(LEAD);
|
|
24
|
+
if (i < 0 || !/\]\s*$/.test(t)) return { text: t, files: [] };
|
|
25
|
+
return { text: t.slice(0, i).trim(), files: t.slice(i + LEAD.length).replace(/\]\s*$/, '').split(' | ').map((s) => s.trim()).filter(Boolean) };
|
|
26
|
+
}
|
|
27
|
+
/** The name a saved file had when the PM picked it: the folder and the time prefix go. Pure. */
|
|
28
|
+
export const shownName = (p) => String(p || '').split('/').pop().replace(/^\d{8}T\d{6}-/, '');
|
|
29
|
+
/** "214 KB", "1.8 MB". Pure. */
|
|
30
|
+
export const sizeText = (n) => (n >= 1048576 ? (n / 1048576).toFixed(1) + ' MB' : Math.max(1, Math.round(n / 1024)) + ' KB');
|
|
31
|
+
const extOf = (n) => ((/\.([A-Za-z0-9]{1,5})$/.exec(n || '') || [])[1] || 'file').toUpperCase();
|
|
32
|
+
export const fileUrl = (p) => '/api/chat-file?path=' + encodeURIComponent(p);
|
|
33
|
+
|
|
34
|
+
/** One chip as HTML. f: { name, path?, size?, state: 'saving'|'saved'|'sent', url? }. Pure. */
|
|
35
|
+
export function chipHtml(f, i) {
|
|
36
|
+
const img = IMG.test(f.name || '') && (f.url || f.path);
|
|
37
|
+
const th = img ? `<img class="ath" alt="" src="${esc(f.url || fileUrl(f.path))}">` : `<span class="ath atx">${esc(extOf(f.name))}</span>`;
|
|
38
|
+
const meta = f.state === 'saving' ? 'Saving' : f.size ? sizeText(f.size) : '';
|
|
39
|
+
const body = `${th}<span class="atn"><b>${esc(f.name)}</b>${meta ? `<em>${esc(meta)}</em>` : ''}</span>`;
|
|
40
|
+
if (f.state === 'sent') return `<button type="button" class="atc" data-att="${esc(f.path)}" title="Open ${esc(f.name)} beside the conversation">${body}</button>`;
|
|
41
|
+
return `<span class="atc${f.state === 'saving' ? ' up' : ''}">${body}<button type="button" class="atx-rm" data-att-rm="${i}" aria-label="Remove ${esc(f.name)}" title="Remove">×</button></span>`;
|
|
42
|
+
}
|
|
43
|
+
/** The files on a sent message, as chips for the PM's bubble. Pure. */
|
|
44
|
+
export const filesHtml = (paths) => (paths && paths.length ? `<div class="atrow sent">${paths.map((p) => chipHtml({ name: shownName(p), path: p, state: 'sent' })).join('')}</div>` : '');
|
|
45
|
+
|
|
46
|
+
export const attachMarkup = () => `<button type="button" class="askplus" id="askPlus" aria-label="Add files, photos or commands" title="Add files, photos or commands" aria-haspopup="menu" aria-expanded="false" aria-controls="plusM" hidden>${PLUS}</button>`
|
|
47
|
+
+ `<div class="plusm" id="plusM" role="menu" aria-label="Add" hidden><button type="button" role="menuitem" data-plus="file">${CLIP}<span>Add files or photos</span><em>or drop, or paste</em></button>`
|
|
48
|
+
+ `<button type="button" role="menuitem" data-plus="slash">${SLASH}<span>Slash commands</span><em>/</em></button><button type="button" role="menuitem" data-plus="pad">${PEN}<span>Scratchpad</span></button></div>`
|
|
49
|
+
+ `<input type="file" id="askFile" multiple hidden tabindex="-1" aria-hidden="true">`;
|
|
50
|
+
export const attachRowMarkup = () => '<div class="atrow" id="attRow" hidden></div>';
|
|
51
|
+
|
|
52
|
+
if (typeof document !== 'undefined') document.addEventListener('pointerdown', (e) => { if (A && A.close && !e.target.closest('#plusM,#askPlus')) A.close(); }, { capture: true }); // a press outside closes the menu
|
|
53
|
+
let A = null; // the box on show: { files: [{ name, size, state, saved, path, url }], key, … }
|
|
54
|
+
/** The saved names to send, or null while one is still saving. */
|
|
55
|
+
export function attachNames() { if (!A) return []; if (A.files.some((f) => f.state === 'saving')) return null; return A.files.map((f) => f.saved); }
|
|
56
|
+
/** After a send: the chips go; the files stay saved, as the message names them. */
|
|
57
|
+
export function clearAttach() { if (!A) return; A.files.forEach((f) => { if (f.url) URL.revokeObjectURL(f.url); }); A.files = []; A.draw(); }
|
|
58
|
+
|
|
59
|
+
/** Wire the + and the chip row openDlg drew. getKey() is the conversation now on show; no key, no +. */
|
|
60
|
+
export function mountAttach({ getKey, input, note, onSlash, onPad }) {
|
|
61
|
+
if (A) clearAttach();
|
|
62
|
+
const plus = document.getElementById('askPlus'), menu = document.getElementById('plusM'), pick = document.getElementById('askFile'), row = document.getElementById('attRow');
|
|
63
|
+
A = null;
|
|
64
|
+
if (!plus || !menu || !pick || !row) return;
|
|
65
|
+
const me = { files: [], key: getKey() };
|
|
66
|
+
const say = (t) => { if (note) note.textContent = t; };
|
|
67
|
+
me.draw = () => { row.hidden = !me.files.length; row.innerHTML = me.files.map(chipHtml).join(''); };
|
|
68
|
+
A = me;
|
|
69
|
+
const sync = () => {
|
|
70
|
+
const k = getKey();
|
|
71
|
+
plus.hidden = !k;
|
|
72
|
+
if (k !== me.key) { clearAttach(); me.key = k; }
|
|
73
|
+
};
|
|
74
|
+
sync(); me.sync = sync;
|
|
75
|
+
const setMenu = (on) => { menu.hidden = !on; plus.setAttribute('aria-expanded', String(on)); plus.classList.toggle('on', on); if (on) menu.setAttribute('data-esc-layer', ''); else menu.removeAttribute('data-esc-layer'); };
|
|
76
|
+
plus.onmousedown = (e) => e.preventDefault(); // no focus move on press: focus inside the box shows the note under it, which moves the + before the click lands
|
|
77
|
+
plus.onclick = (e) => { e.stopPropagation(); setMenu(menu.hidden); if (!menu.hidden) menu.querySelector('button').focus(); };
|
|
78
|
+
menu.onclick = (e) => {
|
|
79
|
+
const b = e.target.closest('[data-plus]'); if (!b) return;
|
|
80
|
+
setMenu(false);
|
|
81
|
+
if (b.dataset.plus === 'file') pick.click();
|
|
82
|
+
else if (b.dataset.plus === 'slash') onSlash && onSlash();
|
|
83
|
+
else onPad && onPad();
|
|
84
|
+
};
|
|
85
|
+
menu.onkeydown = (e) => {
|
|
86
|
+
const items = [...menu.querySelectorAll('[data-plus]')], i = items.indexOf(document.activeElement);
|
|
87
|
+
if (e.key === 'Escape') { e.preventDefault(); e.stopPropagation(); setMenu(false); plus.focus(); }
|
|
88
|
+
else if (e.key === 'ArrowDown' || e.key === 'ArrowUp') { e.preventDefault(); items[(i + (e.key === 'ArrowDown' ? 1 : items.length - 1)) % items.length].focus(); }
|
|
89
|
+
};
|
|
90
|
+
me.close = () => setMenu(false);
|
|
91
|
+
pick.onchange = () => { add([...(pick.files || [])]); pick.value = ''; };
|
|
92
|
+
row.onclick = (e) => {
|
|
93
|
+
const b = e.target.closest('[data-att-rm]'); if (!b) return;
|
|
94
|
+
const f = me.files[Number(b.dataset.attRm)]; if (!f) return;
|
|
95
|
+
me.files = me.files.filter((x) => x !== f); me.draw();
|
|
96
|
+
if (f.url) URL.revokeObjectURL(f.url);
|
|
97
|
+
if (f.saved) pmPost('/api/chat-file/remove', { key: me.key, name: f.saved }).catch(() => { /* left in the folder; nothing names it */ });
|
|
98
|
+
if (input) input.focus();
|
|
99
|
+
};
|
|
100
|
+
if (input) input.addEventListener('paste', (e) => {
|
|
101
|
+
const fs = e.clipboardData ? [...e.clipboardData.files] : [];
|
|
102
|
+
if (!fs.length || !getKey()) return;
|
|
103
|
+
e.preventDefault(); add(fs);
|
|
104
|
+
});
|
|
105
|
+
async function add(list) {
|
|
106
|
+
const key = getKey(); if (!key || !list.length) return;
|
|
107
|
+
const room = MAX_FILES - me.files.length;
|
|
108
|
+
if (room <= 0) { say('A message takes ' + MAX_FILES + ' files at most.'); return; }
|
|
109
|
+
if (list.length > room) say('Only ' + room + ' more ' + (room === 1 ? 'file fits' : 'files fit') + ' on this message.');
|
|
110
|
+
for (const file of list.slice(0, room)) {
|
|
111
|
+
if (file.size > MAX_BYTES) { say(file.name + ' is larger than 20 MB. Attach a smaller copy, or paste a link.'); continue; }
|
|
112
|
+
const name = file.name || (file.type === 'image/png' ? 'pasted-image.png' : 'pasted-file');
|
|
113
|
+
const f = { name, size: file.size, state: 'saving', url: IMG.test(name) ? URL.createObjectURL(file) : null };
|
|
114
|
+
me.files.push(f); me.draw();
|
|
115
|
+
let r = null;
|
|
116
|
+
try {
|
|
117
|
+
const res = await pressFetch('/api/chat-file?key=' + encodeURIComponent(key) + '&name=' + encodeURIComponent(name), { method: 'POST', body: file, headers: { 'Content-Type': 'application/octet-stream' } });
|
|
118
|
+
r = await res.json();
|
|
119
|
+
} catch { r = null; }
|
|
120
|
+
if (!me.files.includes(f)) { if (r && r.ok) pmPost('/api/chat-file/remove', { key, name: r.name }).catch(() => {}); continue; } // removed while it saved
|
|
121
|
+
if (!r || !r.ok) { me.files = me.files.filter((x) => x !== f); me.draw(); say(name + ' was not attached: ' + ((r && r.error) || 'the workspace server did not answer.')); continue; }
|
|
122
|
+
Object.assign(f, { state: 'saved', saved: r.name, path: r.path }); me.draw();
|
|
123
|
+
}
|
|
124
|
+
if (input) input.focus();
|
|
125
|
+
}
|
|
126
|
+
me.add = add;
|
|
127
|
+
}
|
|
128
|
+
/** A file dropped anywhere on the chat side. Call from the dialog's drop handler. */
|
|
129
|
+
export function dropFiles(list) { if (A && A.add) A.add([...list]); }
|
|
130
|
+
/** Re-read the key (the session list switched the conversation without redrawing the box). */
|
|
131
|
+
export function syncAttach() { if (A && A.sync) A.sync(); }
|
|
132
|
+
|
|
133
|
+
/** An attachment as a viewer tab: a photo as the picture, a PDF as the document, anything else by name with Download. */
|
|
134
|
+
export function openAttachment(p) {
|
|
135
|
+
vwStyle('doc');
|
|
136
|
+
const name = shownName(p), url = fileUrl(p);
|
|
137
|
+
const view = IMG.test(name) ? `<img class="atview" alt="${esc(name)}" src="${esc(url)}">`
|
|
138
|
+
: PDF.test(name) ? `<iframe class="atpdf" title="${esc(name)}" src="${esc(url)}"></iframe>`
|
|
139
|
+
: `<div class="vwfnone" role="status"><b>${esc(name)}</b><p class="vwmut">PMOS does not show this kind of file here. Claude can read it.</p><div class="vwrow"><a class="vwbtn pri" href="${esc(url)}" download="${esc(name)}">Download</a></div></div>`;
|
|
140
|
+
return vwOpen({ id: 'att:' + p, title: name, icon: 'doc', html: `<div class="vwdoc"><article class="cf vwfile atfile"><header class="cfh"><h1 class="cft">${esc(name)}</h1></header>${view}<footer class="cff"><span>Attached to your message · saved on this machine</span></footer></article></div>` });
|
|
141
|
+
}
|
|
@@ -308,7 +308,7 @@ export const topicBody = (row, text) => (row && row.id && clip(text, 120) ? { ev
|
|
|
308
308
|
/** The Replay player's model from GET /api/meeting-replay: the lines, the key points, the stretches by topic and the shots, all in meeting time (ms). */
|
|
309
309
|
export function replayModel(rep) {
|
|
310
310
|
if (!rep || rep.ok !== true) return null;
|
|
311
|
-
const lines = (Array.isArray(rep.lines) ? rep.lines : []).filter((l) => l && Number.isFinite(l.t) && String(l.text || '').trim()).map((l, i) => ({ i, t: l.t, who: clip(l.who, 40), text: clip(l.text,
|
|
311
|
+
const lines = (Array.isArray(rep.lines) ? rep.lines : []).filter((l) => l && Number.isFinite(l.t) && String(l.text || '').trim()).map((l, i) => ({ i, t: l.t, who: clip(l.who, 40), text: clip(l.text, 20000) })).sort((a, b) => a.t - b.t);
|
|
312
312
|
const topics = (Array.isArray(rep.topics) ? rep.topics : []).map((t, i) => ({ id: t.id, text: clip(t.text, 120), n: t.n || i + 1 }));
|
|
313
313
|
let len = Number(rep.length_ms) || (rep.audio && Number(rep.audio.ms)) || 0;
|
|
314
314
|
if (!len && lines.length) len = lines[lines.length - 1].t;
|
|
@@ -318,7 +318,7 @@ export function replayModel(rep) {
|
|
|
318
318
|
need: !!k.warn || k.state === 'owner' || k.state === 'open' }));
|
|
319
319
|
const shots = (Array.isArray(rep.shots) ? rep.shots : []).filter((x) => Number.isFinite(x.t)).map((x) => ({ t: x.t, why: clip(x.why, 120) })).sort((a, b) => a.t - b.t);
|
|
320
320
|
/* PMOS's notes (the meeting companion's, from the Focus file), the gaps where the recording was off, and the line each key point was caught from */
|
|
321
|
-
const pmos = (Array.isArray(rep.notes) ? rep.notes : []).filter((x) => x && Number.isFinite(x.t) && String(x.body || '').trim()).map((x) => ({ t: Math.max(0, Math.min(len, x.t)), cat: clip(x.cat, 30), body: clip(x.body,
|
|
321
|
+
const pmos = (Array.isArray(rep.notes) ? rep.notes : []).filter((x) => x && Number.isFinite(x.t) && String(x.body || '').trim()).map((x) => ({ t: Math.max(0, Math.min(len, x.t)), cat: clip(x.cat, 30), body: clip(x.body, 4000) })).sort((a, b) => a.t - b.t);
|
|
322
322
|
const gaps = (Array.isArray(rep.gaps) ? rep.gaps : []).filter((g) => Number.isFinite(g.from_ms) && Number.isFinite(g.to_ms) && g.to_ms > g.from_ms).map((g) => ({ from: g.from_ms, to: Math.min(len, g.to_ms) }));
|
|
323
323
|
const keyOfLine = new Map((Array.isArray(rep.lines) ? rep.lines : []).filter((l) => l && l.key && l.key.k).map((l) => [l.t, l.key.k]));
|
|
324
324
|
lines.forEach((l) => { l.key = keyOfLine.get(l.t) || ''; });
|