fix(webui): drawer polish review round: at 390 the page under the sheet goes back to its place only when the drawer closes onto that same page, so a link in the sheet opens its page at the top and a later page does not jump; Last activity counts a role or conversation claim only when the instances read lists its run as running, says when a running run holds nothing yet, and names the latest of several runs (#1873, lane sp18-drawer-polish)
This commit is contained in:
1 parent
fc558df31a
commit
38ea639d70
2 files changed
+80
-16
No files matched your search
@@ -1348,13 +1348,18 @@
|
||||
? `<div class="ws-drawer-acts" data-drawer-actions>${acts.join(' ')}<p class="ws-drawer-status" id="ws-drawer-status" role="status" data-drawer-status>${esc(st?.text || '')}</p></div>`
|
||||
: `<p class="note" data-drawer-readonly>This Console only reads ${esc(orgName)}. It can not message or stop its agents.</p>`;
|
||||
// SP18: the agents read lists only roles a run holds now, and thread.claims only conversations a run
|
||||
// holds now; each row's time is when that run took the role or the conversation. So the latest of
|
||||
// them is when the agent's current run started. No read keeps when a run ended or when the agent last
|
||||
// sent a message (a thread's messages read pages from the oldest message), so neither is shown.
|
||||
const runAt = [a.s?.claimedAt, ...arr(body?.sessions).filter(x => x?.kind === 'thread' && x.org === org && x.instance === key).map(x => x.claimedAt)]
|
||||
.filter(v => msOf(v) !== null).sort((x, y) => msOf(y) - msOf(x))[0] ?? null;
|
||||
const activity = runAt ? `current run started <time datetime="${esc(runAt)}" title="${esc(new Date(msOf(runAt)).toLocaleString())}">${esc(ago(runAt))}</time>`
|
||||
: `<span class="muted">${(runWhy => runWhy ? `not read: ${esc(runWhy)}` : 'not recorded: no run holds it now, and no read keeps when its last run ended')(notRead(['agents', 'claims']))}</span>`;
|
||||
// holds now; each row carries that run and when it took the role or the conversation. A claim counts
|
||||
// only when the instances read lists its run as running, so a claim left by a run that ended does not
|
||||
// date a stopped agent. Last activity is the latest such time. No read keeps when a run ended or when
|
||||
// the agent last sent a message (a thread's messages read pages from the oldest message), so neither is shown.
|
||||
const runs = !unknown && runsRead(item) ? item.running : null;
|
||||
const claims = [a.s ? { ...a.s, what: 'the role' } : null, ...arr(body?.sessions).filter(x => x?.kind === 'thread' && x.org === org && x.instance === key).map(x => ({ ...x, what: 'the conversation' }))]
|
||||
.filter(c => c && msOf(c.claimedAt) !== null && (!runs || runs.includes(c.run))).sort((x, y) => msOf(y.claimedAt) - msOf(x.claimedAt));
|
||||
const last = claims[0], claimWhy = notRead(['agents', 'claims']);
|
||||
const activity = last ? `${runs && runs.length > 1 ? `the latest of its ${runs.length} runs` : 'its run'} took ${last.what} <time datetime="${esc(last.claimedAt)}" title="${esc(new Date(msOf(last.claimedAt)).toLocaleString())}">${esc(ago(last.claimedAt))}</time>`
|
||||
: `<span class="muted">${claimWhy ? `not read: ${esc(claimWhy)}`
|
||||
: runs?.length ? `not recorded: ${runs.length > 1 ? 'its runs hold' : 'its run holds'} no role or conversation yet`
|
||||
: 'not recorded: no run holds it now, and no read keeps when its last run ended'}</span>`;
|
||||
const fields = [
|
||||
field('org', 'Organization', orgChip(o, org)),
|
||||
// A pack hire's pack is named once, in Hired from; the Role row says only that it was hired.
|
||||
@@ -1381,9 +1386,11 @@
|
||||
document.dispatchEvent(new CustomEvent('mosaic-workspace-render'));
|
||||
}
|
||||
// SP18: below 701 px the open drawer is a sheet and shell.css holds the page under it to one screen, which
|
||||
// scrolls the page to the top. The page's place is kept while no drawer is open and put back on Close.
|
||||
// scrolls the page to the top. The page's place is kept while no drawer is open, with the page the sheet
|
||||
// opened over. It is put back only when the drawer closes onto that same page (Close, Escape or Back); a
|
||||
// link in the sheet goes to another page, which starts at its top, and the kept place is dropped.
|
||||
const SHEET = window.matchMedia('(max-width:700px)');
|
||||
let pageY = 0;
|
||||
let pageY = 0, sheetOver = null;
|
||||
window.addEventListener('scroll', () => { if (!document.querySelector('#bus-view [data-ws-drawer]')) pageY = window.scrollY; }, { passive: true });
|
||||
// bus.js calls this after each paint: focus moves into a drawer a row opened, and back to the row
|
||||
// when the drawer has closed and focus was left nowhere.
|
||||
@@ -1392,9 +1399,13 @@
|
||||
const view = document.getElementById('bus-view'), d = view?.querySelector('[data-ws-drawer]');
|
||||
const now = d?.dataset.wsDrawer || null, was = drawerShown;
|
||||
drawerShown = now;
|
||||
if (now) sheetOver = sansAgent();
|
||||
if (d && drawerFocus) { drawerFocus = false; d.querySelector('h2')?.focus({ preventScroll: true }); return; }
|
||||
drawerFocus = false;
|
||||
if (!now && was && SHEET.matches && pageY) window.scrollTo(0, pageY);
|
||||
if (!now && sheetOver !== null) {
|
||||
if (SHEET.matches && pageY && sheetOver === sansAgent()) window.scrollTo(0, pageY);
|
||||
sheetOver = null; pageY = window.scrollY;
|
||||
}
|
||||
if (!now && was) {
|
||||
const a = document.activeElement;
|
||||
if (!a || a === document.body || !view?.contains(a)) view?.querySelector(`[data-focus-key="${CSS.escape(`agent:${was}`)}"]`)?.focus({ preventScroll: true });
|
||||
|
||||
@@ -18,7 +18,7 @@ const at = minutesAgo => new Date(Date.now() - minutesAgo * 60000).toISOString()
|
||||
const HIRE = '0f3c1a2b-4d5e-4f60-8a7b-9c0d1e2f3a4b';
|
||||
const THREAD = '7b1e2c3d-4f50-4a61-8b72-9c83d4e5f6a7';
|
||||
|
||||
function fixture() {
|
||||
function fixture(tweak) {
|
||||
const LIST = [
|
||||
{ id: 'acme', label: 'Acme Studio', theme: 'cobalt' },
|
||||
{ id: 'beta', label: 'Beta Works', theme: 'grove' },
|
||||
@@ -52,6 +52,7 @@ function fixture() {
|
||||
model: {},
|
||||
},
|
||||
};
|
||||
tweak?.(DATA);
|
||||
const value = (id, name) => Promise.resolve(DATA[id]?.[name] ?? (['usage', 'limits'].includes(name) ? {} : []));
|
||||
const opts = id => ({
|
||||
bus: { inbox: () => value(id, 'inbox'), agents: () => value(id, 'agents'), 'thread.claims': () => value(id, 'claims'), tasks: () => value(id, 'tasks'), usage: () => value(id, 'usage'), limits: () => value(id, 'limits'), decisions: () => value(id, 'decisions') },
|
||||
@@ -115,8 +116,8 @@ const STUB = `(() => {
|
||||
};
|
||||
})();`;
|
||||
|
||||
async function setup(t, { viewport = [1440, 900], hash = '#/agents', stub = true, scripts = [] } = {}) {
|
||||
const server = await startServer({ port: 0, sso: createDevOwner(), organizations: fixture(), log: () => {} });
|
||||
async function setup(t, { viewport = [1440, 900], hash = '#/agents', stub = true, scripts = [], data } = {}) {
|
||||
const server = await startServer({ port: 0, sso: createDevOwner(), organizations: fixture(data), log: () => {} });
|
||||
t.after(() => close(server));
|
||||
const b = await browser({ machine: false }); t.after(() => b.close());
|
||||
await b.viewport(...viewport);
|
||||
@@ -186,8 +187,8 @@ test('the drawer shows each field from its read: name, organization, role and so
|
||||
const decisions = await b.evaluate(`[...document.querySelectorAll('${d} [data-drawer-decisions] li a')].map(a => [a.textContent.trim(), a.getAttribute("href")])`);
|
||||
assert.deepEqual(decisions, [['Ship the hero copy?', '#/inbox?d=acme%3Adec-1']]);
|
||||
// SP18: the agents read lists only roles a run holds now, and its time is when that run took the role,
|
||||
// so Last activity is when the current run started, 40 minutes before the read, with the time itself.
|
||||
assert.match(await text(`${d} [data-drawer-activity]`), /^current run started 4[01] min ago$/);
|
||||
// so Last activity is when coder's running run took the role, 40 minutes before the read, with the time itself.
|
||||
assert.match(await text(`${d} [data-drawer-activity]`), /^its run took the role 4[01] min ago$/);
|
||||
const started = await attr(`${d} [data-drawer-activity] time`, 'datetime');
|
||||
assert.ok(Math.abs(Date.now() - Date.parse(started) - 40 * 60000) < 90000, started);
|
||||
assert.match(await attr(`${d} [data-drawer-activity] time`, 'title'), /\d/);
|
||||
@@ -217,6 +218,33 @@ test('a hired agent shows where its role came from; a not-running agent says not
|
||||
assert.equal(await has(`${d} [data-drawer-activity] time`), false);
|
||||
});
|
||||
|
||||
// SP18 review: a claim dates the agent only when the instances read lists its run as running.
|
||||
test('SP18 review: Last activity counts only a claim whose run is running', async t => {
|
||||
// Coder runs run-2, but the role is still held by run-1, whose process ended: nothing dates run-2 yet.
|
||||
{
|
||||
const { wait, text, has } = await setup(t, { hash: '#/agents?agent=acme%3Acoder', data: d => { d.acme.instances.coder.running = ['run-2']; } });
|
||||
const d = '[data-ws-drawer="acme:coder"]';
|
||||
await wait(`${open('acme:coder')} && /running$/.test(document.querySelector('${d} [data-drawer-state]')?.textContent ?? '')`);
|
||||
assert.equal(await text(`${d} [data-drawer-activity]`), 'not recorded: its run holds no role or conversation yet');
|
||||
assert.equal(await has(`${d} [data-drawer-activity] time`), false);
|
||||
}
|
||||
// Coder runs nothing, and a claim from three days ago is left: not running, and no time from that claim.
|
||||
{
|
||||
const { wait, text, has } = await setup(t, { hash: '#/agents?agent=acme%3Acoder', data: d => { d.acme.instances.coder.running = []; d.acme.agents[0].at = at(3 * 24 * 60); d.acme.agents[0].working = null; } });
|
||||
const d = '[data-ws-drawer="acme:coder"]';
|
||||
await wait(`${open('acme:coder')} && /not running$/.test(document.querySelector('${d} [data-drawer-state]')?.textContent ?? '')`);
|
||||
assert.equal(await text(`${d} [data-drawer-activity]`), 'not recorded: no run holds it now, and no read keeps when its last run ended');
|
||||
assert.equal(await has(`${d} [data-drawer-activity] time`), false);
|
||||
}
|
||||
// Two runs, one holding the role: the line says it is the latest of them.
|
||||
{
|
||||
const { wait, text } = await setup(t, { hash: '#/agents?agent=acme%3Acoder', data: d => { d.acme.instances.coder.running = ['run-1', 'run-2']; } });
|
||||
const d = '[data-ws-drawer="acme:coder"]';
|
||||
await wait(`${open('acme:coder')} && !!document.querySelector('${d} [data-drawer-activity] time')`);
|
||||
assert.match(await text(`${d} [data-drawer-activity]`), /^the latest of its 2 runs took the role 4[01] min ago$/);
|
||||
}
|
||||
});
|
||||
|
||||
test('SP16: a pack hire names its pack and the template the packs read gives; a refused read says so', async t => {
|
||||
const { b, base, wait, text } = await setup(t, { hash: '#/agents?agent=beta%3Aresearch-2' });
|
||||
const d = '[data-ws-drawer="beta:research-2"]';
|
||||
@@ -508,7 +536,7 @@ test('Message opens the agent\'s thread in an Assistant pane; Stop asks first an
|
||||
// SP16: Message is offered, so no line says why it is not.
|
||||
assert.equal(await has('[data-ws-drawer="acme:assistant"] [data-drawer-nomessage]'), false);
|
||||
// SP18: a conversation agent's run took its conversation 5 minutes before the read (thread.claims' time).
|
||||
assert.match(await text('[data-ws-drawer="acme:assistant"] [data-drawer-activity]'), /^current run started [56] min ago$/);
|
||||
assert.match(await text('[data-ws-drawer="acme:assistant"] [data-drawer-activity]'), /^its run took the conversation [56] min ago$/);
|
||||
// A role agent holds no thread to open, so it has no Message; it can still be stopped.
|
||||
await b.evaluate('location.hash = "#/agents?agent=acme%3Acoder"');
|
||||
await wait(`${open('acme:coder')} && document.querySelector('[data-ws-drawer="acme:coder"] [data-drawer-stop]')`);
|
||||
@@ -618,6 +646,31 @@ test('SP18: at 390 wide the open sheet is the whole screen, the page under it do
|
||||
assert.ok(await b.evaluate('document.documentElement.scrollHeight') > 900, 'at 1440 the page beside the drawer keeps its height');
|
||||
});
|
||||
|
||||
// SP18 review: only Close (or Back to the same page) puts the page back. A link in the sheet goes to a new
|
||||
// page, which starts at its top, and the place kept for the page under the sheet is not used later either.
|
||||
test('SP18 review: at 390 a link in the sheet opens its page at the top, and a later page does not jump', async t => {
|
||||
const { b, wait } = await setup(t, { viewport: [390, 844], hash: '#/orgs/acme/organization' });
|
||||
const link = JSON.stringify(sessionLink('acme:coder'));
|
||||
await wait(`document.querySelector(${link}) && document.querySelectorAll("[data-org-settings] [data-org-setting]").length > 10`);
|
||||
await b.evaluate(`document.querySelector(${link}).scrollIntoView({ block: 'center' })`);
|
||||
const at = await b.evaluate('Math.round(scrollY)');
|
||||
assert.ok(at > 100, `the row is down the page: ${at}`);
|
||||
await b.evaluate(`document.querySelector(${link}).click()`);
|
||||
await wait(open('acme:coder'));
|
||||
await b.evaluate(`${drawer('acme:coder')}.querySelector("[data-drawer-task] a").click()`);
|
||||
await wait(`${noDrawer} && location.hash.startsWith("#/orgs/acme/tasks?task=")`);
|
||||
await b.evaluate('new Promise(r => setTimeout(r, 300))');
|
||||
// A long page, so a jump to the kept place would show.
|
||||
await b.evaluate('document.body.style.minHeight = "4000px"; new Promise(r => requestAnimationFrame(() => requestAnimationFrame(r)))');
|
||||
const y = await b.evaluate('Math.round(scrollY)');
|
||||
assert.ok(y <= 1, `the Task page is at its top, not at ${at}: ${y}`);
|
||||
// The next page with no drawer does not take the kept place either.
|
||||
await b.evaluate('location.hash = "#/orgs/acme/organization"');
|
||||
await wait(`document.querySelectorAll("[data-org-settings] [data-org-setting]").length > 10`);
|
||||
await b.evaluate('new Promise(r => setTimeout(r, 300))');
|
||||
assert.ok(await b.evaluate('Math.round(scrollY)') <= 1, `the organization page opens at its top: ${await b.evaluate('Math.round(scrollY)')}`);
|
||||
});
|
||||
|
||||
// #1873 triage-followups: the page focuses its heading when its first render ends. On load the page
|
||||
// starts a second render that reads GET /api/workspace again, so when the first render's read is slow
|
||||
// the second draws the rows first and a reader can open a drawer before the first render ends. Its late
|
||||
|
||||
Reference in new issue
Block a user