feat: add inbound media understanding

Co-authored-by: Tristan Manchester <tmanchester96@gmail.com>
This commit is contained in:
Peter Steinberger
2026-01-17 03:52:37 +00:00
parent 4b749f1b8f
commit 1b973f7506
42 changed files with 2547 additions and 101 deletions

View File

@@ -0,0 +1,46 @@
import { describe, expect, it } from "vitest";
import { resolveMediaUnderstandingScope } from "./scope.js";
describe("resolveMediaUnderstandingScope", () => {
it("defaults to allow when scope is undefined", () => {
expect(resolveMediaUnderstandingScope({})).toBe("allow");
});
it("uses first matching rule", () => {
const decision = resolveMediaUnderstandingScope({
scope: {
default: "deny",
rules: [
{ action: "allow", match: { channel: "whatsapp" } },
{ action: "deny", match: { channel: "whatsapp", chatType: "direct" } },
],
},
channel: "whatsapp",
chatType: "direct",
sessionKey: "whatsapp:direct:123",
});
expect(decision).toBe("allow");
});
it("matches keyPrefix when provided", () => {
const decision = resolveMediaUnderstandingScope({
scope: {
default: "deny",
rules: [{ action: "allow", match: { keyPrefix: "agent:main:" } }],
},
sessionKey: "agent:main:whatsapp:group:123",
});
expect(decision).toBe("allow");
});
it("matches keyPrefix case-insensitively", () => {
const decision = resolveMediaUnderstandingScope({
scope: {
default: "deny",
rules: [{ action: "allow", match: { keyPrefix: "agent:main:" } }],
},
sessionKey: "AGENT:MAIN:WHATSAPP:GROUP:123",
});
expect(decision).toBe("allow");
});
});