okami.mom/strata

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

Niko1221Merge f-split-fb3 into f-split-int (locale keys re-added after the card-list strings)7b06ea51b

main
1.9 KiB26 linesraw
1// Shared helpers for driving a throwaway host with Playwright (the app page in a real browser). STRATA_UI_BASE = the host's address, CHROME_PATH = the browser.
2export { chromium } from 'playwright-core';
3import { chromium as browserType } from 'playwright-core';
4export const BASE = process.env.STRATA_UI_BASE ?? 'http://127.0.0.1:18791';
5export const CHROME = process.env.CHROME_PATH ?? 'C:/Program Files/Google/Chrome/Application/chrome.exe';
6export async function api(path, method = 'GET', body) {
7  const r = await fetch(BASE + path, { method, headers: { 'content-type': 'application/json' }, body: body === undefined ? undefined : JSON.stringify(body) });
8  return { status: r.status, body: await r.json().catch(() => null) };
9}
10export async function ensureMock(name = 'Mock model', models = [{ id: 'mock-model', name: 'Mock model' }], baseUrl = 'http://127.0.0.1:18899/v1') {
11  const list = (await api('/api/model-providers')).body;
12  const have = list.connections.find(c => c.name === name);
13  const res = await api('/api/model-providers', 'POST', { ...(have ? { id: have.id } : {}), kind: 'custom', provider: null, name, baseUrl, protocol: 'openai-chat', apiKey: '', models });
14  return res.body.connections.find(c => c.name === name);
15}
16export async function open({ theme = 'light', width = 1400, height = 900 } = {}) {
17  const browser = await browserType.launch({ executablePath: CHROME, headless: true });
18  const context = await browser.newContext({ viewport: { width, height }, deviceScaleFactor: 1, colorScheme: theme, permissions: ['clipboard-read', 'clipboard-write'] });
19  const page = await context.newPage();
20  await page.goto(BASE + '/');
21  await page.waitForTimeout(1500);
22  const skip = page.getByText('Go straight to the app');
23  await skip.waitFor({ timeout: 10000 }).catch(() => {});
24  if (await skip.count()) { await skip.click(); await page.waitForTimeout(800); }
25  return { browser, context, page };
26}