feat(ui): add browser console served by the daemon
Introduce a minimal operations console reachable on a dedicated UI port (default 8081), kept separate from the OpenAI-compatible API port. - ts_web/ holds the SPA shell (index.html, app.css, vanilla app.js) with sidebar navigation for all views from readme.ui.md and a working Overview page backed by a new /_ui/overview JSON endpoint. - scripts/bundle-ui.ts walks ts_web/ and emits ts_bundled/bundle.ts, a single generated module exporting every asset as base64. Mirrors the @stack.gallery/registry pattern so deno compile binaries embed the entire UI with no external filesystem dependency at runtime. - ts/ui/server.ts (UiServer) serves assets from either the bundled map (default, prod) or directly from ts_web/ on disk (dev). The source is chosen per-config and can be overridden by UI_ASSET_SOURCE=disk|bundle. SPA fallback routes unknown extensionless paths to index.html. - IModelGridConfig.ui block with enabled/port/host/assetSource defaults; config init writes the block, the normalizer fills in defaults on load, and the daemon starts/stops the UI server alongside the API. - deno.json gains a bundle:ui task; compile:all now depends on it so released binaries always contain an up-to-date bundle. dev task sets UI_ASSET_SOURCE=disk for hot edits. - ts_bundled/ is gitignored (generated on build). - test/ui-server.smoke.ts exercises bundle and disk modes end to end (index, app.js, SPA fallback, /_ui/overview, 404).
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
#!/usr/bin/env -S deno run --allow-read --allow-write
|
||||
|
||||
/**
|
||||
* bundle-ui.ts
|
||||
*
|
||||
* Walks `ts_web/` and emits `ts_bundled/bundle.ts`, a single TypeScript
|
||||
* module that exports every UI asset as base64 in order. The daemon's
|
||||
* UI server imports this module at runtime to serve the console without
|
||||
* any external filesystem dependency — the entire browser app ends up
|
||||
* embedded in the `deno compile` binary.
|
||||
*
|
||||
* The output shape matches the `@stack.gallery/registry` convention so
|
||||
* a consumer can loop `files` as `{ path, contentBase64 }` entries.
|
||||
*/
|
||||
|
||||
import { walk } from 'jsr:@std/fs@^1.0.0/walk';
|
||||
import { fromFileUrl, join, relative } from 'jsr:@std/path@^1.0.0';
|
||||
|
||||
const here = fromFileUrl(new URL('./', import.meta.url));
|
||||
const repoRoot = join(here, '..');
|
||||
const sourceDir = join(repoRoot, 'ts_web');
|
||||
const outDir = join(repoRoot, 'ts_bundled');
|
||||
const outFile = join(outDir, 'bundle.ts');
|
||||
|
||||
async function main(): Promise<void> {
|
||||
const entries: Array<{ path: string; contentBase64: string; size: number }> = [];
|
||||
|
||||
for await (
|
||||
const entry of walk(sourceDir, {
|
||||
includeDirs: false,
|
||||
includeSymlinks: false,
|
||||
})
|
||||
) {
|
||||
const rel = relative(sourceDir, entry.path).replaceAll('\\', '/');
|
||||
const bytes = await Deno.readFile(entry.path);
|
||||
entries.push({
|
||||
path: rel,
|
||||
contentBase64: encodeBase64(bytes),
|
||||
size: bytes.byteLength,
|
||||
});
|
||||
}
|
||||
|
||||
entries.sort((a, b) => a.path.localeCompare(b.path));
|
||||
|
||||
const generatedAt = new Date().toISOString();
|
||||
const totalBytes = entries.reduce((sum, e) => sum + e.size, 0);
|
||||
|
||||
const header = [
|
||||
'// AUTO-GENERATED — do not edit.',
|
||||
'// Regenerate with: deno task bundle:ui',
|
||||
`// Source: ts_web/ (${entries.length} files, ${totalBytes} bytes)`,
|
||||
`// Generated: ${generatedAt}`,
|
||||
'',
|
||||
'export interface IBundledFile {',
|
||||
' path: string;',
|
||||
' contentBase64: string;',
|
||||
'}',
|
||||
'',
|
||||
'export const files: IBundledFile[] = [',
|
||||
].join('\n');
|
||||
|
||||
const body = entries.map((e) =>
|
||||
` { path: ${JSON.stringify(e.path)}, contentBase64: ${JSON.stringify(e.contentBase64)} },`
|
||||
).join('\n');
|
||||
|
||||
const footer = '\n];\n';
|
||||
|
||||
await Deno.mkdir(outDir, { recursive: true });
|
||||
await Deno.writeTextFile(outFile, header + '\n' + body + footer);
|
||||
|
||||
console.log(
|
||||
`bundle-ui: wrote ${entries.length} file(s), ${totalBytes} bytes → ${
|
||||
relative(repoRoot, outFile)
|
||||
}`,
|
||||
);
|
||||
}
|
||||
|
||||
function encodeBase64(bytes: Uint8Array): string {
|
||||
let binary = '';
|
||||
for (let i = 0; i < bytes.length; i++) {
|
||||
binary += String.fromCharCode(bytes[i]);
|
||||
}
|
||||
return btoa(binary);
|
||||
}
|
||||
|
||||
if (import.meta.main) {
|
||||
await main();
|
||||
}
|
||||
Reference in New Issue
Block a user