fix: add missing type extensions for engagement mode
This commit is contained in:
parent
294d36df8f
commit
d1241cf6b7
@ -1,11 +1,12 @@
|
||||
import { normalizeCommandBody } from "./commands-registry.js";
|
||||
|
||||
export type GroupActivationMode = "mention" | "always";
|
||||
export type GroupActivationMode = "mention" | "always" | "engagement";
|
||||
|
||||
export function normalizeGroupActivation(raw?: string | null): GroupActivationMode | undefined {
|
||||
const value = raw?.trim().toLowerCase();
|
||||
if (value === "mention") return "mention";
|
||||
if (value === "always") return "always";
|
||||
if (value === "engagement") return "engagement";
|
||||
return undefined;
|
||||
}
|
||||
|
||||
|
||||
@ -111,7 +111,7 @@ export async function buildStatusReply(params: {
|
||||
resolvedElevatedLevel?: ElevatedLevel;
|
||||
resolveDefaultThinkingLevel: () => Promise<ThinkLevel | undefined>;
|
||||
isGroup: boolean;
|
||||
defaultGroupActivation: () => "always" | "mention";
|
||||
defaultGroupActivation: () => "always" | "mention" | "engagement";
|
||||
mediaDecisions?: MediaUnderstandingDecision[];
|
||||
}): Promise<ReplyPayload | undefined> {
|
||||
const {
|
||||
|
||||
@ -39,7 +39,7 @@ export type HandleCommandsParams = {
|
||||
storePath?: string;
|
||||
sessionScope?: SessionScope;
|
||||
workspaceDir: string;
|
||||
defaultGroupActivation: () => "always" | "mention";
|
||||
defaultGroupActivation: () => "always" | "mention" | "engagement";
|
||||
resolvedThinkLevel?: ThinkLevel;
|
||||
resolvedVerboseLevel: VerboseLevel;
|
||||
resolvedReasoningLevel: ReasoningLevel;
|
||||
|
||||
@ -49,7 +49,9 @@ export function resolveGroupRequireMention(params: {
|
||||
return true;
|
||||
}
|
||||
|
||||
export function defaultGroupActivation(requireMention: boolean): "always" | "mention" {
|
||||
export function defaultGroupActivation(
|
||||
requireMention: boolean,
|
||||
): "always" | "mention" | "engagement" {
|
||||
return requireMention === false ? "always" : "mention";
|
||||
}
|
||||
|
||||
@ -57,7 +59,7 @@ export function buildGroupIntro(params: {
|
||||
cfg: MoltbotConfig;
|
||||
sessionCtx: TemplateContext;
|
||||
sessionEntry?: SessionEntry;
|
||||
defaultActivation: "always" | "mention";
|
||||
defaultActivation: "always" | "mention" | "engagement";
|
||||
silentToken: string;
|
||||
}): string {
|
||||
const activation =
|
||||
|
||||
@ -59,7 +59,7 @@ type StatusArgs = {
|
||||
sessionEntry?: SessionEntry;
|
||||
sessionKey?: string;
|
||||
sessionScope?: SessionScope;
|
||||
groupActivation?: "mention" | "always";
|
||||
groupActivation?: "mention" | "always" | "engagement";
|
||||
resolvedThink?: ThinkLevel;
|
||||
resolvedVerbose?: VerboseLevel;
|
||||
resolvedReasoning?: ReasoningLevel;
|
||||
|
||||
@ -1,12 +1,15 @@
|
||||
import type { ChannelId } from "../channels/plugins/types.js";
|
||||
import { normalizeAccountId } from "../routing/session-key.js";
|
||||
import type { MoltbotConfig } from "./config.js";
|
||||
import type { EngagementConfig } from "./engagement.js";
|
||||
import type { GroupToolPolicyBySenderConfig, GroupToolPolicyConfig } from "./types.tools.js";
|
||||
|
||||
export type GroupPolicyChannel = ChannelId;
|
||||
|
||||
export type ChannelGroupConfig = {
|
||||
requireMention?: boolean;
|
||||
mode?: "mention" | "always" | "engagement";
|
||||
engagement?: EngagementConfig;
|
||||
tools?: GroupToolPolicyConfig;
|
||||
toolsBySender?: GroupToolPolicyBySenderConfig;
|
||||
};
|
||||
@ -154,6 +157,31 @@ export function resolveChannelGroupRequireMention(params: {
|
||||
return true;
|
||||
}
|
||||
|
||||
export function resolveChannelGroupMode(params: {
|
||||
cfg: MoltbotConfig;
|
||||
channel: GroupPolicyChannel;
|
||||
groupId?: string | null;
|
||||
accountId?: string | null;
|
||||
}): "mention" | "always" | "engagement" {
|
||||
const { groupConfig, defaultConfig } = resolveChannelGroupPolicy(params);
|
||||
// Explicit mode takes precedence
|
||||
if (groupConfig?.mode) return groupConfig.mode;
|
||||
if (defaultConfig?.mode) return defaultConfig.mode;
|
||||
// Fall back to legacy requireMention behavior
|
||||
const requireMention = resolveChannelGroupRequireMention(params);
|
||||
return requireMention ? "mention" : "always";
|
||||
}
|
||||
|
||||
export function resolveChannelGroupEngagement(params: {
|
||||
cfg: MoltbotConfig;
|
||||
channel: GroupPolicyChannel;
|
||||
groupId?: string | null;
|
||||
accountId?: string | null;
|
||||
}): EngagementConfig | undefined {
|
||||
const { groupConfig, defaultConfig } = resolveChannelGroupPolicy(params);
|
||||
return groupConfig?.engagement ?? defaultConfig?.engagement;
|
||||
}
|
||||
|
||||
export function resolveChannelGroupToolsPolicy(
|
||||
params: {
|
||||
cfg: MoltbotConfig;
|
||||
|
||||
@ -3,6 +3,7 @@ import crypto from "node:crypto";
|
||||
import type { Skill } from "@mariozechner/pi-coding-agent";
|
||||
import type { NormalizedChatType } from "../../channels/chat-type.js";
|
||||
import type { ChannelId } from "../../channels/plugins/types.js";
|
||||
import type { EngagementState } from "../engagement.js";
|
||||
import type { DeliveryContext } from "../../utils/delivery-context.js";
|
||||
import type { TtsAutoMode } from "../types.tts.js";
|
||||
|
||||
@ -54,8 +55,9 @@ export type SessionEntry = {
|
||||
authProfileOverride?: string;
|
||||
authProfileOverrideSource?: "auto" | "user";
|
||||
authProfileOverrideCompactionCount?: number;
|
||||
groupActivation?: "mention" | "always";
|
||||
groupActivation?: "mention" | "always" | "engagement";
|
||||
groupActivationNeedsSystemIntro?: boolean;
|
||||
engagementState?: EngagementState;
|
||||
sendPolicy?: "allow" | "deny";
|
||||
queueMode?:
|
||||
| "steer"
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
import { normalizeGroupActivation } from "../../../auto-reply/group-activation.js";
|
||||
import type { loadConfig } from "../../../config/config.js";
|
||||
import {
|
||||
resolveChannelGroupMode,
|
||||
resolveChannelGroupPolicy,
|
||||
resolveChannelGroupRequireMention,
|
||||
} from "../../../config/group-policy.js";
|
||||
@ -39,6 +40,19 @@ export function resolveGroupRequireMentionFor(
|
||||
});
|
||||
}
|
||||
|
||||
export function resolveGroupModeFor(cfg: ReturnType<typeof loadConfig>, conversationId: string) {
|
||||
const groupId = resolveGroupSessionKey({
|
||||
From: conversationId,
|
||||
ChatType: "group",
|
||||
Provider: "whatsapp",
|
||||
})?.id;
|
||||
return resolveChannelGroupMode({
|
||||
cfg,
|
||||
channel: "whatsapp",
|
||||
groupId: groupId ?? conversationId,
|
||||
});
|
||||
}
|
||||
|
||||
export function resolveGroupActivationFor(params: {
|
||||
cfg: ReturnType<typeof loadConfig>;
|
||||
agentId: string;
|
||||
@ -50,7 +64,16 @@ export function resolveGroupActivationFor(params: {
|
||||
});
|
||||
const store = loadSessionStore(storePath);
|
||||
const entry = store[params.sessionKey];
|
||||
|
||||
// Session-level override takes precedence
|
||||
const sessionActivation = normalizeGroupActivation(entry?.groupActivation);
|
||||
if (sessionActivation) return sessionActivation;
|
||||
|
||||
// Then check config mode (supports "engagement")
|
||||
const configMode = resolveGroupModeFor(params.cfg, params.conversationId);
|
||||
if (configMode) return configMode;
|
||||
|
||||
// Legacy fallback
|
||||
const requireMention = resolveGroupRequireMentionFor(params.cfg, params.conversationId);
|
||||
const defaultActivation = requireMention === false ? "always" : "mention";
|
||||
return normalizeGroupActivation(entry?.groupActivation) ?? defaultActivation;
|
||||
return requireMention === false ? "always" : "mention";
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user