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";
|
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 {
|
export function normalizeGroupActivation(raw?: string | null): GroupActivationMode | undefined {
|
||||||
const value = raw?.trim().toLowerCase();
|
const value = raw?.trim().toLowerCase();
|
||||||
if (value === "mention") return "mention";
|
if (value === "mention") return "mention";
|
||||||
if (value === "always") return "always";
|
if (value === "always") return "always";
|
||||||
|
if (value === "engagement") return "engagement";
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -111,7 +111,7 @@ export async function buildStatusReply(params: {
|
|||||||
resolvedElevatedLevel?: ElevatedLevel;
|
resolvedElevatedLevel?: ElevatedLevel;
|
||||||
resolveDefaultThinkingLevel: () => Promise<ThinkLevel | undefined>;
|
resolveDefaultThinkingLevel: () => Promise<ThinkLevel | undefined>;
|
||||||
isGroup: boolean;
|
isGroup: boolean;
|
||||||
defaultGroupActivation: () => "always" | "mention";
|
defaultGroupActivation: () => "always" | "mention" | "engagement";
|
||||||
mediaDecisions?: MediaUnderstandingDecision[];
|
mediaDecisions?: MediaUnderstandingDecision[];
|
||||||
}): Promise<ReplyPayload | undefined> {
|
}): Promise<ReplyPayload | undefined> {
|
||||||
const {
|
const {
|
||||||
|
|||||||
@ -39,7 +39,7 @@ export type HandleCommandsParams = {
|
|||||||
storePath?: string;
|
storePath?: string;
|
||||||
sessionScope?: SessionScope;
|
sessionScope?: SessionScope;
|
||||||
workspaceDir: string;
|
workspaceDir: string;
|
||||||
defaultGroupActivation: () => "always" | "mention";
|
defaultGroupActivation: () => "always" | "mention" | "engagement";
|
||||||
resolvedThinkLevel?: ThinkLevel;
|
resolvedThinkLevel?: ThinkLevel;
|
||||||
resolvedVerboseLevel: VerboseLevel;
|
resolvedVerboseLevel: VerboseLevel;
|
||||||
resolvedReasoningLevel: ReasoningLevel;
|
resolvedReasoningLevel: ReasoningLevel;
|
||||||
|
|||||||
@ -49,7 +49,9 @@ export function resolveGroupRequireMention(params: {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function defaultGroupActivation(requireMention: boolean): "always" | "mention" {
|
export function defaultGroupActivation(
|
||||||
|
requireMention: boolean,
|
||||||
|
): "always" | "mention" | "engagement" {
|
||||||
return requireMention === false ? "always" : "mention";
|
return requireMention === false ? "always" : "mention";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,7 +59,7 @@ export function buildGroupIntro(params: {
|
|||||||
cfg: MoltbotConfig;
|
cfg: MoltbotConfig;
|
||||||
sessionCtx: TemplateContext;
|
sessionCtx: TemplateContext;
|
||||||
sessionEntry?: SessionEntry;
|
sessionEntry?: SessionEntry;
|
||||||
defaultActivation: "always" | "mention";
|
defaultActivation: "always" | "mention" | "engagement";
|
||||||
silentToken: string;
|
silentToken: string;
|
||||||
}): string {
|
}): string {
|
||||||
const activation =
|
const activation =
|
||||||
|
|||||||
@ -59,7 +59,7 @@ type StatusArgs = {
|
|||||||
sessionEntry?: SessionEntry;
|
sessionEntry?: SessionEntry;
|
||||||
sessionKey?: string;
|
sessionKey?: string;
|
||||||
sessionScope?: SessionScope;
|
sessionScope?: SessionScope;
|
||||||
groupActivation?: "mention" | "always";
|
groupActivation?: "mention" | "always" | "engagement";
|
||||||
resolvedThink?: ThinkLevel;
|
resolvedThink?: ThinkLevel;
|
||||||
resolvedVerbose?: VerboseLevel;
|
resolvedVerbose?: VerboseLevel;
|
||||||
resolvedReasoning?: ReasoningLevel;
|
resolvedReasoning?: ReasoningLevel;
|
||||||
|
|||||||
@ -1,12 +1,15 @@
|
|||||||
import type { ChannelId } from "../channels/plugins/types.js";
|
import type { ChannelId } from "../channels/plugins/types.js";
|
||||||
import { normalizeAccountId } from "../routing/session-key.js";
|
import { normalizeAccountId } from "../routing/session-key.js";
|
||||||
import type { MoltbotConfig } from "./config.js";
|
import type { MoltbotConfig } from "./config.js";
|
||||||
|
import type { EngagementConfig } from "./engagement.js";
|
||||||
import type { GroupToolPolicyBySenderConfig, GroupToolPolicyConfig } from "./types.tools.js";
|
import type { GroupToolPolicyBySenderConfig, GroupToolPolicyConfig } from "./types.tools.js";
|
||||||
|
|
||||||
export type GroupPolicyChannel = ChannelId;
|
export type GroupPolicyChannel = ChannelId;
|
||||||
|
|
||||||
export type ChannelGroupConfig = {
|
export type ChannelGroupConfig = {
|
||||||
requireMention?: boolean;
|
requireMention?: boolean;
|
||||||
|
mode?: "mention" | "always" | "engagement";
|
||||||
|
engagement?: EngagementConfig;
|
||||||
tools?: GroupToolPolicyConfig;
|
tools?: GroupToolPolicyConfig;
|
||||||
toolsBySender?: GroupToolPolicyBySenderConfig;
|
toolsBySender?: GroupToolPolicyBySenderConfig;
|
||||||
};
|
};
|
||||||
@ -154,6 +157,31 @@ export function resolveChannelGroupRequireMention(params: {
|
|||||||
return true;
|
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(
|
export function resolveChannelGroupToolsPolicy(
|
||||||
params: {
|
params: {
|
||||||
cfg: MoltbotConfig;
|
cfg: MoltbotConfig;
|
||||||
|
|||||||
@ -3,6 +3,7 @@ import crypto from "node:crypto";
|
|||||||
import type { Skill } from "@mariozechner/pi-coding-agent";
|
import type { Skill } from "@mariozechner/pi-coding-agent";
|
||||||
import type { NormalizedChatType } from "../../channels/chat-type.js";
|
import type { NormalizedChatType } from "../../channels/chat-type.js";
|
||||||
import type { ChannelId } from "../../channels/plugins/types.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 { DeliveryContext } from "../../utils/delivery-context.js";
|
||||||
import type { TtsAutoMode } from "../types.tts.js";
|
import type { TtsAutoMode } from "../types.tts.js";
|
||||||
|
|
||||||
@ -54,8 +55,9 @@ export type SessionEntry = {
|
|||||||
authProfileOverride?: string;
|
authProfileOverride?: string;
|
||||||
authProfileOverrideSource?: "auto" | "user";
|
authProfileOverrideSource?: "auto" | "user";
|
||||||
authProfileOverrideCompactionCount?: number;
|
authProfileOverrideCompactionCount?: number;
|
||||||
groupActivation?: "mention" | "always";
|
groupActivation?: "mention" | "always" | "engagement";
|
||||||
groupActivationNeedsSystemIntro?: boolean;
|
groupActivationNeedsSystemIntro?: boolean;
|
||||||
|
engagementState?: EngagementState;
|
||||||
sendPolicy?: "allow" | "deny";
|
sendPolicy?: "allow" | "deny";
|
||||||
queueMode?:
|
queueMode?:
|
||||||
| "steer"
|
| "steer"
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
import { normalizeGroupActivation } from "../../../auto-reply/group-activation.js";
|
import { normalizeGroupActivation } from "../../../auto-reply/group-activation.js";
|
||||||
import type { loadConfig } from "../../../config/config.js";
|
import type { loadConfig } from "../../../config/config.js";
|
||||||
import {
|
import {
|
||||||
|
resolveChannelGroupMode,
|
||||||
resolveChannelGroupPolicy,
|
resolveChannelGroupPolicy,
|
||||||
resolveChannelGroupRequireMention,
|
resolveChannelGroupRequireMention,
|
||||||
} from "../../../config/group-policy.js";
|
} 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: {
|
export function resolveGroupActivationFor(params: {
|
||||||
cfg: ReturnType<typeof loadConfig>;
|
cfg: ReturnType<typeof loadConfig>;
|
||||||
agentId: string;
|
agentId: string;
|
||||||
@ -50,7 +64,16 @@ export function resolveGroupActivationFor(params: {
|
|||||||
});
|
});
|
||||||
const store = loadSessionStore(storePath);
|
const store = loadSessionStore(storePath);
|
||||||
const entry = store[params.sessionKey];
|
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 requireMention = resolveGroupRequireMentionFor(params.cfg, params.conversationId);
|
||||||
const defaultActivation = requireMention === false ? "always" : "mention";
|
return requireMention === false ? "always" : "mention";
|
||||||
return normalizeGroupActivation(entry?.groupActivation) ?? defaultActivation;
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user