UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

135 lines (134 loc) • 6.03 kB
import { a as asOptionalRecord } from "./record-coerce-CVPuDqcc.mjs"; import { t as formatErrorMessage } from "./errors-BKzCeTYb.mjs"; import { a as getOpenClawDatabaseMaintenanceScope } from "./openclaw-state-maintenance-context-D6i7Zdhn.mjs"; import { i as executeSqliteQuerySync, s as getNodeSqliteKysely } from "./kysely-sync-YJo2lmGV.mjs"; import "./openclaw-state-db-async-lifecycle-CH8q4Sdl.mjs"; import { o as closeOpenClawAgentDatabaseByPathAsync } from "./openclaw-agent-db-lifecycle-DqaZZnYh.mjs"; import { n as withOpenClawAgentDatabaseReadOnly } from "./openclaw-agent-db-readonly-COYfV-vn.mjs"; import { r as isOpenClawAgentDatabaseOpen, s as runOpenClawAgentWriteTransaction } from "./openclaw-agent-db-CwXW4hGa.mjs"; import { t as escapeHtml } from "./html-escape-BB_nPhWX.mjs"; import { r as listExistingAgentDatabaseTargets, u as resolveTargetSqliteOptions } from "./session-sqlite-migration-readers-DbmEQzSW.mjs"; import { i as parseManifest, n as createBoardWidgetContentFields, u as serializeManifest } from "./sqlite-board-codec-C7odCXMU.mjs"; import { t as backupDoctorMigrationDatabases } from "./doctor-migration-backup-DwSvhlqi.mjs"; import { randomBytes, randomUUID } from "node:crypto"; //#region src/commands/doctor-a2ui-widgets.ts function readLegacyRecord(e) { if (e === null) return; try { return asOptionalRecord(JSON.parse(e)); } catch { return; } } function listLegacyWidgets(e) { const t = getNodeSqliteKysely(e); return executeSqliteQuerySync(e, t.selectFrom("board_widgets").select([ "session_key", "name", "content_kind", "revision", "descriptor_json", "manifest" ])).rows.flatMap((e) => { const t = readLegacyRecord(e.descriptor_json); const n = readLegacyRecord(e.manifest); const r = t?.pluginKind === "canvas:a2ui" || n?.registeredContentKind === "a2ui"; return r || n?.contentOwner === "registered" || e.content_kind === "plugin" && typeof t?.source === "string" ? [{ ...e, descriptor: t, metadata: n, retire: r }] : []; }); } function createRetiredWidgetPreview(e) { const t = typeof e.descriptor?.pluginKind === "string" ? e.descriptor.pluginKind : "unknown"; const n = typeof e.descriptor?.source === "string" ? e.descriptor.source : e.descriptor_json ?? ""; return `<article><h1>Retired ${escapeHtml(t)} widget</h1> <p>This widget renderer was removed. Its saved source is preserved below and can be recreated as an HTML widget.</p> <pre style="white-space:pre-wrap;overflow-wrap:anywhere">${escapeHtml(n)}</pre> <details><summary>Original widget data</summary> <h2>Descriptor</h2><pre style="white-space:pre-wrap;overflow-wrap:anywhere">${escapeHtml(e.descriptor_json ?? "")}</pre> <h2>Manifest</h2><pre style="white-space:pre-wrap;overflow-wrap:anywhere">${escapeHtml(e.manifest)}</pre> </details></article>`; } /** Retire A2UI and preserve other removed renderers as inert HTML before canonical board reads. */ async function retireDoctorA2uiWidgets(e) { const t = { changes: [], warnings: [], warningDisposition: "recoverable" }; const n = listExistingAgentDatabaseTargets(e.cfg, e.env); const r = n.filter((n) => { try { const t = withOpenClawAgentDatabaseReadOnly((e) => listLegacyWidgets(e.db).length, resolveTargetSqliteOptions(n, e.env)); return t.found && t.value > 0; } catch (e) { t.warnings.push(`Could not inspect retired board widgets in agent ${n.agentId}: ${formatErrorMessage(e)}. Run openclaw doctor --fix after resolving the database warning.`); return false; } }); if (r.length === 0) return t; const i = getOpenClawDatabaseMaintenanceScope(); if (!i?.ownsSchemaMaintenance) throw new Error("A2UI widget retirement requires Doctor maintenance ownership."); i.assertAdmission(); const a = await backupDoctorMigrationDatabases({ env: e.env, pendingDatabasePaths: r.map((e) => e.sqlitePath), databasePaths: n.map((e) => e.sqlitePath), check: e.integrityCheck, repair: { key: `retire-a2ui-widgets:${randomUUID()}` } }); t.changes.push(...a.changes); t.warnings.push(...a.warnings); i.assertAdmission(); let o = 0; let s = 0; for (const t of r) { const n = isOpenClawAgentDatabaseOpen(t.sqlitePath); try { const n = runOpenClawAgentWriteTransaction((e) => { i.assertAdmission(); const t = listLegacyWidgets(e.db); const n = getNodeSqliteKysely(e.db); for (const r of t) { if (r.retire) { executeSqliteQuerySync(e.db, n.deleteFrom("board_widgets").where("session_key", "=", r.session_key).where("name", "=", r.name)); continue; } const t = parseManifest(JSON.stringify({ ...r.metadata, contentOwner: "html", netOrigins: void 0, tools: void 0 })); const i = createBoardWidgetContentFields({ sessionKey: r.session_key, name: r.name, content: { kind: "html", html: createRetiredWidgetPreview(r) } }, t, r.revision + 1, "none", randomBytes(16).toString("hex"), Date.now()); i.manifest = serializeManifest({ contentOwner: "html" }, void 0, "none", void 0, t, t.nameIdentity?.kind !== "invalid" ? t.nameIdentity : void 0); executeSqliteQuerySync(e.db, n.updateTable("board_widgets").set(i).where("session_key", "=", r.session_key).where("name", "=", r.name)); } return { removed: t.filter((e) => e.retire).length, converted: t.filter((e) => !e.retire).length }; }, resolveTargetSqliteOptions(t, e.env), { operationLabel: "doctor.retire-a2ui-widgets" }); o += n.removed; s += n.converted; } finally { if (!n) await closeOpenClawAgentDatabaseByPathAsync(t.sqlitePath); } i.assertAdmission(); } if (o > 0) t.warnings.push(`Deleted ${o} stored widget(s) after backup. A2UI widgets were retired and can be recreated as HTML widgets.`); if (s > 0) t.warnings.push(`Converted ${s} other retired widget(s) to inert HTML source previews after backup. Original source and widget metadata were preserved; previous capabilities were removed.`); return t; } //#endregion export { retireDoctorA2uiWidgets };