okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
7b06ea51b
main
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 ) { 7const r = await fetch ( BASE + path , { method, headers :{ 'content-type' :'application/json' }, body :body === undefined ?undefined :JSON . stringify ( body ) }); 8return { 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' ) { 11const list = ( await api ( '/api/model-providers' )). body ; 12const have = list . connections . find ( c => c . name === name ); 13const res = await api ( '/api/model-providers' , 'POST' , { ...( have ?{ id :have . id } :{}), kind :'custom' , provider :null , name, baseUrl, protocol :'openai-chat' , apiKey :'' , models}); 14return res . body . connections . find ( c => c . name === name ); 15} 16export async function open ({ theme= 'light' , width= 1400 , height= 900 } = {}) { 17const browser = await browserType . launch ({ executablePath :CHROME , headless :true }); 18const context = await browser . newContext ({ viewport :{ width, height}, deviceScaleFactor :1 , colorScheme :theme , permissions :[ 'clipboard-read' , 'clipboard-write' ] }); 19const page = await context . newPage (); 20await page . goto ( BASE + '/' ); 21await page . waitForTimeout ( 1500 ); 22const skip = page . getByText ( 'Go straight to the app' ); 23await skip . waitFor ({ timeout :10000 }). catch (() => {}); 24if ( await skip . count ()) { await skip . click (); await page . waitForTimeout ( 800 ); } 25return { browser, context, page}; 26}