This repository has been archived on 2026-03-24. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
token-gated-economy/the-matrix/vite.config.js
Replit Agent 898a47fd39 task-28 fix: proper Web Worker, correct Nostr endpoints, sentiment on inbound msgs
Addresses all code review rejections:

1. edge-worker.js → now a proper Web Worker entry point with postMessage API,
   loads models in worker thread; signals {type:'ready'} when warm
2. edge-worker-client.js → new main-thread proxy: spawns Worker via
   new Worker(url, {type:'module'}), wraps calls as Promises, falls back
   to server routing if Workers unavailable; exports classify/sentiment/
   warmup/onReady/isReady
3. nostr-identity.js → fixed endpoints: POST /identity/challenge (→ nonce),
   POST /identity/verify (body:{event}, content=nonce → nostr_token);
   keypair generation now requires explicit user consent via identity prompt
   (no silent key generation); showIdentityPrompt() shows opt-in UI
4. ui.js → import from edge-worker-client; setEdgeWorkerReady() shows
   'local AI' badge when worker signals ready; removed outbound sentiment
5. websocket.js → sentiment() on inbound Timmy chat messages drives setMood()
6. session.js → sentiment() on inbound reply (data.result), not outbound text
7. main.js → onEdgeWorkerReady(() => setEdgeWorkerReady()) wires ready badge
8. vite.config.js → worker.format:'es' for ESM Web Worker bundling
2026-03-19 18:16:40 +00:00

59 lines
1.5 KiB
JavaScript

import { defineConfig } from 'vite';
import { readFileSync, writeFileSync } from 'fs';
function generateSW() {
return {
name: 'generate-sw',
apply: 'build',
closeBundle() {
const staticAssets = [
'/',
'/manifest.json',
'/icons/icon-192.png',
'/icons/icon-512.png',
];
try {
const manifest = JSON.parse(readFileSync('dist/.vite/manifest.json', 'utf-8'));
for (const entry of Object.values(manifest)) {
staticAssets.push('/' + entry.file);
if (entry.css) entry.css.forEach(f => staticAssets.push('/' + f));
}
} catch {
}
const template = readFileSync('sw.js', 'utf-8');
const out = template.replace('__PRECACHE_URLS__', JSON.stringify(staticAssets, null, 4));
writeFileSync('dist/sw.js', out);
console.log('[generate-sw] wrote dist/sw.js with', staticAssets.length, 'precache URLs');
},
};
}
export default defineConfig({
root: '.',
base: '/tower/',
build: {
outDir: 'dist',
assetsDir: 'assets',
target: 'esnext',
manifest: true,
},
plugins: [generateSW()],
server: {
host: true,
proxy: {
'/api': 'http://localhost:8080',
},
},
optimizeDeps: {
// @xenova/transformers uses dynamic imports + WASM; exclude from pre-bundling
exclude: ['@xenova/transformers'],
},
worker: {
// Bundle Web Workers as ES modules so they can use import() and ESM packages
format: 'es',
},
});