refactor(reply): clarify explicit reply tags in off mode (#16189)

* refactor(reply): clarify explicit reply tags in off mode

* fix(plugin-sdk): alias account-id subpath for extensions
This commit is contained in:
Peter Steinberger
2026-02-14 14:15:37 +01:00
committed by GitHub
parent 6f7d31c426
commit ef70a55b7a
8 changed files with 112 additions and 51 deletions

View File

@@ -7,41 +7,54 @@ import { normalizeTargetForProvider } from "../../infra/outbound/target-normaliz
import { extractReplyToTag } from "./reply-tags.js";
import { createReplyToModeFilterForChannel } from "./reply-threading.js";
function resolveReplyThreadingForPayload(params: {
payload: ReplyPayload;
implicitReplyToId?: string;
currentMessageId?: string;
}): ReplyPayload {
const implicitReplyToId = params.implicitReplyToId?.trim() || undefined;
const currentMessageId = params.currentMessageId?.trim() || undefined;
// 1) Apply implicit reply threading first (replyToMode will strip later if needed).
let resolved: ReplyPayload =
params.payload.replyToId || params.payload.replyToCurrent === false || !implicitReplyToId
? params.payload
: { ...params.payload, replyToId: implicitReplyToId };
// 2) Parse explicit reply tags from text (if present) and clean them.
if (typeof resolved.text === "string" && resolved.text.includes("[[")) {
const { cleaned, replyToId, replyToCurrent, hasTag } = extractReplyToTag(
resolved.text,
currentMessageId,
);
resolved = {
...resolved,
text: cleaned ? cleaned : undefined,
replyToId: replyToId ?? resolved.replyToId,
replyToTag: hasTag || resolved.replyToTag,
replyToCurrent: replyToCurrent || resolved.replyToCurrent,
};
}
// 3) If replyToCurrent was set out-of-band (e.g. tags already stripped upstream),
// ensure replyToId is set to the current message id when available.
if (resolved.replyToCurrent && !resolved.replyToId && currentMessageId) {
resolved = {
...resolved,
replyToId: currentMessageId,
};
}
return resolved;
}
// Backward-compatible helper: apply explicit reply tags/directives to a single payload.
// This intentionally does not apply implicit threading.
export function applyReplyTagsToPayload(
payload: ReplyPayload,
currentMessageId?: string,
): ReplyPayload {
if (typeof payload.text !== "string") {
if (!payload.replyToCurrent || payload.replyToId) {
return payload;
}
return {
...payload,
replyToId: currentMessageId?.trim() || undefined,
};
}
const shouldParseTags = payload.text.includes("[[");
if (!shouldParseTags) {
if (!payload.replyToCurrent || payload.replyToId) {
return payload;
}
return {
...payload,
replyToId: currentMessageId?.trim() || undefined,
replyToTag: payload.replyToTag ?? true,
};
}
const { cleaned, replyToId, replyToCurrent, hasTag } = extractReplyToTag(
payload.text,
currentMessageId,
);
return {
...payload,
text: cleaned ? cleaned : undefined,
replyToId: replyToId ?? payload.replyToId,
replyToTag: hasTag || payload.replyToTag,
replyToCurrent: replyToCurrent || payload.replyToCurrent,
};
return resolveReplyThreadingForPayload({ payload, currentMessageId });
}
export function isRenderablePayload(payload: ReplyPayload): boolean {
@@ -64,13 +77,9 @@ export function applyReplyThreading(params: {
const applyReplyToMode = createReplyToModeFilterForChannel(replyToMode, replyToChannel);
const implicitReplyToId = currentMessageId?.trim() || undefined;
return payloads
.map((payload) => {
const autoThreaded =
payload.replyToId || payload.replyToCurrent === false || !implicitReplyToId
? payload
: { ...payload, replyToId: implicitReplyToId };
return applyReplyTagsToPayload(autoThreaded, currentMessageId);
})
.map((payload) =>
resolveReplyThreadingForPayload({ payload, implicitReplyToId, currentMessageId }),
)
.filter(isRenderablePayload)
.map(applyReplyToMode);
}