refactor: unify inbound debounce policy and split gateway/models helpers

This commit is contained in:
Peter Steinberger
2026-03-03 00:54:28 +00:00
parent 7de4204e57
commit 47083460ea
13 changed files with 415 additions and 192 deletions

View File

@@ -1,6 +1,5 @@
import type { Message, ReactionTypeEmoji } from "@grammyjs/types";
import { resolveAgentDir, resolveDefaultAgentId } from "../agents/agent-scope.js";
import { hasControlCommand } from "../auto-reply/command-detection.js";
import {
createInboundDebouncer,
resolveInboundDebounceMs,
@@ -13,6 +12,7 @@ import {
import { resolveStoredModelOverride } from "../auto-reply/reply/model-selection.js";
import { listSkillCommandsForAgents } from "../auto-reply/skill-commands.js";
import { buildCommandsMessagePaginated } from "../auto-reply/status.js";
import { shouldDebounceTextInbound } from "../channels/inbound-debounce-policy.js";
import { resolveChannelConfigWrites } from "../channels/plugins/config-writes.js";
import { loadConfig } from "../config/config.js";
import { writeConfigFile } from "../config/io.js";
@@ -206,14 +206,18 @@ export const registerTelegramHandlers = ({
buildKey: (entry) => entry.debounceKey,
shouldDebounce: (entry) => {
const text = entry.msg.text ?? entry.msg.caption ?? "";
const hasText = text.trim().length > 0;
if (hasText && hasControlCommand(text, cfg, { botUsername: entry.botUsername })) {
const hasDebounceableText = shouldDebounceTextInbound({
text,
cfg,
commandOptions: { botUsername: entry.botUsername },
});
if (!hasDebounceableText) {
return false;
}
if (entry.debounceLane === "forward") {
return true;
}
return entry.allMedia.length === 0 && hasText;
return entry.allMedia.length === 0;
},
onFlush: async (entries) => {
const last = entries.at(-1);