oxedyne/daimond/dev/real_smoke.mjs
3.0 KiB, 1 run
created by r2519314175:115, 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 | // One real turn against Fireworks gpt-oss-120b, driven through the real Settings |
| 2 | // form (the reliable path), headless. Proves the loop works with a real model. |
| 3 | import fs from 'node:fs'; |
| 4 | import { open, chat, errors } from './harness.mjs'; |
| 5 | const cfg = JSON.parse(fs.readFileSync('dev/.secrets/testcfg.json', 'utf8')); |
| 6 | const MODEL = cfg.models.value; |
| 7 | |
| 8 | const s = await open({ name: 'realsmoke', connect: false }); // signed in, not yet connected |
| 9 | |
| 10 | // Drive the Settings form with REAL values (mirrors connectMock, real key). |
| 11 | await s.page.evaluate(async (c) => { |
| 12 | document.getElementById('settings-btn')?.click(); |
| 13 | await new Promise(r => setTimeout(r, 250)); |
| 14 | const prov = document.getElementById('cfg-provider'); |
| 15 | prov.value = 'custom'; prov.dispatchEvent(new Event('change', { bubbles: true })); |
| 16 | await new Promise(r => setTimeout(r, 200)); |
| 17 | const url = document.getElementById('cfg-base-url'); |
| 18 | url.value = c.baseUrl; url.dispatchEvent(new Event('input', { bubbles: true })); url.dispatchEvent(new Event('change', { bubbles: true })); |
| 19 | const key = document.getElementById('cfg-api-key'); |
| 20 | key.value = c.apiKey; key.dispatchEvent(new Event('input', { bubbles: true })); key.dispatchEvent(new Event('change', { bubbles: true })); |
| 21 | await new Promise(r => setTimeout(r, 1500)); // real /models fetch |
| 22 | const cus = document.getElementById('cfg-model-custom'); |
| 23 | if (cus) { cus.style.display=''; cus.value = c.model; cus.dispatchEvent(new Event('input', { bubbles: true })); } |
| 24 | const sel = document.getElementById('cfg-model'); |
| 25 | if (sel && [...sel.options].some(o=>o.value===c.model)) { sel.value=c.model; sel.dispatchEvent(new Event('change',{bubbles:true})); } |
| 26 | document.getElementById('byok-save')?.click(); |
| 27 | }, { baseUrl: cfg.baseUrl, apiKey: cfg.apiKey, model: MODEL }); |
| 28 | await s.page.waitForTimeout(1500); |
| 29 | |
| 30 | const ready = await s.page.evaluate(() => { try { const j=JSON.parse(localStorage.getItem('daimond-byok')||'{}'); return {model:j.model, hasKey:!!j.apiKey}; } catch { return null; } }); |
| 31 | console.log('connected:', JSON.stringify(ready)); |
| 32 | |
| 33 | const t0 = Date.now(); |
| 34 | const out = await chat(s, 'Use the file_write tool to create hello.txt with exactly this content: Daimond works. Then say you are done.', { timeout: 90000 }); |
| 35 | console.log('elapsed:', ((Date.now()-t0)/1000).toFixed(1)+'s'); |
| 36 | console.log('--- transcript tail ---\n' + out.slice(-400)); |
| 37 | |
| 38 | const wrote = await s.page.evaluate(async () => { |
| 39 | try { const root = await navigator.storage.getDirectory(); const fh = await root.getFileHandle('hello.txt'); return await (await fh.getFile()).text(); } |
| 40 | catch (e) { return '(no file: '+e+')'; } |
| 41 | }); |
| 42 | const spend = await s.page.evaluate(() => { try { return JSON.parse(localStorage.getItem('daimond-ledger')||'[]').reduce((a,e)=>a+(e.u||0),0); } catch { return 0; } }); |
| 43 | console.log('hello.txt on disk:', JSON.stringify(wrote)); |
| 44 | console.log('spend this run: $' + spend.toFixed(4)); |
| 45 | console.log('REAL MODEL DROVE A TOOL CALL:', /Daimond works/.test(wrote)); |
| 46 | console.log('errors:', errors(s)); |
| 47 | await s.close(); |