diff --git a/extensions/qqbot/src/utils/text-parsing.ts b/extensions/qqbot/src/utils/text-parsing.ts index 67cc9259f63..5cec13dda9a 100644 --- a/extensions/qqbot/src/utils/text-parsing.ts +++ b/extensions/qqbot/src/utils/text-parsing.ts @@ -1,41 +1,9 @@ +import { estimateBase64DecodedBytes } from "openclaw/plugin-sdk/media-runtime"; +import { normalizeLowercaseStringOrEmpty } from "openclaw/plugin-sdk/text-runtime"; import type { RefAttachmentSummary } from "../ref-index-store.js"; const MAX_FACE_EXT_BYTES = 64 * 1024; -function estimateBase64DecodedBytes(base64: string): number { - let effectiveLen = 0; - for (let i = 0; i < base64.length; i += 1) { - if (base64.charCodeAt(i) > 0x20) { - effectiveLen += 1; - } - } - if (effectiveLen === 0) { - return 0; - } - - let padding = 0; - let end = base64.length - 1; - while (end >= 0 && base64.charCodeAt(end) <= 0x20) { - end -= 1; - } - if (end >= 0 && base64[end] === "=") { - padding = 1; - end -= 1; - while (end >= 0 && base64.charCodeAt(end) <= 0x20) { - end -= 1; - } - if (end >= 0 && base64[end] === "=") { - padding = 2; - } - } - - return Math.max(0, Math.floor((effectiveLen * 3) / 4) - padding); -} - -function normalizeLowercaseStringOrEmpty(value: unknown): string { - return typeof value === "string" ? value.trim().toLowerCase() : ""; -} - /** Replace QQ face tags with readable text labels. */ export function parseFaceTags(text: string | undefined | null): string { if (!text) {