openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
71 lines (70 loc) • 2.95 kB
JavaScript
import { r as asNullableRecord } from "../../record-coerce-CVPuDqcc.mjs";
import "../../runtime-doctor-migrations-YTlcIEpR.mjs";
import { i as normalizeHistoricalWebhookConfig, n as legacyConfigRules, r as normalizeCompatibilityConfig, t as historicalWebhookListener } from "../../doctor-contract-BLPeSdfU.mjs";
//#region extensions/telegram/doctor-contract-api.ts
const offsetNamespace = "telegram.update-offsets";
function* legacyOffsets(e) {
const t = e.readPluginStateEntriesInKeyRange;
if (!t) throw new Error("Update OpenClaw before inspecting Telegram SQLite offsets, then run openclaw doctor --fix.");
let n;
while (true) {
const e = t(offsetNamespace, {
prefix: "",
after: n,
limit: 512
});
const r = e.flatMap((e) => {
const t = asNullableRecord(e.value);
if (!t || t.version !== 1 && t.version !== 2) return [];
const n = t.lastUpdateId;
if (n !== null && !(typeof n === "number" && Number.isSafeInteger(n) && n >= 0) || t.version === 2 && t.botId !== null && typeof t.botId !== "string") throw new Error(`Telegram offset for account "${e.key}" is malformed; restore its known-good state backup, then run openclaw doctor --fix.`);
return [{
entry: e,
value: {
...t,
version: 3,
botId: t.version === 1 ? null : t.botId,
tokenFingerprint: null
}
}];
});
if (r.length) yield r;
const i = e.at(-1);
if (e.length < 512 || !i) return;
n = i.key;
}
}
async function loadTelegramIngressSpoolMigration() {
return (await import("../../telegram-ingress-spool-migration-tedtSWa1.mjs")).telegramIngressSpoolMigration;
}
const stateMigrations = [{
id: "telegram-update-offsets",
label: "Telegram SQLite update offsets",
phase: "after-session-repair",
collectBackupResources: () => [],
detectLegacyState({ context: e }) {
return legacyOffsets(e).next().done ? null : { preview: ["Normalize Telegram SQLite update offsets before account startup."] };
},
async migrateLegacyState({ context: e }) {
const t = {
changes: [],
warnings: []
};
const n = [...legacyOffsets(e)];
for (const r of n) {
if (!e.repairPluginStateEntries) throw new Error("Update OpenClaw to repair Telegram SQLite offsets.");
const n = await e.repairPluginStateEntries(offsetNamespace, r);
t.changes.push(...n.changes, `Normalized ${r.length} Telegram SQLite update offsets.`);
t.warnings.push(...n.warnings);
}
return t;
}
}, {
id: "telegram-json-ingress-spool",
label: "Telegram JSON ingress spool",
collectBackupResources: async (e) => (await loadTelegramIngressSpoolMigration()).collectBackupResources(e),
detectLegacyState: async (e) => (await loadTelegramIngressSpoolMigration()).detectLegacyState(e),
migrateLegacyState: async (e) => (await loadTelegramIngressSpoolMigration()).migrateLegacyState(e)
}];
//#endregion
export { historicalWebhookListener, legacyConfigRules, normalizeCompatibilityConfig, normalizeHistoricalWebhookConfig, stateMigrations };