chore(deadcode): remove qqbot duplicate wrappers

This commit is contained in:
Vincent Koc
2026-06-20 16:28:51 +08:00
parent 75fd2464cc
commit 5c19699cb2
4 changed files with 17 additions and 114 deletions

View File

@@ -2,14 +2,10 @@
import { describe, expect, it } from "vitest";
import {
DEFAULT_GROUP_HISTORY_LIMIT,
DEFAULT_GROUP_PROMPT,
resolveGroupConfig,
resolveGroupName,
resolveGroupPrompt,
resolveGroupSettings,
resolveHistoryLimit,
resolveIgnoreOtherMentions,
resolveMentionPatterns,
resolveRequireMention,
} from "./group.js";
describe("engine/config/group", () => {
@@ -70,7 +66,7 @@ describe("engine/config/group", () => {
qqbot: { appId: "1", groups: { "*": { historyLimit: -3.7 } } },
},
};
expect(resolveHistoryLimit(cfg, "G")).toBe(0);
expect(resolveGroupConfig(cfg, "G").historyLimit).toBe(0);
});
it("non-finite historyLimit falls back to default", () => {
@@ -79,7 +75,7 @@ describe("engine/config/group", () => {
qqbot: { appId: "1", groups: { "*": { historyLimit: "not a number" } } },
},
};
expect(resolveHistoryLimit(cfg, "G")).toBe(DEFAULT_GROUP_HISTORY_LIMIT);
expect(resolveGroupConfig(cfg, "G").historyLimit).toBe(DEFAULT_GROUP_HISTORY_LIMIT);
});
describe("account-level defaultRequireMention layer", () => {
@@ -103,7 +99,7 @@ describe("engine/config/group", () => {
},
},
};
expect(resolveRequireMention(cfg, "G1", "bot2")).toBe(false);
expect(resolveGroupConfig(cfg, "G1", "bot2").requireMention).toBe(false);
});
it("wildcard overrides account-level defaultRequireMention", () => {
@@ -153,27 +149,28 @@ describe("engine/config/group", () => {
},
},
};
expect(resolveRequireMention(cfg, "G", "bot2")).toBe(false);
expect(resolveHistoryLimit(cfg, "G", "bot2")).toBe(7);
const resolved = resolveGroupConfig(cfg, "G", "bot2");
expect(resolved.requireMention).toBe(false);
expect(resolved.historyLimit).toBe(7);
});
});
describe("resolveGroupName", () => {
describe("resolveGroupSettings name", () => {
it("uses the first 8 chars of openid when name is unset", () => {
expect(resolveGroupName({}, "ABCDEFGH1234")).toBe("ABCDEFGH");
expect(resolveGroupSettings({ cfg: {}, groupOpenid: "ABCDEFGH1234" }).name).toBe("ABCDEFGH");
});
it("prefers the configured name", () => {
const cfg = {
channels: { qqbot: { appId: "1", groups: { ABCDEFGH1234: { name: "Foo" } } } },
};
expect(resolveGroupName(cfg, "ABCDEFGH1234")).toBe("Foo");
expect(resolveGroupSettings({ cfg, groupOpenid: "ABCDEFGH1234" }).name).toBe("Foo");
});
});
describe("resolveGroupPrompt", () => {
describe("resolveGroupConfig prompt", () => {
it("returns the default prompt when nothing configured", () => {
expect(resolveGroupPrompt({}, "G")).toContain("bot");
expect(resolveGroupConfig({}, "G").prompt ?? DEFAULT_GROUP_PROMPT).toContain("bot");
});
it("prefers specific over wildcard", () => {
@@ -185,21 +182,21 @@ describe("engine/config/group", () => {
},
},
};
expect(resolveGroupPrompt(cfg, "G1")).toBe("SPEC");
expect(resolveGroupPrompt(cfg, "G2")).toBe("WILD");
expect(resolveGroupConfig(cfg, "G1").prompt).toBe("SPEC");
expect(resolveGroupConfig(cfg, "G2").prompt).toBe("WILD");
});
});
describe("resolveIgnoreOtherMentions", () => {
describe("resolveGroupConfig ignoreOtherMentions", () => {
it("defaults to false", () => {
expect(resolveIgnoreOtherMentions({}, "G")).toBe(false);
expect(resolveGroupConfig({}, "G").ignoreOtherMentions).toBe(false);
});
it("honours wildcard override", () => {
const cfg = {
channels: { qqbot: { appId: "1", groups: { "*": { ignoreOtherMentions: true } } } },
};
expect(resolveIgnoreOtherMentions(cfg, "G")).toBe(true);
expect(resolveGroupConfig(cfg, "G").ignoreOtherMentions).toBe(true);
});
});

View File

@@ -91,57 +91,6 @@ export function resolveGroupConfig(
};
}
export function resolveHistoryLimit(
cfg: Record<string, unknown>,
groupOpenid?: string | null,
accountId?: string | null,
): number {
return resolveGroupConfig(cfg, groupOpenid, accountId).historyLimit;
}
export function resolveRequireMention(
cfg: Record<string, unknown>,
groupOpenid?: string | null,
accountId?: string | null,
): boolean {
return resolveGroupConfig(cfg, groupOpenid, accountId).requireMention;
}
export function resolveIgnoreOtherMentions(
cfg: Record<string, unknown>,
groupOpenid?: string | null,
accountId?: string | null,
): boolean {
return resolveGroupConfig(cfg, groupOpenid, accountId).ignoreOtherMentions;
}
/**
* Resolve the behaviour prompt (PE) for a group. Falls back to the built-in
* default when neither specific nor wildcard configuration provides one.
*/
export function resolveGroupPrompt(
cfg: Record<string, unknown>,
groupOpenid?: string | null,
accountId?: string | null,
): string {
return resolveGroupConfig(cfg, groupOpenid, accountId).prompt ?? DEFAULT_GROUP_PROMPT;
}
/**
* Resolve the display name for a group.
*
* When no name is configured, the first 8 characters of the openid are used
* as a short identifier so log lines stay compact.
*/
export function resolveGroupName(
cfg: Record<string, unknown>,
groupOpenid: string,
accountId?: string | null,
): string {
const name = resolveGroupConfig(cfg, groupOpenid, accountId).name;
return name || groupOpenid.slice(0, 8);
}
// ============ GroupSettings (aggregate) ============
/**

View File

@@ -6,7 +6,6 @@ import {
formatDelay,
generateJobName,
buildReminderPrompt,
executeRemind,
executeScheduledRemind,
prepareRemindCronAction,
type RemindCronAction,
@@ -113,21 +112,6 @@ describe("engine/tools/remind-logic", () => {
});
});
describe("executeRemind", () => {
it("renders internal scheduling output without exposing cronParams", () => {
const result = executeRemind({ action: "list" });
expect(result.details).toEqual({
_instruction: "Gateway cron action prepared for internal QQ reminder scheduling.",
action: "list",
summary: undefined,
});
expect((result.details as { _instruction: string })["_instruction"]).not.toContain(
"Use the cron tool",
);
expect(result.details).not.toHaveProperty("cronParams");
});
});
describe("prepareRemindCronAction", () => {
it("returns error when removing without jobId", () => {
const result = prepareRemindCronAction({ action: "remove" });

View File

@@ -58,9 +58,6 @@ type RemindCronPlan =
error: string;
};
const PREPARED_CRON_PARAMS_INSTRUCTION =
"Gateway cron action prepared for internal QQ reminder scheduling.";
/**
* JSON Schema for AI tool parameters (used by framework registration).
* AI Tool 参数的 JSON Schema 定义(供框架注册使用)。
@@ -337,30 +334,6 @@ export function prepareRemindCronAction(
};
}
/**
* Execute the reminder tool logic.
* 执行提醒工具逻辑。
*
* Validates params, parses time, and returns a structured result
* containing cron job params that the framework shell passes back
* as the tool output.
*
* When the AI omits `to` / `accountId`, the bridge layer can supply
* `ctx.fallbackTo` / `ctx.fallbackAccountId` (typically resolved from
* the request-scoped AsyncLocalStorage) to fill them in.
*/
export function executeRemind(params: RemindParams, ctx: RemindExecuteContext = {}) {
const plan = prepareRemindCronAction(params, ctx);
if (!plan.ok) {
return json({ error: plan.error });
}
return json({
_instruction: PREPARED_CRON_PARAMS_INSTRUCTION,
action: plan.action,
summary: plan.summary,
});
}
export async function executeScheduledRemind(
params: RemindParams,
ctx: RemindExecuteContext,