mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-11 04:54:33 +00:00
feat(cron): enhance legacy delivery handling in job patches
- Introduced logic to map legacy payload delivery updates onto the delivery object for `agentTurn` jobs, ensuring backward compatibility with legacy clients. - Added tests to validate the correct application of legacy delivery settings in job patches, improving reliability in job configuration. - Refactored delivery handling functions to streamline the merging of legacy delivery fields into the current job structure. This update enhances the flexibility of delivery configurations, ensuring that legacy settings are properly handled in the context of new job patches.
This commit is contained in:
committed by
Peter Steinberger
parent
246896d64b
commit
6fb8d8850e
@@ -39,6 +39,69 @@ function buildDeliveryFromLegacyPayload(payload: Record<string, unknown>) {
|
||||
return next;
|
||||
}
|
||||
|
||||
function buildDeliveryPatchFromLegacyPayload(payload: Record<string, unknown>) {
|
||||
const deliver = payload.deliver;
|
||||
const channelRaw =
|
||||
typeof payload.channel === "string" ? payload.channel.trim().toLowerCase() : "";
|
||||
const toRaw = typeof payload.to === "string" ? payload.to.trim() : "";
|
||||
const next: Record<string, unknown> = {};
|
||||
let hasPatch = false;
|
||||
|
||||
if (deliver === false) {
|
||||
next.mode = "none";
|
||||
hasPatch = true;
|
||||
} else if (deliver === true || toRaw) {
|
||||
next.mode = "announce";
|
||||
hasPatch = true;
|
||||
}
|
||||
if (channelRaw) {
|
||||
next.channel = channelRaw;
|
||||
hasPatch = true;
|
||||
}
|
||||
if (toRaw) {
|
||||
next.to = toRaw;
|
||||
hasPatch = true;
|
||||
}
|
||||
if (typeof payload.bestEffortDeliver === "boolean") {
|
||||
next.bestEffort = payload.bestEffortDeliver;
|
||||
hasPatch = true;
|
||||
}
|
||||
|
||||
return hasPatch ? next : null;
|
||||
}
|
||||
|
||||
function mergeLegacyDeliveryInto(
|
||||
delivery: Record<string, unknown>,
|
||||
payload: Record<string, unknown>,
|
||||
) {
|
||||
const patch = buildDeliveryPatchFromLegacyPayload(payload);
|
||||
if (!patch) {
|
||||
return { delivery, mutated: false };
|
||||
}
|
||||
|
||||
const next = { ...delivery };
|
||||
let mutated = false;
|
||||
|
||||
if ("mode" in patch && patch.mode !== next.mode) {
|
||||
next.mode = patch.mode;
|
||||
mutated = true;
|
||||
}
|
||||
if ("channel" in patch && patch.channel !== next.channel) {
|
||||
next.channel = patch.channel;
|
||||
mutated = true;
|
||||
}
|
||||
if ("to" in patch && patch.to !== next.to) {
|
||||
next.to = patch.to;
|
||||
mutated = true;
|
||||
}
|
||||
if ("bestEffort" in patch && patch.bestEffort !== next.bestEffort) {
|
||||
next.bestEffort = patch.bestEffort;
|
||||
mutated = true;
|
||||
}
|
||||
|
||||
return { delivery: next, mutated };
|
||||
}
|
||||
|
||||
function stripLegacyDeliveryFields(payload: Record<string, unknown>) {
|
||||
if ("deliver" in payload) {
|
||||
delete payload.deliver;
|
||||
@@ -180,6 +243,16 @@ export async function ensureLoaded(state: CronServiceState) {
|
||||
mutated = true;
|
||||
}
|
||||
if (payloadRecord && hasLegacyDelivery) {
|
||||
if (hasDelivery) {
|
||||
const merged = mergeLegacyDeliveryInto(
|
||||
delivery as Record<string, unknown>,
|
||||
payloadRecord,
|
||||
);
|
||||
if (merged.mutated) {
|
||||
raw.delivery = merged.delivery;
|
||||
mutated = true;
|
||||
}
|
||||
}
|
||||
stripLegacyDeliveryFields(payloadRecord);
|
||||
mutated = true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user