The UI source from the 14 October handoff (src/, public/, index.html, vite and tsconfig, tests, audit-fixes, design docs) and the App Host (server/*.mjs): model import and monitor routes, API-provider catalog and streaming (OpenAI chat, OpenAI Responses, the Messages API), serving, tunnel, tasks, plus the host routes for Time-skip (server/timeskip.mjs) and the tuning plan/reports. src/lib/time-skip.ts renders a real job's own record. The UI design is unchanged. The rebuild routed #/tuning to a new TunePanel; that is reverted: src/screens/ModelRun.tsx and src/main.tsx are the handoff's again (#/tuning goes where the handoff sends it), and src/components/TunePanel.tsx and src/styles/tuning.css, which only that route used, are not carried over. Left out of git on purpose: dist/ (build output), node_modules, and docs/evidence + docs/checkpoints (170 MB of screenshots, kept in StrataSplit\evidence-archive). From the owner's rebuild branch strata/rebuild-2026-10.
31 lines
2.2 KiB
JavaScript
31 lines
2.2 KiB
JavaScript
import { execFile } from 'node:child_process';
|
|
import { promisify } from 'node:util';
|
|
import { mkdir, mkdtemp, realpath, stat, writeFile } from 'node:fs/promises';
|
|
import { basename, dirname, extname, join, resolve, sep } from 'node:path';
|
|
const run=promisify(execFile);
|
|
const extensions=new Set(['.md','.txt','.pdf','.html','.htm','.png','.jpg','.jpeg','.webp','.gif','.svg','.csv','.ts','.tsx','.js','.jsx','.py','.json','.css','.rs','.go','.sh','.mp4','.webm']);
|
|
export async function openArtifact(body,{examplesDir,previewsDir,platform=process.platform,launch=run}) {
|
|
if(!['open','reveal'].includes(body.action))throw new Error('Choose Open or Show in file explorer.');
|
|
let file;
|
|
if(typeof body.path==='string') {
|
|
// Only public example assets can be addressed by path. Never accept host paths.
|
|
if(!body.path.startsWith('/examples/'))throw new Error('This file is not a local preview.');
|
|
const base=await realpath(examplesDir);
|
|
file=await realpath(resolve(base,body.path.slice('/examples/'.length)));
|
|
if(!file.startsWith(base+sep)||!(await stat(file)).isFile())throw new Error('This file is not a local preview.');
|
|
} else {
|
|
const name=basename(String(body.name??'document.txt')).replace(/[^\w. -]/g,'_').slice(0,120);
|
|
if(!extensions.has(extname(name).toLowerCase()))throw new Error('This file type cannot be opened from a preview.');
|
|
if(typeof body.content!=='string'&&typeof body.base64!=='string')throw new Error('No file content was supplied.');
|
|
const bytes=typeof body.base64==='string'?Buffer.from(body.base64,'base64'):Buffer.from(body.content,'utf8');
|
|
if(bytes.length>20*1024*1024)throw new Error('Choose a file smaller than 20 MB.');
|
|
await mkdir(previewsDir,{recursive:true});const folder=await mkdtemp(join(previewsDir,'preview-'));
|
|
file=join(folder,name);await writeFile(file,bytes,{flag:'wx',mode:0o600});
|
|
}
|
|
if(!extensions.has(extname(file).toLowerCase()))throw new Error('This file type cannot be opened from a preview.');
|
|
if(platform==='darwin')await launch('open',body.action==='reveal'?['-R',file]:[file]);
|
|
else if(platform==='win32')await launch('explorer.exe',body.action==='reveal'?[`/select,${file}`]:[file]);
|
|
else await launch('xdg-open',[body.action==='reveal'?dirname(file):file]);
|
|
return {ok:true};
|
|
}
|