Files
strata/apps/host/src/lib/artifacts.ts
T
Niko1221 0b3299a019 apps/host: the owner's UI and the Node App Host
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.
2026-10-15 10:24:09 +02:00

30 lines
2.4 KiB
TypeScript

export interface PreviewArtifact { id: string; kind: 'website' | 'markdown' | 'pdf' | 'image' | 'code' | 'table'; title: string; url?: string; content?: string; demo?: boolean; }
export const PREVIEW_EXAMPLES: PreviewArtifact[] = [
{ id:'sample-website', kind:'website', title:'Fieldnotes — website', url:'/examples/fieldnotes.html', demo:true },
{ id:'sample-markdown', kind:'markdown', title:'project-brief.md', url:'/examples/project-brief.md', demo:true },
{ id:'sample-image', kind:'image', title:'fieldnotes-cover.svg', url:'/examples/fieldnotes-cover.svg', demo:true },
{ id:'sample-code', kind:'code', title:'note-card.ts', url:'/examples/note-card.ts', demo:true },
{ id:'sample-table', kind:'table', title:'release-plan.csv', url:'/examples/release-plan.csv', demo:true },
{ id:'sample-pdf', kind:'pdf', title:'project-brief.pdf', url:'/examples/project-brief.pdf', demo:true },
];
export function safePreviewUrl(value: string) {
try { const u = new URL(value, location.origin); return ['http:','https:','blob:'].includes(u.protocol) ? u.href : null; }
catch { return null; }
}
export function artifactFromUrl(url: string): PreviewArtifact | null {
const safe = safePreviewUrl(url); if (!safe) return null;
const path = new URL(safe).pathname;
const kind = /\.pdf$/i.test(path) ? 'pdf' : /\.(png|jpe?g|webp|gif|svg)$/i.test(path) ? 'image' : /\.csv$/i.test(path)?'table':/\.(tsx?|jsx?|mts|cts|mjs|cjs|pyw?|json|css|rs|go|sh|bash|zsh|ya?ml|java|c|h|cpp|cc|cxx|hpp|cs|sql)$/i.test(path)?'code': /\.(md|mdx|markdown|txt)$/i.test(path) ? 'markdown' : 'website';
let filename = path.split('/').at(-1) || 'Document';
try { filename = decodeURIComponent(filename); } catch { /* Keep malformed URL escapes readable. */ }
return { id:safe, kind, url:safe, title:kind === 'website' ? new URL(safe).hostname : filename };
}
export const artifactLabel=(kind:PreviewArtifact['kind'])=>({website:'Website',markdown:'Markdown',pdf:'PDF',image:'Image',code:'Code',table:'Table'}[kind]);
export function artifactFilename(a:PreviewArtifact) {
if(a.url&&!a.url.startsWith('blob:')){try{const u=new URL(a.url,location.origin);const file=decodeURIComponent(u.pathname.split('/').filter(Boolean).at(-1)??'');return /\.[a-z0-9]{1,8}$/i.test(file)?file:a.kind==='website'?u.hostname:a.title;}catch{/* Use the supplied title. */}}
return a.title;
}
export const artifactIcon=(a:PreviewArtifact)=>a.kind==='website'?'link' as const:a.kind==='image'?'image' as const:'file' as const;