openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
367 lines (366 loc) โข 8.78 kB
JavaScript
import { c as normalizeOptionalLowercaseString } from "./string-coerce-CCIiB4H7.mjs";
import "./identity-Cd2mxvzm.mjs";
import { i as shouldAckReaction } from "./ack-reactions-wVmQEGsP.mjs";
import "./logging-DyCvEa9E.mjs";
//#region src/channels/status-reactions.ts
const TOOL_REACTION_EMOJIS = /* @__PURE__ */ new Map([
["bash", "๐ ๏ธ"],
["computer", "๐ฑ๏ธ"],
["mobile_ui", "๐ฑ"],
["screen", "๐ฅ๏ธ"],
["theme", "๐จ"],
["terminal", "โจ๏ธ"],
["portal", "๐"],
["process", "๐งฐ"],
["gateway_process", "๐งฐ"],
["read", "๐"],
["write", "โ๏ธ"],
["edit", "๐"],
["personal_instructions", "๐"],
["presence", "๐งฉ"],
["attach", "๐"],
["api", "๐"],
["browser", "๐"],
["canvas", "๐ผ๏ธ"],
["dashboard", "๐"],
["nodes", "๐ฑ"],
["cron", "โฐ"],
["get_goal", "๐ฏ"],
["create_goal", "๐ฏ"],
["update_goal", "๐ฏ"],
["progress_card", "๐บ๏ธ"],
["ask_user", "โ"],
["secrets", "๐"],
["suggest_task", "โจ"],
["dismiss_task", "๐๏ธ"],
["skill_workshop", "๐งฐ"],
["openclaw", "๐ฆ"],
["gateway", "๐"],
["plugins", "๐งฉ"],
["exec", "๐ ๏ธ"],
["tool_call", "๐งฐ"],
["dispatch_action", "๐งฐ"],
["tool_call_update", "๐งฐ"],
["session_status", "๐"],
["github_publish", "๐"],
["github_identity_status", "๐"],
["sessions", "๐๏ธ"],
["sessions_list", "๐๏ธ"],
["conversations_list", "๐ฌ"],
["conversations_send", "๐จ"],
["conversations_turn", "โ๏ธ"],
["sessions_send", "๐จ"],
["sessions_history", "๐งพ"],
["sessions_search", "๐"],
["transcripts", "๐๏ธ"],
["sessions_spawn", "๐งโ๐ง"],
["agents_wait", "โณ"],
["structured_output", "๐งพ"],
["subagents", "๐ค"],
["agents_list", "๐งญ"],
["memory_search", "๐ง "],
["memory_get", "๐"],
["skills_search", "๐"],
["skills_read", "๐"],
["web_search", "๐"],
["web_fetch", "๐"],
["code_execution", "๐งฎ"],
["decision_evaluate", "โ๏ธ"],
["message", "โ๏ธ"],
["apply_patch", "๐ฉน"],
["image", "๐ผ๏ธ"],
["view_image", "๐ผ๏ธ"],
["image_generate", "๐จ"],
["music_generate", "๐ต"],
["video_generate", "๐ฌ"],
["pdf", "๐"],
["sessions_yield", "โธ๏ธ"],
["tts", "๐"]
]);
const DEFAULT_EMOJIS = {
queued: "๐",
thinking: "๐ง ",
tool: "๐ ๏ธ",
coding: "๐ป",
web: "๐",
deploy: "๐ซ",
build: "๐๏ธ",
concierge: "๐",
done: "โ
",
error: "โ",
stallSoft: "โณ",
stallHard: "โ ๏ธ",
compacting: "๐๏ธ"
};
const DEFAULT_TIMING = {
debounceMs: 700,
stallSoftMs: 1e4,
stallHardMs: 3e4,
doneHoldMs: 1500,
errorHoldMs: 2500
};
const CODING_TOOL_TOKENS = [
"exec",
"process",
"read",
"write",
"edit",
"session_status",
"bash"
];
const WEB_TOOL_TOKENS = [
"web_search",
"web-search",
"web_fetch",
"web-fetch",
"browser"
];
const DEPLOY_TOOL_TOKENS = [
"fastlane",
"deploy",
"upload",
"testflight",
"ship",
"release",
"publish",
"distribute"
];
const BUILD_TOOL_TOKENS = [
"build",
"compile",
"xcode",
"swift",
"gradle",
"cargo",
"make",
"cmake",
"webpack",
"vite",
"tsc",
"lint"
];
const CONCIERGE_TOOL_TOKENS = [
"navigate",
"click",
"fill",
"screenshot",
"scroll",
"page",
"form",
"puppeteer",
"playwright",
"selenium",
"chromedp"
];
function resolveToolEmoji(e, t, n) {
const r = normalizeOptionalLowercaseString(e) ?? "";
if (!r) return t.tool;
const i = DEPLOY_TOOL_TOKENS.some((e) => r.includes(e)) ? "deploy" : BUILD_TOOL_TOKENS.some((e) => r.includes(e)) ? "build" : CONCIERGE_TOOL_TOKENS.some((e) => r.includes(e)) ? "concierge" : WEB_TOOL_TOKENS.some((e) => r.includes(e)) ? "web" : CODING_TOOL_TOKENS.some((e) => r.includes(e)) ? "coding" : "tool";
if (n?.[i] !== void 0) return t[i];
return TOOL_REACTION_EMOJIS.get(r) ?? t[i];
}
/** Defer reaction removal until cleanup to avoid flicker without atomic replacement. */
function createStatusReactionController(e) {
const { enabled: t, adapter: n, initialEmoji: r, onError: i } = e;
const a = e.presentation !== "acknowledgement";
const o = {
...DEFAULT_EMOJIS,
queued: e.emojis?.queued ?? r,
...e.emojis
};
const s = {
...DEFAULT_TIMING,
...e.timing
};
let c = "";
let l = "";
let u = null;
let d = [];
let f = null;
let p = 0;
let m = false;
let h = Promise.resolve();
const g = /* @__PURE__ */ new Set();
function enqueue(e) {
h = h.then(e, e);
return h;
}
function clearActivityTimers() {
clearDebounceTimer();
clearStallTimers();
}
function clearStallTimers() {
for (const e of d) clearTimeout(e);
d = [];
}
function cancelTerminalHold() {
p += 1;
const e = f;
if (!e) return;
f = null;
clearTimeout(e.timer);
e.resolve();
}
function waitForTerminalHold(e, t) {
if (e <= 0 || t !== p) return Promise.resolve();
return new Promise((t) => {
f = {
timer: setTimeout(() => {
f = null;
t();
}, e),
resolve: t
};
});
}
function clearDebounceTimer() {
if (u) {
clearTimeout(u);
u = null;
}
}
function resetStallTimers() {
if (!a) return;
clearStallTimers();
d = ["stallSoft", "stallHard"].map((e) => setTimeout(() => {
scheduleEmoji(o[e], {
immediate: true,
skipStallReset: true
});
}, s[`${e}Ms`]));
}
async function removeActiveEmojis(e = {}) {
if (!n.removeReaction) return;
for (const t of g) {
if (t === e.keepEmoji) continue;
try {
await n.removeReaction(t);
} catch (e) {
i?.(e);
} finally {
g.delete(t);
}
}
}
async function applyEmoji(e) {
try {
if (!n.removeReaction || !g.has(e)) await n.setReaction(e);
g.add(e);
c = e;
} catch (e) {
i?.(e);
}
}
function scheduleEmoji(e, n = {}) {
if (!t || m) return;
const i = a ? e : r;
if (i === c || i === l) {
if (!n.skipStallReset) resetStallTimers();
return;
}
l = i;
clearDebounceTimer();
const applyPendingEmoji = async () => {
await applyEmoji(i);
l = "";
};
if (n.immediate) enqueue(applyPendingEmoji);
else u = setTimeout(() => {
u = null;
enqueue(applyPendingEmoji);
}, s.debounceMs);
if (!n.skipStallReset) resetStallTimers();
}
function finishWithEmoji(e, n) {
if (!t) return Promise.resolve();
m = true;
clearActivityTimers();
const r = p;
return enqueue(async () => {
await applyEmoji(e);
await removeActiveEmojis({ keepEmoji: e });
l = "";
await waitForTerminalHold(n, r);
});
}
async function clear() {
if (!t) return;
clearActivityTimers();
cancelTerminalHold();
m = true;
await enqueue(async () => {
if (n.clearReaction) try {
await n.clearReaction();
} catch (e) {
i?.(e);
} finally {
g.clear();
}
else await removeActiveEmojis();
c = "";
l = "";
});
}
async function restoreInitial() {
if (!t) return;
const e = c === r;
const n = l;
const i = u !== null;
const a = g.size > (g.has(r) ? 1 : 0);
clearActivityTimers();
if (!m && e && (!n || i) && !a) {
l = "";
return;
}
if (!m && n === r && !i) {
await h;
return;
}
await enqueue(async () => {
await applyEmoji(r);
await removeActiveEmojis({ keepEmoji: r });
l = "";
});
}
return {
setQueued: () => scheduleEmoji(o.queued, { immediate: true }),
setThinking: () => scheduleEmoji(o.thinking),
setTool: (t) => scheduleEmoji(resolveToolEmoji(t, o, e.emojis)),
setCompacting: () => scheduleEmoji(o.compacting),
cancelPending() {
clearDebounceTimer();
l = "";
},
setDone: () => a ? finishWithEmoji(o.done, s.doneHoldMs) : finishWithEmoji(r, 0),
setError: () => finishWithEmoji(o.error, s.errorHoldMs),
clear,
restoreInitial
};
}
//#endregion
//#region src/plugin-sdk/channel-feedback.ts
/**
* @deprecated Load-only bridge: the published WhatsApp channel package
* (2026.7.2-beta.7 and earlier) imports this at module top level, so removing
* it makes the installed plugin fail to load after a core upgrade. Behavior
* preserved verbatim from the pre-#121257 owner. Remove once managed releases
* have replaced the old npm latest/extended-stable packages and their upgrade
* window has closed.
*/
function shouldAckReactionForWhatsApp(e) {
if (!e.emoji) return false;
if (e.isDirect) return e.directEnabled;
if (!e.isGroup || e.groupMode === "never") return false;
if (e.groupMode === "always") return true;
return shouldAckReaction({
scope: "group-mentions",
isDirect: false,
isGroup: true,
isMentionableGroup: true,
canDetectMention: true,
effectiveWasMentioned: e.wasMentioned,
shouldBypassMention: e.groupActivated
});
}
//#endregion
export { DEFAULT_EMOJIS as a, WEB_TOOL_TOKENS as c, CONCIERGE_TOOL_TOKENS as i, createStatusReactionController as l, BUILD_TOOL_TOKENS as n, DEFAULT_TIMING as o, CODING_TOOL_TOKENS as r, DEPLOY_TOOL_TOKENS as s, shouldAckReactionForWhatsApp as t, resolveToolEmoji as u };