refactor: drop legacy room chatType

This commit is contained in:
Peter Steinberger
2026-01-17 05:40:28 +00:00
parent 07a3db153d
commit 8b42902cee
18 changed files with 19 additions and 42 deletions

View File

@@ -3,17 +3,10 @@ import { describe, expect, it } from "vitest";
import { normalizeMediaUnderstandingChatType, resolveMediaUnderstandingScope } from "./scope.js";
describe("media understanding scope", () => {
it("normalizes channel/room", () => {
it("normalizes chatType", () => {
expect(normalizeMediaUnderstandingChatType("channel")).toBe("channel");
expect(normalizeMediaUnderstandingChatType("room")).toBe("channel");
});
it("treats room match as channel", () => {
const scope = {
rules: [{ action: "deny", match: { chatType: "room" } }],
} as const;
expect(resolveMediaUnderstandingScope({ scope, chatType: "channel" })).toBe("deny");
expect(normalizeMediaUnderstandingChatType("dm")).toBe("direct");
expect(normalizeMediaUnderstandingChatType("room")).toBeUndefined();
});
it("matches channel chatType explicitly", () => {
@@ -24,4 +17,3 @@ describe("media understanding scope", () => {
expect(resolveMediaUnderstandingScope({ scope, chatType: "channel" })).toBe("deny");
});
});

View File

@@ -1,4 +1,5 @@
import type { MediaUnderstandingScopeConfig } from "../config/types.tools.js";
import { normalizeChatType } from "../channels/chat-type.js";
export type MediaUnderstandingScopeDecision = "allow" | "deny";
@@ -15,12 +16,7 @@ function normalizeMatch(value?: string | null): string | undefined {
}
export function normalizeMediaUnderstandingChatType(raw?: string | null): string | undefined {
const value = raw?.trim().toLowerCase();
if (!value) return undefined;
if (value === "dm" || value === "direct_message" || value === "private") return "direct";
if (value === "groups") return "group";
if (value === "room") return "channel";
return value;
return normalizeChatType(raw ?? undefined);
}
export function resolveMediaUnderstandingScope(params: {
@@ -33,7 +29,7 @@ export function resolveMediaUnderstandingScope(params: {
if (!scope) return "allow";
const channel = normalizeMatch(params.channel);
const chatType = normalizeMediaUnderstandingChatType(params.chatType) ?? normalizeMatch(params.chatType);
const chatType = normalizeMediaUnderstandingChatType(params.chatType);
const sessionKey = normalizeMatch(params.sessionKey) ?? "";
for (const rule of scope.rules ?? []) {
@@ -41,8 +37,7 @@ export function resolveMediaUnderstandingScope(params: {
const action = normalizeDecision(rule.action) ?? "allow";
const match = rule.match ?? {};
const matchChannel = normalizeMatch(match.channel);
const matchChatType =
normalizeMediaUnderstandingChatType(match.chatType) ?? normalizeMatch(match.chatType);
const matchChatType = normalizeMediaUnderstandingChatType(match.chatType);
const matchPrefix = normalizeMatch(match.keyPrefix);
if (matchChannel && matchChannel !== channel) continue;