openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
41 lines (40 loc) • 1.35 kB
JavaScript
import { c as normalizeOptionalString } from "./string-coerce-mnp54Vah.js";
//#region src/auto-reply/reply/reply-reference.ts
/** Plans reply/thread references for multi-payload channel sends. */
/** Returns true for modes that use a reply reference only before the first send. */
function isSingleUseReplyToMode(mode) {
return mode === "first" || mode === "batched";
}
/** Creates a planner that tracks whether a reply reference has already been consumed. */
function createReplyReferencePlanner(options) {
let hasReplied = options.hasReplied ?? false;
const allowReference = options.allowReference !== false;
const existingId = normalizeOptionalString(options.existingId);
const startId = normalizeOptionalString(options.startId);
const resolve = () => {
if (!allowReference) return;
if (options.replyToMode === "off") return;
const id = existingId ?? startId;
if (!id) return;
if (options.replyToMode === "all") return id;
if (isSingleUseReplyToMode(options.replyToMode) && hasReplied) return;
return id;
};
const use = () => {
const id = resolve();
if (!id) return;
hasReplied = true;
return id;
};
const markSent = () => {
hasReplied = true;
};
return {
peek: resolve,
use,
markSent,
hasReplied: () => hasReplied
};
}
//#endregion
export { isSingleUseReplyToMode as n, createReplyReferencePlanner as t };