diff --git a/packages/polymech/src/model/component.ts b/packages/polymech/src/model/component.ts index 94e28bd..56654ce 100644 --- a/packages/polymech/src/model/component.ts +++ b/packages/polymech/src/model/component.ts @@ -245,6 +245,18 @@ export function loader(branch: string): Loader { generateDigest } as any) + // Emit to LLM Registry + try { + const { LLMRegistry } = await import('../registry.js') + LLMRegistry.add("Products and Components", { + title: data.title, + url: `/products/${data.slug}`, + description: storeItem.data.description || "" + }) + } catch (e) { + // console.error("Failed to emit to LLM Registry", e) + } + storeItem.data['config'] = JSON.stringify({ ...storeItem.data }, null, 2) diff --git a/packages/polymech/src/registry.ts b/packages/polymech/src/registry.ts index 94069c3..aba19ce 100644 --- a/packages/polymech/src/registry.ts +++ b/packages/polymech/src/registry.ts @@ -152,3 +152,62 @@ class PolymechRegistry { export const PolymechInstance = PolymechRegistry.getInstance(); export type { PolymechConfig }; + +import * as fs from 'node:fs'; +import * as path from 'node:path'; + +// LLM Registry for aggregating content +export interface LLMItem { + title: string; + url: string; + description: string; +} + +const getCachePath = () => { + const cacheDir = path.join(process.cwd(), 'node_modules', '.cache'); + if (!fs.existsSync(cacheDir)) { + fs.mkdirSync(cacheDir, { recursive: true }); + } + return path.join(cacheDir, 'llms_registry.json'); +} + +export class LLMRegistry { + static add(section: string, item: LLMItem) { + const file = getCachePath(); + let data: Record = {}; + + try { + if (fs.existsSync(file)) { + data = JSON.parse(fs.readFileSync(file, 'utf-8')); + } + } catch (e) { + // ignore errors + } + + if (!data[section]) { + data[section] = []; + } + + if (!data[section].some(i => i.url === item.url)) { + data[section].push(item); + fs.writeFileSync(file, JSON.stringify(data, null, 2)); + } + } + + static getAll(): Map { + const file = getCachePath(); + const map = new Map(); + try { + if (fs.existsSync(file)) { + const data = JSON.parse(fs.readFileSync(file, 'utf-8')); + for (const [key, value] of Object.entries(data)) { + map.set(key, value as LLMItem[]); + } + } + } catch (e) { + // ignore + } + return map; + } +} +