okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221merge f-split-agent2 c7b65c7f7 (/loop, /goal, /time-skip, keyless search, system-browser tool, Settings Tools, Plan refuses connected tools) into f-split-intea2d565e6

main
6.1 KiB81 linesraw
1/**
2 * Settings -> Tools screenshots from the real UI. The host's /api/agent/tools answer is replaced by a fixture (page.route) so every state can be
3 * shown without a model or a Harness.
4 *
5 *   STRATA_URL=http://127.0.0.1:8899 SHOTS=./tools-shots node scripts/tools-shots.mjs
6 */
7import { chromium } from 'playwright-core';
8import { existsSync, mkdirSync } from 'node:fs';
9import { join, resolve } from 'node:path';
10
11const BASE = process.env.STRATA_URL;
12if (!BASE) { console.error('STRATA_URL is required'); process.exit(2); }
13const SHOTS = resolve(process.env.SHOTS ?? 'tools-shots');
14mkdirSync(SHOTS, { recursive: true });
15const CHROME = process.env.CHROME ?? ['C:/Program Files/Google/Chrome/Application/chrome.exe', '/usr/bin/google-chrome'].find(existsSync);
16
17const group = (id, name, about, area, asks = false, enabled = true) => ({ id, name, about, area, asks, enabled });
18const GROUPS = [
19  group('shell', 'Run commands', 'Lets the assistant run commands, for example to open a folder or start a program.', 'computer', true),
20  group('files', 'Read and change files', 'Lets the assistant read, create and edit files in your chat folder.', 'computer', true),
21  group('find', 'Find files and text', 'Lets the assistant look for files by name and search inside them. It only reads.', 'computer'),
22  group('jobs', 'Long-running jobs', 'Lets the assistant start a slow command in the background and check on it later.', 'computer', true),
23  group('fetch', 'Open web pages', 'Lets the assistant read a web page you point it to.', 'web'),
24  group('search', 'Search the web', 'Lets the assistant search the web when it needs fresh information.', 'web'),
25  group('helpers', 'Helper assistants', 'Lets the assistant start helpers that work on parts of a task at the same time.', 'together'),
26  group('goals', 'Goals', 'Lets you give a goal with /goal. The assistant keeps working until it is done.', 'together'),
27  group('todo', 'To-do list', 'Lets the assistant keep a checklist while it works on a big task.', 'together'),
28  group('skills', 'Skills', 'Lets the assistant use your saved skills when they fit the task.', 'together'),
29  group('present', 'Show results', 'Lets the assistant show a page or file in the preview next to the chat.', 'together'),
30];
31const base = () => ({ groups: GROUPS.map(g => ({ ...g })), search: { provider: 'builtin', keySet: false }, browser: { enabled: false, found: true, name: 'Google Chrome' }, custom: [] });
32const STATES = {
33  fresh: base(),
34  busy: (() => { const s = base(); s.groups[3].enabled = false; s.groups[5].enabled = false; s.browser.enabled = true;
35    s.custom = [
36      { id: 'c1', name: 'Release notes', about: 'Write release notes in our house style.', kind: 'instructions', enabled: true, summary: 'Start with a one-line summary…' },
37      { id: 'c2', name: 'Check website', about: 'Check that our website answers.', kind: 'command', enabled: true, summary: 'curl -I https://example.com', command: 'curl -I https://example.com' },
38      { id: 'c3', name: 'Issue tracker', about: 'Look up and update issues.', kind: 'server', enabled: false, summary: 'https://issues.example/mcp', address: 'https://issues.example/mcp' },
39    ]; return s; })(),
40  key: (() => { const s = base(); s.search = { provider: 'exa', keySet: false }; return s; })(),
41  nobrowser: (() => { const s = base(); s.browser = { enabled: false, found: false, name: null }; return s; })(),
42};
43
44const browser = await chromium.launch({ executablePath: CHROME, headless: true });
45let page = null, context = null;
46let current = 'fresh';
47const shot = async name => { await page.waitForTimeout(500); await page.screenshot({ path: join(SHOTS, `${name}.png`) }); console.log(`shot ${name}.png`); };
48const open = async state => {
49  current = state;
50  if (!page) {
51    context = await browser.newContext({ viewport: { width: 1360, height: 980 } });
52    page = await context.newPage();
53    page.on('pageerror', e => console.log('pageerror', e.message.slice(0, 300)));
54    page.on('console', m => { if (m.type() === 'error') console.log('console', m.text().slice(0, 300)); });
55    await page.route('**/api/agent/tools**', route => route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify(STATES[current]) }));
56    await page.goto(`${BASE}/`);
57    const skip = page.getByText('Go straight to the app');
58    await skip.waitFor({ timeout: 8000 }).then(() => skip.click()).catch(() => {});
59    await page.goto(`${BASE}/#/settings`);
60    await page.waitForSelector('#settings-tab-Tools', { timeout: 20000 });
61    await page.locator('#settings-tab-Tools').evaluate(el => el.click());
62  } else {
63    // The Tools panel loads its list when it is shown: leave it and come back to load the next fixture.
64    await page.locator('#settings-tab-Appearance').evaluate(el => el.click());
65    await page.waitForTimeout(300);
66  }
67  await page.locator('#settings-tab-Tools').evaluate(el => el.click());
68  await page.waitForSelector('.settings-tools', { timeout: 10000 });
69};
70await open('fresh'); await shot('01-tools-top');
71await page.getByRole('heading', { name: 'Web search' }).evaluate(el => el.scrollIntoView({ block: 'start' })); await shot('02-tools-web-and-browser');
72await open('busy'); await page.getByRole('heading', { name: 'Your own tools' }).evaluate(el => el.scrollIntoView({ block: 'start' })); await shot('03-your-own-tools');
73await open('key'); await page.getByRole('heading', { name: 'Web search' }).evaluate(el => el.scrollIntoView({ block: 'start' })); await shot('04-search-with-key');
74await open('nobrowser'); await page.getByRole('heading', { name: 'Web browser' }).evaluate(el => el.scrollIntoView({ block: 'start' })); await shot('05-no-browser-found');
75await open('fresh');
76await page.getByRole('button', { name: 'Add a tool' }).click(); await shot('06-add-tool-instructions');
77await page.getByRole('dialog').getByLabel('How it works').click();
78await page.getByRole('option', { name: 'Run a command' }).click(); await shot('07-add-tool-command');
79await page.getByRole('dialog').getByLabel('How it works').click();
80await page.getByRole('option', { name: 'Connect a tool server (MCP)' }).click(); await shot('08-add-tool-server');
81await browser.close();