mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 01:51:24 +00:00
refactor(cron): share legacy delivery helpers
This commit is contained in:
@@ -1,44 +1,17 @@
|
||||
import fs from "node:fs";
|
||||
import type { CronJob } from "../types.js";
|
||||
import type { CronServiceState } from "./state.js";
|
||||
import {
|
||||
buildDeliveryFromLegacyPayload,
|
||||
hasLegacyDeliveryHints,
|
||||
stripLegacyDeliveryFields,
|
||||
} from "../legacy-delivery.js";
|
||||
import { parseAbsoluteTimeMs } from "../parse.js";
|
||||
import { migrateLegacyCronPayload } from "../payload-migration.js";
|
||||
import { loadCronStore, saveCronStore } from "../store.js";
|
||||
import { recomputeNextRuns } from "./jobs.js";
|
||||
import { inferLegacyName, normalizeOptionalText } from "./normalize.js";
|
||||
|
||||
function hasLegacyDeliveryHints(payload: Record<string, unknown>) {
|
||||
if (typeof payload.deliver === "boolean") {
|
||||
return true;
|
||||
}
|
||||
if (typeof payload.bestEffortDeliver === "boolean") {
|
||||
return true;
|
||||
}
|
||||
if (typeof payload.to === "string" && payload.to.trim()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function buildDeliveryFromLegacyPayload(payload: Record<string, unknown>) {
|
||||
const deliver = payload.deliver;
|
||||
const mode = deliver === false ? "none" : "announce";
|
||||
const channelRaw =
|
||||
typeof payload.channel === "string" ? payload.channel.trim().toLowerCase() : "";
|
||||
const toRaw = typeof payload.to === "string" ? payload.to.trim() : "";
|
||||
const next: Record<string, unknown> = { mode };
|
||||
if (channelRaw) {
|
||||
next.channel = channelRaw;
|
||||
}
|
||||
if (toRaw) {
|
||||
next.to = toRaw;
|
||||
}
|
||||
if (typeof payload.bestEffortDeliver === "boolean") {
|
||||
next.bestEffort = payload.bestEffortDeliver;
|
||||
}
|
||||
return next;
|
||||
}
|
||||
|
||||
function buildDeliveryPatchFromLegacyPayload(payload: Record<string, unknown>) {
|
||||
const deliver = payload.deliver;
|
||||
const channelRaw =
|
||||
@@ -102,21 +75,6 @@ function mergeLegacyDeliveryInto(
|
||||
return { delivery: next, mutated };
|
||||
}
|
||||
|
||||
function stripLegacyDeliveryFields(payload: Record<string, unknown>) {
|
||||
if ("deliver" in payload) {
|
||||
delete payload.deliver;
|
||||
}
|
||||
if ("channel" in payload) {
|
||||
delete payload.channel;
|
||||
}
|
||||
if ("to" in payload) {
|
||||
delete payload.to;
|
||||
}
|
||||
if ("bestEffortDeliver" in payload) {
|
||||
delete payload.bestEffortDeliver;
|
||||
}
|
||||
}
|
||||
|
||||
function normalizePayloadKind(payload: Record<string, unknown>) {
|
||||
const raw = typeof payload.kind === "string" ? payload.kind.trim().toLowerCase() : "";
|
||||
if (raw === "agentturn") {
|
||||
|
||||
Reference in New Issue
Block a user