| 88 | return c; |
| 89 | }; |
| 90 | async function run() { |
| 91 | console.log(ASC); |
| 92 | console.log('\n=== Migration Tool ===\n'); |
| 93 | const c = prg(); |
| 94 | if (!c.f || !c.k) { |
| 95 | console.error('[ERROR] Required: --from and --api-key'); |
| 96 | process.exit(1); |
| 97 | } |
| 98 | if (!['zep', 'mem0', 'supermemory'].includes(c.f)) { |
| 99 | console.error('[ERROR] Invalid provider. Use: zep, mem0, or supermemory'); |
| 100 | process.exit(1); |
| 101 | } |
| 102 | if (!fs.existsSync(c.o)) fs.mkdirSync(c.o, { recursive: true }); |
| 103 | console.log(`[CONFIG] Provider: ${c.f.toUpperCase()}`); |
| 104 | console.log(`[CONFIG] Batch Size: ${c.b}`); |
| 105 | console.log(`[CONFIG] Rate Limit: ${c.rl} req/s`); |
| 106 | console.log(`[CONFIG] Output: ${c.o}`); |
| 107 | const omUrl = |
| 108 | c.omu || process.env.OPENMEMORY_URL || process.env.OM_PORT |
| 109 | ? `http://localhost:${process.env.OM_PORT}` |
| 110 | : 'http://localhost:8080'; |
| 111 | const omKey = |
| 112 | c.omk || process.env.OPENMEMORY_API_KEY || process.env.OM_API_KEY || ''; |
| 113 | console.log(`[CONFIG] OpenMemory API: ${omUrl}`); |
| 114 | console.log(`[CONFIG] OpenMemory Auth: ${omKey ? 'Configured' : 'None'}\n`); |
| 115 | |
| 116 | // Pass resolved values to components |
| 117 | if (!c.omu) c.omu = omUrl; |
| 118 | if (!c.omk) c.omk = omKey; |
| 119 | |
| 120 | try { |
| 121 | const A = require(`./providers/${c.f}`), |
| 122 | a = new A(c); |
| 123 | console.log('[PHASE 1/4] Connecting to provider...'); |
| 124 | const s = await a.conn(); |
| 125 | console.log(`[SUCCESS] Connected to ${c.f.toUpperCase()}`); |
| 126 | if (s.ses !== undefined) console.log(`[STATS] Sessions: ${s.ses}`); |
| 127 | if (s.m !== undefined) console.log(`[STATS] Memories: ${s.m}`); |
| 128 | if (s.d !== undefined) console.log(`[STATS] Documents: ${s.d}\n`); |
| 129 | console.log('[PHASE 2/4] Fetching data from provider...'); |
| 130 | const e = await a.exp(); |
| 131 | console.log(`[SUCCESS] Data exported to: ${e}\n`); |
| 132 | console.log('[PHASE 3/4] Importing to OpenMemory HSG...'); |
| 133 | const I = require('./imp'), |
| 134 | im = new I(c), |
| 135 | st = await im.imp(e); |
| 136 | console.log('\n[SUCCESS] Import completed'); |
| 137 | console.log(`[RESULT] Memories imported: ${st.m}`); |
| 138 | if (st.f > 0) console.log(`[RESULT] Failed records: ${st.f}`); |
| 139 | console.log(`[RESULT] Duration: ${st.d}s\n`); |
| 140 | if (c.v) { |
| 141 | console.log('[PHASE 4/4] Running verification...'); |
| 142 | const V = require('./ver'), |
| 143 | vr = new V(c), |
| 144 | vf = await vr.ver(st); |
| 145 | if (vf.ok) { |
| 146 | console.log('[SUCCESS] Verification passed'); |
| 147 | } else { |