| 83 | let stripQqImageAttachmentMarkers = (text) => String(text || "").trim(); |
| 84 | |
| 85 | async function importOptionalModule(label, candidates) { |
| 86 | for (const candidate of candidates.filter(Boolean)) { |
| 87 | try { |
| 88 | const specifier = candidate.startsWith("file:") || candidate.startsWith(".") |
| 89 | ? candidate |
| 90 | : pathToFileURL(candidate).href; |
| 91 | return await import(specifier); |
| 92 | } catch (error) { |
| 93 | if (error?.code && !["ERR_MODULE_NOT_FOUND", "ERR_INVALID_FILE_URL_PATH", "ERR_UNSUPPORTED_ESM_URL_SCHEME"].includes(error.code)) { |
| 94 | console.warn(`${label} failed to load from ${candidate}: ${error.message}`); |
| 95 | } |
| 96 | } |
| 97 | } |
| 98 | console.warn(`${label} not installed; continuing with built-in fallback.`); |
| 99 | return null; |
| 100 | } |
| 101 | |
| 102 | const unifiedMemoryModule = await importOptionalModule("unified-memory", [ |
| 103 | process.env.CODEX_REMOTE_CONTACT_UNIFIED_MEMORY_MODULE, |