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. |
| 2 | import { open, shot } from './harness.mjs'; |
| 3 | import http from 'node:http'; |
| 4 | |
| 5 | function 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 | } |
| 23 | const a = provider(9111, ['llama-3.3-70b-instruct', 'qwen-2.5-coder-32b']); |
| 24 | const b = provider(9112, ['deepseek-v3', 'llama-3.3-70b-instruct']); |
| 25 | |
| 26 | const s = await open({ name: 'focusdlg', connect: false }); |
| 27 | const p = s.page; |
| 28 | await p.waitForTimeout(1200); |
| 29 | await 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 | }); |
| 39 | await p.waitForTimeout(500); |
| 40 | await p.click('#new-diamond-btn'); |
| 41 | await p.waitForSelector('.dlg-select', { timeout: 8000 }); |
| 42 | // Open the pulldown so the grouping is visible in the shot. |
| 43 | await p.click('.dlg-select'); |
| 44 | await p.waitForTimeout(400); |
| 45 | await shot(s, 'focus-dialog'); |
| 46 | console.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 | })); |
| 52 | await s.close(); |
| 53 | a.close(); b.close(); |