import { outboundFetch } from '../server/network.js'; import { mkdir, writeFile, rename } from 'node:fs/promises'; import { scrapeSite } from './importer.js'; try { const site = await scrapeSite(process.env.AG_MOTORS_URL || 'https://agmotors.at', { fetchImpl: outboundFetch }); const directory = new URL('../data/', import.meta.url); await mkdir(directory, { recursive: true }); const output = new URL('site.json', directory); const temporary = new URL('site.json.tmp', directory); await writeFile(temporary, `${JSON.stringify(site, null, 2)}\n`); await rename(temporary, output); // Plain-text source pack can also be reviewed and imported into Vocal Bridge. await writeFile(new URL('vocalbridge-knowledge.txt', directory), `AG Motors website snapshot — ${site.fetchedAt}\nPrices and availability must be confirmed directly.\n\n${site.pages.map(p => `SOURCE: ${p.url}\nTITLE: ${p.title}\n${p.text}`).join('\n\n---\n\n')}`); console.log(`Imported ${site.pages.length} public AG Motors pages. Restart the demo to load the snapshot.`); for (const warning of site.warnings) console.warn(warning); if (site.bounded) console.log('Crawl limit reached: this is a partial website snapshot, not complete inventory.'); } catch (error) { console.error(`Import failed; existing knowledge was preserved. ${error.message}`); process.exitCode = 1; }