scripts / sync-file-search.cjs
// Bundle the canonical file-search ingestion/storage code so the installed
// adapter does not depend on another plugin's private installation directory.
const { copyFileSync, existsSync, mkdirSync } = require('node:fs');
const { resolve, join } = require('node:path');
const source = resolve(__dirname, '../../../yuanjumay/file-search/src');
const target = resolve(__dirname, '../src/fileSearch');
const modules = ['json.ts', 'encoding.ts', 'documents.ts', 'store.ts', 'storageLocation.ts', 'receipts.ts', 'historyDocuments.ts', 'toolNames.ts'];
mkdirSync(target, { recursive: true });
for (const name of modules) {
if (existsSync(join(source, name))) copyFileSync(join(source, name), join(target, name));
else if (!existsSync(join(target, name))) throw new Error(`Missing bundled file-search module: ${name}`);
}
mkdirSync(join(target, 'web'), {recursive: true});
const webSource = resolve(__dirname, '../../../shared/web-documents');
const bundledWebSource = join(source, 'web');
for (const name of ['encoding.ts', 'html.ts']) {
const candidate = existsSync(join(webSource, name)) ? join(webSource, name) : join(bundledWebSource, name);
if (existsSync(candidate)) copyFileSync(candidate, join(target, 'web', name));
else if (!existsSync(join(target, 'web', name))) throw new Error(`Missing bundled HTML module: ${name}`);
}