Oregami
Repositories/oxedyne/daimond

oxedyne/daimond/dev/probe_diamonddlg.mjs

2.0 KiB, 1 run

created by r2519314175:41, which is this file's identity for as long as the history lasts, whatever it is later renamed to

download · who wrote it · its history

1// A look at the New Diamond dialog, with two providers seeded.
2import { open, shot } from './harness.mjs';
3import http from 'node:http';
4
5function provider(port, models) {
6 const srv = http.createServer((req, res) => {
7 // The key rides in an `authorization` header, which makes the browser preflight. Without
8 // an answer to OPTIONS the fetch never happens at all.
9 if (req.method === 'OPTIONS') {
10 res.writeHead(204, {
11 'access-control-allow-origin': '*',
12 'access-control-allow-headers': '*',
13 'access-control-allow-methods': 'POST, GET, OPTIONS',
14 });
15 return res.end();
16 }
17 res.writeHead(200, { 'content-type': 'application/json', 'access-control-allow-origin': '*' });
18 res.end(JSON.stringify({ data: models.map(id => ({ id })) }));
19 });
20 srv.listen(port, '127.0.0.1');
21 return srv;
22}
23const a = provider(9111, ['llama-3.3-70b-instruct', 'qwen-2.5-coder-32b']);
24const b = provider(9112, ['deepseek-v3', 'llama-3.3-70b-instruct']);
25
26const s = await open({ name: 'focusdlg', connect: false });
27const p = s.page;
28await p.waitForTimeout(1200);
29await p.evaluate(async () => {
30 const M = window.DaimondModels;
31 M.addProvider('fireworks', { name: 'Fireworks AI', url: 'http://127.0.0.1:9111/v1/chat/completions' });
32 M.addProvider('groq', { name: 'Groq', url: 'http://127.0.0.1:9112/v1/chat/completions' });
33 await M.setKey('fireworks', 'k1');
34 await M.setKey('groq', 'k2');
35 await M.fetchModels('fireworks');
36 await M.fetchModels('groq');
37 M.setDefault('fireworks', 'llama-3.3-70b-instruct');
38});
39await p.waitForTimeout(500);
40await p.click('#new-diamond-btn');
41await p.waitForSelector('.dlg-select', { timeout: 8000 });
42// Open the pulldown so the grouping is visible in the shot.
43await p.click('.dlg-select');
44await p.waitForTimeout(400);
45await shot(s, 'focus-dialog');
46console.log(await p.evaluate(() => {
47 const sel = document.querySelector('.dlg-select');
48 return [...sel.querySelectorAll('optgroup')]
49 .map(g => g.label + ': ' + [...g.querySelectorAll('option')].map(o => o.textContent).join(', '))
50 .join('\n');
51}));
52await s.close();
53a.close(); b.close();